@ -298,6 +298,7 @@ define([
del
del
] ) ;
] ) ;
$ ( del ) . click ( function ( ) {
$ ( del ) . click ( function ( ) {
var $block = $ ( el ) . closest ( '.cp-form-edit-block' ) ;
$ ( el ) . remove ( ) ;
$ ( el ) . remove ( ) ;
// We've just deleted an item/option so we should be under the MAX limit and
// We've just deleted an item/option so we should be under the MAX limit and
// we can show the "add" button again
// we can show the "add" button again
@ -306,6 +307,13 @@ define([
$add . show ( ) ;
$add . show ( ) ;
if ( v . type === "time" ) { $ ( addMultiple ) . show ( ) ; }
if ( v . type === "time" ) { $ ( addMultiple ) . show ( ) ; }
}
}
// decrement the max choices input when there are fewer options than the current maximum
if ( maxInput ) {
var inputs = $block . find ( 'input' ) . length ;
var $maxInput = $ ( maxInput ) ;
var currentMax = Number ( $maxInput . val ( ) ) ;
$maxInput . val ( Math . min ( inputs , currentMax ) ) ;
}
} ) ;
} ) ;
return el ;
return el ;
} ;
} ;
@ -575,7 +583,22 @@ define([
] ;
] ;
} ;
} ;
var makePollTable = function ( answers , opts ) {
var getWeekDays = function ( large ) {
var baseDate = new Date ( 2017 , 0 , 1 ) ; // just a Sunday
var weekDays = [ ] ;
for ( var i = 0 ; i < 7 ; i ++ ) {
weekDays . push ( baseDate . toLocaleDateString ( undefined , { weekday : 'long' } ) ) ;
baseDate . setDate ( baseDate . getDate ( ) + 1 ) ;
}
if ( ! large ) {
weekDays = weekDays . map ( function ( day ) { return day . slice ( 0 , 3 ) ; } ) ;
}
return weekDays . map ( function ( day ) { return day . replace ( /^./ , function ( str ) { return str . toUpperCase ( ) ; } ) ; } ) ;
} ;
// "resultsPageObj" is an object with "content" and "answers"
// only available when viewing the Responses page
var makePollTable = function ( answers , opts , resultsPageObj ) {
// Sort date values
// Sort date values
if ( opts . type !== "text" ) {
if ( opts . type !== "text" ) {
opts . values . sort ( function ( a , b ) {
opts . values . sort ( function ( a , b ) {
@ -583,18 +606,25 @@ define([
} ) ;
} ) ;
}
}
// Create first line with options
// Create first line with options
var allDays = getWeekDays ( true ) ;
var els = opts . values . map ( function ( data ) {
var els = opts . values . map ( function ( data ) {
var _date ;
if ( opts . type === "day" ) {
if ( opts . type === "day" ) {
var _date = new Date ( data ) ;
_date = new Date ( data ) ;
data = _date . toLocaleDateString ( ) ;
data = _date . toLocaleDateString ( ) ;
}
}
if ( opts . type === "time" ) {
if ( opts . type === "time" ) {
var _date T = new Date ( data ) ;
_date = new Date ( data ) ;
data = Flatpickr . formatDate ( _date T , timeFormat ) ;
data = Flatpickr . formatDate ( _date , timeFormat ) ;
}
}
var day = _date && allDays [ _date . getDay ( ) ] ;
return h ( 'div.cp-poll-cell.cp-form-poll-option' , {
return h ( 'div.cp-poll-cell.cp-form-poll-option' , {
title : Util . fixHTML ( data )
title : Util . fixHTML ( data )
} , data ) ;
} , [
opts . type === 'day' ? h ( 'span.cp-form-weekday' , day ) : undefined ,
opts . type === 'day' ? h ( 'span.cp-form-weekday-separator' , ' - ' ) : undefined ,
h ( 'span' , data )
] ) ;
} ) ;
} ) ;
// Insert axis switch button
// Insert axis switch button
var switchAxis = h ( 'button.btn.btn-default' , [
var switchAxis = h ( 'button.btn.btn-default' , [
@ -611,13 +641,20 @@ define([
opts . values . forEach ( function ( d ) {
opts . values . forEach ( function ( d ) {
var date = new Date ( d ) ;
var date = new Date ( d ) ;
var day = date . toLocaleDateString ( ) ;
var day = date . toLocaleDateString ( ) ;
_days [ day ] = _days [ day ] || 0 ;
_days [ day ] = {
_days [ day ] ++ ;
n : ( _days [ day ] && _days [ day ] . n ) || 0 ,
name : allDays [ date . getDay ( ) ]
} ;
_days [ day ] . n ++ ;
} ) ;
} ) ;
Object . keys ( _days ) . forEach ( function ( day ) {
Object . keys ( _days ) . forEach ( function ( day ) {
days . push ( h ( 'div.cp-poll-cell.cp-poll-time-day' , {
days . push ( h ( 'div.cp-poll-cell.cp-poll-time-day' , {
style : 'flex-grow:' + ( _days [ day ] - 1 ) + ';'
style : 'flex-grow:' + ( _days [ day ] . n - 1 ) + ';'
} , day ) ) ;
} , [
h ( 'span.cp-form-weekday' , _days [ day ] . name ) ,
h ( 'span.cp-form-weekday-separator' , ' - ' ) ,
h ( 'span' , day )
] ) ) ;
} ) ;
} ) ;
lines . unshift ( h ( 'div' , days ) ) ;
lines . unshift ( h ( 'div' , days ) ) ;
}
}
@ -640,13 +677,19 @@ define([
} , v ) ;
} , v ) ;
return cell ;
return cell ;
} ) ;
} ) ;
els . unshift ( h ( 'div.cp-poll-cell.cp-poll-answer-name' , {
var nameCell ;
els . unshift ( nameCell = h ( 'div.cp-poll-cell.cp-poll-answer-name' , {
title : Util . fixHTML ( name )
title : Util . fixHTML ( name )
} , [
} , [
avatar ,
avatar ,
h ( 'span' , name )
h ( 'span' , name )
] ) ) ;
] ) ) ;
bodyEls . push ( h ( 'div' , els ) ) ;
bodyEls . push ( h ( 'div' , els ) ) ;
if ( resultsPageObj && ( APP . isEditor || APP . isAuditor ) ) {
$ ( nameCell ) . addClass ( 'cp-clickable' ) . click ( function ( ) {
APP . renderResults ( resultsPageObj . content , resultsPageObj . answers , answerObj . curve ) ;
} ) ;
}
} ) ;
} ) ;
}
}
var body = h ( 'div.cp-form-poll-body' , bodyEls ) ;
var body = h ( 'div.cp-form-poll-body' , bodyEls ) ;
@ -788,6 +831,7 @@ define([
if ( filterCurve && user === filterCurve ) { return ; }
if ( filterCurve && user === filterCurve ) { return ; }
try {
try {
return {
return {
curve : user ,
user : answers [ user ] . msg . _userdata ,
user : answers [ user ] . msg . _userdata ,
results : answers [ user ] . msg [ uid ]
results : answers [ user ] . msg [ uid ]
} ;
} ;
@ -950,7 +994,7 @@ define([
printResults : function ( answers , uid ) {
printResults : function ( answers , uid ) {
var results = [ ] ;
var results = [ ] ;
var empty = 0 ;
var empty = 0 ;
Object . keys ( answers ) . forEach ( function ( author ) {
Object . keys ( answers ) . forEach ( function ( author ) { // TODO deduplicate these?
var obj = answers [ author ] ;
var obj = answers [ author ] ;
var answer = obj . msg [ uid ] ;
var answer = obj . msg [ uid ] ;
if ( ! answer || ! answer . trim ( ) ) { return empty ++ ; }
if ( ! answer || ! answer . trim ( ) ) { return empty ++ ; }
@ -1016,7 +1060,7 @@ define([
printResults : function ( answers , uid ) {
printResults : function ( answers , uid ) {
var results = [ ] ;
var results = [ ] ;
var empty = 0 ;
var empty = 0 ;
Object . keys ( answers ) . forEach ( function ( author ) {
Object . keys ( answers ) . forEach ( function ( author ) { // TODO deduplicate these
var obj = answers [ author ] ;
var obj = answers [ author ] ;
var answer = obj . msg [ uid ] ;
var answer = obj . msg [ uid ] ;
if ( ! answer || ! answer . trim ( ) ) { return empty ++ ; }
if ( ! answer || ! answer . trim ( ) ) { return empty ++ ; }
@ -1090,8 +1134,7 @@ define([
var obj = answers [ author ] ;
var obj = answers [ author ] ;
var answer = obj . msg [ uid ] ;
var answer = obj . msg [ uid ] ;
if ( ! answer || ! answer . trim ( ) ) { return empty ++ ; }
if ( ! answer || ! answer . trim ( ) ) { return empty ++ ; }
count [ answer ] = count [ answer ] || 0 ;
Util . inc ( count , answer ) ;
count [ answer ] ++ ;
} ) ;
} ) ;
Object . keys ( count ) . forEach ( function ( value ) {
Object . keys ( count ) . forEach ( function ( value ) {
results . push ( h ( 'div.cp-form-results-type-radio-data' , [
results . push ( h ( 'div.cp-form-results-type-radio-data' , [
@ -1193,8 +1236,7 @@ define([
var c = count [ q _uid ] = count [ q _uid ] || { } ;
var c = count [ q _uid ] = count [ q _uid ] || { } ;
var res = answer [ q _uid ] ;
var res = answer [ q _uid ] ;
if ( ! res || ! res . trim ( ) ) { return ; }
if ( ! res || ! res . trim ( ) ) { return ; }
c [ res ] = c [ res ] || 0 ;
Util . inc ( c , res ) ;
c [ res ] ++ ;
} ) ;
} ) ;
} ) ;
} ) ;
Object . keys ( count ) . forEach ( function ( q _uid ) {
Object . keys ( count ) . forEach ( function ( q _uid ) {
@ -1304,8 +1346,7 @@ define([
var answer = obj . msg [ uid ] ;
var answer = obj . msg [ uid ] ;
if ( ! Array . isArray ( answer ) || ! answer . length ) { return empty ++ ; }
if ( ! Array . isArray ( answer ) || ! answer . length ) { return empty ++ ; }
answer . forEach ( function ( val ) {
answer . forEach ( function ( val ) {
count [ val ] = count [ val ] || 0 ;
Util . inc ( count , val ) ;
count [ val ] ++ ;
} ) ;
} ) ;
} ) ;
} ) ;
Object . keys ( count ) . forEach ( function ( value ) {
Object . keys ( count ) . forEach ( function ( value ) {
@ -1420,8 +1461,7 @@ define([
var res = answer [ q _uid ] ;
var res = answer [ q _uid ] ;
if ( ! Array . isArray ( res ) || ! res . length ) { return ; }
if ( ! Array . isArray ( res ) || ! res . length ) { return ; }
res . forEach ( function ( v ) {
res . forEach ( function ( v ) {
c [ v ] = c [ v ] || 0 ;
Util . inc ( c , v ) ;
c [ v ] ++ ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
} ) ;
@ -1470,7 +1510,9 @@ define([
if ( ! Array . isArray ( opts . values ) ) { return ; }
if ( ! Array . isArray ( opts . values ) ) { return ; }
var map = { } ;
var map = { } ;
var invMap = { } ;
var invMap = { } ;
var els = opts . values . map ( function ( data , i ) {
var sorted = false ;
Util . shuffleArray ( opts . values ) ;
var els = opts . values . map ( function ( data ) {
var uid = Util . uid ( ) ;
var uid = Util . uid ( ) ;
map [ uid ] = data ;
map [ uid ] = data ;
invMap [ data ] = uid ;
invMap [ data ] = uid ;
@ -1479,7 +1521,7 @@ define([
h ( 'i.fa.fa-ellipsis-v' ) ,
h ( 'i.fa.fa-ellipsis-v' ) ,
h ( 'i.fa.fa-ellipsis-v' ) ,
h ( 'i.fa.fa-ellipsis-v' ) ,
] ) ,
] ) ,
h ( 'span.cp-form-sort-order' , ( i + 1 ) ) ,
h ( 'span.cp-form-sort-order' , '?' ) ,
h ( 'span' , data )
h ( 'span' , data )
] ) ;
] ) ;
$ ( div ) . data ( 'val' , data ) ;
$ ( div ) . data ( 'val' , data ) ;
@ -1490,10 +1532,11 @@ define([
els
els
] ) ;
] ) ;
var $tag = $ ( tag ) ;
var $tag = $ ( tag ) ;
var reorder = function ( ) {
var reorder = function ( reset ) {
$tag . find ( '.cp-form-type-sort' ) . each ( function ( i , el ) {
$tag . find ( '.cp-form-type-sort' ) . each ( function ( i , el ) {
$ ( el ) . find ( '.cp-form-sort-order' ) . text ( i+ 1 ) ;
$ ( el ) . find ( '.cp-form-sort-order' ) . text ( reset ? '?' : i+ 1 ) ;
} ) ;
} ) ;
sorted = ! reset ;
} ;
} ;
var cursorGetter ;
var cursorGetter ;
var setCursorGetter = function ( f ) { cursorGetter = f ; } ;
var setCursorGetter = function ( f ) { cursorGetter = f ; } ;
@ -1516,16 +1559,18 @@ define([
return {
return {
tag : tag ,
tag : tag ,
getValue : function ( ) {
getValue : function ( ) {
if ( ! sorted ) { return ; }
return sortable . toArray ( ) . map ( function ( id ) {
return sortable . toArray ( ) . map ( function ( id ) {
return map [ id ] ;
return map [ id ] ;
} ) ;
} ) ;
} ,
} ,
reset : function ( ) {
reset : function ( ) {
Util . shuffleArray ( opts . values ) ;
var toSort = ( opts . values ) . map ( function ( val ) {
var toSort = ( opts . values ) . map ( function ( val ) {
return invMap [ val ] ;
return invMap [ val ] ;
} ) ;
} ) ;
sortable . sort ( toSort ) ;
sortable . sort ( toSort ) ;
reorder ( ) ;
reorder ( true ) ;
} ,
} ,
edit : function ( cb , tmp ) {
edit : function ( cb , tmp ) {
var v = Util . clone ( opts ) ;
var v = Util . clone ( opts ) ;
@ -1554,7 +1599,7 @@ define([
if ( ! Array . isArray ( answer ) || ! answer . length ) { return empty ++ ; }
if ( ! Array . isArray ( answer ) || ! answer . length ) { return empty ++ ; }
answer . forEach ( function ( el , i ) {
answer . forEach ( function ( el , i ) {
var score = l - i ;
var score = l - i ;
count[ el ] = ( count [ el ] || 0 ) + score ;
Util. inc ( count , el , score ) ;
} ) ;
} ) ;
} ) ;
} ) ;
var sorted = Object . keys ( count ) . sort ( function ( a , b ) {
var sorted = Object . keys ( count ) . sort ( function ( a , b ) {
@ -1583,7 +1628,7 @@ define([
if ( ! opts ) { opts = TYPES . poll . defaultOpts ; }
if ( ! opts ) { opts = TYPES . poll . defaultOpts ; }
if ( ! Array . isArray ( opts . values ) ) { return ; }
if ( ! Array . isArray ( opts . values ) ) { return ; }
var lines = makePollTable ( answers , opts );
var lines = makePollTable ( answers , opts , false );
// Add form
// Add form
var addLine = opts . values . map ( function ( data ) {
var addLine = opts . values . map ( function ( data ) {
@ -1667,31 +1712,53 @@ define([
} ;
} ;
} ,
} ,
printResults : function ( answers , uid , form ) {
printResults : function ( answers , uid , form , content ) {
var opts = form [ uid ] . opts || TYPES . poll . defaultOpts ;
var opts = form [ uid ] . opts || TYPES . poll . defaultOpts ;
var _answers = getBlockAnswers ( answers , uid ) ;
var _answers = getBlockAnswers ( answers , uid ) ;
var lines = makePollTable ( _answers , opts ) ;
// If content is defined, we'll be able to click on a row to display
// all the answers of this user
var lines = makePollTable ( _answers , opts , content && {
content : content ,
answers : answers
} ) ;
var total = makePollTotal ( _answers , opts ) ;
var total = makePollTotal ( _answers , opts ) ;
if ( total ) { lines . push ( h ( 'div' , total ) ) ; }
if ( total ) { lines . push ( h ( 'div' , total ) ) ; }
return h ( 'div.cp-form-type-poll' , lines ) ;
return h ( 'div.cp-form-type-poll' , lines ) ;
} ,
} ,
exportCSV : function ( answer ) {
exportCSV : function ( answer , form ) {
if ( answer === false ) { return ; }
var opts = form . opts || TYPES . poll . defaultOpts ;
if ( ! answer || ! answer . values ) { return [ '' ] ; }
var q = form . q || Messages . form _default ;
if ( answer === false ) {
var cols = opts . values . map ( function ( key ) {
return q + ' | ' + key ;
} ) ;
cols . unshift ( q ) ;
return cols ;
}
if ( ! answer || ! answer . values ) {
var empty = opts . values . map ( function ( ) { return '' ; } ) ;
empty . unshift ( '' ) ;
return empty ;
}
var str = '' ;
var str = '' ;
Object . keys ( answer . values ) . sort ( ) . forEach ( function ( k , i ) {
Object . keys ( answer . values ) . sort ( ) . forEach ( function ( k , i ) {
if ( i !== 0 ) { str += ';' ; }
if ( i !== 0 ) { str += ';' ; }
str += k . replace ( ';' , '' ) . replace ( ':' , '' ) + ':' + answer . values [ k ] ;
str += k . replace ( ';' , '' ) . replace ( ':' , '' ) + ':' + answer . values [ k ] ;
} ) ;
} ) ;
return [ str ] ;
var res = opts . values . map ( function ( key ) {
return answer . values [ key ] || '' ;
} ) ;
res . unshift ( str ) ;
return res ;
} ,
} ,
icon : h ( 'i.cptools.cptools-form-poll' )
icon : h ( 'i.cptools.cptools-form-poll' )
} ,
} ,
} ;
} ;
var renderResults = function ( content , answers ) {
var renderResults = APP . renderResults = function ( content , answers , showUser ) {
var $container = $ ( 'div.cp-form-creator-results' ) . empty ( ) ;
var $container = $ ( 'div.cp-form-creator-results' ) . empty ( ) ;
if ( ! Object . keys ( answers || { } ) . length ) {
if ( ! Object . keys ( answers || { } ) . length ) {
@ -1699,9 +1766,15 @@ define([
return ;
return ;
}
}
if ( content . answers . msg ) {
var description = h ( 'div.cp-form-creator-results-description#cp-form-response-msg' ) ;
var $desc = $ ( description ) . appendTo ( $container ) ;
DiffMd . apply ( DiffMd . render ( content . answers . msg ) , $desc , APP . common ) ;
}
var controls = h ( 'div.cp-form-creator-results-controls' ) ;
var controls = h ( 'div.cp-form-creator-results-controls' ) ;
var $controls = $ ( controls ) . appendTo ( $container ) ;
var $controls = $ ( controls ) . appendTo ( $container ) ;
var exportButton = h ( 'button.btn.btn-secondary' , Messages . exportButton ) ; // XXX form_exportCSV;
var exportButton = h ( 'button.btn.btn-secondary' , Messages . form _exportCSV) ;
var exportCSV = h ( 'div.cp-form-creator-results-export' , exportButton ) ;
var exportCSV = h ( 'div.cp-form-creator-results-export' , exportButton ) ;
$ ( exportCSV ) . appendTo ( $container ) ;
$ ( exportCSV ) . appendTo ( $container ) ;
var results = h ( 'div.cp-form-creator-results-content' ) ;
var results = h ( 'div.cp-form-creator-results-content' ) ;
@ -1729,7 +1802,9 @@ define([
var type = block . type ;
var type = block . type ;
var model = TYPES [ type ] ;
var model = TYPES [ type ] ;
if ( ! model || ! model . printResults ) { return ; }
if ( ! model || ! model . printResults ) { return ; }
var print = model . printResults ( answers , uid , form ) ;
// Only use content if we're not viewing individual answers
var print = model . printResults ( answers , uid , form , ! header && content ) ;
var q = h ( 'div.cp-form-block-question' , block . q || Messages . form _default ) ;
var q = h ( 'div.cp-form-block-question' , block . q || Messages . form _default ) ;
@ -1823,14 +1898,23 @@ define([
e . preventDefault ( ) ;
e . preventDefault ( ) ;
APP . common . openURL ( Hash . hashToHref ( ud . profile , 'profile' ) ) ;
APP . common . openURL ( Hash . hashToHref ( ud . profile , 'profile' ) ) ;
} ) ;
} ) ;
if ( showUser === curve ) {
setTimeout ( function ( ) {
showUser = undefined ;
$ ( viewButton ) . click ( ) ;
} ) ;
}
return div ;
return div ;
} ) ;
} ) ;
$results . append ( els ) ;
$results . append ( els ) ;
} ) ;
} ) ;
if ( showUser ) {
$s . click ( ) ;
}
} ;
} ;
var addResultsButton = function ( framework , content ) {
var addResultsButton = function ( framework , content ) {
var $res = $ ( h ( 'button.cp-toolbar-appmenu ', [
var $res = $ ( h ( 'button.cp-toolbar-appmenu .cp-toolbar-form-button ', [
h ( 'i.fa.fa-bar-chart' ) ,
h ( 'i.fa.fa-bar-chart' ) ,
h ( 'span.cp-button-name' , Messages . form _results )
h ( 'span.cp-button-name' , Messages . form _results )
] ) ) ;
] ) ) ;
@ -1872,25 +1956,42 @@ define([
var makeFormControls = function ( framework , content , update , evOnChange ) {
var makeFormControls = function ( framework , content , update , evOnChange ) {
var loggedIn = framework . _ . sfCommon . isLoggedIn ( ) ;
var loggedIn = framework . _ . sfCommon . isLoggedIn ( ) ;
var metadataMgr = framework . _ . cpNfInner . metadataMgr ;
var metadataMgr = framework . _ . cpNfInner . metadataMgr ;
var user = metadataMgr . getUserData ( ) ;
if ( ! loggedIn && ! content . answers . anonymous ) { return ; }
if ( ! loggedIn && ! content . answers . anonymous ) { return ; }
var cbox ;
var cbox ;
var anonName , $anonName ;
cbox = UI . createCheckbox ( 'cp-form-anonymous' ,
cbox = UI . createCheckbox ( 'cp-form-anonymous' ,
Messages . form _anonymousBox , true , { mark : { tabindex : 1 } } ) ;
Messages . form _anonymousBox , true , { mark : { tabindex : 1 } } ) ;
var $anonBox = $ ( cbox ) . find ( 'input' ) ;
if ( loggedIn ) {
if ( loggedIn ) {
if ( ! content . answers . anonymous || APP . cantAnon ) {
if ( ! content . answers . anonymous || APP . cantAnon ) {
$ ( cbox ) . hide ( ) . find ( 'input' ) . attr ( 'disabled' , 'disabled' ) . prop ( 'checked' , false ) ;
$ ( cbox ) . hide ( ) . find ( 'input' ) . attr ( 'disabled' , 'disabled' ) . prop ( 'checked' , false ) ;
}
}
} else {
anonName = h ( 'div.cp-form-anon-answer-input' , [
Messages . form _answerAs ,
h ( 'input' , {
value : user . name || '' ,
placeholder : Messages . form _anonName
} )
] ) ;
$anonName = $ ( anonName ) . hide ( ) ;
$anonBox . on ( 'change' , function ( ) {
if ( Util . isChecked ( $anonBox ) ) { $anonName . hide ( ) ; }
else { $anonName . show ( ) ; }
} ) ;
}
}
var send = h ( 'button.cp-open.btn.btn-primary' , update ? Messages . form _update : Messages . form _submit ) ;
var send = h ( 'button.cp-open.btn.btn-primary' , update ? Messages . form _update : Messages . form _submit ) ;
var reset = h ( 'button.cp-open.btn.btn-danger-alt' , Messages . form _reset ) ;
var reset = h ( 'button.cp-open. cp-reset-button. btn.btn-danger-alt', Messages . form _reset ) ;
$ ( reset ) . click ( function ( ) {
$ ( reset ) . click ( function ( ) {
if ( ! Array . isArray ( APP . formBlocks ) ) { return ; }
if ( ! Array . isArray ( APP . formBlocks ) ) { return ; }
APP . formBlocks . forEach ( function ( data ) {
APP . formBlocks . forEach ( function ( data ) {
if ( typeof ( data . reset ) === "function" ) { data . reset ( ) ; }
if ( typeof ( data . reset ) === "function" ) { data . reset ( ) ; }
} ) ;
} ) ;
$ ( reset ) . attr ( 'disabled' , 'disabled' ) ;
} ) ;
} ) ;
var $send = $ ( send ) . click ( function ( ) {
var $send = $ ( send ) . click ( function ( ) {
$send . attr ( 'disabled' , 'disabled' ) ;
$send . attr ( 'disabled' , 'disabled' ) ;
@ -1898,14 +1999,16 @@ define([
if ( ! results ) { return ; }
if ( ! results ) { return ; }
var user = metadataMgr . getUserData ( ) ;
var user = metadataMgr . getUserData ( ) ;
if ( ! Util . isChecked ( $ ( cbox ) . find ( 'input' ) ) ) {
if ( ! Util . isChecked ( $ anonBox ) ) {
results . _userdata = loggedIn ? {
results . _userdata = loggedIn ? {
avatar : user . avatar ,
avatar : user . avatar ,
name : user . name ,
name : user . name ,
notifications : user . notifications ,
notifications : user . notifications ,
curvePublic : user . curvePublic ,
curvePublic : user . curvePublic ,
profile : user . profile
profile : user . profile
} : { name : user . name } ;
} : {
name : $anonName ? $anonName . find ( 'input' ) . val ( ) : user . name
} ;
}
}
var sframeChan = framework . _ . sfCommon . getSframeChannel ( ) ;
var sframeChan = framework . _ . sfCommon . getSframeChannel ( ) ;
@ -1985,7 +2088,10 @@ define([
return h ( 'div.cp-form-send-container' , [
return h ( 'div.cp-form-send-container' , [
invalid ,
invalid ,
cbox ? h ( 'div.cp-form-anon-answer' , cbox ) : undefined ,
cbox ? h ( 'div.cp-form-anon-answer' , [
cbox ,
anonName
] ) : undefined ,
reset , send
reset , send
] ) ;
] ) ;
} ;
} ;
@ -1997,6 +2103,18 @@ define([
APP . formBlocks = [ ] ;
APP . formBlocks = [ ] ;
if ( APP . isClosed && content . answers . privateKey && ! APP . isEditor ) {
var sframeChan = framework . _ . sfCommon . getSframeChannel ( ) ;
sframeChan . query ( "Q_FORM_FETCH_ANSWERS" , content . answers , function ( err , obj ) {
var answers = obj && obj . results ;
if ( answers ) { APP . answers = answers ; }
$ ( 'body' ) . addClass ( 'cp-app-form-results' ) ;
$ ( '.cp-toolbar-form-button' ) . remove ( ) ;
renderResults ( content , answers ) ;
} ) ;
return ;
}
var evOnChange = Util . mkEvent ( ) ;
var evOnChange = Util . mkEvent ( ) ;
if ( ! APP . isEditor ) {
if ( ! APP . isEditor ) {
var _answers = Util . clone ( answers || { } ) ;
var _answers = Util . clone ( answers || { } ) ;
@ -2004,6 +2122,7 @@ define([
delete _answers . _userdata ;
delete _answers . _userdata ;
evOnChange . reg ( function ( noBeforeUnload , isSave ) {
evOnChange . reg ( function ( noBeforeUnload , isSave ) {
if ( noBeforeUnload ) { return ; }
if ( noBeforeUnload ) { return ; }
$container . find ( '.cp-reset-button' ) . removeAttr ( 'disabled' ) ;
var results = getFormResults ( ) ;
var results = getFormResults ( ) ;
if ( isSave ) {
if ( isSave ) {
answers = Util . clone ( results || { } ) ;
answers = Util . clone ( results || { } ) ;
@ -2356,6 +2475,9 @@ define([
// In view mode, add "Submit" and "reset" buttons
// In view mode, add "Submit" and "reset" buttons
$container . append ( makeFormControls ( framework , content , Boolean ( answers ) , evOnChange ) ) ;
$container . append ( makeFormControls ( framework , content , Boolean ( answers ) , evOnChange ) ) ;
if ( ! answers ) {
$container . find ( '.cp-reset-button' ) . attr ( 'disabled' , 'disabled' ) ;
}
} ;
} ;
var getTempFields = function ( ) {
var getTempFields = function ( ) {
@ -2443,6 +2565,72 @@ define([
} ;
} ;
refreshPublic ( ) ;
refreshPublic ( ) ;
var responseMsg = h ( 'div.cp-form-response-msg-container' ) ;
var $responseMsg = $ ( responseMsg ) ;
var refreshResponse = function ( ) {
if ( true ) { return ; } // XXX 4.10.0
$responseMsg . empty ( ) ;
Messages . form _updateMsg = "Update response message" ; // XXX 4.10.0
Messages . form _addMsg = "Add response message" ; // XXX 4.10.0
Messages . form _responseMsg = "Add a message that will be displayed in the response page." ; // XXX 4.10.0
var text = content . answers . msg ? Messages . form _updateMsg : Messages . form _addMsg ;
var btn = h ( 'button.btn.btn-secondary' , text ) ;
$ ( btn ) . click ( function ( ) {
var editor ;
if ( ! APP . responseModal ) {
var t = h ( 'textarea' ) ;
var div = h ( 'div' , [
h ( 'p' , Messages . form _responseMsg ) ,
t
] ) ;
var cm = SFCodeMirror . create ( "gfm" , CMeditor , t ) ;
editor = APP . responseEditor = cm . editor ;
editor . setOption ( 'lineNumbers' , true ) ;
editor . setOption ( 'lineWrapping' , true ) ;
editor . setOption ( 'styleActiveLine' , true ) ;
editor . setOption ( 'readOnly' , false ) ;
setTimeout ( function ( ) {
editor . setValue ( content . answers . msg || '' ) ;
editor . refresh ( ) ;
editor . save ( ) ;
editor . focus ( ) ;
} ) ;
var buttons = [ {
className : 'primary' ,
name : Messages . settings _save ,
onClick : function ( ) {
var v = editor . getValue ( ) ;
content . answers . msg = v . trim ( 0 , 2000 ) ; // XXX 4.10.0 max length?
framework . localChange ( ) ;
framework . _ . cpNfInner . chainpad . onSettle ( function ( ) {
UI . log ( Messages . saved ) ;
refreshResponse ( ) ;
} ) ;
} ,
//keys: []
} , {
className : 'cancel' ,
name : Messages . cancel ,
onClick : function ( ) { } ,
keys : [ 27 ]
} ] ;
APP . responseModal = UI . dialog . customModal ( div , { buttons : buttons } ) ;
} else {
editor = APP . responseEditor ;
setTimeout ( function ( ) {
editor . setValue ( content . answers . msg || '' ) ;
editor . refresh ( ) ;
editor . save ( ) ;
editor . focus ( ) ;
} ) ;
}
UI . openCustomModal ( APP . responseModal ) ;
} ) ;
// $responseMsg.append(btn); // XXX 4.10.0
} ;
//refreshResponse();
// Allow anonymous answers
// Allow anonymous answers
var privacyContainer = h ( 'div.cp-form-privacy-container' ) ;
var privacyContainer = h ( 'div.cp-form-privacy-container' ) ;
var $privacy = $ ( privacyContainer ) ;
var $privacy = $ ( privacyContainer ) ;
@ -2538,11 +2726,13 @@ define([
evOnChange . reg ( refreshPublic ) ;
evOnChange . reg ( refreshPublic ) ;
evOnChange . reg ( refreshPrivacy ) ;
evOnChange . reg ( refreshPrivacy ) ;
evOnChange . reg ( refreshEndDate ) ;
evOnChange . reg ( refreshEndDate ) ;
//evOnChange.reg(refreshResponse);
return [
return [
endDateContainer ,
endDateContainer ,
privacyContainer ,
privacyContainer ,
resultsType ,
resultsType ,
responseMsg
] ;
] ;
} ;
} ;