From ef3a13799c69bc50ca3e40e379c8c075b96c90f1 Mon Sep 17 00:00:00 2001 From: Josh Young Date: Mon, 15 Aug 2016 23:07:17 -0400 Subject: [PATCH] Fixing interaction between stickit and template renderer for option tags. --- .../classes/Torso.Utils.handlebarsUtils.html | 4 +- .../classes/Torso.Utils.templateRenderer.html | 14 +++---- docs/js/data.json | 37 ++++++++++++++----- docs/js/files/modules_handlebarsUtils.js.html | 4 +- .../js/files/modules_templateRenderer.js.html | 22 +++++++++++ modules/handlebarsUtils.js | 4 +- modules/templateRenderer.js | 22 +++++++++++ torso-bundle.js | 26 ++++++++++++- torso-bundle.min.js | 4 +- 9 files changed, 111 insertions(+), 26 deletions(-) diff --git a/docs/js/classes/Torso.Utils.handlebarsUtils.html b/docs/js/classes/Torso.Utils.handlebarsUtils.html index 6cf27405..2569887f 100644 --- a/docs/js/classes/Torso.Utils.handlebarsUtils.html +++ b/docs/js/classes/Torso.Utils.handlebarsUtils.html @@ -442,7 +442,7 @@

Handlebars.helpers.formAttr

Usage: {{formAttr 'fieldName[x].sub' 'id, for' value='demo' x=123}} -Generates: id="first-name-123_sub-demo" for="first-name-123_sub"

+Generates: id="first-name-123_sub-demo" for="first-name-123_sub" value="demo"

@@ -538,7 +538,7 @@

Handlebars.helpers.labelFor

-

Usage: {{label 'fieldName' value="suffix"}} +

Usage: {{labelFor 'fieldName' value="suffix"}} Generates: for="field-name-suffix"

diff --git a/docs/js/classes/Torso.Utils.templateRenderer.html b/docs/js/classes/Torso.Utils.templateRenderer.html index ac19dfa5..0094c86d 100644 --- a/docs/js/classes/Torso.Utils.templateRenderer.html +++ b/docs/js/classes/Torso.Utils.templateRenderer.html @@ -103,7 +103,7 @@

Torso.Utils.templateRenderer Class

- Defined in: modules/templateRenderer.js:132 + Defined in: modules/templateRenderer.js:154
Module: Torso @@ -195,7 +195,7 @@

copyTopElement

Defined in - modules/templateRenderer.js:197 + modules/templateRenderer.js:219

@@ -261,7 +261,7 @@

getCaretPosition

Defined in - modules/templateRenderer.js:222 + modules/templateRenderer.js:244

@@ -417,7 +417,7 @@

hotswapKeepCaret

Defined in - modules/templateRenderer.js:169 + modules/templateRenderer.js:191

@@ -502,7 +502,7 @@

render

Defined in - modules/templateRenderer.js:143 + modules/templateRenderer.js:165

@@ -631,7 +631,7 @@

setCaretPosition

Defined in - modules/templateRenderer.js:252 + modules/templateRenderer.js:274

@@ -708,7 +708,7 @@

supportsSelection

Defined in - modules/templateRenderer.js:211 + modules/templateRenderer.js:233

