diff --git a/docs/js/classes/View.html b/docs/js/classes/View.html index 28f90fc9..c59c2b21 100644 --- a/docs/js/classes/View.html +++ b/docs/js/classes/View.html @@ -352,6 +352,10 @@

Methods

  • render +
  • +
  • + renderIfAttached +
  • set @@ -445,7 +449,7 @@

    __activateTrackedViews

    Defined in - modules/View.js:825 + modules/View.js:835

    @@ -526,7 +530,7 @@

    __deactivateTrackedViews

    Defined in - modules/View.js:810 + modules/View.js:820

    @@ -601,7 +605,7 @@

    __generateFeedbackBindings

    Defined in - modules/View.js:1143 + modules/View.js:1153

    @@ -634,7 +638,7 @@

    __generateFeedbackCellCallbacks

    Defined in - modules/View.js:1083 + modules/View.js:1093

    @@ -682,7 +686,7 @@

    __generateSubAttributes

    Defined in - modules/View.js:1388 + modules/View.js:1398

    @@ -753,7 +757,7 @@

    __generateThenCallback

    Defined in - modules/View.js:1252 + modules/View.js:1262

    @@ -855,7 +859,7 @@

    __generateWhenEvents

    Defined in - modules/View.js:1298 + modules/View.js:1308

    @@ -924,7 +928,7 @@

    __getAllIndexTokens

    Defined in - modules/View.js:1338 + modules/View.js:1348

    @@ -967,7 +971,7 @@

    __getFeedbackDestinations

    Defined in - modules/View.js:1275 + modules/View.js:1285

    @@ -1035,7 +1039,7 @@

    __getLastTrackedViewAtInjectionSite

    Defined in - modules/View.js:1005 + modules/View.js:1015

    @@ -1097,7 +1101,7 @@

    __getPrepareFieldsContext

    Defined in - modules/View.js:672 + modules/View.js:682

    @@ -1174,7 +1178,7 @@

    __getTrackedViewsHash

    Defined in - modules/View.js:963 + modules/View.js:973

    @@ -1258,7 +1262,7 @@

    __initializeBehaviors

    Defined in - modules/View.js:754 + modules/View.js:764

    @@ -1290,7 +1294,7 @@

    __invokeAttached

    Defined in - modules/View.js:1046 + modules/View.js:1056

    @@ -1321,7 +1325,7 @@

    __invokeDetached

    Defined in - modules/View.js:1065 + modules/View.js:1075

    @@ -1353,7 +1357,7 @@

    __performPendingAttach

    Defined in - modules/View.js:798 + modules/View.js:808

    @@ -1404,7 +1408,7 @@

    __performTwoWayTransition

    Defined in - modules/View.js:902 + modules/View.js:912

    @@ -1518,7 +1522,7 @@

    __processFeedbackThenResult

    Defined in - modules/View.js:1130 + modules/View.js:1140

    @@ -1587,7 +1591,7 @@

    __replaceInjectionSite

    Defined in - modules/View.js:1029 + modules/View.js:1039

    @@ -1672,7 +1676,7 @@

    __stripAllAttribute

    Defined in - modules/View.js:1357 + modules/View.js:1367

    @@ -1705,7 +1709,7 @@

    __substituteIndicesUsingMap

    Defined in - modules/View.js:1370 + modules/View.js:1380

    @@ -1738,7 +1742,7 @@

    __updateInjectionSiteMap

    Defined in - modules/View.js:990 + modules/View.js:1000

    @@ -1769,7 +1773,7 @@

    _activate

    Defined in - modules/View.js:437 + modules/View.js:447

    @@ -1801,7 +1805,7 @@

    _attached

    Defined in - modules/View.js:351 + modules/View.js:361

    @@ -1833,7 +1837,7 @@

    _deactivate

    Defined in - modules/View.js:466 + modules/View.js:476

    @@ -1865,7 +1869,7 @@

    _detached

    Defined in - modules/View.js:417 + modules/View.js:427

    @@ -1897,7 +1901,7 @@

    _dispose

    Defined in - modules/View.js:507 + modules/View.js:517

    @@ -1930,7 +1934,7 @@

    activate

    Defined in - modules/View.js:424 + modules/View.js:434

    @@ -1973,7 +1977,7 @@

    attachTo

    Defined in - modules/View.js:259 + modules/View.js:269

    @@ -2073,7 +2077,7 @@

    attachTrackedViews

    Defined in - modules/View.js:343 + modules/View.js:353

    @@ -2129,7 +2133,7 @@

    attachView

    Defined in - modules/View.js:289 + modules/View.js:299

    @@ -2313,7 +2317,7 @@

    deactivate

    Defined in - modules/View.js:452 + modules/View.js:462

    @@ -2345,7 +2349,7 @@

    delegateEvents

    Defined in - modules/View.js:230 + modules/View.js:240

    @@ -2377,7 +2381,7 @@

    detach

    Defined in - modules/View.js:375 + modules/View.js:385

    @@ -2416,7 +2420,7 @@

    detachTrackedViews

    Defined in - modules/View.js:401 + modules/View.js:411

    @@ -2491,7 +2495,7 @@

    dispose

    Defined in - modules/View.js:473 + modules/View.js:483

    @@ -2525,7 +2529,7 @@

    disposeChildViews

    Defined in - modules/View.js:840 + modules/View.js:850

    @@ -2661,7 +2665,7 @@

    getTrackedView

    Defined in - modules/View.js:548 + modules/View.js:558

    @@ -2725,7 +2729,7 @@

    getTrackedViews

    Defined in - modules/View.js:535 + modules/View.js:545

    @@ -2817,7 +2821,7 @@

    hasTrackedViews

    Defined in - modules/View.js:523 + modules/View.js:533

    @@ -2911,7 +2915,7 @@

    invokeFeedback

    Defined in - modules/View.js:643 + modules/View.js:653

    @@ -2986,7 +2990,7 @@

    isActive

    Defined in - modules/View.js:444 + modules/View.js:454

    @@ -3028,7 +3032,7 @@

    isAttached

    Defined in - modules/View.js:366 + modules/View.js:376

    @@ -3071,7 +3075,7 @@

    isAttachedToParent

    Defined in - modules/View.js:358 + modules/View.js:368

    @@ -3113,7 +3117,7 @@

    isDisposed

    Defined in - modules/View.js:515 + modules/View.js:525

    @@ -3155,7 +3159,7 @@

    postrender

    Defined in - modules/View.js:208 + modules/View.js:218

    @@ -3245,7 +3249,7 @@

    prerender

    Defined in - modules/View.js:185 + modules/View.js:195

    @@ -3299,7 +3303,7 @@

    registerTrackedView

    Defined in - modules/View.js:559 + modules/View.js:569

    @@ -3416,6 +3420,37 @@

    Returns:

    +
    +
    +

    renderIfAttached

    + + () + + + + + + + + +
    +

    + Defined in + modules/View.js:185 +

    + + + +
    + +
    +

    Renders the view only if it is active and part of the DOM.

    + +
    + + + +

    set

    @@ -3465,7 +3500,7 @@

    templateRender

    Defined in - modules/View.js:217 + modules/View.js:227

    @@ -3539,7 +3574,7 @@

    transitionIn

    Defined in - modules/View.js:626 + modules/View.js:636

    @@ -3659,7 +3694,7 @@

    transitionInView

    Defined in - modules/View.js:937 + modules/View.js:947

    @@ -3780,7 +3815,7 @@

    transitionNewViewIntoSite

    Defined in - modules/View.js:851 + modules/View.js:861

    @@ -3917,7 +3952,7 @@

    transitionOut

    Defined in - modules/View.js:611 + modules/View.js:621

    @@ -4040,7 +4075,7 @@

    undelegateEvents

    Defined in - modules/View.js:247 + modules/View.js:257

    @@ -4065,6 +4100,9 @@

    unregisterTrackedView

  • view
  • +
  • + [options] +
  • )
    @@ -4081,7 +4119,7 @@

    unregisterTrackedView

    Defined in - modules/View.js:581 + modules/View.js:603

    @@ -4089,7 +4127,8 @@

    unregisterTrackedView

    -

    Unbinds the tracked view - no recursive calls will be made to this shared view

    +

    Unbinds all tracked view - no recursive calls will be made to this shared view +You can limit the types of views that will be unregistered by using the options parameter.

    @@ -4108,6 +4147,43 @@

    Parameters:

  • +
  • + [options] + Object + optional + + +
    +

    {Object} Optional options.

    + +
    + + +
  • @@ -4131,9 +4207,6 @@

    unregisterTrackedView

  • view
  • -
  • - [options] -
  • ) @@ -4150,7 +4223,7 @@

    unregisterTrackedView

    Defined in - modules/View.js:593 + modules/View.js:591

    @@ -4158,8 +4231,7 @@

    unregisterTrackedView

    -

    Unbinds all tracked view - no recursive calls will be made to this shared view -You can limit the types of views that will be unregistered by using the options parameter.

    +

    Unbinds the tracked view - no recursive calls will be made to this shared view

    @@ -4178,43 +4250,6 @@

    Parameters:

    -
  • - [options] - Object - optional - - -
    -

    {Object} Optional options.

    - -
    - - -
  • @@ -4245,7 +4280,7 @@

    updateDOM

    Defined in - modules/View.js:194 + modules/View.js:204

    diff --git a/docs/js/data.json b/docs/js/data.json index 7fdd2ce7..4a05954b 100644 --- a/docs/js/data.json +++ b/docs/js/data.json @@ -4597,6 +4597,15 @@ { "file": "modules/View.js", "line": 185, + "description": "Renders the view only if it is active and part of the DOM.", + "itemtype": "method", + "name": "renderIfAttached", + "class": "View", + "module": "Torso" + }, + { + "file": "modules/View.js", + "line": 195, "description": "Hook during render that is invoked before any DOM rendering is performed.\nThis method can be overwritten as usual OR extended using .prototype.prerender.apply(this, arguments);\nNOTE: if you require the view to be detached from the DOM, consider using _detach callback", "itemtype": "method", "name": "prerender", @@ -4609,7 +4618,7 @@ }, { "file": "modules/View.js", - "line": 194, + "line": 204, "description": "Produces and sets this view's elements DOM. Used during the rendering process. Override if you have custom DOM update logic.\nDefaults to using the stanrdard: this.templateRender(this.$el, this.template, this.prepare(), templateRendererOptions);\nthis.templateRendererOptions is an object or function defined on the view that is passed into the renderer.\nExamples include: views with no template or multiple templates, or if you wish to use a different rendering engine than the templateRenderer or wish to pass options to it.", "itemtype": "method", "name": "updateDOM", @@ -4618,7 +4627,7 @@ }, { "file": "modules/View.js", - "line": 208, + "line": 218, "description": "Hook during render that is invoked after all DOM rendering is done and tracked views attached.\nThis method can be overwritten as usual OR extended using .prototype.postrender.apply(this, arguments);\nNOTE: if you require the view to be attached to the DOM, consider using _attach callback", "itemtype": "method", "name": "postrender", @@ -4631,7 +4640,7 @@ }, { "file": "modules/View.js", - "line": 217, + "line": 227, "description": "Hotswap rendering system reroute method.", "itemtype": "method", "name": "templateRender\nSee Torso.templateRenderer#render for params", @@ -4640,7 +4649,7 @@ }, { "file": "modules/View.js", - "line": 230, + "line": 240, "description": "Overrides the base delegateEvents\nBinds DOM events with the view using events hash while also adding feedback event bindings", "itemtype": "method", "name": "delegateEvents", @@ -4649,7 +4658,7 @@ }, { "file": "modules/View.js", - "line": 247, + "line": 257, "description": "Overrides undelegateEvents\nUnbinds DOM events from the view.", "itemtype": "method", "name": "undelegateEvents", @@ -4658,7 +4667,7 @@ }, { "file": "modules/View.js", - "line": 259, + "line": 269, "description": "If detached, will replace the element passed in with this view's element and activate the view.", "params": [ { @@ -4700,7 +4709,7 @@ }, { "file": "modules/View.js", - "line": 289, + "line": 299, "description": "Registers the view as a tracked view (defaulting as a child view), then calls view.attachTo with the element argument\nThe element argument can be a String that references an element with the corresponding \"inject\" attribute.\nWhen using attachView with options.useTransition:\n Will inject a new view into an injection site by using the new view's transitionIn method. If the parent view\n previously had another view at this injections site, this previous view will be removed with that view's transitionOut.\n If this method is used within a render, the current views' injection sites will be cached so they can be transitioned out even\n though they are detached in the process of re-rendering. If no previous view is given and none can be found, the new view is transitioned in regardless.\n If the previous view is the same as the new view, it is injected normally without transitioning in.\n The previous view must has used an injection site with the standard \"inject=\" attribute to be found.\n When the transitionIn and transitionOut methods are invoked on the new and previous views, the options parameter will be passed on to them. Other fields\n will be added to the options parameter to allow better handling of the transitions. These include:\n {\n newView: the new view\n previousView: the previous view (can be undefined)\n parentView: the parent view transitioning in or out the tracked view\n }", "params": [ { @@ -4767,7 +4776,7 @@ }, { "file": "modules/View.js", - "line": 343, + "line": 353, "description": "Hook to attach all your tracked views. This hook will be called after all DOM rendering is done so injection sites should be available.\nThis method can be overwritten as usual OR extended using .prototype.attachTrackedViews.apply(this, arguments);", "itemtype": "method", "name": "attachTrackedViews", @@ -4780,7 +4789,7 @@ }, { "file": "modules/View.js", - "line": 351, + "line": 361, "description": "Method to be invoked when the view is fully attached to the DOM (NOT just the parent). Use this method to manipulate the view\nafter the DOM has been attached to the document. The default implementation is a no-op.", "itemtype": "method", "name": "_attached", @@ -4789,7 +4798,7 @@ }, { "file": "modules/View.js", - "line": 358, + "line": 368, "return": { "description": "true if the view is attached to a parent", "type": "Boolean" @@ -4801,7 +4810,7 @@ }, { "file": "modules/View.js", - "line": 366, + "line": 376, "description": "NOTE: depends on a global variable \"document\"", "return": { "description": "true if the view is attached to the DOM", @@ -4814,7 +4823,7 @@ }, { "file": "modules/View.js", - "line": 375, + "line": 385, "description": "If attached, will detach the view from the DOM.\nThis method will only separate this view from the DOM it was attached to, but it WILL invoke the _detach\ncallback on each tracked view recursively.", "itemtype": "method", "name": "detach", @@ -4823,7 +4832,7 @@ }, { "file": "modules/View.js", - "line": 401, + "line": 411, "description": "Detach all tracked views or a subset of them based on the options parameter.\nNOTE: this is not recursive - it will not separate the entire view tree.", "params": [ { @@ -4855,7 +4864,7 @@ }, { "file": "modules/View.js", - "line": 417, + "line": 427, "description": "Method to be invoked when the view is detached from the DOM (NOT just the parent). Use this method to clean up state\nafter the view has been removed from the document. The default implementation is a no-op.", "itemtype": "method", "name": "_detached", @@ -4864,7 +4873,7 @@ }, { "file": "modules/View.js", - "line": 424, + "line": 434, "description": "Resets listeners and events in order for the view to be reattached to the visible DOM", "itemtype": "method", "name": "activate", @@ -4873,7 +4882,7 @@ }, { "file": "modules/View.js", - "line": 437, + "line": 447, "description": "Method to be invoked when activate is called. Use this method to turn on any\ncustom timers, listenTo's or on's that should be activatable. The default implementation is a no-op.", "itemtype": "method", "name": "_activate", @@ -4882,7 +4891,7 @@ }, { "file": "modules/View.js", - "line": 444, + "line": 454, "return": { "description": "true if the view is active", "type": "Boolean" @@ -4894,7 +4903,7 @@ }, { "file": "modules/View.js", - "line": 452, + "line": 462, "description": "Maintains view state and DOM but prevents view from becoming a zombie by removing listeners\nand events that may affect user experience. Recursively invokes deactivate on child views", "itemtype": "method", "name": "deactivate", @@ -4903,7 +4912,7 @@ }, { "file": "modules/View.js", - "line": 466, + "line": 476, "description": "Method to be invoked when deactivate is called. Use this method to turn off any\ncustom timers, listenTo's or on's that should be deactivatable. The default implementation is a no-op.", "itemtype": "method", "name": "_deactivate", @@ -4912,7 +4921,7 @@ }, { "file": "modules/View.js", - "line": 473, + "line": 483, "description": "Removes all listeners, disposes children views, stops listening to events, removes DOM.\nAfter dispose is called, the view can be safely garbage collected. Called while\nrecursively removing views from the hierarchy.", "itemtype": "method", "name": "dispose", @@ -4921,7 +4930,7 @@ }, { "file": "modules/View.js", - "line": 507, + "line": 517, "description": "Method to be invoked when dispose is called. By default calling dispose will remove the\nview's element, its on's, listenTo's, and any registered children.\nOverride this method to destruct any extra", "itemtype": "method", "name": "_dispose", @@ -4930,7 +4939,7 @@ }, { "file": "modules/View.js", - "line": 515, + "line": 525, "return": { "description": "true if the view was disposed", "type": "Boolean" @@ -4942,7 +4951,7 @@ }, { "file": "modules/View.js", - "line": 523, + "line": 533, "return": { "description": "true if this view has tracked views (limited by the options parameter)", "type": "Boolean" @@ -4977,7 +4986,7 @@ }, { "file": "modules/View.js", - "line": 535, + "line": 545, "description": "Returns all tracked views, both child views and shared views.", "itemtype": "method", "name": "getTrackedViews", @@ -5013,7 +5022,7 @@ }, { "file": "modules/View.js", - "line": 548, + "line": 558, "return": { "description": "the view with the given cid. Will look in both shared and child views." }, @@ -5031,7 +5040,7 @@ }, { "file": "modules/View.js", - "line": 559, + "line": 569, "description": "Binds the view as a tracked view - any recursive calls like activate, deactivate, or dispose will\nbe done to the tracked view as well. Except dispose for shared views. This method defaults to register the\nview as a child view unless specified by options.shared.", "params": [ { @@ -5065,7 +5074,7 @@ }, { "file": "modules/View.js", - "line": 581, + "line": 591, "description": "Unbinds the tracked view - no recursive calls will be made to this shared view", "params": [ { @@ -5085,7 +5094,7 @@ }, { "file": "modules/View.js", - "line": 593, + "line": 603, "description": "Unbinds all tracked view - no recursive calls will be made to this shared view\nYou can limit the types of views that will be unregistered by using the options parameter.", "params": [ { @@ -5126,7 +5135,7 @@ }, { "file": "modules/View.js", - "line": 611, + "line": 621, "description": "Override to provide your own transition out logic. Default logic is to just detach from the page.\nThe method is passed a callback that should be invoked when the transition out has fully completed.", "itemtype": "method", "name": "transitionOut", @@ -5164,7 +5173,7 @@ }, { "file": "modules/View.js", - "line": 626, + "line": 636, "description": "Override to provide your own transition in logic. Default logic is to just attach to the page.\nThe method is passed a callback that should be invoked when the transition in has fully completed.", "itemtype": "method", "name": "transitionIn", @@ -5207,7 +5216,7 @@ }, { "file": "modules/View.js", - "line": 643, + "line": 653, "description": "Invokes a feedback entry's \"then\" method", "params": [ { @@ -5235,7 +5244,7 @@ }, { "file": "modules/View.js", - "line": 672, + "line": 682, "description": "Parses the combined arrays from the defaultPrepareFields array and the prepareFields array (or function\nreturning an array).\n\nThe default prepared fields are: [ { name: 'view', value: 'viewState' }, 'model' ]\n\nPrepared fields can be defined in a couple of ways:\n preparedFields = [\n 'model',\n { name: 'app', value: someGlobalCell },\n 'a value that does not exist on the view',\n { name: 'view', value: 'viewState' },\n { name: 'patientId', value: '_patientId' },\n 'objectWithoutToJSON'\n ]\n\nWill result in the following context (where this === this view and it assumes all the properties on the view\nthat are referenced are defined):\n {\n model: this.model.toJSON(),\n app: someGlobalCell.toJSON(),\n view: this.viewState.toJSON(),\n patientId: this._patientId,\n objectWithoutToJSON: this.objectWithoutToJSON\n }\n\nThings to be careful of:\n * If the view already has a field named 'someGlobalCell' then the property on the view will be used instead of the global value.\n * if the prepared field item is not a string or object containing 'name' and 'value' properties, then an exception\n will be thrown.\n * 'model' and 'view' are reserved field names and cannot be reused.", "itemtype": "method", "name": "__getPrepareFieldsContext", @@ -5250,7 +5259,7 @@ }, { "file": "modules/View.js", - "line": 754, + "line": 764, "description": "Initializes the behaviors", "itemtype": "method", "name": "__initializeBehaviors", @@ -5259,7 +5268,7 @@ }, { "file": "modules/View.js", - "line": 798, + "line": 808, "description": "If the view is attaching during the render process, then it replaces the injection site\nwith the view's element after the view has generated its DOM.", "itemtype": "method", "name": "__performPendingAttach", @@ -5270,7 +5279,7 @@ }, { "file": "modules/View.js", - "line": 810, + "line": 820, "description": "Deactivates all tracked views or a subset of them based on the options parameter.", "params": [ { @@ -5304,7 +5313,7 @@ }, { "file": "modules/View.js", - "line": 825, + "line": 835, "description": "Activates all tracked views or a subset of them based on the options parameter.", "params": [ { @@ -5338,7 +5347,7 @@ }, { "file": "modules/View.js", - "line": 840, + "line": 850, "description": "Disposes all child views recursively", "itemtype": "method", "name": "disposeChildViews", @@ -5349,7 +5358,7 @@ }, { "file": "modules/View.js", - "line": 851, + "line": 861, "description": "Will inject a new view into an injection site by using the new view's transitionIn method. If the parent view\npreviously had another view at this injections site, this previous view will be removed with that view's transitionOut.\nIf this method is used within a render, the current views' injection sites will be cached so they can be transitioned out even\nthough they are detached in the process of re-rendering. If no previous view is given and none can be found, the new view is transitioned in regardless.\nIf the previous view is the same as the new view, it is injected normally without transitioning in.\nThe previous view must has used an injection site with the standard \"inject=\" attribute to be found.", "itemtype": "method", "name": "transitionNewViewIntoSite", @@ -5404,7 +5413,7 @@ }, { "file": "modules/View.js", - "line": 902, + "line": 912, "description": "Will transition out previousView at the same time as transitioning in newView.", "itemtype": "method", "name": "__performTwoWayTransition", @@ -5451,7 +5460,7 @@ }, { "file": "modules/View.js", - "line": 937, + "line": 947, "description": "Simliar to this.attachView except it utilizes the new view's transitionIn method instead of just attaching the view.\nThis method is invoked on the parent view to attach a tracked view where the transitionIn method defines how a tracked view is brought onto the page.", "params": [ { @@ -5500,7 +5509,7 @@ }, { "file": "modules/View.js", - "line": 963, + "line": 973, "description": "Gets the hash from id to tracked views. You can limit the subset of views returned based on the options passed in.\nNOTE: returns READ-ONLY snapshots. Updates to the returned cid->view map will not be saved nor will updates to the underlying maps be reflected later in returned objects.\nThis means that you can add \"add\" or \"remove\" tracked view using this method, however you can interact with the views inside the map completely.", "params": [ { @@ -5537,7 +5546,7 @@ }, { "file": "modules/View.js", - "line": 990, + "line": 1000, "description": "Used internally by Torso.View to keep a cache of tracked views and their current injection sites before detaching during render logic.", "access": "private", "tagname": "", @@ -5548,7 +5557,7 @@ }, { "file": "modules/View.js", - "line": 1005, + "line": 1015, "description": "Finds the last view at a given injection site. The view returned must be currently tracked by this view (the parent view).\nWhen used with the render method, it will return the view at a injections site before the render logic detaches all tracked views.", "access": "private", "tagname": "", @@ -5570,7 +5579,7 @@ }, { "file": "modules/View.js", - "line": 1029, + "line": 1039, "description": "Replaces the injection site element passed in using $el.replaceWith OR you can use your own replace method", "itemtype": "method", "name": "__replaceInjectionSite", @@ -5609,7 +5618,7 @@ }, { "file": "modules/View.js", - "line": 1046, + "line": 1056, "description": "Call this method when a view is attached to the DOM. It is recursive to child views, but checks whether each child view is attached.", "itemtype": "method", "name": "__invokeAttached", @@ -5620,7 +5629,7 @@ }, { "file": "modules/View.js", - "line": 1065, + "line": 1075, "description": "Call this method when a view is detached from the DOM. It is recursive to child views.", "itemtype": "method", "name": "__invokeDetached", @@ -5629,7 +5638,7 @@ }, { "file": "modules/View.js", - "line": 1083, + "line": 1093, "description": "Generates callbacks for changes in feedback cell fields\n'change fullName' -> invokes all the jQuery (or $) methods on the element as stored by the feedback cell\nIf feedbackCell.get('fullName') returns:\n{ text: 'my text',\n attr: {class: 'newClass'}\n hide: [100, function() {...}]\n...}\nThen it will invoke $element.text('my text'), $element.attr({class: 'newClass'}), etc.", "access": "private", "tagname": "", @@ -5640,7 +5649,7 @@ }, { "file": "modules/View.js", - "line": 1130, + "line": 1140, "description": "Processes the result of the then method. Adds to the feedback cell.", "params": [ { @@ -5663,7 +5672,7 @@ }, { "file": "modules/View.js", - "line": 1143, + "line": 1153, "description": "Creates the \"when\" bindings, and collates and invokes the \"then\" methods for all feedbacks\nFinds all feedback zones that match the \"to\" field, and binds the \"when\" events to invoke the \"then\" method", "access": "private", "tagname": "", @@ -5674,7 +5683,7 @@ }, { "file": "modules/View.js", - "line": 1252, + "line": 1262, "description": "Returns a properly wrapped \"then\" using a configuration object \"bindInfo\" and an \"eventKey\" that will be passed as the type", "params": [ { @@ -5711,7 +5720,7 @@ }, { "file": "modules/View.js", - "line": 1275, + "line": 1285, "description": "Returns all elements on the page that match the feedback mapping\nIf dest is: my-feedback-foo[x][y] then it will find all elements that match: data-feedback=\"my-feedback-foo[*][*]\"", "params": [ { @@ -5733,7 +5742,7 @@ }, { "file": "modules/View.js", - "line": 1298, + "line": 1308, "description": "Generates the events needed to listen to the feedback's when methods. A when event is only created\nif the appropriate element exist on the page", "params": [ { @@ -5757,7 +5766,7 @@ }, { "file": "modules/View.js", - "line": 1338, + "line": 1348, "description": "Returns an array of all the values and variables used within the array notations in a string\nExample: foo.bar[x].baz[0][1].taz[y] will return ['x', 0, 1, 'y']. It will parse integers if they are numbers\nThis does not handle or return any \"open\" array notations: []", "access": "private", "tagname": "", @@ -5768,7 +5777,7 @@ }, { "file": "modules/View.js", - "line": 1357, + "line": 1367, "description": "Replaces all array notations with open array notations.\nExample: foo.bar[x].baz[0][1].taz[y] will return as foo.bar[].baz[][].taz[]", "access": "private", "tagname": "", @@ -5779,7 +5788,7 @@ }, { "file": "modules/View.js", - "line": 1370, + "line": 1380, "description": "Takes a map from variable name to value to be replaced and processes a string with them.\nExample: foo.bar[x].baz[0][1].taz[y] and {x: 5, y: 9} will return as foo.bar[5].baz[0][1].taz[9]", "access": "private", "tagname": "", @@ -5790,7 +5799,7 @@ }, { "file": "modules/View.js", - "line": 1388, + "line": 1398, "description": "Generates an array of all the possible field accessors and their indices when using\nthe \"open\" array notation:\n foo[] -> ['foo[0]', 'foo[1]'].\nWill also perform nested arrays:\n foo[][] -> ['foo[0][0]', foo[1][0]']", "itemtype": "method", "name": "__generateSubAttributes", diff --git a/docs/js/files/modules_View.js.html b/docs/js/files/modules_View.js.html index a4c1d78b..511db5cf 100644 --- a/docs/js/files/modules_View.js.html +++ b/docs/js/files/modules_View.js.html @@ -290,6 +290,16 @@

    File: modules/View.js

    }); }, + /** + * Renders the view only if it is active and part of the DOM. + * @method renderIfAttached + */ + renderIfAttached: function() { + if (this.isActive() && this.isAttached()) { + this.render(); + } + }, + /** * Hook during render that is invoked before any DOM rendering is performed. * This method can be overwritten as usual OR extended using <baseClass>.prototype.prerender.apply(this, arguments); diff --git a/modules/View.js b/modules/View.js index 19f98521..87845dc2 100644 --- a/modules/View.js +++ b/modules/View.js @@ -182,6 +182,16 @@ }); }, + /** + * Renders the view only if it is active and part of the DOM. + * @method renderIfAttached + */ + renderIfAttached: function() { + if (this.isActive() && this.isAttached()) { + this.render(); + } + }, + /** * Hook during render that is invoked before any DOM rendering is performed. * This method can be overwritten as usual OR extended using .prototype.prerender.apply(this, arguments); diff --git a/torso-bundle.js b/torso-bundle.js index bc912ead..922cb368 100644 --- a/torso-bundle.js +++ b/torso-bundle.js @@ -1899,6 +1899,16 @@ }); }, + /** + * Renders the view only if it is active and part of the DOM. + * @method renderIfAttached + */ + renderIfAttached: function() { + if (this.isActive() && this.isAttached()) { + this.render(); + } + }, + /** * Hook during render that is invoked before any DOM rendering is performed. * This method can be overwritten as usual OR extended using .prototype.prerender.apply(this, arguments); diff --git a/torso-bundle.min.js b/torso-bundle.min.js index 65e223ee..a0d3fca3 100644 --- a/torso-bundle.min.js +++ b/torso-bundle.min.js @@ -1,3 +1,3 @@ -!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,d=r.hash?r.hash.value:void 0,c=e.helpers.injectFieldIndices(n,r.hash),u="";for(s=s.split(","),o=0;o0)for(var s=0;s'),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],d="@"===r.charAt(0);"on"===r&&"listenTo"===r||(d&&(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;d&&(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},c=function(t,i,n){var s,r,o,a,d=t.indexOf("[]");if(e.isEmpty(n)&&(n=[]),d===-1)return{attr:t,index:n};s=t.substring(0,d),r=t.substring(d+2),o=[];var u=i.get(s);return e.each(u,function(e,t){a=n.slice(),a.push(t),o.push(c(s+"["+t+"]"+r,i,a))}),o},h=function(e){return t&&e instanceof t},l=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,d;return e.isArray(i)?e.reduce(i,function(e,i){return e.push(p(t,i,n,s,r,o+1)),e},[]):(d=i.index,a=i.attr,e.isUndefined(n)&&l(a)&&(n=t.get(a)),_(r,t,n,a,s,d))},_=function(t,i,s,r,o,a){return e.reduce(t,function(t,d){var c=e.extend({msgKey:d.msgKey},n,u),h=d.fn.call(c,s,r,d.val,i,o,a);return h!==!1&&t!==!1&&(h&&!t?e.result(e.extend({},d,n,u),"msg")||h:t)},"")},v=function(t,i,n,s){var r,o,d,u=a(t,i);return o=c(i,t),d=p(t,o,n,s,u,0),e.isArray(d)&&(r=e.reduce(e.flatten(d),function(e,t){return e||t},!1),!r)?"":d},g=function(t,i,n){var s,r={},o=!0,a=e.clone(i);return e.each(n,function(e,i){s=v(t,i,e,a),s&&(r[i]=s,o=!1)}),{invalidAttrs:r,isValid:o}},m=function(t,i,n){var s,r,o=t.validation?e.result(t,"validation")||{}:{};return e.contains(e.keys(o),n)?v(t,n,i,e.extend({},t.attributes)):(s=d(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)&&h(this)&&(i=this.get(t)),m(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=h(this)?this.get(e):s(this.attributes)[e],r=m(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,d=e.extend({},t,n),c=r(a,o(t)),u=e.extend({},c,a.attributes,i),h=e.extend(s(u),i),l=i?s(i):h,f=g(a,u,e.pick(h,e.keys(c)));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)}),!d.forceUpdate&&e.intersection(e.keys(f.invalidAttrs),e.keys(l)).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"},d=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]||d.sentenceCase(e,t)}},c=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,d){var c=e.isFunction(n)?n.call(o,t,i,d):n;return!(!c&&!s(t))&&(c&&!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,models: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.trackModels(n,s):this.trackModel(t,n,s))},setMappings:function(t,i,n){e.each(t,function(e,t){this.setMapping(t,e)},this),i&&this.trackModels(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.untrackModel(s)},unsetMappings:function(){this.__currentMappings={},this.resetUpdating()},getTrackedModel:function(e){return this.__currentObjectModels[e]},getTrackedModels:function(){return e.values(this.__currentObjectModels)},setTrackedModel:function(){this.trackModel.apply(this,arguments)},trackModel: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(){this.trackModels.apply(this,arguments)},trackModels:function(t,i){e.each(t,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(){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(d){}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){d[s.cid]={success:u,response:n},a+o===h&&(a>0?(i.rollback&&e.each(r.getTrackedModels(),function(e){e.set(c[e.cid]),d[e.cid].success&&e.save()}),r.trigger("save-fail",d),t.reject(d)):(r.trigger("save-success",d),t.resolve(d)))}var s,r=this,o=0,a=0,d={},c={},u=r.getTrackedModels(),h=u.length;if(!i.force&&(s=r.checkIfModelsAreStale(),s.length>0))throw{name:"Stale data",staleModels:s};e.each(u,function(e){c[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,s=e.result(this,"mapping"),r=e.result(this,"models");i=t.mapping||s,n=t.models||r,i&&this.setMappings(i,n)},__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),d={};a?(r?e.each(r,function(e){d[e]=t.__cloneVal(a.get(e))}):d=t.__cloneVal(modelConfig.model.attributes),o[i]=d):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,d,c;c=function(e){e.__delayedRenderTimeout&&(clearTimeout(e.__delayedRenderTimeout),e.__delayedRenderTimeout=null,e.isDisposed()||e.render())},d=function(e,t){var i=function(){t.__delayedRenderTimeout=null,t.isDisposed()||t.render()};return function(){!t.__delayedRenderTimeout&&e>0?t.__delayedRenderTimeout=setTimeout(i,e):e<=0&&!t.isDisposed()&&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()?(c(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,this.itemContainer=e.itemContainer||this.itemContainer,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,this.__modelToViewMap={},this.__renderWait=e.renderWait||this.__renderWait,this.__modelId=e.modelId||this.modelId||"cid",this.__modelName=e.modelName||this.modelName||"model",this.__orderedModelIdList=[],this.__createItemViews(),this.__delayedRender=d(this.__renderWait,this),t&&this.setCollection(t,!0),this.on("render:after-dom-update",this.__cleanupItemViewsAfterAttachedToParent)},setCollection:function(e,t){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),t||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),d=e.size(this.__orderedModelIdList),c=a===d;if(!c)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),d=r-a+o,c=o+a,u=c/Math.max(d,1),h=!r&&o,l=r&&r===a&&!o,f=this.updateThreshold||.5,p=u>=f;return c<=0?this.reorder():(t=h||l||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},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,d=this,c=e.size(i),u=(e.size(n),e.size(s));d.itemContainer&&c&&c==u&&(o=t(""),e.first(i).$el.before(o)),d.__removeStaleItemViews(s),e.each(n,function(t,i){if(0===t.indexOfModel){var n;if(d.itemContainer)if(o)n=e.bind(o.replaceWith,o);else{var c=e.indexBy(s,"modelId"),u=e.find(d.__orderedModelIdList,function(e){return!c[e]});r=d.getTrackedView(d.__modelToViewMap[u]),n=e.bind(r.$el.prepend,r.$el)}else n=e.bind(d.$el.prepend,d.$el);d.attachView(null,t.view,{replaceMethod:n,discardInjectionSite:!0})}else a.call(d,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){if("function"==typeof define&&define.amd)define(["underscore","jquery","../Behavior","../Collection","../Events"],t);else if("object"==typeof exports){var i=require("underscore"),n=require("jquery"),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.$,e.Torso.Behavior,e.Torso.Collection,e.Torso.Events)}(this,function(e,t,i,n,s){"use strict";function r(t){return e.isArray(t)?(t=e.flatten(t),e.uniq(t)):e.isString(t)||e.isNumber(t)?[t]:t&&t.skipObjectRetrieval?t:void 0}function o(t){return(e.isUndefined(t)||e.isNull(t))&&(t=[]),t}function a(t,i){i=i.replace(/\[(\w+)\]/g,".$1"),i=i.replace(/^\./,"");var n=i.split(c);return e.reduce(n,function(t,i){return e.isUndefined(t)?void 0:t[i]},t)}function d(e){return!!e&&e.indexOf(u)>-1}var c=".",u=":",h={SUCCESS:"success",FAILURE:"failed"},l=i.extend({cache:void 0,renderOnFetch:!1,skipInitialLoad:!1,returnSingleResult:!1,alwaysFetch:!1,ids:void 0,updateEvents:void 0,data:void 0,FETCHED_STATUSES:h,constructor:function(t,n,s){e.bindAll(this,"__skipRetrieveOnEmptyTrackedIdsAndNewIds","__completeLoadingIds","__fetchSuccess","__fetchFailed"),n=n||{},n=e.defaults(n,{alwaysFetch:!1}),e.extend(this,e.pick(n,"cache","id","ids","renderOnFetch","skipInitialLoad","returnSingleResult","alwaysFetch","updateEvents")),this.__validateCache(),this.__normalizeAndValidateIds(),this.__normalizeAndValidateUpdateEvents(),this.cid=this.cid||e.uniqueId(this.cidPrefix),this.data=new this.Data({parentBehavior:this,privateCollection:this.cache.createPrivateCollection(this.cid)}),i.apply(this,arguments),this.set("loadingIds",0),this.on("id-container-updated",this.listenToIdsPropertyChangeEvent),this.on("id-container-updated",this.retrieve),this.listenTo(this.view,"initialize:complete",this.listenToIdsPropertyChangeEvent),this.listenTo(this.view,"initialize:complete",this._delegateUpdateEvents),this.skipInitialLoad||this.listenTo(this.view,"initialize:complete",this.retrieve),this.on("fetched",function(){this.renderOnFetch&&this.view.isActive()&&this.view.isAttached()&&this.view.render()})},retrieve:function(){return this.alwaysFetch?this.fetch():this.pull()},pull:function(){var e=this;return this.__getIds().then(this.__skipRetrieveOnEmptyTrackedIdsAndNewIds).then(function(t){return t&&!t.skipObjectRetrieval?e.data.privateCollection.trackAndPull(t):t},function(e){return e.failedOnIds=!0,e}).then(this.__fetchSuccess,this.__fetchFailed)},fetch:function(){var e=this;return this.__getIds().then(this.__skipRetrieveOnEmptyTrackedIdsAndNewIds).then(function(t){return t&&!t.skipObjectRetrieval?e.data.privateCollection.trackAndFetch(t):t},function(e){return e.failedOnIds=!0,e}).then(this.__fetchSuccess,this.__fetchFailed)},prepare:function(){var e=i.prototype.prepare.apply(this)||{};return e.data=this.data.toJSON(),e.loading=this.isLoading(),e.loadingIds=this.isLoadingIds(),e.loadingObjects=this.isLoadingObjects(),e},isLoading:function(){return this.isLoadingIds()||this.isLoadingObjects()},isLoadingIds:function(){return this.get("loadingIds")>0},isLoadingObjects:function(){return this.data.privateCollection.isLoading()},listenToIdsPropertyChangeEvent:function(){if(!e.isUndefined(this.ids.property)){this.stopListeningToIdsPropertyChangeEvent();var t=this.__parseIdsPropertyNameAndIdContainer(),i=t.idContainer,n=i&&e.isFunction(i.on);n&&(this.__currentContextWithListener=i,this.__currentContextEventName="change:"+t.idsPropertyName,this.listenTo(this.__currentContextWithListener,this.__currentContextEventName,this.retrieve),this.listenTo(this.__currentContextWithListener,"fetched:ids",this.retrieve))}},stopListeningToIdsPropertyChangeEvent:function(){this.__currentContextWithListener&&(this.stopListening(this.__currentContextWithListener,this.__currentContextEventName,this.retrieve),this.stopListening(this.__currentContextWithListener,"fetched:ids",this.retrieve),delete this.__currentContextWithListener,delete this.__currentContextEventName)},_delegateUpdateEvents:function(){this._undelegateUpdateEvents();var t=this.__parseUpdateEvents();e.each(t,function(e){this.listenTo(e.idContainer,e.eventName,this.retrieve)},this)},_undelegateUpdateEvents:function(){var t=this.__parseUpdateEvents();e.each(t,function(e){this.stopListening(e.idContainer,e.eventName,this.retrieve)},this)},__parseUpdateEvents:function(){this.__normalizeAndValidateUpdateEvents();var t=e.flatten(e.map(this.updateEvents,this.__parseUpdateEvent,this));return e.compact(t)},__parseUpdateEvent:function(t){if(!e.isUndefined(t)){var i=[];if(e.isString(t)){var n=this.__parseStringUpdateEvent(t);e.isUndefined(n)||i.push(n)}else e.isObject(t)&&(i=e.map(t,function(e,t){return{idContainer:e,eventName:t}}));return i}},__validateCache:function(){if(!this.cache)throw new Error("Torso Data Behavior constructed without a cache");if(!(this.cache instanceof n))throw new Error("Torso Data Behavior's cache is not of type Torso.Collection")},__normalizeAndValidateIds:function(){if(!e.isUndefined(this.ids)&&!e.isUndefined(this.id))throw new Error("Torso Data Behavior constructed with both id and ids. Please define only one.");this.ids=this.id||this.ids,this.__validateIds()},__validateIds:function(){if(e.isUndefined(this.ids))throw new Error("Torso Data Behavior constructed without a way to identify the ids for this data. Please define either id, ids.");var t=e.isArray(this.ids),i=e.isString(this.ids)||e.isNumber(this.ids),n=e.isFunction(this.ids),s=e.isString(this.ids.property),r=e.isObject(this.ids),o=t||i||n||s;if(!o&&r)throw new Error("Data Behavior ids invalid definition. It is an object, but the property field is not defined or is not a string: "+JSON.stringify(this.ids));if(!o)throw new Error("Data Behavior ids invalid definition. Not a string, number, object, array or function: "+JSON.stringify(this.ids));if(s){var a=d(this.ids.property),c=!e.isUndefined(this.ids.idContainer);if(c&&a)throw new Error("Data Behavior ids invalid definition. Id container defined on both ids.property and ids.idContainer: ",JSON.stringify(this.ids))}},__normalizeAndValidateUpdateEvents:function(){var t=e.isArray(this.updateEvents),i=!t&&(e.isObject(this.updateEvents)||e.isString(this.updateEvents)),n=e.isUndefined(this.updateEvents),s=t||i||n; -if(i&&(this.updateEvents=[this.updateEvents]),!s)throw new Error("Update events are not an array, string or object. Please see parameters for examples of how to define updateEvents. Configured UpdateEvents: ",this.updateEvents);this.updateEvents=e.compact(this.updateEvents),e.each(this.updateEvents,this.__validUpdateEvent)},__validUpdateEvent:function(t){var i=e.isString(t),n=e.isObject(t)&&e.keys(t).length>0;if(!i&&!n)throw new Error("Not a valid updateEvent configuration. Update events need to either be strings or objects with a single property: "+JSON.stringify(t))},__getIds:function(){this.set("loadingIds",this.get("loadingIds")+1),this.__validateIds();var i=t.Deferred(),n=this.ids,s=r(n);if(e.isUndefined(s)){if(e.isFunction(this.ids))n=this.ids(this.cache),s=r(n),e.isUndefined(s)?n&&e.isFunction(n.then)?i=n.then(r):i.resolve([]):i.resolve(s);else if(!e.isUndefined(this.ids.property)){var d=this.__parseIdsPropertyNameAndIdContainer(),c=d.idsPropertyName,u=d.idContainer;n=a(u,c);var h=u&&e.isUndefined(n),l=u&&e.isFunction(u.get);h&&l&&(n=u.get(c)),s=r(n),i.resolve(s)}}else i.resolve(s);return i.promise().then(o).always(this.__completeLoadingIds)},__completeLoadingIds:function(){this.set("loadingIds",this.get("loadingIds")-1)},__parseIdsPropertyNameAndIdContainer:function(){var t,i=this.ids.property,n=d(i),s=!e.isUndefined(this.ids.idContainer);if(s&&(t=this.__parseIdContainer()),n){var r=this.__parseContainerDetailString(i);i=r.detail,t=r.idContainer}return e.isUndefined(t)&&(t=this.view),{idsPropertyName:i,idContainer:t}},__parseIdContainer:function(){var t,i=this.ids.idContainer;if(e.isUndefined(i))t=void 0;else if(e.isFunction(i)){var n=e.bind(i,this);t=n()}else{if(!e.isObject(i))throw new Error("Invalid idContainer. Not an object or function: "+JSON.stringify(this.ids));t=i}return t},__parseContainerDetailString:function(e){var t="";d(e)&&(t=e.split(u,1)[0]);var i,n=t.split(c),s=n[0];if("this"===s)i=this;else if("behaviors"===s||"behavior"===s){var r=n[1];s+=c+r,i=this.view.getBehavior(r)}else"view"!==s&&(s=""),i=this.view;var o=i,h=t.replace(s,"");h&&(h[0]===c&&(h=h.slice(1)),o=a(i,h));var l=e.replace(t+u,"");return{detail:l,idContainer:o}},__parseStringUpdateEvent:function(e){var t=this.__parseContainerDetailString(e);if(t)return{idContainer:t.idContainer,eventName:t.detail}},__fetchSuccess:function(e){return this.set("fetchSuccess",!0),this.__shouldTriggerFetchedEvent(e)&&(this.trigger("fetched",{status:h.SUCCESS,response:e}),this.data.trigger("fetched",{status:h.SUCCESS,response:e})),this.trigger("fetched:ids"),this.data.trigger("fetched:ids"),e},__fetchFailed:function(e){return this.set("fetchSuccess",!1),this.__shouldTriggerFetchedEvent(e)&&(this.trigger("fetched",{status:h.FAILURE,response:e}),this.data.trigger("fetched",{status:h.FAILURE,response:e}),e.emptyIds&&(this.__firstEmptyFetchedTriggered=!0)),this.trigger("fetched:ids"),this.data.trigger("fetched:ids"),e},__shouldTriggerFetchedEvent:function(e){return!e||!e.skipObjectRetrieval||e.forceFetchedEvent},__skipRetrieveOnEmptyTrackedIdsAndNewIds:function(t){return e.isEmpty(t)&&e.isEmpty(this.data.privateCollection.getTrackedIds())?{skipObjectRetrieval:!0,forceFetchedEvent:!0}:t},_activate:function(){this.listenToIdsPropertyChangeEvent(),this._delegateUpdateEvents(),this.data.activate()},_deactivate:function(){this.stopListeningToIdsPropertyChangeEvent(),this._undelegateUpdateEvents(),this.data.deactivate()},_dispose:function(){this.data.dispose(),this.off(),this.stopListening()}}),f=function(e){this.initialize(e)};return e.extend(f.prototype,s,{initialize:function(e){this.parentBehavior=e.parentBehavior,this.privateCollection=e.privateCollection},isLoading:function(){return this.parentBehavior.isLoading()},isLoadingIds:function(){return this.parentBehavior.isLoadingIds()},isLoadingObjects:function(){return this.parentBehavior.isLoadingObjects()},toJSON:function(){var e=this.privateCollection;if(!this.parentBehavior.returnSingleResult)return e.toJSON();if(0!==e.length){if(1===e.length){var t=e.at(0);return t.toJSON()}throw new Error("Multiple results found, but single result expected: "+JSON.stringify(e.toJSON()))}},get:function(t){var i=this.privateCollection;if(!this.parentBehavior.returnSingleResult)return e.isString(t)?i.pluck(t):i.toJSON();var n=this.getModel();return n?e.isString(t)?n.get(t):n.toJSON():void 0},getModel:function(t){var i=this.privateCollection;if(!this.parentBehavior.returnSingleResult&&e.isUndefined(t))throw new Error("data.getModel() of a DataBehavior is only valid if the behavior is set to returnSingleResult === true");if(!e.isUndefined(t))return i.get(t);if(0!==i.length){if(1===i.length)return i.at(0);throw new Error("Multiple results found, but single result expected: "+JSON.stringify(i.toJSON()))}},getModels:function(){return this.privateCollection.models.slice(0)},activate:function(){this.listenTo(this.privateCollection,"all",this.trigger)},deactivate:function(){this.stopListening(this.privateCollection,"all",this.trigger)},dispose:function(){this.off(),this.stopListening()}}),l.prototype.Data=f,l.FETCHED_STATUSES=h,l}),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||{};var s=t.FormModelClass||this.FormModelClass||n;this.model=t.model||this.model||new s,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(){var t=i.prototype.prepare.apply(this);return t.formErrors=0!==e.size(this._errors)?this._errors:null,t.formSuccess=this._success,t},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);t(e).is("select")&&(r.selectOptions=i.__generateSelectOptions(e,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}}},__generateSelectOptions:function(i,n){var s=[],r=t(i).children("option");return e.each(r,function(e){s.push({label:t(e).text(),value:n.modelFormat?n.modelFormat.apply(this,[t(e).val()]):t(e).val()})}),{collection:s,labelPath:"label",valuePath:"value"}}});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,d=r.hash?r.hash.value:void 0,c=e.helpers.injectFieldIndices(n,r.hash),u="";for(s=s.split(","),o=0;o0)for(var s=0;s'),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],d="@"===r.charAt(0);"on"===r&&"listenTo"===r||(d&&(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;d&&(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},c=function(t,i,n){var s,r,o,a,d=t.indexOf("[]");if(e.isEmpty(n)&&(n=[]),d===-1)return{attr:t,index:n};s=t.substring(0,d),r=t.substring(d+2),o=[];var u=i.get(s);return e.each(u,function(e,t){a=n.slice(),a.push(t),o.push(c(s+"["+t+"]"+r,i,a))}),o},h=function(e){return t&&e instanceof t},l=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,d;return e.isArray(i)?e.reduce(i,function(e,i){return e.push(p(t,i,n,s,r,o+1)),e},[]):(d=i.index,a=i.attr,e.isUndefined(n)&&l(a)&&(n=t.get(a)),_(r,t,n,a,s,d))},_=function(t,i,s,r,o,a){return e.reduce(t,function(t,d){var c=e.extend({msgKey:d.msgKey},n,u),h=d.fn.call(c,s,r,d.val,i,o,a);return h!==!1&&t!==!1&&(h&&!t?e.result(e.extend({},d,n,u),"msg")||h:t)},"")},v=function(t,i,n,s){var r,o,d,u=a(t,i);return o=c(i,t),d=p(t,o,n,s,u,0),e.isArray(d)&&(r=e.reduce(e.flatten(d),function(e,t){return e||t},!1),!r)?"":d},g=function(t,i,n){var s,r={},o=!0,a=e.clone(i);return e.each(n,function(e,i){s=v(t,i,e,a),s&&(r[i]=s,o=!1)}),{invalidAttrs:r,isValid:o}},m=function(t,i,n){var s,r,o=t.validation?e.result(t,"validation")||{}:{};return e.contains(e.keys(o),n)?v(t,n,i,e.extend({},t.attributes)):(s=d(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)&&h(this)&&(i=this.get(t)),m(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=h(this)?this.get(e):s(this.attributes)[e],r=m(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,d=e.extend({},t,n),c=r(a,o(t)),u=e.extend({},c,a.attributes,i),h=e.extend(s(u),i),l=i?s(i):h,f=g(a,u,e.pick(h,e.keys(c)));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)}),!d.forceUpdate&&e.intersection(e.keys(f.invalidAttrs),e.keys(l)).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"},d=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]||d.sentenceCase(e,t)}},c=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,d){var c=e.isFunction(n)?n.call(o,t,i,d):n;return!(!c&&!s(t))&&(c&&!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,models: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.trackModels(n,s):this.trackModel(t,n,s))},setMappings:function(t,i,n){e.each(t,function(e,t){this.setMapping(t,e)},this),i&&this.trackModels(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.untrackModel(s)},unsetMappings:function(){this.__currentMappings={},this.resetUpdating()},getTrackedModel:function(e){return this.__currentObjectModels[e]},getTrackedModels:function(){return e.values(this.__currentObjectModels)},setTrackedModel:function(){this.trackModel.apply(this,arguments)},trackModel: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(){this.trackModels.apply(this,arguments)},trackModels:function(t,i){e.each(t,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(){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(d){}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){d[s.cid]={success:u,response:n},a+o===h&&(a>0?(i.rollback&&e.each(r.getTrackedModels(),function(e){e.set(c[e.cid]),d[e.cid].success&&e.save()}),r.trigger("save-fail",d),t.reject(d)):(r.trigger("save-success",d),t.resolve(d)))}var s,r=this,o=0,a=0,d={},c={},u=r.getTrackedModels(),h=u.length;if(!i.force&&(s=r.checkIfModelsAreStale(),s.length>0))throw{name:"Stale data",staleModels:s};e.each(u,function(e){c[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,s=e.result(this,"mapping"),r=e.result(this,"models");i=t.mapping||s,n=t.models||r,i&&this.setMappings(i,n)},__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),d={};a?(r?e.each(r,function(e){d[e]=t.__cloneVal(a.get(e))}):d=t.__cloneVal(modelConfig.model.attributes),o[i]=d):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,d,c;c=function(e){e.__delayedRenderTimeout&&(clearTimeout(e.__delayedRenderTimeout),e.__delayedRenderTimeout=null,e.isDisposed()||e.render())},d=function(e,t){var i=function(){t.__delayedRenderTimeout=null,t.isDisposed()||t.render()};return function(){!t.__delayedRenderTimeout&&e>0?t.__delayedRenderTimeout=setTimeout(i,e):e<=0&&!t.isDisposed()&&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()?(c(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,this.itemContainer=e.itemContainer||this.itemContainer,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,this.__modelToViewMap={},this.__renderWait=e.renderWait||this.__renderWait,this.__modelId=e.modelId||this.modelId||"cid",this.__modelName=e.modelName||this.modelName||"model",this.__orderedModelIdList=[],this.__createItemViews(),this.__delayedRender=d(this.__renderWait,this),t&&this.setCollection(t,!0),this.on("render:after-dom-update",this.__cleanupItemViewsAfterAttachedToParent)},setCollection:function(e,t){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),t||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),d=e.size(this.__orderedModelIdList),c=a===d;if(!c)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),d=r-a+o,c=o+a,u=c/Math.max(d,1),h=!r&&o,l=r&&r===a&&!o,f=this.updateThreshold||.5,p=u>=f;return c<=0?this.reorder():(t=h||l||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},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,d=this,c=e.size(i),u=(e.size(n),e.size(s));d.itemContainer&&c&&c==u&&(o=t(""),e.first(i).$el.before(o)),d.__removeStaleItemViews(s),e.each(n,function(t,i){if(0===t.indexOfModel){var n;if(d.itemContainer)if(o)n=e.bind(o.replaceWith,o);else{var c=e.indexBy(s,"modelId"),u=e.find(d.__orderedModelIdList,function(e){return!c[e]});r=d.getTrackedView(d.__modelToViewMap[u]),n=e.bind(r.$el.prepend,r.$el)}else n=e.bind(d.$el.prepend,d.$el);d.attachView(null,t.view,{replaceMethod:n,discardInjectionSite:!0})}else a.call(d,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){if("function"==typeof define&&define.amd)define(["underscore","jquery","../Behavior","../Collection","../Events"],t);else if("object"==typeof exports){var i=require("underscore"),n=require("jquery"),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.$,e.Torso.Behavior,e.Torso.Collection,e.Torso.Events)}(this,function(e,t,i,n,s){"use strict";function r(t){return e.isArray(t)?(t=e.flatten(t),e.uniq(t)):e.isString(t)||e.isNumber(t)?[t]:t&&t.skipObjectRetrieval?t:void 0}function o(t){return(e.isUndefined(t)||e.isNull(t))&&(t=[]),t}function a(t,i){i=i.replace(/\[(\w+)\]/g,".$1"),i=i.replace(/^\./,"");var n=i.split(c);return e.reduce(n,function(t,i){return e.isUndefined(t)?void 0:t[i]},t)}function d(e){return!!e&&e.indexOf(u)>-1}var c=".",u=":",h={SUCCESS:"success",FAILURE:"failed"},l=i.extend({cache:void 0,renderOnFetch:!1,skipInitialLoad:!1,returnSingleResult:!1,alwaysFetch:!1,ids:void 0,updateEvents:void 0,data:void 0,FETCHED_STATUSES:h,constructor:function(t,n,s){e.bindAll(this,"__skipRetrieveOnEmptyTrackedIdsAndNewIds","__completeLoadingIds","__fetchSuccess","__fetchFailed"),n=n||{},n=e.defaults(n,{alwaysFetch:!1}),e.extend(this,e.pick(n,"cache","id","ids","renderOnFetch","skipInitialLoad","returnSingleResult","alwaysFetch","updateEvents")),this.__validateCache(),this.__normalizeAndValidateIds(),this.__normalizeAndValidateUpdateEvents(),this.cid=this.cid||e.uniqueId(this.cidPrefix),this.data=new this.Data({parentBehavior:this,privateCollection:this.cache.createPrivateCollection(this.cid)}),i.apply(this,arguments),this.set("loadingIds",0),this.on("id-container-updated",this.listenToIdsPropertyChangeEvent),this.on("id-container-updated",this.retrieve),this.listenTo(this.view,"initialize:complete",this.listenToIdsPropertyChangeEvent),this.listenTo(this.view,"initialize:complete",this._delegateUpdateEvents),this.skipInitialLoad||this.listenTo(this.view,"initialize:complete",this.retrieve),this.on("fetched",function(){this.renderOnFetch&&this.view.isActive()&&this.view.isAttached()&&this.view.render()})},retrieve:function(){return this.alwaysFetch?this.fetch():this.pull()},pull:function(){var e=this;return this.__getIds().then(this.__skipRetrieveOnEmptyTrackedIdsAndNewIds).then(function(t){return t&&!t.skipObjectRetrieval?e.data.privateCollection.trackAndPull(t):t},function(e){return e.failedOnIds=!0,e}).then(this.__fetchSuccess,this.__fetchFailed)},fetch:function(){var e=this;return this.__getIds().then(this.__skipRetrieveOnEmptyTrackedIdsAndNewIds).then(function(t){return t&&!t.skipObjectRetrieval?e.data.privateCollection.trackAndFetch(t):t},function(e){return e.failedOnIds=!0,e}).then(this.__fetchSuccess,this.__fetchFailed)},prepare:function(){var e=i.prototype.prepare.apply(this)||{};return e.data=this.data.toJSON(),e.loading=this.isLoading(),e.loadingIds=this.isLoadingIds(),e.loadingObjects=this.isLoadingObjects(),e},isLoading:function(){return this.isLoadingIds()||this.isLoadingObjects()},isLoadingIds:function(){return this.get("loadingIds")>0},isLoadingObjects:function(){return this.data.privateCollection.isLoading()},listenToIdsPropertyChangeEvent:function(){if(!e.isUndefined(this.ids.property)){this.stopListeningToIdsPropertyChangeEvent();var t=this.__parseIdsPropertyNameAndIdContainer(),i=t.idContainer,n=i&&e.isFunction(i.on);n&&(this.__currentContextWithListener=i,this.__currentContextEventName="change:"+t.idsPropertyName,this.listenTo(this.__currentContextWithListener,this.__currentContextEventName,this.retrieve),this.listenTo(this.__currentContextWithListener,"fetched:ids",this.retrieve))}},stopListeningToIdsPropertyChangeEvent:function(){this.__currentContextWithListener&&(this.stopListening(this.__currentContextWithListener,this.__currentContextEventName,this.retrieve),this.stopListening(this.__currentContextWithListener,"fetched:ids",this.retrieve),delete this.__currentContextWithListener,delete this.__currentContextEventName)},_delegateUpdateEvents:function(){this._undelegateUpdateEvents();var t=this.__parseUpdateEvents();e.each(t,function(e){this.listenTo(e.idContainer,e.eventName,this.retrieve)},this)},_undelegateUpdateEvents:function(){var t=this.__parseUpdateEvents();e.each(t,function(e){this.stopListening(e.idContainer,e.eventName,this.retrieve)},this)},__parseUpdateEvents:function(){this.__normalizeAndValidateUpdateEvents();var t=e.flatten(e.map(this.updateEvents,this.__parseUpdateEvent,this));return e.compact(t)},__parseUpdateEvent:function(t){if(!e.isUndefined(t)){var i=[];if(e.isString(t)){var n=this.__parseStringUpdateEvent(t);e.isUndefined(n)||i.push(n)}else e.isObject(t)&&(i=e.map(t,function(e,t){return{idContainer:e,eventName:t}}));return i}},__validateCache:function(){if(!this.cache)throw new Error("Torso Data Behavior constructed without a cache");if(!(this.cache instanceof n))throw new Error("Torso Data Behavior's cache is not of type Torso.Collection")},__normalizeAndValidateIds:function(){if(!e.isUndefined(this.ids)&&!e.isUndefined(this.id))throw new Error("Torso Data Behavior constructed with both id and ids. Please define only one.");this.ids=this.id||this.ids,this.__validateIds()},__validateIds:function(){if(e.isUndefined(this.ids))throw new Error("Torso Data Behavior constructed without a way to identify the ids for this data. Please define either id, ids.");var t=e.isArray(this.ids),i=e.isString(this.ids)||e.isNumber(this.ids),n=e.isFunction(this.ids),s=e.isString(this.ids.property),r=e.isObject(this.ids),o=t||i||n||s;if(!o&&r)throw new Error("Data Behavior ids invalid definition. It is an object, but the property field is not defined or is not a string: "+JSON.stringify(this.ids));if(!o)throw new Error("Data Behavior ids invalid definition. Not a string, number, object, array or function: "+JSON.stringify(this.ids));if(s){var a=d(this.ids.property),c=!e.isUndefined(this.ids.idContainer);if(c&&a)throw new Error("Data Behavior ids invalid definition. Id container defined on both ids.property and ids.idContainer: ",JSON.stringify(this.ids))}},__normalizeAndValidateUpdateEvents:function(){ +var t=e.isArray(this.updateEvents),i=!t&&(e.isObject(this.updateEvents)||e.isString(this.updateEvents)),n=e.isUndefined(this.updateEvents),s=t||i||n;if(i&&(this.updateEvents=[this.updateEvents]),!s)throw new Error("Update events are not an array, string or object. Please see parameters for examples of how to define updateEvents. Configured UpdateEvents: ",this.updateEvents);this.updateEvents=e.compact(this.updateEvents),e.each(this.updateEvents,this.__validUpdateEvent)},__validUpdateEvent:function(t){var i=e.isString(t),n=e.isObject(t)&&e.keys(t).length>0;if(!i&&!n)throw new Error("Not a valid updateEvent configuration. Update events need to either be strings or objects with a single property: "+JSON.stringify(t))},__getIds:function(){this.set("loadingIds",this.get("loadingIds")+1),this.__validateIds();var i=t.Deferred(),n=this.ids,s=r(n);if(e.isUndefined(s)){if(e.isFunction(this.ids))n=this.ids(this.cache),s=r(n),e.isUndefined(s)?n&&e.isFunction(n.then)?i=n.then(r):i.resolve([]):i.resolve(s);else if(!e.isUndefined(this.ids.property)){var d=this.__parseIdsPropertyNameAndIdContainer(),c=d.idsPropertyName,u=d.idContainer;n=a(u,c);var h=u&&e.isUndefined(n),l=u&&e.isFunction(u.get);h&&l&&(n=u.get(c)),s=r(n),i.resolve(s)}}else i.resolve(s);return i.promise().then(o).always(this.__completeLoadingIds)},__completeLoadingIds:function(){this.set("loadingIds",this.get("loadingIds")-1)},__parseIdsPropertyNameAndIdContainer:function(){var t,i=this.ids.property,n=d(i),s=!e.isUndefined(this.ids.idContainer);if(s&&(t=this.__parseIdContainer()),n){var r=this.__parseContainerDetailString(i);i=r.detail,t=r.idContainer}return e.isUndefined(t)&&(t=this.view),{idsPropertyName:i,idContainer:t}},__parseIdContainer:function(){var t,i=this.ids.idContainer;if(e.isUndefined(i))t=void 0;else if(e.isFunction(i)){var n=e.bind(i,this);t=n()}else{if(!e.isObject(i))throw new Error("Invalid idContainer. Not an object or function: "+JSON.stringify(this.ids));t=i}return t},__parseContainerDetailString:function(e){var t="";d(e)&&(t=e.split(u,1)[0]);var i,n=t.split(c),s=n[0];if("this"===s)i=this;else if("behaviors"===s||"behavior"===s){var r=n[1];s+=c+r,i=this.view.getBehavior(r)}else"view"!==s&&(s=""),i=this.view;var o=i,h=t.replace(s,"");h&&(h[0]===c&&(h=h.slice(1)),o=a(i,h));var l=e.replace(t+u,"");return{detail:l,idContainer:o}},__parseStringUpdateEvent:function(e){var t=this.__parseContainerDetailString(e);if(t)return{idContainer:t.idContainer,eventName:t.detail}},__fetchSuccess:function(e){return this.set("fetchSuccess",!0),this.__shouldTriggerFetchedEvent(e)&&(this.trigger("fetched",{status:h.SUCCESS,response:e}),this.data.trigger("fetched",{status:h.SUCCESS,response:e})),this.trigger("fetched:ids"),this.data.trigger("fetched:ids"),e},__fetchFailed:function(e){return this.set("fetchSuccess",!1),this.__shouldTriggerFetchedEvent(e)&&(this.trigger("fetched",{status:h.FAILURE,response:e}),this.data.trigger("fetched",{status:h.FAILURE,response:e}),e.emptyIds&&(this.__firstEmptyFetchedTriggered=!0)),this.trigger("fetched:ids"),this.data.trigger("fetched:ids"),e},__shouldTriggerFetchedEvent:function(e){return!e||!e.skipObjectRetrieval||e.forceFetchedEvent},__skipRetrieveOnEmptyTrackedIdsAndNewIds:function(t){return e.isEmpty(t)&&e.isEmpty(this.data.privateCollection.getTrackedIds())?{skipObjectRetrieval:!0,forceFetchedEvent:!0}:t},_activate:function(){this.listenToIdsPropertyChangeEvent(),this._delegateUpdateEvents(),this.data.activate()},_deactivate:function(){this.stopListeningToIdsPropertyChangeEvent(),this._undelegateUpdateEvents(),this.data.deactivate()},_dispose:function(){this.data.dispose(),this.off(),this.stopListening()}}),f=function(e){this.initialize(e)};return e.extend(f.prototype,s,{initialize:function(e){this.parentBehavior=e.parentBehavior,this.privateCollection=e.privateCollection},isLoading:function(){return this.parentBehavior.isLoading()},isLoadingIds:function(){return this.parentBehavior.isLoadingIds()},isLoadingObjects:function(){return this.parentBehavior.isLoadingObjects()},toJSON:function(){var e=this.privateCollection;if(!this.parentBehavior.returnSingleResult)return e.toJSON();if(0!==e.length){if(1===e.length){var t=e.at(0);return t.toJSON()}throw new Error("Multiple results found, but single result expected: "+JSON.stringify(e.toJSON()))}},get:function(t){var i=this.privateCollection;if(!this.parentBehavior.returnSingleResult)return e.isString(t)?i.pluck(t):i.toJSON();var n=this.getModel();return n?e.isString(t)?n.get(t):n.toJSON():void 0},getModel:function(t){var i=this.privateCollection;if(!this.parentBehavior.returnSingleResult&&e.isUndefined(t))throw new Error("data.getModel() of a DataBehavior is only valid if the behavior is set to returnSingleResult === true");if(!e.isUndefined(t))return i.get(t);if(0!==i.length){if(1===i.length)return i.at(0);throw new Error("Multiple results found, but single result expected: "+JSON.stringify(i.toJSON()))}},getModels:function(){return this.privateCollection.models.slice(0)},activate:function(){this.listenTo(this.privateCollection,"all",this.trigger)},deactivate:function(){this.stopListening(this.privateCollection,"all",this.trigger)},dispose:function(){this.off(),this.stopListening()}}),l.prototype.Data=f,l.FETCHED_STATUSES=h,l}),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||{};var s=t.FormModelClass||this.FormModelClass||n;this.model=t.model||this.model||new s,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(){var t=i.prototype.prepare.apply(this);return t.formErrors=0!==e.size(this._errors)?this._errors:null,t.formSuccess=this._success,t},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);t(e).is("select")&&(r.selectOptions=i.__generateSelectOptions(e,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}}},__generateSelectOptions:function(i,n){var s=[],r=t(i).children("option");return e.each(r,function(e){s.push({label:t(e).text(),value:n.modelFormat?n.modelFormat.apply(this,[t(e).val()]):t(e).val()})}),{collection:s,labelPath:"label",valuePath:"value"}}});return r}); \ No newline at end of file