forked from vecnatechnologies/backbone-torso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
torso-bundle.min.js
2 lines (2 loc) · 43.5 KB
/
torso-bundle.min.js
1
2
!function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone")):(e.Torso=e.Torso||{},e.Torso.Events=t(e._,e.Backbone))}(this,function(e,t){"use strict";var i=e.extend({},t.Events);return i}),function(e,t){"function"==typeof define&&define.amd?define(["backbone"],t):"object"==typeof exports?module.exports=t(require("backbone")):(e.Torso=e.Torso||{},e.Torso.Router=t(e.Backbone))}(this,function(e){"use strict";return e.Router.extend({})}),function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():(e.Torso=e.Torso||{},e.Torso.Mixins=e.Torso.Mixins||{},e.Torso.Mixins.cellPersistenceRemovalMixin=t())}(this,function(){"use strict";return{isModelCompatible:!1,save:function(){if(!this.isModelCompatible)throw"Cell does not have save"},fetch:function(){if(!this.isModelCompatible)throw"Cell does not have fetch"},sync:function(){if(!this.isModelCompatible)throw"Cell does not have sync"},url:function(){if(!this.isModelCompatible)throw"Cell does not have url"}}}),function(e,t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports?module.exports=t(require("jquery")):(e.Torso=e.Torso||{},e.Torso.Mixins=e.Torso.Mixins||{},e.Torso.Mixins.collectionLoading=t(e.jQuery||e.Zepto||e.ender||e.$))}(this,function(e){var t=function(t){return{constructor:function(i){t.call(this,i),this.loadedOnceDeferred=new e.Deferred,this.loadedOnce=!1,this.loading=!1},hasLoadedOnce:function(){return this.loadedOnce},isLoading:function(){return this.loading},getLoadedOncePromise:function(){return this.loadedOnceDeferred.promise()},fetch:function(e){return this.__loadWrapper(t.prototype.fetch,e)},__loadWrapper:function(t,i){var n=this;return this.loading=!0,this.trigger("load-begin"),e.when(t.call(n,i)).done(function(e,t,i){n.trigger("load-complete",{success:!0,data:e,textStatus:t,jqXHR:i})}).fail(function(e,t,i){n.trigger("load-complete",{success:!1,jqXHR:e,textStatus:t,errorThrown:i})}).always(function(){n.loadedOnce||(n.loadedOnce=!0,n.loadedOnceDeferred.resolve()),n.loading=!1})}}};return t}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","jquery"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("jquery")):(e.Torso=e.Torso||{},e.Torso.Mixins=e.Torso.Mixins||{},e.Torso.Mixins.collectionRegistration=t(e._,e.jQuery||e.Zepto||e.ender||e.$))}(this,function(e,t){var i=function(i){var n,o;return o=function(i,n){return i.constructor.extend(function(i,n,o){var s={getTrackedIds:function(){return this.trackedIds},fetch:function(){var e=this;return this.__loadWrapper(function(){return e.trackedIds&&e.trackedIds.length?n.fetchByIds({idsToFetch:e.trackedIds,setOptions:{remove:!1}}):t.Deferred().resolve().promise()})},trackIds:function(t){this.remove(e.difference(this.trackedIds,t)),n.registerIds(t,o),this.trackedIds=t},addModelAndTrack:function(e){this.add(e),this.trackNewId(e.id)},trackNewId:function(e){this.trackIds(this.getTrackedIds().concat(e))},fetchByIds:function(e){return this.trackIds(e),this.fetch()},requesterDispose:function(){n.removeRequster(o)}};return s}(i.constructor.__super__,i,n))},n=function(n){var s=function(t,i){n.requestMap[t]={array:i,dict:e.object(e.map(i,function(e){return[e,e]}))}};n.getRequesterIds=function(e){return this.requestMap[e]&&this.requestMap[e].array},n.getRequesterIdsAsDictionary=function(e){return this.requestMap[e]&&this.requestMap[e].dict},n.removeRequster=function(e){delete this.requestMap[e],delete this.knownPrivateCollections[e]},n.getRequesters=function(){return e.keys(this.requestMap)},n.getAllRequestedIds=function(){return this.collectionTrackedIds},n.createPrivateCollection=function(e,t){t=t||{},t.isRequester=!0,t.parentInstance=n;var i=o(n,e);return this.knownPrivateCollections[e]=new i(null,t),this.knownPrivateCollections[e]},n.registerIds=function(e,t){var i,o,r,a,d,u={},c=[];for(s(t,e),a=n.getRequesters(),d=a.length,o=0;d>o;o++)for(r=this.getRequesterIds(a[o]),i=0;i<r.length;i++)u[r[i]]=!0;for(i in u)c.push(i);this.collectionTrackedIds=c,this.polledFetch=function(){n.fetchByIds({setOptions:{remove:!0}})}},n.fetch=function(t){return t=t||{},this.fetchUsingTrackedIds?this.fetchByIds({setOptions:e.extend({remove:!0},t)}):i.fetch(t)},n.fetchByIds=function(i){return i=i||{},this.__loadWrapper(function(i){var o,s;return o=i.idsToFetch||n.collectionTrackedIds,s=n.lazyFetch?e.difference(o,this.models.pluck("id")):o,t.ajax({type:n.fetchHttpAction,url:n.url+n.getByIdsUrl,contentType:"application/json; charset=utf-8",data:JSON.stringify(s)}).done(function(e){var t,s,r,a,d,u,c,l,h=o.length,f=i.setOptions;for(n.set(n.parse(e),f),c=n.getRequesters(),u=c.length,s=0;u>s;s++){for(r=n.getRequesterIdsAsDictionary(c[s]),a=[],t=0;h>t;t++)r[o[t]]&&(l=n.get(o[t]),l&&a.push(l));d=n.knownPrivateCollections[c[s]],d.set(a,{remove:!1})}})},i)},n.setLazyFetch=function(e){this.lazyFetch=e},n.isLazyFetch=function(){return this.lazyFetch}},{constructor:function(e,t){t=t||{},i.call(this,e,t),this.isRequester=t.isRequester,this.parentInstance=t.parentInstance,this.isRequester?(this.trackedIds=[],this.listenTo(this.parentInstance,"load-begin",function(){this.trigger("cache-load-begin")}),this.listenTo(this.parentInstance,"load-complete",function(){this.trigger("cache-load-complete")})):(this.requestMap={},this.collectionTrackedIds=[],this.knownPrivateCollections={},this.getByIdsUrl=t.getByIdsUrl||"/ids",this.fetchHttpAction="POST",this.lazyFetch=t.lazyFetch||!1,this.fetchUsingTrackedIds=t.fetchUsingTrackedIds!==!1,n(this))},dispose:function(){this.unbind(),this.off(),this.stopListening(),this.stopPolling(),this.isRequester&&this.requesterDispose()},filterDefault:function(){return this.constructor(this)}}};return i}),function(e,t){"function"==typeof define&&define.amd?define(["backbone","jquery"],t):"object"==typeof exports?module.exports=t(require("backbone"),require("jquery")):t(e.Backbone,e.$)}(this,function(e,t){"use strict";return e.$=t,!0}),function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?t():(e.Torso=e.Torso||{},e.Torso.Utils=e.Torso.Utils||{},e.Torso.Utils.handlebarsUtils=t())}(this,function(){"use strict";return function(e){var t="feedback",i="model";e.registerHelper("labelFor",function(t,i){return e.helpers.formAttr(t,"for",i)}),e.registerHelper("bindModel",function(n,o){return e.helpers.formAttr(n,i+", "+t+", name, id",o)}),e.registerHelper("feedback",function(i,n){return e.helpers.formAttr(i,t,n)}),e.registerHelper("formAttr",function(n,o,s){var r,a,d=s.hash?s.hash.value:void 0,u=e.helpers.injectFieldIndices(n,s.hash),c="";for(o=o.split(","),r=0;r<o.length;r++)a=o[r].trim(),a===t?c+='data-feedback="'+u+'" ':a===i?c+='data-model="'+u+'" ':"name"===a?c+='name="'+e.helpers.dasherize(u)+'" ':"id"===a?(c+='id="'+e.helpers.dasherize(u),void 0!==d&&(c+="-"+d),c+='" '):"for"===a&&(c+='for="'+e.helpers.dasherize(u),void 0!==d&&(c+="-"+d),c+='" ');return void 0!==d&&(c+='value="'+d+'"'),new e.SafeString(c)}),e.registerHelper("dasherize",function(e){var t,i,n;return t=e.replace(/([A-Z])/g,function(e){return"-"+e.toLowerCase()}),i=t.replace(/\./g,function(){return"_"}),n=i.replace(/\[[0-9]+\]/g,function(e){return"-"+e.substring(1,e.length-1)})}),e.registerHelper("injectFieldIndices",function(e,t){return t?e.replace(/\[.+?\]/g,function(e){var i=t[e.substring(1,e.length-1)];return"["+(void 0===i?"":i)+"]"}):e})}}),function(e,t){"function"==typeof define&&define.amd?define(["backbone"],t):"object"==typeof exports?module.exports=t(require("backbone")):(e.Torso=e.Torso||{},e.Torso.history=t(e.Backbone))}(this,function(e){"use strict";return e.history}),function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():(e.Torso=e.Torso||{},e.Torso.Mixins=e.Torso.Mixins||{},e.Torso.Mixins.polling=t())}(this,function(){var e={pollTimeoutId:void 0,__pollStarted:!1,__pollInterval:5e3,isPolling:function(){return this.__pollStarted},startPolling:function(e){var t=this;e&&(this.__pollInterval=e),this.__pollStarted||(this.__pollStarted=!0,this.__poll(),this.pollTimeoutId=window.setInterval(function(){t.__poll()},this.__pollInterval))},stopPolling:function(){window.clearInterval(this.pollTimeoutId),this.__pollStarted=!1},polledFetch:function(){this.fetch()},__poll:function(){this.polledFetch()}};return e}),function(e,t){"function"==typeof define&&define.amd?define(["backbone","backbone.stickit"],t):"object"==typeof exports?(require("backbone.stickit"),t(require("backbone"))):t(e.Backbone)}(this,function(e){"use strict";e.Stickit.addHandler({selector:'input[type="radio"]',events:["change"],update:function(e,t){e.prop("checked",!1),e.filter('[value="'+t+'"]').prop("checked",!0)},getVal:function(e){return e.filter(":checked").val()}})}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","jquery"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("jquery")):(e.Torso=e.Torso||{},e.Torso.Utils=e.Torso.Utils||{},e.Torso.Utils.templateRenderer=t(e._,e.jQuery||e.Zepto||e.ender||e.$))}(this,function(e,t){"use strict";function i(e,i,n){var o,r=i.nodeType,a=e.nodeType;r!==a?t(e).replaceWith(i):(o=s[r]||s["default"])(e,i,n)}function n(n,o,s){var r,a,d,u,c,l=t(n),h=t(o),f=0;if(a=e.some(s,function(e){return l.is(e)}),!a){if(o.tagName!==n.tagName)return void l.replaceWith(o);for(c=n.attributes;f<c.length;)r=c[f].name,e.contains(r,o.attributes)||n.removeAttribute(r),f++;if(e.each(o.attributes,function(e){n.setAttribute(e.name,e.value)}),l.html()!==h.html())return u=h.contents(),d=l.contents(),u.length!==d.length?void l.html(h.html()):void d.each(function(e,t){i(t,u.get(e),s)})}}function o(e,i){var n=i.nodeValue!==e.nodeValue;n&&t(e).replaceWith(i)}var s={1:n,3:o,4:o,8:o,"default":function(e,i){t(e).replaceWith(i)}},r={render:function(e,i,n,o){var s,r=i(n),a=e.get(0);o=o||{},o.force?e.html(r):(s=this.copyTopElement(a),t(s).html(r),this.hotswapKeepCaret(a,s,o.ignoreElements))},hotswapKeepCaret:function(e,t,i){var n,o=document.activeElement;o&&this.supportsSelection(o)&&(n=this.getCaretPosition(o)),this.hotswap(e,t,i),o&&this.supportsSelection(o)&&this.setCaretPosition(o,n)},hotswap:i,copyTopElement:function(t){var i=document.createElement(t.tagName);return e.each(t.attributes,function(e){i.setAttribute(e.name,e.value)}),i},supportsSelection:function(e){return/text|password|search|tel|url/.test(e.type)},getCaretPosition:function(e){var t,i=0;return document.selection?(e.focus(),t=document.selection.createRange(),t.moveStart("character",-e.value.length),i=t.text.length):(e.selectionStart||0===e.selectionStart)&&(i=e.selectionStart),i},setCaretPosition:function(e,t){var i;e&&(e.createTextRange?(i=e.createTextRange(),i.move("character",t),i.select()):e.selectionStart||0===e.selectionStart?(e.focus(),e.setSelectionRange(t,t)):e.focus())}};return r}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./cellPersistenceRemovalMixin"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./cellPersistenceRemovalMixin")):(e.Torso=e.Torso||{},e.Torso.Cell=t(e._,e.Backbone,e.Torso.Mixins.cellPersistenceRemovalMixin))}(this,function(e,t,i){"use strict";var n=t.Model.extend({});return e.extend(n.prototype,i),n}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./pollingMixin","./collectionRegistrationMixin","./collectionLoadingMixin"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./pollingMixin"),require("./collectionRegistrationMixin"),require("./collectionLoadingMixin")):(e.Torso=e.Torso||{},e.Torso.Collection=t(e._,e.Backbone,e.Torso.Mixins.polling,e.Torso.Mixins.collectionRegistration,e.Torso.Mixins.collectionLoading))}(this,function(e,t,i,n,o){"use strict";var s=t.Collection.extend({});return e.extend(s.prototype,i),s=s.extend(o(s)),s=s.extend(n(s))}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./pollingMixin"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./pollingMixin")):(e.Torso=e.Torso||{},e.Torso.Model=t(e._,e.Backbone,e.Torso.Mixins.polling))}(this,function(e,t,i){"use strict";var n=t.Model.extend({});return e.extend(n.prototype,i),n}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./cellPersistenceRemovalMixin","backbone-nested"],t):"object"==typeof exports?(require("backbone-nested"),module.exports=t(require("underscore"),require("backbone"),require("./cellPersistenceRemovalMixin"))):(e.Torso=e.Torso||{},e.Torso.NestedCell=t(e._,e.Backbone,e.Torso.Mixins.cellPersistenceRemovalMixin))}(this,function(e,t,i){"use strict";var n=t.NestedModel.extend({});return e.extend(n.prototype,i),n}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./pollingMixin","backbone-nested"],t):"object"==typeof exports?(require("backbone-nested"),module.exports=t(require("underscore"),require("backbone"),require("./pollingMixin"))):(e.Torso=e.Torso||{},e.Torso.NestedModel=t(e._,e.Backbone,e.Torso.Mixins.polling))}(this,function(e,t,i){"use strict";var n=t.NestedModel.extend({});return e.extend(n.prototype,i),n}),function(e,t){"function"==typeof define&&define.amd?define(["./Cell"],t):"object"==typeof exports?module.exports=t(require("./Cell")):(e.Torso=e.Torso||{},e.Torso.ServiceCell=t(e.Torso.Cell))}(this,function(e){"use strict";var t=e.extend({});return t}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./templateRenderer","./Cell"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./templateRenderer"),require("./Cell")):(e.Torso=e.Torso||{},e.Torso.View=t(e._,e.Backbone,e.Torso.Utils.templateRenderer,e.Torso.Cell))}(this,function(e,t,i,n){"use strict";var o=t.View.extend({viewState:null,template:null,feedback:null,feedbackModel:null,__childViews:null,__isActive:!1,__isAttachedToParent:!1,__isDisposed:!1,__feedbackEvents:null,constructor:function(e){e=e||{},this.viewState=new n,this.feedbackModel=new n,this.__childViews={},this.__feedbackEvents=[],t.View.apply(this,arguments),e.noActivate||this.activate()},prepare:function(){return this.model?{model:this.model.toJSON(),view:this.viewState.toJSON()}:{view:this.viewState.toJSON()}},render:function(){this.unplug(),this.template&&this.templateRender(this.$el,this.template,this.prepare()),this.plug(),this.delegateEvents()},templateRender:function(e,t,n,o){this.detachChildViews(),i.render(e,t,n,o)},delegateEvents:function(){t.View.prototype.delegateEvents.call(this),this.__generateFeedbackBindings(),this.__generateFeedbackModelCallbacks(),e.each(this.__childViews,function(e){e.isAttachedToParent()&&e.delegateEvents()})},undelegateEvents:function(){t.View.prototype.undelegateEvents.call(this),e.each(this.__childViews,function(e){e.undelegateEvents()})},injectView:function(e,t,i){var n=this.$("[inject="+e+"]");t&&n.size()>0&&this.attachChildView(n,t,i)},detach:function(){this.isAttachedToParent()&&(this.injectionSite?this.$el.replaceWith(this.injectionSite):this.$el.detach(),this.undelegateEvents(),this.__isAttachedToParent=!1)},attach:function(e){this.isAttachedToParent()||(this.render(),this.injectionSite=e.replaceWith(this.$el),this.delegateEvents(),this.__isAttachedToParent=!0)},deactivate:function(){this.deactivateChildViews(),this.isActive()&&(this._deactivate(),this.__isActive=!1)},activate:function(){this.activateChildViews(),this.isActive()||(this._activate(),this.__isActive=!0)},dispose:function(){this._dispose(),this.detach(),this.deactivate(),this.disposeChildViews(),this.remove(),this.off(),this.stopListening(),this.viewState&&(this.viewState.off(),this.viewState.stopListening()),delete this.$el,delete this.el,this.__isDisposed=!0},_dispose:e.noop,_deactivate:e.noop,_activate:e.noop,unplug:e.noop,plug:e.noop,attachChildView:function(e,t,i){i=i||{},t.detach(),this.registerChildView(t),t.attach(e),i.noActivate||t.activate()},hasChildViews:function(){return!e.isEmpty(this.__childViews)},getChildViews:function(){return e.values(this.__childViews)},getChildView:function(e){return this.__childViews[e]},disposeChildViews:function(){e.each(this.__childViews,function(e){e.dispose()})},deactivateChildViews:function(){e.each(this.__childViews,function(e){e.deactivate()})},detachChildViews:function(){e.each(this.__childViews,function(e){e.detach()})},activateChildViews:function(){e.each(this.__childViews,function(e){e.activate()})},registerChildView:function(e){this.__childViews[e.cid]=e},unregisterChildView:function(e){delete this.__childViews[e.cid]},unregisterChildViews:function(){e.each(this.__childViews,function(e){this.unregisterChildView(e)},this)},isAttachedToParent:function(){return this.__isAttachedToParent},isActive:function(){return this.__isActive},isDisposed:function(){return this.__isDisposed},invokeFeedback:function(t,i,n){var o,s=e.find(this.feedback,function(i){var n=i.to;return e.isArray(n)?e.contains(n,t):t===n}),r=t;s&&(n&&(r=this.__substituteIndicesUsingMap(t,n)),o=s.then.call(this,i,n),this.__processFeedbackThenResult(o,r))},__generateFeedbackModelCallbacks:function(){var t=this;t.feedbackModel.off(),e.each(this.$("[data-feedback]"),function(i){var n=$(i).data("feedback");t.feedbackModel.on("change:"+n,function(i){return function(){var n,o=t.feedbackModel.get(i);o&&(n=t.$el.find('[data-feedback="'+i+'"]'),e.each(o,function(i,o){var s;s="_"===e.first(o)?t[o.slice(1)]:n[o],e.isArray(i)?s.apply(n,i):void 0!==i&&s.call(n,i)}))}}(n))}),e.each(t.feedbackModel.attributes,function(e,i){t.feedbackModel.trigger("change:"+i)})},__processFeedbackThenResult:function(e,t){var i=$.extend({},e);this.feedbackModel.set(t,i,{silent:!0}),this.feedbackModel.trigger("change:"+t)},__generateFeedbackBindings:function(){var t,i=this;for(t=0;t<this.__feedbackEvents.length;t++)this.off(null,this.__feedbackEvents[t]);this.__feedbackEvents=[],e.each(this.feedback,function(t){var n=[t.to];e.isArray(t.to)&&(n=t.to),e.each(n,function(n){var o=i.__getFeedbackDestinations(n),s=i.__getAllIndexTokens(n);e.each(o,function(n){var o,r,a,d,u,c,l,h;n=$(n),o=n.data("feedback"),r=i.__getAllIndexTokens(o),a={},e.each(s,function(e,t){a[e]=r[t]}),d=t.then,e.isString(d)?d=i[d]:e.isArray(d)&&(u=d.slice(),c=u[0],u.shift(),d=i[c].apply(i,u)),h={feedbackModelField:o,fn:d,indices:a},l=i.__generateWhenEvents(t.when,a),e.each(l,function(t){var n,o,s=function(e){var t,n,o;t=[e],o={},t.push(h.indices),n=h.fn.apply(i,t),i.__processFeedbackThenResult(n,h.feedbackModelField)};o=/^(\S+)\s*(.*)$/,n=t.match(o),i.$el.on(n[1]+".delegateEvents"+i.cid,n[2],e.bind(s,i))}),e.each(t.when.on,function(e){var t=function(){var t,n=[{args:arguments,type:e}];n.push(h.indices),t=h.fn.apply(i,n),i.__processFeedbackThenResult(t,h.feedbackModelField)};i.on(e,t,i),i.__feedbackEvents.push(t)})})})})},__getFeedbackDestinations:function(e){var t=this,i=this.__stripAllAttribute(e),n=e,o=e.indexOf("[");return o>0&&(n=e.substring(0,o)),this.$('[data-feedback^="'+n+'"]').filter(function(){return t.__stripAllAttribute($(this).data("feedback"))===i})},__generateWhenEvents:function(t,i){var n=this,o=[];return e.each(t,function(t,s){var r,a=[s],d="@"===s.charAt(0);"on"!==s&&(d&&(s=s.substring(1),r=n.__substituteIndicesUsingMap(s,i),a=e.flatten(n.__generateSubAttributes(r,n.model))),e.each(a,function(i){e.each(t,function(e){var t=e+" "+i;d&&(t=e+' [data-model="'+i+'"]'),o.push(t)})}))}),o},__getAllIndexTokens:function(t){return e.reduce(t.match(/\[.+?\]/g),function(e,t){var i=t.substring(1,t.length-1);return e.push(isNaN(i)?i:parseInt(i,10)),e},[])},__stripAllAttribute:function(e){return e=e.replace(/\[.+?\]/g,function(){return"[]"})},__substituteIndicesUsingMap:function(e,t){var i;return e.replace(/\[.?\]/g,function(e){return e.match(/\[\d+\]/g)||e.match(/\[\]/g)?e:(i=t[e.substring(1,e.length-1)],"["+(void 0===i?"":i)+"]")})},__generateSubAttributes:function(e,t){var i,n,o,s,r,a=e.indexOf("[]");if(-1===a)return[e];if(n=e.substring(0,a),o=e.substring(a+2),s=[],r=t.get(n),!r)return[e];for(i=0;i<r.length;i++)s.push(this.__generateSubAttributes(n+"["+i+"]"+o,t));return s}});return o}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","./NestedModel"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("./NestedModel")):(e.Torso=e.Torso||{},e.Torso.Mixins=e.Torso.Mixins||{},e.Torso.validation=t(e._,e.Torso.NestedModel),e.Torso.Mixins.validation=e.Torso.validation.mixin)}(this,function(e,t){"use strict";var i={forceUpdate:!1,selector:"name",labelFormatter:"sentenceCase",messageFormatter:"none",valid:Function.prototype,invalid:Function.prototype},n={formatLabel:function(e,t){return u[i.labelFormatter](e,t)},format:function(){return c[i.messageFormatter].apply(c,arguments)}},o=function(t,i,n){return i=i||{},n=n||"",e.each(t,function(e,s){t.hasOwnProperty(s)&&(e&&"object"==typeof e&&e.constructor===Object&&o(e,i,n+s+"."),i[n+s]=e)}),i},s=function(){var s=function(t,i){return i=i||e.keys(e.result(t,"validation")||{}),e.reduce(i,function(e,t){return e[t]=void 0,e},{})},a=function(t,i){var n=t.attributes;return e.isFunction(n)?n=n(i):e.isString(n)&&e.isFunction(l[n])&&(n=l[n](i)),e.isArray(n)?n:void 0},d=function(t,i){var n=t.validation?e.result(t,"validation")[i]||{}:{};return(e.isFunction(n)||e.isString(n))&&(n={fn:n}),e.isArray(n)||(n=[n]),e.reduce(n,function(t,i){return e.each(e.without(e.keys(i),"msg","msgKey"),function(e){t.push({fn:h[e],val:i[e],msg:i.msg,msgKey:i.msgKey})}),t},[])},u=function(e){var t,i,n=0,o=!0,s=[];for(t=e.indexOf("[",n);t>0&&o;)i=e.indexOf("]",n),s.push(parseInt(e.substring(t+1,i),10)),n=i+1,o=n>0,t=e.indexOf("[",n);return s},c=function(t,i,n){var o,s,r,a,d,u=t.indexOf("[]");if(e.isEmpty(n)&&(n=[]),-1===u)return{attr:t,index:n};for(s=t.substring(0,u),r=t.substring(u+2),a=[],o=0;o<i.get(s).length;o++)d=n.slice(),d.push(o),a.push(c(s+"["+o+"]"+r,i,d));return a},f=function(e){return t&&e instanceof t},p=function(e){return e.indexOf(".")>0||e.indexOf("]")>0},m=function(e){var t,i,n=0,o=!0;if(t=e.indexOf("[",n),0>t)return e;for(i=e.substring(0,t+1);t>0&&o;)n=e.indexOf("]",n)+1,o=n>0,t=e.indexOf("[",n),t>0&&(i+=e.substring(n-1,t+1));return i+=e.substring(n-1)},_=function(t,i,n,o,s,r){var a,d;return e.isArray(i)?e.reduce(i,function(e,i){return e.push(_(t,i,n,o,s,r+1)),e},[]):(d=i.index,a=i.attr,e.isUndefined(n)&&p(a)&&(n=t.get(a)),g(s,t,n,a,o,d))},g=function(t,i,o,s,r,a){return e.reduce(t,function(t,d){var u=e.extend({msgKey:d.msgKey},n,h),c=d.fn.call(u,o,s,d.val,i,r,a);return c===!1||t===!1?!1:c&&!t?e.result(e.extend({},d,n,h),"msg")||c:t},"")},v=function(t,i,n,o){var s,r,a,u=d(t,i);return r=c(i,t),a=_(t,r,n,o,u,0),e.isArray(a)&&(s=e.reduce(e.flatten(a),function(e,t){return e||t},!1),!s)?"":a},F=function(t,i,n){var o,s={},r=!0,a=e.clone(i);return e.each(n,function(e,i){o=v(t,i,e,a),o&&(s[i]=o,r=!1)}),{invalidAttrs:s,isValid:r}},b=function(t,i,n){var o,s,r=t.validation?e.result(t,"validation")||{}:{};return e.contains(e.keys(r),n)?v(t,n,i,e.extend({},t.attributes)):(o=u(n),n=m(n),s=d(t,n),g(s,t,i,n,e.extend({},t.attributes),o))},y=function(t,i){return{preValidate:function(t,i){var n,o=this,s={};return e.isArray(t)?(e.each(t,function(e){n=o.preValidate(e),n&&(s[e]=n)}),e.isEmpty(s)?void 0:s):e.isObject(t)?(e.each(t,function(e,t){n=o.preValidate(t,e),n&&(s[t]=n)}),e.isEmpty(s)?void 0:s):(e.isUndefined(i)&&f(this)&&(i=this.get(t)),b(this,i,t))},isValid:function(n){var s,r,d;return n=n||a(i,t),e.isString(n)?s=[n]:e.isArray(n)&&(s=n),s&&e.each(s,function(t){var n;n=f(this)?this.get(t):o(this.attributes)[t],r=b(this,n,t),r&&(d=d||{},d[t]=r),e.each(this.associatedViews,function(e){r?i.invalid(e,t,r,i.selector):i.valid(e,t,i.selector)},this)},this),n===!0&&(d=this.validate()),d&&this.trigger("invalid",this,d,{validationError:d}),s?!d:this.validation?this._isValid:!0},validate:function(n,r){var d,u,c,l,h,f,p,m=this;return d=!n,u=e.extend({},i,r),c=s(m,a(i,t)),l=e.extend({},c,m.attributes,n),h=o(l),f=n?o(n):h,p=F(m,l,e.pick(h,e.keys(c))),m._isValid=p.isValid,e.each(m.associatedViews,function(t){e.each(c,function(e,i){var n=p.invalidAttrs.hasOwnProperty(i),o=f.hasOwnProperty(i);n||u.valid(t,i,u.selector),n&&(o||d)&&u.invalid(t,i,p.invalidAttrs[i],u.selector)})}),e.defer(function(){m.trigger("validated",m._isValid,m,p.invalidAttrs),m.trigger("validated:"+(m._isValid?"valid":"invalid"),m,p.invalidAttrs)}),!u.forceUpdate&&e.intersection(e.keys(p.invalidAttrs),e.keys(f)).length>0?p.invalidAttrs:void 0}}},x=function(t,i,n){i.associatedViews?i.associatedViews.push(t):i.associatedViews=[t],e.extend(i,y(t,n))},T=function(t,i){i&&t.associatedViews.length>1?t.associatedViews=e.without(t.associatedViews,i):(delete t.validate,delete t.preValidate,delete t.isValid,delete t.associatedViews)},k=function(e){x(this.view,e,this.options)},w=function(e){T(e)};return{version:"0.11.3",configure:function(t){e.extend(i,t)},bind:function(t,n){n=e.extend({},i,r,n);var o=n.model||t.model,s=n.collection||t.collection;if("undefined"==typeof o&&"undefined"==typeof s)throw"Before you execute the binding your view must have a model or a collection.\nSee http://thedersen.com/projects/backbone-validation/#using-form-model-validation for more information.";o?x(t,o,n):s&&(s.each(function(e){x(t,e,n)}),s.bind("add",k,{view:t,options:n}),s.bind("remove",w))},unbind:function(t,i){i=e.extend({},i);var n=i.model||t.model,o=i.collection||t.collection;n?T(n,t):o&&(o.each(function(e){T(e,t)}),o.unbind("add",k),o.unbind("remove",w))},mixin:y(null,i)}}(),r=s.callbacks={valid:function(e,t,i){e.$("["+i+'~="'+t+'"]').removeClass("invalid").removeAttr("data-error")},invalid:function(e,t,i,n){e.$("["+n+'~="'+t+'"]').addClass("invalid").attr("data-error",i)}},a=s.patterns={digits:/^\d+$/,number:/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,url:/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i},d=s.messages={required:"{0} is required",acceptance:"{0} must be accepted",min:"{0} must be greater than or equal to {1}",max:"{0} must be less than or equal to {1}",range:"{0} must be between {1} and {2}",length:"{0} must be {1} characters",minLength:"{0} must be at least {1} characters",maxLength:"{0} must be at most {1} characters",rangeLength:"{0} must be between {1} and {2} characters",oneOf:"{0} must be one of: {1}",equalTo:"{0} must be the same as {1}",digits:"{0} must only contain digits",number:"{0} must be a number",email:"{0} must be a valid email",url:"{0} must be a valid url",inlinePattern:"{0} is invalid"},u=s.labelFormatters={none:function(e){return e},sentenceCase:function(e){return e.replace(/(?:^\w|[A-Z]|\b\w)/g,function(e,t){return 0===t?e.toUpperCase():" "+e.toLowerCase()}).replace(/_/g," ")},label:function(e,t){return t.labels&&t.labels[e]||u.sentenceCase(e,t)}},c=s.messageFormatters={none:function(){var e=Array.prototype.slice.call(arguments),t=e.shift();return t.replace(/\{(\d+)\}/g,function(t,i){return"undefined"!=typeof e[i]?e[i]:t})}},l=s.attributeLoaders={inputNames:function(e){var t=[];return e&&e.$("form [name]").each(function(){/^(?:input|select|textarea)$/i.test(this.nodeName)&&this.name&&"submit"!==this.type&&-1===t.indexOf(this.name)&&t.push(this.name)}),t}},h=s.validators=function(){var t=String.prototype.trim?function(e){return null===e?"":String.prototype.trim.call(e)}:function(e){var t=/^\s+/,i=/\s+$/;return null===e?"":e.toString().replace(t,"").replace(i,"")},i=function(t){return e.isNumber(t)||e.isString(t)&&t.match(a.number)},o=function(i){return!(e.isNull(i)||e.isUndefined(i)||e.isString(i)&&""===t(i)||e.isArray(i)&&e.isEmpty(i))},s=function(e,t){return e?e:t};return{format:n.format,formatLabel:n.formatLabel,fn:function(t,i,n,o,s){return e.isString(n)&&(n=o[n]),n.call(o,t,i,s)},inlineFn:function(e,t,i,n,o,s){return i.call(this,e,t,n,o,s)},required:function(t,i,n,r,a){var u=e.isFunction(n)?n.call(r,t,i,a):n;return u||o(t)?u&&!o(t)?this.format(s(this.msgKey,d.required),this.formatLabel(i,r)):void 0:!1},acceptance:function(t,i,n,o){return"true"===t||e.isBoolean(t)&&t!==!1?void 0:this.format(s(this.msgKey,d.acceptance),this.formatLabel(i,o))},min:function(e,t,n,o){return!i(e)||n>e?this.format(s(this.msgKey,d.min),this.formatLabel(t,o),n):void 0},max:function(e,t,n,o){return!i(e)||e>n?this.format(s(this.msgKey,d.max),this.formatLabel(t,o),n):void 0},range:function(e,t,n,o){return!i(e)||e<n[0]||e>n[1]?this.format(s(this.msgKey,d.range),this.formatLabel(t,o),n[0],n[1]):void 0},length:function(t,i,n,o){return e.isString(t)&&t.length===n?void 0:this.format(s(this.msgKey,d.length),this.formatLabel(i,o),n)},minLength:function(t,i,n,o){return!e.isString(t)||t.length<n?this.format(s(this.msgKey,d.minLength),this.formatLabel(i,o),n):void 0},maxLength:function(t,i,n,o){return!e.isString(t)||t.length>n?this.format(s(this.msgKey,d.maxLength),this.formatLabel(i,o),n):void 0},rangeLength:function(t,i,n,o){return!e.isString(t)||t.length<n[0]||t.length>n[1]?this.format(s(this.msgKey,d.rangeLength),this.formatLabel(i,o),n[0],n[1]):void 0},oneOf:function(t,i,n,o){return e.include(n,t)?void 0:this.format(s(this.msgKey,d.oneOf),this.formatLabel(i,o),n.join(", "))},equalTo:function(e,t,i,n,o){return e!==o[i]?this.format(s(this.msgKey,d.equalTo),this.formatLabel(t,n),this.formatLabel(i,n)):void 0},pattern:function(e,t,i,n){return o(e)&&e.toString().match(a[i]||i)?void 0:this.format(s(this.msgKey,d[i])||d.inlinePattern,this.formatLabel(t,n),i)}}}();return s}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","jquery","./NestedModel","./validation"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("jquery"),require("./NestedModel"),require("./validation")):(e.Torso=e.Torso||{},e.Torso.FormModel=t(e._,e.jQuery||e.Zepto||e.ender||e.$,e.Torso.NestedModel,e.Torso.validation))}(this,function(e,t,i,n){
"use strict";var o=i.extend({defaultMapping:null,initialize:function(t,i){i=i||{},this.__computed=[],this.__cache={},this.__currentUpdateEvents=[],this.__modelConfigs=[],this.__initMappings(i),this.validation=e.extend({},this.validation||{},i.validation||{}),this.labels=e.extend({},this.labels||{},i.labels||{}),this.pull(),t&&this.set(t),i.startUpdating&&this.startUpdating(),this.trigger("initialization-complete")},addModel:function(e,t){this.__modelConfigs.push(e),t&&(this.__copyFields(e.fields,this,e.model),this.__updateCache(e.model))},addComputed:function(t,i){this.__computed.push(t),i&&(this.__invokeComputedPull.call({formModel:this,models:t.models,pull:t.pull}),e.each(t.models,function(e){this.__updateCache(e.model)},this))},isTrackingObjectModel:function(){return e.size(this.__modelConfigs)>0||e.size(this.__computed)>0},isUpdating:function(){return this.__currentUpdateEvents.length>0},startUpdating:function(e){this.isTrackingObjectModel()&&!this.isUpdating()&&(e&&this.pull(),this.__setupListeners())},stopUpdating:function(){e.each(this.__currentUpdateEvents,function(e){this.stopListening(e.model,e.eventName)},this),this.__currentUpdateEvents=[]},save:function(n){var o,s=new t.Deferred,r=this;return n=n||{},e.defaults(n,{rollback:!0,force:!0}),this.isTrackingObjectModel()?e.has(r,"url")?i.prototype.save.apply(this,arguments).done(function(){r.push()}):(this.__saveToModels(s,n),s.promise()):(o={none:{success:!1,response:[{responseJSON:{generalReasons:[{messageKey:"no.models.were.bound.to.form"}]}}]}},this.trigger("save-fail",o),(new t.Deferred).reject(o).promise())},push:function(){e.each(this.__modelConfigs,function(e){this.__copyFields(e.fields,e.model,this)},this),e.each(this.__computed,function(t){t.push&&t.push.apply(this,[e.pluck(t.models,"model")])},this)},pull:function(){e.each(this.__modelConfigs,function(e){this.__copyFields(e.fields,this,e.model),this.__updateCache(e.model)},this),e.each(this.__computed,function(t){this.__invokeComputedPull.call({formModel:this,models:t.models,pull:t.pull}),e.each(t.models,function(e){this.__updateCache(e.model)},this)},this)},isModelStale:function(e,t,i){var n;i=i||{},i[e.cid]||(i[e.cid]=this.__generateHashValue(e)),n=i[e.cid];var o=this.__cache[e.cid]!==n;return t&&(o?t[e.cid]=e:t[e.cid]&&delete t[e.cid]),o},checkIfModelsAreStale:function(){var t={},i=this.__generateAllHashValues();return e.each(this.__getAllModels(!0),function(e){this.isModelStale(e,t,i)},this),e.values(t)},listenToModelField:function(t,i){var n="change:"+i;this.listenTo(t,n,e.bind(this.__updateFormField,{formModel:this,field:i})),this.__currentUpdateEvents.push({model:t,eventName:n})},listenToComputedValuesDependency:function(t,i,n){var o="change:"+n;this.listenTo(i,"change:"+n,e.bind(this.__invokeComputedPull,{formModel:this,models:t.models,pull:t.pull})),this.__currentUpdateEvents.push({model:i,eventName:o})},__saveToModels:function(t,i){function n(n,o,c){d[o.cid]={success:c,response:n},a+r===l&&(a>0?(i.rollback&&e.each(s.__getAllModels(!0),function(e){e.set(u[e.cid]),d[e.cid].success&&e.save()}),s.trigger("save-fail",d),t.reject(d)):(s.trigger("save-success",d),t.resolve(d)))}var o,s=this,r=0,a=0,d={},u={},c=s.__getAllModels(!0),l=c.length;if(!i.force&&(o=s.checkIfModelsAreStale(),o.length>0))throw{name:"Stale data",staleModels:o};e.each(c,function(e){u[e.cid]=s.__getTrackedModelFields(e)}),s.push(),e.each(c,function(e){e.save().fail(function(){a++,n(arguments,e,!1)}).done(function(){r++,n(arguments,e,!0)})})},__updateFormField:function(e,t){this.formModel.set(this.field,t),this.formModel.__updateCache(e)},__updateFormModel:function(t){e.each(t.changedAttributes(),function(e,t){this.set(t,this.__cloneVal(e))},this),this.__updateCache(t)},__updateCache:function(e){this.__cache[e.cid]=this.__generateHashValue(e)},__hashValue:function(e){return JSON.stringify(e)},__generateHashValue:function(e){var t=this.__getTrackedModelFields(e);return this.__hashValue(t)},__generateAllHashValues:function(){var t={};return e.each(this.__getAllModels(!0),function(e){t[e.cid]=this.__generateHashValue(e)},this),t},__cloneVal:function(i){var n;if(e.isArray(i))n=[];else{if(!e.isObject(i))return i;n={}}return t.extend(!0,n,i)},__setupListeners:function(){e.each(this.__modelConfigs,function(t){t.fields?e.each(t.fields,function(e){this.listenToModelField(t.model,e)},this):(this.listenTo(t.model,"change",this.__updateFormModel,this),this.__currentUpdateEvents.push({model:t.model,eventName:"change"}))},this),e.each(this.__computed,function(t){e.each(t.models,function(i){e.each(i.fields,function(e){this.listenToComputedValuesDependency(t,i.model,e)},this)},this)},this)},__copyFields:function(t,i,n){t||this!==n||(t=e.keys(i.attributes)),t?e.each(t,function(e){i.set(e,this.__cloneVal(n.get(e)))},this):i.set(this.__cloneVal(n.attributes))},__initMappings:function(t){var i=e.result(this,"mapping"),n=e.pick(t,["model","fields","models","computed"]);this.__initModels(n,i),this.__initComputeds(n,i)},__initModels:function(t,i){var n=this.__pullModelsFromMapping(t)||this.__pullModelsFromMapping(i);e.each(n,this.addModel,this)},__initComputeds:function(t,i){var n;t=t||{},i=i||{},n=t.computed||i.computed,e.each(n,this.addComputed,this)},__pullModelsFromMapping:function(e){var t=[];return e&&e.model?t.push({model:e.model,fields:e.fields}):e&&e.models&&(t=e.models.slice()),0===t.length?null:t},__getTrackedModelFields:function(t){var i,n={},o={},s=[];return e.each(this.__getAllModelConfigs(),function(e){e.model.cid===t.cid&&s.push(e)}),i=e.reduce(s,function(e,t){return e||!t.fields},!1),i?o=this.__cloneVal(t.attributes):e.each(s,function(i){e.each(i.fields,function(e){n[e]||(n[e]=!0,o[e]=this.__cloneVal(t.get(e)))},this)},this),o},__getAllModels:function(t){var i={},n=e.pluck(this.__getAllModelConfigs(),"model");if(t){var o=[];e.each(n,function(e){i[e.cid]||(i[e.cid]=!0,o.push(e))}),n=o}return n},__getAllModelConfigs:function(){var t=this.__modelConfigs.slice();return e.each(this.__computed,function(e){t=t.concat(e.models)}),t},__invokeComputedPull:function(t){var i=[];t&&this.formModel.__updateCache(t),function(t,n,o){e.each(o,function(n){n.fields?e.each(n.fields,function(e){i.push(t.__cloneVal(n.model.get(e)))}):i.push(t.__cloneVal(n.model.attributes))}),n.apply(t,i)}(this.formModel,this.pull,this.models)}});return e.extend(o.prototype,n.mixin),o}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","jquery","./View","./templateRenderer"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("jquery"),require("./View"),require("./templateRenderer")):(e.Torso=e.Torso||{},e.Torso.ListView=t(e._,e.$,e.Torso.View,e.Torso.Utils.templateRenderer))}(this,function(e,t,i,n){"use strict";var o,s,r,a;a=function(e){e.__delayedRenderTimeout&&(clearTimeout(e.__delayedRenderTimeout),e.__delayedRenderTimeout=null,e.render())},r=function(e,t){var i=function(){t.__delayedRenderTimeout=null,t.render()};return function(){!t.__delayedRenderTimeout&&e>0?t.__delayedRenderTimeout=setTimeout(i,e):0>=e&&t.render()}},o=function(e){var t=this.getChildViewFromModel(e);t&&(t.dispose(),this.unregisterChildView(t),delete this.__modelToViewMap[e.cid],this.trigger("child-view-removed",{model:e,view:t}),this.hasChildViews()||this.__delayedRender())},s=function(e){var t,i,n,o=this.modelsToRender(),s=o.indexOf(e);s>-1&&(this.__createChildViews(),this.hasChildViews()?(a(this),t=this.getChildViewFromModel(e),i=this.getChildViewFromModel(o[s+1]),n=this.getChildViewFromModel(o[s-1]),i?i.$el.before(t.$el):n?n.$el.after(t.$el):this.__delayedRender()):this.__delayedRender())};var d=i.extend({collection:null,childView:null,template:null,emptyTemplate:null,childrenContainer:null,__modelName:"",__modelId:"",__modelToViewMap:null,__childContext:null,__renderWait:0,__delayedRender:null,__delayedRenderTimeout:null,initialize:function(e){this.$el;if(e=e||{},this.collection=e.collection,this.template=e.template,this.emptyTemplate=e.emptyTemplate,this.childView=e.childView,this.childrenContainer=e.childrenContainer,this.template&&!this.childrenContainer)throw"Children container is required when using a template";this.modelsToRender=e.modelsToRender||this.modelsToRender,this.__childContext=e.childContext,this.__modelToViewMap={},this.__renderWait=e.renderWait||this.__renderWait,this.__modelId=e.modelId||"cid",this.__modelName=e.childModel||"model",this.__createChildViews(),this.__delayedRender=r(this.__renderWait,this),this.listenTo(this.collection,"remove",o,this),this.listenTo(this.collection,"add",s,this),this.listenTo(this.collection,"sort",this.__delayedRender,this),this.listenTo(this.collection,"reset",this.update,this)},render:function(){var e,i=t(n.copyTopElement(this.el));this.template?(i.html(this.template(this.prepare())),e=i.find("[inject="+this.childrenContainer+"]")):(e=t("<span>"),i.append(e)),this.hasChildViews()?e.replaceWith(this.__buildChildViewsFragment()):this.emptyTemplate&&e.replaceWith(this.emptyTemplate(this.prepareEmpty())),this.trigger("render-before-dom-replacement",i),this.$el.html(i.contents()),this.delegateEvents(),this.trigger("render-complete")},renderChildViews:function(){e.each(this.modelsToRender(),function(e){var t=this.getChildViewFromModel(e);t.render()},this)},prepare:function(){return{}},prepareEmpty:function(){return{}},modelsToRender:function(){return this.collection?this.collection.models:[]},update:function(){this.__createChildViews(),this.__delayedRender()},getChildViewFromModel:function(e){return e?this.getChildView(this.__modelToViewMap[e[this.__modelId]]):void 0},__createChildViews:function(){e.each(this.modelsToRender(),function(e){var t=this.getChildViewFromModel(e);t||(t=this.__createChildView(e),this.trigger("child-view-added",{model:e,view:t}))},this)},__buildChildViewsFragment:function(i){var n=document.createDocumentFragment();return e.each(this.modelsToRender(),function(e){var t=this.getChildViewFromModel(e);t&&n.appendChild(t.el)},this),t(n)},__createChildView:function(e){var t=new this.childView(this.__generateChildArgs(e));return this.registerChildView(t),this.__modelToViewMap[e.cid]=t.cid,t},__generateChildArgs:function(t){var i={context:e.extend({},e.result(this,"__childContext"))};return i[this.__modelName]=t,i}});return d}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","jquery","./View","./FormModel","./Cell","backbone.stickit"],t):"object"==typeof exports?(require("backbone.stickit"),module.exports=t(require("underscore"),require("jquery"),require("./View"),require("./FormModel"),require("./Cell"))):(e.Torso=e.Torso||{},e.Torso.FormView=t(e._,e.jQuery||e.Zepto||e.ender||e.$,e.Torso.View,e.Torso.FormModel,e.Torso.Cell))}(this,function(e,t,i,n,o){"use strict";var s=i.extend({initialize:function(t){t=t||{},this.model=this.model||new n,this.listenTo(this.model,"validated:valid",this.valid),this.listenTo(this.model,"validated:invalid",this.invalid),this.template=t.template||this.template,this.events=e.extend({},this.events||{},t.events||{}),this.fields=e.extend({},this.fields||{},t.fields||{}),this._errors=[],this._success=!1,this._bindings=e.extend({},this.bindings||{},t.bindings||{})},prepare:function(){return{model:this.model.toJSON(),view:this.viewState.toJSON(),formErrors:0!==e.size(this._errors)?this._errors:null,formSuccess:this._success}},delegateEvents:function(){this.__generateStickitBindings(),this.stickit(),i.prototype.delegateEvents.call(this)},valid:function(){this._success=!0,this._errors=[]},invalid:function(e,t){this._success=!1,this._errors=t},_deactivate:function(){i.prototype._deactivate.call(this),this.unstickit()},_thenAddClassIfInvalid:function(e,t,i){var n=this.model.isValid(e);return(i?!0:!1)==(n?!0:!1)?{addClass:t}:{removeClass:t}},_thenSetTextIfInvalid:function(e,t,i){var n=this.model.isValid(e);return(i?!0:!1)==(n?!0:!1)?{text:t}:{text:""}},__generateStickitBindings:function(){var i=this;this.bindings=e.extend({},this._bindings),e.each(this.$("[data-model]"),function(e){var n=t(e).data("model"),o=i.__getFieldOptions(n),s=i.__generateModelFieldBinding(n,o);i.bindings['[data-model="'+n+'"]']=s})},__getFieldOptions:function(e){return e=this.__stripAllAttribute(e),this.fields[e]||{}},__generateModelFieldBinding:function(t,i){var n=this.__getAllIndexTokens(t);return{observe:t,onSet:function(t){var o=[t];return o.push(n),o=e.flatten(o),i.modelFormat?i.modelFormat.apply(this,o):t},onGet:function(t){var o=[t];return o.push(n),o=e.flatten(o),i.viewFormat?i.viewFormat.apply(this,o):t}}}});return s});