diff --git a/docs/js/data.json b/docs/js/data.json index 632fe0f0..5371b36c 100644 --- a/docs/js/data.json +++ b/docs/js/data.json @@ -552,7 +552,7 @@ "module": "Torso", "namespace": "Torso.Utils", "file": "modules/templateRenderer.js", - "line": 132, + "line": 154, "description": "Static Template Engine.\nAll template renders should be piped through this method." }, "Torso": { @@ -4646,7 +4646,7 @@ { "file": "modules/handlebarsUtils.js", "line": 28, - "description": "Usage: {{label 'fieldName' value=\"suffix\"}}\nGenerates: for=\"field-name-suffix\"", + "description": "Usage: {{labelFor 'fieldName' value=\"suffix\"}}\nGenerates: for=\"field-name-suffix\"", "itemtype": "method", "name": "Handlebars.helpers.labelFor", "params": [ @@ -4738,7 +4738,7 @@ { "file": "modules/handlebarsUtils.js", "line": 66, - "description": "Usage: {{formAttr 'fieldName[x].sub' 'id, for' value='demo' x=123}}\nGenerates: id=\"first-name-123_sub-demo\" for=\"first-name-123_sub\"", + "description": "Usage: {{formAttr 'fieldName[x].sub' 'id, for' value='demo' x=123}}\nGenerates: id=\"first-name-123_sub-demo\" for=\"first-name-123_sub\" value=\"demo\"", "itemtype": "method", "name": "Handlebars.helpers.formAttr", "params": [ @@ -4844,7 +4844,22 @@ }, { "file": "modules/templateRenderer.js", - "line": 143, + "line": 40, + "description": "Stickit will rely on the 'stickit-bind-val' jQuery data attribute to determine the value to use for a given option.\nIf the value DOM attribute is not the same as the stickit-bind-val, then this will clear the jquery data attribute\nso that stickit will use the value DOM attribute of the option. This happens when templateRenderer merges\nthe attributes of the newNode into a current node of the same type when the current node has the stickit-bind-val\njQuery data attribute set.\n\nIf the node value is not set, then the stickit-bind-val might be how the view is communicating the value for stickit to use\n(possibly in the case of non-string values). In this case trust the stickit-bind-val.", + "params": [ + { + "name": "node", + "description": "the DoM element to test and fix the stickit data on.", + "type": "Node" + } + ], + "class": "Torso.Utils.templateRenderer", + "module": "Torso", + "namespace": "Torso.Utils" + }, + { + "file": "modules/templateRenderer.js", + "line": 165, "description": "Performs efficient re-rendering of a template.", "itemtype": "method", "name": "render", @@ -4898,7 +4913,7 @@ }, { "file": "modules/templateRenderer.js", - "line": 169, + "line": 191, "description": "Call this.hotswap but also keeps the caret position the same", "params": [ { @@ -4925,7 +4940,7 @@ }, { "file": "modules/templateRenderer.js", - "line": 197, + "line": 219, "description": "Produces a copy of the element tag with attributes but with no contents", "params": [ { @@ -4946,7 +4961,7 @@ }, { "file": "modules/templateRenderer.js", - "line": 211, + "line": 233, "description": "Determines if the element supports selection. As per spec, https://html.spec.whatwg.org/multipage/forms.html#do-not-apply\nselection is only allowed for text, search, tel, url, password. Other input types will throw an exception in chrome", "params": [ { @@ -4967,7 +4982,7 @@ }, { "file": "modules/templateRenderer.js", - "line": 222, + "line": 244, "description": "Method that returns the current caret (cursor) position of a given element.\nSource: http://stackoverflow.com/questions/2897155/get-cursor-position-in-characters-within-a-text-input-field", "itemtype": "method", "name": "getCaretPosition", @@ -4988,7 +5003,7 @@ }, { "file": "modules/templateRenderer.js", - "line": 252, + "line": 274, "description": "Method that returns sets the current caret (cursor) position of a given element and puts it in focus.\nSource: http://stackoverflow.com/questions/512528/set-cursor-position-in-html-textbox", "itemtype": "method", "name": "setCaretPosition", @@ -5051,6 +5066,10 @@ { "message": "Missing item type\nViewStateCell is a NestedCell that holds view state data and can trigger\nchange events. These changes events will propogate up and trigger on the view\nas well.", "line": " modules/View.js:13" + }, + { + "message": "Missing item type\nStickit will rely on the 'stickit-bind-val' jQuery data attribute to determine the value to use for a given option.\nIf the value DOM attribute is not the same as the stickit-bind-val, then this will clear the jquery data attribute\nso that stickit will use the value DOM attribute of the option. This happens when templateRenderer merges\nthe attributes of the newNode into a current node of the same type when the current node has the stickit-bind-val\njQuery data attribute set.\n\nIf the node value is not set, then the stickit-bind-val might be how the view is communicating the value for stickit to use\n(possibly in the case of non-string values). In this case trust the stickit-bind-val.", + "line": " modules/templateRenderer.js:40" } ] } \ No newline at end of file diff --git a/docs/js/files/modules_handlebarsUtils.js.html b/docs/js/files/modules_handlebarsUtils.js.html index ad9f1b54..cf5787a6 100644 --- a/docs/js/files/modules_handlebarsUtils.js.html +++ b/docs/js/files/modules_handlebarsUtils.js.html @@ -130,7 +130,7 @@

File: modules/handlebarsUtils.js

MODEL_KEY = 'model'; /** - * Usage: {{label 'fieldName' value="suffix"}} + * Usage: {{labelFor 'fieldName' value="suffix"}} * Generates: for="field-name-suffix" * @method Handlebars.helpers.labelFor * @param field {String} The field name to convert to a compliant "for" attribute @@ -169,7 +169,7 @@

File: modules/handlebarsUtils.js

/** * Usage: {{formAttr 'fieldName[x].sub' 'id, for' value='demo' x=123}} - * Generates: id="first-name-123_sub-demo" for="first-name-123_sub" + * Generates: id="first-name-123_sub-demo" for="first-name-123_sub" value="demo" * @method Handlebars.helpers.formAttr * @param field {String} The field name to convert to a compliant data-feedback attribute * @param options {<Handlebars context>} Always passed in as final argument diff --git a/docs/js/files/modules_templateRenderer.js.html b/docs/js/files/modules_templateRenderer.js.html index cc1f01c3..67613dec 100644 --- a/docs/js/files/modules_templateRenderer.js.html +++ b/docs/js/files/modules_templateRenderer.js.html @@ -141,6 +141,26 @@

File: modules/templateRenderer.js

} } + /** + * Stickit will rely on the 'stickit-bind-val' jQuery data attribute to determine the value to use for a given option. + * If the value DOM attribute is not the same as the stickit-bind-val, then this will clear the jquery data attribute + * so that stickit will use the value DOM attribute of the option. This happens when templateRenderer merges + * the attributes of the newNode into a current node of the same type when the current node has the stickit-bind-val + * jQuery data attribute set. + * + * If the node value is not set, then the stickit-bind-val might be how the view is communicating the value for stickit to use + * (possibly in the case of non-string values). In this case trust the stickit-bind-val. + * + * @param node {Node} the DoM element to test and fix the stickit data on. + */ + function cleanupStickitData(node) { + var $node = $(node); + var stickitValue = $node.data('stickit-bind-val'); + if (node.tagName === 'OPTION' && node.value !== undefined && stickitValue !== node.value) { + $node.removeData('stickit-bind-val'); + } + } + /* * Swap method for Element Nodes * @param currentNode {Element} The pre-existing DOM Element to update @@ -185,6 +205,8 @@

File: modules/templateRenderer.js

currentNode.setAttribute(attrib.name, attrib.value); }); + cleanupStickitData(currentNode); + // Quick check to see if we need to bother comparing sub-levels if ($currentNode.html() === $newNode.html()) { return; diff --git a/modules/handlebarsUtils.js b/modules/handlebarsUtils.js index d85769b5..ee6e665e 100644 --- a/modules/handlebarsUtils.js +++ b/modules/handlebarsUtils.js @@ -26,7 +26,7 @@ MODEL_KEY = 'model'; /** - * Usage: {{label 'fieldName' value="suffix"}} + * Usage: {{labelFor 'fieldName' value="suffix"}} * Generates: for="field-name-suffix" * @method Handlebars.helpers.labelFor * @param field {String} The field name to convert to a compliant "for" attribute @@ -65,7 +65,7 @@ /** * Usage: {{formAttr 'fieldName[x].sub' 'id, for' value='demo' x=123}} - * Generates: id="first-name-123_sub-demo" for="first-name-123_sub" + * Generates: id="first-name-123_sub-demo" for="first-name-123_sub" value="demo" * @method Handlebars.helpers.formAttr * @param field {String} The field name to convert to a compliant data-feedback attribute * @param options {} Always passed in as final argument diff --git a/modules/templateRenderer.js b/modules/templateRenderer.js index d746f9fe..a9e6d83f 100644 --- a/modules/templateRenderer.js +++ b/modules/templateRenderer.js @@ -37,6 +37,26 @@ } } + /** + * Stickit will rely on the 'stickit-bind-val' jQuery data attribute to determine the value to use for a given option. + * If the value DOM attribute is not the same as the stickit-bind-val, then this will clear the jquery data attribute + * so that stickit will use the value DOM attribute of the option. This happens when templateRenderer merges + * the attributes of the newNode into a current node of the same type when the current node has the stickit-bind-val + * jQuery data attribute set. + * + * If the node value is not set, then the stickit-bind-val might be how the view is communicating the value for stickit to use + * (possibly in the case of non-string values). In this case trust the stickit-bind-val. + * + * @param node {Node} the DoM element to test and fix the stickit data on. + */ + function cleanupStickitData(node) { + var $node = $(node); + var stickitValue = $node.data('stickit-bind-val'); + if (node.tagName === 'OPTION' && node.value !== undefined && stickitValue !== node.value) { + $node.removeData('stickit-bind-val'); + } + } + /* * Swap method for Element Nodes * @param currentNode {Element} The pre-existing DOM Element to update @@ -81,6 +101,8 @@ currentNode.setAttribute(attrib.name, attrib.value); }); + cleanupStickitData(currentNode); + // Quick check to see if we need to bother comparing sub-levels if ($currentNode.html() === $newNode.html()) { return; diff --git a/torso-bundle.js b/torso-bundle.js index 9b43000d..76053dfc 100644 --- a/torso-bundle.js +++ b/torso-bundle.js @@ -83,7 +83,7 @@ MODEL_KEY = 'model'; /** - * Usage: {{label 'fieldName' value="suffix"}} + * Usage: {{labelFor 'fieldName' value="suffix"}} * Generates: for="field-name-suffix" * @method Handlebars.helpers.labelFor * @param field {String} The field name to convert to a compliant "for" attribute @@ -122,7 +122,7 @@ /** * Usage: {{formAttr 'fieldName[x].sub' 'id, for' value='demo' x=123}} - * Generates: id="first-name-123_sub-demo" for="first-name-123_sub" + * Generates: id="first-name-123_sub-demo" for="first-name-123_sub" value="demo" * @method Handlebars.helpers.formAttr * @param field {String} The field name to convert to a compliant data-feedback attribute * @param options {} Always passed in as final argument @@ -298,6 +298,26 @@ } } + /** + * Stickit will rely on the 'stickit-bind-val' jQuery data attribute to determine the value to use for a given option. + * If the value DOM attribute is not the same as the stickit-bind-val, then this will clear the jquery data attribute + * so that stickit will use the value DOM attribute of the option. This happens when templateRenderer merges + * the attributes of the newNode into a current node of the same type when the current node has the stickit-bind-val + * jQuery data attribute set. + * + * If the node value is not set, then the stickit-bind-val might be how the view is communicating the value for stickit to use + * (possibly in the case of non-string values). In this case trust the stickit-bind-val. + * + * @param node {Node} the DoM element to test and fix the stickit data on. + */ + function cleanupStickitData(node) { + var $node = $(node); + var stickitValue = $node.data('stickit-bind-val'); + if (node.tagName === 'OPTION' && node.value !== undefined && stickitValue !== node.value) { + $node.removeData('stickit-bind-val'); + } + } + /* * Swap method for Element Nodes * @param currentNode {Element} The pre-existing DOM Element to update @@ -342,6 +362,8 @@ currentNode.setAttribute(attrib.name, attrib.value); }); + cleanupStickitData(currentNode); + // Quick check to see if we need to bother comparing sub-levels if ($currentNode.html() === $newNode.html()) { return; diff --git a/torso-bundle.min.js b/torso-bundle.min.js index 20b57dc7..ac1ba487 100644 --- a/torso-bundle.min.js +++ b/torso-bundle.min.js @@ -1,2 +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(["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?module.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,s){return e.helpers.formAttr(n,i+", "+t+", name, id",s)}),e.registerHelper("feedback",function(i,n){return e.helpers.formAttr(i,t,n)}),e.registerHelper("formAttr",function(n,s,r){var o,a,c=r.hash?r.hash.value:void 0,d=e.helpers.injectFieldIndices(n,r.hash),u="";for(s=s.split(","),o=0;oc;c++)if(d=this.getRequesterIds(u[c]),!e.isUndefined(d))for(n=0;nr;r++){for(o=s.getRequesterIdsAsDictionary(u[r]),a=[],t=0;h>t;t++)o[n[t]]&&(l=s.get(n[t]),l&&a.push(l));c=s.knownPrivateCollections[u[r]],c.set(a,{remove:!1})}})},n).always(function(){delete s.idsFetching[r]})}},{constructor:function(t,i){if(i=i||{},n.call(this,t,i),this.isRequester=i.isRequester,this.parentInstance=i.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")});else{this.requestMap={},this.collectionTrackedIds=[],this.knownPrivateCollections={};var r=e.defaults(e.pick(i,"getByIdsUrl","fetchHttpAction","fetchUsingTrackedIds"),e.pick(this,"getByIdsUrl","fetchHttpAction","fetchUsingTrackedIds"),{getByIdsUrl:"/ids",fetchHttpAction:"GET",fetchUsingTrackedIds:!0});e.extend(this,r),s(this)}}}};return n}),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.cell=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.loading=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)).always(function(){n.loadedOnce||(n.loadedOnce=!0,n.loadedOnceDeferred.resolve()),n.loading=!1}).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})})}}};return t}),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(["underscore","backbone","./mixins/cellMixin"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./mixins/cellMixin")):(e.Torso=e.Torso||{},e.Torso.Cell=t(e._,e.Backbone,e.Torso.Mixins.cell))}(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","./mixins/pollingMixin","./mixins/cacheMixin","./mixins/loadingMixin"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./mixins/pollingMixin"),require("./mixins/cacheMixin"),require("./mixins/loadingMixin")):(e.Torso=e.Torso||{},e.Torso.Collection=t(e._,e.Backbone,e.Torso.Mixins.polling,e.Torso.Mixins.cache,e.Torso.Mixins.loading))}(this,function(e,t,i,n,s){"use strict";var r=t.Collection.extend({filterDefault:function(){return this.constructor(this)},dispose:function(){this.unbind(),this.off(),this.stopListening(),this.stopPolling(),this.isRequester&&this.requesterDispose()}});return e.extend(r.prototype,i),r=r.extend(s(r)),r=r.extend(n(r))}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./mixins/pollingMixin"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./mixins/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","./mixins/cellMixin","backbone-nested"],t):"object"==typeof exports?(require("backbone-nested"),module.exports=t(require("underscore"),require("backbone"),require("./mixins/cellMixin"))):(e.Torso=e.Torso||{},e.Torso.NestedCell=t(e._,e.Backbone,e.Torso.Mixins.cell))}(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","./mixins/pollingMixin","backbone-nested"],t):"object"==typeof exports?(require("backbone-nested"),module.exports=t(require("underscore"),require("backbone"),require("./mixins/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){if("function"==typeof define&&define.amd)define(["underscore","./Cell"],t);else if("object"==typeof exports){var i=require("underscore"),n=require("./Cell");module.exports=t(i,n)}else e.Torso=e.Torso||{},e.Torso.Behavior=t(e._,e.Torso.Cell)}(this,function(e,t){"use strict";var i={"before-attached-callback":"_attached","before-detached-callback":"_detached","before-activate-callback":"_activate","before-deactivate-callback":"_deactivate","before-dispose-callback":"_dispose","render:before-attach-tracked-views":"attachTrackedViews","render:begin":"prerender","render:complete":"postrender","initialize:begin":"preinitialize","initialize:complete":"postinitialize"},n=t.extend({cidPrefix:"b",mixin:{},prepare:e.noop,constructor:function(i,n){if(i=i||{},!i.view)throw new Error("Torso Behavior constructed without behaviorOptions.view");if(this.view=i.view,!i.alias)throw new Error("Torso Behavior constructed without behaviorOptions.alias");this.alias=i.alias,this.cid=e.uniqueId(this.cidPrefix),this.__bindLifecycleMethods(),t.apply(this,arguments),this.__bindEventCallbacks()},__augmentViewPrepare:function(){var t=e.bind(this.view.prepare,this.view),i=e.wrap(t,this.__viewPrepareWrapper);this.view.prepare=e.bind(i,this)},__viewPrepareWrapper:function(t){var i=t()||{},n=e.omit(this.toJSON(),"view");return e.extend(n,this.prepare()),i[this.alias]=n,i},__bindLifecycleMethods:function(){this.listenTo(this.view,"initialize:complete",this.__augmentViewPrepare),e.each(i,function(e,t){this.listenTo(this.view,t,this[e])},this)},__bindEventCallbacks:function(){var t=e.result(this,"events"),i=this.view.events;if(!i){if(!t)return;i={}}var n=this.__namespaceEvents(t),s=this.__bindEventCallbacksToBehavior(n);e.isFunction(i)?this.view.events=e.wrap(e.bind(i,this.view),function(t){return e.extend(s,t())}):e.isObject(i)&&(this.view.events=e.extend(s,i))},__namespaceEvents:function(t){var i=/^(\S+)\s*(.*)$/,n={},s=this.cid;return e.each(t,function(e,t){var r=t.match(i),o=r[1],a=r[2],c=o+".behavior."+s;n[[c,a].join(" ")]=e}),n},__bindEventCallbacksToBehavior:function(t){return e.mapObject(t,function(t){return e.isFunction(t)||(t=this[t]),e.bind(t,this)},this)}});return 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","jquery","backbone","./templateRenderer","./Cell","./NestedCell"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("jquery"),require("backbone"),require("./templateRenderer"),require("./Cell"),require("./NestedCell")):(e.Torso=e.Torso||{},e.Torso.View=t(e._,e.$,e.Backbone,e.Torso.Utils.templateRenderer,e.Torso.Cell,e.Torso.NestedCell))}(this,function(e,t,i,n,s,r){"use strict";var o=r.extend({initialize:function(e,t){t=t||{},this.view=t.view},trigger:function(e){"change"!==e&&0!==e.indexOf("change:")||a.prototype.trigger.apply(this.view,arguments),r.prototype.trigger.apply(this,arguments)}}),a=i.View.extend({viewState:null,template:void 0,feedback:null,feedbackCell:null,behaviors:null,templateRendererOptions:void 0,__behaviorInstances:null,__childViews:null,__sharedViews:null,__isActive:!1,__isAttachedToParent:!1,__isDisposed:!1,__attachedCallbackInvoked:!1,__feedbackOnEvents:null,__feedbackListenToEvents:null,constructor:function(e){e=e||{},this.viewState=new o({},{view:this}),this.feedbackCell=new s,this.__childViews={},this.__sharedViews={},this.__injectionSiteMap={},this.__feedbackOnEvents=[],this.__feedbackListenToEvents=[],this.template=e.template||this.template,this.templateRendererOptions=e.templateRendererOptions||this.templateRendererOptions,this.__initializeBehaviors(e),this.trigger("initialize:begin"),i.View.apply(this,arguments),this.trigger("initialize:complete"),e.noActivate||this.activate()},get:function(){return this.viewState.get.apply(this.viewState,arguments)},set:function(){return this.viewState.set.apply(this.viewState,arguments)},getBehavior:function(e){return this.__behaviorInstances?this.__behaviorInstances[e]:void 0},prepare:function(){return this.model?{model:this.model.toJSON(),view:this.viewState.toJSON()}:{view:this.viewState.toJSON()}},render:function(){var i,n=this;return this.trigger("render:begin"),this.prerender(),this.__updateInjectionSiteMap(),this.trigger("render:before-dom-update"),this.detachTrackedViews(),this.updateDOM(),this.__pendingAttachInfo&&this.__performPendingAttach(),this.trigger("render:after-dom-update"),this.delegateEvents(),this.trigger("render:after-delegate-events"),this.trigger("render:before-attach-tracked-views"),i=this.attachTrackedViews(),t.when.apply(t,e.flatten([i])).done(function(){n.postrender(),n.trigger("render:complete")})},prerender:e.noop,updateDOM:function(){if(this.template){var t=e.result(this,"templateRendererOptions");this.templateRender(this.$el,this.template,this.prepare(),t)}},postrender:e.noop,templateRender:function(t,i,s,r){r=r||{},e.isString(i)&&(r.newHTML=i),n.render(t,i,s,r)},delegateEvents:function(){this.undelegateEvents(),i.View.prototype.delegateEvents.call(this),this.__generateFeedbackBindings(),this.__generateFeedbackCellCallbacks(),e.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.delegateEvents()})},undelegateEvents:function(){i.View.prototype.undelegateEvents.call(this),e.each(this.getTrackedViews(),function(e){e.undelegateEvents()})},attachTo:function(e,i){i=i||{};var n=this;return this.isAttachedToParent()?t.Deferred().resolve().promise():(this.__pendingAttachInfo={$el:e,options:i},this.render().done(function(){!n.__attachedCallbackInvoked&&n.isAttached()&&n.__invokeAttached(),n.__isAttachedToParent=!0}))},attachView:function(i,n,s){s=s||{};var r,o,a=e.isString(i);if(a){if(o=i,r=this.$("[inject="+o+"]"),!r)throw"View.attachView: No injection site found with which to attach this view. View.cid="+this.cid}else r=i;return s.useTransition?this.__transitionNewViewIntoSite(o,n,s):(n.detach(),this.registerTrackedView(n,s),n.attachTo(r,s),s.noActivate||n.activate(),t.Deferred().resolve().promise())},attachTrackedViews:e.noop,_attached:e.noop,isAttachedToParent:function(){return this.__isAttachedToParent},isAttached:function(){return t.contains(document,this.$el[0])},detach:function(){var e;this.isAttachedToParent()&&(e=this.isAttached(),this.injectionSite?(this.$el.replaceWith(this.injectionSite),this.injectionSite=void 0):this.$el.detach(),e&&this.__invokeDetached(),this.undelegateEvents(),this.__isAttachedToParent=!1)},detachTrackedViews:function(t){var i=this.getTrackedViews(t);e.each(i,function(e){e.detach()})},_detached:e.noop,activate:function(){this.__activateTrackedViews(),this.isActive()||(this.trigger("before-activate-callback"),this._activate(),this.__isActive=!0)},_activate:e.noop,isActive:function(){return this.__isActive},deactivate:function(){this.__deactivateTrackedViews(),this.isActive()&&(this.trigger("before-deactivate-callback"),this._deactivate(),this.__isActive=!1)},_deactivate:e.noop,dispose:function(){this.trigger("before-dispose-callback"),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,isDisposed:function(){return this.__isDisposed},hasTrackedViews:function(t){return!e.isEmpty(this.getTrackedViews(t))},getTrackedViews:function(t){return e.values(this.__getTrackedViewsHash(t))},getTrackedView:function(e){var t=this.__childViews[e],i=this.__sharedViews[e];return t||i},registerTrackedView:function(e,t){return t=t||{},this.unregisterTrackedView(e),t.child||!t.shared?this.__childViews[e.cid]=e:this.__sharedViews[e.cid]=e,e},unregisterTrackedView:function(e){return delete this.__childViews[e.cid],delete this.__sharedViews[e.cid],e},unregisterTrackedViews:function(t){var i=this.getTrackedViews(t);e.each(i,function(e){this.unregisterTrackedView(e,t)},this)},transitionOut:function(e,t){this.detach(),e()},transitionIn:function(e,t,i){e(),t()},invokeFeedback:function(t,i,n){var s,r=e.find(this.feedback,function(i){var n=i.to;return e.isArray(n)?e.contains(n,t):t===n}),o=t;r&&(n&&(o=this.__substituteIndicesUsingMap(t,n)),s=r.then.call(this,i,n),this.__processFeedbackThenResult(s,o))},__initializeBehaviors:function(t){var i=this;e.isEmpty(this.behaviors)||(i.__behaviorInstances={},e.each(this.behaviors,function(n,s){var r=n.behavior;if(!r||!e.isFunction(r))throw new Error('Incorrect behavior definition. Expected key "behavior" to be a class but instead got '+String(r));var o=e.pick(n,function(e,t){return"behavior"!==t});o.view=i,o.alias=s;var a=i.__behaviorInstances[s]=new r(o,t);if(a.mixin){var c=e.result(a,"mixin");e.each(c,function(t,n){e.isUndefined(i[n])&&(e.isFunction(t)?i[n]=e.bind(t,a):i[n]=t)})}}))},__performPendingAttach:function(){this.__replaceInjectionSite(this.__pendingAttachInfo.$el,this.__pendingAttachInfo.options),delete this.__pendingAttachInfo},__deactivateTrackedViews:function(t){e.each(this.getTrackedViews(t),function(e){e.deactivate()})},__activateTrackedViews:function(t){e.each(this.getTrackedViews(t),function(e){e.activate()})},__disposeChildViews:function(){e.each(this.__childViews,function(e){e.dispose()})},__transitionNewViewIntoSite:function(t,i,n){var s,r;return n=n||{},s=n.previousView,s||(s=this.__getLastTrackedViewAtInjectionSite(t)),e.defaults(n,{parentView:this,newView:i,previousView:s}),n.useTransition=!1,s==i?this.attachView(t,i,n):s?this.__performTwoWayTransition(t,s,i,n):(r=this.$("[inject="+t+"]"),this.__transitionInView(r,i,n))},__performTwoWayTransition:function(e,i,n,s){var r,o,a=t.Deferred();return this.attachView(e,i,s),s.cachedInjectionSite=i.injectionSite,r=s.newInjectionSite=t(''),s.addBefore?i.$el.before(r):i.$el.after(r),i.injectionSite=void 0,i.transitionOut(a.resolve,s),o=this.__transitionInView(r,n,s),t.when(a.promise(),o)},__transitionInView:function(i,n,s){var r=t.Deferred(),o=this;return s=e.extend({},s),e.defaults(s,{parentView:this,newView:n}),n.transitionIn(function(){o.attachView(i,n,s)},r.resolve,s),r.promise()},__getTrackedViewsHash:function(t){var i={};return t=t||{},t.shared&&(i=e.extend(i,this.__sharedViews)),t.child&&(i=e.extend(i,this.__childViews)),t.child||t.shared||(i=e.extend(i,this.__sharedViews,this.__childViews)),i},__updateInjectionSiteMap:function(){var t=this;this.__injectionSiteMap={},e.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.injectionSite&&(t.__injectionSiteMap[e.injectionSite.attr("inject")]=e)})},__getLastTrackedViewAtInjectionSite:function(t){var i=this.__injectionSiteMap[t];if(i)i=e.contains(this.getTrackedViews(),i)?i:void 0;else{var n=this.getTrackedViews().filter(function(e){return e.injectionSite&&e.injectionSite.attr("inject")==t});i=e.first(n)}return i},__replaceInjectionSite:function(e,t){t=t||{},this.injectionSite=t.replaceMethod?t.replaceMethod(this.$el):e.replaceWith(this.$el),t.discardInjectionSite&&(this.injectionSite=void 0)},__invokeAttached:function(){this.__attachedCallbackInvoked||(this.trigger("before-attached-callback"),this._attached(),this.__attachedCallbackInvoked=!0,e.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.__invokeAttached()}))},__invokeDetached:function(){this.__attachedCallbackInvoked&&(this.trigger("before-detached-callback"),this._detached(),this.__attachedCallbackInvoked=!1),e.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.__invokeDetached()})},__generateFeedbackCellCallbacks:function(){var i=this;i.feedbackCell.off(),e.each(this.$("[data-feedback]"),function(n){var s=t(n).data("feedback");i.feedbackCell.on("change:"+s,function(t){return function(){var n,s=i.feedbackCell.get(t);s&&(n=i.$el.find('[data-feedback="'+t+'"]'),e.each(s,function(t,s){var r;r="_"===e.first(s)?i[s.slice(1)]:n[s],e.isArray(t)?r.apply(n,t):void 0!==t&&r.call(n,t)}))}}(s))}),e.each(i.feedbackCell.attributes,function(e,t){i.feedbackCell.trigger("change:"+t)})},__processFeedbackThenResult:function(e,i){var n=t.extend({},e);this.feedbackCell.set(i,n,{silent:!0}),this.feedbackCell.trigger("change:"+i)},__generateFeedbackBindings:function(){var i,n=this;for(i=0;i0&&(s=e.substring(0,r)),this.$('[data-feedback^="'+s+'"]').filter(function(){return i.__stripAllAttribute(t(this).data("feedback"))===n})},__generateWhenEvents:function(t,i){var n=this,s=[];return e.each(t,function(t,r){var o,a=[r],c="@"===r.charAt(0);"on"===r&&"listenTo"===r||(c&&(r=r.substring(1),o=n.__substituteIndicesUsingMap(r,i),a=e.flatten(n.__generateSubAttributes(o,n.model))),e.each(a,function(i){e.each(t,function(e){var t=e+" "+i;c&&(t=e+' [data-model="'+i+'"]'),s.push(t)})}))}),s},__getAllIndexTokens:function(t){return e.reduce(t.match(/\[.+?\]/g),function(e,t){var i=t.substring(1,t.length-1);return isNaN(i)?e.push(i):e.push(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,s,r,o,a=e.indexOf("[]");if(-1===a)return[e];if(n=e.substring(0,a),s=e.substring(a+2),r=[],o=t.get(n),!o)return[e];for(i=0;i0&&s;)i=e.indexOf("]",n),r.push(parseInt(e.substring(t+1,i),10)),n=i+1,s=n>0,t=e.indexOf("[",n);return r},d=function(t,i,n){var s,r,o,a,c=t.indexOf("[]");if(e.isEmpty(n)&&(n=[]),-1===c)return{attr:t,index:n};s=t.substring(0,c),r=t.substring(c+2),o=[];var u=i.get(s);return e.each(u,function(e,t){a=n.slice(),a.push(t),o.push(d(s+"["+t+"]"+r,i,a))}),o},l=function(e){return t&&e instanceof t},h=function(e){return e.indexOf(".")>0||e.indexOf("]")>0},f=function(e){var t,i,n=0,s=!0;if(t=e.indexOf("[",n),0>t)return e;for(i=e.substring(0,t+1);t>0&&s;)n=e.indexOf("]",n)+1,s=n>0,t=e.indexOf("[",n),t>0&&(i+=e.substring(n-1,t+1));return i+=e.substring(n-1)},p=function(t,i,n,s,r,o){var a,c;return e.isArray(i)?e.reduce(i,function(e,i){return e.push(p(t,i,n,s,r,o+1)),e},[]):(c=i.index,a=i.attr,e.isUndefined(n)&&h(a)&&(n=t.get(a)),_(r,t,n,a,s,c))},_=function(t,i,s,r,o,a){return e.reduce(t,function(t,c){var d=e.extend({msgKey:c.msgKey},n,u),l=c.fn.call(d,s,r,c.val,i,o,a);return l===!1||t===!1?!1:l&&!t?e.result(e.extend({},c,n,u),"msg")||l:t},"")},m=function(t,i,n,s){var r,o,c,u=a(t,i);return o=d(i,t),c=p(t,o,n,s,u,0),e.isArray(c)&&(r=e.reduce(e.flatten(c),function(e,t){return e||t},!1),!r)?"":c},g=function(t,i,n){var s,r={},o=!0,a=e.clone(i);return e.each(n,function(e,i){s=m(t,i,e,a),s&&(r[i]=s,o=!1)}),{invalidAttrs:r,isValid:o}},v=function(t,i,n){var s,r,o=t.validation?e.result(t,"validation")||{}:{}; -return e.contains(e.keys(o),n)?m(t,n,i,e.extend({},t.attributes)):(s=c(n),n=f(n),r=a(t,n),_(r,t,i,n,e.extend({},t.attributes),s))},b=function(t){return{preValidate:function(t,i){var n,s=this,r={};return e.isArray(t)?(e.each(t,function(e){n=s.preValidate(e),n&&(r[e]=n)}),e.isEmpty(r)?void 0:r):e.isObject(t)?(e.each(t,function(e,t){n=s.preValidate(t,e),n&&(r[t]=n)}),e.isEmpty(r)?void 0:r):(e.isUndefined(i)&&l(this)&&(i=this.get(t)),v(this,i,t))},isValid:function(i){var n,r,a;return i=i||o(t),e.isString(i)?n=[i]:e.isArray(i)&&(n=i),n&&e.each(n,function(e){var t;t=l(this)?this.get(e):s(this.attributes)[e],r=v(this,t,e),r&&(a=a||{},a[e]=r)},this),i===!0&&(a=this.validate()),a&&this.trigger("invalid",this,a,{validationError:a}),n?!a:this.validation?this._isValid:!0},validate:function(i,n){var a=this,c=e.extend({},t,n),d=r(a,o(t)),u=e.extend({},d,a.attributes,i),l=e.extend(s(u),i),h=i?s(i):l,f=g(a,u,e.pick(l,e.keys(d)));return a._isValid=f.isValid,e.defer(function(){a.trigger("validated",a._isValid,a,f.invalidAttrs),a.trigger("validated:"+(a._isValid?"valid":"invalid"),a,f.invalidAttrs)}),!c.forceUpdate&&e.intersection(e.keys(f.invalidAttrs),e.keys(h)).length>0?f.invalidAttrs:void 0}}};return{version:"0.11.3",configure:function(t){e.extend(i,t)},mixin:b(i)}}(),o=r.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},a=r.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"},c=r.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]||c.sentenceCase(e,t)}},d=r.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})}},u=r.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(o.number)},s=function(i){return!(e.isNull(i)||e.isUndefined(i)||e.isString(i)&&""===t(i)||e.isArray(i)&&e.isEmpty(i))},r=function(e,t){return e?e:t};return{format:n.format,formatLabel:n.formatLabel,fn:function(t,i,n,s,r){return e.isString(n)&&(n=s[n]),n.call(s,t,i,r)},inlineFn:function(e,t,i,n,s,r){return i.call(this,e,t,n,s,r)},required:function(t,i,n,o,c){var d=e.isFunction(n)?n.call(o,t,i,c):n;return d||s(t)?d&&!s(t)?this.format(r(this.msgKey,a.required),this.formatLabel(i,o)):void 0:!1},acceptance:function(t,i,n,s){return"true"===t||e.isBoolean(t)&&t!==!1?void 0:this.format(r(this.msgKey,a.acceptance),this.formatLabel(i,s))},min:function(e,t,n,s){return!i(e)||n>e?this.format(r(this.msgKey,a.min),this.formatLabel(t,s),n):void 0},max:function(e,t,n,s){return!i(e)||e>n?this.format(r(this.msgKey,a.max),this.formatLabel(t,s),n):void 0},range:function(e,t,n,s){return!i(e)||en[1]?this.format(r(this.msgKey,a.range),this.formatLabel(t,s),n[0],n[1]):void 0},length:function(t,i,n,s){return e.isString(t)&&t.length===n?void 0:this.format(r(this.msgKey,a.length),this.formatLabel(i,s),n)},minLength:function(t,i,n,s){return!e.isString(t)||t.lengthn?this.format(r(this.msgKey,a.maxLength),this.formatLabel(i,s),n):void 0},rangeLength:function(t,i,n,s){return!e.isString(t)||t.lengthn[1]?this.format(r(this.msgKey,a.rangeLength),this.formatLabel(i,s),n[0],n[1]):void 0},oneOf:function(t,i,n,s){return e.include(n,t)?void 0:this.format(r(this.msgKey,a.oneOf),this.formatLabel(i,s),n.join(", "))},equalTo:function(e,t,i,n,s){return e!==s[i]?this.format(r(this.msgKey,a.equalTo),this.formatLabel(t,n),this.formatLabel(i,n)):void 0},pattern:function(e,t,i,n){return s(e)&&e.toString().match(o[i]||i)?void 0:this.format(r(this.msgKey,a[i])||a.inlinePattern,this.formatLabel(t,n),i)}}}();return r}),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 s=i.extend({mapping:void 0,constructor:function(t,n){n=n||{},this.__cache={},this.__currentUpdateEvents=[],this.__currentMappings={},this.__currentObjectModels={},this.validation=e.extend({},this.validation,n.validation),this.labels=e.extend({},this.labels,n.labels),i.apply(this,arguments),this.__initMappings(n),this.pull(),t&&this.set(t),n.startUpdating&&this.startUpdating(),this.trigger("initialization-complete")},getMapping:function(e){return this.__currentMappings[e]},getMappings:function(){return this.__currentMappings},setMapping:function(t,i,n,s){var r,o,a={};e.isString(i)?o=i.split(" "):i===!0?o=void 0:e.isObject(i)&&(i=e.clone(i),r=!0),a.computed=r,r?(a.mapping=i,e.each(this.__getModelAliases(a),function(t){var i=a.mapping[t];e.isString(i)?i=i.split(" "):i===!0&&(i=void 0),a.mapping[t]=i})):a.mapping=o,this.__currentMappings[t]=a,n&&(r?this.setTrackedModels(n,s):this.setTrackedModel(t,n,s))},setMappings:function(t,i,n){e.each(t,function(e,t){this.setMapping(t,e)},this),i&&this.setTrackedModels(i,n)},unsetMapping:function(t,i){var n=this.__findAlias(t);n&&delete this.__currentMappings[n];var s=this.getTrackedModel(n);i&&s&&e.isEmpty(this.__getTrackedModelFields(s))&&this.unsetTrackedModel(s)},unsetMappings:function(){this.__currentMappings={},this.resetUpdating()},getTrackedModel:function(e){return this.__currentObjectModels[e]},getTrackedModels:function(){return e.values(this.__currentObjectModels)},setTrackedModel:function(t,i,n){this.__currentObjectModels[t]=i,this.__updateCache(i),this.resetUpdating(),n&&e.each(this.getMappings(),function(i,n){var s;t===n&&this.__pull(n),i.computed&&(s=this.__getModelAliases(n),e.contains(s,t)&&this.__pull(n))},this)},setTrackedModels:function(t,i){e.each(t,function(e,t){this.setTrackedModel(t,e,i)},this)},unsetTrackedModel:function(e){var t,i=this.__findAlias(e);i&&(t=this.__currentObjectModels[i],delete this.__currentObjectModels[i],this.__updateCache(t)),this.resetUpdating()},unsetTrackedModels:function(){this.__currentObjectModels=[],this.__updateCache(),this.resetUpdating()},push:function(){e.each(this.getMappings(),function(e,t){this.__push(t)},this)},pull:function(){e.each(this.getMappings(),function(e,t){this.__pull(t)},this),this.__updateCache()},save:function(n){var s,r,o=new t.Deferred,a=this;n=n||{},e.defaults(n,{rollback:!0,force:!0});try{r=e.result(a,"url")}catch(c){}return r?i.prototype.save.apply(a,arguments).done(function(){a.push()}):this.isTrackingAnyObjectModel()?(this.__saveToModels(o,n),o.promise()):(s={none:{success:!1,response:[{responseJSON:{generalReasons:[{messageKey:"no.models.were.bound.to.form"}]}}]}},this.trigger("save-fail",s),(new t.Deferred).reject(s).promise())},isTrackingAnyObjectModel:function(){return e.size(this.__currentObjectModels)>0},isUpdating:function(){return this.__currentUpdateEvents.length>0},startUpdating:function(e){this.isTrackingAnyObjectModel()&&!this.isUpdating()&&(e&&this.pull(),this.__setupListeners())},stopUpdating:function(){e.each(this.__currentUpdateEvents,function(e){this.stopListening(e.model,e.eventName)},this),this.__currentUpdateEvents=[]},resetUpdating:function(){this.isUpdating()&&(this.stopUpdating(),this.startUpdating())},isModelStale:function(e,t,i){var n;i=i||{},i[e.cid]||(i[e.cid]=this.__generateHashValue(e)),n=i[e.cid];var s=this.__cache[e.cid]!==n;return t&&(s?t[e.cid]=e:t[e.cid]&&delete t[e.cid]),s},checkIfModelsAreStale:function(){var t={},i=this.__generateAllHashValues();return e.each(this.getTrackedModels(),function(e){this.isModelStale(e,t,i)},this),e.values(t)},__listenToModelField:function(t,i){var n,s;i?(s="change:"+i,n=e.bind(this.__updateFormField,{formModel:this,field:i})):(s="change",n=this.__updateFormModel),this.listenTo(t,s,n),this.__currentUpdateEvents.push({model:t,eventName:s})},__listenToComputedValuesDependency:function(t,i,n){var s,r;r=i?"change:"+i:"change",s=e.bind(this.__invokeComputedPull,{formModel:this,alias:n}),this.listenTo(t,r,s),this.__currentUpdateEvents.push({model:t,eventName:r})},__getComputedModels:function(t){var i=!e.isUndefined(this.getMapping(t)),n={};return e.each(this.__getModelAliases(t),function(e){var t=this.getTrackedModel(e);t?n[e]=t:i=!1},this),i?n:void 0},__getModelAliases:function(t){var i;return i=e.isString(t)?this.getMapping(t):t,e.filter(e.keys(i.mapping),function(e){return"pull"!=e&&"push"!=e})},__getComputedModelConfigs:function(t){var i=!0,n=this.getMapping(t),s=[];return e.each(this.__getModelAliases(t),function(e){var t=this.__createModelConfig(e,n.mapping[e]);t?s.push(t):i=!1},this),i?s:void 0},__saveToModels:function(t,i){function n(n,s,u){c[s.cid]={success:u,response:n},a+o===l&&(a>0?(i.rollback&&e.each(r.getTrackedModels(),function(e){e.set(d[e.cid]),c[e.cid].success&&e.save()}),r.trigger("save-fail",c),t.reject(c)):(r.trigger("save-success",c),t.resolve(c)))}var s,r=this,o=0,a=0,c={},d={},u=r.getTrackedModels(),l=u.length;if(!i.force&&(s=r.checkIfModelsAreStale(),s.length>0))throw{name:"Stale data",staleModels:s};e.each(u,function(e){d[e.cid]=r.__getTrackedModelFields(e)}),r.push(),e.each(u,function(e){e.save().fail(function(){a++,n(arguments,e,!1)}).done(function(){o++,n(arguments,e,!0)})})},__pull:function(t){var i=this.getMapping(t);if(i.computed&&i.mapping.pull)this.__invokeComputedPull.call({formModel:this,alias:t});else if(i.computed){var n=this.__getModelAliases(t);e.each(n,function(e){var t=this.getTrackedModel(e);t&&this.__copyFields(i.mapping[e],this,t)},this)}else{var s=this.getTrackedModel(t);s&&this.__copyFields(i.mapping,this,s)}},__push:function(t){var i=this.getMapping(t);if(i.computed&&i.mapping.push){var n=this.__getComputedModels(t);n&&i.mapping.push.call(this,n)}else if(i.computed){var s=this.__getModelAliases(t);e.each(s,function(e){var t=this.getTrackedModel(e);t&&this.__copyFields(i.mapping[e],t,this)},this)}else{var r=this.getTrackedModel(t);r&&this.__copyFields(i.mapping,r,this)}},__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(t){t?this.__cache[t.cid]=this.__generateHashValue(t):(this.__cache={},e.each(this.getTrackedModels(),function(e){e&&this.__updateCache(e)},this))},__hashValue:function(e){return JSON.stringify(e)},__findAlias:function(t){var i,n;return e.isString(t)?i=t:(n=t,i=e.find(this.__currentObjectModels,function(e){return e==n})),i},__generateHashValue:function(e){var t=this.__getTrackedModelFields(e);return this.__hashValue(t)},__generateAllHashValues:function(){var t={};return e.each(this.getTrackedModels(),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(){var t,i,n=this;e.each(n.getMappings(),function(s,r){s.computed?(i=n.__getComputedModelConfigs(r),e.each(i,function(t){var i=t.model;t.fields?e.each(t.fields,function(e){n.__listenToComputedValuesDependency(i,e,r)}):n.__listenToComputedValuesDependency(i,"",r)})):(t=n.getTrackedModel(r),t&&(s.mapping?e.each(s.mapping,function(e){n.__listenToModelField(t,e)}):n.__listenToModelField(t)))})},__copyFields:function(t,i,n){(!t||t===!0)&&this===n&&e.size(this.getTrackedModels())>1&&(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,n=e.result(this,"mapping");t.mapping;i=t.mapping||n,i&&this.setMappings(i,t.models)},__getTrackedModelFields:function(t){var i,n={},s={},r=[];return e.each(this.__getAllModelConfigs(),function(e){e.model&&e.model.cid===t.cid&&r.push(e)}),i=e.reduce(r,function(e,t){return e||!t.fields},!1),i?s=this.__cloneVal(t.attributes):e.each(r,function(i){e.each(i.fields,function(e){n[e]||(n[e]=!0,s[e]=this.__cloneVal(t.get(e)))},this)},this),s},__createModelConfig:function(e,t){var i=this.getTrackedModel(e);return i?{fields:t,model:i}:void 0},__getAllModelConfigs:function(){var t=[];return e.each(this.getMappings(),function(e,i){if(e.computed){var n=this.__getComputedModelConfigs(i);n&&(t=t.concat(n))}else{var s=this.__createModelConfig(i,e.mapping);s&&t.push(s)}},this),t},__invokeComputedPull:function(t){t&&this.formModel.__updateCache(t),function(t,i){var n=!0,s=t.getMapping(i),r=t.__getModelAliases(i),o={};return s.mapping.pull?(e.each(r,function(i){var r=s.mapping[i],a=t.getTrackedModel(i),c={};a?(r?e.each(r,function(e){c[e]=t.__cloneVal(a.get(e))}):c=t.__cloneVal(modelConfig.model.attributes),o[i]=c):n=!1}),void(n&&s.mapping.pull.call(t,o))):void(console&&e.isFunction(console.log)&&console.log("Not pulling the computed: "+i+", because no pull method was defined for this computed."))}(this.formModel,this.alias)}});return e.extend(s.prototype,n.mixin),s}),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 s,r,o,a,c,d;d=function(e){e.__delayedRenderTimeout&&(clearTimeout(e.__delayedRenderTimeout),e.__delayedRenderTimeout=null,e.render())},c=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()}},s=function(e){var t=this.getItemViewFromModel(e);t&&(r.call(this,t,e[this.__modelId],e),this.hasItemViews()||this.__delayedRender())},r=function(e,t,i){e.dispose(),this.unregisterTrackedView(e,{shared:!1}),delete this.__modelToViewMap[t],this.__updateOrderedModelIdList(),this.trigger("item-view-removed",{model:i||e.model,view:e}),this.trigger("child-view-removed",{model:i||e.model,view:e})},o=function(e){var t,i=this.modelsToRender(),n=i.indexOf(e);n>-1&&(t=this.__createItemView(e),a.call(this,t,n))},a=function(t,i){var n,s,r,o=this.modelsToRender();this.hasItemViews()?(d(this),n=this.getItemViewFromModel(o[i+1]),s=this.getItemViewFromModel(o[i-1]),n?r=e.bind(n.$el.before,n.$el):s?r=e.bind(s.$el.after,s.$el):this.__delayedRender(),r&&this.attachView(null,t,{replaceMethod:r,discardInjectionSite:!0})):this.__delayedRender()};var u=i.extend({collection:null,itemView:null,template:null,emptyTemplate:null,itemContainer:null,__modelName:"",__modelId:"",__modelToViewMap:null,__itemContext:null,__renderWait:0,__delayedRender:null,__delayedRenderTimeout:null,constructor:function(e){i.apply(this,arguments),e=e||{};var t=e.collection||this.collection;if(this.template=e.template||this.template,this.emptyTemplate=e.emptyTemplate||this.emptyTemplate,this.itemView=e.itemView||this.itemView||e.childView||this.childView,this.itemContainer=e.itemContainer||this.itemContainer||e.childrenContainer||this.childrenContainer,this.template&&!this.itemContainer)throw"Item container is required when using a template";this.modelsToRender=e.modelsToRender||this.modelsToRender,this.__itemContext=e.itemContext||this.__itemContext||e.childContext||this.__childContext,this.__modelToViewMap={},this.__renderWait=e.renderWait||this.__renderWait,this.__modelId=e.modelId||"cid",this.__modelName=e.modelName||e.childModel||"model",this.__orderedModelIdList=[],this.__createItemViews(),this.__delayedRender=c(this.__renderWait,this),t&&this.setCollection(t),this.on("render:after-dom-update",this.__cleanupItemViewsAfterAttachedToParent)},setCollection:function(e){this.stopListening(this.collection,"remove",s),this.stopListening(this.collection,"add",o),this.stopListening(this.collection,"sort",this.reorder),this.stopListening(this.collection,"reset",this.update),this.collection=e,this.listenTo(this.collection,"remove",s),this.listenTo(this.collection,"add",o),this.listenTo(this.collection,"sort",this.reorder),this.listenTo(this.collection,"reset",this.update)},updateDOM:function(){var e,i=t(n.copyTopElement(this.el));this.template?(i.html(this.template(this.prepare())),e=i.find("[inject="+this.itemContainer+"]")):(e=t(""),i.append(e)),this.hasItemViews()?e.replaceWith(this.__emptyAndRebuildItemViewsFragment()):this.emptyTemplate&&e.replaceWith(this.emptyTemplate(this.prepareEmpty())),this.$el.html(i.contents())},__cleanupItemViewsAfterAttachedToParent:function(){e.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&(t.delegateEvents(),!t.__attachedCallbackInvoked&&t.isAttached()&&t.__invokeAttached(),t.activate())},this)},renderChildViews:function(){e.each(this.getTrackedViews({child:!0}),function(e){e.render()})},reorder:function(){var i,n,s=[],r=this.modelsToRender(),o=e.pluck(r,this.__modelId),a=e.size(o),c=e.size(this.__orderedModelIdList),d=a===c;if(!d)throw"Reorder should not be invoked if the number of models have changed";if(n=e.reduce(this.__orderedModelIdList,function(e,t,i){return e&&o[i]==t},!0),a&&!n){if(e.each(r,function(e,t){var n=this.getItemViewFromModel(e);n&&s.push(n.$el),0===t&&(i=n)},this),this.itemContainer){if(i){var u=t("");i.$el.before(u),u.after(s),u.remove()}}else this.$el.append(s);this.__updateOrderedModelIdList(o),this.trigger("reorder-complete")}},prepareEmpty:function(){return this.prepare()},modelsToRender:function(){return this.collection?this.collection.models:[]},update:function(){var t=!1,i=this.getItemViews(),n=this.__createItemViews(),s=this.__getStaleItemViews(),r=e.size(i),o=e.size(n),a=e.size(s),c=r-a+o,d=o+a,u=d/Math.max(c,1),l=!r&&o,h=r&&r===a&&!o,f=this.updateThreshold||.5,p=u>=f;return 0>=d?this.reorder():(t=l||h||p,void(t?(this.__removeStaleItemViews(s),this.__delayedRender()):this.__updateByAddingRemoving(i,n,s)))},getItemViewFromModel:function(e){return e?this.getTrackedView(this.__modelToViewMap[e[this.__modelId]]):void 0},getChildViewFromModel:function(){return this.getItemViewFromModel.apply(this,arguments)},hasItemViews:function(){return!e.isEmpty(this.getItemViews())},getItemViews:function(){var t=e.map(this.__orderedModelIdList,this.__getViewIdFromModelId,this);return e.map(t,this.getTrackedView,this)},__createItemViews:function(){var t=[];return e.each(this.modelsToRender(),function(e,i){var n=this.getItemViewFromModel(e);n||t.push({view:this.__createItemView(e,!0),indexOfModel:i})},this),this.__updateOrderedModelIdList(),t},__createItemView:function(t,i){var n,s=this.itemView;return e.isFunction(this.itemView.extend)||(s=this.itemView(t)),n=new s(this.__generateItemViewArgs(t)),this.registerTrackedView(n,{shared:!1}),this.__modelToViewMap[t[this.__modelId]]=n.cid,i||this.__updateOrderedModelIdList(),this.trigger("child-view-added",{model:t,view:n}),this.trigger("item-view-added",{model:t,view:n}),n},__getStaleItemViews:function(){var t=[],i=e.clone(this.__modelToViewMap);return e.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&delete i[e[this.__modelId]]},this),e.each(i,function(e,i){var n=this.getTrackedView(e);n&&t.push({view:n,modelId:i})},this),t},__removeStaleItemViews:function(t){var i=this;t=t||this.__getStaleItemViews(),e.each(t,function(e){r.call(i,e.view,e.modelId)})},__emptyAndRebuildItemViewsFragment:function(){var i=document.createDocumentFragment();return this.$el.empty(),e.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&(t.detach(),this.registerTrackedView(t),t.attachTo(null,{replaceMethod:function(e){i.appendChild(e[0])},discardInjectionSite:!0}))},this),this.__updateOrderedModelIdList(),t(i)},__updateByAddingRemoving:function(i,n,s){var r,o,c=this,d=e.size(i),u=(e.size(n),e.size(s));c.itemContainer&&d&&d==u&&(o=t(""),e.first(i).$el.before(o)),c.__removeStaleItemViews(s),e.each(n,function(t,i){if(0===t.indexOfModel){var n;if(c.itemContainer)if(o)n=e.bind(o.replaceWith,o);else{var d=e.indexBy(s,"modelId"),u=e.find(c.__orderedModelIdList,function(e){return!d[e]});r=c.getTrackedView(c.__modelToViewMap[u]),n=e.bind(r.$el.prepend,r.$el)}else n=e.bind(c.$el.prepend,c.$el);c.attachView(null,t.view,{replaceMethod:n,discardInjectionSite:!0})}else a.call(c,t.view,t.indexOfModel)}),this.reorder()},__updateOrderedModelIdList:function(t){this.__orderedModelIdList=t||e.pluck(this.modelsToRender(),this.__modelId)},__generateItemViewArgs:function(t){var i={context:e.extend({},e.result(this,"__itemContext")),listView:this};return i[this.__modelName]=t,i},__generateChildArgs:function(){return this.__generateItemViewArgs.apply(this,arguments)},__getViewIdFromModelId:function(e){return this.__modelToViewMap[e]}});return u}),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,s){"use strict";var r=i.extend({constructor:function(t){t=t||{},this.model=t.model||this.model||new n,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||{}),i.apply(this,arguments),this.resetModelListeners(this.model)},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)},resetModelListeners:function(e,t){this.model&&t&&this.stopListening(this.model),this.model=e,this.listenTo(this.model,"validated:valid",this.valid),this.listenTo(this.model,"validated:invalid",this.invalid)},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==!!n?{addClass:t}:{removeClass:t}},_thenSetTextIfInvalid:function(e,t,i){var n=this.model.isValid(e);return!!i==!!n?{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"),s=i.__getFieldOptions(n),r=i.__generateModelFieldBinding(n,s);i.bindings['[data-model="'+n+'"]']=r})},__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 s=[t];return s.push(n),s=e.flatten(s),i.modelFormat?i.modelFormat.apply(this,s):t},onGet:function(t){var s=[t];return s.push(n),s=e.flatten(s),i.viewFormat?i.viewFormat.apply(this,s):t}}}});return r}); \ No newline at end of file +!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(["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?module.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,s){return e.helpers.formAttr(n,i+", "+t+", name, id",s)}),e.registerHelper("feedback",function(i,n){return e.helpers.formAttr(i,t,n)}),e.registerHelper("formAttr",function(n,s,r){var o,a,c=r.hash?r.hash.value:void 0,d=e.helpers.injectFieldIndices(n,r.hash),u="";for(s=s.split(","),o=0;o'),s.addBefore?i.$el.before(r):i.$el.after(r),i.injectionSite=void 0,i.transitionOut(a.resolve,s),o=this.__transitionInView(r,n,s),t.when(a.promise(),o)},__transitionInView:function(i,n,s){var r=t.Deferred(),o=this;return s=e.extend({},s),e.defaults(s,{parentView:this,newView:n}),n.transitionIn(function(){o.attachView(i,n,s)},r.resolve,s),r.promise()},__getTrackedViewsHash:function(t){var i={};return t=t||{},t.shared&&(i=e.extend(i,this.__sharedViews)),t.child&&(i=e.extend(i,this.__childViews)),t.child||t.shared||(i=e.extend(i,this.__sharedViews,this.__childViews)),i},__updateInjectionSiteMap:function(){var t=this;this.__injectionSiteMap={},e.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.injectionSite&&(t.__injectionSiteMap[e.injectionSite.attr("inject")]=e)})},__getLastTrackedViewAtInjectionSite:function(t){var i=this.__injectionSiteMap[t];if(i)i=e.contains(this.getTrackedViews(),i)?i:void 0;else{var n=this.getTrackedViews().filter(function(e){return e.injectionSite&&e.injectionSite.attr("inject")==t});i=e.first(n)}return i},__replaceInjectionSite:function(e,t){t=t||{},this.injectionSite=t.replaceMethod?t.replaceMethod(this.$el):e.replaceWith(this.$el),t.discardInjectionSite&&(this.injectionSite=void 0)},__invokeAttached:function(){this.__attachedCallbackInvoked||(this.trigger("before-attached-callback"),this._attached(),this.__attachedCallbackInvoked=!0,e.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.__invokeAttached()}))},__invokeDetached:function(){this.__attachedCallbackInvoked&&(this.trigger("before-detached-callback"),this._detached(),this.__attachedCallbackInvoked=!1),e.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.__invokeDetached()})},__generateFeedbackCellCallbacks:function(){var i=this;i.feedbackCell.off(),e.each(this.$("[data-feedback]"),function(n){var s=t(n).data("feedback");i.feedbackCell.on("change:"+s,function(t){return function(){var n,s=i.feedbackCell.get(t);s&&(n=i.$el.find('[data-feedback="'+t+'"]'),e.each(s,function(t,s){var r;r="_"===e.first(s)?i[s.slice(1)]:n[s],e.isArray(t)?r.apply(n,t):void 0!==t&&r.call(n,t)}))}}(s))}),e.each(i.feedbackCell.attributes,function(e,t){i.feedbackCell.trigger("change:"+t)})},__processFeedbackThenResult:function(e,i){var n=t.extend({},e);this.feedbackCell.set(i,n,{silent:!0}),this.feedbackCell.trigger("change:"+i)},__generateFeedbackBindings:function(){var i,n=this;for(i=0;i0&&(s=e.substring(0,r)),this.$('[data-feedback^="'+s+'"]').filter(function(){return i.__stripAllAttribute(t(this).data("feedback"))===n})},__generateWhenEvents:function(t,i){var n=this,s=[];return e.each(t,function(t,r){var o,a=[r],c="@"===r.charAt(0);"on"===r&&"listenTo"===r||(c&&(r=r.substring(1),o=n.__substituteIndicesUsingMap(r,i),a=e.flatten(n.__generateSubAttributes(o,n.model))),e.each(a,function(i){e.each(t,function(e){var t=e+" "+i;c&&(t=e+' [data-model="'+i+'"]'),s.push(t)})}))}),s},__getAllIndexTokens:function(t){return e.reduce(t.match(/\[.+?\]/g),function(e,t){var i=t.substring(1,t.length-1);return isNaN(i)?e.push(i):e.push(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,s,r,o,a=e.indexOf("[]");if(a===-1)return[e];if(n=e.substring(0,a),s=e.substring(a+2),r=[],o=t.get(n),!o)return[e];for(i=0;i0&&s;)i=e.indexOf("]",n),r.push(parseInt(e.substring(t+1,i),10)),n=i+1,s=n>0,t=e.indexOf("[",n);return r},d=function(t,i,n){var s,r,o,a,c=t.indexOf("[]");if(e.isEmpty(n)&&(n=[]),c===-1)return{attr:t,index:n};s=t.substring(0,c),r=t.substring(c+2),o=[];var u=i.get(s);return e.each(u,function(e,t){a=n.slice(),a.push(t),o.push(d(s+"["+t+"]"+r,i,a))}),o},l=function(e){return t&&e instanceof t},h=function(e){return e.indexOf(".")>0||e.indexOf("]")>0},f=function(e){var t,i,n=0,s=!0;if(t=e.indexOf("[",n),t<0)return e;for(i=e.substring(0,t+1);t>0&&s;)n=e.indexOf("]",n)+1,s=n>0,t=e.indexOf("[",n),t>0&&(i+=e.substring(n-1,t+1));return i+=e.substring(n-1)},p=function(t,i,n,s,r,o){var a,c;return e.isArray(i)?e.reduce(i,function(e,i){return e.push(p(t,i,n,s,r,o+1)),e},[]):(c=i.index,a=i.attr,e.isUndefined(n)&&h(a)&&(n=t.get(a)),_(r,t,n,a,s,c))},_=function(t,i,s,r,o,a){return e.reduce(t,function(t,c){var d=e.extend({msgKey:c.msgKey},n,u),l=c.fn.call(d,s,r,c.val,i,o,a);return l!==!1&&t!==!1&&(l&&!t?e.result(e.extend({},c,n,u),"msg")||l:t)},"")},m=function(t,i,n,s){var r,o,c,u=a(t,i);return o=d(i,t),c=p(t,o,n,s,u,0),e.isArray(c)&&(r=e.reduce(e.flatten(c),function(e,t){return e||t},!1),!r)?"":c},g=function(t,i,n){var s,r={},o=!0,a=e.clone(i); +return e.each(n,function(e,i){s=m(t,i,e,a),s&&(r[i]=s,o=!1)}),{invalidAttrs:r,isValid:o}},v=function(t,i,n){var s,r,o=t.validation?e.result(t,"validation")||{}:{};return e.contains(e.keys(o),n)?m(t,n,i,e.extend({},t.attributes)):(s=c(n),n=f(n),r=a(t,n),_(r,t,i,n,e.extend({},t.attributes),s))},b=function(t){return{preValidate:function(t,i){var n,s=this,r={};return e.isArray(t)?(e.each(t,function(e){n=s.preValidate(e),n&&(r[e]=n)}),e.isEmpty(r)?void 0:r):e.isObject(t)?(e.each(t,function(e,t){n=s.preValidate(t,e),n&&(r[t]=n)}),e.isEmpty(r)?void 0:r):(e.isUndefined(i)&&l(this)&&(i=this.get(t)),v(this,i,t))},isValid:function(i){var n,r,a;return i=i||o(t),e.isString(i)?n=[i]:e.isArray(i)&&(n=i),n&&e.each(n,function(e){var t;t=l(this)?this.get(e):s(this.attributes)[e],r=v(this,t,e),r&&(a=a||{},a[e]=r)},this),i===!0&&(a=this.validate()),a&&this.trigger("invalid",this,a,{validationError:a}),n?!a:!this.validation||this._isValid},validate:function(i,n){var a=this,c=e.extend({},t,n),d=r(a,o(t)),u=e.extend({},d,a.attributes,i),l=e.extend(s(u),i),h=i?s(i):l,f=g(a,u,e.pick(l,e.keys(d)));if(a._isValid=f.isValid,e.defer(function(){a.trigger("validated",a._isValid,a,f.invalidAttrs),a.trigger("validated:"+(a._isValid?"valid":"invalid"),a,f.invalidAttrs)}),!c.forceUpdate&&e.intersection(e.keys(f.invalidAttrs),e.keys(h)).length>0)return f.invalidAttrs}}};return{version:"0.11.3",configure:function(t){e.extend(i,t)},mixin:b(i)}}(),o=r.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},a=r.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"},c=r.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]||c.sentenceCase(e,t)}},d=r.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})}},u=r.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(o.number)},s=function(i){return!(e.isNull(i)||e.isUndefined(i)||e.isString(i)&&""===t(i)||e.isArray(i)&&e.isEmpty(i))},r=function(e,t){return e?e:t};return{format:n.format,formatLabel:n.formatLabel,fn:function(t,i,n,s,r){return e.isString(n)&&(n=s[n]),n.call(s,t,i,r)},inlineFn:function(e,t,i,n,s,r){return i.call(this,e,t,n,s,r)},required:function(t,i,n,o,c){var d=e.isFunction(n)?n.call(o,t,i,c):n;return!(!d&&!s(t))&&(d&&!s(t)?this.format(r(this.msgKey,a.required),this.formatLabel(i,o)):void 0)},acceptance:function(t,i,n,s){if("true"!==t&&(!e.isBoolean(t)||t===!1))return this.format(r(this.msgKey,a.acceptance),this.formatLabel(i,s))},min:function(e,t,n,s){if(!i(e)||en)return this.format(r(this.msgKey,a.max),this.formatLabel(t,s),n)},range:function(e,t,n,s){if(!i(e)||en[1])return this.format(r(this.msgKey,a.range),this.formatLabel(t,s),n[0],n[1])},length:function(t,i,n,s){if(!e.isString(t)||t.length!==n)return this.format(r(this.msgKey,a.length),this.formatLabel(i,s),n)},minLength:function(t,i,n,s){if(!e.isString(t)||t.lengthn)return this.format(r(this.msgKey,a.maxLength),this.formatLabel(i,s),n)},rangeLength:function(t,i,n,s){if(!e.isString(t)||t.lengthn[1])return this.format(r(this.msgKey,a.rangeLength),this.formatLabel(i,s),n[0],n[1])},oneOf:function(t,i,n,s){if(!e.include(n,t))return this.format(r(this.msgKey,a.oneOf),this.formatLabel(i,s),n.join(", "))},equalTo:function(e,t,i,n,s){if(e!==s[i])return this.format(r(this.msgKey,a.equalTo),this.formatLabel(t,n),this.formatLabel(i,n))},pattern:function(e,t,i,n){if(!s(e)||!e.toString().match(o[i]||i))return this.format(r(this.msgKey,a[i])||a.inlinePattern,this.formatLabel(t,n),i)}}}();return r}),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 s=i.extend({mapping:void 0,constructor:function(t,n){n=n||{},this.__cache={},this.__currentUpdateEvents=[],this.__currentMappings={},this.__currentObjectModels={},this.validation=e.extend({},this.validation,n.validation),this.labels=e.extend({},this.labels,n.labels),i.apply(this,arguments),this.__initMappings(n),this.pull(),t&&this.set(t),n.startUpdating&&this.startUpdating(),this.trigger("initialization-complete")},getMapping:function(e){return this.__currentMappings[e]},getMappings:function(){return this.__currentMappings},setMapping:function(t,i,n,s){var r,o,a={};e.isString(i)?o=i.split(" "):i===!0?o=void 0:e.isObject(i)&&(i=e.clone(i),r=!0),a.computed=r,r?(a.mapping=i,e.each(this.__getModelAliases(a),function(t){var i=a.mapping[t];e.isString(i)?i=i.split(" "):i===!0&&(i=void 0),a.mapping[t]=i})):a.mapping=o,this.__currentMappings[t]=a,n&&(r?this.setTrackedModels(n,s):this.setTrackedModel(t,n,s))},setMappings:function(t,i,n){e.each(t,function(e,t){this.setMapping(t,e)},this),i&&this.setTrackedModels(i,n)},unsetMapping:function(t,i){var n=this.__findAlias(t);n&&delete this.__currentMappings[n];var s=this.getTrackedModel(n);i&&s&&e.isEmpty(this.__getTrackedModelFields(s))&&this.unsetTrackedModel(s)},unsetMappings:function(){this.__currentMappings={},this.resetUpdating()},getTrackedModel:function(e){return this.__currentObjectModels[e]},getTrackedModels:function(){return e.values(this.__currentObjectModels)},setTrackedModel:function(t,i,n){this.__currentObjectModels[t]=i,this.__updateCache(i),this.resetUpdating(),n&&e.each(this.getMappings(),function(i,n){var s;t===n&&this.__pull(n),i.computed&&(s=this.__getModelAliases(n),e.contains(s,t)&&this.__pull(n))},this)},setTrackedModels:function(t,i){e.each(t,function(e,t){this.setTrackedModel(t,e,i)},this)},unsetTrackedModel:function(e){var t,i=this.__findAlias(e);i&&(t=this.__currentObjectModels[i],delete this.__currentObjectModels[i],this.__updateCache(t)),this.resetUpdating()},unsetTrackedModels:function(){this.__currentObjectModels=[],this.__updateCache(),this.resetUpdating()},push:function(){e.each(this.getMappings(),function(e,t){this.__push(t)},this)},pull:function(){e.each(this.getMappings(),function(e,t){this.__pull(t)},this),this.__updateCache()},save:function(n){var s,r,o=new t.Deferred,a=this;n=n||{},e.defaults(n,{rollback:!0,force:!0});try{r=e.result(a,"url")}catch(c){}return r?i.prototype.save.apply(a,arguments).done(function(){a.push()}):this.isTrackingAnyObjectModel()?(this.__saveToModels(o,n),o.promise()):(s={none:{success:!1,response:[{responseJSON:{generalReasons:[{messageKey:"no.models.were.bound.to.form"}]}}]}},this.trigger("save-fail",s),(new t.Deferred).reject(s).promise())},isTrackingAnyObjectModel:function(){return e.size(this.__currentObjectModels)>0},isUpdating:function(){return this.__currentUpdateEvents.length>0},startUpdating:function(e){this.isTrackingAnyObjectModel()&&!this.isUpdating()&&(e&&this.pull(),this.__setupListeners())},stopUpdating:function(){e.each(this.__currentUpdateEvents,function(e){this.stopListening(e.model,e.eventName)},this),this.__currentUpdateEvents=[]},resetUpdating:function(){this.isUpdating()&&(this.stopUpdating(),this.startUpdating())},isModelStale:function(e,t,i){var n;i=i||{},i[e.cid]||(i[e.cid]=this.__generateHashValue(e)),n=i[e.cid];var s=this.__cache[e.cid]!==n;return t&&(s?t[e.cid]=e:t[e.cid]&&delete t[e.cid]),s},checkIfModelsAreStale:function(){var t={},i=this.__generateAllHashValues();return e.each(this.getTrackedModels(),function(e){this.isModelStale(e,t,i)},this),e.values(t)},__listenToModelField:function(t,i){var n,s;i?(s="change:"+i,n=e.bind(this.__updateFormField,{formModel:this,field:i})):(s="change",n=this.__updateFormModel),this.listenTo(t,s,n),this.__currentUpdateEvents.push({model:t,eventName:s})},__listenToComputedValuesDependency:function(t,i,n){var s,r;r=i?"change:"+i:"change",s=e.bind(this.__invokeComputedPull,{formModel:this,alias:n}),this.listenTo(t,r,s),this.__currentUpdateEvents.push({model:t,eventName:r})},__getComputedModels:function(t){var i=!e.isUndefined(this.getMapping(t)),n={};return e.each(this.__getModelAliases(t),function(e){var t=this.getTrackedModel(e);t?n[e]=t:i=!1},this),i?n:void 0},__getModelAliases:function(t){var i;return i=e.isString(t)?this.getMapping(t):t,e.filter(e.keys(i.mapping),function(e){return"pull"!=e&&"push"!=e})},__getComputedModelConfigs:function(t){var i=!0,n=this.getMapping(t),s=[];return e.each(this.__getModelAliases(t),function(e){var t=this.__createModelConfig(e,n.mapping[e]);t?s.push(t):i=!1},this),i?s:void 0},__saveToModels:function(t,i){function n(n,s,u){c[s.cid]={success:u,response:n},a+o===l&&(a>0?(i.rollback&&e.each(r.getTrackedModels(),function(e){e.set(d[e.cid]),c[e.cid].success&&e.save()}),r.trigger("save-fail",c),t.reject(c)):(r.trigger("save-success",c),t.resolve(c)))}var s,r=this,o=0,a=0,c={},d={},u=r.getTrackedModels(),l=u.length;if(!i.force&&(s=r.checkIfModelsAreStale(),s.length>0))throw{name:"Stale data",staleModels:s};e.each(u,function(e){d[e.cid]=r.__getTrackedModelFields(e)}),r.push(),e.each(u,function(e){e.save().fail(function(){a++,n(arguments,e,!1)}).done(function(){o++,n(arguments,e,!0)})})},__pull:function(t){var i=this.getMapping(t);if(i.computed&&i.mapping.pull)this.__invokeComputedPull.call({formModel:this,alias:t});else if(i.computed){var n=this.__getModelAliases(t);e.each(n,function(e){var t=this.getTrackedModel(e);t&&this.__copyFields(i.mapping[e],this,t)},this)}else{var s=this.getTrackedModel(t);s&&this.__copyFields(i.mapping,this,s)}},__push:function(t){var i=this.getMapping(t);if(i.computed&&i.mapping.push){var n=this.__getComputedModels(t);n&&i.mapping.push.call(this,n)}else if(i.computed){var s=this.__getModelAliases(t);e.each(s,function(e){var t=this.getTrackedModel(e);t&&this.__copyFields(i.mapping[e],t,this)},this)}else{var r=this.getTrackedModel(t);r&&this.__copyFields(i.mapping,r,this)}},__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(t){t?this.__cache[t.cid]=this.__generateHashValue(t):(this.__cache={},e.each(this.getTrackedModels(),function(e){e&&this.__updateCache(e)},this))},__hashValue:function(e){return JSON.stringify(e)},__findAlias:function(t){var i,n;return e.isString(t)?i=t:(n=t,i=e.find(this.__currentObjectModels,function(e){return e==n})),i},__generateHashValue:function(e){var t=this.__getTrackedModelFields(e);return this.__hashValue(t)},__generateAllHashValues:function(){var t={};return e.each(this.getTrackedModels(),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(){var t,i,n=this;e.each(n.getMappings(),function(s,r){s.computed?(i=n.__getComputedModelConfigs(r),e.each(i,function(t){var i=t.model;t.fields?e.each(t.fields,function(e){n.__listenToComputedValuesDependency(i,e,r)}):n.__listenToComputedValuesDependency(i,"",r)})):(t=n.getTrackedModel(r),t&&(s.mapping?e.each(s.mapping,function(e){n.__listenToModelField(t,e)}):n.__listenToModelField(t)))})},__copyFields:function(t,i,n){(!t||t===!0)&&this===n&&e.size(this.getTrackedModels())>1&&(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,n=e.result(this,"mapping");t.mapping;i=t.mapping||n,i&&this.setMappings(i,t.models)},__getTrackedModelFields:function(t){var i,n={},s={},r=[];return e.each(this.__getAllModelConfigs(),function(e){e.model&&e.model.cid===t.cid&&r.push(e)}),i=e.reduce(r,function(e,t){return e||!t.fields},!1),i?s=this.__cloneVal(t.attributes):e.each(r,function(i){e.each(i.fields,function(e){n[e]||(n[e]=!0,s[e]=this.__cloneVal(t.get(e)))},this)},this),s},__createModelConfig:function(e,t){var i=this.getTrackedModel(e);if(i)return{fields:t,model:i}},__getAllModelConfigs:function(){var t=[];return e.each(this.getMappings(),function(e,i){if(e.computed){var n=this.__getComputedModelConfigs(i);n&&(t=t.concat(n))}else{var s=this.__createModelConfig(i,e.mapping);s&&t.push(s)}},this),t},__invokeComputedPull:function(t){t&&this.formModel.__updateCache(t),function(t,i){var n=!0,s=t.getMapping(i),r=t.__getModelAliases(i),o={};return s.mapping.pull?(e.each(r,function(i){var r=s.mapping[i],a=t.getTrackedModel(i),c={};a?(r?e.each(r,function(e){c[e]=t.__cloneVal(a.get(e))}):c=t.__cloneVal(modelConfig.model.attributes),o[i]=c):n=!1}),void(n&&s.mapping.pull.call(t,o))):void(console&&e.isFunction(console.log)&&console.log("Not pulling the computed: "+i+", because no pull method was defined for this computed."))}(this.formModel,this.alias)}});return e.extend(s.prototype,n.mixin),s}),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 s,r,o,a,c,d;d=function(e){e.__delayedRenderTimeout&&(clearTimeout(e.__delayedRenderTimeout),e.__delayedRenderTimeout=null,e.render())},c=function(e,t){var i=function(){t.__delayedRenderTimeout=null,t.render()};return function(){!t.__delayedRenderTimeout&&e>0?t.__delayedRenderTimeout=setTimeout(i,e):e<=0&&t.render()}},s=function(e){var t=this.getItemViewFromModel(e);t&&(r.call(this,t,e[this.__modelId],e),this.hasItemViews()||this.__delayedRender())},r=function(e,t,i){e.dispose(),this.unregisterTrackedView(e,{shared:!1}),delete this.__modelToViewMap[t],this.__updateOrderedModelIdList(),this.trigger("item-view-removed",{model:i||e.model,view:e}),this.trigger("child-view-removed",{model:i||e.model,view:e})},o=function(e){var t,i=this.modelsToRender(),n=i.indexOf(e);n>-1&&(t=this.__createItemView(e),a.call(this,t,n))},a=function(t,i){var n,s,r,o=this.modelsToRender();this.hasItemViews()?(d(this),n=this.getItemViewFromModel(o[i+1]),s=this.getItemViewFromModel(o[i-1]),n?r=e.bind(n.$el.before,n.$el):s?r=e.bind(s.$el.after,s.$el):this.__delayedRender(),r&&this.attachView(null,t,{replaceMethod:r,discardInjectionSite:!0})):this.__delayedRender()};var u=i.extend({collection:null,itemView:null,template:null,emptyTemplate:null,itemContainer:null,__modelName:"",__modelId:"",__modelToViewMap:null,__itemContext:null,__renderWait:0,__delayedRender:null,__delayedRenderTimeout:null,constructor:function(e){i.apply(this,arguments),e=e||{};var t=e.collection||this.collection;if(this.template=e.template||this.template,this.emptyTemplate=e.emptyTemplate||this.emptyTemplate,this.itemView=e.itemView||this.itemView||e.childView||this.childView,this.itemContainer=e.itemContainer||this.itemContainer||e.childrenContainer||this.childrenContainer,this.template&&!this.itemContainer)throw"Item container is required when using a template";this.modelsToRender=e.modelsToRender||this.modelsToRender,this.__itemContext=e.itemContext||this.__itemContext||e.childContext||this.__childContext,this.__modelToViewMap={},this.__renderWait=e.renderWait||this.__renderWait,this.__modelId=e.modelId||"cid",this.__modelName=e.modelName||e.childModel||"model",this.__orderedModelIdList=[],this.__createItemViews(),this.__delayedRender=c(this.__renderWait,this),t&&this.setCollection(t),this.on("render:after-dom-update",this.__cleanupItemViewsAfterAttachedToParent)},setCollection:function(e){this.stopListening(this.collection,"remove",s),this.stopListening(this.collection,"add",o),this.stopListening(this.collection,"sort",this.reorder),this.stopListening(this.collection,"reset",this.update),this.collection=e,this.listenTo(this.collection,"remove",s),this.listenTo(this.collection,"add",o),this.listenTo(this.collection,"sort",this.reorder),this.listenTo(this.collection,"reset",this.update)},updateDOM:function(){var e,i=t(n.copyTopElement(this.el));this.template?(i.html(this.template(this.prepare())),e=i.find("[inject="+this.itemContainer+"]")):(e=t(""),i.append(e)),this.hasItemViews()?e.replaceWith(this.__emptyAndRebuildItemViewsFragment()):this.emptyTemplate&&e.replaceWith(this.emptyTemplate(this.prepareEmpty())),this.$el.html(i.contents())},__cleanupItemViewsAfterAttachedToParent:function(){e.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&(t.delegateEvents(),!t.__attachedCallbackInvoked&&t.isAttached()&&t.__invokeAttached(),t.activate())},this)},renderChildViews:function(){e.each(this.getTrackedViews({child:!0}),function(e){e.render()})},reorder:function(){var i,n,s=[],r=this.modelsToRender(),o=e.pluck(r,this.__modelId),a=e.size(o),c=e.size(this.__orderedModelIdList),d=a===c;if(!d)throw"Reorder should not be invoked if the number of models have changed";if(n=e.reduce(this.__orderedModelIdList,function(e,t,i){return e&&o[i]==t},!0),a&&!n){if(e.each(r,function(e,t){var n=this.getItemViewFromModel(e);n&&s.push(n.$el),0===t&&(i=n)},this),this.itemContainer){if(i){var u=t("");i.$el.before(u),u.after(s),u.remove()}}else this.$el.append(s);this.__updateOrderedModelIdList(o),this.trigger("reorder-complete")}},prepareEmpty:function(){return this.prepare()},modelsToRender:function(){return this.collection?this.collection.models:[]},update:function(){var t=!1,i=this.getItemViews(),n=this.__createItemViews(),s=this.__getStaleItemViews(),r=e.size(i),o=e.size(n),a=e.size(s),c=r-a+o,d=o+a,u=d/Math.max(c,1),l=!r&&o,h=r&&r===a&&!o,f=this.updateThreshold||.5,p=u>=f;return d<=0?this.reorder():(t=l||h||p,void(t?(this.__removeStaleItemViews(s),this.__delayedRender()):this.__updateByAddingRemoving(i,n,s)))},getItemViewFromModel:function(e){return e?this.getTrackedView(this.__modelToViewMap[e[this.__modelId]]):void 0},getChildViewFromModel:function(){return this.getItemViewFromModel.apply(this,arguments)},hasItemViews:function(){return!e.isEmpty(this.getItemViews())},getItemViews:function(){var t=e.map(this.__orderedModelIdList,this.__getViewIdFromModelId,this);return e.map(t,this.getTrackedView,this)},__createItemViews:function(){var t=[];return e.each(this.modelsToRender(),function(e,i){var n=this.getItemViewFromModel(e);n||t.push({view:this.__createItemView(e,!0),indexOfModel:i})},this),this.__updateOrderedModelIdList(),t},__createItemView:function(t,i){var n,s=this.itemView;return e.isFunction(this.itemView.extend)||(s=this.itemView(t)),n=new s(this.__generateItemViewArgs(t)),this.registerTrackedView(n,{shared:!1}),this.__modelToViewMap[t[this.__modelId]]=n.cid,i||this.__updateOrderedModelIdList(),this.trigger("child-view-added",{model:t,view:n}),this.trigger("item-view-added",{model:t,view:n}),n},__getStaleItemViews:function(){var t=[],i=e.clone(this.__modelToViewMap);return e.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&delete i[e[this.__modelId]]},this),e.each(i,function(e,i){var n=this.getTrackedView(e);n&&t.push({view:n,modelId:i})},this),t},__removeStaleItemViews:function(t){var i=this;t=t||this.__getStaleItemViews(),e.each(t,function(e){r.call(i,e.view,e.modelId)})},__emptyAndRebuildItemViewsFragment:function(){var i=document.createDocumentFragment();return this.$el.empty(),e.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&(t.detach(),this.registerTrackedView(t),t.attachTo(null,{replaceMethod:function(e){i.appendChild(e[0])},discardInjectionSite:!0}))},this),this.__updateOrderedModelIdList(),t(i)},__updateByAddingRemoving:function(i,n,s){var r,o,c=this,d=e.size(i),u=(e.size(n),e.size(s));c.itemContainer&&d&&d==u&&(o=t(""),e.first(i).$el.before(o)),c.__removeStaleItemViews(s),e.each(n,function(t,i){if(0===t.indexOfModel){var n;if(c.itemContainer)if(o)n=e.bind(o.replaceWith,o);else{var d=e.indexBy(s,"modelId"),u=e.find(c.__orderedModelIdList,function(e){return!d[e]});r=c.getTrackedView(c.__modelToViewMap[u]),n=e.bind(r.$el.prepend,r.$el)}else n=e.bind(c.$el.prepend,c.$el);c.attachView(null,t.view,{replaceMethod:n,discardInjectionSite:!0})}else a.call(c,t.view,t.indexOfModel)}),this.reorder()},__updateOrderedModelIdList:function(t){this.__orderedModelIdList=t||e.pluck(this.modelsToRender(),this.__modelId)},__generateItemViewArgs:function(t){var i={context:e.extend({},e.result(this,"__itemContext")),listView:this};return i[this.__modelName]=t,i},__generateChildArgs:function(){return this.__generateItemViewArgs.apply(this,arguments)},__getViewIdFromModelId:function(e){return this.__modelToViewMap[e]}});return u}),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,s){"use strict";var r=i.extend({constructor:function(t){t=t||{},this.model=t.model||this.model||new n,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||{}),i.apply(this,arguments),this.resetModelListeners(this.model)},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)},resetModelListeners:function(e,t){this.model&&t&&this.stopListening(this.model),this.model=e,this.listenTo(this.model,"validated:valid",this.valid),this.listenTo(this.model,"validated:invalid",this.invalid)},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==!!n?{addClass:t}:{removeClass:t}},_thenSetTextIfInvalid:function(e,t,i){var n=this.model.isValid(e);return!!i==!!n?{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"),s=i.__getFieldOptions(n),r=i.__generateModelFieldBinding(n,s);i.bindings['[data-model="'+n+'"]']=r})},__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 s=[t];return s.push(n),s=e.flatten(s),i.modelFormat?i.modelFormat.apply(this,s):t},onGet:function(t){var s=[t];return s.push(n),s=e.flatten(s),i.viewFormat?i.viewFormat.apply(this,s):t}}}});return r}); \ No newline at end of file