/
traction.min.js
1 lines (1 loc) · 25 KB
/
traction.min.js
1
(function(){window.Traction={Rendering:{},Bindings:{},TemplateHelpers:{},Rails:{},Forms:{},config:{templatePath:"templates",fieldClassName:"field",fieldWithErrorsClass:"error",inlineErrorsClass:"inline-errors",formatters:{},templateHelpers:{}}}}).call(this),function(){Traction.ComputedAttribute=function(){function a(a,b){this.attribute=a,this.computation=b}return a.prototype.bindTo=function(a){var b,c,d,e;for(this.model=a,e=this._dependencies(),c=0,d=e.length;d>c;c++)b=e[c],this.model.on("change:"+b,this._assign,this);return this._assign()},a.prototype._dependencies=function(){return _.map(this._getterCalls(),function(a){return a.replace(/this\.get\("/,"").replace(/\W/g,"")})},a.prototype._getterCalls=function(){return this.computation.toString().match(/this\.get\(.*?\)/g)},a.prototype._assign=function(){return this.model.set(this.attribute,this.computation.apply(this.model))},a}(),Traction.ComputedAttributes={_assignComputedAttributes:function(){var a,b,c,d;this.computedAttributes||(this.computedAttributes={}),c=this.computedAttributes,d=[];for(a in c)b=c[a],d.push(new Traction.ComputedAttribute(a,b).bindTo(this));return d}}}.call(this),function(){Traction.IE={supportsInnerHTMLForTag:function(a){var b;return"COL"===(b=a.toUpperCase())||"COLGROUP"===b||"FRAMESET"===b||"HEAD"===b||"HTML"===b||"STYLE"===b||"TABLE"===b||"TBODY"===b||"TFOOT"===b||"THEAD"===b||"TITLE"===b||"TR"===b}}}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Model=function(b){function c(){c.__super__.constructor.apply(this,arguments),this._assignComputedAttributes()}return a(c,b),_.extend(c.prototype,Traction.ComputedAttributes),c.prototype.associations={},c.prototype.toggle=function(a){return this.set(a,!this.get(a))},c.prototype.set=function(a,b,d){var e;return"object"==typeof a?(e=_.clone(a),d=b):(e={},e[a]=b),this._setAssociations(e,d||{}),c.__super__.set.call(this,e,d)},c.prototype.url=function(){return this.get("url")||c.__super__.url.apply(this,arguments)},c.prototype._setAssociations=function(a,b){var c,d,e,f,g,h,i,j;h=this.associations,i=[];for(c in h){if(e=h[c],f=a[c],g=this.get(c)){if(!(c in a))continue;d=this._updateAssociation(e,c,f),d&&!b.silent&&this.trigger("change:"+c,g)}else this._createAssociation(e,c,f);delete a[c],(j=a[c+"_url"])?i.push(this.get(c).url=j):i.push(void 0)}return i},c.prototype._createAssociation=function(a,b,c){return c instanceof a?this.attributes[b]=c:(c=new a(c),this.attributes[b]=c)},c.prototype._updateAssociation=function(a,b,c){var d,e;return e=!1,d=function(a){return function(c){var d;return d=function(){return e=!0},a.get(b).on("change add remove",d),c(),a.get(b).off("change add remove",d)}}(this),c instanceof a||!c?this._isCollection(this.get(b))&&this._isCollection(c)?d(function(a){return function(){return a.attributes[b].set(c.models)}}(this)):(e=c!==this.get(b),this.attributes[b]=c):d(function(a){return function(){return a.get(b).set(c)}}(this)),e},c.prototype._isCollection=function(a){return null!=a?a.models:void 0},c}(Backbone.Model)}.call(this),function(){Traction.Decorator=function(){function a(a){this.decorated=a,_.defaults(this,this.decorated),this._attributesComputable()&&this._assignComputedAttributes()}return _.extend(a.prototype,Traction.ComputedAttributes),a.prototype._attributesComputable=function(){return this.on&&this.get&&this.set},a}(),Traction.Decorator.extend=Backbone.Model.extend}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.View=function(b){function c(a){this._initializeCallbacks(),this.invokeCallbacks("before:initialize"),this.children=new Traction.ViewCollection,this.decorator&&(a.model=this.buildDecorator(a.model)),c.__super__.constructor.apply(this,arguments),this.renderer=this.buildRenderer(a||{}),this.invokeCallbacks("after:initialize")}return a(c,b),c.prototype.setElement=function(){return c.__super__.setElement.apply(this,arguments),this.renderer=this.buildRenderer({el:this.el})},c.prototype.buildRenderer=function(a){return this.template?new Traction.Rendering.TemplateStrategy({template:this.template,renderWithin:this.el}):a.el?new Traction.Rendering.PrerenderedStrategy({renderWithin:this.el}):new Traction.Rendering.AppendStrategy({renderWithin:this.el})},c.prototype.buildDecorator=function(a){var b;return _.isFunction(this.decorator)?new this.decorator(a):new(b=Traction.Decorator.extend(this.decorator))(a)},c.prototype.proxyEvent=function(a,b,c){var d;return d=function(a){return function(){var d;return d=Array.prototype.slice.call(arguments),d.unshift(c||b),a.trigger.apply(a,d)}}(this),this.listenTo(a,b,d)},c.prototype.render=function(){return this.invokeCallbacks("before:render"),this.children.render(),this.renderer.call({bindTo:this.model,children:this.children}),this.invokeCallbacks("after:render"),this},c.prototype.delegateEvents=function(){return c.__super__.delegateEvents.apply(this,arguments),this.children.each(function(a){return a.delegateEvents()})},c.prototype.remove=function(){var a;return this.invokeCallbacks("before:remove"),c.__super__.remove.apply(this,arguments),"function"==typeof(a=this.renderer).destroy&&a.destroy(),this.children.each(function(a){return a.remove()}),this.invokeCallbacks("after:remove")},c.prototype.invokeCallbacks=function(a){var b,c,d,e,f;for(e=this._callbacks[a],f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(this[b]());return f},c.prototype._initializeCallbacks=function(){var a,b,c,d;this._callbacks={"before:initialize":[],"after:initialize":[],"before:render":[],"after:render":[],"before:remove":[],"after:remove":[]},c=this.callbacks||{},d=[];for(b in c)a=c[b],d.push(this._callbacks[b]=a.split(" "));return d},c}(Backbone.View),Traction.View.mixin=function(a){return _.extend(this.prototype,a)},Traction.View["extends"]=function(a){return this.mixin(a.prototype)}}.call(this),function(){Traction.ViewCollection=function(){function a(){this.collection={}}return _.extend(a.prototype,Backbone.Events),a.prototype.add=function(a,b){return b?this.collection[a]=b:(b=a,this.collection[_.uniqueId()]=b),b.on&&b.off?this.listenTo(b,"all",function(a){return function(){var c;return c=Array.prototype.slice.call(arguments),c=[c[0],b].concat(c.slice(1)),a.trigger.apply(a,c)}}(this)):void 0},a.prototype.broadcastOn=function(a,b){return this.listenTo(this,a,function(a){return function(c){return a.each(function(a){return a!==c?b(a):void 0})}}(this))},a.prototype.destroy=function(){return this.each(function(a){return a.remove()}),this.collection={}},a.prototype.get=function(a){return this.collection[a]},a.prototype.each=function(a){var b,c,d,e;d=this.collection,e=[];for(c in d)b=d[c],e.push(a(b,c));return e},a.prototype.map=function(a){return _.map(this.collection,function(b,c){return a(b,c)})},a.prototype.render=function(){return this.each(function(a){return a.render().delegateEvents()}),this},a.prototype.els=function(){return this.map(function(a){return a.el})},a.prototype.views=function(){return _.values(this.collection)},a}()}.call(this),function(){Traction.TemplateHelpers.Formatting={downcase:function(a){return a.toLowerCase()},upcase:function(a){return a.toUpperCase()},append:function(a,b){return a+b},prepend:function(a,b){return a+b},nonBreaking:function(a){return a?a.replace(/\s/g," "):" "},datetime:function(a,b){return null==b&&(b="L h:mm a"),a=moment(a||null),a?a.format(b):""},currency:function(a,b){return null==b&&(b="$"),a?b+_.string.numberFormat(parseFloat(a),2):""}}}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Rendering.NodeStrategy=function(b){function c(){c.__super__.constructor.apply(this,arguments),this.bindings=[]}return a(c,b),c.prototype.events={"click [data-emit]:not(form)":"_emit","submit form[data-emit]":"_emit"},c.prototype.destroy=function(){return _.each(this.bindings,function(a){return a.destroy()})},c.prototype.call=function(a){return null==a&&(a={}),a.bindTo&&this._applyBindings(a.bindTo),a.children?this._outlet(a.children):void 0},c.prototype._outlet=function(a){return this.$("script[data-outlet]").each(function(b){return function(b,c){var d;return(d=$(c).data("outlet"))?$(c).replaceWith(a.get(d).el):$(c).replaceWith(a.els())}}(this))},c.prototype._applyBindings=function(a){var b,c,d,e;for(e=this.bindings,c=0,d=e.length;d>c;c++)b=e[c],b.destroy();return this.$("[data-bind]").each(function(b){return function(c,d){var e,f,g,h,i;for(g=$(d).data("bind").split(" "),h=[],e=0,f=g.length;f>e;e++)i=g[e],h.push(b.bindings.push(Traction.Bindings.Factory(d,i).bindTo(a)));return h}}(this))},c.prototype._emit=function(a){var b,c,d,e,f;for(c=a.currentTarget.getAttribute("data-emit").split(" "),f=[],d=0,e=c.length;e>d;d++)b=c[d],f.push(this.$el.trigger(b,a));return f},c}(Backbone.View)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Rendering.AppendStrategy=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.initialize=function(a){return this.setElement(a.renderWithin)},c.prototype.call=function(a){return null==a&&(a={}),this.$el.empty(),null!=a.children?this.$el.append(a.children.els()):void 0},c}(Backbone.View)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Rendering.PrerenderedStrategy=function(b){function c(a){this.setElement(a.renderWithin),c.__super__.constructor.apply(this,arguments)}return a(c,b),c}(Traction.Rendering.NodeStrategy)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Rendering.TemplateStrategy=function(b){function c(a){this.setElement(a.renderWithin),this.template=this.findTemplate(a.template),c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.defaultTemplateFinder=function(a){var b;return b=Traction.config.templatePath+"/"+a,JST[b]},c.prototype.findTemplate=function(a){return(Traction.config.findTemplate||this.defaultTemplateFinder)(a)||function(){throw"Missing template: "+a}()},c.prototype.call=function(a){return null==a&&(a={}),this.insert(this._template({context:a.bindTo})),c.__super__.call.call(this,a)},c.prototype.buildOutlet=function(a){return a||(a=""),"<script data-outlet='"+a+"'></script>"},c.prototype.insert=function(a){return Traction.config.supportIE&&Traction.IE.supportsInnerHTMLForTag(this.el.tagName)?this.$el.html(a):this.el.innerHTML=a},c.prototype._template=function(a){return this.template(_.extend(a||{},this._defaultTemplateOptions()))},c.prototype._defaultTemplateOptions=function(){return _.extend({outlet:this.buildOutlet},Traction.config.templateHelpers)},c}(Traction.Rendering.NodeStrategy)}.call(this),function(){Traction.Bindings.Binding=function(){function a(){}return a.prototype.bindTo=function(a){return this.model=a,this.model.on("change:"+this.property,this.update,this),this.update(),this},a.prototype.destroy=function(){return this.model.off(null,null,this)},a}()}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Bindings.ContentBinding=function(b){function c(a,b){this.el=a,this.specification=b,this.property=this.specification}return a(c,b),c.prototype.update=function(a){return this.el.innerHTML=this.model.get(this.property)||""},c}(Traction.Bindings.Binding)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty,c=[].slice;Traction.Bindings.FormattedContentBinding=function(b){function d(a,b){var d;this.el=a,this.specification=b,d=this.specification.split("|"),this.property=d[0],this.formatters=2<=d.length?c.call(d,1):[],this.formattingFunctions=_.map(this.formatters,function(a){return function(b){return a._callFormattingFunction(b)}}(this))}return a(d,b),d.prototype.update=function(a){return this.el.innerHTML=_.reduce(this.formattingFunctions,function(a,b){return b(a)},this.model.get(this.property))},d.prototype._callFormattingFunction=function(a){var b,d,e;if(e=this._extractArgs(a),a=e[0],b=2<=e.length?c.call(e,1):[],d=this._formatters()[a])return function(a){return d.apply(this,[a].concat(b))};throw"Can't find formatter: "+a},d.prototype._extractArgs=function(a){var b;return b=_.str.reverse(a).split(/:(?!\\)/).reverse(),_.map(b,function(a){return _.str.reverse(a).replace(/\\:/g,":")})},d.prototype._formatters=function(){return _.extend(Traction.TemplateHelpers.Formatting,Traction.config.formatters)},d}(Traction.Bindings.Binding)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Bindings.AttributeBinding=function(b){function c(a,b){var c;this.el=a,this.specification=b,c=this.specification.split(":"),this.attribute=c[0],this.property=c[1],this.trueValue=c[2],this.falseValue=c[3]}return a(c,b),c.prototype.update=function(a){return this._hasBooleanSpecification()?this._booleanUpdate():this._directUpdate()},c.prototype._hasBooleanSpecification=function(){return null!=this.trueValue},c.prototype._booleanUpdate=function(){if(this._currentValue()){if(this._addValueToAttribute(this.trueValue),this.falseValue)return this._removeValueFromAttribute(this.falseValue)}else if(this._removeValueFromAttribute(this.trueValue),this.falseValue)return this._addValueToAttribute(this.falseValue)},c.prototype._directUpdate=function(){return this._removeValueFromAttribute(this.previousValue),this._addValueToAttribute(this._currentValue()),this.previousValue=this._currentValue()},c.prototype._addValueToAttribute=function(a){return this._setAttribute(_.union(this._existingValues(),[a]))},c.prototype._removeValueFromAttribute=function(a){return this._setAttribute(_.without(this._existingValues(),a))},c.prototype._existingValues=function(){return($(this.el).attr(this.attribute)||"").split(" ")},c.prototype._setAttribute=function(a){return $(this.el).attr(this.attribute,_.string.clean(a.join(" ")))},c.prototype._currentValue=function(){return this.model.get(this.property)},c}(Traction.Bindings.Binding)}.call(this),function(){Traction.Bindings.Factory=function(a,b){return b.indexOf("|")>0?new Traction.Bindings.FormattedContentBinding(a,b):b.indexOf(":")>0?new Traction.Bindings.AttributeBinding(a,b):new Traction.Bindings.ContentBinding(a,b)}}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Rails.Model=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.initialize=function(){return this._isBaseClass()||this.paramRoot||(this.paramRoot=this._inferParamRoot()),this.on("error",this.parseErrors,this)},c.prototype.parseErrors=function(a,b){var c;return this.errors=null!=(c=$.parseJSON(b.responseText))?c.errors:void 0},c.prototype.patch=function(){var a;return this.paramRoot?(a={},a[this.paramRoot]=this.changedAttributes()):a=this.changedAttributes(),this.sync("update",this,{attrs:a})},c.prototype.toJSON=function(){var a,b,d,e,f;if(this.persists){for(d={},f=this.persists,b=0,e=f.length;e>b;b++)a=f[b],d[a]=this.get(a);return d}return c.__super__.toJSON.apply(this,arguments)},c.prototype._inferParamRoot=function(){return _.string.underscored(this._className())},c.prototype._className=function(){return this.constructor.toString().match(/function\s(.*?)\(/)[1].toString()},c.prototype._isBaseClass=function(){return this.constructor===Traction.Rails.Model},c}(Traction.Model)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Rails.Collection=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.model=Traction.Rails.Model,c.prototype.build=function(a){var b;return null==a&&(a={}),b=new this.model(a),b.urlRoot=this.url,b},c}(Backbone.Collection)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Forms.Field=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.labelTemplate=_.template("<label for=\"<%= options.id %>\">\n <% if(options.required) { %><i class='required-icon'>*</i><% } %> <%= options.label %>\n</label>"),c.prototype.inputSelector="input",c.prototype.className=function(){return Traction.config.fieldClassName},c.prototype.initialize=function(a){return this.options=_.extend(this._defaults(),{placeholder:a.label||""},a),this.classConfig={errorWrapper:Traction.config.fieldWithErrorsClass,inlineErrors:Traction.config.inlineErrorsClass},this.model?this._bind():void 0},c.prototype.setModel=function(a){return this._unbind(),this.model=a,this._bind(),this},c.prototype.render=function(){return this._empty(),this.options.label!==!1&&this._renderLabel(),this._renderInput(),this.options.required&&this._designateAsRequired(),this.reset(),this.options.disabled&&this.disable(),this},c.prototype.renderErrors=function(a){return this.$el.addClass(this.classConfig.errorWrapper).append('<span class="'+this.classConfig.inlineErrors+'">'+a.join(", ")+"</span>")},c.prototype.disable=function(){return this.options.disabled=!0,this._input().attr("disabled","disabled")},c.prototype.isDisabled=function(){return this._input().is(":disabled")},c.prototype.enable=function(){return this.options.disabled=!1,this._input().removeAttr("disabled")},c.prototype.get=function(){return this._input().val()},c.prototype.set=function(a){return this._input().val(a)},c.prototype.clear=function(){return this.set(""),this.clearErrors()},c.prototype.clearErrors=function(){return this.$el.removeClass(this.classConfig.errorWrapper),this.$("."+this.classConfig.inlineErrors).remove()},c.prototype.rerenderErrors=function(a){return this.clearErrors(),this.renderErrors(a)},c.prototype.reset=function(){return this.set(this.model.get(this.options.attribute))},c.prototype.commit=function(a){return null==a&&(a={}),this.model.set(this.options.attribute,this.get()),(null!=a?a.silent:void 0)?void 0:this.trigger("commit",this.model)},c.prototype.applyAutoCommit=function(){return this.options.autoCommit?this.commit():void 0},c.prototype._bind=function(){return this.listenTo(this.model,"change:"+this.options.attribute,this.reset)},c.prototype._unbind=function(){return this.stopListening(this.model)},c.prototype._input=function(){return this.options.cache?this.input||(this.input=this.$(this.inputSelector)):this.$(this.inputSelector)},c.prototype._empty=function(){return this.$el.empty(),this.input=null},c.prototype._renderLabel=function(){return this.$el.append(this.labelTemplate({options:this.options}))},c.prototype._renderInput=function(){return this.$el.append(this.inputTemplate({options:this.options}))},c.prototype._designateAsRequired=function(){return this.$el.addClass("required")},c.prototype._defaults=function(a){return{id:this.cid,autoCommit:!0,required:!1,cache:!0}},c}(Backbone.View)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Forms.TextField=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.inputTemplate=_.template('<input id="<%= options.id %>" type="text" name="<%= options.name %>" placeholder="<%= options.placeholder %>"/>'),c.prototype.events={"change input":"applyAutoCommit"},c}(Traction.Forms.Field)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Forms.TextArea=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.inputTemplate=_.template('<textarea id="<%= options.id %>" name="<%= options.name %>" placeholder="<%= options.placeholder %>"/>'),c.prototype.inputSelector="textarea",c.prototype.events={"change textarea":"applyAutoCommit"},c}(Traction.Forms.Field)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Forms.Select=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.inputTemplate=_.template('<select id="<%= options.id %>" name="<%= options.name %>" <%= options.multiple %> >\n <% if(options.includeBlank) { %><option value=""><%= options.includeBlank %></option><% } %>\n <% _.each(options.options, function(value, label){ %>\n <option value="<%= value %>"><%= label %></option>\n <% }) %>\n</select>'),c.prototype.inputSelector="select",c.prototype.events={"change select":"applyAutoCommit"},c.prototype.initialize=function(a){return null==a&&(a={}),a.multiple=a.multiple?"multiple":"",c.__super__.initialize.apply(this,arguments)},c.prototype.clear=function(){return this._input().val(this._firstOptionValue()),this.clearErrors()},c.prototype.setOptions=function(a){return this.options.options=a,this.render()},c.prototype._firstOptionValue=function(){return this.$("option:first").attr("value")},c.prototype._renderInput=function(){return this.$el.append(this.inputTemplate({options:this.options}))},c}(Traction.Forms.Field)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Forms.Checkbox=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c.prototype.inputTemplate=_.template('<input type="checkbox" id="<%= options.id %>" name="<%= options.name %>">'),c.prototype.events={"change input":"applyAutoCommit"},c.prototype.get=function(){return this._input().is(":checked")?this.options.checkedValue:this.options.uncheckedValue},c.prototype.set=function(a){return this._input().prop("checked",this._checkedTest(a))},c.prototype.clear=function(){return this.set(this.options.uncheckedValue),this.clearErrors()},c.prototype._defaults=function(){return _.extend(c.__super__._defaults.apply(this,arguments),{checkedValue:!0,uncheckedValue:null,checkedTest:function(a){return a===this.options.checkedValue}})},c.prototype._checkedTest=function(a){return this.options.checkedTest.call(this,a)},c}(Traction.Forms.Field)}.call(this),function(){var a=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},b={}.hasOwnProperty;Traction.Forms.Form=function(){function a(){}return a.prototype.addInput=function(a){var b,c;return a=_.extend(this._defaults(a),a),(c=a.name)&&delete a.name,(b=a.type)&&delete a.type,this.children.add(c,new b(a))},a.prototype.addInputs=function(a){var b,c,d;d=[];for(b in a)c=a[b],c.attribute=b,d.push(this.addInput(c));return d},a.prototype.serialize=function(){var a;return a={},this.children.each(function(b){return a[b.attribute]=b.val()}),a},a.prototype.renderErrors=function(){return this.children.each(function(a){return function(b,c){var d,e;return(d=null!=(e=a.model.errors)?e[c]:void 0)?"function"==typeof b.rerenderErrors?b.rerenderErrors(d):void 0:"function"==typeof b.clearErrors?b.clearErrors():void 0}}(this))},a.prototype.clearErrors=function(){return this.children.each(function(a){return"function"==typeof a.clearErrors?a.clearErrors():void 0})},a.prototype.clear=function(){return this.children.each(function(a){return"function"==typeof a.clear?a.clear():void 0})},a.prototype.commit=function(a){return this.children.each(function(b){return"function"==typeof b.commit?b.commit(a):void 0})},a.prototype.reset=function(){return this.children.each(function(a){return"function"==typeof a.reset?a.reset():void 0})},a.prototype._defaults=function(a){return{name:a.attribute,label:this._generateLabel(a.attribute),type:Traction.Forms.TextField,model:this.model}},a.prototype._generateLabel=function(a){return _.str.capitalize(_.str.humanize(a))},a}(),Traction.Forms.FormView=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return a(c,b),c["extends"](Traction.Forms.Form),c}(Traction.View)}.call(this);