(function(){rivets.binders.input={publishes:!0,routine:rivets.binders.value.routine,bind:function(a){return a.addEventListener("input",this.publish)},unbind:function(a){return a.removeEventListener("input",this.publish)}},rivets.configure({prefix:"rv",adapter:{subscribe:function(a,b,c){return c.wrapped=function(a,b){return c(b)},a.on("change:"+b,c.wrapped)},unsubscribe:function(a,b,c){return a.off("change:"+b,c.wrapped)},read:function(a,b){return"cid"===b?a.cid:a.get(b)},publish:function(a,b,c){return a.cid?a.set(b,c):a[b]=c}}})}).call(this),function(){var a;a=function(){function a(b,c){null==c&&(c={}),_.extend(this,Backbone.Events),this.mainView=new a.views.main(_.extend({selector:b},c,{formBuilder:this}))}return a.helpers={defaultFieldAttrs:function(b){var c,d;return c={label:"Untitled",field_type:b,required:!0,field_options:{}},("function"==typeof(d=a.fields[b]).defaultAttributes?d.defaultAttributes(c):void 0)||c},simple_format:function(a){return null!=a?a.replace(/\n/g," "):void 0}},a.options={BUTTON_CLASS:"fb-button",HTTP_ENDPOINT:"",HTTP_METHOD:"POST",mappings:{SIZE:"field_options.size",UNITS:"field_options.units",LABEL:"label",FIELD_TYPE:"field_type",REQUIRED:"required",ADMIN_ONLY:"admin_only",OPTIONS:"field_options.options",DESCRIPTION:"field_options.description",INCLUDE_OTHER:"field_options.include_other_option",INCLUDE_BLANK:"field_options.include_blank_option",INTEGER_ONLY:"field_options.integer_only",MIN:"field_options.min",MAX:"field_options.max",MINLENGTH:"field_options.minlength",MAXLENGTH:"field_options.maxlength",LENGTH_UNITS:"field_options.min_max_length_units"},dict:{ALL_CHANGES_SAVED:"All changes saved",SAVE_FORM:"Save form",UNSAVED_CHANGES:"You have unsaved changes. If you leave this page, you will lose those changes!"}},a.fields={},a.inputFields={},a.nonInputFields={},a.model=Backbone.DeepModel.extend({sync:function(){},indexInDOM:function(){var a,b=this;return a=$(".fb-field-wrapper").filter(function(a,c){return $(c).data("cid")===b.cid}),$(".fb-field-wrapper").index(a)},is_input:function(){return null!=a.inputFields[this.get(a.options.mappings.FIELD_TYPE)]}}),a.collection=Backbone.Collection.extend({initialize:function(){return this.on("add",this.copyCidToModel)},model:a.model,comparator:function(a){return a.indexInDOM()},copyCidToModel:function(a){return a.attributes.cid=a.cid}}),a.registerField=function(b,c){var d,e,f,g;for(g=["view","edit"],e=0,f=g.length;f>e;e++)d=g[e],c[d]=_.template(c[d]);return a.fields[b]=c,"non_input"===c.type?a.nonInputFields[b]=c:a.inputFields[b]=c},a.views={view_field:Backbone.View.extend({className:"fb-field-wrapper",events:{"click .subtemplate-wrapper":"focusEditView","click .js-duplicate":"duplicate","click .js-clear":"clear"},initialize:function(){return this.parentView=this.options.parentView,this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"destroy",this.remove)},render:function(){return this.$el.addClass("response-field-"+this.model.get(a.options.mappings.FIELD_TYPE)).data("cid",this.model.cid).html(a.templates["view/base"+(this.model.is_input()?"":"_non_input")]({rf:this.model})),this},focusEditView:function(){return this.parentView.createAndShowEditView(this.model)},clear:function(){return this.parentView.handleFormUpdate(),this.model.destroy()},duplicate:function(){var a;return a=_.clone(this.model.attributes),delete a.id,a.label+=" Copy",this.parentView.createField(a,{position:this.model.indexInDOM()+1})}}),edit_field:Backbone.View.extend({className:"edit-response-field",events:{"click .js-add-option":"addOption","click .js-remove-option":"removeOption","click .js-default-updated":"defaultUpdated","input .option-label-input":"forceRender"},initialize:function(){return this.listenTo(this.model,"destroy",this.remove)},render:function(){return this.$el.html(a.templates["edit/base"+(this.model.is_input()?"":"_non_input")]({rf:this.model})),rivets.bind(this.$el,{model:this.model}),this},remove:function(){return this.options.parentView.editView=void 0,this.options.parentView.$el.find('[href="#addField"]').click(),Backbone.View.prototype.remove.call(this)},addOption:function(b){var c,d,e,f;return c=$(b.currentTarget),d=this.$el.find(".option").index(c.closest(".option")),f=this.model.get(a.options.mappings.OPTIONS)||[],e={label:"",checked:!1},d>-1?f.splice(d+1,0,e):f.push(e),this.model.set(a.options.mappings.OPTIONS,f),this.model.trigger("change:"+a.options.mappings.OPTIONS),this.forceRender()},removeOption:function(b){var c,d,e;return c=$(b.currentTarget),d=this.$el.find(".js-remove-option").index(c),e=this.model.get(a.options.mappings.OPTIONS),e.splice(d,1),this.model.set(a.options.mappings.OPTIONS,e),this.model.trigger("change:"+a.options.mappings.OPTIONS),this.forceRender()},defaultUpdated:function(b){var c;return c=$(b.currentTarget),"checkboxes"!==this.model.get(a.options.mappings.FIELD_TYPE)&&this.$el.find(".js-default-updated").not(c).attr("checked",!1).trigger("change"),this.forceRender()},forceRender:function(){return this.model.trigger("change")}}),main:Backbone.View.extend({SUBVIEWS:[],events:{"click .js-save-form":"saveForm","click .fb-tabs a":"showTab","click .fb-add-field-types a":"addField"},initialize:function(){return this.$el=$(this.options.selector),this.formBuilder=this.options.formBuilder,this.collection=new a.collection,this.collection.bind("add",this.addOne,this),this.collection.bind("reset",this.reset,this),this.collection.bind("change",this.handleFormUpdate,this),this.collection.bind("destroy add reset",this.hideShowNoResponseFields,this),this.collection.bind("destroy",this.ensureEditViewScrolled,this),this.render(),this.collection.reset(this.options.bootstrapData),this.initAutosave()},initAutosave:function(){var b=this;return this.formSaved=!0,this.saveFormButton=this.$el.find(".js-save-form"),this.saveFormButton.attr("disabled",!0).text(a.options.dict.ALL_CHANGES_SAVED),setInterval(function(){return b.saveForm.call(b)},5e3),$(window).bind("beforeunload",function(){return b.formSaved?void 0:a.options.dict.UNSAVED_CHANGES})},reset:function(){return this.$responseFields.html(""),this.addAll()},render:function(){var b,c,d,e;for(this.$el.html(a.templates.page()),this.$fbLeft=this.$el.find(".fb-left"),this.$responseFields=this.$el.find(".fb-response-fields"),this.bindWindowScrollEvent(),this.hideShowNoResponseFields(),e=this.SUBVIEWS,c=0,d=e.length;d>c;c++)b=e[c],new b({parentView:this}).render();return this},bindWindowScrollEvent:function(){var a=this;return $(window).on("scroll",function(){var b,c;if(a.$fbLeft.data("locked")!==!0)return c=Math.max(0,$(window).scrollTop()),b=a.$responseFields.height(),a.$fbLeft.css({"margin-top":Math.min(b,c)})})},showTab:function(a){var b,c,d;return b=$(a.currentTarget),d=b.data("target"),b.closest("li").addClass("active").siblings("li").removeClass("active"),$(d).addClass("active").siblings(".fb-tab-pane").removeClass("active"),"#editField"!==d&&this.unlockLeftWrapper(),"#editField"===d&&!this.editView&&(c=this.collection.models[0])?this.createAndShowEditView(c):void 0},addOne:function(b,c,d){var e,f;return f=new a.views.view_field({model:b,parentView:this}),null!=d.$replaceEl?d.$replaceEl.replaceWith(f.render().el):null==d.position||-1===d.position?this.$responseFields.append(f.render().el):0===d.position?this.$responseFields.prepend(f.render().el):(e=this.$responseFields.find(".fb-field-wrapper").eq(d.position))[0]?e.before(f.render().el):this.$responseFields.append(f.render().el)},setSortable:function(){var b=this;return this.$responseFields.hasClass("ui-sortable")&&this.$responseFields.sortable("destroy"),this.$responseFields.sortable({forcePlaceholderSize:!0,placeholder:"sortable-placeholder",stop:function(c,d){var e;return d.item.data("field-type")&&(e=b.collection.create(a.helpers.defaultFieldAttrs(d.item.data("field-type")),{$replaceEl:d.item}),b.createAndShowEditView(e)),b.handleFormUpdate(),!0},update:function(a,c){return c.item.data("field-type")?void 0:b.ensureEditViewScrolled()}}),this.setDraggable()},setDraggable:function(){var a,b=this;return a=this.$el.find("[data-field-type]"),a.draggable({connectToSortable:this.$responseFields,helper:function(){var a;return a=$("
"),a.css({width:b.$responseFields.width(),height:"80px"}),a}})},addAll:function(){return this.collection.each(this.addOne,this),this.setSortable()},hideShowNoResponseFields:function(){return this.$el.find(".fb-no-response-fields")[this.collection.length>0?"hide":"show"]()},addField:function(b){var c;return c=$(b.currentTarget).data("field-type"),this.createField(a.helpers.defaultFieldAttrs(c))},createField:function(a,b){var c;return c=this.collection.create(a,b),this.createAndShowEditView(c),this.handleFormUpdate()},createAndShowEditView:function(b){var c,d,e;if(d=this.$el.find(".fb-field-wrapper").filter(function(){return $(this).data("cid")===b.cid}),d.addClass("editing").siblings(".fb-field-wrapper").removeClass("editing"),this.editView){if(this.editView.model.cid===b.cid)return this.$el.find('.fb-tabs a[data-target="#editField"]').click(),this.scrollLeftWrapper(d,"undefined"!=typeof e&&null!==e&&e),void 0;e=this.$fbLeft.css("padding-top"),this.editView.remove()}return this.editView=new a.views.edit_field({model:b,parentView:this}),c=this.editView.render().$el,this.$el.find(".fb-edit-field-wrapper").html(c),this.$el.find('.fb-tabs a[data-target="#editField"]').click(),this.scrollLeftWrapper(d),this},ensureEditViewScrolled:function(){return this.editView?this.scrollLeftWrapper($(".fb-field-wrapper.editing")):void 0},scrollLeftWrapper:function(a){var b=this;return this.unlockLeftWrapper(),$.scrollWindowTo(a.offset().top-this.$responseFields.offset().top,200,function(){return b.lockLeftWrapper()})},lockLeftWrapper:function(){return this.$fbLeft.data("locked",!0)},unlockLeftWrapper:function(){return this.$fbLeft.data("locked",!1)},handleFormUpdate:function(){return this.updatingBatch?void 0:(this.formSaved=!1,this.saveFormButton.removeAttr("disabled").text(a.options.dict.SAVE_FORM))},saveForm:function(){var b;if(!this.formSaved)return this.formSaved=!0,this.saveFormButton.attr("disabled",!0).text(a.options.dict.ALL_CHANGES_SAVED),this.collection.sort(),b=JSON.stringify({fields:this.collection.toJSON()}),a.options.HTTP_ENDPOINT&&this.doAjaxSave(b),this.formBuilder.trigger("save",b)},doAjaxSave:function(b){var c=this;return $.ajax({url:a.options.HTTP_ENDPOINT,type:a.options.HTTP_METHOD,data:b,contentType:"application/json",success:function(a){var b,d,e,f;for(c.updatingBatch=!0,d=0,e=a.length;e>d;d++)b=a[d],null!=(f=c.collection.get(b.cid))&&f.set({id:b.id}),c.collection.trigger("sync");return c.updatingBatch=void 0}})}})},a}(),window.Formbuilder=a,"undefined"!=typeof module&&null!==module?module.exports=a:window.Formbuilder=a}.call(this),function(){Formbuilder.registerField("address",{view:"\n \n \n Address \n \n
\n\n\n \n \n City \n \n\n \n \n State / Province / Region \n \n
\n\n\n \n \n Zipcode \n \n\n \n United States \n Country \n \n
",edit:"",addButton:' Address'})}.call(this),function(){Formbuilder.registerField("checkboxes",{view:"<% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n \n \n onclick=\"javascript: return false;\" />\n <%= rf.get(Formbuilder.options.mappings.OPTIONS)[i].label %>\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n \n \n \n Other\n \n\n \n
\n<% } %>",edit:"<%= Formbuilder.templates['edit/options']({ includeOther: true }) %>",addButton:' Checkboxes',defaultAttributes:function(a){return a.field_options.options=[{label:"",checked:!1},{label:"",checked:!1}],a}})}.call(this),function(){Formbuilder.registerField("date",{view:"\n \n \n MM \n \n\n / \n\n \n \n DD \n \n\n / \n\n \n \n YYYY \n \n
",edit:"",addButton:' Date'})}.call(this),function(){Formbuilder.registerField("dropdown",{view:"\n <% if (rf.get(Formbuilder.options.mappings.INCLUDE_BLANK)) { %>\n \n <% } %>\n\n <% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n >\n <%= rf.get(Formbuilder.options.mappings.OPTIONS)[i].label %>\n \n <% } %>\n ",edit:"<%= Formbuilder.templates['edit/options']({ includeBlank: true }) %>",addButton:' Dropdown',defaultAttributes:function(a){return a.field_options.options=[{label:"",checked:!1},{label:"",checked:!1}],a.field_options.include_blank_option=!1,a}})}.call(this),function(){Formbuilder.registerField("email",{view:" ",edit:"",addButton:' Email'})}.call(this),function(){Formbuilder.registerField("file",{view:" ",edit:"",addButton:' File'})}.call(this),function(){Formbuilder.registerField("number",{view:" \n<% if (units = rf.get(Formbuilder.options.mappings.UNITS)) { %>\n <%= units %>\n<% } %>",edit:"<%= Formbuilder.templates['edit/min_max']() %>\n<%= Formbuilder.templates['edit/units']() %>\n<%= Formbuilder.templates['edit/integer_only']() %>",addButton:'123 Number'})}.call(this),function(){Formbuilder.registerField("paragraph",{view:"",edit:"<%= Formbuilder.templates['edit/size']() %>\n<%= Formbuilder.templates['edit/min_max_length']() %>",addButton:'¶ Paragraph',defaultAttributes:function(a){return a.field_options.size="small",a}})}.call(this),function(){Formbuilder.registerField("price",{view:"\n $ \n \n \n Dollars \n \n . \n \n \n Cents \n \n
",edit:"",addButton:' Price'})}.call(this),function(){Formbuilder.registerField("radio",{view:"<% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n \n \n onclick=\"javascript: return false;\" />\n <%= rf.get(Formbuilder.options.mappings.OPTIONS)[i].label %>\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n \n \n \n Other\n \n\n \n
\n<% } %>",edit:"<%= Formbuilder.templates['edit/options']({ includeOther: true }) %>",addButton:' Multiple Choice',defaultAttributes:function(a){return a.field_options.options=[{label:"",checked:!1},{label:"",checked:!1}],a}})}.call(this),function(){Formbuilder.registerField("section_break",{type:"non_input",view:"<%= rf.get(Formbuilder.options.mappings.LABEL) %> \n<%= rf.get(Formbuilder.options.mappings.DESCRIPTION) %>
",edit:"\n \n",addButton:" Section Break"})}.call(this),function(){Formbuilder.registerField("text",{view:" ",edit:"<%= Formbuilder.templates['edit/size']() %>\n<%= Formbuilder.templates['edit/min_max_length']() %>",addButton:" Text",defaultAttributes:function(a){return a.field_options.size="small",a}})}.call(this),function(){Formbuilder.registerField("time",{view:"\n \n \n HH \n \n\n : \n\n \n \n MM \n \n\n : \n\n \n \n SS \n \n\n \n \n AM \n PM \n \n \n
",edit:"",addButton:' Time'})}.call(this),function(){Formbuilder.registerField("website",{view:" ",edit:"<%= Formbuilder.templates['edit/size']() %>",addButton:' Website'})}.call(this),this.Formbuilder=this.Formbuilder||{},this.Formbuilder.templates=this.Formbuilder.templates||{},this.Formbuilder.templates["edit/base"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+=(null==(__t=Formbuilder.templates["edit/base_header"]())?"":__t)+"\n"+(null==(__t=Formbuilder.templates["edit/common"]())?"":__t)+"\n"+(null==(__t=Formbuilder.fields[rf.get(Formbuilder.options.mappings.FIELD_TYPE)].edit({rf:rf}))?"":__t)+"\n";return __p},this.Formbuilder.templates["edit/base_header"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n \n
\n \n
";return __p},this.Formbuilder.templates["edit/base_non_input"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+=(null==(__t=Formbuilder.templates["edit/base_header"]())?"":__t)+"\n"+(null==(__t=Formbuilder.fields[rf.get(Formbuilder.options.mappings.FIELD_TYPE)].edit({rf:rf}))?"":__t)+"\n";return __p},this.Formbuilder.templates["edit/checkboxes"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n \n Required\n \n\n \n Admin only\n ";return __p},this.Formbuilder.templates["edit/common"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n\n\n
\n "+(null==(__t=Formbuilder.templates["edit/label_description"]())?"":__t)+"\n
\n
\n "+(null==(__t=Formbuilder.templates["edit/checkboxes"]())?"":__t)+"\n
\n
\n
\n";return __p},this.Formbuilder.templates["edit/integer_only"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n\n \n Only accept integers\n \n";return __p},this.Formbuilder.templates["edit/label_description"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+=" \n";return __p},this.Formbuilder.templates["edit/min_max"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+='\n\nAbove\n \n\n \n\nBelow\n \n';return __p},this.Formbuilder.templates["edit/min_max_length"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+='\n\nMin\n \n\n \n\nMax\n \n\n \n\n\n characters \n words \n \n';return __p},this.Formbuilder.templates["edit/options"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,Array.prototype.join,obj)__p+="\n\n","undefined"!=typeof includeBlank&&(__p+="\n \n \n Include blank\n \n"),__p+="\n\n\n\n',"undefined"!=typeof includeOther&&(__p+="\n \n \n Include "other"\n \n'),__p+="\n\n\n';return __p},this.Formbuilder.templates["edit/size"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n\n Small \n Medium \n Large \n \n';return __p},this.Formbuilder.templates["edit/units"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+='\n \n';return __p},this.Formbuilder.templates.page=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+=(null==(__t=Formbuilder.templates["partials/save_button"]())?"":__t)+"\n"+(null==(__t=Formbuilder.templates["partials/left_side"]())?"":__t)+"\n"+(null==(__t=Formbuilder.templates["partials/right_side"]())?"":__t)+"\n
";return __p},this.Formbuilder.templates["partials/add_field"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,Array.prototype.join,obj){__p+=""}return __p},this.Formbuilder.templates["partials/edit_field"]=function(obj){obj||(obj={});var __p="";with(_.escape,obj)__p+="\n";return __p},this.Formbuilder.templates["partials/left_side"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n
\n\n
\n "+(null==(__t=Formbuilder.templates["partials/add_field"]())?"":__t)+"\n "+(null==(__t=Formbuilder.templates["partials/edit_field"]())?"":__t)+"\n
\n
";return __p},this.Formbuilder.templates["partials/right_side"]=function(obj){obj||(obj={});var __p="";with(_.escape,obj)__p+="\n
No response fields
\n
\n
\n";return __p},this.Formbuilder.templates["partials/save_button"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n \n
";return __p},this.Formbuilder.templates["view/base"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n
\n "+(null==(__t=Formbuilder.templates["view/label"]({rf:rf}))?"":__t)+"\n\n "+(null==(__t=Formbuilder.fields[rf.get(Formbuilder.options.mappings.FIELD_TYPE)].view({rf:rf}))?"":__t)+"\n\n "+(null==(__t=Formbuilder.templates["view/description"]({rf:rf}))?"":__t)+"\n "+(null==(__t=Formbuilder.templates["view/duplicate_remove"]({rf:rf}))?"":__t)+"\n
\n";return __p},this.Formbuilder.templates["view/base_non_input"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n
\n "+(null==(__t=Formbuilder.fields[rf.get(Formbuilder.options.mappings.FIELD_TYPE)].view({rf:rf}))?"":__t)+"\n "+(null==(__t=Formbuilder.templates["view/duplicate_remove"]({rf:rf}))?"":__t)+"\n
\n";return __p},this.Formbuilder.templates["view/description"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="\n "+(null==(__t=Formbuilder.helpers.simple_format(rf.get(Formbuilder.options.mappings.DESCRIPTION)))?"":__t)+"\n \n";return __p},this.Formbuilder.templates["view/duplicate_remove"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,obj)__p+="';return __p},this.Formbuilder.templates["view/label"]=function(obj){obj||(obj={});var __t,__p="";with(_.escape,Array.prototype.join,obj)__p+="\n "+(null==(__t=Formbuilder.helpers.simple_format(rf.get(Formbuilder.options.mappings.LABEL)))?"":__t)+"\n ",rf.get(Formbuilder.options.mappings.REQUIRED)&&(__p+="\n * \n "),__p+="\n \n";return __p};