;(function($,_,undefined){"use strict";ips.controller.register('workgroups.front.respond.main',{initialize:function(){this.on('change','#elEnableSurvey',this.toggleSurvey);this.on('change','#elEnableDiscussions',this.toggleDiscussions);this.on('survey.updateData',this.updateData);this.on('click','[data-action="publish"], [data-action="save"]',this.submitForm);this.on('submit','#elRespondForm',this.handleSubmitForm);this.on('survey.builderReady',this.builderReady);this.setup();},setup:function(){},builderReady:function(){if($.trim(this.scope.find('[name="surveyJSON"]').val())!==''){this.triggerOn('workgroups.front.survey.builder','survey.rehydrateData',{data:JSON.parse(this.scope.find('[name="surveyJSON"]').val())});}},handleSubmitForm:function(e){var form=$(e.currentTarget);if(!form.attr('data-allowSubmit')){e.preventDefault();}},submitForm:function(e){var form=this.scope.find('#elRespondForm');e.preventDefault();if($(e.currentTarget).is('[data-action="publish"]')){if(form.find('[name="saveProgress"]').length){form.find('[name="saveProgress"]').remove();}
e.preventDefault();ips.ui.alert.show({type:'confirm',message:'Are you sure you want to open the Response stage of this workgroup to participants?',subText:"Once this stage opens to participants, you won't be able to edit your survey questions.",icon:'question',buttons:{ok:'Continue',cancel:'Cancel'},callbacks:{ok:function(){form.attr('data-allowSubmit',true);form.submit();}}});}else{form.attr('data-allowSubmit',true).append("<input type='hidden' name='saveProgress' value='1'>").submit();}},updateData:function(e,data){this.scope.find('[name="surveyJSON"]').val(JSON.stringify(data.data));},toggleDiscussions:function(e){e.preventDefault();if($(e.currentTarget).is(':checked')){this.scope.find('[data-role="discussions"]').fadeIn().slideDown();}else{this.scope.find('[data-role="discussions"]').fadeOut().slideUp();}},toggleSurvey:function(e){e.preventDefault();if($(e.currentTarget).is(':checked')){this.scope.find('[data-role="surveyBuilder"]').fadeIn().slideDown();}else{this.scope.find('[data-role="surveyBuilder"]').fadeOut().slideUp();}}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('workgroups.front.respond.toggleSection',{initialize:function(){this.on('change','[data-role="toggleSection"]',this.toggle);this.setup();},setup:function(){},toggle:function(){ips.getAjax()(this.scope.attr('action'),{data:this.scope.serialize()});}});}(jQuery,_));;