diff --git a/docs/annotated/modules/templateRenderer.html b/docs/annotated/modules/templateRenderer.html index bc3fde61..39a9d09a 100644 --- a/docs/annotated/modules/templateRenderer.html +++ b/docs/annotated/modules/templateRenderer.html @@ -304,14 +304,14 @@

templateRenderer.js

    currentAttributes = currentNode.attributes;
+    var prevLength = currentAttributes.length;
     while (idx < currentAttributes.length) {
       currentAttr = currentAttributes[idx].name;
       if (newNode.getAttribute(currentAttr)) {
         idx++;
       } else {
         currentNode.removeAttribute(currentAttr);
-      }
-    }
+ if (prevLength === currentAttributes.length) { @@ -322,6 +322,26 @@

templateRenderer.js

+

bail since we can’t remove the attribute.

+ + + +
          $currentNode.replaceWith(newNode);
+          return;
+        }
+        prevLength = currentAttributes.length;
+      }
+    }
+ + + + +
  • +
    + +
    + +

    Set new attributes

    @@ -335,11 +355,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    Quick check to see if we need to bother comparing sub-levels

    @@ -352,11 +372,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    Include all child nodes, including text and comment nodes

    @@ -368,11 +388,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    If the DOM lists are different sizes, perform a hard refresh

    @@ -386,11 +406,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    Perform a recursive hotswap for all children nodes

    @@ -493,11 +513,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    See above function declaration for method-level documentation

    @@ -539,11 +559,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    range {IE selection object} iCaretPos {Integer} will store the final caret position

    @@ -556,11 +576,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    IE Support

    @@ -571,11 +591,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    Set focus on the element

    @@ -586,11 +606,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    To get cursor position, get empty selection range

    @@ -601,11 +621,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    Move selection start to 0 position

    @@ -616,11 +636,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    The caret position is selection length

    @@ -632,11 +652,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    Firefox support

    @@ -648,11 +668,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    Return results

    @@ -676,11 +696,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    IE support

    @@ -694,11 +714,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    Firefox support

    @@ -711,11 +731,11 @@

    templateRenderer.js

  • -
  • +
  • - +

    At least focus the element if nothing else

    diff --git a/docs/api/templateRenderer.html b/docs/api/templateRenderer.html index c1b04330..30b470f0 100644 --- a/docs/api/templateRenderer.html +++ b/docs/api/templateRenderer.html @@ -75,7 +75,7 @@

    Source:
    @@ -168,7 +168,7 @@

    (static) Source:
    @@ -323,7 +323,7 @@

    (static) Source:
    @@ -658,7 +658,7 @@

    (static) Source:
    @@ -837,7 +837,7 @@

    (static) rende
    Source:
    @@ -1218,7 +1218,7 @@

    (static) Source:
    @@ -1396,7 +1396,7 @@

    (static) <
    Source:
    diff --git a/docs/api/templateRenderer.js.html b/docs/api/templateRenderer.js.html index 42675f7b..280ad2c3 100644 --- a/docs/api/templateRenderer.js.html +++ b/docs/api/templateRenderer.js.html @@ -157,12 +157,19 @@

    templateRenderer.js

    // This is necessary, because some types of attributes cannot be removed // without causing a browser error. currentAttributes = currentNode.attributes; + var prevLength = currentAttributes.length; while (idx < currentAttributes.length) { currentAttr = currentAttributes[idx].name; if (newNode.getAttribute(currentAttr)) { idx++; } else { currentNode.removeAttribute(currentAttr); + if (prevLength === currentAttributes.length) { + // bail since we can't remove the attribute. + $currentNode.replaceWith(newNode); + return; + } + prevLength = currentAttributes.length; } } diff --git a/torso-bundle.js b/torso-bundle.js index 3c1bc0c5..6f40dc7e 100644 --- a/torso-bundle.js +++ b/torso-bundle.js @@ -627,12 +627,19 @@ // This is necessary, because some types of attributes cannot be removed // without causing a browser error. currentAttributes = currentNode.attributes; + var prevLength = currentAttributes.length; while (idx < currentAttributes.length) { currentAttr = currentAttributes[idx].name; if (newNode.getAttribute(currentAttr)) { idx++; } else { currentNode.removeAttribute(currentAttr); + if (prevLength === currentAttributes.length) { + // bail since we can't remove the attribute. + $currentNode.replaceWith(newNode); + return; + } + prevLength = currentAttributes.length; } } diff --git a/torso-bundle.min.js b/torso-bundle.min.js index db450ddf..88937a6d 100644 --- a/torso-bundle.min.js +++ b/torso-bundle.min.js @@ -1 +1 @@ -!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";return e.extend({},t.Events)}),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(["underscore"],t):"object"==typeof exports?module.exports=t(require("underscore")):(e.Torso=e.Torso||{},e.Torso.Utils=e.Torso.Utils||{},e.Torso.Utils.handlebarsUtils=t(e._))}(this,function(o){"use strict";return function(l){var h="feedback",u="model";l.registerHelper("labelFor",function(e,t){return t=o.extend(t,{noValueAttr:!0}),l.helpers.formAttr(e,"for",t)}),l.registerHelper("bindModel",function(e,t){return l.helpers.formAttr(e,u+", "+h+", name, id",t)}),l.registerHelper("feedback",function(e,t){return t=o.extend(t,{noValueAttr:!0}),l.helpers.formAttr(e,h,t)}),l.registerHelper("formAttr",function(e,t,i){var n,s,r=i.hash?i.hash.value:void 0,o=l.helpers.injectFieldIndices(e,i.hash),a=l.helpers.injectFieldIndices(e,i.hash,{forceArrayNotation:!0}),d="";for(t=t.split(","),n=0;n'),n.addBefore?t.$el.before(s):t.$el.after(s),t.injectionSite=void 0,t.transitionOut(o.resolve,n),r=this.__transitionInView(s,i,n),f.when(o.promise(),r)},__transitionInView:function(e,t,i){var n=f.Deferred(),s=this;return i=u.extend({},i),u.defaults(i,{parentView:this,newView:t}),t.transitionIn(function(){s.attachView(e,t,i)},n.resolve,i),n.promise()},__getTrackedViewsHash:function(e){var t={};return(e=e||{}).shared&&(t=u.extend(t,this.__sharedViews)),e.child&&(t=u.extend(t,this.__childViews)),e.child||e.shared||(t=u.extend(t,this.__sharedViews,this.__childViews)),t},__updateInjectionSiteMap:function(){var t=this;this.__injectionSiteMap={},this.__lastTrackedViews={},u.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.injectionSite&&(t.__injectionSiteMap[e.injectionSite.attr("inject")]=e),t.__lastTrackedViews[e.cid]=e})},__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,u.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.__invokeAttached()}))},__invokeDetached:function(){this.__attachedCallbackInvoked&&(this.trigger("before-detached-callback"),this._detached(),this.__attachedCallbackInvoked=!1),u.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.__invokeDetached()})},__generateFeedbackCellCallbacks:function(){var s=this;s.feedbackCell.off(),u.each(this.$("[data-feedback]"),function(e){var t,i=f(e).data("feedback");s.feedbackCell.on("change:"+i,(t=i,function(){var n,e=s.feedbackCell.get(t);e&&(n=s.$el.find('[data-feedback="'+t+'"]'),u.each(e,function(e,t){var i;i="_"===u.first(t)?s[t.slice(1)]:n[t],u.isArray(e)?i.apply(n,e):void 0!==e&&i.call(n,e)}))}))}),u.each(s.feedbackCell.attributes,function(e,t){s.feedbackCell.trigger("change:"+t)})},__processFeedbackThenResult:function(e,t){var i=f.extend({},e);this.feedbackCell.set(t,i,{silent:!0}),this.feedbackCell.trigger("change:"+t)},__generateFeedbackBindings:function(){var e,h=this;for(e=0;ei[1])return this.format(u(this.msgKey,_.range),this.formatLabel(t,n),i[0],i[1])},length:function(e,t,i,n){if(!m.isString(e)||e.length!==i)return this.format(u(this.msgKey,_.length),this.formatLabel(t,n),i)},minLength:function(e,t,i,n){if(!m.isString(e)||e.lengthi)return this.format(u(this.msgKey,_.maxLength),this.formatLabel(t,n),i)},rangeLength:function(e,t,i,n){if(!m.isString(e)||e.lengthi[1])return this.format(u(this.msgKey,_.rangeLength),this.formatLabel(t,n),i[0],i[1])},oneOf:function(e,t,i,n){if(!m.include(i,e))return this.format(u(this.msgKey,_.oneOf),this.formatLabel(t,n),i.join(", "))},equalTo:function(e,t,i,n,s){if(e!==s[i])return this.format(u(this.msgKey,_.equalTo),this.formatLabel(t,n),this.formatLabel(i,n))},pattern:function(e,t,i,n){if(!d(e)||!e.toString().match(p[i]||i))return this.format(u(this.msgKey,_[i])||_.inlinePattern,this.formatLabel(t,n),i)}});return e}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./NestedModel","./validation"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./NestedModel"),require("./validation")):(e.Torso=e.Torso||{},e.Torso.FormModel=t(e._,e.Backbone,e.Torso.NestedModel,e.Torso.validation))}(this,function(h,e,r,t){"use strict";var o=e.$,i=r.extend({mapping:void 0,models:void 0,constructor:function(e,t){t=t||{},this.__cache={},this.__currentUpdateEvents=[],this.__currentMappings={},this.__currentObjectModels={},this.validation=h.extend({},this.validation,t.validation),this.labels=h.extend({},this.labels,t.labels),r.apply(this,arguments),this.__initMappings(t),this.pull(),e&&this.set(e),t.startUpdating&&this.startUpdating(),this.trigger("initialization-complete")},getMapping:function(e){return this.__currentMappings[e]},getMappings:function(){return this.__currentMappings},setMapping:function(e,t,i,n){var s,r,o={};h.isString(t)?r=t.split(" "):!0===t?r=void 0:h.isObject(t)&&(t=h.clone(t),s=!0),(o.computed=s)?(o.mapping=t,h.each(this.__getModelAliases(o),function(e){var t=o.mapping[e];h.isString(t)?t=t.split(" "):!0===t&&(t=void 0),o.mapping[e]=t})):o.mapping=r,this.__currentMappings[e]=o,i&&(s?this.trackModels(i,n):this.trackModel(e,i,n))},setMappings:function(e,t,i){h.each(e,function(e,t){this.setMapping(t,e)},this),t&&this.trackModels(t,i)},unsetMapping:function(e,t){var i=this.__findAlias(e);i&&delete this.__currentMappings[i];var n=this.getTrackedModel(i);t&&n&&h.isEmpty(this.__getTrackedModelFields(n))&&this.untrackModel(n)},unsetMappings:function(){this.__currentMappings={},this.resetUpdating()},getTrackedModel:function(e){return this.__currentObjectModels[e]},getTrackedModels:function(){return h.values(this.__currentObjectModels)},setTrackedModel:function(){this.trackModel.apply(this,arguments)},trackModel:function(n,e,t){this.__currentObjectModels[n]=e,this.__updateCache(e),this.resetUpdating(),t&&h.each(this.getMappings(),function(e,t){var i;n===t&&this.__pull(t),e.computed&&(i=this.__getModelAliases(t),h.contains(i,n)&&this.__pull(t))},this)},setTrackedModels:function(){this.trackModels.apply(this,arguments)},trackModels:function(e,i){h.each(e,function(e,t){this.trackModel(t,e,i)},this)},unsetTrackedModel:function(){this.untrackModel.apply(this,arguments)},untrackModel: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.untrackModels.apply(this,arguments)},untrackModels:function(){this.__currentObjectModels=[],this.__updateCache(),this.resetUpdating()},push:function(){h.each(this.getMappings(),function(e,t){this.__push(t)},this)},pull:function(){h.each(this.getMappings(),function(e,t){this.__pull(t)},this),this.__updateCache()},save:function(e){var t,i,n=new o.Deferred,s=this;e=e||{},h.defaults(e,{rollback:!0,force:!0});try{i=h.result(s,"url")}catch(e){}return i?r.prototype.save.apply(s,arguments).done(function(){s.push()}):this.isTrackingAnyObjectModel()?(this.__saveToModels(n,e),n.promise()):(t={none:{success:!1,response:[{responseJSON:{generalReasons:[{messageKey:"no.models.were.bound.to.form"}]}}]}},this.trigger("save-fail",t),(new o.Deferred).reject(t).promise())},isTrackingAnyObjectModel:function(){return 0"),t.append(e)),this.hasItemViews()?e.replaceWith(this.__emptyAndRebuildItemViewsFragment()):this.emptyTemplate&&e.replaceWith(this.emptyTemplate(this.prepareEmpty())),this.$el.html(t.contents())},__cleanupItemViewsAfterAttachedToParent:function(){u.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&(t.delegateEvents(),!t.__attachedCallbackInvoked&&t.isAttached()&&t.__invokeAttached(),t.activate())},this)},renderChildViews:function(){u.each(this.getTrackedViews({child:!0}),function(e){e.render()})},reorder:function(){var n,e,s=[],t=this.modelsToRender(),r=u.pluck(t,this.__modelId),i=u.size(r);if(!(i===u.size(this.__orderedModelIdList)))throw"Reorder should not be invoked if the number of models have changed";if(e=u.reduce(this.__orderedModelIdList,function(e,t,i){return e&&r[i]==t},!0),i&&!e){if(u.each(t,function(e,t){var i=this.getItemViewFromModel(e);i&&s.push(i.$el),0===t&&(n=i)},this),this.itemContainer){if(n){var o=l("");n.$el.before(o),o.after(s),o.remove()}}else this.$el.append(s);this.__updateOrderedModelIdList(r),this.trigger("reorder-complete")}},prepareEmpty:function(){return this.prepare()},modelsToRender:function(){return this.collection?this.collection.models:[]},update:function(){var e=this.getItemViews(),t=this.__createItemViews(),i=this.__getStaleItemViews(),n=u.size(e),s=u.size(t),r=u.size(i),o=n-r+s,a=s+r,d=a/Math.max(o,1),c=!n&&s,l=n&&n===r&&!s,h=(this.updateThreshold||.5)<=d;if(a<=0)return this.reorder();c||l||h?(this.__removeStaleItemViews(i),this.__delayedRender()):this.__updateByAddingRemoving(e,t,i)},getItemViewFromModel:function(e){return e?this.getTrackedView(this.__modelToViewMap[e[this.__modelId]]):void 0},hasItemViews:function(){return!u.isEmpty(this.getItemViews())},getItemViews:function(){var e=u.map(this.__orderedModelIdList,this.__getViewIdFromModelId,this);return u.map(e,this.getTrackedView,this)},__createItemViews:function(){var i=[];return u.each(this.modelsToRender(),function(e,t){this.getItemViewFromModel(e)||i.push({view:this.__createItemView(e,!0),indexOfModel:t})},this),this.__updateOrderedModelIdList(),i},__createItemView:function(e,t){var i,n=this.itemView;return u.isFunction(this.itemView.extend)||(n=this.itemView(e)),i=new n(this.__generateItemViewArgs(e)),this.registerTrackedView(i,{shared:!1}),this.__modelToViewMap[e[this.__modelId]]=i.cid,t||this.__updateOrderedModelIdList(),this.trigger("child-view-added",{model:e,view:i}),this.trigger("item-view-added",{model:e,view:i}),i},__getStaleItemViews:function(){var n=[],t=u.clone(this.__modelToViewMap);return u.each(this.modelsToRender(),function(e){this.getItemViewFromModel(e)&&delete t[e[this.__modelId]]},this),u.each(t,function(e,t){var i=this.getTrackedView(e);i&&n.push({view:i,modelId:t})},this),n},__removeStaleItemViews:function(e){var t=this;e=e||this.__getStaleItemViews(),u.each(e,function(e){r.call(t,e.view,e.modelId)})},__emptyAndRebuildItemViewsFragment:function(){var i=document.createDocumentFragment();return this.$el.empty(),u.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&(t.detach(),this.registerTrackedView(t,{shared:!1}),t.attachTo(null,{replaceMethod:function(e){i.appendChild(e[0])},discardInjectionSite:!0}))},this),this.__updateOrderedModelIdList(),l(i)},__updateByAddingRemoving:function(e,t,r){var o,a,d=this,i=u.size(e),n=(u.size(t),u.size(r));d.itemContainer&&i&&i==n&&(a=l(""),u.first(e).$el.before(a)),d.__removeStaleItemViews(r),u.each(t,function(e,t){if(0===e.indexOfModel){var i;if(d.itemContainer)if(a)i=u.bind(a.replaceWith,a);else{var n=u.indexBy(r,"modelId"),s=u.find(d.__orderedModelIdList,function(e){return!n[e]});o=d.getTrackedView(d.__modelToViewMap[s]),i=u.bind(o.$el.prepend,o.$el)}else i=u.bind(d.$el.prepend,d.$el);d.attachView(null,e.view,{replaceMethod:i,discardInjectionSite:!0})}else c.call(d,e.view,e.indexOfModel)}),this.reorder()},__updateOrderedModelIdList:function(e){this.__orderedModelIdList=e||u.pluck(this.modelsToRender(),this.__modelId)},__generateItemViewArgs:function(e){var t={context:u.extend({},u.result(this,"__itemContext")),listView:this};return t[this.__modelName]=e,t},__generateChildArgs:function(){return this.__generateItemViewArgs.apply(this,arguments)},__getViewIdFromModelId:function(e){return this.__modelToViewMap[e]}})}),function(e,t){if("function"==typeof define&&define.amd)define(["underscore","backbone","../Behavior","../Collection","../Events"],t);else if("object"==typeof exports){var i=require("underscore"),n=require("backbone"),s=require("../Behavior"),r=require("../Collection"),o=require("../Events");module.exports=t(i,n,s,r,o)}else e.Torso=e.Torso||{},e.Torso.behaviors=e.Torso.behaviors||{},e.Torso.behaviors.DataBehavior=t(e._,e.Backbone,e.Torso.Behavior,e.Torso.Collection,e.Torso.Events)}(this,function(d,e,n,t,i){"use strict";var c=e.$,s={SUCCESS:"success",FAILURE:"failed"};function l(e){return d.isArray(e)?(e=d.flatten(e),d.uniq(e)):d.isString(e)||d.isNumber(e)?[e]:e&&e.skipObjectRetrieval?e:void 0}function h(e){return(d.isUndefined(e)||d.isNull(e))&&(e=[]),e}function u(e,t){var i=(t=(t=t.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split(".");return d.reduce(i,function(e,t){return d.isUndefined(e)?void 0:e[t]},e)}function f(e){return!!e&&-1'),n.addBefore?t.$el.before(s):t.$el.after(s),t.injectionSite=void 0,t.transitionOut(o.resolve,n),r=this.__transitionInView(s,i,n),f.when(o.promise(),r)},__transitionInView:function(e,t,i){var n=f.Deferred(),s=this;return i=u.extend({},i),u.defaults(i,{parentView:this,newView:t}),t.transitionIn(function(){s.attachView(e,t,i)},n.resolve,i),n.promise()},__getTrackedViewsHash:function(e){var t={};return(e=e||{}).shared&&(t=u.extend(t,this.__sharedViews)),e.child&&(t=u.extend(t,this.__childViews)),e.child||e.shared||(t=u.extend(t,this.__sharedViews,this.__childViews)),t},__updateInjectionSiteMap:function(){var t=this;this.__injectionSiteMap={},this.__lastTrackedViews={},u.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.injectionSite&&(t.__injectionSiteMap[e.injectionSite.attr("inject")]=e),t.__lastTrackedViews[e.cid]=e})},__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,u.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.__invokeAttached()}))},__invokeDetached:function(){this.__attachedCallbackInvoked&&(this.trigger("before-detached-callback"),this._detached(),this.__attachedCallbackInvoked=!1),u.each(this.getTrackedViews(),function(e){e.isAttachedToParent()&&e.__invokeDetached()})},__generateFeedbackCellCallbacks:function(){var s=this;s.feedbackCell.off(),u.each(this.$("[data-feedback]"),function(e){var t,i=f(e).data("feedback");s.feedbackCell.on("change:"+i,(t=i,function(){var n,e=s.feedbackCell.get(t);e&&(n=s.$el.find('[data-feedback="'+t+'"]'),u.each(e,function(e,t){var i;i="_"===u.first(t)?s[t.slice(1)]:n[t],u.isArray(e)?i.apply(n,e):void 0!==e&&i.call(n,e)}))}))}),u.each(s.feedbackCell.attributes,function(e,t){s.feedbackCell.trigger("change:"+t)})},__processFeedbackThenResult:function(e,t){var i=f.extend({},e);this.feedbackCell.set(t,i,{silent:!0}),this.feedbackCell.trigger("change:"+t)},__generateFeedbackBindings:function(){var e,h=this;for(e=0;ei[1])return this.format(u(this.msgKey,_.range),this.formatLabel(t,n),i[0],i[1])},length:function(e,t,i,n){if(!m.isString(e)||e.length!==i)return this.format(u(this.msgKey,_.length),this.formatLabel(t,n),i)},minLength:function(e,t,i,n){if(!m.isString(e)||e.lengthi)return this.format(u(this.msgKey,_.maxLength),this.formatLabel(t,n),i)},rangeLength:function(e,t,i,n){if(!m.isString(e)||e.lengthi[1])return this.format(u(this.msgKey,_.rangeLength),this.formatLabel(t,n),i[0],i[1])},oneOf:function(e,t,i,n){if(!m.include(i,e))return this.format(u(this.msgKey,_.oneOf),this.formatLabel(t,n),i.join(", "))},equalTo:function(e,t,i,n,s){if(e!==s[i])return this.format(u(this.msgKey,_.equalTo),this.formatLabel(t,n),this.formatLabel(i,n))},pattern:function(e,t,i,n){if(!d(e)||!e.toString().match(p[i]||i))return this.format(u(this.msgKey,_[i])||_.inlinePattern,this.formatLabel(t,n),i)}});return e}),function(e,t){"function"==typeof define&&define.amd?define(["underscore","backbone","./NestedModel","./validation"],t):"object"==typeof exports?module.exports=t(require("underscore"),require("backbone"),require("./NestedModel"),require("./validation")):(e.Torso=e.Torso||{},e.Torso.FormModel=t(e._,e.Backbone,e.Torso.NestedModel,e.Torso.validation))}(this,function(h,e,r,t){"use strict";var o=e.$,i=r.extend({mapping:void 0,models:void 0,constructor:function(e,t){t=t||{},this.__cache={},this.__currentUpdateEvents=[],this.__currentMappings={},this.__currentObjectModels={},this.validation=h.extend({},this.validation,t.validation),this.labels=h.extend({},this.labels,t.labels),r.apply(this,arguments),this.__initMappings(t),this.pull(),e&&this.set(e),t.startUpdating&&this.startUpdating(),this.trigger("initialization-complete")},getMapping:function(e){return this.__currentMappings[e]},getMappings:function(){return this.__currentMappings},setMapping:function(e,t,i,n){var s,r,o={};h.isString(t)?r=t.split(" "):!0===t?r=void 0:h.isObject(t)&&(t=h.clone(t),s=!0),(o.computed=s)?(o.mapping=t,h.each(this.__getModelAliases(o),function(e){var t=o.mapping[e];h.isString(t)?t=t.split(" "):!0===t&&(t=void 0),o.mapping[e]=t})):o.mapping=r,this.__currentMappings[e]=o,i&&(s?this.trackModels(i,n):this.trackModel(e,i,n))},setMappings:function(e,t,i){h.each(e,function(e,t){this.setMapping(t,e)},this),t&&this.trackModels(t,i)},unsetMapping:function(e,t){var i=this.__findAlias(e);i&&delete this.__currentMappings[i];var n=this.getTrackedModel(i);t&&n&&h.isEmpty(this.__getTrackedModelFields(n))&&this.untrackModel(n)},unsetMappings:function(){this.__currentMappings={},this.resetUpdating()},getTrackedModel:function(e){return this.__currentObjectModels[e]},getTrackedModels:function(){return h.values(this.__currentObjectModels)},setTrackedModel:function(){this.trackModel.apply(this,arguments)},trackModel:function(n,e,t){this.__currentObjectModels[n]=e,this.__updateCache(e),this.resetUpdating(),t&&h.each(this.getMappings(),function(e,t){var i;n===t&&this.__pull(t),e.computed&&(i=this.__getModelAliases(t),h.contains(i,n)&&this.__pull(t))},this)},setTrackedModels:function(){this.trackModels.apply(this,arguments)},trackModels:function(e,i){h.each(e,function(e,t){this.trackModel(t,e,i)},this)},unsetTrackedModel:function(){this.untrackModel.apply(this,arguments)},untrackModel: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.untrackModels.apply(this,arguments)},untrackModels:function(){this.__currentObjectModels=[],this.__updateCache(),this.resetUpdating()},push:function(){h.each(this.getMappings(),function(e,t){this.__push(t)},this)},pull:function(){h.each(this.getMappings(),function(e,t){this.__pull(t)},this),this.__updateCache()},save:function(e){var t,i,n=new o.Deferred,s=this;e=e||{},h.defaults(e,{rollback:!0,force:!0});try{i=h.result(s,"url")}catch(e){}return i?r.prototype.save.apply(s,arguments).done(function(){s.push()}):this.isTrackingAnyObjectModel()?(this.__saveToModels(n,e),n.promise()):(t={none:{success:!1,response:[{responseJSON:{generalReasons:[{messageKey:"no.models.were.bound.to.form"}]}}]}},this.trigger("save-fail",t),(new o.Deferred).reject(t).promise())},isTrackingAnyObjectModel:function(){return 0"),t.append(e)),this.hasItemViews()?e.replaceWith(this.__emptyAndRebuildItemViewsFragment()):this.emptyTemplate&&e.replaceWith(this.emptyTemplate(this.prepareEmpty())),this.$el.html(t.contents())},__cleanupItemViewsAfterAttachedToParent:function(){u.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&(t.delegateEvents(),!t.__attachedCallbackInvoked&&t.isAttached()&&t.__invokeAttached(),t.activate())},this)},renderChildViews:function(){u.each(this.getTrackedViews({child:!0}),function(e){e.render()})},reorder:function(){var n,e,s=[],t=this.modelsToRender(),r=u.pluck(t,this.__modelId),i=u.size(r);if(!(i===u.size(this.__orderedModelIdList)))throw"Reorder should not be invoked if the number of models have changed";if(e=u.reduce(this.__orderedModelIdList,function(e,t,i){return e&&r[i]==t},!0),i&&!e){if(u.each(t,function(e,t){var i=this.getItemViewFromModel(e);i&&s.push(i.$el),0===t&&(n=i)},this),this.itemContainer){if(n){var o=l("");n.$el.before(o),o.after(s),o.remove()}}else this.$el.append(s);this.__updateOrderedModelIdList(r),this.trigger("reorder-complete")}},prepareEmpty:function(){return this.prepare()},modelsToRender:function(){return this.collection?this.collection.models:[]},update:function(){var e=this.getItemViews(),t=this.__createItemViews(),i=this.__getStaleItemViews(),n=u.size(e),s=u.size(t),r=u.size(i),o=n-r+s,a=s+r,d=a/Math.max(o,1),c=!n&&s,l=n&&n===r&&!s,h=(this.updateThreshold||.5)<=d;if(a<=0)return this.reorder();c||l||h?(this.__removeStaleItemViews(i),this.__delayedRender()):this.__updateByAddingRemoving(e,t,i)},getItemViewFromModel:function(e){return e?this.getTrackedView(this.__modelToViewMap[e[this.__modelId]]):void 0},hasItemViews:function(){return!u.isEmpty(this.getItemViews())},getItemViews:function(){var e=u.map(this.__orderedModelIdList,this.__getViewIdFromModelId,this);return u.map(e,this.getTrackedView,this)},__createItemViews:function(){var i=[];return u.each(this.modelsToRender(),function(e,t){this.getItemViewFromModel(e)||i.push({view:this.__createItemView(e,!0),indexOfModel:t})},this),this.__updateOrderedModelIdList(),i},__createItemView:function(e,t){var i,n=this.itemView;return u.isFunction(this.itemView.extend)||(n=this.itemView(e)),i=new n(this.__generateItemViewArgs(e)),this.registerTrackedView(i,{shared:!1}),this.__modelToViewMap[e[this.__modelId]]=i.cid,t||this.__updateOrderedModelIdList(),this.trigger("child-view-added",{model:e,view:i}),this.trigger("item-view-added",{model:e,view:i}),i},__getStaleItemViews:function(){var n=[],t=u.clone(this.__modelToViewMap);return u.each(this.modelsToRender(),function(e){this.getItemViewFromModel(e)&&delete t[e[this.__modelId]]},this),u.each(t,function(e,t){var i=this.getTrackedView(e);i&&n.push({view:i,modelId:t})},this),n},__removeStaleItemViews:function(e){var t=this;e=e||this.__getStaleItemViews(),u.each(e,function(e){r.call(t,e.view,e.modelId)})},__emptyAndRebuildItemViewsFragment:function(){var i=document.createDocumentFragment();return this.$el.empty(),u.each(this.modelsToRender(),function(e){var t=this.getItemViewFromModel(e);t&&(t.detach(),this.registerTrackedView(t,{shared:!1}),t.attachTo(null,{replaceMethod:function(e){i.appendChild(e[0])},discardInjectionSite:!0}))},this),this.__updateOrderedModelIdList(),l(i)},__updateByAddingRemoving:function(e,t,r){var o,a,d=this,i=u.size(e),n=(u.size(t),u.size(r));d.itemContainer&&i&&i==n&&(a=l(""),u.first(e).$el.before(a)),d.__removeStaleItemViews(r),u.each(t,function(e,t){if(0===e.indexOfModel){var i;if(d.itemContainer)if(a)i=u.bind(a.replaceWith,a);else{var n=u.indexBy(r,"modelId"),s=u.find(d.__orderedModelIdList,function(e){return!n[e]});o=d.getTrackedView(d.__modelToViewMap[s]),i=u.bind(o.$el.prepend,o.$el)}else i=u.bind(d.$el.prepend,d.$el);d.attachView(null,e.view,{replaceMethod:i,discardInjectionSite:!0})}else c.call(d,e.view,e.indexOfModel)}),this.reorder()},__updateOrderedModelIdList:function(e){this.__orderedModelIdList=e||u.pluck(this.modelsToRender(),this.__modelId)},__generateItemViewArgs:function(e){var t={context:u.extend({},u.result(this,"__itemContext")),listView:this};return t[this.__modelName]=e,t},__generateChildArgs:function(){return this.__generateItemViewArgs.apply(this,arguments)},__getViewIdFromModelId:function(e){return this.__modelToViewMap[e]}})}),function(e,t){if("function"==typeof define&&define.amd)define(["underscore","backbone","../Behavior","../Collection","../Events"],t);else if("object"==typeof exports){var i=require("underscore"),n=require("backbone"),s=require("../Behavior"),r=require("../Collection"),o=require("../Events");module.exports=t(i,n,s,r,o)}else e.Torso=e.Torso||{},e.Torso.behaviors=e.Torso.behaviors||{},e.Torso.behaviors.DataBehavior=t(e._,e.Backbone,e.Torso.Behavior,e.Torso.Collection,e.Torso.Events)}(this,function(d,e,n,t,i){"use strict";var c=e.$,s={SUCCESS:"success",FAILURE:"failed"};function l(e){return d.isArray(e)?(e=d.flatten(e),d.uniq(e)):d.isString(e)||d.isNumber(e)?[e]:e&&e.skipObjectRetrieval?e:void 0}function h(e){return(d.isUndefined(e)||d.isNull(e))&&(e=[]),e}function u(e,t){var i=(t=(t=t.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split(".");return d.reduce(i,function(e,t){return d.isUndefined(e)?void 0:e[t]},e)}function f(e){return!!e&&-1