ips.templates.set('workgroups.question'," <li class='legoSurveyQuestion ipsBox ipsBox_transparent' data-controller='workgroups.front.survey.question' data-questionNumber='{{questionNumber}}' data-questionID='{{id}}'>  <ul class='legoSurveyQuestionTypes ipsPad'>   <li><a class='ipsType_blendLinks' href='#' data-role='questionType' data-type='text'>Text</a></li>   <!-- @todo <li><a class='ipsType_blendLinks' href='#' data-role='questionType' data-type='multiText'>Multiple Text</a></li>-->   <li><a class='ipsType_blendLinks' href='#' data-role='questionType' data-type='checkboxes'>Checkboxes</a></li>   <li><a class='ipsType_blendLinks' href='#' data-role='questionType' data-type='radios'>Radios</a></li>   <li><a class='ipsType_blendLinks' href='#' data-role='questionType' data-type='select'>Dropdown</a></li>   <li><a class='ipsType_blendLinks' href='#' data-role='questionType' data-type='slider'>Slider</a></li>   <li><a class='ipsType_blendLinks' href='#' data-role='questionType' data-type='upload'>Upload</a></li>  </ul> </li>");ips.templates.set('workgroups.questionBody'," <div>  <div class='legoQuestionHeader ipsAreaBackground_light ipsPad'>   <h2 class='ipsType_reset'>Q{{questionNumber}}:</h2>   <input type='text' class='legoSurveyQuestionTitle' data-role='questionTitle' placeholder='Question Title' value='{{questionTitle}}'>  </div>  {{#hasBody}}   <div class='legoQuestionBody ipsAreaBackground_reset'>    {{#content}}     <div class='legoQuestionBody_choices' data-role='choicesContainer'>      {{{content}}}     </div>    {{/content}}    <div class='legoQuestionBody_options'>     <h3 class='ipsType_minorHeading'>Field Options</h3>     <ul class='ipsForm ipsForm_vertical ipsSpacer_top' data-ipsForm>      <li class='ipsFieldRow ipsFieldRow_checkbox'>       <span class='ipsCustomInput'>        <input type='checkbox' id='required_{{id}}' data-role='required' {{#required}}checked{{/required}}>        <span></span>       </span>       <div class='ipsFieldRow_content'>        <label for='required_{{id}}'>Require an answer to this question</label>       </div>      </li>      {{{options}}}     </ul>    </div>   </div>  {{/hasBody}}  <div class='legoQuestionFooter ipsAreaBackground ipsClearfix ipsPad ipsType_center'>   <ul class='ipsList_inline'>    {{#newQuestion}}<li><button type='button' data-role='cancel' class='ipsButton ipsButton_veryLight ipsButton_verySmall'>Cancel</button></li>{{/newQuestion}}    <li><button type='button' data-role='save' class='ipsButton ipsButton_primary ipsButton_verySmall'>Save Question</button></li>   </ul>  </div> </div>");ips.templates.set('workgroups.choices'," <ul class='legoQuestionChoices' data-role='choices'>  {{{choices}}} </ul>");ips.templates.set('workgroups.sliderChoices'," <li>  <span class='legoQuestionChoices_textLabel'>   Left Label  </span>   <input type='text' data-role='startLabel' value='{{startLabel}}' length='30'> </li> <li>  <span class='legoQuestionChoices_textLabel'>   Center Label  </span>   <input type='text' data-role='centerLabel' value='{{centerLabel}}' length='30'> </li> <li>  <span class='legoQuestionChoices_textLabel'>   Right Label  </span>   <input type='text' data-role='endLabel' value='{{endLabel}}' length='30'> </li>");ips.templates.set('workgroups.choicesItems'," <li>  <span class='legoQuestionChoices_number'>   <i class='fa fa-bars ipsType_light ipsFaded'></i> <span data-role='choiceNumber'>{{id}}</span>  </span>   <span class='legoQuestionChoices_dummy'>{{{dummyControl}}}</span>   <input type='text' data-role='choice' placeholder='{{placeholder}}' value='{{value}}'>  <span class='legoQuestionChoices_controls'>   <a href='#' data-role='addChoice' title='Insert a row' data-ipsTooltip><i class='fa fa-plus-circle'></i></a>   <a href='#' data-role='removeChoice' title='Remove this row' data-ipsTooltip><i class='fa fa-minus-circle'></i></a>  </span> </li>");ips.templates.set('workgroups.dummyCheckbox'," <span class='ipsCustomInput legoQuestionChoices_dummyControl'>  <input type='checkbox'>  <span></span> </span>");ips.templates.set('workgroups.dummyRadio'," <span class='ipsCustomInput legoQuestionChoices_dummyControl'>  <input type='radio'>  <span></span> </span>");ips.templates.set('workgroups.sliderOptions'," <li class='ipsFieldRow'>  <p class='ipsType_reset ipsType_minorHeading'><strong>Scale</strong></p>  <div class='ipsGrid'>   <div class='ipsGrid_span5'>    <input type='number' data-role='start' value='{{start}}'>   </div>   <div class='ipsGrid_span2 ipsType_center ipsType_normal ipsSpacer_top ipsSpacer_half'>    to   </div>   <div class='ipsGrid_span5'>    <input type='number' data-role='end' value='{{end}}'>   </div>  </div> </li> <li class='ipsFieldRow'>  <div class='ipsGrid'>   <div class='ipsGrid_span6'>    <p class='ipsType_reset ipsType_minorHeading'><strong>Step Size</strong></p>    <input type='number' data-role='step' value='{{step}}'>   </div>   <div class='ipsGrid_span6'>    <p class='ipsType_reset ipsType_minorHeading'><strong>Start Position</strong></p>    <select data-role='startPos'>     <option value='left'>Left</option>     <option value='center'>Center</option>     <option value='right'>Right</option>    </select>   </div>  </div> </li>");ips.templates.set('workgroups.uploadOptions'," <li class='ipsFieldRow ipsFieldRow_checkbox'>  <span class='ipsCustomInput'>   <input type='checkbox' id='imagesOnly_{{id}}' data-role='imagesOnly' {{#imagesOnly}}checked{{/imagesOnly}}>   <span></span>  </span>  <div class='ipsFieldRow_content'>   <label for='imagesOnly_{{id}}'>Only allow image uploads</label>  </div> </li>");ips.templates.set('workgroups.radioCheckOptions'," <li class='ipsFieldRow ipsFieldRow_checkbox'>  <span class='ipsCustomInput'>   <input type='checkbox' id='other_{{id}}' data-role='allowOther' {{#allowOther}}checked{{/allowOther}}>   <span></span>  </span>  <div class='ipsFieldRow_content'>   <label for='other_{{id}}'>Add a text field for an 'Other' answer</label>  </div> </li>");ips.templates.set('workgroups.textOptions'," <li class='ipsFieldRow ipsFieldRow_checkbox'>  <span class='ipsCustomInput'>   <input type='checkbox' id='multiLine_{{id}}' {{#multiLine}}checked{{/multiLine}} data-role='multiLine' data-control='toggle' data-togglesOff='lengthToggleRow_{{id}},formatRow_{{id}}'>   <span></span>  </span>  <div class='ipsFieldRow_content'>   <label for='multiLine_{{id}}'>Allow multiple lines (comment field)</label>  </div> </li> <li class='ipsFieldRow ipsFieldRow_checkbox' id='formatRow_{{id}}'>  <span class='ipsCustomInput'>   <input type='checkbox' id='format_{{id}}' {{#textFormat}}checked{{/textFormat}} data-role='textFormat' data-control='toggle' data-toggles='formats_{{id}}' data-togglesOff='lengthToggleRow_{{id}}'>   <span></span>  </span>  <div class='ipsFieldRow_content'>   <label for='format_{{id}}'>Require specific format</label>  </div> </li> <li class='ipsFieldRow ipsFieldRow_checkbox' id='formats_{{id}}'>  <div class='ipsFieldRow_content'>   <select data-role='textFormatChoice'>    <option value='number' {{#format.number}}selected{{/format.number}} data-control='toggle' data-toggles='decimals_{{id}}'>Number</option>    <option value='email' {{#format.email}}selected{{/format.email}}>Email Address</option>    <option value='url' {{#format.url}}selected{{/format.url}}>URL</option>   </select>  </div> </li> <li class='ipsFieldRow ipsFieldRow_checkbox' id='lengthToggleRow_{{id}}'>  <span class='ipsCustomInput'>   <input type='checkbox' id='lengthToggle_{{id}}' {{#limitLength}}checked{{/limitLength}} data-role='limitLength' data-control='toggle' data-toggles='lengths_{{id}}'>   <span></span>  </span>  <div class='ipsFieldRow_content'>   <label for='lengthToggle_{{id}}'>Limit length</label>  </div> </li> <li class='ipsFieldRow ipsFieldRow_checkbox' id='lengths_{{id}}'>  <div class='ipsFieldRow_content'>   <ul class='ipsList_reset legoQuestionMinMax'>    <li><label for='min_{{id}}' class='ipsType_small'>Min:</label> <input type='number' id='min_{{id}}' data-role='minLength' class='ipsField_short ipsField_small' value='{{minLen}}'></li>    <li><label for='max_{{id}}' class='ipsType_small'>Max:</label> <input type='number' id='max_{{id}}' data-role='maxLength' class='ipsField_short ipsField_small' value='{{maxLen}}'></li>   </ul>  </div> </li> <li class='ipsFieldRow ipsFieldRow_checkbox' id='decimals_{{id}}'>  <span class='ipsCustomInput'>   <input type='checkbox' id='format_{{id}}' {{#wholeNumbers}}checked{{/wholeNumbers}} data-role='wholeNumbers'>   <span></span>  </span>  <div class='ipsFieldRow_content'>   <label for='format_{{id}}'>Whole numbers only</label>  </div> </li>");ips.templates.set('workgroups.renderQuestion'," <h1 class='ipsType_pageTitle legoSurveyQuestion_title ipsAreaBackground_light'>  {{#required}}<span class='legoSurveyQuestion_required ipsPos_right'>Required</span>{{/required}}  <strong>Q<span data-role='questionNumber'>{{questionNumber}}</span>:</strong> &nbsp;&nbsp;  {{questionTitle}} </h1> <div class='legoQuestionRendered'>  {{{questionContent}}}  <div class='legoQuestionRendered_overlay'>   <ul class='ipsList_inline'>    <li><a href='#' data-role='edit' class='ipsButton ipsButton_medium ipsButton_primary'>Edit Question</a></li>    <li><a href='#' data-role='delete' class='ipsButton ipsButton_medium ipsButton_primary'>Delete Question</a></li>   </ul>   <p class='ipsType_reset ipsType_center ipsType_medium ipsSpacer_top legoSurveyQuestion_drag'>Drag to reorder questions</p>  </div> </div>");ips.templates.set('workgroups.renderChoices'," <ul class='ipsList_reset ipsForm_vertical legoSurveyChoices'>  {{{choices}}} </ul>");ips.templates.set('workgroups.slider'," <div class='ipsPad'>  <input class='legoQuestionSlider slider' type='range' min='{{start}} max='{{end}}' step='{{step}}' value='{{value}}'>  <div class='ipsGrid ipsSpacer_top'>   <div class='ipsGrid_span4 ipsType_left'>    <span class='ipsType_sectionHead'>{{startLabel}}</span>   </div>   <div class='ipsGrid_span4 ipsType_center'>    <span class='ipsType_sectionHead'>{{centerLabel}}</span>   </div>   <div class='ipsGrid_span4 ipsType_right'>    <span class='ipsType_sectionHead'>{{endLabel}}</span>   </div>  </div> </div>");ips.templates.set('workgroups.upload'," <div class='ipsAttachment_dropZone ipsClearfix'>  <i class='fa fa-cloud-upload'></i>  <span class='ipsAttachment_supportDrag' style='display: inline;'>Drag and drop your file here, or<br></span>  <a href='#' data-action='uploadFile' class='ipsButton ipsButton_verySmall ipsButton_primary' id=''>Choose Single File...</a> </div>");ips.templates.set('workgroups.textinput'," {{#multi}}  <input type='text' placeholder='{{placeholder}}'> {{/multi}} {{^multi}}  <textarea placeholder='{{placeholder}}'></textarea> {{/multi}}");ips.templates.set('workgroups.select'," <select>  <option value='' selected disabled>Choose...</option> </select>");ips.templates.set('workgroups.radiosChoice'," <li class='ipsFieldRow ipsFieldRow_checkbox'>  <span class='ipsCustomInput'>   <input type='radio'>   <span></span>  </span>  <div class='ipsFieldRow_content'>   {{choice}}  </div> </li>");ips.templates.set('workgroups.checkboxesChoice'," <li class='ipsFieldRow ipsFieldRow_checkbox'>  <span class='ipsCustomInput'>   <input type='checkbox'>   <span></span>  </span>  <div class='ipsFieldRow_content'>   {{choice}}  </div> </li>");ips.templates.set('workgroups.otherChoice'," <li class='ipsFieldRow ipsFieldRow_checkbox'>  <span class='ipsCustomInput'>   <input type='{{type}}'>   <span></span>  </span>  <div class='ipsFieldRow_content'>   <strong>Other</strong> (please specify):<br>   <input type='text' class='ipsSpacer_top ipsSpacer_half'>  </div> </li>");ips.templates.set('workgroups.multiTextChoice'," <li class='ipsDataList ipsDataList_reducedSpacing'>  <div class='ipsDataItem'>   <div class='ipsDataItem_generic ipsDataItem_size6'>    <p class='ipsType_reset ipsPad_half ipsType_normal'>{{choice}}</p>   </div>   <div class='ipsDataItem_main'>    {{#multi}}     <textarea placeholder='{{placeholder}}'></textarea>    {{/multi}}    {{^multi}}     <input type='text' placeholder='{{placeholder}}'>    {{/multi}}   </div>  </div> </li>");;
;(function($,_,undefined){"use strict";ips.controller.register('workgroups.front.survey.builder',{_hasNewQuestion:false,_questionData:{},initialize:function(){this.on('click','[data-action="addQuestion"]',this.addQuestion);this.on('survey.cancelNewQuestion',this.cancelNewQuestion);this.on('survey.saveQuestion',this.saveQuestion);this.on('survey.deleteQuestion',this.deleteQuestion);this.on('survey.rehydrateData',this.rehydrateData);this.setup();},setup:function(){this._questionContainer=this.scope.find('[data-role="questionContainer"]');this._newQuestionContainer=this.scope.find('[data-role="newQuestionContainer"]');this._setUpDragging();this.trigger('survey.builderReady');},rehydrateData:function(e,data){if(!data.data.length){return;}
ips.controller.cleanContentsOf(this._questionContainer);this._questionContainer.html('').hide();var questionCount=0;var ids=[];for(var i=0;i<data.data.length;i++){var id=this._makeID();this._questionContainer.append(ips.templates.render('workgroups.question',{questionNumber:(questionCount+1),id:id})).show();this._questionData[id]=data.data[i];var elem=this.scope.find('[data-questionID="'+id+'"]');$(document).trigger('contentChange',[elem]);elem.trigger('survey.rehydrateQuestion',data.data[i]);}
this._questionContainer.show();this._updateQuestionCounts();this._pushData();},deleteQuestion:function(e,data){if(!_.isUndefined(this._questionData[data.id])){delete this._questionData[data.id];}
this.scope.find('[data-questionID="'+data.id+'"]').remove();this._updateQuestionCounts();this._pushData();},_setUpDragging:function(){var self=this;ips.loader.get(['core/interface/jquery/jquery-ui.js']).then(function(){self._questionContainer.css({zIndex:ips.ui.zIndex(),}).sortable({stop:_.bind(self._stopDragging,self)});});},_stopDragging:function(){this._updateQuestionCounts();this._pushData();},saveQuestion:function(e,data){var id=data.id;var question=this.scope.find('[data-questionID="'+id+'"]');if(question.closest('[data-role="newQuestionContainer"]').length){question.appendTo(this._questionContainer);this._hasNewQuestion=false;this.scope.find('[data-role="addQuestionContainer"]').show();}
this._updateQuestionCounts();this._questionData[data.id]=data.data;this._pushData();Debug.log('Received data from question:');Debug.log(data.data);},_updateQuestionCounts:function(){var questions=this._questionContainer.find('[data-questionNumber]');questions.each(function(idx){$(this).trigger('survey.updateQuestionNumber',{number:(idx+1)});});},cancelNewQuestion:function(){this._hasNewQuestion=false;this._newQuestionContainer.html('');this.scope.find('[data-role="addQuestionContainer"]').show();},addQuestion:function(e){e.preventDefault();var self=this;var questionCount=this._questionContainer.find('> li').length;var _doAddQuestion=function(){self._newQuestionContainer.html(ips.templates.render('workgroups.question',{questionNumber:(questionCount+1),id:self._makeID()})).show();self._hasNewQuestion=true;self.scope.find('[data-role="addQuestionContainer"]').hide();$(document).trigger('contentChange',[self._newQuestionContainer]);};if(this._hasNewQuestion){ips.ui.alert.show({type:'confirm',message:'Add a new question without saving the current question?',icon:'question',callbacks:{ok:function(){_doAddQuestion();}}});}else{_doAddQuestion();}},removeNewQuestion:function(e){this._newQuestionContainer.html('').hide();this._hasNewQuestion=false;},_makeID:function(){return'e'+Math.ceil(Math.random()*10000000);},_pushData:function(){var self=this;var questionOrder=this._questionContainer.find('[data-questionNumber]');var data=[];questionOrder.each(function(){var id=$(this).attr('data-questionID');if(!_.isUndefined(self._questionData[id])){data.push(Object.assign({},self._questionData[id]));}});this.trigger('survey.updateData',{data:data});}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('workgroups.front.survey.question',{_questionType:null,_dirty:false,_viewState:'edit',_newQuestion:true,_id:0,_data:{options:{}},initialize:function(){this.on('click','[data-role="questionType"]',this.chooseQuestionType);this.on('focus','[data-role="choices"] li:last-child input[type="text"][data-role="choice"]',this.focusChoice);this.on('click','[data-role="addChoice"]',this.addChoice);this.on('click','[data-role="removeChoice"]',this.removeChoice);this.on('click','[data-role="cancel"]',this.cancelQuestion);this.on('click','[data-role="save"]',this.saveQuestion);this.on('click','[data-role="delete"]',this.deleteQuestion);this.on('click','[data-role="edit"]',this.editQuestion);this.on('change','[data-role="questionTitle"], [data-role="choice"]',this.dirtyQuestion);this.on('survey.updateQuestionNumber',this.updateQuestionNumber);this.on('survey.rehydrateQuestion',this.rehydrateQuestion);this.setup();},setup:function(){this._id=this.scope.attr('data-questionID');},destruct:function(){},rehydrateQuestion:function(e,data){e.stopPropagation();this._data=data;this._viewState='view';this._questionType=data.questionType;this._renderQuestion();},editQuestion:function(e){e.preventDefault();this._viewState='edit';this._renderEditor();},deleteQuestion:function(e){e.preventDefault();var self=this;ips.ui.alert.show({type:'confirm',message:'Are you sure you want to delete this question?',icon:'question',callbacks:{ok:function(){self.scope.slideUp('fast');self.scope.fadeOut(function(){self.trigger('survey.deleteQuestion',{id:self._id});self.cleanContents();});}}});},updateQuestionNumber:function(e,data){e.stopPropagation();this.scope.find('[data-role="questionNumber"]').text(data.number);this.scope.attr('data-questionNumber',data.number);},dirtyQuestion:function(){this._dirty=true;},saveQuestion:function(e){e.preventDefault();if(!this._validateData()){return;}
this._buildData();this._viewState='view';this._newQuestion=false;this._renderQuestion();this.trigger('survey.saveQuestion',{id:this._id,data:this._data});},cancelQuestion:function(e){e.preventDefault();var self=this;var _doRemoveQuestion=function(){self.scope.slideUp('fast',function(){self.trigger('survey.cancelNewQuestion');});};if(this._dirty){ips.ui.alert.show({type:'confirm',message:'Are you sure you want to remove this question without saving?',icon:'question',callbacks:{ok:function(){_doRemoveQuestion();}}});}else{_doRemoveQuestion();}},removeChoice:function(e){e.preventDefault();if(this.scope.find('[data-role="choices"] > li').length==1){return;}
$(e.currentTarget).closest('li').remove();this._recountChoices();},addChoice:function(e){e.preventDefault();var count=this.scope.find('[data-role="choices"] > li').length;var dummyControl=this._getDummyControl();var control=ips.templates.render('workgroups.choicesItems',{id:count+1,dummyControl:dummyControl,placeholder:(this._questionType!=='multiText')?'Answer':'Label Title'});$(e.currentTarget).closest('li').after(control);this._recountChoices();},focusChoice:function(e){var count=this.scope.find('[data-role="choices"] > li').length;var dummyControl=this._getDummyControl();var control=ips.templates.render('workgroups.choicesItems',{id:count+1,dummyControl:dummyControl,placeholder:(this._questionType!=='multiText')?'Answer':'Label Title'});this.scope.find('[data-role="choices"]').append(control);},chooseQuestionType:function(e){e.preventDefault();var choice=$(e.currentTarget);this._questionType=choice.attr('data-type');this._renderEditor();},_getDummyControl:function(){var dummyControl='';if(this._questionType=='radios'){dummyControl=ips.templates.render('workgroups.dummyRadio');}else if(this._questionType=='checkboxes'){dummyControl=ips.templates.render('workgroups.dummyCheckbox');}
return dummyControl;},_getPlaceholder:function(){var placeholder='';if(this._questionType=='text'||this._questionType=='multiText'){if(this._data.options.format=='number'){placeholder='e.g. 1234';}else if(this._data.options.format=='email'){placeholder='e.g. test@example.com';}else if(this._data.options.format=='url'){placeholder='e.g. http://www.example.com';}}
return placeholder;},_typeHasChoices:function(){return(this._questionType=='radios'||this._questionType=='checkboxes'||this._questionType=='select'||this._questionType=='multiText');},_recountChoices:function(){var choices=this.scope.find('[data-role="choices"] > li');choices.each(function(idx){$(this).find('[data-role="choiceNumber"]').text(parseInt(idx)+1);});},_buildOptions:function(){if(this._questionType=='text'||this._questionType=='multiText'){return ips.templates.render('workgroups.textOptions',{id:this._id,multiLine:this._data.options.multiLine||false,textFormat:this._data.options.format||false,format:{number:this._data.options.format=='number'||false,email:this._data.options.format=='email'||false,url:this._data.options.format=='url'||false},wholeNumbers:this._data.options.wholeNumbers||true,limitLength:(!_.isUndefined(this._data.options.minLen)&&!_.isUndefined(this._data.options.maxLen))||false,minLen:this._data.options.minLen||0,maxLen:this._data.options.maxLen||300});}else if(this._questionType=='radios'||this._questionType=='checkboxes'){return ips.templates.render('workgroups.radioCheckOptions',{id:this._id,allowOther:this._data.options.allowOther||false});}else if(this._questionType=='slider'){return ips.templates.render('workgroups.sliderOptions',{id:this._id,start:this._data.options.start||0,end:this._data.options.end||10,step:this._data.options.step||1,startPos:this._data.options.startPos||'center'});}else if(this._questionType=='upload'){return ips.templates.render('workgroups.uploadOptions',{id:this._id,imagesOnly:this._data.options.imagesOnly||true});}
return'';},_buildChoices:function(){var choices=[];if(!this._typeHasChoices()&&this._questionType!=='slider'){return'';}
if(this._questionType=='slider'){choices.push(ips.templates.render('workgroups.sliderChoices',{startLabel:this._data.options.startLabel||this._data.options.start||0,centerLabel:this._data.options.centerLabel||'',endLabel:this._data.options.endLabel||this._data.options.end||10}));}else{var dummyControl=this._getDummyControl();var placeholder=(this._questionType!=='multiText')?'Answer':'Label Title';if(!_.isUndefined(this._data.choices)&&_.size(this._data.choices)){_.each(this._data.choices,function(choice,idx){choices.push(ips.templates.render('workgroups.choicesItems',{id:(idx+1),dummyControl:dummyControl,placeholder:placeholder,value:choice}));});choices.push(ips.templates.render('workgroups.choicesItems',{id:_.size(this._data.choices)+1,dummyControl:dummyControl,placeholder:placeholder,value:''}));}else{for(var i=1;i<=4;i++){choices.push(ips.templates.render('workgroups.choicesItems',{id:i,dummyControl:dummyControl,placeholder:placeholder,value:''}));}}}
return ips.templates.render('workgroups.choices',{choices:choices.join('')});},_setUpDragging:function(){var self=this;ips.loader.get(['core/interface/jquery/jquery-ui.js']).then(function(){self.scope.find('[data-role="choices"]').css({zIndex:ips.ui.zIndex(),}).sortable({dragHandle:'.legoQuestionChoices_number',scroll:true,stop:_.bind(self._recountChoices,self)});});},_validateData:function(){var self=this;if($.trim(this.scope.find('[data-role="questionTitle"]').val())==''){ips.ui.alert.show({type:'alert',message:'You must enter a question title.',icon:'warn',callbacks:{ok:function(){self.scope.find('[data-role="questionTitle"]').focus();}}});return false;}
if(this._typeHasChoices()){var choices=this.scope.find('[data-role="choice"]');var hasChoiceText=false;choices.each(function(){if($.trim($(this).val())!==''){hasChoiceText=true;return false;}});if(!hasChoiceText){ips.ui.alert.show({type:'alert',message:(this._questionType=='multiText')?'You must enter a label for at least one field.':'You must enter at least one choice.',icon:'warn',callbacks:{ok:function(){self.scope.find('[data-role="choice"]').first().focus();}}});return false;}}
if(this._questionType=='text'||this._questionType=='multiText'){if(!this.scope.find('[data-role="multiLine"]').is(':checked')&&this.scope.find('[data-role="limitLength"]').is(':checked')){var min=$.trim(this.scope.find('[data-role="minLength"]').val());var max=$.trim(this.scope.find('[data-role="maxLength"]').val());if(min===''||max===''){ips.ui.alert.show({type:'alert',message:'The min and max length fields must be completed since you have checked the "Limit Length" option.',icon:'warn',callbacks:{ok:function(){self.scope.find('[data-role="minLength"]').focus();}}});return false;}}}
if(this._questionType=='slider'){var start=parseInt($.trim(this.scope.find('[data-role="start"]').val()));var end=parseInt($.trim(this.scope.find('[data-role="end"]').val()));var step=parseInt($.trim(this.scope.find('[data-role="step"]').val()));if(!_.isNumber(start)||!_.isNumber(end)||!_.isNumber(step)){ips.ui.alert.show({type:'alert',message:'Please ensure you have provided a start and end value, and a step value.',icon:'warn',callbacks:{ok:function(){self.scope.find('[data-role="start"]').focus();}}});return false;}}
return true;},_buildData:function(){var data={};data['questionTitle']=$.trim(this.scope.find('[data-role="questionTitle"]').val());data['questionType']=this._questionType;if(this._typeHasChoices()){data['choices']=[];var choices=this.scope.find('[data-role="choice"]');choices.each(function(){var val=$.trim($(this).val());if(val!==''){data['choices'].push(val);}});}
data['options']={required:this.scope.find('[data-role="required"]').is(':checked')};if(this._questionType=='radios'||this._questionType=='checkboxes'){data['options']['addOther']=this.scope.find('[data-role="allowOther"]').is(':checked');}
if(this._questionType=='text'||this._questionType=='multiText'){if(this.scope.find('[data-role="multiLine"]').is(':checked')){data['options']['multiLine']=true;}else if(this.scope.find('[data-role="textFormat"]').is(':checked')){data['options']['format']=this.scope.find('[data-role="textFormatChoice"]').val();if(data['options']['format']=='number'){data['options']['wholeNumbers']=this.scope.find('[data-role="wholeNumbers"]').is(':checked');}}else if(this.scope.find('[data-role="limitLength"]').is(':checked')){data['options']['minLen']=this.scope.find('[data-role="minLength"]').val();data['options']['maxLen']=this.scope.find('[data-role="maxLength"]').val();}}
if(this._questionType=='slider'){data['options']['start']=this.scope.find('[data-role="start"]').val();data['options']['end']=this.scope.find('[data-role="end"]').val();data['options']['step']=this.scope.find('[data-role="step"]').val();data['options']['startLabel']=(this.scope.find('[data-role="startLabel"]').val())?this.scope.find('[data-role="startLabel"]').val():data['options']['start'];data['options']['endLabel']=(this.scope.find('[data-role="endLabel"]').val())?this.scope.find('[data-role="endLabel"]').val():data['options']['end'];data['options']['centerLabel']=this.scope.find('[data-role="centerLabel"]').val();data['options']['startPos']=this.scope.find('[data-role="startPos"]').val();}
if(this._questionType=='upload'){data['options']['imagesOnly']=this.scope.find('[data-role="imagesOnly"]').is(':checked');}
this._data=data;return data;},_renderQuestion:function(){var self=this;if(!this._data){this._buildData();}
var control;if(this._questionType=='text'){control=ips.templates.render('workgroups.textinput',{multi:_.isUndefined(this._data.options.multiLine),placeholder:this._getPlaceholder()});}else if(this._questionType=='select'){control=ips.templates.render('workgroups.select',{});}else if(this._questionType=='slider'){control=ips.templates.render('workgroups.slider',this._data.options);}else if(this._questionType=='upload'){control=ips.templates.render('workgroups.upload',this._data.options);}else if(this._typeHasChoices()&&this._data.choices.length){var choices=[];_.each(this._data.choices,function(choice){choices.push(ips.templates.render('workgroups.'+self._questionType+'Choice',{choice:choice,multi:(self._questionType=='multiText'&&!_.isUndefined(self._data.options.multiLine)),placeholder:self._getPlaceholder()}));});if(this._data.options.addOther){choices.push(ips.templates.render('workgroups.otherChoice',{type:(this._questionType=='checkboxes')?'checkbox':'radio'}));}
control=ips.templates.render('workgroups.renderChoices',{choices:choices.join('')});}
var html=ips.templates.render('workgroups.renderQuestion',{questionTitle:this._data.questionTitle,questionContent:control,required:this._data.options.required||false});this.scope.html(html).addClass('legoSurveyQuestion_rendered');$(document).trigger('contentChange',[this.scope]);},_renderEditor:function(){var content=this._buildChoices();var options=this._buildOptions();this.scope.html(ips.templates.render('workgroups.questionBody',{content:content,options:options,questionTitle:this._data.questionTitle||'',questionNumber:this.scope.attr('data-questionNumber'),required:this._data.options.required||false,id:this._id,hasBody:(content||options),newQuestion:this._newQuestion}));$(document).trigger('contentChange',[this.scope]);if(this._typeHasChoices()){this._setUpDragging();}
this.scope.removeClass('legoSurveyQuestion_rendered');this.scope.find('[data-role="questionTitle"]').focus();},});}(jQuery,_));;