diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 00000000..5e6701af --- /dev/null +++ b/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory" : "bower_components" +} \ No newline at end of file diff --git a/Gruntfile.coffee b/Gruntfile.coffee index eed98e72..9ca67683 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -58,19 +58,19 @@ module.exports = (grunt) -> '<%= distFolder %>/formbuilder.js': '<%= compiledFolder %>/*.js' '<%= vendorFolder %>/js/vendor.js': [ 'bower_components/ie8-node-enum/index.js' - 'bower_components/jquery/jquery.js' - 'bower_components/jquery-ui/ui/jquery.ui.core.js' - 'bower_components/jquery-ui/ui/jquery.ui.widget.js' - 'bower_components/jquery-ui/ui/jquery.ui.mouse.js' - 'bower_components/jquery-ui/ui/jquery.ui.draggable.js' - 'bower_components/jquery-ui/ui/jquery.ui.droppable.js' - 'bower_components/jquery-ui/ui/jquery.ui.sortable.js' + 'bower_components/jquery/dist/jquery.min.js' + 'bower_components/jquery-ui/ui/core.js' + 'bower_components/jquery-ui/ui/widget.js' + 'bower_components/jquery-ui/ui/mouse.js' + 'bower_components/jquery-ui/ui/draggable.js' + 'bower_components/jquery-ui/ui/droppable.js' + 'bower_components/jquery-ui/ui/sortable.js' 'bower_components/jquery.scrollWindowTo/index.js' - 'bower_components/underscore/underscore-min.js' + 'bower_components/underscore/underscore.js' 'bower_components/underscore.mixin.deepExtend/index.js' 'bower_components/rivets/dist/rivets.js' 'bower_components/backbone/backbone.js' - 'bower_components/backbone-deep-model/src/deep-model.js' + 'bower_components/backbone-nested-model/backbone-nested.js' ] mobile_friendly: files: @@ -80,7 +80,7 @@ module.exports = (grunt) -> 'bower_components/jquery.scrollWindowTo/index.js' 'bower_components/underscore.mixin.deepExtend/index.js' 'bower_components/rivets/dist/rivets.js' - 'bower_components/backbone-deep-model/src/deep-model.js' + 'bower_components/backbone-nested-model/backbone-nested.js' ] cssmin: diff --git a/bower.json b/bower.json index bfe2ca92..370ae60f 100644 --- a/bower.json +++ b/bower.json @@ -17,14 +17,14 @@ ], "dependencies": { "ie8-node-enum": "https://gist.github.com/ajb/8902451/raw/b68459289526cb76c2e22416d98d0dbd0b722fa0/ie8_node_enum.js", - "jquery": "~2.0.3", - "jquery-ui": "~1.10.3", + "jquery": "~2.1.1", + "jquery-ui": "~1.11.1", "jquery.scrollWindowTo": "https://gist.github.com/ajb/6519570/raw/cd741057495d0fb19e545a0f9a098efba3bef9c8/jquery.scrollWindowTo.js", - "underscore": "~1.5.2", + "underscore": ">=1.6", "underscore.mixin.deepExtend": "https://gist.github.com/ajb/6519561/raw/63682037af9b10200b05c1a3d5890903397b2103/underscore.mixin.deepExtend.js", "backbone": "~1.1.0", - "backbone-deep-model": "~0.10.4", - "rivets": "~0.5.13", - "font-awesome": "~4.0.0" + "backbone-nested-model": "~2.0.1", + "rivets": "~0.6.10", + "font-awesome": "~4.2.0" } } diff --git a/dist/formbuilder-min.css b/dist/formbuilder-min.css index 0247fb6d..ff97d7bc 100644 --- a/dist/formbuilder-min.css +++ b/dist/formbuilder-min.css @@ -1 +1 @@ -.fb-button{display:inline-block;margin:0;padding:.563rem .844rem;border:0 none;background:#16a085;color:#fff;text-align:center;text-decoration:none;font-size:12px;line-height:1.5;cursor:pointer;border-radius:.125rem;border:thin solid #19b394;border-bottom:2px solid #16a085}.fb-button[disabled]{background:#ddd!important;border:thin solid #ccc;color:#777!important;text-shadow:none!important;-ms-filter:"alpha(Opacity=65)";opacity:.65;cursor:default}.fb-clear{clear:both}.fb-main{max-width:1000px;margin:0 auto;padding:0 20px 0 0;position:relative;font-family:'Source Sans Pro','Open Sans',Tahoma}.fb-save-wrapper{position:absolute;right:20px;top:10px}.fb-left{width:320px;float:left;padding-top:30px}.fb-right{padding-top:70px;margin-left:320px;border-left:1px solid #ddd;padding-left:20px;min-height:100%;overflow:hidden}.fb-no-response-fields{color:#999}.fb-tabs{list-style:none;margin:0 0 20px;padding:0 0 0 20px;border-bottom:1px solid #ccc}.fb-tabs li{display:inline-block}.fb-tabs li a{display:block;padding:10px;border-radius:5px 5px 0 0;font-size:13px;cursor:pointer;border-left:1px solid transparent;border-right:1px solid transparent}.fb-tabs li.active a{border:1px solid #ccc;margin-bottom:-1px;border-bottom-color:#fff}.fb-tab-content .fb-tab-pane{padding:0 20px;display:none}.fb-tab-content .fb-tab-pane.active{display:block}.fb-add-field-types .section{padding-bottom:5px;margin-bottom:20px}.fb-add-field-types{font-size:0}.fb-add-field-types a{font-size:13px;display:inline-block;width:48.5%;background-color:#1abc9c;margin-bottom:9px;box-sizing:border-box}.fb-add-field-types a:nth-child(odd){margin-right:3%}.fb-add-field-types a .symbol{opacity:.6;margin:0 .25em 0 -1em}.fb-response-fields{padding-bottom:150px}.fb-response-fields a.sortable-placeholder{display:block;border:1px dashed #ddd;min-height:80px;height:80px;width:100%}.fb-field-wrapper{cursor:pointer;position:relative;margin-bottom:20px}.fb-field-wrapper input{border-radius:3px;border:thin solid #ddd}.fb-field-wrapper:hover .actions-wrapper,.fb-field-wrapper.editing .actions-wrapper{display:block}.fb-field-wrapper:hover .subtemplate-wrapper{border-color:#ddd;border-radius:3px}.fb-field-wrapper.editing{background-color:#ecf0f1;border-radius:3px}.fb-field-wrapper.editing .subtemplate-wrapper{border-color:#d9e1e3;border-style:solid;margin:0;border-radius:3px}.fb-field-wrapper .actions-wrapper{display:none;position:absolute;bottom:-7px;right:5px;z-index:3}.fb-field-wrapper .actions-wrapper a{display:inline-block;background-color:#ccc;padding:2px 8px}.edit-response-field input,.edit-response-field textarea,.edit-response-field select{border:thin solid #ddd;border-radius:.25em;padding:.5em;display:inline-block;height:auto;vertical-align:middle}.edit-response-field input:focus,.edit-response-field textarea:focus,.edit-response-field select:focus{outline:0;border:thin solid #1abc9c}.edit-response-field select{font-size:14px}.fb-field-wrapper .actions-wrapper a.js-duplicate,.fb-edit-field-wrapper .js-add-option{background-color:#2ecc71;border:0}.fb-field-wrapper .actions-wrapper a.js-clear,.fb-edit-field-wrapper .js-remove-option{background-color:#e74c3c;border:0}.fb-field-wrapper .subtemplate-wrapper{border:1px dashed transparent;margin-bottom:10px;padding:10px;position:relative}.fb-field-wrapper .subtemplate-wrapper .cover{position:absolute;top:0;left:0;height:100%;width:100%;z-index:2}.fb-field-wrapper .subtemplate-wrapper>label{display:block;border-bottom:thin solid #eee;padding-bottom:3px;margin-bottom:7px}.fb-field-wrapper .subtemplate-wrapper abbr{color:red}.fb-field-wrapper .input-line{clear:both;margin-bottom:10px}.fb-field-wrapper .input-line .above-line{margin-top:7px}.fb-field-wrapper .input-line>span{display:inline-block;vertical-align:top}.fb-field-wrapper .input-line>span input{width:100%}.fb-field-wrapper .input-line>span>label{display:block;font-size:13px;margin-left:3px}.fb-field-wrapper .help-block{display:block;font-size:12px;margin-top:5px}.fb-edit-field-wrapper{font-size:13px}.fb-edit-field-wrapper .fb-field-label{font-weight:400;background:#eee;padding:.75em;color:#666;font-size:1.25em}.fb-edit-field-wrapper .fb-field-label .field-type{margin-top:.5em;display:block;font-family:'Source Sans Pro',sans-serif;font-size:1em}.fb-edit-field-wrapper .fb-field-label .field-type:before{content:'Type: ';color:#999}.fb-edit-field-wrapper .fb-field-label .fa.fa-arrow-right{display:none}.fb-edit-field-wrapper .fb-edit-section-header{border-bottom:1px solid #ddd;margin-top:25px;margin-bottom:10px;padding-bottom:5px;clear:both;font-weight:700}.fb-edit-field-wrapper .js-add-option,.fb-edit-field-wrapper .js-remove-option{padding:3px 6px}.fb-edit-field-wrapper .fb-bottom-add{margin-top:8px}.fb-common-wrapper .fb-label-description{margin-bottom:10px}.fb-common-wrapper .fb-label-description input,.fb-common-wrapper .fb-label-description textarea{width:100%}.fb-common-wrapper .fb-label-description textarea{min-height:5em}.response-field-draggable-helper{border:1px dashed #ddd;background:#eee}.response-field-text input.rf-size-small{width:130px}.response-field-text input.rf-size-medium{width:300px}.response-field-text input.rf-size-large{width:100%}.response-field-paragraph textarea.rf-size-small{width:200px;min-height:60px}.response-field-paragraph textarea.rf-size-medium{width:400px;min-height:100px}.response-field-paragraph textarea.rf-size-large{width:100%;min-height:200px}.response-field-address .street{width:400px}.response-field-address .city,.response-field-address .state,.response-field-address .zip,.response-field-address .country{width:198px}.response-field-date .month,.response-field-date .day,.response-field-date .year{width:50px}.response-field-time .hours,.response-field-time .minutes,.response-field-time .seconds{width:50px}.response-field-checkboxes .fb-option,.response-field-radio .fb-option{margin-bottom:5px;display:inline-block} \ No newline at end of file +.fb-button{display:inline-block;margin:0;padding:.563rem .844rem;border:0 none;background:#16a085;color:#fff;text-align:center;text-decoration:none;font-size:12px;line-height:1.5;cursor:pointer;border-radius:.125rem;border:thin solid #19b394;border-bottom:2px solid #16a085}.fb-button[disabled]{background:#ddd!important;border:thin solid #ccc;color:#777!important;text-shadow:none!important;-ms-filter:"alpha(Opacity=65)";opacity:.65;cursor:default}.fb-clear{clear:both}.fb-main{max-width:1000px;margin:0 auto;padding:0 20px 0 0;position:relative;font-family:'Source Sans Pro','Open Sans',Tahoma}.fb-save-wrapper{position:absolute;right:20px;top:10px}.fb-left{float:left;width:320px;padding-top:30px}.fb-right{padding-top:70px;margin-left:320px;border-left:1px solid #ddd;padding-left:20px;min-height:100%;overflow:hidden}.fb-no-response-fields{color:#999}.fb-tabs{list-style:none;margin:0 0 20px;padding:0 0 0 20px;border-bottom:1px solid #ccc}.fb-tabs li{display:inline-block}.fb-tabs li a{display:block;padding:10px;border-radius:5px 5px 0 0;font-size:13px;cursor:pointer;border-left:1px solid transparent;border-right:1px solid transparent}.fb-tabs li.active a{border:1px solid #ccc;margin-bottom:-1px;border-bottom-color:#fff}.fb-tab-content .fb-tab-pane{padding:0 20px;display:none}.fb-tab-content .fb-tab-pane.active{display:block}.fb-add-field-types .section{padding-bottom:5px;margin-bottom:20px}.fb-add-field-types{font-size:0}.fb-add-field-types a{font-size:13px;display:inline-block;width:48.5%;background-color:#1abc9c;margin-bottom:9px;box-sizing:border-box}.fb-add-field-types a:nth-child(odd){margin-right:3%}.fb-add-field-types a .symbol{opacity:.6;margin:0 .25em 0 -1em}.fb-response-fields{padding-bottom:150px}.fb-response-fields a.sortable-placeholder{display:block;border:1px dashed #ddd;min-height:80px;height:80px;width:100%}.fb-field-wrapper{cursor:pointer;position:relative;margin-bottom:20px}.fb-field-wrapper input{border-radius:3px;border:thin solid #ddd}.fb-field-wrapper:hover .actions-wrapper,.fb-field-wrapper.editing .actions-wrapper{display:block}.fb-field-wrapper:hover .subtemplate-wrapper{border-color:#ddd;border-radius:3px}.fb-field-wrapper.editing{background-color:#ecf0f1;border-radius:3px}.fb-field-wrapper.editing .subtemplate-wrapper{border-color:#d9e1e3;border-style:solid;margin:0;border-radius:3px}.fb-field-wrapper .actions-wrapper{display:none;position:absolute;bottom:-7px;right:5px;z-index:3}.fb-field-wrapper .actions-wrapper a{display:inline-block;background-color:#ccc;padding:2px 8px}.edit-response-field input,.edit-response-field textarea,.edit-response-field select{border:thin solid #ddd;border-radius:.25em;padding:.5em;display:inline-block;height:auto;vertical-align:middle}.edit-response-field input:focus,.edit-response-field textarea:focus,.edit-response-field select:focus{outline:0;border:thin solid #1abc9c}.edit-response-field select{font-size:14px}.fb-field-wrapper .actions-wrapper a.js-duplicate,.fb-edit-field-wrapper .js-add-option{background-color:#2ecc71;border:0}.fb-field-wrapper .actions-wrapper a.js-clear,.fb-edit-field-wrapper .js-remove-option{background-color:#e74c3c;border:0}.fb-field-wrapper .subtemplate-wrapper{border:1px dashed transparent;margin-bottom:10px;padding:10px;position:relative}.fb-field-wrapper .subtemplate-wrapper .cover{position:absolute;top:0;left:0;height:100%;width:100%;z-index:2}.fb-field-wrapper .subtemplate-wrapper>label{display:block;border-bottom:thin solid #eee;padding-bottom:3px;margin-bottom:7px}.fb-field-wrapper .subtemplate-wrapper abbr{color:red}.fb-field-wrapper .input-line{clear:both;margin-bottom:10px}.fb-field-wrapper .input-line .above-line{margin-top:7px}.fb-field-wrapper .input-line>span{display:inline-block;vertical-align:top}.fb-field-wrapper .input-line>span input{width:100%}.fb-field-wrapper .input-line>span>label{display:block;font-size:13px;margin-left:3px}.fb-field-wrapper .help-block{display:block;font-size:12px;margin-top:5px}.fb-edit-field-wrapper{font-size:13px}.fb-edit-field-wrapper .fb-field-label{font-weight:400;background:#eee;padding:.75em;color:#666;font-size:1.25em}.fb-edit-field-wrapper .fb-field-label .field-type{margin-top:.5em;display:block;font-family:'Source Sans Pro',sans-serif;font-size:1em}.fb-edit-field-wrapper .fb-field-label .field-type:before{content:'Type: ';color:#999}.fb-edit-field-wrapper .fb-field-label .fa.fa-arrow-right{display:none}.fb-edit-field-wrapper .fb-edit-section-header{border-bottom:1px solid #ddd;margin-top:25px;margin-bottom:10px;padding-bottom:5px;clear:both;font-weight:700}.fb-edit-field-wrapper .js-add-option,.fb-edit-field-wrapper .js-remove-option{padding:3px 6px}.fb-edit-field-wrapper .fb-bottom-add{margin-top:8px}.fb-common-wrapper .fb-label-description{margin-bottom:10px}.fb-common-wrapper .fb-label-description input,.fb-common-wrapper .fb-label-description textarea{width:100%}.fb-common-wrapper .fb-label-description textarea{min-height:5em}.response-field-draggable-helper{border:1px dashed #ddd;background:#eee}.response-field-text input.rf-size-small{width:130px}.response-field-text input.rf-size-medium{width:300px}.response-field-text input.rf-size-large{width:100%}.response-field-paragraph textarea.rf-size-small{width:200px;min-height:60px}.response-field-paragraph textarea.rf-size-medium{width:400px;min-height:100px}.response-field-paragraph textarea.rf-size-large{width:100%;min-height:200px}.response-field-address .street{width:400px}.response-field-address .city,.response-field-address .state,.response-field-address .zip,.response-field-address .country{width:198px}.response-field-date .month,.response-field-date .day,.response-field-date .year{width:50px}.response-field-time .hours,.response-field-time .minutes,.response-field-time .seconds{width:50px}.response-field-checkboxes .fb-option,.response-field-radio .fb-option{margin-bottom:5px;display:inline-block}.response-field-website input{width:200px} \ No newline at end of file diff --git a/dist/formbuilder-min.js b/dist/formbuilder-min.js index cb44897a..200f435f 100644 --- a/dist/formbuilder-min.js +++ b/dist/formbuilder-min.js @@ -1 +1 @@ -(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,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};e=function(a){function b(){return g=b.__super__.constructor.apply(this,arguments)}return m(b,a),b.prototype.sync=function(){},b.prototype.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)},b.prototype.is_input=function(){return null!=c.inputFields[this.get(c.options.mappings.FIELD_TYPE)]},b}(Backbone.DeepModel),d=function(a){function b(){return h=b.__super__.constructor.apply(this,arguments)}return m(b,a),b.prototype.initialize=function(){return this.on("add",this.copyCidToModel)},b.prototype.model=e,b.prototype.comparator=function(a){return a.indexInDOM()},b.prototype.copyCidToModel=function(a){return a.attributes.cid=a.cid},b}(Backbone.Collection),f=function(a){function b(){return i=b.__super__.constructor.apply(this,arguments)}return m(b,a),b.prototype.className="fb-field-wrapper",b.prototype.events={"click .subtemplate-wrapper":"focusEditView","click .js-duplicate":"duplicate","click .js-clear":"clear"},b.prototype.initialize=function(a){return this.parentView=a.parentView,this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"destroy",this.remove)},b.prototype.render=function(){return this.$el.addClass("response-field-"+this.model.get(c.options.mappings.FIELD_TYPE)).data("cid",this.model.cid).html(c.templates["view/base"+(this.model.is_input()?"":"_non_input")]({rf:this.model})),this},b.prototype.focusEditView=function(){return this.parentView.createAndShowEditView(this.model)},b.prototype.clear=function(){return this.parentView.handleFormUpdate(),this.model.destroy()},b.prototype.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})},b}(Backbone.View),b=function(a){function b(){return j=b.__super__.constructor.apply(this,arguments)}return m(b,a),b.prototype.className="edit-response-field",b.prototype.events={"click .js-add-option":"addOption","click .js-remove-option":"removeOption","click .js-default-updated":"defaultUpdated","input .option-label-input":"forceRender"},b.prototype.initialize=function(a){return this.parentView=a.parentView,this.listenTo(this.model,"destroy",this.remove)},b.prototype.render=function(){return this.$el.html(c.templates["edit/base"+(this.model.is_input()?"":"_non_input")]({rf:this.model})),rivets.bind(this.$el,{model:this.model}),this},b.prototype.remove=function(){return this.parentView.editView=void 0,this.parentView.$el.find('[data-target="#addField"]').click(),b.__super__.remove.apply(this,arguments)},b.prototype.addOption=function(a){var b,d,e,f;return b=$(a.currentTarget),d=this.$el.find(".option").index(b.closest(".option")),f=this.model.get(c.options.mappings.OPTIONS)||[],e={label:"",checked:!1},d>-1?f.splice(d+1,0,e):f.push(e),this.model.set(c.options.mappings.OPTIONS,f),this.model.trigger("change:"+c.options.mappings.OPTIONS),this.forceRender()},b.prototype.removeOption=function(a){var b,d,e;return b=$(a.currentTarget),d=this.$el.find(".js-remove-option").index(b),e=this.model.get(c.options.mappings.OPTIONS),e.splice(d,1),this.model.set(c.options.mappings.OPTIONS,e),this.model.trigger("change:"+c.options.mappings.OPTIONS),this.forceRender()},b.prototype.defaultUpdated=function(a){var b;return b=$(a.currentTarget),"checkboxes"!==this.model.get(c.options.mappings.FIELD_TYPE)&&this.$el.find(".js-default-updated").not(b).attr("checked",!1).trigger("change"),this.forceRender()},b.prototype.forceRender=function(){return this.model.trigger("change")},b}(Backbone.View),a=function(a){function e(){return k=e.__super__.constructor.apply(this,arguments)}return m(e,a),e.prototype.SUBVIEWS=[],e.prototype.events={"click .js-save-form":"saveForm","click .fb-tabs a":"showTab","click .fb-add-field-types a":"addField"},e.prototype.initialize=function(a){var b;return b=a.selector,this.formBuilder=a.formBuilder,this.bootstrapData=a.bootstrapData,null!=b&&this.setElement($(b)),this.collection=new d,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.bootstrapData),this.initAutosave()},e.prototype.initAutosave=function(){var a=this;return this.formSaved=!0,this.saveFormButton=this.$el.find(".js-save-form"),this.saveFormButton.attr("disabled",!0).text(c.options.dict.ALL_CHANGES_SAVED),setInterval(function(){return a.saveForm.call(a)},5e3),$(window).bind("beforeunload",function(){return a.formSaved?void 0:c.options.dict.UNSAVED_CHANGES})},e.prototype.reset=function(){return this.$responseFields.html(""),this.addAll()},e.prototype.render=function(){var a,b,d,e;for(this.$el.html(c.templates.page()),this.$fbLeft=this.$el.find(".fb-left"),this.$responseFields=this.$el.find(".fb-response-fields"),this.bindWindowScrollEvent(),this.hideShowNoResponseFields(),e=this.SUBVIEWS,b=0,d=e.length;d>b;b++)a=e[b],new a({parentView:this}).render();return this},e.prototype.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)})})},e.prototype.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},e.prototype.addOne=function(a,b,c){var d,e;return e=new f({model:a,parentView:this}),null!=c.$replaceEl?c.$replaceEl.replaceWith(e.render().el):null==c.position||-1===c.position?this.$responseFields.append(e.render().el):0===c.position?this.$responseFields.prepend(e.render().el):(d=this.$responseFields.find(".fb-field-wrapper").eq(c.position))[0]?d.before(e.render().el):this.$responseFields.append(e.render().el)},e.prototype.setSortable=function(){var a=this;return this.$responseFields.hasClass("ui-sortable")&&this.$responseFields.sortable("destroy"),this.$responseFields.sortable({forcePlaceholderSize:!0,placeholder:"sortable-placeholder",stop:function(b,d){var e;return d.item.data("field-type")&&(e=a.collection.create(c.helpers.defaultFieldAttrs(d.item.data("field-type")),{$replaceEl:d.item}),a.createAndShowEditView(e)),a.handleFormUpdate(),!0},update:function(b,c){return c.item.data("field-type")?void 0:a.ensureEditViewScrolled()}}),this.setDraggable()},e.prototype.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}})},e.prototype.addAll=function(){return this.collection.each(this.addOne,this),this.setSortable()},e.prototype.hideShowNoResponseFields=function(){return this.$el.find(".fb-no-response-fields")[this.collection.length>0?"hide":"show"]()},e.prototype.addField=function(a){var b;return b=$(a.currentTarget).data("field-type"),this.createField(c.helpers.defaultFieldAttrs(b))},e.prototype.createField=function(a,b){var c;return c=this.collection.create(a,b),this.createAndShowEditView(c),this.handleFormUpdate()},e.prototype.createAndShowEditView=function(a){var c,d,e;if(d=this.$el.find(".fb-field-wrapper").filter(function(){return $(this).data("cid")===a.cid}),d.addClass("editing").siblings(".fb-field-wrapper").removeClass("editing"),this.editView){if(this.editView.model.cid===a.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 b({model:a,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},e.prototype.ensureEditViewScrolled=function(){return this.editView?this.scrollLeftWrapper($(".fb-field-wrapper.editing")):void 0},e.prototype.scrollLeftWrapper=function(a){var b=this;return this.unlockLeftWrapper(),a[0]?$.scrollWindowTo(a.offset().top-this.$responseFields.offset().top,200,function(){return b.lockLeftWrapper()}):void 0},e.prototype.lockLeftWrapper=function(){return this.$fbLeft.data("locked",!0)},e.prototype.unlockLeftWrapper=function(){return this.$fbLeft.data("locked",!1)},e.prototype.handleFormUpdate=function(){return this.updatingBatch?void 0:(this.formSaved=!1,this.saveFormButton.removeAttr("disabled").text(c.options.dict.SAVE_FORM))},e.prototype.saveForm=function(){var a;if(!this.formSaved)return this.formSaved=!0,this.saveFormButton.attr("disabled",!0).text(c.options.dict.ALL_CHANGES_SAVED),this.collection.sort(),a=JSON.stringify({fields:this.collection.toJSON()}),c.options.HTTP_ENDPOINT&&this.doAjaxSave(a),this.formBuilder.trigger("save",a)},e.prototype.doAjaxSave=function(a){var b=this;return $.ajax({url:c.options.HTTP_ENDPOINT,type:c.options.HTTP_METHOD,data:a,contentType:"application/json",success:function(a){var c,d,e,f;for(b.updatingBatch=!0,d=0,e=a.length;e>d;d++)c=a[d],null!=(f=b.collection.get(c.cid))&&f.set({id:c.id}),b.collection.trigger("sync");return b.updatingBatch=void 0}})},e}(Backbone.View),c=function(){function b(b){var c;null==b&&(b={}),_.extend(this,Backbone.Events),c=_.extend(b,{formBuilder:this}),this.mainView=new a(c)}return b.helpers={defaultFieldAttrs:function(a){var c,d;return c={label:"Untitled",field_type:a,required:!0,field_options:{}},("function"==typeof(d=b.fields[a]).defaultAttributes?d.defaultAttributes(c):void 0)||c},simple_format:function(a){return null!=a?a.replace(/\n/g,"
"):void 0}},b.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!"}},b.fields={},b.inputFields={},b.nonInputFields={},b.registerField=function(a,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 c.field_type=a,b.fields[a]=c,"non_input"===c.type?b.nonInputFields[a]=c:b.inputFields[a]=c},b}(),window.Formbuilder=c,"undefined"!=typeof module&&null!==module?module.exports=c:window.Formbuilder=c}.call(this),function(){Formbuilder.registerField("address",{order:50,view:"
\n \n \n \n \n
\n\n
\n \n \n \n \n\n \n \n \n \n
\n\n
\n \n \n \n \n\n \n \n \n \n
",edit:"",addButton:' Address'})}.call(this),function(){Formbuilder.registerField("checkboxes",{order:10,view:"<% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n
\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n
\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",{order:20,view:"
\n \n \n \n \n\n /\n\n \n \n \n \n\n /\n\n \n \n \n \n
",edit:"",addButton:' Date'})}.call(this),function(){Formbuilder.registerField("dropdown",{order:24,view:"",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",{order:40,view:"",edit:"",addButton:' Email'})}.call(this),function(){Formbuilder.registerField("file",{order:55,view:"",edit:"",addButton:' File'})}.call(this),function(){Formbuilder.registerField("number",{order:30,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",{order:5,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",{order:45,view:"
\n $\n \n \n \n \n .\n \n \n \n \n
",edit:"",addButton:' Price'})}.call(this),function(){Formbuilder.registerField("radio",{order:15,view:"<% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n
\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n
\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",{order:0,type:"non_input",view:"\n

<%= rf.get(Formbuilder.options.mappings.DESCRIPTION) %>

",edit:"
Label
\n\n",addButton:" Section Break"})}.call(this),function(){Formbuilder.registerField("text",{order:0,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",{order:25,view:"
\n \n \n \n \n\n :\n\n \n \n \n \n\n :\n\n \n \n \n \n\n \n \n \n
",edit:"",addButton:' Time'})}.call(this),function(){Formbuilder.registerField("website",{order:35,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="";_.escape}with(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="";_.escape}with(obj)__p+="
\n \n \n \n
";return __p},this.Formbuilder.templates["edit/base_non_input"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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="";_.escape}with(obj)__p+="\n";return __p},this.Formbuilder.templates["edit/common"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+="
Label
\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="";_.escape}with(obj)__p+="
Integer only
\n\n";return __p},this.Formbuilder.templates["edit/label_description"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+="\n";return __p},this.Formbuilder.templates["edit/min_max"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+='
Minimum / Maximum
\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="";_.escape}with(obj)__p+='
Length Limit
\n\nMin\n\n\n  \n\nMax\n\n\n  \n\n\n';return __p},this.Formbuilder.templates["edit/options"]=function(obj){obj||(obj={});{var __t,__p="";_.escape,Array.prototype.join}with(obj)__p+="
Options
\n\n","undefined"!=typeof includeBlank&&(__p+="\n \n"),__p+="\n\n
\n \n \n \n \n
\n\n',"undefined"!=typeof includeOther&&(__p+="\n \n'),__p+="\n\n
\n Add option\n
\n';return __p},this.Formbuilder.templates["edit/size"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+="
Size
\n\n';return __p},this.Formbuilder.templates["edit/units"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+='
Units
\n\n';return __p},this.Formbuilder.templates.page=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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="";_.escape,Array.prototype.join}with(obj)__p+="
\n
\n
\n ",_.each(_.sortBy(Formbuilder.inputFields,"order"),function(a){__p+='\n \n '+(null==(__t=a.addButton)?"":__t)+"\n \n "}),__p+="\n
\n\n
\n ",_.each(_.sortBy(Formbuilder.nonInputFields,"order"),function(a){__p+='\n \n '+(null==(__t=a.addButton)?"":__t)+"\n \n "}),__p+="\n
\n
\n
";return __p},this.Formbuilder.templates["partials/edit_field"]=function(obj){obj||(obj={});{var __p="";_.escape}with(obj)__p+="
\n
\n
\n";return __p},this.Formbuilder.templates["partials/left_side"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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="";_.escape}with(obj)__p+="
\n
No response fields
\n
\n
\n";return __p},this.Formbuilder.templates["partials/save_button"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+="
\n \n
";return __p},this.Formbuilder.templates["view/base"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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="";_.escape}with(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="";_.escape}with(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="";_.escape}with(obj)__p+="
\n \n \n
';return __p},this.Formbuilder.templates["view/label"]=function(obj){obj||(obj={});{var __t,__p="";_.escape,Array.prototype.join}with(obj)__p+="\n";return __p}; \ No newline at end of file +(function(){rivets.binders.input={publishes:!0,routine:rivets.binders.value.routine,bind:function(a){return $(a).bind("input.rivets",this.publish)},unbind:function(a){return $(a).unbind("input.rivets")}},rivets.adapters[":"]={subscribe:function(a,b,c){return a.on("change:"+b,c)},unsubscribe:function(a,b,c){return a.off("change:"+b,c)},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,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};e=function(a){function b(){return g=b.__super__.constructor.apply(this,arguments)}return m(b,a),b.prototype.sync=function(){},b.prototype.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)},b.prototype.is_input=function(){return null!=c.inputFields[this.get(c.options.mappings.FIELD_TYPE)]},b}(Backbone.DeepModel),d=function(a){function b(){return h=b.__super__.constructor.apply(this,arguments)}return m(b,a),b.prototype.initialize=function(){return this.on("add",this.copyCidToModel)},b.prototype.model=e,b.prototype.comparator=function(a){return a.indexInDOM()},b.prototype.copyCidToModel=function(a){return a.attributes.cid=a.cid},b}(Backbone.Collection),f=function(a){function b(){return i=b.__super__.constructor.apply(this,arguments)}return m(b,a),b.prototype.className="fb-field-wrapper",b.prototype.events={"click .subtemplate-wrapper":"focusEditView","click .js-duplicate":"duplicate","click .js-clear":"clear"},b.prototype.initialize=function(a){return this.parentView=a.parentView,this.listenTo(this.model,"change",this.render),this.listenTo(this.model,"destroy",this.remove)},b.prototype.render=function(){return this.$el.addClass("response-field-"+this.model.get(c.options.mappings.FIELD_TYPE)).data("cid",this.model.cid).html(c.templates["view/base"+(this.model.is_input()?"":"_non_input")]({rf:this.model})),this},b.prototype.focusEditView=function(){return this.parentView.createAndShowEditView(this.model)},b.prototype.clear=function(a){var b,d,e=this;switch(a.preventDefault(),a.stopPropagation(),b=function(){return e.parentView.handleFormUpdate(),e.model.destroy()},d=c.options.CLEAR_FIELD_CONFIRM,typeof d){case"string":if(confirm(d))return b();break;case"function":return d(b);default:return b()}},b.prototype.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})},b}(Backbone.View),b=function(a){function b(){return j=b.__super__.constructor.apply(this,arguments)}return m(b,a),b.prototype.className="edit-response-field",b.prototype.events={"click .js-add-option":"addOption","click .js-remove-option":"removeOption","click .js-default-updated":"defaultUpdated","input .option-label-input":"forceRender"},b.prototype.initialize=function(a){return this.parentView=a.parentView,this.listenTo(this.model,"destroy",this.remove)},b.prototype.render=function(){return this.$el.html(c.templates["edit/base"+(this.model.is_input()?"":"_non_input")]({rf:this.model})),rivets.bind(this.$el,{model:this.model}),this},b.prototype.remove=function(){return this.parentView.editView=void 0,this.parentView.$el.find('[data-target="#addField"]').click(),b.__super__.remove.apply(this,arguments)},b.prototype.addOption=function(a){var b,d,e,f;return b=$(a.currentTarget),d=this.$el.find(".option").index(b.closest(".option")),f=this.model.get(c.options.mappings.OPTIONS)||[],e={label:"",checked:!1},d>-1?f.splice(d+1,0,e):f.push(e),this.model.set(c.options.mappings.OPTIONS,f),this.model.trigger("change:"+c.options.mappings.OPTIONS),this.forceRender()},b.prototype.removeOption=function(a){var b,d,e;return b=$(a.currentTarget),d=this.$el.find(".js-remove-option").index(b),e=this.model.get(c.options.mappings.OPTIONS),e.splice(d,1),this.model.set(c.options.mappings.OPTIONS,e),this.model.trigger("change:"+c.options.mappings.OPTIONS),this.forceRender()},b.prototype.defaultUpdated=function(a){var b;return b=$(a.currentTarget),"checkboxes"!==this.model.get(c.options.mappings.FIELD_TYPE)&&this.$el.find(".js-default-updated").not(b).attr("checked",!1).trigger("change"),this.forceRender()},b.prototype.forceRender=function(){return this.model.trigger("change")},b}(Backbone.View),a=function(a){function e(){return k=e.__super__.constructor.apply(this,arguments)}return m(e,a),e.prototype.SUBVIEWS=[],e.prototype.events={"click .js-save-form":"saveForm","click .fb-tabs a":"showTab","click .fb-add-field-types a":"addField","mouseover .fb-add-field-types":"lockLeftWrapper","mouseout .fb-add-field-types":"unlockLeftWrapper"},e.prototype.initialize=function(a){var b;return b=a.selector,this.formBuilder=a.formBuilder,this.bootstrapData=a.bootstrapData,null!=b&&this.setElement($(b)),this.collection=new d,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.bootstrapData),this.bindSaveEvent()},e.prototype.bindSaveEvent=function(){var a=this;return this.formSaved=!0,this.saveFormButton=this.$el.find(".js-save-form"),this.saveFormButton.attr("disabled",!0).text(c.options.dict.ALL_CHANGES_SAVED),c.options.AUTOSAVE&&setInterval(function(){return a.saveForm.call(a)},5e3),$(window).bind("beforeunload",function(){return a.formSaved?void 0:c.options.dict.UNSAVED_CHANGES})},e.prototype.reset=function(){return this.$responseFields.html(""),this.addAll()},e.prototype.render=function(){var a,b,d,e;for(this.$el.html(c.templates.page()),this.$fbLeft=this.$el.find(".fb-left"),this.$responseFields=this.$el.find(".fb-response-fields"),this.bindWindowScrollEvent(),this.hideShowNoResponseFields(),e=this.SUBVIEWS,b=0,d=e.length;d>b;b++)a=e[b],new a({parentView:this}).render();return this},e.prototype.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()-a.$el.offset().top),b=a.$responseFields.height(),a.$fbLeft.css({"margin-top":Math.min(b,c)})})},e.prototype.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},e.prototype.addOne=function(a,b,c){var d,e;return e=new f({model:a,parentView:this}),null!=c.$replaceEl?c.$replaceEl.replaceWith(e.render().el):null==c.position||-1===c.position?this.$responseFields.append(e.render().el):0===c.position?this.$responseFields.prepend(e.render().el):(d=this.$responseFields.find(".fb-field-wrapper").eq(c.position))[0]?d.before(e.render().el):this.$responseFields.append(e.render().el)},e.prototype.setSortable=function(){var a=this;return this.$responseFields.hasClass("ui-sortable")&&this.$responseFields.sortable("destroy"),this.$responseFields.sortable({forcePlaceholderSize:!0,placeholder:"sortable-placeholder",stop:function(b,d){var e;return d.item.data("field-type")&&(e=a.collection.create(c.helpers.defaultFieldAttrs(d.item.data("field-type")),{$replaceEl:d.item}),a.createAndShowEditView(e)),a.handleFormUpdate(),!0},update:function(b,c){return c.item.data("field-type")?void 0:a.ensureEditViewScrolled()}}),this.setDraggable()},e.prototype.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}})},e.prototype.addAll=function(){return this.collection.each(this.addOne,this),this.setSortable()},e.prototype.hideShowNoResponseFields=function(){return this.$el.find(".fb-no-response-fields")[this.collection.length>0?"hide":"show"]()},e.prototype.addField=function(a){var b;return b=$(a.currentTarget).data("field-type"),this.createField(c.helpers.defaultFieldAttrs(b))},e.prototype.createField=function(a,b){var c;return c=this.collection.create(a,b),this.createAndShowEditView(c),this.handleFormUpdate()},e.prototype.createAndShowEditView=function(a){var c,d;if(d=this.$el.find(".fb-field-wrapper").filter(function(){return $(this).data("cid")===a.cid}),d.addClass("editing").siblings(".fb-field-wrapper").removeClass("editing"),this.editView){if(this.editView.model.cid===a.cid)return this.$el.find('.fb-tabs a[data-target="#editField"]').click(),void this.scrollLeftWrapper(d);this.editView.remove()}return this.editView=new b({model:a,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},e.prototype.ensureEditViewScrolled=function(){return this.editView?this.scrollLeftWrapper($(".fb-field-wrapper.editing")):void 0},e.prototype.scrollLeftWrapper=function(a){var b=this;return this.unlockLeftWrapper(),a[0]?$.scrollWindowTo(this.$el.offset().top+a.offset().top-this.$responseFields.offset().top,200,function(){return b.lockLeftWrapper()}):void 0},e.prototype.lockLeftWrapper=function(){return this.$fbLeft.data("locked",!0)},e.prototype.unlockLeftWrapper=function(){return this.$fbLeft.data("locked",!1)},e.prototype.handleFormUpdate=function(){return this.updatingBatch?void 0:(this.formSaved=!1,this.saveFormButton.removeAttr("disabled").text(c.options.dict.SAVE_FORM))},e.prototype.saveForm=function(){var a;if(!this.formSaved)return this.formSaved=!0,this.saveFormButton.attr("disabled",!0).text(c.options.dict.ALL_CHANGES_SAVED),this.collection.sort(),a=JSON.stringify({fields:this.collection.toJSON()}),c.options.HTTP_ENDPOINT&&this.doAjaxSave(a),this.formBuilder.trigger("save",a)},e.prototype.doAjaxSave=function(a){var b=this;return $.ajax({url:c.options.HTTP_ENDPOINT,type:c.options.HTTP_METHOD,data:a,contentType:"application/json",success:function(a){var c,d,e,f;for(b.updatingBatch=!0,d=0,e=a.length;e>d;d++)c=a[d],null!=(f=b.collection.get(c.cid))&&f.set({id:c.id}),b.collection.trigger("sync");return b.updatingBatch=void 0}})},e}(Backbone.View),c=function(){function b(b){var c;null==b&&(b={}),_.extend(this,Backbone.Events),c=_.extend(b,{formBuilder:this}),this.mainView=new a(c)}return b.helpers={defaultFieldAttrs:function(a){var c,d;return c={},c[b.options.mappings.LABEL]="Untitled",c[b.options.mappings.FIELD_TYPE]=a,c[b.options.mappings.REQUIRED]=!0,c.field_options={},("function"==typeof(d=b.fields[a]).defaultAttributes?d.defaultAttributes(c):void 0)||c},simple_format:function(a){return null!=a?a.replace(/\n/g,"
"):void 0}},b.options={BUTTON_CLASS:"fb-button",HTTP_ENDPOINT:"",HTTP_METHOD:"POST",AUTOSAVE:!0,CLEAR_FIELD_CONFIRM:!1,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!"}},b.fields={},b.inputFields={},b.nonInputFields={},b.registerField=function(a,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 c.field_type=a,b.fields[a]=c,"non_input"===c.type?b.nonInputFields[a]=c:b.inputFields[a]=c},b}(),window.Formbuilder=c,"undefined"!=typeof module&&null!==module?module.exports=c:window.Formbuilder=c}.call(this),function(){Formbuilder.registerField("address",{order:50,view:"
\n \n \n \n \n
\n\n
\n \n \n \n \n\n \n \n \n \n
\n\n
\n \n \n \n \n\n \n \n \n \n
",edit:"",addButton:' Address'})}.call(this),function(){Formbuilder.registerField("checkboxes",{order:10,view:"<% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n
\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n
\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",{order:20,view:"
\n \n \n \n \n\n /\n\n \n \n \n \n\n /\n\n \n \n \n \n
",edit:"",addButton:' Date'})}.call(this),function(){Formbuilder.registerField("dropdown",{order:24,view:"",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",{order:40,view:"",edit:"",addButton:' Email'})}.call(this),function(){}.call(this),function(){Formbuilder.registerField("number",{order:30,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",{order:5,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",{order:45,view:"
\n $\n \n \n \n \n .\n \n \n \n \n
",edit:"",addButton:' Price'})}.call(this),function(){Formbuilder.registerField("radio",{order:15,view:"<% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n
\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n
\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",{order:0,type:"non_input",view:"\n

<%= rf.get(Formbuilder.options.mappings.DESCRIPTION) %>

",edit:"
Label
\n\n",addButton:" Section Break"})}.call(this),function(){Formbuilder.registerField("text",{order:0,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",{order:25,view:"
\n \n \n \n \n\n :\n\n \n \n \n \n\n :\n\n \n \n \n \n\n \n \n \n
",edit:"",addButton:' Time'})}.call(this),function(){Formbuilder.registerField("website",{order:35,view:"",edit:"",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="";_.escape}with(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="";_.escape}with(obj)__p+="
\n \n \n \n
";return __p},this.Formbuilder.templates["edit/base_non_input"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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="";_.escape}with(obj)__p+="\n";return __p},this.Formbuilder.templates["edit/common"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+="
Label
\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="";_.escape}with(obj)__p+="
Integer only
\n\n";return __p},this.Formbuilder.templates["edit/label_description"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+="\n";return __p},this.Formbuilder.templates["edit/min_max"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+='
Minimum / Maximum
\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="";_.escape}with(obj)__p+='
Length Limit
\n\nMin\n\n\n  \n\nMax\n\n\n  \n\n\n';return __p},this.Formbuilder.templates["edit/options"]=function(obj){obj||(obj={});{var __t,__p="";_.escape,Array.prototype.join}with(obj)__p+="
Options
\n\n","undefined"!=typeof includeBlank&&(__p+="\n \n"),__p+="\n\n
\n \n \n \n \n
\n\n',"undefined"!=typeof includeOther&&(__p+="\n \n'),__p+="\n\n\n';return __p},this.Formbuilder.templates["edit/size"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+="
Size
\n\n';return __p},this.Formbuilder.templates["edit/units"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+='
Units
\n\n';return __p},this.Formbuilder.templates.page=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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="";_.escape,Array.prototype.join}with(obj)__p+="
\n
\n
\n ",_.each(_.sortBy(Formbuilder.inputFields,"order"),function(a){__p+='\n \n '+(null==(__t=a.addButton)?"":__t)+"\n \n "}),__p+="\n
\n\n \n
\n
";return __p},this.Formbuilder.templates["partials/edit_field"]=function(obj){obj||(obj={});{var __p="";_.escape}with(obj)__p+="
\n
\n
\n";return __p},this.Formbuilder.templates["partials/left_side"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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="";_.escape}with(obj)__p+="
\n
No response fields
\n
\n
\n";return __p},this.Formbuilder.templates["partials/save_button"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(obj)__p+="
\n \n
";return __p},this.Formbuilder.templates["view/base"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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 __p="";_.escape}with(obj)__p+="";return __p},this.Formbuilder.templates["view/description"]=function(obj){obj||(obj={});{var __t,__p="";_.escape}with(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="";_.escape}with(obj)__p+="
\n \n \n
';return __p},this.Formbuilder.templates["view/label"]=function(obj){obj||(obj={});{var __t,__p="";_.escape,Array.prototype.join}with(obj)__p+="\n";return __p}; \ No newline at end of file diff --git a/dist/formbuilder.js b/dist/formbuilder.js index 56e87356..04774416 100644 --- a/dist/formbuilder.js +++ b/dist/formbuilder.js @@ -10,33 +10,27 @@ } }; - rivets.configure({ - prefix: "rv", - adapter: { - subscribe: function(obj, keypath, callback) { - callback.wrapped = function(m, v) { - return callback(v); - }; - return obj.on('change:' + keypath, callback.wrapped); - }, - unsubscribe: function(obj, keypath, callback) { - return obj.off('change:' + keypath, callback.wrapped); - }, - read: function(obj, keypath) { - if (keypath === "cid") { - return obj.cid; - } - return obj.get(keypath); - }, - publish: function(obj, keypath, value) { - if (obj.cid) { - return obj.set(keypath, value); - } else { - return obj[keypath] = value; - } + rivets.adapters[':'] = { + subscribe: function(obj, keypath, callback) { + return obj.on('change:' + keypath, callback); + }, + unsubscribe: function(obj, keypath, callback) { + return obj.off('change:' + keypath, callback); + }, + read: function(obj, keypath) { + if (keypath === "cid") { + return obj.cid; + } + return obj.get(keypath); + }, + publish: function(obj, keypath, value) { + if (obj.cid) { + return obj.set(keypath, value); + } else { + return obj[keypath] = value; } } - }); + }; }).call(this); @@ -55,6 +49,10 @@ FormbuilderModel.prototype.sync = function() {}; + FormbuilderModel.prototype.initialize = function() { + return this.on('change', this.log); + }; + FormbuilderModel.prototype.indexInDOM = function() { var $wrapper, _this = this; @@ -68,9 +66,13 @@ return Formbuilder.inputFields[this.get(Formbuilder.options.mappings.FIELD_TYPE)] != null; }; + FormbuilderModel.prototype.log = function() { + return console.log(this); + }; + return FormbuilderModel; - })(Backbone.DeepModel); + })(Backbone.NestedModel); FormbuilderCollection = (function(_super) { __extends(FormbuilderCollection, _super); @@ -657,7 +659,7 @@ (function() { Formbuilder.registerField('checkboxes', { order: 10, - view: "<% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n
\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n
\n \n\n \n
\n<% } %>", + view: "<% for (i = 0; i < (rf.get(Formbuilder.options.mappings.OPTIONS).length || []); i++) {%>\n
\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n
\n \n\n \n
\n<% } %>", edit: "<%= Formbuilder.templates['edit/options']({ includeOther: true }) %>", addButton: " Checkboxes", defaultAttributes: function(attrs) { @@ -761,7 +763,7 @@ (function() { Formbuilder.registerField('radio', { order: 15, - view: "<% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %>\n
\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n
\n \n\n \n
\n<% } %>", + view: "<% for (i = 0; i < (rf.get(Formbuilder.options.mappings.OPTIONS).length || []); i++) {%>\n
\n \n
\n<% } %>\n\n<% if (rf.get(Formbuilder.options.mappings.INCLUDE_OTHER)) { %>\n
\n \n\n \n
\n<% } %>", edit: "<%= Formbuilder.templates['edit/options']({ includeOther: true }) %>", addButton: " Multiple Choice", defaultAttributes: function(attrs) { @@ -785,7 +787,7 @@ order: 0, type: 'non_input', view: "\n

<%= rf.get(Formbuilder.options.mappings.DESCRIPTION) %>

", - edit: "
Label
\n\n", + edit: "
Label
\n\n", addButton: " Section Break" }); @@ -848,9 +850,9 @@ this["Formbuilder"]["templates"]["edit/base_header"] = function(obj) { obj || (obj = {}); var __t, __p = '', __e = _.escape; with (obj) { -__p += '
\n \n \n \n \n
'; @@ -876,9 +878,9 @@ this["Formbuilder"]["templates"]["edit/checkboxes"] = function(obj) { obj || (obj = {}); var __t, __p = '', __e = _.escape; with (obj) { -__p += '\n'; @@ -904,7 +906,7 @@ this["Formbuilder"]["templates"]["edit/integer_only"] = function(obj) { obj || (obj = {}); var __t, __p = '', __e = _.escape; with (obj) { -__p += '
Integer only
\n
\n\n'; @@ -916,9 +918,9 @@ this["Formbuilder"]["templates"]["edit/label_description"] = function(obj) { obj || (obj = {}); var __t, __p = '', __e = _.escape; with (obj) { -__p += '\n'; @@ -930,9 +932,9 @@ this["Formbuilder"]["templates"]["edit/min_max"] = function(obj) { obj || (obj = {}); var __t, __p = '', __e = _.escape; with (obj) { -__p += '
Minimum / Maximum
\n\nAbove\n\n\n  \n\nBelow\n\n\n  \n\nBelow\n\n'; @@ -944,11 +946,11 @@ this["Formbuilder"]["templates"]["edit/min_max_length"] = function(obj) { obj || (obj = {}); var __t, __p = '', __e = _.escape; with (obj) { -__p += '
Length Limit
\n\nMin\n\n\n  \n\nMax\n\n\n  \n\nMax\n\n\n  \n\n\n \n \n\n'; @@ -963,23 +965,23 @@ function print() { __p += __j.call(arguments, '') } with (obj) { __p += '
Options
\n\n'; if (typeof includeBlank !== 'undefined'){ ; -__p += '\n \n'; } ; -__p += '\n\n
\n \n \n \n \n \n \n
\n\n'; if (typeof includeOther !== 'undefined'){ ; -__p += '\n \n'; } ; -__p += '\n\n\n'; @@ -991,7 +993,7 @@ this["Formbuilder"]["templates"]["edit/size"] = function(obj) { obj || (obj = {}); var __t, __p = '', __e = _.escape; with (obj) { -__p += '
Size
\n\n'; @@ -1003,7 +1005,7 @@ this["Formbuilder"]["templates"]["edit/units"] = function(obj) { obj || (obj = {}); var __t, __p = '', __e = _.escape; with (obj) { -__p += '
Units
\n\n'; diff --git a/src/scripts/fields/checkboxes.coffee b/src/scripts/fields/checkboxes.coffee index 89368a71..77021476 100644 --- a/src/scripts/fields/checkboxes.coffee +++ b/src/scripts/fields/checkboxes.coffee @@ -3,10 +3,10 @@ Formbuilder.registerField 'checkboxes', order: 10 view: """ - <% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %> + <% for (i = 0; i < (rf.get(Formbuilder.options.mappings.OPTIONS).length || []); i++) {%>
diff --git a/src/scripts/fields/radio.coffee b/src/scripts/fields/radio.coffee index 14dbfaf0..56c7f62c 100644 --- a/src/scripts/fields/radio.coffee +++ b/src/scripts/fields/radio.coffee @@ -3,7 +3,7 @@ Formbuilder.registerField 'radio', order: 15 view: """ - <% for (i in (rf.get(Formbuilder.options.mappings.OPTIONS) || [])) { %> + <% for (i = 0; i < (rf.get(Formbuilder.options.mappings.OPTIONS).length || []); i++) {%>