ips.templates.set('forms.question'," <li class='legoFormsQuestion ipsBox ipsBox_transparent' data-controller='forms.admin.form.question' data-questionNumber='{{questionNumber}}' data-questionID='{{id}}'>  <ul class='legoFormsQuestionTypes 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('forms.questionBody'," <div>  <div class='legoQuestionHeader ipsAreaBackground_light ipsPad'>   <h2 class='ipsType_reset'>Q{{questionNumber}}:</h2>   <input type='text' class='legoFormsQuestionTitle' 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('forms.choices'," <ul class='legoQuestionChoices' data-role='choices'>  {{{choices}}} </ul>");ips.templates.set('forms.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('forms.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('forms.dummyCheckbox'," <span class='ipsCustomInput legoQuestionChoices_dummyControl'>  <input type='checkbox'>  <span></span> </span>");ips.templates.set('forms.dummyRadio'," <span class='ipsCustomInput legoQuestionChoices_dummyControl'>  <input type='radio'>  <span></span> </span>");ips.templates.set('forms.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('forms.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('forms.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> {{#isCheckbox}}  <li class='ipsFieldRow ipsFieldRow_checkbox' id='numChoicesToggleRow_{{id}}'>   <span class='ipsCustomInput'>    <input type='checkbox' id='numChoicesToggle_{{id}}' {{#hasLimit}}checked{{/hasLimit}} data-role='limitChoices' data-control='toggle' data-toggles='limitChoices_{{id}}'>    <span></span>   </span>   <div class='ipsFieldRow_content'>    <label for='numChoicesToggle_{{id}}'>Limit number of selected choices</label>   </div>  </li>  <li class='ipsFieldRow ipsFieldRow_checkbox ipsSpacer_top ipsSpacer_half' id='limitChoices_{{id}}'>   <div class='ipsFieldRow_content'>    Number of choices to allow: <select id='limit_choices_{{id}}' data-role='limitChoicesNum'>{{{limitOptions}}}</select>   </div>  </li> {{/isCheckbox}}");ips.templates.set('forms.checkboxLimitOption'," <option value='{{number}}' {{#selected}}selected{{/selected}}>{{number}}</option>");ips.templates.set('forms.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('forms.renderQuestion'," <h1 class='ipsType_pageTitle legoFormsQuestion_title ipsAreaBackground_light'>  {{#required}}<span class='legoFormsQuestion_required ipsPos_right'>Required</span>{{/required}}  <strong>Q<span data-role='questionNumber'>{{questionNumber}}</span>:</strong> &nbsp;&nbsp;  {{questionTitle}} </h1> <div class='legoQuestionRendered'>  {{{questionContent}}}  {{#questionFooter}}   <p class='ipsType_reset ipsSpacer_top ipsType_light'>{{questionFooter}}</p>  {{/questionFooter}}  <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 legoFormsQuestion_drag'>Drag to reorder questions</p>  </div> </div>");ips.templates.set('forms.renderChoices'," <ul class='ipsList_reset ipsForm_vertical legoFormsChoices'>  {{{choices}}} </ul>");ips.templates.set('forms.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('forms.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('forms.textinput'," {{#multi}}  <input type='text' placeholder='{{placeholder}}'> {{/multi}} {{^multi}}  <textarea placeholder='{{placeholder}}'></textarea> {{/multi}}");ips.templates.set('forms.select'," <select>  <option value='' selected disabled>Choose...</option> </select>");ips.templates.set('forms.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('forms.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('forms.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('forms.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('forms.admin.form.builder',{_hasNewQuestion:false,_questionData:{},initialize:function(){this.on('click','[data-action="addQuestion"]',this.addQuestion);this.on('form.cancelNewQuestion',this.cancelNewQuestion);this.on('form.saveQuestion',this.saveQuestion);this.on('form.deleteQuestion',this.deleteQuestion);this.on(document,'click','[data-action="saveFieldConfig"]',this.saveForm);this.setup();},setup:function(){this._questionContainer=this.scope.find('[data-role="questionContainer"]');this._newQuestionContainer=this.scope.find('[data-role="newQuestionContainer"]');this._setUpDragging();var existingVal=$('body').find('input[name="fieldJSON"]').val();if(existingVal!==''){this.rehydrateData(existingVal);}
this.trigger('form.builderReady');},saveForm:function(e){e.preventDefault();$('body').find('[data-role="fieldConfigForm"]').submit();},rehydrateData:function(existingVal){try{var data=JSON.parse(existingVal);}catch(err){return;}
ips.controller.cleanContentsOf(this._questionContainer);this._questionContainer.html('').hide();var questionCount=0;var ids=[];var self=this;var questions=_.sortBy(_.values(data),function(question){return parseInt(question.field_position);});_.each(questions,function(question){var key=question.field_id;self._questionContainer.append(ips.templates.render('forms.question',{questionNumber:(questionCount+1),id:key})).show();self._questionData[key]=question;var elem=self.scope.find('[data-questionID="'+key+'"]');$(document).trigger('contentChange',[elem]);elem.trigger('form.rehydrateQuestion',question);});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('form.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('forms.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]));}});$('body').find('input[name="fieldJSON"]').val(JSON.stringify(data));}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('forms.admin.form.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('change','[data-role="limitChoicesNum"]',this.changeLimitChoices);this.on('blur','[data-role="choice"]',this.checkChoiceText);this.on('form.updateQuestionNumber',this.updateQuestionNumber);this.on('form.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;if(!_.isUndefined(this._data.field_options)&&this._data.field_options!==null){this._data.field_options=JSON.parse(this._data.field_options||{});}
if(!_.isUndefined(this._data.field_choices)&&this._data.field_choices!==null){this._data.field_choices=JSON.parse(this._data.field_choices||[]);}
this._viewState='view';this._questionType=data.field_type;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('form.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('form.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('form.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();this._buildCheckboxLimitOption();},addChoice:function(e){e.preventDefault();var count=this.scope.find('[data-role="choices"] > li').length;var dummyControl=this._getDummyControl();var control=ips.templates.render('forms.choicesItems',{id:count+1,dummyControl:dummyControl,placeholder:(this._questionType!=='multiText')?'Answer':'Label Title'});$(e.currentTarget).closest('li').after(control);this._recountChoices();},changeLimitChoices:function(e){if(this._questionType!=="checkboxes"){return;}
if(_.isUndefined(this._data.field_options)){this._data.field_options={};}
this._data.field_options.limitChoices=this.scope.find('[data-role="limitChoicesNum"]').val();},checkChoiceText:function(e){if(this._questionType!=="checkboxes"){return;}
this._buildCheckboxLimitOption();},focusChoice:function(e){var count=this.scope.find('[data-role="choices"] > li').length;var dummyControl=this._getDummyControl();var control=ips.templates.render('forms.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('forms.dummyRadio');}else if(this._questionType=='checkboxes'){dummyControl=ips.templates.render('forms.dummyCheckbox');}
return dummyControl;},_getPlaceholder:function(){var placeholder='';if(this._questionType=='text'||this._questionType=='multiText'){if(this._data.field_options.format=='number'){placeholder='e.g. 1234';}else if(this._data.field_options.format=='email'){placeholder='e.g. test@example.com';}else if(this._data.field_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(){var options=this._data.field_options;var optionsIsDefined=!_.isUndefined(options);if(this._questionType=='text'||this._questionType=='multiText'){return ips.templates.render('forms.textOptions',{id:this._id,multiLine:(optionsIsDefined&&options.multiLine)||false,textFormat:(optionsIsDefined&&options.format)||false,format:{number:(optionsIsDefined&&options.format=='number')||false,email:(optionsIsDefined&&options.format=='email')||false,url:(optionsIsDefined&&options.format=='url')||false},wholeNumbers:(optionsIsDefined&&!_.isUndefined(options.wholeNumbers))?options.wholeNumbers:true,limitLength:(optionsIsDefined&&!_.isUndefined(options.minLen)&&!_.isUndefined(options.maxLen))||false,minLen:(optionsIsDefined&&options.minLen)?options.minLen:0,maxLen:(optionsIsDefined&&options.maxLen)?options.maxLen:300});}else if(this._questionType=='radios'||this._questionType=='checkboxes'){return ips.templates.render('forms.radioCheckOptions',{id:this._id,allowOther:(optionsIsDefined&&options.addOther)||false,isCheckbox:this._questionType=='checkboxes',hasLimit:(optionsIsDefined&&options.limitChoices)||false});}else if(this._questionType=='slider'){return ips.templates.render('forms.sliderOptions',{id:this._id,start:(optionsIsDefined&&options.start)?options.start:0,end:(optionsIsDefined&&options.end)?options.end:10,step:(optionsIsDefined&&options.step)?options.step:1,startPos:(optionsIsDefined&&options.startPos)?options.startPos:'center'});}else if(this._questionType=='upload'){return ips.templates.render('forms.uploadOptions',{id:this._id,imagesOnly:(optionsIsDefined&&!_.isUndefined(options.imagesOnly))?options.imagesOnly:true});}
return'';},_buildChoices:function(){var choices=[];var options=this._data.field_options;var optionsIsDefined=!_.isUndefined(options);if(!this._typeHasChoices()&&this._questionType!=='slider'){return'';}
if(this._questionType=='slider'){choices.push(ips.templates.render('forms.sliderChoices',{startLabel:(optionsIsDefined&&!_.isUndefined(options.startLabel))?options.startLabel:(optionsIsDefined&&!_.isUndefined(options.start)?options.start:0),centerLabel:(optionsIsDefined&&!_.isUndefined(options.centerLabel))?options.centerLabel:'',endLabel:(optionsIsDefined&&!_.isUndefined(options.endLabel))?options.endLabel:(optionsIsDefined&&!_.isUndefined(options.end)?options.end:10)}));}else{var dummyControl=this._getDummyControl();var placeholder=(this._questionType!=='multiText')?'Answer':'Label Title';if(!_.isUndefined(this._data.field_choices)&&_.size(this._data.field_choices)){_.each(this._data.field_choices,function(choice,idx){choices.push(ips.templates.render('forms.choicesItems',{id:(idx+1),dummyControl:dummyControl,placeholder:placeholder,value:choice}));});choices.push(ips.templates.render('forms.choicesItems',{id:_.size(this._data.field_choices)+1,dummyControl:dummyControl,placeholder:placeholder,value:''}));}else{for(var i=1;i<=4;i++){choices.push(ips.templates.render('forms.choicesItems',{id:i,dummyControl:dummyControl,placeholder:placeholder,value:''}));}}}
return ips.templates.render('forms.choices',{choices:choices.join('')});},_buildCheckboxLimitOption:function(){var choiceCount=0;var choiceHtml=[];var choices=this.scope.find('[data-role="choice"]');if(choices.length){_.each(choices,function(choice){if($.trim($(choice).val())!==''){choiceCount++;}});}
for(var i=1;i<=choiceCount;i++){choiceHtml.push(ips.templates.render('forms.checkboxLimitOption',{number:i,selected:!_.isUndefined(this._data.field_options)&&!_.isUndefined(this._data.field_options.limitChoices)&&parseInt(this._data.field_options.limitChoices)===i}));}
this.scope.find('[data-role="limitChoicesNum"]').html(choiceHtml.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=$.extend(true,{},this._data||{});data['field_title']=$.trim(this.scope.find('[data-role="questionTitle"]').val());data['field_type']=this._questionType;if(this._typeHasChoices()){data['field_choices']=[];var choices=this.scope.find('[data-role="choice"]');choices.each(function(){var val=$.trim($(this).val());if(val!==''){data['field_choices'].push(val);}});}
data['field_options']={required:this.scope.find('[data-role="required"]').is(':checked')};if(this._questionType=='radios'||this._questionType=='checkboxes'){data['field_options']['addOther']=this.scope.find('[data-role="allowOther"]').is(':checked');}
if(this._questionType=='checkboxes'){if(this.scope.find('[data-role="limitChoices"]').is(':checked')){data['field_options']['limitChoices']=this.scope.find('[data-role="limitChoicesNum"]').val()}else{data['field_options']['limitChoices']=null;}}
if(this._questionType=='text'||this._questionType=='multiText'){if(this.scope.find('[data-role="multiLine"]').is(':checked')){data['field_options']['multiLine']=true;}else if(this.scope.find('[data-role="textFormat"]').is(':checked')){data['field_options']['format']=this.scope.find('[data-role="textFormatChoice"]').val();if(data['field_options']['format']=='number'){data['field_options']['wholeNumbers']=this.scope.find('[data-role="wholeNumbers"]').is(':checked');}}else if(this.scope.find('[data-role="limitLength"]').is(':checked')){data['field_options']['minLen']=this.scope.find('[data-role="minLength"]').val();data['field_options']['maxLen']=this.scope.find('[data-role="maxLength"]').val();}}
if(this._questionType=='slider'){data['field_options']['start']=this.scope.find('[data-role="start"]').val();data['field_options']['end']=this.scope.find('[data-role="end"]').val();data['field_options']['step']=this.scope.find('[data-role="step"]').val();data['field_options']['startLabel']=(this.scope.find('[data-role="startLabel"]').val())?this.scope.find('[data-role="startLabel"]').val():data['field_options']['start'];data['field_options']['endLabel']=(this.scope.find('[data-role="endLabel"]').val())?this.scope.find('[data-role="endLabel"]').val():data['field_options']['end'];data['field_options']['centerLabel']=this.scope.find('[data-role="centerLabel"]').val();data['field_options']['startPos']=this.scope.find('[data-role="startPos"]').val();}
if(this._questionType=='upload'){data['field_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;var questionFooter;if(this._questionType=='text'){control=ips.templates.render('forms.textinput',{multi:_.isUndefined(this._data.field_options.multiLine),placeholder:this._getPlaceholder()});}else if(this._questionType=='select'){control=ips.templates.render('forms.select',{});}else if(this._questionType=='slider'){control=ips.templates.render('forms.slider',this._data.field_options);}else if(this._questionType=='upload'){control=ips.templates.render('forms.upload',this._data.field_options);}else if(this._typeHasChoices()&&this._data.field_choices.length){var choices=[];_.each(this._data.field_choices,function(choice){choices.push(ips.templates.render('forms.'+self._questionType+'Choice',{choice:choice,multi:(self._questionType=='multiText'&&!_.isUndefined(self._data.field_options.multiLine)),placeholder:self._getPlaceholder()}));});if(this._data.field_options.addOther){choices.push(ips.templates.render('forms.otherChoice',{type:(this._questionType=='checkboxes')?'checkbox':'radio'}));}
control=ips.templates.render('forms.renderChoices',{choices:choices.join('')});}
if(this._questionType=='checkboxes'&&this._data.field_options.limitChoices){questionFooter=ips.pluralize(ips.getString('selectNumChoices'),[this._data.field_options.limitChoices]);}
var html=ips.templates.render('forms.renderQuestion',{questionTitle:this._data.field_title,questionContent:control,questionFooter:questionFooter,required:this._data.field_options.required||false});this.scope.html(html).addClass('legoFormsQuestion_rendered');$(document).trigger('contentChange',[this.scope]);},_renderEditor:function(){var content=this._buildChoices();var options=this._buildOptions();this.scope.html(ips.templates.render('forms.questionBody',{content:content,options:options,questionTitle:this._data.field_title||'',questionNumber:this.scope.attr('data-questionNumber'),required:!_.isUndefined(this._data.field_options)&&this._data.field_options.required,id:this._id,hasBody:(content||options),newQuestion:this._newQuestion}));$(document).trigger('contentChange',[this.scope]);if(this._questionType){this._buildCheckboxLimitOption();}
if(this._typeHasChoices()){this._setUpDragging();}
this.scope.removeClass('legoFormsQuestion_rendered');this.scope.find('[data-role="questionTitle"]').focus();},});}(jQuery,_));;