(function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Array=function(a){function c(){this.__fillData(arguments,!1)}return b(c,a),Joosy.Module.merge(c,Joosy.Module),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.load=function(){return this.__fillData(arguments)},c.prototype.get=function(a){return this[a]},c.prototype.set=function(a,b){return this[a]=b,this.trigger("changed"),b},c.prototype.push=function(){var a;return a=c.__super__.push.apply(this,arguments),this.trigger("changed"),a},c.prototype.pop=function(){var a;return a=c.__super__.pop.apply(this,arguments),this.trigger("changed"),a},c.prototype.shift=function(){var a;return a=c.__super__.shift.apply(this,arguments),this.trigger("changed"),a},c.prototype.unshift=function(){var a;return a=c.__super__.unshift.apply(this,arguments),this.trigger("changed"),a},c.prototype.splice=function(){var a;return a=c.__super__.splice.apply(this,arguments),this.trigger("changed"),a},c.prototype.__fillData=function(a,b){var c,d,e,f;for(null==b&&(b=!0),a=this.slice.call(a,0),this.length>0&&this.splice(0,this.length),f=this.__applyBeforeLoads(a),d=0,e=f.length;e>d;d++)c=f[d],this.push(c);return b&&this.trigger("changed"),null},c}(Array),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/array",function(){return Joosy.Resources.Array})}).call(this),function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Hash=function(a){function c(a){null==a&&(a={}),this.__fillData(a,!1)}return b(c,a),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.__call=function(a,b){return arguments.length>1?this.set(a,b):this.get(a)},c.prototype.load=function(a){return this.__fillData(a),this},c.prototype.get=function(a){var b,c,d;return d=this.__callTarget(a,!0),b=d[0],c=d[1],b?b.get?b.get(c):b[c]:void 0},c.prototype.set=function(a,b){var c,d,e;return e=this.__callTarget(a),c=e[0],d=e[1],null!=c.set?c.set(d,b):c[d]=b,this.trigger("changed"),b},c.prototype.__callTarget=function(a,b){var c,d,e,f,g;if(null==b&&(b=!1),-1!==a.indexOf(".")&&null==this.data[a]){for(a=a.split("."),c=a.pop(),e=this.data,f=0,g=a.length;g>f;f++){if(d=a[f],b&&null==e[d])return!1;null==e[d]&&(e[d]={}),e=e.__get?e.__get(d):e[d]}return[e,c]}return[this.data,a]},c.prototype.__fillData=function(a,b){return null==b&&(b=!0),this.data=this.__applyBeforeLoads(a),b&&this.trigger("changed"),null},c.prototype.toString=function(){return"Hash: "+JSON.stringify(this.data)},c}(Joosy.Module),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/hash",function(){return Joosy.Resources.Hash})}.call(this),function(){Joosy.Modules.Resources={}}.call(this),function(){Joosy.Modules.Resources.Model={included:function(){return this.primaryKey=function(a){return this.prototype.__primaryKey=a},this.collection=function(a){return this.prototype.__collection=a},this.entity=function(a){return this.prototype.__entityName=a},this.map=function(a,b){if(null==b&&(b=!1),b||(b=window[inflection.camelize(inflection.singularize(a))]),!b)throw new Error(""+Joosy.Module.__className(this)+"> class can not be detected for '"+a+"' mapping");return this.beforeLoad(function(c){var d;return null==b.build&&(b=b()),c[a]instanceof Array?(d=c[a].map(function(a){return b.build(a)}),c[a]=function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(b.prototype.__collection,d,function(){})):c[a]&&(c[a]=b.build(c[a])),c})},this.grab=function(a){return this.build({}).grab(a)},this.attrAccessor=function(){var a,b,c,d,e=this;for(d=[],b=0,c=arguments.length;c>b;b++)a=arguments[b],d.push(function(a){return e.prototype[a]=function(b){return b?this.set(a,b):this.get(a)}}(a));return d}},__primaryKey:"id",__collection:Joosy.Resources.Array,id:function(){var a;return null!=(a=this.data)?a[this.__primaryKey]:void 0},knownAttributes:function(){return Object.keys(this.data)},load:function(a,b){return null==b&&(b=!1),b&&(this.data={}),this.__fillData(a),this},__fillData:function(a,b){return null==b&&(b=!0),this.raw=a,this.hasOwnProperty("data")||(this.data={}),Joosy.Module.merge(this.data,this.__applyBeforeLoads(a)),b&&this.trigger("changed"),null},grab:function(a){var b,c,d,e,f;for(b={},f=$(a).serializeArray(),d=0,e=f.length;e>d;d++)c=f[d],b[c.name]?(b[c.name]instanceof Array||(b[c.name]=[b[c.name]]),b[c.name].push(c.value)):b[c.name]=c.value;return this.load(b)},toString:function(){return" "+JSON.stringify(this.data)}}}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a},d=[].slice;Joosy.Resources.REST=function(b){function e(){return a=e.__super__.constructor.apply(this,arguments)}return c(e,b),e.include(Joosy.Modules.Resources.Model),e.registerPlainFilters("beforeSave"),e.beforeLoad(function(a){var b;return a.constructor===Object&&1===Object.keys(a).length&&this.__entityName&&(b=inflection.camelize(this.__entityName,!0),a[b]&&(a=a[b])),a}),e.requestOptions=function(a){return this.prototype.__requestOptions=a},e.source=function(a){return this.__source=a},e.__atWrapper=function(){var a,b,c=this;return b=arguments[0],a=2<=arguments.length?d.call(arguments,1):[],1===a.length&&a[0]instanceof Array?this.__atWrapper.apply(this,[b].concat(d.call(a[0]))):b(function(b){return b.__source=a.reduce(function(a,b){return a+=Joosy.Module.hasAncestor(b.constructor,Joosy.Resources.REST)?b.memberPath():b.replace(/^\/?/,"/")},""),b.__source+="/"+inflection.pluralize(c.prototype.__entityName)})},e.at=function(){var a=this;return this.__atWrapper.apply(this,[function(b){var d,e;return d=function(a){function d(){return e=d.__super__.constructor.apply(this,arguments)}return c(d,a),b(d),d}(a)}].concat(d.call(arguments)))},e.prototype.at=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],new((b=this.constructor).at.apply(b,a))(this.data)},e.prototype.__interpolatePath=function(a,b){return b instanceof Array||(b=[b]),b.reduce(function(a,b){return b instanceof Joosy.Resources.REST&&(b=b.id()),a.replace(/:[^\/]+/,b)},a)},e.collectionPath=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],(b=this.prototype).collectionPath.apply(b,a)},e.prototype.collectionPath=function(a,b){var c,d;return null==a&&(a=[]),null==b&&(b={}),a.constructor===Object&&(b=a,a=[]),b.url?b.url:(d=this.__source||this.constructor.__source,d?c=this.__interpolatePath(d,a):(c="/",this.constructor.__namespace__.length>0&&(c+=this.constructor.__namespace__.map(String.prototype.underscore).join("/")+"/"),c+=inflection.pluralize(this.__entityName)),b.action&&(c+="/"+b.action),c)},e.memberPath=function(){var a,b;return a=1<=arguments.length?d.call(arguments,0):[],(b=this.prototype).memberPath.apply(b,a)},e.prototype.memberPath=function(a,b){var c,d,e;return null==a&&(a=[]),null==b&&(b={}),a.constructor===Object&&(b=a,a=[]),b.url?b.url:(a instanceof Array||(a=[a]),d=this.id()||a.pop(),c=b.action,a.push(this.id()),e=this.collectionPath(a,Joosy.Module.merge(b,{action:void 0}))+("/"+d),null!=c&&(e+="/"+c),e)},e.send=function(a,b,c){var d;return d=this.prototype.__extractOptionsAndCallback(b,c),b=d[0],c=d[1],this.__query(this.collectionPath(b),a.toUpperCase(),b.params,c)},e.prototype.send=function(a,b,c){var d;return d=this.__extractOptionsAndCallback(b,c),b=d[0],c=d[1],this.constructor.__query(this.memberPath(b),a.toUpperCase(),b.params,c)},e.prototype.reload=function(a,b){var c,d=this;return null==a&&(a={}),null==b&&(b=!1),c=this.__extractOptionsAndCallback(a,b),a=c[0],b=c[1],this.constructor.__query(this.memberPath(a),"GET",a.params,function(a,c,e){return null!=c&&d.load(c),"function"==typeof b?b(a,d,c,e):void 0})},e.find=function(a,b,c){var d,e;return null==b&&(b={}),null==c&&(c=!1),e=this.prototype.__extractOptionsAndCallback(b,c),b=e[0],c=e[1],d={},d[this.prototype.__primaryKey]=a instanceof Array?a[a.length-1]:a,d=this.build(d),a instanceof Array&&a.length>1&&(d.__source=this.collectionPath(a)),this.__query(this.memberPath(a,b),"GET",b.params,function(a,b,e){return null!=b&&d.load(b),"function"==typeof c?c(a,d,b,e):void 0}),d},e.all=function(a,b,c){var d,e,f,g=this;return null==b&&(b={}),null==c&&(c=!1),"function"==typeof a||a.constructor===Object?(e=this.prototype.__extractOptionsAndCallback(a,b),b=e[0],c=e[1],a=[]):(f=this.prototype.__extractOptionsAndCallback(b,c),b=f[0],c=f[1]),d=new this.prototype.__collection,this.__query(this.collectionPath(a,b),"GET",b.params,function(b,e,f){var h;if(null!=(h=e)){if(h.constructor===Object&&!(h=h[inflection.pluralize(g.prototype.__entityName)]))throw new Error("Invalid data for `all` received: "+JSON.stringify(h));h=h.map(function(b){var c;return c=g.build(b),a.length>1&&(c.__source=g.collectionPath(a)),c}),d.load.apply(d,h)}return"function"==typeof c?c(b,d,e,f):void 0}),d},e.prototype.update=function(a){var b=this;return this.send("put",{params:this.__applyBeforeSaves(this.data)},function(c,d){return c||b.load(d),"function"==typeof a?a(c,b):void 0})},e.prototype.create=function(a){var b=this;return this.constructor.send("post",{params:this.__applyBeforeSaves(this.data)},function(c,d){return c||b.load(d),"function"==typeof a?a(c,b):void 0})},e.prototype.save=function(a){return this.id()?this.update(a):this.create(a)},e.__query=function(a,b,c,d){var e;return e={url:a,data:c,type:b,cache:!1,dataType:"json"},"function"==typeof d?(e.success=function(a,b,c){return d(!1,a,c)},e.error=function(a){return d(a)}):Joosy.Module.merge(e,d),this.prototype.__requestOptions instanceof Function?this.prototype.__requestOptions(e):this.prototype.__requestOptions&&Joosy.Module.merge(e,this.prototype.__requestOptions),$.ajax(e)},e.prototype.__extractOptionsAndCallback=function(a,b){return"function"==typeof a&&(b=a,a={}),[a,b]},e}(Joosy.Resources.Hash),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/rest",function(){return Joosy.Resources.REST})}.call(this),function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b};Joosy.Resources.Scalar=function(a){function c(a){this.load(a)}return b(c,a),c.include(Joosy.Modules.Events),c.include(Joosy.Modules.Filters),c.registerPlainFilters("beforeLoad"),c.build=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})},c.prototype.__call=function(){return arguments.length>0?this.set(arguments[0]):this.get()},c.prototype.load=function(a){return this.value=this.__applyBeforeLoads(a),this.trigger("changed"),this.value},c.prototype.get=function(){return this.value},c.prototype.set=function(a){return this.value=a,this.trigger("changed")},c.prototype.valueOf=function(){return this.value.valueOf()},c.prototype.toString=function(){return this.value.toString()},c}(Joosy.Module),null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/resources/scalar",function(){return Joosy.Resources.Scalar})}.call(this),function(){var a=[].slice;Joosy.Modules.Resources.Cacher={included:function(){return this.cache=function(a){return this.prototype.__cacheKey=a},this.fetcher=function(a){return this.prototype.__fetcher=a},this.cached=function(a,b,c){var d,e=this;return null==b&&(b=!1),null==c&&(c=!1),"function"==typeof b&&(c=b,b=void 0),b||(b=this.prototype.__cacheKey),c||(c=this.prototype.__fetcher),b&&localStorage&&localStorage[b]?(d=this.build.apply(this,JSON.parse(localStorage[b])),"function"==typeof a&&a(d),d.refresh()):this.fetch(function(b){return d=e.build.apply(e,b),"function"==typeof a?a(d):void 0})},this.fetch=function(b){var c=this;return this.prototype.__fetcher(function(){var d;return d=1<=arguments.length?a.call(arguments,0):[],c.prototype.__cacheKey&&localStorage&&(localStorage[c.prototype.__cacheKey]=JSON.stringify(d)),b(d)})}},refresh:function(a){var b=this;return this.constructor.fetch(function(c){return b.load.apply(b,c),"function"==typeof a?a(b):void 0})}},null!=("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define("joosy/modules/resources/cacher",function(){return Joosy.Modules.Resources.Cacher})}.call(this),function(){Joosy.Modules.Resources.Function={extended:function(){return this.build?this.aliasStaticMethodChain("build","function"):(this.build=this.buildWithFunction,this.buildWithoutFunction=function(){return function(a,b,c){c.prototype=a.prototype;var d=new c,e=a.apply(d,b);return Object(e)===e?e:d}(this,arguments,function(){})})},buildWithFunction:function(){var a,b,c,d;if(c=function(){return c.__call.apply(c,arguments)},b=this.buildWithoutFunction.apply(this,arguments),c.__proto__)c.__proto__=b;else for(a in b)d=b[a],c[a]=d;return c.constructor=b.constructor,c}}}.call(this),function(){Joosy.Modules.Resources.IdentityMap={extended:function(){return this.prototype.__identityHolder=this,this.aliasStaticMethodChain("build","identityMap")},identityReset:function(){return this.prototype.__identityHolder.identity={}},identityPath:function(a){return[this.prototype.__entityName,"s"+(this.__source||""),a[this.prototype.__primaryKey]]},buildWithIdentityMap:function(a){var b,c,d,e,f,g,h,i;if(null==a&&(a={}),d=this.identityPath(a),0===d.filter(function(a){return null==a}).length){for(e=null!=(g=this.prototype.__identityHolder).identity?(g=this.prototype.__identityHolder).identity:g.identity={},b=d.pop(),h=0,i=d.length;i>h;h++)c=d[h],e=null!=e[c]?e[c]:e[c]={};return f={},f[this.prototype.__primaryKey]=a[this.prototype.__primaryKey],null==e[b]&&(e[b]=this.buildWithoutIdentityMap(f)),e[b].load(a)}return this.buildWithoutIdentityMap(a)}}}.call(this),function(){}.call(this);