diff --git a/package.json b/package.json index 2b3786df..685d1509 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "backbone-torso", - "version": "0.1.0", + "version": "0.1.1", "repository": { "type": "git", "url": "https://github.com/vecnatechnologies/backbone-torso" diff --git a/torso-bundle.min.js b/torso-bundle.min.js index 72e706c0..358d882d 100644 --- a/torso-bundle.min.js +++ b/torso-bundle.min.js @@ -1,3 +1,2 @@ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():(e.Torso=e.Torso||{},e.Torso.Utils=e.Torso.Utils||{},e.Torso.Utils.guidManager=t())}(this,function(){"use strict";var e={_current:0,generate:function(){var e=this._generateGUID();return e},_generateGUID:function(){var e="G"+this._current;return this._current++,e}};return e}),function(e,t){"function"==typeof define&&define.amd?define(["handlebars"],t):t("object"==typeof exports?require("handlebars"):e.Handlebars)}(this,function(e){"use strict";var t="feedback",i="model";e.registerHelper("labelFor",function(t,i){return e.helpers.formAttr(t,"for",i)}),e.registerHelper("bindModel",function(n,r){return e.helpers.formAttr(n,i+", "+t+", name, id",r)}),e.registerHelper("feedback",function(i,n){return e.helpers.formAttr(i,t,n)}),e.registerHelper("formAttr",function(n,r,o){var s,a,u=o.hash?o.hash.value:void 0,d=e.helpers.injectFieldIndices(n,o.hash),l="";for(r=r.split(","),s=0;s"+n.html()+""),i.replaceWith(m),i=m),f=n.get(0).attributes,p=i.get(0).attributes;p.length>0;)p.removeNamedItem(p[0].name);if(e.each(f,function(e){g=document.createAttribute(e.name),g.value=e.value,p.setNamedItem(g)}),i.html()===n.html())return!1;if(c=n.children(),h=i.children(),c.length!==h.length)return i.html(n.html()),!0;if(0===h.length)return i.html(n.html()),!1;for(s=0;sF;F++)if(l.is(r[F])){v=!0;break}v||(_=this.hotswap(l,d,r,o),o&&b.push(_))}return b},copyTopElement:function(i){var n=t("<"+i.prop("tagName")+">");return e.each(i.get(0).attributes,function(e){n.attr(e.name,e.value)}),n},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 i}),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){var i,n=t["super"]||function(){};return i=function(i,n){var r=n.loadedOnceDeferred,o=n.loadedOnce,s=n.loading;i.hasLoadedOnce=function(){return o},i.isLoading=function(){return s},i.getLoadedOncePromise=function(){return r.promise()},i.fetch=function(e){this._loadWrapper(t.fetch,e)},i._loadWrapper=function(t,n){return s=!0,i.trigger("load-begin"),e.when(t.call(i,n)).done(function(e,t,n){i.trigger("load-complete",{success:!0,data:e,textStatus:t,jqXHR:n})}).fail(function(e,t,n){i.trigger("load-complete",{success:!1,jqXHR:e,textStatus:t,errorThrown:n})}).always(function(){o||(o=!0,r.resolve()),s=!1})}},{"super":function(t){n.call(this,t),i(this,{loadedOnceDeferred:new e.Deferred,loadedOnce:!1,loading:!1})}}};return t}),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.polling=t(e.jQuery||e.Zepto||e.ender||e.$))}(this,function(e){var t={pollTimeoutId:void 0,_pollStarted:!1,_pollInterval:5e3,isPolling:function(){return this._pollStarted},startPolling:function(t){t&&(this._pollInterval=t),this._pollStarted||(this._pollStarted=!0,this._poll(),this.pollTimeoutId=window.setInterval(e.proxy(function(){this._poll()},this),this._pollInterval))},stopPolling:function(){window.clearInterval(this.pollTimeoutId),this._pollStarted=!1},polledFetch:function(){this.fetch()},_poll:function(){this.polledFetch()}};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,r,o=i["super"]||function(){};return r=function(i,n){return i.constructor.extend(function(i,n,r){var o,s=i["super"];return o=function(i,o){i.getTrackedIds=function(){return o},i.fetch=function(){return i._loadWrapper(function(){return o&&o.length?n.fetchByIds({idsToFetch:o,setOptions:{remove:!1}}):t.Deferred().resolve().promise()})},i.trackIds=function(t){i.remove(e.difference(o,t)),n.registerIds(t,r),o=t},i.fetchByIds=function(e){return i.trackIds(e),i.fetch()},i.requesterDispose=function(){n.removeRequster(r)}},{"super":function(e){e=e||{},e.isRequester=!0,s.call(this,e),o(this,[]),this.listenTo(n,"load-begin",function(){this.trigger("cache-load-begin")}),this.listenTo(n,"load-complete",function(){this.trigger("cache-load-complete")})}}}(i.constructor.__super__,i,n))},n=function(i,n){var o,s=n.requestMap,a=n.collectionTrackedIds,u=n.getByIdsUrl||"/ids",d=n.knownPrivateCollections;i.lazyFetch=i.lazyFetch||!1,o=function(t,i){s[t]={array:i,dict:e.object(e.map(i,function(e){return[e,e]}))}},i.getRequesterIds=function(e){return s[e]&&s[e].array},i.getRequesterIdsAsDictionary=function(e){return s[e]&&s[e].dict},i.removeRequster=function(e){delete s[e],delete d[e]},i.getRequesters=function(){return e.keys(s)},i.getAllRequestedIds=function(){return a},i.createPrivateCollection=function(e){var t=r(i,e);return d[e]=new t,d[e]},i.registerIds=function(e,t){var n,r,s,u,d,l={},c=[];for(o(t,e),u=i.getRequesters(),d=u.length,r=0;d>r;r++)for(s=i.getRequesterIds(u[r]),n=0;no;o++){for(s=i.getRequesterIdsAsDictionary(c[o]),a=[],t=0;f>t;t++)s[r[t]]&&(h=i.get(r[t]),h&&a.push(h));u=d[c[o]],u.set(a,{remove:!1})}})},n)},i.setLazyFetch=function(e){i.lazyFetch=e},i.isLazyFetch=function(){return i.lazyFetch}},{"super":function(e){e=e||{},o.call(this,e),this.isRequester=e&&e.isRequester,this.isRequester||n(this,{requestMap:{},collectionTrackedIds:[],knownPrivateCollections:{},getByIdsUrl:e.getByIdsUrl})},initialize:function(e){this["super"](e)},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([],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(["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(["./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(["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(["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.history=t(e.Backbone))}(this,function(e){"use strict";return e.history}),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,r){"use strict";var o=t.Collection.extend({});return e.extend(o.prototype,i),e.extend(o.prototype,n(o.prototype)),e.extend(o.prototype,r(o.prototype)),o}),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","./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(["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","./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 d[i.labelFormatter](e,t)},format:function(){return l[i.messageFormatter].apply(l,arguments)}},r=function(t,i,n){return i=i||{},n=n||"",e.each(t,function(e,o){t.hasOwnProperty(o)&&(e&&"object"==typeof e&&e.constructor===Object&&r(e,i,n+o+"."),i[n+o]=e)}),i},o=function(){var o=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(c[n])&&(n=c[n](i)),e.isArray(n)?n:void 0},u=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},[])},d=function(e){var t,i,n=0,r=!0,o=[];for(t=e.indexOf("[",n);t>0&&r;)i=e.indexOf("]",n),o.push(parseInt(e.substring(t+1,i),10)),n=i+1,r=n>0,t=e.indexOf("[",n);return o},l=function(t,i,n){var r,o,s,a,u,d=t.indexOf("[]");if(e.isEmpty(n)&&(n=[]),-1===d)return{attr:t,index:n};for(o=t.substring(0,d),s=t.substring(d+2),a=[],r=0;r0||e.indexOf("]")>0},m=function(e){var t,i,n=0,r=!0;if(t=e.indexOf("[",n),0>t)return e;for(i=e.substring(0,t+1);t>0&&r;)n=e.indexOf("]",n)+1,r=n>0,t=e.indexOf("[",n),t>0&&(i+=e.substring(n-1,t+1));return i+=e.substring(n-1)},g=function(t,i,n,r,o,s){var a,u;return e.isArray(i)?e.reduce(i,function(e,i){return e.push(g(t,i,n,r,o,s+1)),e},[]):(u=i.index,a=i.attr,e.isUndefined(n)&&p(a)&&(n=t.get(a)),v(o,t,n,a,r,u))},v=function(t,i,r,o,s,a){return e.reduce(t,function(t,u){var d=e.extend({msgKey:u.msgKey},n,h),l=u.fn.call(d,r,o,u.val,i,s,a);return l===!1||t===!1?!1:l&&!t?e.result(e.extend({},u,n,h),"msg")||l:t},"")},F=function(t,i,n,r){var o,s,a,d=u(t,i);return s=l(i,t),a=g(t,s,n,r,d,0),e.isArray(a)&&(o=e.reduce(e.flatten(a),function(e,t){return e||t},!1),!o)?"":a},_=function(t,i,n){var r,o={},s=!0,a=e.clone(i);return e.each(n,function(e,i){r=F(t,i,e,a),r&&(o[i]=r,s=!1)}),{invalidAttrs:o,isValid:s}},b=function(t,i,n){var r,o,s=t.validation?e.result(t,"validation")||{}:{};return e.contains(e.keys(s),n)?F(t,n,i,e.extend({},t.attributes)):(r=d(n),n=m(n),o=u(t,n),v(o,t,i,n,e.extend({},t.attributes),r))},y=function(t,i){return{preValidate:function(t,i){var n,r=this,o={};return e.isArray(t)?(e.each(t,function(e){n=r.preValidate(e),n&&(o[e]=n)}),e.isEmpty(o)?void 0:o):e.isObject(t)?(e.each(t,function(e,t){n=r.preValidate(t,e),n&&(o[t]=n)}),e.isEmpty(o)?void 0:o):(e.isUndefined(i)&&f(this)&&(i=this.get(t)),b(this,i,t))},isValid:function(n){var o,s,u;return n=n||a(i,t),e.isString(n)?o=[n]:e.isArray(n)&&(o=n),o&&e.each(o,function(t){var n;n=f(this)?this.get(t):r(this.attributes)[t],s=b(this,n,t),s&&(u=u||{},u[t]=s),e.each(this.associatedViews,function(e){s?i.invalid(e,t,s,i.selector):i.valid(e,t,i.selector)},this)},this),n===!0&&(u=this.validate()),u&&this.trigger("invalid",this,u,{validationError:u}),o?!u:this.validation?this._isValid:!0},validate:function(n,s){var u,d,l,c,h,f,p,m=this;return u=!n,d=e.extend({},i,s),l=o(m,a(i,t)),c=e.extend({},l,m.attributes,n),h=r(c),f=n?r(n):h,p=_(m,c,e.pick(h,e.keys(l))),m._isValid=p.isValid,e.each(m.associatedViews,function(t){e.each(l,function(e,i){var n=p.invalidAttrs.hasOwnProperty(i),r=f.hasOwnProperty(i);n||d.valid(t,i,d.selector),n&&(r||u)&&d.invalid(t,i,p.invalidAttrs[i],d.selector)})}),e.defer(function(){m.trigger("validated",m._isValid,m,p.invalidAttrs),m.trigger("validated:"+(m._isValid?"valid":"invalid"),m,p.invalidAttrs)}),!d.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)},C=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,s,n);var r=n.model||t.model,o=n.collection||t.collection;if("undefined"==typeof r&&"undefined"==typeof o)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.";r?x(t,r,n):o&&(o.each(function(e){x(t,e,n)}),o.bind("add",C,{view:t,options:n}),o.bind("remove",w))},unbind:function(t,i){i=e.extend({},i);var n=i.model||t.model,r=i.collection||t.collection;n?T(n,t):r&&(r.each(function(e){T(e,t)}),r.unbind("add",C),r.unbind("remove",w))},mixin:y(null,i)}}(),s=o.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=o.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},u=o.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"},d=o.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]||d.sentenceCase(e,t)}},l=o.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})}},c=o.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=o.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)},r=function(i){return!(e.isNull(i)||e.isUndefined(i)||e.isString(i)&&""===t(i)||e.isArray(i)&&e.isEmpty(i))},o=function(e,t){return e?e:t};return{format:n.format,formatLabel:n.formatLabel,fn:function(t,i,n,r,o){return e.isString(n)&&(n=r[n]),n.call(r,t,i,o)},inlineFn:function(e,t,i,n,r,o){return i.call(this,e,t,n,r,o)},required:function(t,i,n,s,a){var d=e.isFunction(n)?n.call(s,t,i,a):n;return d||r(t)?d&&!r(t)?this.format(o(this.msgKey,u.required),this.formatLabel(i,s)):void 0:!1},acceptance:function(t,i,n,r){return"true"===t||e.isBoolean(t)&&t!==!1?void 0:this.format(o(this.msgKey,u.acceptance),this.formatLabel(i,r))},min:function(e,t,n,r){return!i(e)||n>e?this.format(o(this.msgKey,u.min),this.formatLabel(t,r),n):void 0},max:function(e,t,n,r){return!i(e)||e>n?this.format(o(this.msgKey,u.max),this.formatLabel(t,r),n):void 0},range:function(e,t,n,r){return!i(e)||en[1]?this.format(o(this.msgKey,u.range),this.formatLabel(t,r),n[0],n[1]):void 0},length:function(t,i,n,r){return e.isString(t)&&t.length===n?void 0:this.format(o(this.msgKey,u.length),this.formatLabel(i,r),n)},minLength:function(t,i,n,r){return!e.isString(t)||t.lengthn?this.format(o(this.msgKey,u.maxLength),this.formatLabel(i,r),n):void 0},rangeLength:function(t,i,n,r){return!e.isString(t)||t.lengthn[1]?this.format(o(this.msgKey,u.rangeLength),this.formatLabel(i,r),n[0],n[1]):void 0},oneOf:function(t,i,n,r){return e.include(n,t)?void 0:this.format(o(this.msgKey,u.oneOf),this.formatLabel(i,r),n.join(", "))},equalTo:function(e,t,i,n,r){return e!==r[i]?this.format(o(this.msgKey,u.equalTo),this.formatLabel(t,n),this.formatLabel(i,n)):void 0},pattern:function(e,t,i,n){return r(e)&&e.toString().match(a[i]||i)?void 0:this.format(o(this.msgKey,u[i])||u.inlinePattern,this.formatLabel(t,n),i)}}}();return o}),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 r=i.extend({defaultMapping:null,initialize:function(t,i){this._computed=[],this._cache={},this._currentUpdateEvents=[],this._modelConfigs=[],i=i||{},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(i){var n,r=new t.Deferred;return i=i||{},e.defaults(i,{rollback:!0,force:!0}),this.isTrackingObjectModel()?(function(t){function n(n,o,l){u[o.cid]={success:l,response:n},a+s===c&&(a>0?(i.rollback&&e.each(t._getAllModels(!0),function(e){e.set(d[e.cid]),u[e.cid].success&&e.save()}),t.trigger("save-fail",u),r.reject(u)):(t.trigger("save-success",u),r.resolve(u)))}var o,s=0,a=0,u={},d={},l=t._getAllModels(!0),c=l.length;if(!i.force&&(o=t.checkIfModelsAreStale(),o.length>0))throw{name:"Stale data",staleModels:o};e.each(l,function(e){d[e.cid]=t._getTrackedModelFields(e)}),t.push(),e.each(l,function(e){e.save().fail(function(){a++,n(arguments,e,!1)}).done(function(){s++,n(arguments,e,!0)})})}(this),r.promise()):(n={none:{success:!1,response:[{responseJSON:{generalReasons:[{messageKey:"no.models.were.bound.to.form"}]}}]}},this.trigger("save-fail",n),(new t.Deferred).reject(n).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 r=this._cache[e.cid]!==n;return t&&(r?t[e.cid]=e:t[e.cid]&&delete t[e.cid]),r},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 r="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:r})},_clone: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._clone(n.get(e)))},this):i.set(this._clone(n.attributes))},_updateFormField:function(e,t){this.formModel.set(this.field,t),this.formModel._updateCache(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},_updateFormModel:function(t){e.each(t.changedAttributes(),function(e,t){this.set(t,this._clone(e))},this),this._updateCache(t)},_updateCache:function(e){this._cache[e.cid]=this._generateHashValue(e)},_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)},_mappingHasModels:function(e){return e&&(e.model||e.models)},_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={},r={},o=[];return e.each(this._getAllModelConfigs(),function(e){e.model.cid===t.cid&&o.push(e)}),i=e.reduce(o,function(e,t){return e||!t.fields},!1),i?r=this._clone(t.attributes):e.each(o,function(i){e.each(i.fields,function(e){n[e]||(n[e]=!0,r[e]=this._clone(t.get(e)))},this)},this),r},_getAllModels:function(t){var i={},n=e.pluck(this._getAllModelConfigs(),"model");if(t){var r=[];e.each(n,function(e){i[e.cid]||(i[e.cid]=!0,r.push(e))}),n=r}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,r){e.each(r,function(n){n.fields?e.each(n.fields,function(e){i.push(t._clone(n.model.get(e)))}):i.push(t._clone(n.model.attributes))}),n.apply(t,i)}(this.formModel,this.pull,this.models)}});return e.extend(r.prototype,n.mixin),r}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./guidManager","./templateRenderer","./Cell"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./guidManager"),require("./templateRenderer"),require("./Cell")):(e.Torso=e.Torso||{},e.Torso.View=t(e._,e.Backbone,e.Torso.Utils.guidManager,e.Torso.Utils.templateRenderer,e.Torso.Cell))}(this,function(e,t,i,n,r){"use strict";var o=t.View.extend({_GUID:null,_childViews:null,viewState:null,template:null,_isActive:!1,_isAttached:!1,_isDisposed:!1,"super":function(){this.generateGUID(),this._childViews={},this.viewState=new r},initialize:function(){this["super"](),this.render(),this.activate()},prepare:function(){return this.model?this.model.toJSON():{}},render:function(){this.template&&(this.templateRender(this.$el,this.template,this.prepare()),this.delegateEvents())},generateGUID:function(){null===this._GUID&&(this._GUID=i.generate(this))},getGUID:function(){return this._GUID},templateRender:function(e,t,i,r){this.detachChildViews(),n.render(e,t,i,r)},createPrivateCollection:function(e){return e.createPrivateCollection(this._GUID); - -},cleanupSelf:function(){this.detach(),this.cleanupChildViews(),this.remove(),this.off(),this.stopListening(),this.viewState&&(this.viewState.off(),this.viewState.stopListening()),delete this.$el,delete this.el,this._isDisposed=!0},deactivateCallback:e.noop,activateCallback:e.noop,hasChildViews:function(){return!e.isEmpty(this._childViews)},getChildViews:function(){return e.values(this._childViews)},cleanupChildViews:function(){e.each(this._childViews,function(e){e.dispose()})},deactivateChildViews:function(){e.each(this._childViews,function(e){e.deactivate()})},activateChildViews:function(){e.each(this._childViews,function(e){e.activate()})},detachChildViews:function(){e.each(this._childViews,function(e){e.detach()})},registerChildView:function(e){return this._childViews[e.cid]=e,e},unregisterChildView:function(e){return delete this._childViews[e.cid],e},injectView:function(e,t){var i=this.$el.find("[inject="+e+"]");t&&i.size()>0&&this.attachChildView(i,t)},attachChildView:function(e,t){t.detach(),this.registerChildView(t),t.attach(e)},detach:function(){this.isAttached()&&(this.injectionSite?this.$el.replaceWith(this.injectionSite):this.$el.detach(),this.deactivate(),this._isAttached=!1)},attach:function(e){this.isAttached()||(this.deactivate(),this.render(),this.injectionSite=e.replaceWith(this.$el),this.activate(),this._isAttached=!0)},isAttached:function(){return this._isAttached},deactivate:function(){this.deactivateChildViews(),this.isActive()&&(this.undelegateEvents(),this.deactivateCallback(),this._isActive=!1)},activate:function(){this.activateChildViews(),this.isActive()||(this.delegateEvents(),this.activateCallback(),this._isActive=!0)},isActive:function(){return this._isActive},dispose:function(){this.cleanupSelf()},isDisposed:function(){return this._isDisposed}});return 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 r,o,s,a;a=function(e){e._delayedRenderTimeout&&(clearTimeout(e._delayedRenderTimeout),e._delayedRenderTimeout=null,e.render())},s=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()}},r=function(e){var t=this.getChildView(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())},o=function(e){var t,i,n,r=this.modelsToRender(),o=r.indexOf(e);o>-1&&(this._createChildViews(),this.hasChildViews()?(a(this),t=this.getChildView(e),i=this.getChildView(r[o+1]),n=this.getChildView(r[o-1]),i?i.$el.before(t.$el):n?n.$el.after(t.$el):this._delayedRender()):this._delayedRender())};var u=i.extend({className:"",_collection:null,_modelName:"",_childView:null,_modelToViewMap:null,_template:null,_emptyTemplate:null,_childContext:null,_renderWait:0,_delayedRender:null,_delayedRenderTimeout:null,initialize:function(e){this["super"](),this.listViewSetup(e),this.render()},listViewSetup:function(e){this.$el;if(e=e||{},this._modelName=e.childModel||"model",this._collection=e.collection,this._childView=e.childView,this._template=e.template,this._childrenContainer=e.childrenContainer,this._template&&!this._childrenContainer)throw"Children container is required when using a template";this._emptyTemplate=e.emptyTemplate,this.modelsToRender=e.modelsToRender||this.modelsToRender,this._childContext=e.childContext,this._modelToViewMap={},this._renderWait=e.renderWait||this._renderWait,this._modelId=e.modelId||"cid",this._createChildViews(),this._delayedRender=s(this._renderWait,this),this.listenTo(this._collection,"remove",r,this),this.listenTo(this._collection,"add",o,this),this.listenTo(this._collection,"sort",this._delayedRender,this),this.listenTo(this._collection,"reset",this.update,this)},render:function(){var e,i=n.copyTopElement(this.$el);this._template?(i.html(this._template(this.prepare())),e=i.find("[inject="+this._childrenContainer+"]")):(e=t(""),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.getChildView(e);t.render()},this)},prepare:function(){return{}},prepareEmpty:function(){return{}},modelsToRender:function(){return this._collection?this._collection.models:[]},update:function(){this._createChildViews(),this._delayedRender()},getChildView:function(e){return e?this._childViews[this._modelToViewMap[e[this._modelId]]]:void 0},_createChildViews:function(){e.each(this.modelsToRender(),function(e){var t=this.getChildView(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.getChildView(e);t&&n.appendChild(t.el)},this),t(n)},_createChildView:function(e){var t=this.registerChildView(new this._childView(this._generateChildArgs(e)));return 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 u}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","jquery","./View","./FormModel"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("jquery"),require("./View"),require("./FormModel")):(e.Torso=e.Torso||{},e.Torso.FormView=t(e._,e.jQuery||e.Zepto||e.ender||e.$,e.Torso.View,e.Torso.FormModel))}(this,function(e,t,i,n){"use strict";var r=i.extend({initialize:function(t){this["super"](),t=t||{},this.feedbackModel=new Backbone.Model,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._feedbackEvents=[],this._bindings=e.extend({},this.bindings||{},t.bindings||{}),this.render()},prepare:function(){return{model:this.model.toJSON(),formErrors:0!==e.size(this._errors)?this._errors:null,formSuccess:this._success}},render:function(){var e=this.prepare();this.unplug(),this.templateRender(this.$el,this.template,e),this.plug(),this.delegateEvents()},delegateEvents:function(){this._generateStickitBindings(),this.stickit(),i.prototype.delegateEvents.call(this),this._generateFeedbackBindings(),this._generateFeedbackModelCallbacks()},unplug:function(){},plug:function(){},valid:function(){this._success=!0,this._errors=[]},invalid:function(e,t){this._success=!1,this._errors=t},invokeFeedback:function(t,i,n){var r,o=e.find(this.feedback,function(i){var n=i.to;return e.isArray(n)?e.contains(n,t):t===n}),s=t;o&&(n&&(s=this._substituteIndicesUsingMap(t,n)),r=o.then.call(this,i,n),this._processFeedbackThenResult(r,s))},dispose:function(){this.unstickit(),r.__super__.dispose.apply(this,arguments)},_generateStickitBindings:function(){var i=this;this.bindings=e.extend({},this._bindings),e.each(this.$el.find("[data-model]"),function(e){var n=t(e).data("model"),r=i._getFieldOptions(n),o=i._generateModelFieldBinding(n,r);i.bindings['[data-model="'+n+'"]']=o})},_generateFeedbackModelCallbacks:function(){var i=this;i.feedbackModel.off(),e.each(this.$el.find("[data-feedback]"),function(n){var r=t(n).data("feedback");i.feedbackModel.on("change:"+r,function(t){return function(){var n,r=i.feedbackModel.get(t);r&&(n=i.$el.find('[data-feedback="'+t+'"]'),e.each(r,function(t,r){var o;o="_"===e.first(r)?i[r.slice(1)]:n[r],e.isArray(t)?o.apply(n,t):void 0!==t&&o.call(n,t)}))}}(r))}),e.each(i.feedbackModel.attributes,function(e,t){i.feedbackModel.trigger("change:"+t)})},_getFieldOptions:function(e){return e=this._stripAllAttribute(e),this.fields[e]||{}},_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)+"]")})},_processFeedbackThenResult:function(e,i){var n=t.extend({},e);this.feedbackModel.set(i,n,{silent:!0}),this.feedbackModel.trigger("change:"+i)},_generateModelFieldBinding:function(t,i){var n=this._getAllIndexTokens(t);return{observe:t,onSet:function(t){var r=[t];return r.push(n),r=e.flatten(r),i.modelFormat?i.modelFormat.apply(this,r):t},onGet:function(t){var r=[t];return r.push(n),r=e.flatten(r),i.viewFormat?i.viewFormat.apply(this,r):t}}},_generateFeedbackBindings:function(){var i,n=this;for(i=0;i0&&(r=e.substring(0,o)),this.$el.find('[data-feedback^="'+r+'"]').filter(function(){return i._stripAllAttribute(t(this).data("feedback"))===n})},_generateWhenEvents:function(t,i){var n=this,r=[];return e.each(t,function(t,o){var s,a=[o],u="@"===o.charAt(0);"on"!==o&&(u&&(o=o.substring(1),s=n._substituteIndicesUsingMap(o,i),a=e.flatten(n._generateSubAttributes(s,n.model))),e.each(a,function(i){e.each(t,function(e){var t=e+" "+i;u&&(t=e+' [data-model="'+i+'"]'),r.push(t)})}))}),r},_generateSubAttributes:function(e,t){var i,n,r,o,s,a=e.indexOf("[]");if(-1===a)return[e];if(n=e.substring(0,a),r=e.substring(a+2),o=[],s=t.get(n),!s)return[e];for(i=0;i"+n.html()+""),i.replaceWith(m),i=m),f=n.get(0).attributes,p=i.get(0).attributes;p.length>0;)p.removeNamedItem(p[0].name);if(e.each(f,function(e){g=document.createAttribute(e.name),g.value=e.value,p.setNamedItem(g)}),i.html()===n.html())return!1;if(c=n.children(),h=i.children(),c.length!==h.length)return i.html(n.html()),!0;if(0===h.length)return i.html(n.html()),!1;for(s=0;sF;F++)if(l.is(r[F])){v=!0;break}v||(_=this.hotswap(l,d,r,o),o&&b.push(_))}return b},copyTopElement:function(i){var n=t("<"+i.prop("tagName")+">");return e.each(i.get(0).attributes,function(e){n.attr(e.name,e.value)}),n},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 i}),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){var i,n=t["super"]||function(){};return i=function(i,n){var r=n.loadedOnceDeferred,o=n.loadedOnce,s=n.loading;i.hasLoadedOnce=function(){return o},i.isLoading=function(){return s},i.getLoadedOncePromise=function(){return r.promise()},i.fetch=function(e){this._loadWrapper(t.fetch,e)},i._loadWrapper=function(t,n){return s=!0,i.trigger("load-begin"),e.when(t.call(i,n)).done(function(e,t,n){i.trigger("load-complete",{success:!0,data:e,textStatus:t,jqXHR:n})}).fail(function(e,t,n){i.trigger("load-complete",{success:!1,jqXHR:e,textStatus:t,errorThrown:n})}).always(function(){o||(o=!0,r.resolve()),s=!1})}},{"super":function(t){n.call(this,t),i(this,{loadedOnceDeferred:new e.Deferred,loadedOnce:!1,loading:!1})}}};return t}),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.polling=t(e.jQuery||e.Zepto||e.ender||e.$))}(this,function(e){var t={pollTimeoutId:void 0,_pollStarted:!1,_pollInterval:5e3,isPolling:function(){return this._pollStarted},startPolling:function(t){t&&(this._pollInterval=t),this._pollStarted||(this._pollStarted=!0,this._poll(),this.pollTimeoutId=window.setInterval(e.proxy(function(){this._poll()},this),this._pollInterval))},stopPolling:function(){window.clearInterval(this.pollTimeoutId),this._pollStarted=!1},polledFetch:function(){this.fetch()},_poll:function(){this.polledFetch()}};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,r,o=i["super"]||function(){};return r=function(i,n){return i.constructor.extend(function(i,n,r){var o,s=i["super"];return o=function(i,o){i.getTrackedIds=function(){return o},i.fetch=function(){return i._loadWrapper(function(){return o&&o.length?n.fetchByIds({idsToFetch:o,setOptions:{remove:!1}}):t.Deferred().resolve().promise()})},i.trackIds=function(t){i.remove(e.difference(o,t)),n.registerIds(t,r),o=t},i.fetchByIds=function(e){return i.trackIds(e),i.fetch()},i.requesterDispose=function(){n.removeRequster(r)}},{"super":function(e){e=e||{},e.isRequester=!0,s.call(this,e),o(this,[]),this.listenTo(n,"load-begin",function(){this.trigger("cache-load-begin")}),this.listenTo(n,"load-complete",function(){this.trigger("cache-load-complete")})}}}(i.constructor.__super__,i,n))},n=function(i,n){var o,s=n.requestMap,a=n.collectionTrackedIds,u=n.getByIdsUrl||"/ids",d=n.knownPrivateCollections;i.lazyFetch=i.lazyFetch||!1,o=function(t,i){s[t]={array:i,dict:e.object(e.map(i,function(e){return[e,e]}))}},i.getRequesterIds=function(e){return s[e]&&s[e].array},i.getRequesterIdsAsDictionary=function(e){return s[e]&&s[e].dict},i.removeRequster=function(e){delete s[e],delete d[e]},i.getRequesters=function(){return e.keys(s)},i.getAllRequestedIds=function(){return a},i.createPrivateCollection=function(e){var t=r(i,e);return d[e]=new t,d[e]},i.registerIds=function(e,t){var n,r,s,u,d,l={},c=[];for(o(t,e),u=i.getRequesters(),d=u.length,r=0;d>r;r++)for(s=i.getRequesterIds(u[r]),n=0;no;o++){for(s=i.getRequesterIdsAsDictionary(c[o]),a=[],t=0;f>t;t++)s[r[t]]&&(h=i.get(r[t]),h&&a.push(h));u=d[c[o]],u.set(a,{remove:!1})}})},n)},i.setLazyFetch=function(e){i.lazyFetch=e},i.isLazyFetch=function(){return i.lazyFetch}},{"super":function(e){e=e||{},o.call(this,e),this.isRequester=e&&e.isRequester,this.isRequester||n(this,{requestMap:{},collectionTrackedIds:[],knownPrivateCollections:{},getByIdsUrl:e.getByIdsUrl})},initialize:function(e){this["super"](e)},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([],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(["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(["./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(["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(["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.history=t(e.Backbone))}(this,function(e){"use strict";return e.history}),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,r){"use strict";var o=t.Collection.extend({});return e.extend(o.prototype,i),e.extend(o.prototype,n(o.prototype)),e.extend(o.prototype,r(o.prototype)),o}),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","./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(["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","./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 d[i.labelFormatter](e,t)},format:function(){return l[i.messageFormatter].apply(l,arguments)}},r=function(t,i,n){return i=i||{},n=n||"",e.each(t,function(e,o){t.hasOwnProperty(o)&&(e&&"object"==typeof e&&e.constructor===Object&&r(e,i,n+o+"."),i[n+o]=e)}),i},o=function(){var o=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(c[n])&&(n=c[n](i)),e.isArray(n)?n:void 0},u=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},[])},d=function(e){var t,i,n=0,r=!0,o=[];for(t=e.indexOf("[",n);t>0&&r;)i=e.indexOf("]",n),o.push(parseInt(e.substring(t+1,i),10)),n=i+1,r=n>0,t=e.indexOf("[",n);return o},l=function(t,i,n){var r,o,s,a,u,d=t.indexOf("[]");if(e.isEmpty(n)&&(n=[]),-1===d)return{attr:t,index:n};for(o=t.substring(0,d),s=t.substring(d+2),a=[],r=0;r0||e.indexOf("]")>0},m=function(e){var t,i,n=0,r=!0;if(t=e.indexOf("[",n),0>t)return e;for(i=e.substring(0,t+1);t>0&&r;)n=e.indexOf("]",n)+1,r=n>0,t=e.indexOf("[",n),t>0&&(i+=e.substring(n-1,t+1));return i+=e.substring(n-1)},g=function(t,i,n,r,o,s){var a,u;return e.isArray(i)?e.reduce(i,function(e,i){return e.push(g(t,i,n,r,o,s+1)),e},[]):(u=i.index,a=i.attr,e.isUndefined(n)&&p(a)&&(n=t.get(a)),v(o,t,n,a,r,u))},v=function(t,i,r,o,s,a){return e.reduce(t,function(t,u){var d=e.extend({msgKey:u.msgKey},n,h),l=u.fn.call(d,r,o,u.val,i,s,a);return l===!1||t===!1?!1:l&&!t?e.result(e.extend({},u,n,h),"msg")||l:t},"")},F=function(t,i,n,r){var o,s,a,d=u(t,i);return s=l(i,t),a=g(t,s,n,r,d,0),e.isArray(a)&&(o=e.reduce(e.flatten(a),function(e,t){return e||t},!1),!o)?"":a},_=function(t,i,n){var r,o={},s=!0,a=e.clone(i);return e.each(n,function(e,i){r=F(t,i,e,a),r&&(o[i]=r,s=!1)}),{invalidAttrs:o,isValid:s}},b=function(t,i,n){var r,o,s=t.validation?e.result(t,"validation")||{}:{};return e.contains(e.keys(s),n)?F(t,n,i,e.extend({},t.attributes)):(r=d(n),n=m(n),o=u(t,n),v(o,t,i,n,e.extend({},t.attributes),r))},y=function(t,i){return{preValidate:function(t,i){var n,r=this,o={};return e.isArray(t)?(e.each(t,function(e){n=r.preValidate(e),n&&(o[e]=n)}),e.isEmpty(o)?void 0:o):e.isObject(t)?(e.each(t,function(e,t){n=r.preValidate(t,e),n&&(o[t]=n)}),e.isEmpty(o)?void 0:o):(e.isUndefined(i)&&f(this)&&(i=this.get(t)),b(this,i,t))},isValid:function(n){var o,s,u;return n=n||a(i,t),e.isString(n)?o=[n]:e.isArray(n)&&(o=n),o&&e.each(o,function(t){var n;n=f(this)?this.get(t):r(this.attributes)[t],s=b(this,n,t),s&&(u=u||{},u[t]=s),e.each(this.associatedViews,function(e){s?i.invalid(e,t,s,i.selector):i.valid(e,t,i.selector)},this)},this),n===!0&&(u=this.validate()),u&&this.trigger("invalid",this,u,{validationError:u}),o?!u:this.validation?this._isValid:!0},validate:function(n,s){var u,d,l,c,h,f,p,m=this;return u=!n,d=e.extend({},i,s),l=o(m,a(i,t)),c=e.extend({},l,m.attributes,n),h=r(c),f=n?r(n):h,p=_(m,c,e.pick(h,e.keys(l))),m._isValid=p.isValid,e.each(m.associatedViews,function(t){e.each(l,function(e,i){var n=p.invalidAttrs.hasOwnProperty(i),r=f.hasOwnProperty(i);n||d.valid(t,i,d.selector),n&&(r||u)&&d.invalid(t,i,p.invalidAttrs[i],d.selector)})}),e.defer(function(){m.trigger("validated",m._isValid,m,p.invalidAttrs),m.trigger("validated:"+(m._isValid?"valid":"invalid"),m,p.invalidAttrs)}),!d.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)},C=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,s,n);var r=n.model||t.model,o=n.collection||t.collection;if("undefined"==typeof r&&"undefined"==typeof o)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.";r?x(t,r,n):o&&(o.each(function(e){x(t,e,n)}),o.bind("add",C,{view:t,options:n}),o.bind("remove",w))},unbind:function(t,i){i=e.extend({},i);var n=i.model||t.model,r=i.collection||t.collection;n?T(n,t):r&&(r.each(function(e){T(e,t)}),r.unbind("add",C),r.unbind("remove",w))},mixin:y(null,i)}}(),s=o.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=o.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},u=o.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"},d=o.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]||d.sentenceCase(e,t)}},l=o.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})}},c=o.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=o.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)},r=function(i){return!(e.isNull(i)||e.isUndefined(i)||e.isString(i)&&""===t(i)||e.isArray(i)&&e.isEmpty(i))},o=function(e,t){return e?e:t};return{format:n.format,formatLabel:n.formatLabel,fn:function(t,i,n,r,o){return e.isString(n)&&(n=r[n]),n.call(r,t,i,o)},inlineFn:function(e,t,i,n,r,o){return i.call(this,e,t,n,r,o)},required:function(t,i,n,s,a){var d=e.isFunction(n)?n.call(s,t,i,a):n;return d||r(t)?d&&!r(t)?this.format(o(this.msgKey,u.required),this.formatLabel(i,s)):void 0:!1},acceptance:function(t,i,n,r){return"true"===t||e.isBoolean(t)&&t!==!1?void 0:this.format(o(this.msgKey,u.acceptance),this.formatLabel(i,r))},min:function(e,t,n,r){return!i(e)||n>e?this.format(o(this.msgKey,u.min),this.formatLabel(t,r),n):void 0},max:function(e,t,n,r){return!i(e)||e>n?this.format(o(this.msgKey,u.max),this.formatLabel(t,r),n):void 0},range:function(e,t,n,r){return!i(e)||en[1]?this.format(o(this.msgKey,u.range),this.formatLabel(t,r),n[0],n[1]):void 0},length:function(t,i,n,r){return e.isString(t)&&t.length===n?void 0:this.format(o(this.msgKey,u.length),this.formatLabel(i,r),n)},minLength:function(t,i,n,r){return!e.isString(t)||t.lengthn?this.format(o(this.msgKey,u.maxLength),this.formatLabel(i,r),n):void 0},rangeLength:function(t,i,n,r){return!e.isString(t)||t.lengthn[1]?this.format(o(this.msgKey,u.rangeLength),this.formatLabel(i,r),n[0],n[1]):void 0},oneOf:function(t,i,n,r){return e.include(n,t)?void 0:this.format(o(this.msgKey,u.oneOf),this.formatLabel(i,r),n.join(", "))},equalTo:function(e,t,i,n,r){return e!==r[i]?this.format(o(this.msgKey,u.equalTo),this.formatLabel(t,n),this.formatLabel(i,n)):void 0},pattern:function(e,t,i,n){return r(e)&&e.toString().match(a[i]||i)?void 0:this.format(o(this.msgKey,u[i])||u.inlinePattern,this.formatLabel(t,n),i)}}}();return o}),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 r=i.extend({defaultMapping:null,initialize:function(t,i){this._computed=[],this._cache={},this._currentUpdateEvents=[],this._modelConfigs=[],i=i||{},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(i){var n,r=new t.Deferred;return i=i||{},e.defaults(i,{rollback:!0,force:!0}),this.isTrackingObjectModel()?(function(t){function n(n,o,l){u[o.cid]={success:l,response:n},a+s===c&&(a>0?(i.rollback&&e.each(t._getAllModels(!0),function(e){e.set(d[e.cid]),u[e.cid].success&&e.save()}),t.trigger("save-fail",u),r.reject(u)):(t.trigger("save-success",u),r.resolve(u)))}var o,s=0,a=0,u={},d={},l=t._getAllModels(!0),c=l.length;if(!i.force&&(o=t.checkIfModelsAreStale(),o.length>0))throw{name:"Stale data",staleModels:o};e.each(l,function(e){d[e.cid]=t._getTrackedModelFields(e)}),t.push(),e.each(l,function(e){e.save().fail(function(){a++,n(arguments,e,!1)}).done(function(){s++,n(arguments,e,!0)})})}(this),r.promise()):(n={none:{success:!1,response:[{responseJSON:{generalReasons:[{messageKey:"no.models.were.bound.to.form"}]}}]}},this.trigger("save-fail",n),(new t.Deferred).reject(n).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 r=this._cache[e.cid]!==n;return t&&(r?t[e.cid]=e:t[e.cid]&&delete t[e.cid]),r},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 r="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:r})},_clone: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._clone(n.get(e)))},this):i.set(this._clone(n.attributes))},_updateFormField:function(e,t){this.formModel.set(this.field,t),this.formModel._updateCache(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},_updateFormModel:function(t){e.each(t.changedAttributes(),function(e,t){this.set(t,this._clone(e))},this),this._updateCache(t)},_updateCache:function(e){this._cache[e.cid]=this._generateHashValue(e)},_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)},_mappingHasModels:function(e){return e&&(e.model||e.models)},_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={},r={},o=[];return e.each(this._getAllModelConfigs(),function(e){e.model.cid===t.cid&&o.push(e)}),i=e.reduce(o,function(e,t){return e||!t.fields},!1),i?r=this._clone(t.attributes):e.each(o,function(i){e.each(i.fields,function(e){n[e]||(n[e]=!0,r[e]=this._clone(t.get(e)))},this)},this),r},_getAllModels:function(t){var i={},n=e.pluck(this._getAllModelConfigs(),"model");if(t){var r=[];e.each(n,function(e){i[e.cid]||(i[e.cid]=!0,r.push(e))}),n=r}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,r){e.each(r,function(n){n.fields?e.each(n.fields,function(e){i.push(t._clone(n.model.get(e)))}):i.push(t._clone(n.model.attributes))}),n.apply(t,i)}(this.formModel,this.pull,this.models)}});return e.extend(r.prototype,n.mixin),r}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./guidManager","./templateRenderer","./Cell"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./guidManager"),require("./templateRenderer"),require("./Cell")):(e.Torso=e.Torso||{},e.Torso.View=t(e._,e.Backbone,e.Torso.Utils.guidManager,e.Torso.Utils.templateRenderer,e.Torso.Cell))}(this,function(e,t,i,n,r){"use strict";var o=t.View.extend({_GUID:null,_childViews:null,viewState:null,template:null,_isActive:!1,_isAttached:!1,_isDisposed:!1,"super":function(){this.generateGUID(),this._childViews={},this.viewState=new r},initialize:function(){this["super"](),this.render(),this.activate()},prepare:function(){return this.model?this.model.toJSON():{}},render:function(){this.template&&(this.templateRender(this.$el,this.template,this.prepare()),this.delegateEvents())},generateGUID:function(){null===this._GUID&&(this._GUID=i.generate(this))},getGUID:function(){return this._GUID},templateRender:function(e,t,i,r){this.detachChildViews(),n.render(e,t,i,r)},createPrivateCollection:function(e){return e.createPrivateCollection(this._GUID) +},cleanupSelf:function(){this.detach(),this.cleanupChildViews(),this.remove(),this.off(),this.stopListening(),this.viewState&&(this.viewState.off(),this.viewState.stopListening()),delete this.$el,delete this.el,this._isDisposed=!0},deactivateCallback:e.noop,activateCallback:e.noop,hasChildViews:function(){return!e.isEmpty(this._childViews)},getChildViews:function(){return e.values(this._childViews)},cleanupChildViews:function(){e.each(this._childViews,function(e){e.dispose()})},deactivateChildViews:function(){e.each(this._childViews,function(e){e.deactivate()})},activateChildViews:function(){e.each(this._childViews,function(e){e.activate()})},detachChildViews:function(){e.each(this._childViews,function(e){e.detach()})},registerChildView:function(e){return this._childViews[e.cid]=e,e},unregisterChildView:function(e){return delete this._childViews[e.cid],e},injectView:function(e,t){var i=this.$el.find("[inject="+e+"]");t&&i.size()>0&&this.attachChildView(i,t)},attachChildView:function(e,t){t.detach(),this.registerChildView(t),t.attach(e)},detach:function(){this.isAttached()&&(this.injectionSite?this.$el.replaceWith(this.injectionSite):this.$el.detach(),this.deactivate(),this._isAttached=!1)},attach:function(e){this.isAttached()||(this.deactivate(),this.render(),this.injectionSite=e.replaceWith(this.$el),this.activate(),this._isAttached=!0)},isAttached:function(){return this._isAttached},deactivate:function(){this.deactivateChildViews(),this.isActive()&&(this.undelegateEvents(),this.deactivateCallback(),this._isActive=!1)},activate:function(){this.activateChildViews(),this.isActive()||(this.delegateEvents(),this.activateCallback(),this._isActive=!0)},isActive:function(){return this._isActive},dispose:function(){this.cleanupSelf()},isDisposed:function(){return this._isDisposed}});return 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 r,o,s,a;a=function(e){e._delayedRenderTimeout&&(clearTimeout(e._delayedRenderTimeout),e._delayedRenderTimeout=null,e.render())},s=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()}},r=function(e){var t=this.getChildView(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())},o=function(e){var t,i,n,r=this.modelsToRender(),o=r.indexOf(e);o>-1&&(this._createChildViews(),this.hasChildViews()?(a(this),t=this.getChildView(e),i=this.getChildView(r[o+1]),n=this.getChildView(r[o-1]),i?i.$el.before(t.$el):n?n.$el.after(t.$el):this._delayedRender()):this._delayedRender())};var u=i.extend({className:"",_collection:null,_modelName:"",_childView:null,_modelToViewMap:null,_template:null,_emptyTemplate:null,_childContext:null,_renderWait:0,_delayedRender:null,_delayedRenderTimeout:null,initialize:function(e){this["super"](),this.listViewSetup(e),this.render()},listViewSetup:function(e){this.$el;if(e=e||{},this._modelName=e.childModel||"model",this._collection=e.collection,this._childView=e.childView,this._template=e.template,this._childrenContainer=e.childrenContainer,this._template&&!this._childrenContainer)throw"Children container is required when using a template";this._emptyTemplate=e.emptyTemplate,this.modelsToRender=e.modelsToRender||this.modelsToRender,this._childContext=e.childContext,this._modelToViewMap={},this._renderWait=e.renderWait||this._renderWait,this._modelId=e.modelId||"cid",this._createChildViews(),this._delayedRender=s(this._renderWait,this),this.listenTo(this._collection,"remove",r,this),this.listenTo(this._collection,"add",o,this),this.listenTo(this._collection,"sort",this._delayedRender,this),this.listenTo(this._collection,"reset",this.update,this)},render:function(){var e,i=n.copyTopElement(this.$el);this._template?(i.html(this._template(this.prepare())),e=i.find("[inject="+this._childrenContainer+"]")):(e=t(""),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.getChildView(e);t.render()},this)},prepare:function(){return{}},prepareEmpty:function(){return{}},modelsToRender:function(){return this._collection?this._collection.models:[]},update:function(){this._createChildViews(),this._delayedRender()},getChildView:function(e){return e?this._childViews[this._modelToViewMap[e[this._modelId]]]:void 0},_createChildViews:function(){e.each(this.modelsToRender(),function(e){var t=this.getChildView(e);t||(t=this._createChildView(e),this.trigger("child-view-added",{model:e,view:t}))},this)},_buildChildViewsFragment:function(){var i=document.createDocumentFragment();return e.each(this.modelsToRender(),function(e){var t=this.getChildView(e);t&&i.appendChild(t.el)},this),t(i)},_createChildView:function(e){var t=this.registerChildView(new this._childView(this._generateChildArgs(e)));return 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 u}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","jquery","./View","./FormModel"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("jquery"),require("./View"),require("./FormModel")):(e.Torso=e.Torso||{},e.Torso.FormView=t(e._,e.jQuery||e.Zepto||e.ender||e.$,e.Torso.View,e.Torso.FormModel))}(this,function(e,t,i,n){"use strict";var r=i.extend({initialize:function(t){this["super"](),t=t||{},this.feedbackModel=new Backbone.Model,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._feedbackEvents=[],this._bindings=e.extend({},this.bindings||{},t.bindings||{}),this.render()},prepare:function(){return{model:this.model.toJSON(),formErrors:0!==e.size(this._errors)?this._errors:null,formSuccess:this._success}},render:function(){var e=this.prepare();this.unplug(),this.templateRender(this.$el,this.template,e),this.plug(),this.delegateEvents()},delegateEvents:function(){this._generateStickitBindings(),this.stickit(),i.prototype.delegateEvents.call(this),this._generateFeedbackBindings(),this._generateFeedbackModelCallbacks()},unplug:function(){},plug:function(){},valid:function(){this._success=!0,this._errors=[]},invalid:function(e,t){this._success=!1,this._errors=t},invokeFeedback:function(t,i,n){var r,o=e.find(this.feedback,function(i){var n=i.to;return e.isArray(n)?e.contains(n,t):t===n}),s=t;o&&(n&&(s=this._substituteIndicesUsingMap(t,n)),r=o.then.call(this,i,n),this._processFeedbackThenResult(r,s))},dispose:function(){this.unstickit(),r.__super__.dispose.apply(this,arguments)},_generateStickitBindings:function(){var i=this;this.bindings=e.extend({},this._bindings),e.each(this.$el.find("[data-model]"),function(e){var n=t(e).data("model"),r=i._getFieldOptions(n),o=i._generateModelFieldBinding(n,r);i.bindings['[data-model="'+n+'"]']=o})},_generateFeedbackModelCallbacks:function(){var i=this;i.feedbackModel.off(),e.each(this.$el.find("[data-feedback]"),function(n){var r=t(n).data("feedback");i.feedbackModel.on("change:"+r,function(t){return function(){var n,r=i.feedbackModel.get(t);r&&(n=i.$el.find('[data-feedback="'+t+'"]'),e.each(r,function(t,r){var o;o="_"===e.first(r)?i[r.slice(1)]:n[r],e.isArray(t)?o.apply(n,t):void 0!==t&&o.call(n,t)}))}}(r))}),e.each(i.feedbackModel.attributes,function(e,t){i.feedbackModel.trigger("change:"+t)})},_getFieldOptions:function(e){return e=this._stripAllAttribute(e),this.fields[e]||{}},_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)+"]")})},_processFeedbackThenResult:function(e,i){var n=t.extend({},e);this.feedbackModel.set(i,n,{silent:!0}),this.feedbackModel.trigger("change:"+i)},_generateModelFieldBinding:function(t,i){var n=this._getAllIndexTokens(t);return{observe:t,onSet:function(t){var r=[t];return r.push(n),r=e.flatten(r),i.modelFormat?i.modelFormat.apply(this,r):t},onGet:function(t){var r=[t];return r.push(n),r=e.flatten(r),i.viewFormat?i.viewFormat.apply(this,r):t}}},_generateFeedbackBindings:function(){var i,n=this;for(i=0;i0&&(r=e.substring(0,o)),this.$el.find('[data-feedback^="'+r+'"]').filter(function(){return i._stripAllAttribute(t(this).data("feedback"))===n})},_generateWhenEvents:function(t,i){var n=this,r=[];return e.each(t,function(t,o){var s,a=[o],u="@"===o.charAt(0);"on"!==o&&(u&&(o=o.substring(1),s=n._substituteIndicesUsingMap(o,i),a=e.flatten(n._generateSubAttributes(s,n.model))),e.each(a,function(i){e.each(t,function(e){var t=e+" "+i;u&&(t=e+' [data-model="'+i+'"]'),r.push(t)})}))}),r},_generateSubAttributes:function(e,t){var i,n,r,o,s,a=e.indexOf("[]");if(-1===a)return[e];if(n=e.substring(0,a),r=e.substring(a+2),o=[],s=t.get(n),!s)return[e];for(i=0;i