this._reset();this.initialize.apply(this,arguments);a&&this.reset(a,{silent:!0,parse:b.parse})};f.extend(r.prototype,k,{model:o,initialize:function(){},toJSON:function(a){returnthis.map(function(b){returnb.toJSON(a)})},add:function(a,b){varc,d,e,g,i,j={},k={},l=[];b||(b={});a=f.isArray(a)?a.slice():[a];c=0;for(d=a.length;c<d;c++){if(!(e=a[c]=this._prepareModel(a[c],b)))throwError("Can't add an invalid model to a collection");g=e.cid;i=e.id;j[g]||this._byCid[g]||null!=i&&(k[i]||this._byId[i])?
shift:function(a){varb=this.at(0);this.remove(b,a);returnb},get:function(a){returnnull==a?void0:this._byId[null!=a.id?a.id:a]},getByCid:function(a){returna&&this._byCid[a.cid||a]},at:function(a){returnthis.models[a]},where:function(a){returnf.isEmpty(a)?[]:this.filter(function(b){for(varcina)if(a[c]!==b.get(c))return!1;return!0})},sort:function(a){a||(a={});if(!this.comparator)throwError("Cannot sort a set without a comparator");varb=f.bind(this.comparator,this);1==this.comparator.length?
""},getFragment:function(a,b){if(null==a)if(this._hasPushState||b){vara=window.location.pathname,c=window.location.search;c&&(a+=c)}elsea=this.getHash();a.indexOf(this.options.root)||(a=a.substr(this.options.root.length));returna.replace(s,"")},start:function(a){if(m.started)throwError("Backbone.history has already been started");m.started=!0;this.options=f.extend({},{root:"/"},this.options,a);this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=
for(varbina){varc=a[b];f.isFunction(c)||(c=this[a[b]]);if(!c)throwError('Method "'+a[b]+'" does not exist');vard=b.match(F),e=d[1],d=d[2],c=f.bind(c,this),e=e+(".delegateEvents"+this.cid);""===d?this.$el.bind(e,c):this.$el.delegate(d,e,c)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(varb=0,c=w.length;b<c;b++){vard=w[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(this.el)this.setElement(this.el,
b,c){vard;d=b&&b.hasOwnProperty("constructor")?b.constructor:function(){a.apply(this,arguments)};f.extend(d,a);x.prototype=a.prototype;d.prototype=newx;b&&f.extend(d.prototype,b);c&&f.extend(d,c);d.prototype.constructor=d;d.__super__=a.prototype;returnd},n=function(a,b){return!a||!a[b]?null:f.isFunction(a[b])?a[b]():a[b]},t=function(){throwError('A "url" property or function must be specified');}}).call(this);
*/(function(){functiona(){return((1+Math.random())*65536|0).toString(16).substring(1)}functionb(){returna()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()}Backbone.LocalStorage=window.Store=function(a){this.name=a;varb=this.localStorage().getItem(this.name);this.records=b&&b.split(",")||[]},_.extend(Backbone.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(a){returna.id||(a.id=b(),a.set(a.idAttribute,a.id)),this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),this.records.push(a.id.toString()),this.save(),a},update:function(a){returnthis.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),_.include(this.records,a.id.toString())||this.records.push(a.id.toString()),this.save(),a},find:function(a){returnJSON.parse(this.localStorage().getItem(this.name+"-"+a.id))},findAll:function(){return_(this.records).chain().map(function(a){returnJSON.parse(this.localStorage().getItem(this.name+"-"+a))},this).compact().value()},destroy:function(a){returnthis.localStorage().removeItem(this.name+"-"+a.id),this.records=_.reject(this.records,function(b){returnb==a.id.toString()}),this.save(),a},localStorage:function(){returnlocalStorage}}),Backbone.LocalStorage.sync=window.Store.sync=Backbone.localSync=function(a,b,c,d){vare=b.localStorage||b.collection.localStorage;typeofc=="function"&&(c={success:c,error:d});varf;switch(a){case"read":f=b.id!=undefined?e.find(b):e.findAll();break;case"create":f=e.create(b);break;case"update":f=e.update(b);break;case"delete":f=e.destroy(b)}f?c.success(f):c.error("Record not found")},Backbone.ajaxSync=Backbone.sync,Backbone.getSyncMethod=function(a){returna.localStorage||a.collection&&a.collection.localStorage?Backbone.localSync:Backbone.ajaxSync},Backbone.sync=function(a,b,c,d){returnBackbone.getSyncMethod(b).apply(this,[a,b,c,d])}})();
*/(function(){functiona(){return((1+Math.random())*65536|0).toString(16).substring(1)}functionb(){returna()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()}Backbone.LocalStorage=window.Store=function(a){this.name=a;varb=this.localStorage().getItem(this.name);this.records=b&&b.split(",")||[]},_.extend(Backbone.LocalStorage.prototype,{save:function(){this.localStorage().setItem(this.name,this.records.join(","))},create:function(a){returna.id||(a.id=b(),a.set(a.idAttribute,a.id)),this.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),this.records.push(a.id.toString()),this.save(),a},update:function(a){returnthis.localStorage().setItem(this.name+"-"+a.id,JSON.stringify(a)),_.include(this.records,a.id.toString())||this.records.push(a.id.toString()),this.save(),a},find:function(a){returnJSON.parse(this.localStorage().getItem(this.name+"-"+a.id))},findAll:function(){return_(this.records).chain().map(function(a){returnJSON.parse(this.localStorage().getItem(this.name+"-"+a))},this).compact().value()},destroy:function(a){returnthis.localStorage().removeItem(this.name+"-"+a.id),this.records=_.reject(this.records,function(b){returnb==a.id.toString()}),this.save(),a},localStorage:function(){returnlocalStorage}}),Backbone.LocalStorage.sync=window.Store.sync=Backbone.localSync=function(a,b,c,d){vare=b.localStorage||b.collection.localStorage;typeofc=="function"&&(c={success:c,error:d});varf;switch(a){case"read":f=b.id!=undefined?e.find(b):e.findAll();break;case"create":f=e.create(b);break;case"update":f=e.update(b);break;case"delete":f=e.destroy(b)}f?c.success(f):c.error("Record not found")},Backbone.ajaxSync=Backbone.sync,Backbone.getSyncMethod=function(a){returna.localStorage||a.collection&&a.collection.localStorage?Backbone.localSync:Backbone.ajaxSync},Backbone.sync=function(a,b,c,d){returnBackbone.getSyncMethod(b).apply(this,[a,b,c,d])}})();
a.reduce===A){e&&(c=b.bind(c,e));returnf?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,i){if(f)d=c.call(e,d,a,b,i);else{d=a;f=true}});if(!f)thrownewTypeError("Reduce of empty array with no initial value");returnd};b.reduceRight=b.foldr=function(a,c,d,e){varf=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));returnf?a.reduceRight(c,d):a.reduceRight(c)}varg=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));returnf?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=function(a,
this._reset();this.initialize.apply(this,arguments);a&&this.reset(a,{silent:!0,parse:b.parse})};f.extend(r.prototype,k,{model:o,initialize:function(){},toJSON:function(a){returnthis.map(function(b){returnb.toJSON(a)})},add:function(a,b){varc,d,e,g,i,j={},k={},l=[];b||(b={});a=f.isArray(a)?a.slice():[a];c=0;for(d=a.length;c<d;c++){if(!(e=a[c]=this._prepareModel(a[c],b)))throwError("Can't add an invalid model to a collection");g=e.cid;i=e.id;j[g]||this._byCid[g]||null!=i&&(k[i]||this._byId[i])?
shift:function(a){varb=this.at(0);this.remove(b,a);returnb},get:function(a){returnnull==a?void0:this._byId[null!=a.id?a.id:a]},getByCid:function(a){returna&&this._byCid[a.cid||a]},at:function(a){returnthis.models[a]},where:function(a){returnf.isEmpty(a)?[]:this.filter(function(b){for(varcina)if(a[c]!==b.get(c))return!1;return!0})},sort:function(a){a||(a={});if(!this.comparator)throwError("Cannot sort a set without a comparator");varb=f.bind(this.comparator,this);1==this.comparator.length?
""},getFragment:function(a,b){if(null==a)if(this._hasPushState||b){vara=window.location.pathname,c=window.location.search;c&&(a+=c)}elsea=this.getHash();a.indexOf(this.options.root)||(a=a.substr(this.options.root.length));returna.replace(s,"")},start:function(a){if(m.started)throwError("Backbone.history has already been started");m.started=!0;this.options=f.extend({},{root:"/"},this.options,a);this._wantsHashChange=!1!==this.options.hashChange;this._wantsPushState=!!this.options.pushState;this._hasPushState=
for(varbina){varc=a[b];f.isFunction(c)||(c=this[a[b]]);if(!c)throwError('Method "'+a[b]+'" does not exist');vard=b.match(F),e=d[1],d=d[2],c=f.bind(c,this),e=e+(".delegateEvents"+this.cid);""===d?this.$el.bind(e,c):this.$el.delegate(d,e,c)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=f.extend({},this.options,a));for(varb=0,c=w.length;b<c;b++){vard=w[b];a[d]&&(this[d]=a[d])}this.options=a},_ensureElement:function(){if(this.el)this.setElement(this.el,
b,c){vard;d=b&&b.hasOwnProperty("constructor")?b.constructor:function(){a.apply(this,arguments)};f.extend(d,a);x.prototype=a.prototype;d.prototype=newx;b&&f.extend(d.prototype,b);c&&f.extend(d,c);d.prototype.constructor=d;d.__super__=a.prototype;returnd},n=function(a,b){return!a||!a[b]?null:f.isFunction(a[b])?a[b]():a[b]},t=function(){throwError('A "url" property or function must be specified');}}).call(this);
// Knockout JavaScript library v2.1.0
// (c) Steven Sanderson - http://knockoutjs.com/
// License: MIT (http://www.opensource.org/licenses/mit-license.php)
(c) 2011, 2012 Kevin Malakoff - http://kmalakoff.github.com/knockback/
License: MIT (http://www.opensource.org/licenses/mit-license.php)
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
*/(function(){returnfunction(e){returntypeofdefine=="function"&&define.amd?define("knockback",["underscore","backbone","knockout"],e):e.call(this)}(function(){vare,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L=function(e,t){returnfunction(){returne.apply(t,arguments)}};m=function(){functiont(){}returnt.VERSION="0.16.7",t.TYPE_UNKNOWN=0,t.TYPE_SIMPLE=1,t.TYPE_ARRAY=2,t.TYPE_MODEL=3,t.TYPE_COLLECTION=4,t.release=function(n,r){vari,s,u,a,f,l,c,h;if(!n||n!==Object(n)||typeofn=="function"&&!g.isObservable(n)||n.__kb_destroyed||ninstanceofe.Model||ninstanceofe.Collection)returnthis;if(b.isArray(n)){i=n.splice(0,n.length);for(f=0,c=i.length;f<c;f++)s=i[f],t.release(s);returnthis}n.__kb_destroyed=!0,!r||r();if(g.isObservable(n)||typeofn.dispose=="function"||typeofn.destroy=="function"||typeofn.release=="function")if(g.isObservable(n)&&b.isArray(i=n())){if(n.__kb_is_co||n.__kb_is_o&&n.valueType()===o)n.destroy?n.destroy():n.dispose&&n.dispose();elseif(i.length){a=i.slice(0),i.splice(0,i.length);for(l=0,h=a.length;l<h;l++)u=a[l],t.release(u)}}elsen.release?n.release():n.destroy?n.destroy():n.dispose&&n.dispose();elsethis.releaseKeys(n);returnthis},t.releaseKeys=function(e){varn,r;for(nine)r=e[n],n==="__kb"||t.release(r,function(){returne[n]=null});returnthis},t.releaseOnNodeRemove=function(e,n){returne||T(this,"missing view model"),n||T(this,"missing node"),g.utils.domNodeDisposal.addDisposeCallback(n,function(){returnt.release(e)})},t.renderTemplate=function(e,n,r){vari,s;returnr==null&&(r={}),i=document.createElement("div"),s=g.renderTemplate(e,n,r,i,"replaceChildren"),i.children.length===1&&(i=i.children[0]),t.releaseOnNodeRemove(n,i),s.dispose(),i},t.renderAutoReleasedTemplate=function(e,t,n){returnn==null&&(n={}),S("kb.renderAutoReleasedTemplate","0.16.3","Please use kb.renderTemplate instead"),this.renderTemplate(e,t,n={})},t.applyBindings=function(e,n){returng.applyBindings(e,n),t.releaseOnNodeRemove(e,n)},t}(),this.Knockback=this.kb=m,typeofexports!="undefined"&&(module.exports=m);if(!this._&&typeofrequire!="undefined")try{b=require("lodash")}catch(A){b=require("underscore")}elseb=this._;returnm._=b=b.hasOwnProperty("_")?b._:b,m.Backbone=e=!this.Backbone&&typeofrequire!="undefined"?require("backbone"):this.Backbone,m.ko=g=!this.ko&&typeofrequire!="undefined"?require("knockout"):this.ko,x=function(e,t){throw""+(b.isString(e)?e:e.constructor.name)+": "+t+" is missing"},T=function(e,t){throw""+(b.isString(e)?e:e.constructor.name)+": "+t+" is unexpected"},S=function(e,t,n){varr;returnthis._legacy_warnings||(this._legacy_warnings={}),(r=this._legacy_warnings)[e]||(r[e]=0),this._legacy_warnings[e]++,console.warn("warning: '"+e+"' has been deprecated (will be removed in Knockback after "+t+"). "+n+".")},E=Array.prototype.splice,C=g.utils.unwrapObservable,v=function(e){vart;t=b.clone(e);while(e.options)b.defaults(t,e.options),e=e.options;returndeletet.options,t},f=m.TYPE_UNKNOWN,a=m.TYPE_SIMPLE,s=m.TYPE_ARRAY,u=m.TYPE_MODEL,o=m.TYPE_COLLECTION,k=function(e,t,n){returnarguments.length===2?e&&e.__kb&&e.__kb.hasOwnProperty(t)?e.__kb[t]:void0:(e||T(this,"no obj for wrapping "+t),e.__kb||(e.__kb={}),e.__kb[t]=n,n)},w=function(e,t){returnE.call(e,1,0,t),e},N=function(e){vart,n,r;if(!e)returne;if(e.__kb)return"object"ine.__kb?e.__kb.object:e;if(b.isArray(e))returnb.map(e,function(e){returnN(e)});if(b.isObject(e)&&e.constructor==={}.constructor){n={};for(tine)r=e[t],n[t]=N(r);returnn}returne},m.utils=function(){functiont(){}returnt.wrappedObservable=function(e,t){returnk.apply(this,w(arguments,"observable"))},t.wrappedObject=function(e,t){returnk.apply(this,w(arguments,"object"))},t.wrappedModel=function(e,t){returnarguments.length===1?(t=k(e,"object"),b.isUndefined(t)?e:t):k(e,"object",t)},t.wrappedStore=function(e,t){returnk.apply(this,w(arguments,"store"))},t.wrappedStoreIsOwned=function(e,t){returnk.apply(this,w(arguments,"store_is_owned"))},t.wrappedFactory=function(e,t){returnk.apply(this,w(arguments,"factory"))},t.wrappedEventWatcher=function(e,t){returnk.apply(this,w(arguments,"event_watcher"))},t.wrappedEventWatcherIsOwned=function(e,t){returnk.apply(this,w(arguments,"event_watcher_is_owned"))},t.wrappedDestroy=function(e){vart;if(!e.__kb)return;returne.__kb.event_watcher&&e.__kb.event_watcher.releaseCallbacks(e),t=e.__kb,e.__kb=null,t.observable&&(t.observable.destroy=t.observable.release=null,this.wrappedDestroy(t.observable),t.observable=null),t.factory=null,t.event_watcher_is_owned&&t.event_watcher.destroy(),t.event_watcher=null,t.store_is_owned&&t.store.destroy(),t.store=null},t.valueType=function(t){returnt?t.__kb_is_o?t.valueType():t.__kb_is_co||tinstanceofe.Collection?o:tinstanceofm.ViewModel||tinstanceofe.Model?u:b.isArray(t)?s:a:f},t.pathJoin=function(e,t){return(e?e[e.length-1]!=="."?""+e+".":e:"")+t},t.optionsPathJoin=function(e,t){returnb.defaults({path:this.pathJoin(e.path,t)},e)},t.inferCreator=function(t,n,r,i,s){varo,u;n&&(o=n.creatorForPath(t,r));if(o)returno;if(i&&e.RelationalModel&&iinstanceofe.RelationalModel){s=C(s),u=b.find(i.getRelations(),function(e){returne.key===s});if(u)returnu.collectionType||b.isArray(u.keyContents)?m.CollectionObservable:m.ViewModel}returnt?tinstanceofe.Model?m.ViewModel:tinstanceofe.Collection?m.CollectionObservable:null:null},t.createFromDefaultCreator=function(t,n){returntinstanceofe.Model?m.viewModel(t,n):tinstanceofe.Collection?m.collectionObservable(t,n):b.isArray(t)?g.observableArray(t):g.observable(t)},t.hasModelSignature=function(e){returne&&e.attributes&&!e.models&&typeofe.get=="function"&&typeofe.trigger=="function"},t.hasCollectionSignature=function(e){returne&&e.models&&typeofe.get=="function"&&typeofe.trigger=="function"},t.release=function(e){returnS("kb.utils.release","0.16.0","Please use kb.release instead"),m.release(e)},t}(),m.Factory=function(){functione(e){this.parent_factory=e,this.paths={}}returne.useOptionsOrCreate=function(e,t,n){varr;returne.factory&&(!e.factories||e.factories&&e.factory.hasPathMappings(e.factories,n))?m.utils.wrappedFactory(t,e.factory):(r=m.utils.wrappedFactory(t,newm.Factory(e.factory)),e.factories&&r.addPathMappings(e.factories,n),r)},e.prototype.hasPath=function(e){returnthis.paths.hasOwnProperty(e)||this.parent_factory&&this.parent_factory.hasPath(e)},e.prototype.addPathMapping=function(e,t){returnthis.paths[e]=t},e.prototype.addPathMappings=function(e,t){varn,r;for(rine)n=e[r],this.paths[m.utils.pathJoin(t,r)]=n},e.prototype.hasPathMappings=function(e,t){varn,r,i,s;n=!0;for(sine)r=e[s],n&=(i=this.creatorForPath(null,m.utils.pathJoin(t,s)))&&r===i;returnn},e.prototype.creatorForPath=function(e,t){varn;if(n=this.paths[t])returnn.view_model?n.view_model:n;if(this.parent_factory)if(n=this.parent_factory.creatorForPath(e,t))returnn;returnnull},e}(),m.Store=function(){functiont(){this.observable_records=[],this.replaced_observables=[]}returnt.useOptionsOrCreate=function(e,t,n){returne.store?(e.store.register(t,n,e),m.utils.wrappedStore(n,e.store)):(m.utils.wrappedStoreIsOwned(n,!0),m.utils.wrappedStore(n,newm.Store))},t.prototype.destroy=function(){returnthis.clear()},t.prototype.clear=function(){vare,t,n,r;r=this.observable_records.splice(0,this.observable_records.length);for(t=0,n=r.length;t<n;t++)e=r[t],m.release(e.observable);m.release(this.replaced_observables)},t.prototype.register=function(e,t,n){varr;if(!t)return;if(g.isObservable(t)||t.__kb_is_co)return;returnm.utils.wrappedObject(t,e),e||(t.__kb_null=!0),r=n.creator?n.creator:n.path&&n.factory?n.factory.creatorForPath(e,n.path):null,r||(r=t.constructor),this.observable_records.push({obj:e,observable:t,creator:r}),t},t.prototype.findIndex=function(t,n){varr,i,s;if(!t||tinstanceofe.Model){s=this.observable_records;for(rins){i=s[r];if(!i.observable)continue;if(i.observable.__kb_destroyed){i.obj=null,i.observable=null;continue}if(!t&&!i.observable.__kb_null||t&&(i.observable.__kb_null||i.obj!==t))continue;if(i.creator===n||i.creator.create&&i.creator.create===n.create)returnr}}return-1},t.prototype.find=function(e,t){varn;return(n=this.findIndex(e,t))<0?null:this.observable_records[n].observable},t.prototype.isRegistered=function(e){vart,n,r,i;i=this.observable_records;for(n=0,r=i.length;n<r;n++){t=i[n];if(t.observable===e)return!0}return!1},t.prototype.findOrCreate=function(t,n){varr,i;returnn.store=this,n.creator||(n.creator=m.utils.inferCreator(t,n.factory,n.path)),!n.creator&&tinstanceofe.Model&&(n.creator=kv.ViewModel),r=n.creator,r?r.models_only?t:(r&&(i=this.find(t,r)),i?i:(r.create?i=r.create(t,n):i=newr(t,n),i||(i=g.observable(null)),g.isObservable(i)||this.isRegistered(i)||this.register(t,i,n),i)):m.utils.createFromDefaultCreator(t,n)},t.prototype.findOrReplace=function(e,t,n){varr,i;returne||raiseUnexpected("obj missing"),(r=this.findIndex(e,t))<0?this.register(e,n,{creator:t}):(i=this.observable_records[r],m.utils.wrappedObject(i.observable)===e||T(this,"different object"),i.observable!==n&&(i.observable.constructor===n.constructor||T(this,"replacing different type"),this.replaced_observables.push(i.observable),i.observable=n),n)},t}(),h=function(e,t,n){return!m.statistics||m.statistics.addModelEvent({name:t,emitter:e,key:n.key,path:n.path})},m.EventWatcher=function(){functiont(e,t,n){this._onModelUnloaded=L(this._onModelUnloaded,this),this._onModelLoaded=L(this._onModelLoaded,this),this.__kb||(this.__kb={}),this.__kb.callbacks={},this.__kb._onModelLoaded=b.bind(this._onModelLoaded,this),this.__kb._onModelUnloaded=b.bind(this._onModelUnloaded,this),n&&this.registerCallbacks(t,n),e?this.emitter(e):this.ee=null}returnt.useOptionsOrCreate=function(e,t,n,r){returne.event_watcher?(e.event_watcher.emitter()!==t&&e.event_watcher.model_ref!==t&&T(this,"emitter not matching"),m.utils.wrappedEventWatcher(n,e.event_watcher).registerCallbacks(n,r)):(m.utils.wrappedEventWatcherIsOwned(n,!0),m.utils.wrappedEventWatcher(n,newm.EventWatcher(t)).registerCallbacks(n,r))},t.prototype.destroy=function(){returnthis.emitter(null),this.__kb.callbacks=null,m.utils.wrappedDestroy(this)},t.prototype.emitter=function(t){varn,r,i,s,o,u,a,f;if(arguments.length===0||this.ee===t)returnthis.ee;this.model_ref&&(this.model_ref.unbind("loaded",this.__kb._onModelLoaded),this.model_ref.unbind("unloaded",this.__kb._onModelUnloaded),this.model_ref.release(),this.model_ref=null),e.ModelRef&&tinstanceofe.ModelRef?(this.model_ref=t,this.model_ref.retain(),this.model_ref.bind("loaded",this.__kb._onModelLoaded),this.model_ref.bind("unloaded",this.__kb._onModelUnloaded),t=this.model_ref.model()):deletethis.model_ref,o=this.ee,this.ee=t,f=this.__kb.callbacks;for(rinf){n=f[r],o&&o.unbind(r,n.fn),t&&this.ee.bind(r,n.fn),s=n.list;for(u=0,a=s.length;u<a;u++)i=s[u],i.emitter&&i.emitter(this.ee)}returnt},t.prototype.registerCallbacks=function(t,n){varr,i,s,o,u,a,f,l,c=this;t||x(this,"obj"),n||x(this,"info"),o=n.event_selector?n.event_selector:"change",s=o.split("");for(f=0,l=s.length;f<l;f++){i=s[f];if(!i)continue;r=this.__kb.callbacks[i],r||(a=[],r={list:a,fn:function(e){vart,n,r;for(n=0,r=a.length;n<r;n++){t=a[n];if(t.update&&!t.rel_fn){if(e&&t.key&&e.hasChanged&&!e.hasChanged(C(t.key)))continue;!m.statistics||h(e,i,t),t.update()}}returnnull}},this.__kb.callbacks[i]=r,this.ee&&this.ee.bind(i,r.fn)),u=b.defaults({obj:t},n),r.list.push(u)}this.ee&&(e.RelationalModel&&this.eeinstanceofe.RelationalModel&&b.contains(s,"change")&&this._modelBindRelatationalInfo("change",u),u.emitter(this.ee)&&u.emitter)},t.prototype.releaseCallbacks=function(e){vart,n,r,i,s,o;if(!this.__kb.callbacks)return;s=this.__kb.callbacks;for(nins){t=s[n],o=t.list;for(rino){i=o[r];if(i.obj!==e)continue;t.list.splice(r,1),i.rel_fn&&this._modelUnbindRelatationalInfo(n,i),i.emitter&&i.emitter(null);return}}},t.prototype._onModelLoaded=function(t){varn,r,i,s,o,u,a,f;s=e.RelationalModel&&tinstanceofe.RelationalModel,this.ee=t,f=this.__kb.callbacks;for(rinf){n=f[r],this.ee.bind(r,n.fn),o=n.list;for(u=0,a=o.length;u<a;u++)i=o[u],s&&this._modelBindRelatationalInfo(r,i),i.emitter&&i.emitter(this.ee)}},t.prototype._onModelUnloaded=function(e){vart,n,r,i,s,o,u;this.ee=null,u=this.__kb.callbacks;for(ninu){t=u[n],e.unbind(n,t.fn),i=t.list;for(s=0,o=i.length;s<o;s++)r=i[s],r.rel_fn&&this._modelUnbindRelatationalInfo(n,r),r.emitter&&r.emitter(null)}},t.prototype._modelBindRelatationalInfo=function(e,t){varn,r;if(e==="change"&&t.key&&t.update){n=C(t.key),r=b.find(this.ee.getRelations(),function(e){returne.key===n});if(!r)return;t.rel_fn=function(n){return!m.statistics||h(n,""+e+" (relational)",t),t.update()},r.collectionType||b.isArray(r.keyContents)?(t.is_collection=!0,this.ee.bind("add:"+t.key,t.rel_fn),this.ee.bind("remove:"+t.key,t.rel_fn)):this.ee.bind("update:"+t.key,t.rel_fn)}},t.prototype._modelUnbindRelatationalInfo=function(e,t){if(!t.rel_fn)return;t.is_collection?(this.ee.unbind("add:"+t.key,t.rel_fn),this.ee.unbind("remove:"+t.key,t.rel_fn)):this.ee.unbind("update:"+t.key,t.rel_fn),t.rel_fn=null},t}(),m.emitterObservable=function(e,t){returnnewm.EventWatcher(e,t)},m.Observable=function(){functione(e,t,n){varr,i,s,o=this;returnthis.vm=n,t||x(this,"options"),this.vm||(this.vm={}),b.isString(t)||g.isObservable(t)?r=this.create_options={key:t}:r=this.create_options=v(t),this.key=r.key,deleter.key,this.key||x(this,"key"),!r.args||(this.args=r.args,deleter.args),!r.read||(this.read=r.read,deleter.read),!r.write||(this.write=r.write,deleter.write),i=r.event_watcher,deleter.event_watcher,this.vo=g.observable(null),this._model=g.observable(),s=m.utils.wrappedObservable(this,g.dependentObservable({read:function(){vare,t,n,r,i,s;t=[C(o.key)];if(o.args)if(b.isArray(o.args)){s=o.args;for(r=0,i=s.length;r<i;r++)e=s[r],t.push(C(e))}elset.push(C(o.args));returno._mdl===o._model()&&o._mdl&&(n=o.read?o.read.apply(o.vm,t):o._mdl.get.apply(o._mdl,t),o.update(n)),C(o.vo())},write:function(e){vart,n,r,i,s,u,a;i=N(e),r={},r[C(o.key)]=i,n=o.write?[i]:[r];if(o.args)if(b.isArray(o.args)){a=o.args;for(s=0,u=a.length;s<u;s++)t=a[s],n.push(C(t))}elsen.push(C(o.args));returno._mdl&&(o.write?o.write.apply(o.vm,n):o._mdl.set.apply(o._mdl,n)),o.update(e)},owner:this.vm})),s.__kb_is_o=!0,r.store=m.utils.wrappedStore(s,r.store),r.path=m.utils.pathJoin(r.path,this.key),r.factories&&(typeofr.factories=="function"||r.factories.create)?(r.factory=m.utils.wrappedFactory(s,newm.Factory(r.factory)),r.factory.addPathMapping(r.path,r.factories)):r.factory=m.Factory.useOptionsOrCreate(r,s,r.path),deleter.factories,s.value=b.bind(this.value,this),s.valueType=b.bind(this.valueType,this),s.destroy=b.bind(this.destroy,this),s.model=this.model=g.dependentObservable({read:function(){returno._model(),o._mdl},write:function(e){if(o.__kb_destroyed||o._mdl===e)return;returno._mdl=e,o.update(null),o._model(e)}}),m.EventWatcher.useOptionsOrCreate({event_watcher:i},e,this,{emitter:this.model,update:b.bind(this.update,this),key:this.key,path:r.path}),this.__kb_value||this.update(),m.LocalizedObservable&&r.localizer&&(s=newr.localizer(s),deleter.localizer),m.DefaultObservable&&r.hasOwnProperty("default")&&(s=m.defaultObservable(s,r["default"]),deleter["default"]),s}returne.prototype.destroy=function(){vare;returne=m.utils.wrappedObservable(this),this.__kb_destroyed=!0,m.release(this.__kb_value),this.__kb_value=null,this.model.dispose(),this._mdl=this.model=e.model=null,m.utils.wrappedDestroy(this)},e.prototype.value=function(){returnthis.__kb_value},e.prototype.valueType=function(){vare;returne=this._mdl?this._mdl.get(this.key):null,this.value_type||this._updateValueObservable(e),this.value_type},e.prototype.update=function(e){vart,n;if(this.__kb_destroyed)return;this._mdl&&!arguments.length&&(e=this._mdl.get(C(this.key))),e!==void0||(e=null),t=m.utils.valueType(e);if(!this.__kb_value||this.__kb_value.__kb_destroyed||this.__kb_value.__kb_null&&e)this.__kb_value=void0,this.value_type=void0;n=this.__kb_value;if(b.isUndefined(this.value_type)||this.value_type!==t&&t!==f)returnthis.value_type===o&&t===s?n(e):this._updateValueObservable(e);if(this.value_type===u){if(typeofn.model=="function"){if(n.model()!==e)returnn.model(e)}elseif(m.utils.wrappedObject(n)!==e)returnthis._updateValueObservable(e)}elseif(this.value_type===o){if(n.collection()!==e)returnn.collection(e)}elseif(n()!==e)returnn(e)},e.prototype._updateValueObservable=function(e){vart,n,r,i;returnt=this.create_options,t.creator=m.utils.inferCreator(e,t.factory,t.path,this._mdl,this.key),this.value_type=f,n=t.creator,r=this.__kb_value,this.__kb_value=void0,r&&m.release(r),n?t.store?i=t.store.findOrCreate(e,t):n.models_only?(i=e,this.value_type=a):n.create?i=n.create(e,t):i=newn(e,t):b.isArray(e)?(this.value_type=s,i=g.observableArray(e)):(this.value_type=a,i=g.observable(e)),this.value_type===f&&(g.isObservable(i)?i.__kb_is_co?this.value_type=o:this.value_type=a:(this.value_type=u,typeofi.model!="function"&&m.utils.wrappedObject(i,e))),this.__kb_value=i,this.vo(i)},e}(),m.observable=function(e,t,n){returnnewm.Observable(e,t,n)},m.ViewModel=function(){functiont(t,n,r){vari,s,o,u,a,f,l,c,h,p=this;!t||tinstanceofe.Model||typeoft.get=="function"&&typeoft.bind=="function"||T(this,"not a model"),n||(n={}),r||(r={}),b.isArray(n)?n={keys:n}:n=v(n),this.__kb||(this.__kb={}),this.__kb.vm_keys={},this.__kb.model_keys={},this.__kb.view_model=b.isUndefined(r)?this:r,!n.internals||(this.__kb.internals=n.internals),!n.excludes||(this.__kb.excludes=n.excludes),m.Store.useOptionsOrCreate(n,t,this),this.__kb.path=n.path,m.Factory.useOptionsOrCreate(n,this,n.path),c=k(this,"_mdl",g.observable()),this.model=g.dependentObservable({read:function(){returnc(),m.utils.wrappedObject(p)},write:function(e){vart,n;if(m.utils.wrappedObject(p)===e)return;if(p.__kb_null){!e||T(p,"model set on shared null");return}m.utils.wrappedObject(p,e),t=m.utils.wrappedEventWatcher(p);if(!t){c(e);return}t.emitter(e),p.__kb.keys||!e||!e.attributes||(n=b.difference(b.keys(e.attributes),b.keys(p.__kb.model_keys)),n&&p._createObservables(e,n)),c(e)}}),o=m.utils.wrappedEventWatcher(this,newm.EventWatcher(t,this,{emitter:this.model})),n.requires&&b.isArray(n.requires)&&(u=b.clone(n.requires)),this.__kb.internals&&(u=u?b.union(u,this.__kb.internals):b.clone(this.__kb.internals));if(n.keys)if(b.isArray(n.keys))this.__kb.keys=n.keys,u=u?b.union(u,n.keys):b.clone(n.keys);else{a={},h=n.keys;for(linh)f=h[l],a[b.isString(f)?f:f.key?f.key:l]=!0;this.__kb.keys=b.keys(a)}elses=o.emitter(),s&&s.attributes&&(i=b.keys(s.attributes),u=u?b.union(u,i):i);u&&this.__kb.excludes&&(u=b.difference(u,this.__kb.excludes)),b.isObject(n.keys)&&!b.isArray(n.keys)&&this._mapObservables(t,n.keys),b.isObject(n.requires)&&!b.isArray(n.requires)&&this._mapObservables(t,n.requires),!n.mappings||this._mapObservables(t,n.mappings),!u||this._createObservables(t,u),!m.statistics||m.statistics.register("ViewModel",this)}returnt.extend=e.Model.extend,t.prototype.destroy=function(){vare;if(this.__kb.view_model!==this)for(einthis.__kb.vm_keys)this.__kb.view_model[e]=null;returnthis.__kb.view_model=null,m.releaseKeys(this),m.utils.wrappedDestroy(this),!m.statistics||m.statistics.unregister("ViewModel",this)},t.prototype.shareOptions=function(){return{store:m.utils.wrappedStore(this),factory:m.utils.wrappedFactory(this)}},t.prototype._createObservables=function(e,t){varn,r,i,s,o;n={store:m.utils.wrappedStore(this),factory:m.utils.wrappedFactory(this),path:this.__kb.path,event_watcher:m.utils.wrappedEventWatcher(this)};for(s=0,o=t.length;s<o;s++){r=t[s],i=this.__kb.internals&&b.contains(this.__kb.internals,r)?"_"+r:r;if(this[i])continue;this.__kb.vm_keys[i]=!0,this.__kb.model_keys[r]=!0,n.key=r,this[i]=this.__kb.view_model[i]=m.observable(e,n,this)}},t.prototype._mapObservables=function(e,t){varn,r,i;n={store:m.utils.wrappedStore(this),factory:m.utils.wrappedFactory(this),path:this.__kb.path,event_watcher:m.utils.wrappedEventWatcher(this)};for(iint){r=t[i];if(this[i])continue;r=b.isString(r)?{key:r}:b.clone(r),r.key||(r.key=i),this.__kb.vm_keys[i]=!0,this.__kb.model_keys[r.key]=!0,this[i]=this.__kb.view_model[i]=m.observable(e,b.defaults(r,n),this)}},t}(),m.viewModel=function(e,t,n){returnnewm.ViewModel(e,t,n)},m.observables=function(e,t,n){returnS("kb.observables","0.16.0","Please use kb.viewModel instead"),newm.ViewModel(e,t,n)},r=0,t=-1,n=1,m.compare=function(e,i){returnb.isString(e)?e.localeCompare(i):b.isString(i)?i.localeCompare(e):typeofe!="object"?e===i?r:e<i?t:n:e===i?r:e<i?t:n},m.CollectionObservable=function(){functiont(t,n){varr,i,s=this;return!t||tinstanceofe.Collection||T(this,"not a collection"),n||(n={}),i=m.utils.wrappedObservable(this,g.observableArray([])),i.__kb_is_co=!0,this.in_edit=0,this.__kb||(this.__kb={}),this.__kb._onCollectionChange=b.bind(this._onCollectionChange,this),n=v(n),n.sort_attribute?this._comparator=g.observable(this._attributeComparator(n.sort_attribute)):(n.sorted_index&&S("sortedIndex no longer supported","0.16.7","please use comparator instead"),this._comparator=g.observable(n.comparator)),n.filters?this._filters=g.observableArray(b.isArray(n.filters)?n.filters:n.filters?[n.filters]:void0):this._filters=g.observableArray([]),r=this.create_options={store:m.Store.useOptionsOrCreate(n,t,i)},this.path=n.path,r.factory=m.utils.wrappedFactory(i,this._shareOrCreateFactory(n)),r.path=m.utils.pathJoin(n.path,"models"),r.creator=r.factory.creatorForPath(null,r.path),r.creator&&(this.models_only=r.creator.models_only),i.destroy=b.bind(this.destroy,this),i.shareOptions=b.bind(this.shareOptions,this),i.filters=b.bind(this.filters,this),i.comparator=b.bind(this.comparator,this),i.sortAttribute=b.bind(this.sortAttribute,this),i.viewModelByModel=b.bind(this.viewModelByModel,this),i.hasViewModels=b.bind(this.hasViewModels,this),this._collection=g.observable(t),i.collection=this.collection=g.dependentObservable({read:function(){returns._collection()},write:function(e){vart;if((t=s._collection())===e)return;returnt&&t.unbind("all",s.__kb._onCollectionChange),e&&e.bind("all",s.__kb._onCollectionChange),s._collection(e)}}),t&&t.bind("all",this.__kb._onCollectionChange),this._mapper=g.dependentObservable(function(){vare,t,n,r,o;e=s._comparator(),n=s._filters(),t=s._collection();if(s.in_edit)return;returni=m.utils.wrappedObservable(s),t&&(r=t.models),!r||t.models.length===0?o=[]:(n.length&&(r=b.filter(r,function(e){return!s._modelIsFiltered(e)})),e?o=b.map(r,function(e){returns._createViewModel(e)}).sort(e):s.models_only?o=n.length?r:r.slice():o=b.map(r,function(e){returns._createViewModel(e)})),s.in_edit++,i(o),s.in_edit--}),i.subscribe(b.bind(this._onObservableArrayChange,this)),!m.statistics||m.statistics.register("CollectionObservable",this),i}returnt.extend=e.Model.extend,t.prototype.destroy=function(){vare,t,n;returnn=m.utils.wrappedObservable(this),t=this._collection(),t&&(t.unbind("all",this.__kb._onCollectionChange),e=n(),e.splice(0,e.length)),this._mapper.dispose(),this._mapper=null,m.release(this._filters),this._comparator(null),this.collection.dispose(),n.collection=this.collection=null,n.collection=null,m.utils.wrappedDestroy(this),!m.statistics||m.statistics.unregister("CollectionObservable",this)},t.prototype.shareOptions=function(){vare;returne=m.utils.wrappedObservable(this),{store:m.utils.wrappedStore(e),factory:m.utils.wrappedFactory(e)}},t.prototype.filters=function(e){returne?this._filters(b.isArray(e)?e:[e]):this._filters([])},t.prototype.comparator=function(e){returnthis._comparator(e)},t.prototype.sortedIndex=function(){returnS("sortedIndex no longer supported","0.16.7","please use comparator instead")},t.prototype.sortAttribute=function(e){returnthis._comparator(e?this._attributeComparator(e):null)},t.prototype.viewModelByModel=function(e){vart;returnthis.models_only?null:(t=e.hasOwnProperty(e.idAttribute)?e.idAttribute:"cid",b.find(m.utils.wrappedObservable(this)(),function(n){returnn.__kb.object[t]===e[t]}))},t.prototype.hasViewModels=function(){return!this.models_only},t.prototype._shareOrCreateFactory=function(e){vart,n,r,i;t=m.utils.pathJoin(e.path,"models"),r=e.factories;if(i=e.factory)if((n=i.creatorForPath(null,t))&&(!r||r.models===n)){if(!r)returni;if(i.hasPathMappings(r,e.path))returni}returni=newm.Factory(e.factory),r&&i.addPathMappings(r,e.path),i.creatorForPath(null,t)||(e.hasOwnProperty("models_only")?e.models_only?i.addPathMapping(t,{models_only:!0}):i.addPathMapping(t,m.ViewModel):e.view_model?i.addPathMapping(t,e.view_model):e.create?i.addPathMapping(t,{create:e.create}):i.addPathMapping(t,m.ViewModel)),i},t.prototype._onCollectionChange=function(e,t){varn,r,i,s;if(this.in_edit)return;switch(e){case"reset":case"resort":this._collection.notifySubscribers(this._collection());break;case"new":case"add":if(this._modelIsFiltered(t))return;i=m.utils.wrappedObservable(this),n=this._collection();if(s=this.viewModelByModel(t))return;s=this._createViewModel(t),this.in_edit++,(r=this._comparator())?(i().push(s),i.sort(r)):i.splice(n.indexOf(t),0,s),this.in_edit--;break;case"remove":case"destroy":this._onModelRemove(t);break;case"change":if(this._modelIsFiltered(t))this._onModelRemove(t);else{s=this.viewModelByModel(t);if(s){if(r=this._comparator())i=m.utils.wrappedObservable(this),this.in_edit++,i.sort(r),this.in_edit--}elsethis._onCollectionChange("add",t)}}},t.prototype._onModelRemove=function(e){vart,n;n=this.models_only?e:this.viewModelByModel(e);if(!n)return;returnt=m.utils.wrappedObservable(this),this.in_edit++,t.remove(n),this.in_edit--},t.prototype._onObservableArrayChange=function(e){vart,n,r,i,s,o,u,a,f,l=this;if(this.in_edit)return;this.models_only&&(!e.length||m.utils.hasModelSignature(e[0]))||!this.models_only&&(!e.length||b.isObject(e[0])&&!m.utils.hasModelSignature(e[0]))||T(this,"incorrect type passed"),s=m.utils.wrappedObservable(this),t=this._collection(),n=this._filters().length;if(!t)return;u=e;if(this.models_only)n&&(i=b.filter(e,function(e){return!l._modelIsFiltered(e)}));else{!n||(u=[]),i=[];for(a=0,f=e.length;a<f;a++){o=e[a],r=m.utils.wrappedObject(o);if(n){if(this._modelIsFiltered(r))continue;u.push(o)}this.create_options.store.findOrReplace(r,this.create_options.creator,o),i.push(r)}}this.in_edit++,e.length===u.length||s(u),b.isEqual(t.models,i)||t.reset(i),this.in_edit--},t.prototype._attributeComparator=function(e){vart;returnt=function(t,n){varr;returnr=C(e),m.compare(t.get(r),n.get(r))},this.models_only?t:function(e,n){returnt(m.utils.wrappedModel(e),m.utils.wrappedModel(n))}},t.prototype._createViewModel=function(e){returnthis.models_only?e:this.create_options.store.findOrCreate(e,this.create_options)},t.prototype._modelIsFiltered=function(e){vart,n,r,i;n=this._filters();for(r=0,i=n.length;r<i;r++){t=n[r],t=C(t);if(typeoft=="function"&&t(e)||e&&e.id===t)return!0}return!1},t}(),m.collectionObservable=function(e,t){returnnewm.CollectionObservable(e,t)},g.bindingHandlers.inject={init:function(e,t,n,r){returnm.Inject.inject(C(t()),r,e,t,n)}},m.Inject=function(){functione(){}returne.inject=function(e,t,n,r,i,s){varo,u,a;returno=function(e){varo,u,a;if(b.isFunction(e))t=newe(t,n,r,i),m.releaseOnNodeRemove(t,n);else{e.view_model&&(t=newe.view_model(t,n,r,i),m.releaseOnNodeRemove(t,n));for(oine){a=e[o];if(o==="view_model")continue;o==="create"?a(t,n,r,i):b.isObject(a)&&!b.isFunction(a)?(u=s||a&&a.create?{}:t,t[o]=m.Inject.inject(a,u,n,r,i,!0)):t[o]=a}}returnt},s?o(e):(u=(a=g.dependentObservable(function(){returno(e)}))(),a.dispose(),u)},e.injectViewModels=function(e){vart,n,r,i,s,o,u,a,f,l;a=[],o=function(e){vart,n,r,i,s;e.__kb_injected||e.attributes&&(t=b.find(e.attributes,function(e){returne.name==="kb-inject"}))&&(e.__kb_injected=!0,a.push({el:e,view_model:{},binding:t.value})),s=e.childNodes;for(r=0,i=s.length;r<i;r++)n=s[r],o(n)},o(e||document);for(f=0,l=a.length;f<l;f++){n=a[f];if(s=n.binding)s.search(/[:]/)<0||(s="{"+s+"}"),i=(newFunction("","return ( "+s+" )"))(),i||(i={}),!i.options||(u=i.options,deletei.options),u||(u={}),n.view_model=m.Inject.inject(i,n.view_model,n.el,null,null,!0),t=n.view_model.afterBinding||u.afterBinding,r=n.view_model.beforeBinding||u.beforeBinding;r&&r(n.view_model,n.el,u),m.applyBindings(n.view_model,n.el,u),t&&t(n.view_model,n.el,u)}returna},e}(),m.injectViewModels=m.Inject.injectViewModels,this.$?this.$(function(){returnm.injectViewModels()}):(y=function(){returndocument.readyState!=="complete"?setTimeout(y,0):m.injectViewModels()})(),m.DefaultObservable=function(){functione(e,t){varn,r=this;returnthis.dv=t,n=m.utils.wrappedObservable(this,g.dependentObservable({read:function(){vart;return(t=C(e()))?t:C(r.dv)},write:function(t){returne(t)}})),n.destroy=b.bind(this.destroy,this),n.setToDefault=b.bind(this.setToDefault,this),n}returne.prototype.destroy=function(){returnm.utils.wrappedDestroy(this)},e.prototype.setToDefault=function(){returnm.utils.wrappedObservable(this)(this.dv)},e}(),m.defaultObservable=function(e,t){returnnewm.DefaultObservable(e,t)},m.defaultWrapper=function(e,t){returnS("ko.defaultWrapper","0.16.3","Please use kb.defaultObservable instead"),newm.DefaultObservable(e,t)},m.Observable.prototype.setToDefault=function(){vare;(e=this.__kb_value)!=null&&typeofe.setToDefault=="function"&&e.setToDefault()},m.ViewModel.prototype.setToDefault=function(){vare,t;for(einthis.__kb.vm_keys)(t=this[e])!=null&&typeoft.setToDefault=="function"&&t.setToDefault()},m.utils.setToDefault=function(e){vart,n;if(!e)return;if(g.isObservable(e))typeofe.setToDefault=="function"&&e.setToDefault();elseif(b.isObject(e))for(tine)n=e[t],n&&(g.isObservable(n)||typeofn!="function")&&(t[0]!=="_"||t.search("__kb"))&&this.setToDefault(n);returne},p=Array.prototype.slice,m.toFormattedString=function(e){vart,n,r,i,s,o;s=e.slice(),n=p.call(arguments,1);for(rinn){t=n[r],o=C(t),o||(o=""),i=e.indexOf("{"+r+"}");while(i>=0)s=s.replace("{"+r+"}",o),i=e.indexOf("{"+r+"}",i+1)}returns},m.parseFormattedString=function(e,t){varn,r,i,s,o,u,a,f,l,c,h,p,d;c=t.slice(),i=0,u=0,f={};while(c.search("\\{"+i+"\\}")>=0){a=t.indexOf("{"+i+"}");while(a>=0)c=c.replace("{"+i+"}","(.*)"),f[a]=i,u++,a=t.indexOf("{"+i+"}",a+1);i++}n=i,l=newRegExp(c),o=l.exec(e),o&&o.shift();if(!o||o.length!==u){h=[];while(n-->0)h.push("");returnh}d=b.sortBy(b.keys(f),function(e,t){returnparseInt(e,10)}),r={};for(sind){a=d[s],i=f[a];if(r.hasOwnProperty(i))continue;r[i]=s}p=[],i=0;while(i<n)p.push(o[r[i]]),i++;returnp},m.FormattedObservable=function(){functione(e,t){varn,r;returnb.isArray(t)?(e=e,r=t):r=p.call(arguments,1),n=m.utils.wrappedObservable(this,g.dependentObservable({read:function(){varn,i,s;t=[C(e)];for(i=0,s=r.length;i<s;i++)n=r[i],t.push(C(n));returnm.toFormattedString.apply(null,t)},write:function(t){varn,i,s;i=m.parseFormattedString(t,C(e)),s=Math.min(r.length,i.length),n=0;while(n<s)r[n](i[n]),n++}})),n}returne.prototype.destroy=function(){returnm.utils.wrappedDestroy(this)},e}(),m.formattedObservable=function(e,t){returnnewm.FormattedObservable(e,p.call(arguments,1))},m.LocalizedObservable=function(){functiont(e,t,n){varr,i=this;returnthis.value=e,this.vm=n,t||(t={}),this.vm||(this.vm={}),this.read||x(this,"read"),m.locale_manager||x(this,"kb.locale_manager"),this.__kb||(this.__kb={}),this.__kb._onLocaleChange=b.bind(this._onLocaleChange,this),this.__kb._onChange=t.onChange,this.value&&(e=C(this.value)),this.vo=g.observable(e?this.read(e,null):null),r=m.utils.wrappedObservable(this,g.dependentObservable({read:function(){returni.value&&C(i.value),i.vo(),i.read(C(i.value))},write:function(e){i.write||T(i,"writing to read-only"),i.write(e,C(i.value)),i.vo(e);if(i.__kb._onChange)returni.__kb._onChange(e)},owner:this.vm})),r.destroy=b.bind(this.destroy,this),r.observedValue=b.bind(this.observedValue,this),r.resetToCurrent=b.bind(this.resetToCurrent,this),m.locale_manager.bind("change",this.__kb._onLocaleChange),t.hasOwnProperty("default")&&(r=m.DefaultObservable&&g.defaultObservable(r,t["default"])),r}returnt.extend=e.Model.extend,t.prototype.destroy=function(){returnm.locale_manager.unbind("change",this.__kb._onLocaleChange),this.vm=null,m.utils.wrappedDestroy(this)},t.prototype.resetToCurrent=function(){vare,t;t=m.utils.wrappedObservable(this),e=this.value?this.read(C(this.value)):null;if(t()===e)return;returnt(e)},t.prototype.observedValue=function(e){if(arguments.length===0)returnthis.value;this
Dependencies: Knockout.js, Backbone.js, and Underscore.js.
Optional dependency: Backbone.ModelRef.js.
*/
varBackbone,Knockback,kb,ko,_;if(typeofexports!=="undefined"){Knockback=kb=exports}else{this.Knockback=this.kb={}}Knockback.VERSION="0.15.1";_=!this._&&(typeofrequire!=="undefined")?require("underscore"):this._;Backbone=!this.Backbone&&(typeofrequire!=="undefined")?require("backbone"):this.Backbone;ko=!this.ko&&(typeofrequire!=="undefined")?require("knockout"):this.ko;Knockback.locale_manager;Knockback.stats={collection_observables:0,view_models:0};Knockback.stats_on=false;Knockback.utils={};Knockback.utils.legacyWarning=function(a,d,c){varb;kb._legacy_warnings||(kb._legacy_warnings={});(b=kb._legacy_warnings)[a]||(b[a]=0);kb._legacy_warnings[a]++;returnconsole.warn("Legacy warning! '"+a+"' has been deprecated (will be removed in Knockback "+d+"). "+c+".")};Knockback.utils.wrappedObservable=function(a,b){if(arguments.length===1){if(!(a&&a.__kb&&a.__kb.observable)){thrownewError("Knockback: instance is not wrapping an observable")}returna.__kb.observable}if(!a){thrownewError("Knockback: no instance for wrapping a observable")}a.__kb||(a.__kb={});if(a.__kb.observable&&a.__kb.observable.__kb){a.__kb.observable.__kb.instance=null}a.__kb.observable=b;if(b){b.__kb||(b.__kb={});b.__kb.instance=a}returnb};Knockback.wrappedObservable=function(a){kb.utils.legacyWarning("kb.wrappedObservable","0.16.0","Please use kb.utils.wrappedObservable instead");returnkb.utils.wrappedObservable(a)};Knockback.utils.observableInstanceOf=function(b,a){if(!b){returnfalse}if(!(b.__kb&&b.__kb.instance)){returnfalse}returnb.__kb.instanceinstanceofa};Knockback.utils.wrappedModel=function(a,b){if(arguments.length===1){if(a&&a.__kb&&a.__kb.hasOwnProperty("model")){returna.__kb.model}else{returna}}if(!a){thrownewError("Knockback: no view_model for wrapping a model")}a.__kb||(a.__kb={});a.__kb.model=b;returnb};Knockback.viewModelGetModel=Knockback.vmModel=function(a){kb.utils.legacyWarning("kb.vmModel","0.16.0","Please use kb.utils.wrappedModel instead");returnkb.utils.wrappedModel(a)};Knockback.utils.setToDefault=function(d){varb,c,a;if(!d){return}if(ko.isObservable(d)){returntypeofd.setToDefault==="function"?d.setToDefault():void0}else{if(_.isObject(d)){a=[];for(bind){c=d[b];a.push(c&&(b!=="__kb")?kb.utils.setToDefault(c):void0)}returna}}};Knockback.vmSetToDefault=function(a){kb.utils.legacyWarning("kb.vmSetToDefault","0.16.0","Please use kb.utils.release instead");returnkb.utils.setToDefault(a)};Knockback.utils.release=function(c){vara,b;if(!c){returnfalse}if(ko.isObservable(c)||(cinstanceofkb.Observables)||(typeofc.release==="function")||(typeofc.destroy==="function")){if(c.release){c.release()}else{if(c.destroy){c.destroy()}else{if(c.dispose){c.dispose()}}}returntrue}else{if(_.isObject(c)&&!(typeofc==="function")){for(ainc){b=c[a];if(!b||(a==="__kb")){continue}if(kb.utils.release(b)){c[a]=null}}returntrue}}returnfalse};Knockback.vmRelease=function(a){kb.utils.legacyWarning("kb.vmRelease","0.16.0","Please use kb.utils.release instead");returnkb.utils.release(a)};Knockback.vmReleaseObservable=function(a){kb.utils.legacyWarning("kb.vmReleaseObservable","0.16.0","Please use kb.utils.release instead");returnkb.utils.release(a)};kb.utils.optionsCreateClear=function(a){deletea.create;deletea.children;deletea.view_model;returndeletea.view_model_create};kb.utils.optionsCreateOverride=function(a,b){kb.utils.optionsCreateClear(a);return_.extend(a,b)};Knockback.RefCountable=(function(){a.name="RefCountable";a.extend=Backbone.Model.extend;functiona(){this.__kb||(this.__kb={});this.__kb.ref_count=1}a.prototype.__destroy=function(){};a.prototype.retain=function(){if(this.__kb.ref_count<=0){thrownewError("RefCountable: ref_count is corrupt: "+this.__kb.ref_count)}this.__kb.ref_count++;returnthis};a.prototype.release=function(){if(this.__kb.ref_count<=0){thrownewError("RefCountable: ref_count is corrupt: "+this.__kb.ref_count)}this.__kb.ref_count--;if(!this.__kb.ref_count){this.__destroy()}returnthis};a.prototype.refCount=function(){returnthis.__kb.ref_count};returna})();Knockback.Store=(function(){a.name="Store";functiona(){this.keys=[];this.values=[]}a.prototype.destroy=function(){varc,e,d,b;this.keys=null;d=this.values;for(cind){e=d[c];if(!kb.utils.observableInstanceOf(e,kb.CollectionObservable)){continue}this.values[c]=null;while(e.refCount()>0){e.release()}}b=this.values;for(cinb){e=b[c];if(!e){continue}this.values[c]=null;if(einstanceofkb.RefCountable){while(e.refCount()>0){e.release()}}else{kb.utils.release(e)}}returnthis.values=null};a.prototype.registerValue=function(c,d){varb;if(dinstanceofkb.RefCountable){d.retain()}b=_.indexOf(this.keys,c);if(b>=0){this.values[b]=d}else{this.keys.push(c);this.values.push(d)}returnd};a.prototype.resolveValue=function(d,f,c){varb,e;b=_.indexOf(this.keys,d);if(b>=0){if(this.values[b]){if((this.values[b]instanceofkb.RefCountable)&&(this.values[b].refCount()<=0)){this.values[b]=null}else{if(this.values[b]instanceofkb.RefCountable){returnthis.values[b].retain()}else{returnthis.values[b]}}}}else{b=this.keys.length;this.keys.push(d);this.values.push(void0)}e=f.apply(null,Array.prototype.slice.call(arguments,2));if(this.keys[b]!==d){this.registerValue(d,e)}else{if(!this.values[b]){if(einstanceofkb.RefCountable){e.retain()}this.values[b]=e}}returne};a.prototype.releaseValue=function(c){varb;if(!(cinstanceofkb.RefCountable)){return}c.release();if(c.refCount()>0){return}b=_.indexOf(this.values,c);if(!(b>=0)){return}returnthis.values[b]=0};a.prototype.addResolverToOptions=function(b,c){return_.extend(b,{store:this,store_key:c})};a.resolveFromOptions=function(b,c){if(!(b.store&&b.store_key)){return}returnb.store.registerValue(b.store_key,c)};returna})();var__hasProp={}.hasOwnProperty,__extends=function(d,b){for(varainb){if(__hasProp.call(b,a)){d[a]=b[a]}}functionc(){this.constructor=d}c.prototype=b.prototype;d.prototype=newc;d.__super__=b.prototype;returnd};Knockback.CollectionObservable=(function(b){__extends(a,b);a.name="CollectionObservable";functiona(f,c){vare,d,g=this;if(c==null){c={}}if(!f){thrownewError("CollectionObservable: collection is missing")}a.__super__.constructor.apply(this,arguments);if(Knockback.stats_on){kb.stats.collection_observables++}if(ko.isObservable(c)&&c.hasOwnProperty("indexOf")){kb.utils.legacyWarning("kb.collectionObservable with an external ko.observableArray","0.16.0","Please use the kb.collectionObservable directly instead of passing a ko.observableArray");d=kb.utils.wrappedObservable(this,c);c=arguments[2]||{};e=true}else{d=kb.utils.wrappedObservable(this,ko.observableArray([]))}if(!c.store_skip_resolve){kb.Store.resolveFromOptions(c,kb.utils.wrappedObservable(this))}if(c.store){this.__kb.store=c.store}else{this.__kb.store=newkb.Store();this.__kb.store_is_owned=true}if(c.hasOwnProperty("view_model")){if(!c.view_model){thrownewError("Knockback.CollectionObservable: options.view_model is empty")}this.view_model_create_fn=c.view_model;this.view_model_create_with_new=true}else{if(c.hasOwnProperty("view_model_constructor")){if(!c.view_model_constructor){thrownewError("Knockback.CollectionObservable: options.view_model_constructor is empty")}kb.utils.legacyWarning("kb.collectionObservable option view_model_constructor","0.16.0","Please use view_model option instead");this.view_model_create_fn=c.view_model_constructor;this.view_model_create_with_new=true}else{if(c.hasOwnProperty("view_model_create")){if(!c.view_model_create){thrownewError("Knockback.CollectionObservable: options.view_model_create is empty")}this.view_model_create_fn=c.view_model_create}else{if(c.hasOwnProperty("create")){if(!c.create){thrownewError("Knockback.CollectionObservable: options.create is empty")}this.view_model_create_fn=c.create}}}}this.sort_attribute=c.sort_attribute;this.sorted_index=c.sorted_index;this.__kb._onCollectionReset=_.bind(this._onCollectionReset,this);this.__kb._onCollectionResort=_.bind(this._onCollectionResort,this);this.__kb._onModelAdd=_.bind(this._onModelAdd,this);this.__kb._onModelRemove=_.bind(this._onModelRemove,this);this.__kb._onModelChange=_.bind(this._onModelChange,this);if(e&&f){f.bind("change",function(){returnkb.utils.wrappedObservable(g).valueHasMutated()})}d.retain=_.bind(this.retain,this);d.refCount=_.bind(this.refCount,this);d.release=_.bind(this.release,this);d.collection=_.bind(this.collection,this);d.viewModelByModel=_.bind(this.viewModelByModel,this);d.sortedIndex=_.bind(this.sortedIndex,this);d.sortAttribute=_.bind(this.sortAttribute,this);d.hasViewModels=_.bind(this.hasViewModels,this);d.bind=_.bind(this.bind,this);d.unbind=_.bind(this.unbind,this);d.trigger=_.bind(this.trigger,this);this.collection(f,{silent:true,defer:c.defer});returnd}a.prototype.__destroy=function(){this.collection(null);if(this.hasViewModels()&&this.__kb.store_is_owned){this.__kb.store.destroy();this.__kb.store=null}this.view_model_create_fn=null;this.__kb.collection=null;kb.utils.wrappedObservable(this,null);a.__super__.__destroy.apply(this,arguments);if(Knockback.stats_on){returnkb.stats.collection_observables--}};a.prototype.retain=function(){a.__super__.retain.apply(this,arguments);returnkb.utils.wrappedObservable(this)};a.prototype.release=function(){varc;c=kb.utils.wrappedObservable(this);a.__super__.release.apply(this,arguments);returnc};a.prototype.collection=function(g,c){varf,d,e;f=kb.utils.wrappedObservable(this);if(arguments.length===0){f();returnthis.__kb.collection}if(g===this.__kb.collection){return}if(this.__kb.collection){this._clear();this._collectionUnbind(this.__kb.collection);if(typeof(d=this.__kb.collection).release==="function"){d.release()}this.__kb.collection=null}this.__kb.collection=g;if(this.__kb.collection){if(typeof(e=this.__kb.collection).retain==="function"){e.retain()}this._collectionBind(this.__kb.collection);returnthis.sortedIndex(this.sorted_index,this.sort_attribute,c)}};a.prototype.sortedIndex=function(g,c,d){vare,f=this;if(d==null){d={}}if(g){this.sorted_index=g;this.sort_attribute=c}else{if(c){this.sort_attribute=c;this.sorted_index=this._sortAttributeFn(c)}else{this.sort_attribute=null;this.sorted_index=null}}e=function(){varh;h=kb.utils.wrappedObservable(f);if((f.__kb.collection.models.length===0)&&(h().length===0)){return}f._collectionResync(true);if(!d.silent){returnf.trigger("resort",h())}};if(d.defer){_.defer(e)}else{e()}returnthis};a.prototype.sortAttribute=function(d,e,c){returnthis.sortedIndex(e,d,c)};a.prototype.viewModelByModel=function(d){varc,e;if(!this.hasViewModels()){returnnull}e=kb.utils.wrappedObservable(this);c=d.hasOwnProperty(d.idAttribute)?d.idAttribute:"cid";return_.find(e(),function(f){returnf.__kb.model[c]===d[c]})};a.prototype.hasViewModels=function(){return!!this.view_model_create_fn};a.prototype._collectionBind=function(j){varg,i,f,e,d,h,c;if(!j){return}j.bind("reset",this.__kb._onCollectionReset);if(!this.sorted_index){j.bind("resort",this.__kb._onCollectionResort)}h=["new","add"];for(i=0,e=h.length;i<e;i++){g=h[i];j.bind(g,this.__kb._onModelAdd)}c=["remove","destroy"];for(f=0,d=c.length;f<d;f++){g=c[f];j.bind(g,this.__kb._onModelRemove)}returnj.bind("change",this.__kb._onModelChange)};a.prototype._collectionUnbind=function(j){varg,i,f,e,d,h,c;if(!j){return}j.unbind("reset",this.__kb._onCollectionReset);if(!this.sorted_index){j.unbind("resort",this.__kb._onCollectionResort)}h=["new","add"];for(i=0,e=h.length;i<e;i++){g=h[i];j.unbind(g,this.__kb._onModelAdd)}c=["remove","destroy"];for(f=0,d=c.length;f<d;f++){g=c[f];j.unbind(g,this.__kb._onModelRemove)}returnj.unbind("change",this.__kb._onModelChange)};a.prototype._onCollectionReset=function(){returnthis._collectionResync()};a.prototype._onCollectionResort=function(d){varc;if(this.sorted_index){thrownewError("CollectionObservable: collection sorted_index unexpected")}if(_.isArray(d)){c=kb.utils.wrappedObservable(this);returnthis.trigger("resort",c())}else{returnthis._onModelResort(d)}};a.prototype._onModelAdd=function(d){varc,f,e;e=this.hasViewModels()?this._createTarget(d):d;f=kb.utils.wrappedObservable(this);if(this.sorted_index){c=this.sorted_index(f(),e)}else{c=this.__kb.collection.indexOf(d)}f.splice(c,0,e);returnthis.trigger("add",e,f())};a.prototype._onModelRemove=function(c){vare,d;d=this.hasViewModels()?this.viewModelByModel(c):c;if(!d){return}e=kb.utils.wrappedObservable(this);e.remove(d);this.trigger("remove",d,e);if(this.hasViewModels()){returnthis.__kb.store.releaseValue(d)}};a.prototype._onModelChange=function(c){if(this.sorted_index&&(!this.sort_attribute||c.hasChanged(this.sort_attribute))){returnthis._onModelResort(c)}};a.prototype._onModelResort=function(d){varc,g,f,h,e;g=kb.utils.wrappedObservable(this);e=this.hasViewModels()?this.viewModelByModel(d):d;f=g.indexOf(e);if(this.sorted_index){h=_.clone(g());h.splice(f,1);c=this.sorted_index(h,e)}else{c=this.__kb.collection.indexOf(d)}if(f===c){return}g.splice(f,1);g.splice(c,0,e);returnthis.trigger("resort",e,g(),c)};a.prototype._clear=function(f){vari,h,e,g,d,c;i=kb.utils.wrappedObservable(this);if(!f){this.trigger("remove",i())}e=i.removeAll();if(this.hasViewModels()){c=[];for(g=0,d=e.length;g<d;g++){h=e[g];c.push(this.__kb.store.releaseValue(h))}returnc}};a.prototype._collectionResync=function(k){vard,g,c,j,i,e,l,f,h=this;this._clear(k);c=kb.utils.wrappedObservable(this);if(this.sorted_index){i=[];f=this.__kb.collection.models;for(e=0,l=f.length;e<l;e++){g=f[e];j=this._createTarget(g);d=this.sorted_index(i,j);i.splice(d,0,j)}}else{i=this.hasViewModels()?_.map(this.__kb.collection.models,function(m){returnh._createTarget(m)}):_.clone(this.__kb.collection.models)}c(i);if(!k){returnthis.trigger("add",c())}};a.prototype._sortAttributeFn=function(c){if(this.hasViewModels()){returnfunction(e,d){return_.sortedIndex(e,d,function(f){returnkb.utils.wrappedModel(f).get(c)})}}else{returnfunction(e,d){return_.sortedIndex(e,d,function(f){returnf.get(c)})}}};a.prototype._createTarget=function(c){vare,d=this;e=function(){varh,g,f;g=d.__kb.store.addResolverToOptions({},c);h=kb.utils.wrappedObservable(d);f=d.view_model_create_with_new?newd.view_model_create_fn(c,g,h):d.view_model_create_fn(c,g,h);kb.utils.wrappedModel(f,c);returnf};if(this.hasViewModels()){returnthis.__kb.store.resolveValue(c,e)}else{returnc}};returna})(kb.RefCountable);__extends(Knockback.CollectionObservable.prototype,Backbone.Events);Knockback.collectionObservable=function(c,b,a){returnnewKnockback.CollectionObservable(c,b,a)};Knockback.sortedIndexWrapAttr=Knockback.siwa=function(a,b){returnfunction(d,c){return_.sortedIndex(d,c,function(e){returnnewb(kb.utils.wrappedModel(e).get(a))})}};if(!this.Knockback){thrownewError("Knockback: Dependency alert! knockback_core.js must be included before this file")}Knockback.DefaultWrapper=(function(){a.name="DefaultWrapper";functiona(b,e){varc,d=this;this.default_value_observable=e;this.__kb={};c=kb.utils.wrappedObservable(this,ko.dependentObservable({read:function(){varg,f;f=ko.utils.unwrapObservable(b());g=ko.utils.unwrapObservable(d.default_value_observable);if(!f){returng}else{returnf}},write:function(f){returnb(f)}}));c.destroy=_.bind(this.destroy,this);c.setToDefault=_.bind(this.setToDefault,this);returnc}a.prototype.destroy=function(){kb.utils.wrappedObservable(this,null);returnthis.default_value=null};a.prototype.setToDefault=function(){varb;b=kb.utils.wrappedObservable(this);returnb(this.default_value_observable)};returna})();Knockback.defaultWrapper=function(b,a){returnnewKnockback.DefaultWrapper(b,a)};Knockback.toFormattedString=function(g){varb,e,d,c,a,f;a=g.slice();e=Array.prototype.slice.call(arguments,1);for(dine){b=e[d];f=ko.utils.unwrapObservable(b);if(!f){f=""}c=g.indexOf("{"+d+"}");while(c>=0){a=a.replace("{"+d+"}",f);c=g.indexOf("{"+d+"}",c+1)}}returna};Knockback.parseFormattedString=function(h,m){vari,a,j,k,g,p,o,f,l,b,e,n,d,c;b=m.slice();j=0;p=0;f={};while(b.search("\\{"+j+"\\}")>=0){o=m.indexOf("{"+j+"}");while(o>=0){b=b.replace("{"+j+"}","(.*)");f[o]=j;p++;o=m.indexOf("{"+j+"}",o+1)}j++}i=j;l=newRegExp(b);g=l.exec(h);if(g){g.shift()}if(!g||(g.length!==p)){return_.map((function(){c=[];for(varq=1;1<=i?q<=i:q>=i;1<=i?q++:q--){c.push(q)}returnc}).apply(this),function(){return""})}n=_.sortBy(_.keys(f),function(q,r){returnparseInt(q,10)});a={};for(kinn){o=n[k];j=f[o];if(a.hasOwnProperty(j)){continue}a[j]=k}e=[];j=0;while(j<i){e.push(g[a[j]]);j++}returne};Knockback.FormattedObservable=(function(){a.name="FormattedObservable";functiona(e,c){vard,b;this.__kb={};if(_.isArray(c)){e=e;b=c}else{b=Array.prototype.slice.call(arguments,1)}d=kb.utils.wrappedObservable(this,ko.dependentObservable({read:function(){varf,h,g;c=[ko.utils.unwrapObservable(e)];for(h=0,g=b.length;h<g;h++){f=b[h];c.push(ko.utils.unwrapObservable(f))}returnkb.toFormattedString.apply(null,c)},write:function(i){varg,h,j,f;h=kb.parseFormattedString(i,ko.utils.unwrapObservable(e));j=Math.min(b.length,h.length);g=0;f=[];while(g<j){b[g](h[g]);f.push(g++)}returnf}}));returnd}a.prototype.destroy=function(){returnkb.utils.wrappedObservable(this,null)};returna})();Knockback.formattedObservable=function(b,a){returnnewKnockback.FormattedObservable(b,Array.prototype.slice.call(arguments,1))};Knockback.LocalizedObservable=(function(){a.name="LocalizedObservable";a.extend=Backbone.Model.extend;functiona(d,c,b){vare;this.value=d;this.options=c!=null?c:{};this.view_model=b!=null?b:{};if(!(this.options.read||this.read)){thrownewError("LocalizedObservable: options.read is missing")}if(this.options.read&&this.read){thrownewError("LocalizedObservable: options.read and read class function exist. You need to choose one.")}if(this.options.write&&this.write){thrownewError("LocalizedObservable: options.write and write class function exist. You need to choose one.")}if(!kb.locale_manager){thrownewError("LocalizedObservable: Knockback.locale_manager is not defined")}this.__kb={};this.__kb._onLocaleChange=_.bind(this._onLocaleChange,this);if(this.value){d=ko.utils.unwrapObservable(this.value)}this.__kb.value_observable=ko.observable(!d?this._getDefaultValue():this.read.call(this,d,null));if(this.write&&!(typeofthis.write==="function")){thrownewError("LocalizedObservable: options.write is not a function for read_write model attribute")}e=kb.utils.wrappedObservable(this,ko.dependentObservable({read:_.bind(this._onGetValue,this),write:this.write?_.bind(this._onSetValue,this):(function(){thrownewError("Knockback.LocalizedObservable: value is read only")}),owner:this.view_model}));e.destroy=_.bind(this.destroy,this);e.observedValue=_.bind(this.observedValue,this);e.setToDefault=_.bind(this.setToDefault,this);e.resetToCurrent=_.bind(this.resetToCurrent,this);kb.locale_manager.bind("change",this.__kb._onLocaleChange);returne}a.prototype.destroy=function(){kb.locale_manager.unbind("change",this.__kb._onLocaleChange);this.__kb.value_observable=null;kb.utils.wrappedObservable(this).dispose();kb.utils.wrappedObservable(this,null);this.options={};this.view_model=null;returnthis.__kb=null};a.prototype.setToDefault=function(){varc,b;if(!this["default"]){return}b=this._getDefaultValue();c=this.__kb.value_observable();if(c!==b){returnthis._onSetValue(b)}else{returnthis.__kb.value_observable.valueHasMutated()}};a.prototype.resetToCurrent=function(){this.__kb.value_observable(null);returnthis._onSetValue(this._getCurrentValue())};a.prototype.observedValue=function(b){if(arguments.length===0){returnthis.value}this.value=b;this._onLocaleChange();returnthis};a.prototype._getDefaultValue=function(){if(!this["default"]){return""}if(typeofthis["default"]==="function"){returnthis["default"]()}else{returnthis["default"]}};a.prototype._getCurrentValue=function(){varb;b=kb.utils.wrappedObservable(this);if(!(this.value&&b)){returnthis._getDefaultValue()}returnthis.read.call(this,ko.utils.unwrapObservable(this.value))};a.prototype._onGetValue=function(){if(this.value){ko.utils.unwrapObservable(this.value)}returnthis.__kb.value_observable()};a.prototype._onSetValue=function(b){this.write.call(this,b,ko.utils.unwrapObservable(this.value));b=this.read.call(this,ko.utils.unwrapObservable(this.value));this.__kb.value_observable(b);if(this.options.onChange){returnthis.options.onChange(b)}};a.prototype._onLocaleChange=function(){varb;b=this.read.call(this,ko.utils.unwrapObservable(this.value));this.__kb.value_observable(b);if(this.options.onChange){returnthis.options.onChange(b)}};returna})();Knockback.localizedObservable=function(c,b,a){returnnewKnockback.LocalizedObservable(c,b,a)};Knockback.Observable=(function(){a.name="Observable";functiona(c,d,b){vare,f=this;this.model=c;this.mapping_info=d;this.view_model=b!=null?b:{};if(!this.model){thrownewError("Observable: model is missing")}if(!this.mapping_info){thrownewError("Observable: mapping_info is missing")}if(_.isString(this.mapping_info)||ko.isObservable(this.mapping_info)){this.mapping_info={key:this.mapping_info}}if(!this.mapping_info.key){thrownewError("Observable: mapping_info.key is missing")}this.__kb={};this.__kb._onModelChange=_.bind(this._onModelChange,this);this.__kb._onModelLoaded=_.bind(this._onModelLoaded,this);this.__kb._onModelUnloaded=_.bind(this._onModelUnloaded,this);if(this.mapping_info.hasOwnProperty("write")&&_.isBoolean(this.mapping_info.write)){this.mapping_info=_.clone(this.mapping_info);this.mapping_info.read_only=!this.mapping_info.write}if(Backbone.ModelRef&&(this.modelinstanceofBackbone.ModelRef)){this.model_ref=this.model;this.model_ref.retain();this.model_ref.bind("loaded",this.__kb._onModelLoaded);this.model_ref.bind("unloaded",this.__kb._onModelUnloaded);this.model=this.model_ref.getModel()}this.__kb.value_observable=ko.observable();if(this.mapping_info.localizer){this.__kb.localizer=newthis.mapping_info.localizer(this._getCurrentValue())}e=kb.utils.wrappedObservable(this,ko.dependentObservable({read:_.bind(this._onGetValue,this),write:this.mapping_info.read_only?(function(){thrownewError("Knockback.Observable: "+f.mapping_info.key+" is read only")}):_.bind(this._onSetValue,this),owner:this.view_model}));e.destroy=_.bind(this.destroy,this);e.setToDefault=_.bind(this.setToDefault,this);if(!this.model_ref||this.model_ref.isLoaded()){this.model.bind("change",this.__kb._onModelChange)}returne}a.prototype.destroy=function(){this.__kb.value_observable=null;kb.utils.wrappedObservable(this).dispose();kb.utils.wrappedObservable(this,null);if(this.model){this.__kb._onModelUnloaded(this.model)}if(this.model_ref){this.model_ref.unbind("loaded",this.__kb._onModelLoaded);this.model_ref.unbind("unloaded",this.__kb._onModelUnloaded);this.model_ref.release();this.model_ref=null}this.mapping_info=null;this.view_model=null;returnthis.__kb=null};a.prototype.setToDefault=function(){varb;b=this._getDefaultValue();if(this.__kb.localizer){this.__kb.localizer.observedValue(b);b=this.__kb.localizer()}returnthis.__kb.value_observable(b)};a.prototype._getDefaultValue=function(){if(!this.mapping_info.hasOwnProperty("default")){return""}if(typeofthis.mapping_info["default"]==="function"){returnthis.mapping_info["default"]()}else{returnthis.mapping_info["default"]}};a.prototype._getCurrentValue=function(){varb,d,e,g,c,f;if(!this.model){returnthis._getDefaultValue()}e=ko.utils.unwrapObservable(this.mapping_info.key);d=[e];if(!_.isUndefined(this.mapping_info.args)){if(_.isArray(this.mapping_info.args)){f=this.mapping_info.args;for(g=0,c=f.length;g<c;g++){b=f[g];d.push(ko.utils.unwrapObservable(b))}}else{d.push(ko.utils.unwrapObservable(this.mapping_info.args))}}if(this.mapping_info.read){returnthis.mapping_info.read.apply(this.view_model,d)}else{returnthis.model.get.apply(this.model,d)}};a.prototype._onGetValue=function(){varb,f,e,c,d;this.__kb.value_observable();ko.utils.unwrapObservable(this.mapping_info.key);if(!_.isUndefined(this.mapping_info.args)){if(_.isArray(this.mapping_info.args)){d=this.mapping_info.args;for(e=0,c=d.length;e<c;e++){b=d[e];ko.utils.unwrapObservable(b)}}else{ko.utils.unwrapObservable(this.mapping_info.args)}}f=this._getCurrentValue();if(this.__kb.localizer){this.__kb.localizer.observedValue(f);f=this.__kb.localizer()}returnf};a.prototype._onSetValue=function(h){varb,e,d,g,c,f;if(this.__kb.localizer){this.__kb.localizer(h);h=this.__kb.localizer.observedValue()}if(this.model){d={};d[ko.utils.unwrapObservable(this.mapping_info.key)]=h;e=typeofthis.mapping_info.write==="function"?[h]:[d];if(!_.isUndefined(this.mapping_info.args)){if(_.isArray(this.mapping_info.args)){f=this.mapping_info.args;for(g=0,c=f.length;g<c;g++){b=f[g];e.push(ko.utils.unwrapObservable(b))}}else{e.push(ko.utils.unwrapObservable(this.mapping_info.args))}}if(typeofthis.mapping_info.write==="function"){this.mapping_info.write.apply(this.view_model,e)}else{this.model.set.apply(this.model,e)}}if(this.__kb.localizer){returnthis.__kb.value_observable(this.__kb.localizer())}else{returnthis.__kb.value_observable(h)}};a.prototype._modelBind=function(b){if(!b){return}b.bind("change",this.__kb._onModelChange);if(Backbone.RelationalModel&&(binstanceofBackbone.RelationalModel)){b.bind("add",this.__kb._onModelChange);b.bind("remove",this.__kb._onModelChange);returnb.bind("update",this.__kb._onModelChange)}};a.prototype._modelUnbind=function(b){if(!b){return}b.unbind("change",this.__kb._onModelChange);if(Backbone.RelationalModel&&(binstanceofBackbone.RelationalModel)){b.unbind("add",this.__kb._onModelChange);b.unbind("remove",this.__kb._onModelChange);returnb.unbind("update",this.__kb._onModelChange)}};a.prototype._onModelLoaded=function(b){this.model=b;this._modelBind(b);returnthis._updateValue()};a.prototype._onModelUnloaded=function(b){if(this.__kb.localizer&&this.__kb.localizer.destroy){this.__kb.localizer.destroy();this.__kb.localizer=null}this._modelUnbind(b);returnthis.model=null};a.prototype._onModelChange=function(){if((this.model&&this.model.hasChanged)&&!this.model.hasChanged(ko.utils.unwrapObservable(this.mapping_info.key))){return}returnthis._updateValue()};a.prototype._updateValue=function(){varb;b=this._getCurrentValue();if(this.__kb.localizer){this.__kb.localizer.observedValue(b);b=this.__kb.localizer()}returnthis.__kb.value_observable(b)};returna})();Knockback.observable=function(b,c,a){returnnewKnockback.Observable(b,c,a)};Knockback.Observables=(function(){a.name="Observables";functiona(e,g,k,j){varh,i,f,c,d,b;if(!e){thrownewError("Observables: model is missing")}if(!g||!_.isObject(g)){thrownewError("Observables: mappings_info is missing")}this.__kb||(this.__kb={});this.__kb.model=e;this.__kb.mappings_info=g;this.__kb.view_model=_.isUndefined(k)?this:k;if(!_.isUndefined(j)&&j.hasOwnProperty("write")){kb.utils.legacyWarning("Knockback.Observables option.write","0.16.0","Now default is writable so only supply read_only as required");j.read_only=!j.write;deletej.write}if(!_.isUndefined(j)){c=_.isBoolean(j)?j:j.read_only;d=this.__kb.mappings_info;for(find){i=d[f];h=_.isString(i);if(h){i=!_.isUndefined(c)?{key:i,read_only:c}:{key:i}}else{if(!_.isUndefined(c)&&!(i.hasOwnProperty("read_only")||i.hasOwnProperty("write"))){i.read_only=c}}if(!i.hasOwnProperty("key")){i.key=f}this[f]=this.__kb.view_model[f]=kb.observable(this.__kb.model,i,this.__kb.view_model)}}else{b=this.__kb.mappings_info;for(finb){i=b[f];if(i.hasOwnProperty("write")){kb.utils.legacyWarning("Knockback.Observables option.write","0.16.0","Now default is writable so only supply read_only as required")}if(!i.hasOwnProperty("key")){i.key=f}this[f]=this.__kb.view_model[f]=kb.observable(this.__kb.model,i,this.__kb.view_model)}}}a.prototype.destroy=function(){varc,b,d;d=this.__kb.mappings_info;for(bind){c=d[b];if(this.__kb.view_model[b]){this.__kb.view_model[b].destroy()}this.__kb.view_model[b]=null;this[b]=null}this.__kb.view_model=null;this.__kb.mappings_info=null;returnthis.__kb.model=null};a.prototype.setToDefault=function(){vard,b,e,c;e=this.__kb.mappings_info;c=[];for(bine){d=e[b];c.push(this.__kb.view_model[b].setToDefault())}returnc};returna})();Knockback.observables=function(c,d,a,b){returnnewKnockback.Observables(c,d,a,b)};Knockback.TriggeredObservable=(function(){a.name="TriggeredObservable";functiona(b,d){varc;this.model=b;this.event_name=d;if(!this.model){thrownewError("Observable: model is missing")}if(!this.event_name){thrownewError("Observable: event_name is missing")}this.__kb={};this.__kb._onValueChange=_.bind(this._onValueChange,this);this.__kb._onModelLoaded=_.bind(this._onModelLoaded,this);this.__kb._onModelUnloaded=_.bind(this._onModelUnloaded,this);if(Backbone.ModelRef&&(this.modelinstanceofBackbone.ModelRef)){this.model_ref=this.model;this.model_ref.retain();this.model_ref.bind("loaded",this.__kb._onModelLoaded);this.model_ref.bind("unloaded",this.__kb._onModelUnloaded);this.model=this.model_ref.getModel()}this.__kb.value_observable=ko.observable();c=kb.utils.wrappedObservable(this,ko.dependentObservable(_.bind(this._onGetValue,this)));c.destroy=_.bind(this.destroy,this);if(!this.model_ref||this.model_ref.isLoaded()){this._onModelLoaded(this.model)}returnc}a.prototype.destroy=function(){kb.utils.wrappedObservable(this).dispose();kb.utils.wrappedObservable(this,null);this.__kb.value_observable=null;if(this.model){this._onModelUnloaded(this.model)}if(this.model_ref){this.model_ref.unbind("loaded",this.__kb._onModelLoaded);this.model_ref.unbind("unloaded",this.__kb._onModelUnloaded);this.model_ref.release();this.model_ref=null}this.options=null;this.view_model=null;returnthis.__kb=null};a.prototype._onGetValue=function(){returnthis.__kb.value_observable()};a.prototype._onModelLoaded=function(b){this.model=b;this.model.bind(this.event_name,this.__kb._onValueChange);returnthis._onValueChange()};a.prototype._onModelUnloaded=function(){if(this.__kb.localizer&&this.__kb.localizer.destroy){this.__kb.localizer.destroy();this.__kb.localizer=null}this.model.unbind(this.event_name,this.__kb._onValueChange);returnthis.model=null};a.prototype._onValueChange=function(){varb;b=this.__kb.value_observable();if(b!==this.model){returnthis.__kb.value_observable(this.model)}else{returnthis.__kb.value_observable.valueHasMutated()}};returna})();Knockback.triggeredObservable=function(a,b){returnnewKnockback.TriggeredObservable(a,b)};var__hasProp={}.hasOwnProperty,__extends=function(d,b){for(varainb){if(__hasProp.call(b,a)){d[a]=b[a]}}functionc(){this.constructor=d}c.prototype=b.prototype;d.prototype=newc;d.__super__=b.prototype;returnd};Knockback.AttributeConnector=(function(){a.name="AttributeConnector";functiona(c,d,b){vare;this.key=d;this.options=b!=null?b:{};kb.utils.wrappedModel(this,c);this.options=_.clone(this.options);this.__kb.value_observable=ko.observable();e=kb.utils.wrappedObservable(this,ko.dependentObservable({read:_.bind(this.read,this),write:_.bind(this.write,this)}));e.destroy=_.bind(this.destroy,this);e.model=_.bind(this.model,this);e.update=_.bind(this.update,this);this.__kb.initializing=true;this.update();this.__kb.initializing=false;returne}a.prototype.destroy=function(){this.__kb.value_observable=null;kb.utils.wrappedObservable(this).dispose();returnkb.utils.wrappedObservable(this,null)};a.prototype.read=function(){returnthis.__kb.value_observable()};a.prototype.write=function(d){varc,b;c=kb.utils.wrappedModel(this);if(!c){return}if(this.options.read_only){if(!this.__kb.initializing){throw"Cannot write a value to a dependentObservable unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters."}}else{b={};b[this.key]=d;returnc.set(b)}};a.prototype.model=function(b){varc;c=kb.utils.wrappedModel(this);if(arguments.length===0){returnc}if(c===b){return}kb.utils.wrappedModel(this,b);returnthis.update()};a.inferType=function(b,c){vard,e;e=b.get(c);if(!e){if(!(Backbone.RelationalModel&&(binstanceofBackbone.RelationalModel))){return"simple"}d=_.find(b.getRelations(),function(f){returnf.key===c});if(!d){return"simple"}if(d.collectionKey){return"collection"}else{return"model"}}if(einstanceofBackbone.Collection){return"collection"}if((einstanceofBackbone.Model)||(Backbone.ModelRef&&(einstanceofBackbone.ModelRef))){return"model"}return"simple"};a.createByType=function(e,c,d,b){varf;switch(e){case"collection":f=b?_.clone(b):{};if(!(b.view_model||b.view_model_create||b.children||b.create)){f.view_model=kb.ViewModel}if(b.store){b.store.addResolverToOptions(f,c.get(d))}returnkb.collectionAttributeConnector(c,d,f);case"model":f=b?_.clone(b):{};if(!f.options){f.options={}}if(!(b.view_model||b.view_model_create||b.children||b.create)){f.view_model=kb.ViewModel}if(b.store){b.store.addResolverToOptions(f.options,c.get(d))}returnkb.viewModelAttributeConnector(c,d,f);default:returnkb.simpleAttributeConnector(c,d,b)}};a.createOrUpdate=function(f,c,d,b){varg,e;if(f){if(kb.utils.observableInstanceOf(f,kb.AttributeConnector)){if(f.model()!==c){f.model(c)}else{f.update()}}returnf}if(!c){returnkb.simpleAttributeConnector(c,d,b)}if(b.hasOwnProperty("create")){if(!b.create){thrownewError("Knockback.AttributeConnector: options.create is empty")}returnb.create(c,d,b.options||{})}e=c.get(d);if(b.hasOwnProperty("view_model")){if(!b.view_model){thrownewError("Knockback.AttributeConnector: options.view_model is empty")}returnnewb.view_model(e,b.options||{})}else{if(b.hasOwnProperty("view_model_create")){if(!b.view_model_create){thrownewError("Knockback.AttributeConnector: options.view_model_create is empty")}returnb.view_model_create(e,b.options||{})}else{if(b.hasOwnProperty("children")){if(!b.children){thrownewError("Knockback.AttributeConnector: options.children is empty")}if(typeofb.children==="function"){g={view_model:b.children}}else{g=b.children||{}}returnkb.collectionAttributeConnector(c,d,g)}}}returnthis.createByType(this.inferType(c,d),c,d,b)};returna})();Knockback.SimpleAttributeConnector=(function(b){__extends(a,b);a.name="SimpleAttributeConnector";functiona(){a.__super__.constructor.apply(this,arguments);returnkb.utils.wrappedObservable(this)}a.prototype.destroy=function(){this.current_value=null;returna.__super__.destroy.apply(this,arguments)};a.prototype.update=function(){vard,c,e;c=kb.utils.wrappedModel(this);if(!c){return}e=c.get(this.key);d=this.__kb.value_observable();if(!_.isEqual(d,e)){returnthis.__kb.value_observable(e)}};a.prototype.write=function(d){varc;c=kb.utils.wrappedModel(this);if(!c){this.__kb.value_observable(d);return}returna.__super__.write.apply(this,arguments)};returna})(Knockback.AttributeConnector);Knockback.simpleAttributeConnector=function(b,c,a){returnnewKnockback.SimpleAttributeConnector(b,c,a)};Knockback.CollectionAttributeConnector=(function(a){__extends(b,a);b.name="CollectionAttributeConnector";functionb(){b.__super__.constructor.apply(this,arguments);returnkb.utils.wrappedObservable(this)}b.prototype.destroy=function(){varc;c=this.__kb.value_observable();if(c&&(typeofc.refCount==="function")&&(c.refCount()>0)){c.release()}returnb.__super__.destroy.apply(this,arguments)};b.prototype.update=function(){vard,c,e,f=this;c=kb.utils.wrappedModel(this);if(!c){return}e=c.get(this.key);d=this.__kb.value_observable();if(!d){if(this.options.store){returnthis.__kb.value_observable(this.options.store.resolveValue(e,function(){returnkb.collectionObservable(e,f.options)}))}else{returnthis.__kb.value_observable(kb.collectionObservable(e,this.options))}}else{if(d.collection()!==e){d.collection(e);returnthis.__kb.value_observable.valueHasMutated()}}};b.prototype.read=function(){varc;c=this.__kb.value_observable();if(c){returnc()}else{return}};returnb})(Knockback.AttributeConnector);Knockback.collectionAttributeConnector=function(b,c,a){returnnewKnockback.CollectionAttributeConnector(b,c,a)};Knockback.ViewModelAttributeConnector=(function(b){__extends(a,b);a.name="ViewModelAttributeConnector";functiona(){a.__super__.constructor.apply(this,arguments);returnkb.utils.wrappedObservable(this)}a.prototype.destroy=function(){varc;c=this.__kb.value_observable();if(c&&(typeofc.refCount==="function")&&(c.refCount()>0)){c.release()}returna.__super__.destroy.apply(this,arguments)};a.prototype.update=function(){vard,c,e,f,g=this;c=kb.utils.wrappedModel(this);if(!c){return}e=c.get(this.key);d=this.__kb.value_observable();if(!d){f=this.options.options?_.clone(this.options.options):{};if(f.store){returnthis.__kb.value_observable(f.store.resolveValue(e,function(){if(g.options.view_model){returnnewg.options.view_model(e,f)}else{returng.options.view_model_create(e,f)}}))}else{returnthis.__kb.value_observable(this.options.view_model?newthis.options.view_model(e,f):this.options.view_model_create(e,f))}}else{if(!(d.model&&(typeofd.model==="function"))){thrownewError("Knockback.viewModelAttributeConnector: unknown how to model a view model")}if(d.model()!==e){d.model(e);returnthis.__kb.value_observable.valueHasMutated()}}};returna})(Knockback.AttributeConnector);Knockback.viewModelAttributeConnector=function(b,c,a){returnnewKnockback.ViewModelAttributeConnector(b,c,a)};var__hasProp={}.hasOwnProperty,__extends=function(d,b){for(varainb){if(__hasProp.call(b,a)){d[a]=b[a]}}functionc(){this.constructor=d}c.prototype=b.prototype;d.prototype=newc;d.__super__=b.prototype;returnd};Knockback.ViewModel_RCBase=(function(b){__extends(a,b);a.name="ViewModel_RCBase";functiona(){returna.__super__.constructor.apply(this,arguments)}a.prototype.__destroy=function(){vard,e,c;c=[];for(dinthis){e=this[d];if(!e||(d==="__kb")){continue}if(kb.utils.release(e)){c.push(this[d]=null)}else{c.push(void0)}}returnc};returna})(Knockback.RefCountable);Knockback.ViewModel=(function(b){__extends(a,b);a.name="ViewModel";functiona(e,d){varg,f,h,c;if(d==null){d={}}a.__super__.constructor.apply(this,arguments);if(Knockback.stats_on){kb.stats.view_models++}if(!d.store_skip_resolve){kb.Store.resolveFromOptions(d,this)}if(d.store){this.__kb.store=d.store}else{this.__kb.store=newkb.Store();this.__kb.store_is_owned=true}this.__kb._onModelChange=_.bind(this._onModelChange,this);this.__kb._onModelLoaded=_.bind(this._onModelLoaded,this);this.__kb._onModelUnloaded=_.bind(this._onModelUnloaded,this);this.__kb.internals=d.internals;this.__kb.requires=d.requires;this.__kb.children=d.children;this.__kb.create=d.create;this.__kb.read_only=d.read_only;kb.utils.wrappedModel(this,e);if(Backbone.ModelRef&&(einstanceofBackbone.ModelRef)){this.__kb.model_ref=e;this.__kb.model_ref.retain();kb.utils.wrappedModel(this,this.__kb.model_ref.getModel());this.__kb.model_ref.bind("loaded",this.__kb._onModelLoaded);this.__kb.model_ref.bind("unloaded",this.__kb._onModelUnloaded)}if(this.__kb.model){this._onModelLoaded(this.__kb.model)}if(!this.__kb.internals&&!this.__kb.requires){returnthis}f=_.union((this.__kb.internals?this.__kb.internals:[]),(this.__kb.requires?this.__kb.requires:[]));if(!this.__kb.model_ref||this.__kb.model_ref.isLoaded()){f=_.difference(f,_.keys(this.__kb.model.attributes))}for(h=0,c=f.length;h<c;h++){g=f[h];this._updateAttributeConnector(this.__kb.model,g)}}a.prototype.__destroy=function(){varc;c=this.__kb.model;kb.utils.wrappedModel(this,null);this._modelUnbind(c);if(this.__kb.store_is_owned){this.__kb.store.destroy()}this.__kb.store=null;a.__super__.__destroy.apply(this,arguments);if(Knockback.stats_on){returnkb.stats.view_models--}};a.prototype.model=function(c){vard;d=kb.utils.wrappedModel(this);if(arguments.length===0){returnd}if(c===d){return}if(d){this._onModelUnloaded(d)}if(c){returnthis._onModelLoaded(c)}};a.prototype._modelBind=function(c){if(!c){return}c.bind("change",this.__kb._onModelChange);if(Backbone.RelationalModel&&(cinstanceofBackbone.RelationalModel)){c.bind("add",this.__kb._onModelChange);c.bind("remove",this.__kb._onModelChange);returnc.bind("update",this.__kb._onModelChange)}};a.prototype._modelUnbind=function(c){if(!c){return}c.unbind("change",this.__kb._onModelChange);if(Backbone.RelationalModel&&(cinstanceofBackbone.RelationalModel)){c.unbind("add",this.__kb._onModelChange);c.unbind("remove",this.__kb._onModelChange);returnc.unbind("update",this.__kb._onModelChange)}};a.prototype._onModelLoaded=function(d){vare,c;kb.utils.wrappedModel(this,d);this._modelBind(d);c=[];for(einthis.__kb.model.attributes){c.push(this._updateAttributeConnector(this.__kb.model,e))}returnc};a.prototype._onModelUnloaded=function(d){vare,c;this._modelUnbind(d);kb.utils.wrappedModel(this,null);c=[];for(eind.attributes){c.push(this._updateAttributeConnector(null,e))}returnc};a.prototype._onModelChange=function(){vare,c,d;if(this.__kb.model._changed){c=[];for(einthis.__kb.model.attributes){c.push(this.__kb.model.hasChanged(e)?this._updateAttributeConnector(this.__kb.model,e):void0)}returnc}else{if(this.__kb.model.changed){d=[];for(einthis.__kb.model.changed){d.push(this._updateAttributeConnector(this.__kb.model,e))}returnd}}};a.prototype._updateAttributeConnector=function(c,e){vard;d=this.__kb.internals&&_.contains(this.__kb.internals,e)?"_"+e:e;returnthis[d]=kb.AttributeConnector.createOrUpdate(this[d],c,e,this._createOptions(e))};a.prototype._createOptions=function(d){varc;if(this.__kb.children){if(this.__kb.children.hasOwnProperty(d)){c=this.__kb.children[d];if(typeofc==="function"){c={view_model:c}}c.options={read_only:this.__kb.read_only,store:this.__kb.store};returnc}else{if(this.__kb.children.hasOwnProperty("create")){return{create:this.__kb.children.create,options:{read_only:this.__kb.read_only,store:this.__kb.store}}}}}else{if(this.__kb.create){return{create:this.__kb.create,options:{read_only:this.__kb.read_only,store:this.__kb.store}}}}return{read_only:this.__kb.read_only,store:this.__kb.store}};returna})(Knockback.ViewModel_RCBase);Knockback.viewModel=function(b,a){returnnewKnockback.ViewModel(b,a)};