From 880873857057a2c27f88711332a1e3d636e9fa36 Mon Sep 17 00:00:00 2001 From: Ignacio Baixas Date: Mon, 26 Oct 2015 14:29:27 -0300 Subject: [PATCH] 1.1.11 --- CHANGELOG.md | 9 +++++++++ bower.json | 2 +- dist/angular-restmod-bundle.js | 3 ++- dist/angular-restmod-bundle.min.js | 4 ++-- dist/angular-restmod.js | 3 ++- dist/angular-restmod.min.js | 4 ++-- dist/plugins/debounced.js | 2 +- dist/plugins/debounced.min.js | 2 +- dist/plugins/dirty.js | 2 +- dist/plugins/dirty.min.js | 2 +- dist/plugins/find-many.js | 2 +- dist/plugins/find-many.min.js | 2 +- dist/plugins/nested-dirty.js | 2 +- dist/plugins/nested-dirty.min.js | 2 +- dist/plugins/paged.js | 2 +- dist/plugins/paged.min.js | 2 +- dist/plugins/preload.js | 2 +- dist/plugins/preload.min.js | 2 +- dist/styles/ams.js | 2 +- dist/styles/ams.min.js | 2 +- package.json | 2 +- 21 files changed, 33 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24769c7..42d14d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ + +### 1.1.11 (2015-10-26) + + +#### Bug Fixes + +* **Builder:** fixes `mask` modifier being removed by mistake ([dc498735](http://github.com/angular-platanus/restmod/commit/dc49873538a260f26bf503498926cc22ed7e0156)) + + ### 1.1.10 (2015-10-24) diff --git a/bower.json b/bower.json index e896114..5b732fa 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-restmod", - "version": "1.1.10", + "version": "1.1.11", "authors": [ "Ignacio Baixas " ], diff --git a/dist/angular-restmod-bundle.js b/dist/angular-restmod-bundle.js index 518d957..217b3e8 100644 --- a/dist/angular-restmod-bundle.js +++ b/dist/angular-restmod-bundle.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT @@ -2038,6 +2038,7 @@ RMModule.factory('RMBuilder', ['$injector', 'inflector', '$log', 'RMUtils', func var mappings = [ { fun: 'attrDefault', sign: ['init'] }, { fun: 'attrMask', sign: ['ignore'] }, + { fun: 'attrMask', sign: ['mask'] }, { fun: 'attrMap', sign: ['map', 'force'] }, { fun: 'attrDecoder', sign: ['decode', 'param', 'chain'] }, { fun: 'attrEncoder', sign: ['encode', 'param', 'chain'] }, diff --git a/dist/angular-restmod-bundle.min.js b/dist/angular-restmod-bundle.min.js index 2ec62e8..fbb6330 100644 --- a/dist/angular-restmod-bundle.min.js +++ b/dist/angular-restmod-bundle.min.js @@ -1,8 +1,8 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT */ -!function(a,b){"use strict";!function(a){a.module("platanus.inflector",[]).provider("inflector",[function(){function a(a,b,c){if(-1===c.indexOf(a.toLowerCase()))for(var d,e=0;d=b[e++];)if(a.match(d[0]))return a.replace(d[0],d[1]);return a}var b="en",c={en:{uncountable:["music","art","love","happiness","advice","furniture","luggage","sugar","butter","water","electricity","gas","power","currency","equipment","information","rice","money","species","series","fish","sheep","moose","deer","news"],plural:[[new RegExp("(m)an$","gi"),"$1en"],[new RegExp("(pe)rson$","gi"),"$1ople"],[new RegExp("(child)$","gi"),"$1ren"],[new RegExp("^(ox)$","gi"),"$1en"],[new RegExp("(ax|test)is$","gi"),"$1es"],[new RegExp("(octop|vir)us$","gi"),"$1i"],[new RegExp("(alias|status)$","gi"),"$1es"],[new RegExp("(bu)s$","gi"),"$1ses"],[new RegExp("(buffal|tomat|potat)o$","gi"),"$1oes"],[new RegExp("([ti])um$","gi"),"$1a"],[new RegExp("sis$","gi"),"ses"],[new RegExp("(?:([^f])fe|([lr])f)$","gi"),"$1$2ves"],[new RegExp("(hive)$","gi"),"$1s"],[new RegExp("([^aeiouy]|qu)y$","gi"),"$1ies"],[new RegExp("(x|ch|ss|sh)$","gi"),"$1es"],[new RegExp("(matr|vert|ind)ix|ex$","gi"),"$1ices"],[new RegExp("([m|l])ouse$","gi"),"$1ice"],[new RegExp("(quiz)$","gi"),"$1zes"],[new RegExp("s$","gi"),"s"],[new RegExp("$","gi"),"s"]],singular:[[new RegExp("(m)en$","gi"),"$1an"],[new RegExp("(pe)ople$","gi"),"$1rson"],[new RegExp("(child)ren$","gi"),"$1"],[new RegExp("([ti])a$","gi"),"$1um"],[new RegExp("((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$","gi"),"$1$2sis"],[new RegExp("(hive)s$","gi"),"$1"],[new RegExp("(tive)s$","gi"),"$1"],[new RegExp("(curve)s$","gi"),"$1"],[new RegExp("([lr])ves$","gi"),"$1f"],[new RegExp("([^fo])ves$","gi"),"$1fe"],[new RegExp("([^aeiouy]|qu)ies$","gi"),"$1y"],[new RegExp("(s)eries$","gi"),"$1eries"],[new RegExp("(m)ovies$","gi"),"$1ovie"],[new RegExp("(x|ch|ss|sh)es$","gi"),"$1"],[new RegExp("([m|l])ice$","gi"),"$1ouse"],[new RegExp("(bus)es$","gi"),"$1"],[new RegExp("(o)es$","gi"),"$1"],[new RegExp("(shoe)s$","gi"),"$1"],[new RegExp("(cris|ax|test)es$","gi"),"$1is"],[new RegExp("(octop|vir)i$","gi"),"$1us"],[new RegExp("(alias|status)es$","gi"),"$1"],[new RegExp("^(ox)en","gi"),"$1"],[new RegExp("(vert|ind)ices$","gi"),"$1ex"],[new RegExp("(matr)ices$","gi"),"$1ix"],[new RegExp("(quiz)zes$","gi"),"$1"],[new RegExp("s$","gi"),""]]}};return{registerLocale:function(a,b){c[a]=b},setLocale:function(a){b=a},$get:["$log",function(d){function e(a){a=a||b;var e=c[a];return e||d.warn("Invalid inflector locale "+a),e}return{camelize:function(a,b){return"string"!=typeof a?a:a.replace(/(?:^[-_\s]*|[-_\s]+)([A-Z\d])/gi,function(a,c,d){return b||0!==d?c.toUpperCase():c})},parameterize:function(a,b){return"string"!=typeof a?a:a.replace(/(?:[A-Z]+|[0-9]+)/g,function(a,c){return 0===c?a:(b||"-")+a}).toLowerCase()},dasherize:function(a,b){return a.replace(/[-_\s]+/g,b||"-")},singularize:function(b,c){var d=e(c);return d?a(b,d.singular,d.uncountable):b},pluralize:function(b,c){var d=e(c);return d?a(b,d.plural,d.uncountable):b}}}]}}])}(a);var c=a.module("restmod",["ng","platanus.inflector"]);c.provider("restmod",[function(){function b(a){return function(b){b.invoke(a,this,{$builder:this})}}var c=["RMBuilderExt","RMBuilderRelations","RMBuilderComputed"];return{rebase:function(){var d,e,f=arguments.length;for(e=0;f>e;e++)d=arguments[e],(a.isArray(d)||a.isFunction(d))&&(d=b(d)),c.push(d);return this},$get:["RMModelFactory","$log",function(a,b){var d=Array.prototype.slice,e={model:function(e){var f=a(e,c);return arguments.length>1&&(f.mix(d.call(arguments,1)),b.warn("Passing mixins and definitions in the model method will be deprecated in restmod 1.2, use restmod.model().mix() instead.")),f},mixin:function(){return{$isAbstract:!0,$$chain:d.call(arguments,0)}},singleton:function(a){return e.model.apply(this,arguments).single(a)}};return e}]}}]).factory("model",["restmod",function(a){return a.model}]).factory("mixin",["restmod",function(a){return a.mixin}]),c.factory("RMCollectionApi",["RMUtils",function(c){var d=a.extend;return{$isCollection:!0,$initialize:function(){this.$dispatch("after-collection-init")},$decode:function(b,d){c.assert(b&&a.isArray(b),"Collection $decode expected array");for(var e=0,f=b.length;f>e;e++)this.$buildRaw(b[e],d).$reveal();return this.$dispatch("after-feed-many",[b]),this},$encode:function(a){for(var b=[],c=0,d=this.length;d>c;c++)b.push(this[c].$encode(a));return this.$dispatch("before-render-many",[b]),b},$clear:function(){return this.$always(function(){this.length=0})},$fetch:function(a){return this.$action(function(){var b={method:"GET",url:this.$url("fetchMany"),params:this.$params};a&&(b.params=b.params?d(b.params,a):a),this.$dispatch("before-fetch-many",[b]).$send(b,function(a){this.$unwrap(a.data).$dispatch("after-fetch-many",[a])},function(a){this.$dispatch("after-fetch-many-error",[a])})})},$add:function(a,d){return c.assert(a.$type&&a.$type===this.$type,"Collection $add expects record of the same $type"),this.$action(function(){a.$position===b&&(d!==b?this.splice(d,0,a):this.push(a),a.$position=!0,this.$dispatch("after-add",[a]))})},$remove:function(a){return this.$action(function(){var c=this.$indexOf(a);-1!==c&&(this.splice(c,1),a.$position=b,this.$dispatch("after-remove",[a]))})},$indexOf:function(a,b){var d="function"!=typeof a?function(b){return b===a}:a;return c.indexWhere(this,d,b)}}}]),c.factory("RMCommonApi",["$http","RMFastQ","$log","RMUtils",function(c,d,e,f){function g(a,c){var d=a.$dispatcher();return function(e){var f=a.$promise;a.$promise=b;try{a.$last=e;var g=d?a.$decorate(d,c,[a]):c.call(a,a);return g===b?a.$promise:g}finally{a.$promise=f}}}var h=[],i={$url:function(a){if(a){if(a="$"+a+"UrlFor",this.$scope[a])return this.$scope[a](this)}else if(this.$scope.$canonicalUrlFor)return this.$scope.$canonicalUrlFor(this);return this.$scope.$urlFor(this)},$dispatch:function(a,c,d){var e,f,g,i=this.$$dsp;if(d||(d=this),i&&(this.$$dsp=b,i(a,c,d)),this.$$cb&&(e=this.$$cb[a]))for(f=0;g=e[f];f++)g.apply(d,c||h);return this.$scope&&this.$scope.$dispatch?this.$scope.$dispatch(a,c,d):this.$type&&this.$type.$dispatch(a,c,d),this.$$dsp=i,this},$on:function(a,b){var c=(this.$$cb||(this.$$cb={}))[a]||(this.$$cb[a]=[]);return c.push(b),this},$off:function(a,b){if(this.$$cb&&this.$$cb[a]){var c=f.indexWhere(this.$$cb[a],function(a){return a===b});-1!==c&&this.$$cb[a].splice(c,1)}return this},$decorate:function(a,b,c){var d=this.$$dsp;this.$$dsp="function"!=typeof a&&a?function(b,c,e){d&&d.apply(null,arguments);var f=a[b];f&&f.apply(e,c||h)}:a;try{return b.apply(this,c)}finally{this.$$dsp=d}},$dispatcher:function(){return this.$$dsp},$asPromise:function(){var a=this;return this.$promise?this.$promise.then(function(){return a},function(){return d.reject(a)}):d.when(this)},$then:function(a,b){return this.$promise=this.$promise?this.$promise.then(a?g(this,a):a,b?g(this,b):b):d.when(g(this,a)(this)),this},$always:function(a){return this.$then(a,a)},$finally:function(a){return this.$promise=this.$promise["finally"](g(this,a)),this},$send:function(a,b,f){this.$type.getProperty("style")||e.warn("No API style base was selected, see the Api Integration FAQ for more information on this warning");var h=this.$$action;return this.$always(function(){return this.$response=null,this.$status="pending",this.$dispatch("before-request",[a]),c(a).then(g(this,function(){return h&&h.canceled?(this.$status="canceled",this.$dispatch("after-request-cancel",[]),d.reject(this)):(this.$status="ok",this.$response=this.$last,this.$dispatch("after-request",[this.$response]),b&&b.call(this,this.$response),void 0)}),g(this,function(){return h&&h.canceled?(this.$status="canceled",this.$dispatch("after-request-cancel",[])):(this.$status="error",this.$response=this.$last,this.$dispatch("after-request-error",[this.$response]),f&&f.call(this,this.$response)),d.reject(this)}))})},$action:function(a){var b={canceled:!1},c=this.$pending||(this.$pending=[]);return c.push(b),this.$always(function(){var c=this.$$action;try{return b.canceled?d.reject(this):(this.$$action=b,a.call(this))}finally{this.$$action=c}}).$finally(function(){c.splice(c.indexOf(b),1)})},$cancel:function(){return this.$pending&&a.forEach(this.$pending,function(a){a.canceled=!0}),this},$hasPendingActions:function(){var b=0;return this.$pending&&a.forEach(this.$pending,function(a){a.canceled||b++}),b>0}};return i}]),c.factory("RMExtendedApi",["$q","RMPackerCache",function(a,b){return{$decode:function(a,b){return this.$resolved===!1&&this.$clear&&this.$clear(),this.$super(a,b),this.$resolved=!0,this},$unwrap:function(a,c){try{return b.prepare(),a=this.$type.unpack(this,a),this.$decode(a,c)}finally{b.clear()}},$wrap:function(a){var b=this.$encode(a);return b=this.$type.pack(this,b)},$reset:function(){return this.$cancel().$action(function(){this.$resolved=!1})},$resolve:function(a){return this.$action(function(){this.$dispatch("before-resolve",[]),this.$resolved||this.$fetch(a)})},$refresh:function(a){return this.$reset().$fetch(a)}}}]),c.factory("RMListApi",[function(){return{$asList:function(a){var b=this.$type.list(),c=this.$asPromise();return b.$promise=c.then(function(c){b.push.apply(b,a?a(c):c)}),b}}}]),c.factory("RMRecordApi",["RMUtils",function(a){var c=function(b,c,d){this.$scope=b,this.$target=c,this.$partial=a.cleanUrl(d)};return c.prototype={$nestedUrl:function(){return a.joinUrl(this.$scope.$url(),this.$partial)},$urlFor:function(a){return a.$isCollection||this.$target.isNested()?this.$nestedUrl():this.$target.$urlFor(a)},$fetchUrlFor:function(){return this.$nestedUrl()},$createUrlFor:function(){return null}},{$initialize:function(){this.$super(),this.$dispatch("after-init")},$isNew:function(){return this.$pk===b||null===this.$pk},$buildUrl:function(b){return this.$isNew()?null:a.joinUrl(b.$url(),this.$pk+"")},$buildScope:function(a,b){return a.$buildOwnScope?void 0:new c(this,a,b)},$each:function(a,b){for(var c in this)this.hasOwnProperty(c)&&"$"!==c[0]&&a.call(b||this[c],this[c],c);return this},$decode:function(b,c){return a.assert(b&&"object"==typeof b,"Record $decode expected an object"),this.$type.decode(this,b,c||a.READ_MASK),this.$isNew()&&(this.$pk=this.$type.inferKey(b)),this.$dispatch("after-feed",[b]),this},$encode:function(b){var c=this.$type.encode(this,b||a.CREATE_MASK);return this.$dispatch("before-render",[c]),c},$fetch:function(b){return this.$action(function(){var c=this.$url("fetch");a.assert(!!c,"Cant $fetch if resource is not bound");var d={method:"GET",url:c,params:b};this.$dispatch("before-fetch",[d]),this.$send(d,function(a){this.$unwrap(a.data),this.$dispatch("after-fetch",[a])},function(a){this.$dispatch("after-fetch-error",[a])})})},$extend:function(a){return this.$action(function(){for(var b in a)a.hasOwnProperty(b)&&"$"!==b[0]&&(this[b]=a[b])})},$update:function(a){return this.$extend(a).$save()},$save:function(c){return this.$action(function(){var d,e=this.$url("update");e?(d=c?{method:this.$type.getProperty("patchMethod","PATCH"),url:e,data:this.$wrap(function(a){a=a.replace("[]","");for(var b=0,d=c.length;d>b;b++)if(a===c[b]||0===a.indexOf(c[b]+".")||0===c[b].indexOf(a+"."))return!1;return!0})}:{method:"PUT",url:e,data:this.$wrap(a.UPDATE_MASK)},this.$dispatch("before-update",[d,!!c]).$dispatch("before-save",[d]).$send(d,function(a){a.data&&this.$unwrap(a.data),this.$dispatch("after-update",[a,!!c]).$dispatch("after-save",[a])},function(a){this.$dispatch("after-update-error",[a,!!c]).$dispatch("after-save-error",[a])})):(e=this.$url("create")||this.$scope.$url(),a.assert(!!e,"Cant $create if parent scope is not bound"),d={method:"POST",url:e,data:this.$wrap(a.CREATE_MASK)},this.$dispatch("before-save",[d]).$dispatch("before-create",[d]).$send(d,function(a){a.data&&this.$unwrap(a.data),this.$scope.$isCollection&&this.$position===b&&!this.$preventReveal&&this.$scope.$add(this,this.$revealAt),this.$dispatch("after-create",[a]).$dispatch("after-save",[a])},function(a){this.$dispatch("after-create-error",[a]).$dispatch("after-save-error",[a])}))})},$destroy:function(){return this.$action(function(){var a=this.$url("destroy");if(a){var b={method:"DELETE",url:a};this.$dispatch("before-destroy",[b]).$send(b,function(a){this.$scope.$remove&&this.$scope.$remove(this),this.$dispatch("after-destroy",[a])},function(a){this.$dispatch("after-destroy-error",[a])})}else this.$scope.$remove&&this.$scope.$remove(this)})},$moveTo:function(a){return this.$position!==b||(this.$revealAt=a),this},$reveal:function(a){return a===b||a?this.$scope.$add(this,this.$revealAt):this.$preventReveal=!0,this}}}]),c.factory("RMScopeApi",["RMUtils",function(){return{$urlFor:function(a){var b=this.$type.isNested()?this:this.$type;return"function"==typeof a.$buildUrl?a.$buildUrl(b):b.$url()},$new:function(a,b){return this.$super(a,b)},$build:function(a){return this.$new().$extend(a)},$buildRaw:function(a,b){var c=this.$new(this.$type.inferKey(a));return c.$decode(a,b),c},$find:function(a,b){return this.$new(a).$resolve(b)},$create:function(a){return this.$build(a).$save()},$collection:function(a,b){return this.$super(a,b)},$search:function(a){return this.$collection(a).$fetch()}}}]),c.factory("RMBuilder",["$injector","inflector","$log","RMUtils",function(b,c,d,e){function f(a){var b=[{fun:"attrDefault",sign:["init"]},{fun:"attrMask",sign:["ignore"]},{fun:"attrMap",sign:["map","force"]},{fun:"attrDecoder",sign:["decode","param","chain"]},{fun:"attrEncoder",sign:["encode","param","chain"]},{fun:"attrVolatile",sign:["volatile"]}];this.dsl=k(a,{describe:function(a){return g(a,function(a,b){switch(b.charAt(0)){case"@":d.warn("Usage of @ in description objects will be removed in 1.2, use a $extend block instead"),this.define("Scope."+b.substring(1),a);break;case"~":b=c.parameterize(b.substring(1)),d.warn("Usage of ~ in description objects will be removed in 1.2, use a $hooks block instead"),this.on(b,a);break;default:if("$config"===b)for(var e in a)a.hasOwnProperty(e)&&this.setProperty(e,a[e]);else if("$extend"===b)for(var e in a)a.hasOwnProperty(e)&&this.define(e,a[e]);else if("$hooks"===b)for(var e in a)a.hasOwnProperty(e)&&this.on(e,a[e]);else l.test(b)?(d.warn("Usage of ~ in description objects will be removed in 1.2, use a $config block instead"),b=c.camelize(b.toLowerCase()),this.setProperty(b,a)):h(a)?this.attribute(b,a):j(a)?this.define(b,a):this.attrDefault(b,a)}},this),this},extend:function(a,c,d){return"string"==typeof a?(this[a]=e.override(this[name],c),d&&b.push({fun:a,sign:d})):e.extendOverriden(this,a),this},attribute:function(a,c){for(var d,e=0;d=b[e++];)if(c.hasOwnProperty(d.sign[0])){for(var f=[a],g=0;gb;b++)this.mixin(a[b])},mixin:function(a){a.$$chain?this.chain(a.$$chain):"string"==typeof a?this.mixin(b.get(a)):i(a)?this.chain(a):j(a)?a.call(this.dsl,b):this.dsl.describe(a)}},f}]),c.factory("RMBuilderComputed",["restmod",function(a){var b={attrAsComputed:function(a,b){return this.attrComputed(a,b),this}};return a.mixin(function(){this.extend("attrAsComputed",b.attrAsComputed,["computed"])})}]),c.factory("RMBuilderExt",["$injector","$parse","inflector","$log","restmod",function(b,c,d,e,f){var g=a.bind,h=a.isFunction,i={setUrlPrefix:function(a){return this.setProperty("urlPrefix",a)},setPrimaryKey:function(a){return this.setProperty("primaryKey",a)},attrSerializer:function(a,c,e){return"string"==typeof c&&(c=b.get(d.camelize(c,!0)+"Serializer")),h(c)&&(c=c(e)),c.decode&&this.attrDecoder(a,g(c,c.decode)),c.encode&&this.attrEncoder(a,g(c,c.encode)),this},attrExpression:function(a,b){var d=c(b);return this.on("after-feed",function(){this[a]=d(this)})}};return f.mixin(function(){this.extend("setUrlPrefix",i.setUrlPrefix).extend("setPrimaryKey",i.setPrimaryKey).extend("attrSerializer",i.attrSerializer,["serialize"])})}]),c.factory("RMBuilderRelations",["$injector","inflector","$log","RMUtils","restmod","RMPackerCache",function(a,c,d,e,f,g){function h(a,b){return function(){var c=this.$owner;this.$owner=b;try{return a.apply(this,arguments)}finally{this.$owner=c}}}function i(a,b,c){for(var d in b)b.hasOwnProperty(d)&&a.$on(d,h(b[d],c))}var j={attrAsCollection:function(b,c,f,g,h,j,k){var l,m;return this.attrDefault(b,function(){if("string"==typeof c&&(c=a.get(c),l=c.getProperty("hasMany",{}),m=l.hooks,h)){var e=c.$$getDescription(h);e&&"belongs_to"===e.relation||(d.warn("Must define an inverse belongsTo relation for inverseOf to work"),h=!1)}var g,n=this.$buildScope(c,f||c.encodeUrlName(b));if(g=c.$collection(j||null,n),m&&i(g,m,this),k&&i(g,k,this),g.$dispatch("after-has-many-init"),h){var o=this;g.$on("after-add",function(a){a[h]=o})}return g}),(g||f)&&this.attrMap(b,g||f),this.attrDecoder(b,function(a){this[b].$reset().$decode(a||[])}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"has_many"}),this},attrAsResource:function(b,c,f,g,h,j){var k,l;return this.attrDefault(b,function(){if("string"==typeof c&&(c=a.get(c),k=c.getProperty("hasOne",{}),l=k.hooks,h)){var e=c.$$getDescription(h);e&&"belongs_to"===e.relation||(d.warn("Must define an inverse belongsTo relation for inverseOf to work"),h=!1)}var g,m=this.$buildScope(c,f||c.encodeUrlName(b));return g=c.$new(null,m),l&&i(g,l,this),j&&i(g,j,this),g.$dispatch("after-has-one-init"),h&&(g[h]=this),g}),(g||f)&&this.attrMap(b,g||f),this.attrDecoder(b,function(a){this[b].$decode(a||{})}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"has_one"}),this},attrAsReference:function(c,d,f,h){function i(){"string"==typeof d&&(d=a.get(d))}return this.attrDefault(c,null).attrMask(c,e.WRITE_MASK).attrMeta(c,{relation:"belongs_to"}),this.attrDecoder(c,function(a){return null===a?null:(i(),void(this[c]&&this[c].$pk===d.inferKey(a)?this[c].$decode(a):this[c]=d.$buildRaw(a)))}),f!==!1&&this.attrMap(c+"Id",f||"*",!0).attrDecoder(c+"Id",function(a){a!==b&&(this[c]&&this[c].$pk===a||(null!==a&&a!==!1?(i(),this[c]=g.resolve(d.$new(a)),h&&this[c].$fetch()):this[c]=null))}).attrEncoder(c+"Id",function(){return this[c]?this[c].$pk:null}),this},attrAsReferenceToMany:function(b,d,f){function h(){"string"==typeof d&&(d=a.get(d))}function i(a,b){h(),b.length=0;for(var c=0,e=a.length;e>c;c++)b.push("object"==typeof a[c]?d.$buildRaw(a[c]):g.resolve(d.$new(a[c])))}if(this.attrDefault(b,function(){return[]}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"belongs_to_many"}),this.attrDecoder(b,function(a){a&&i(a,this[b])}),f!==!1){var j=c.singularize(b)+"Ids";this.attrMap(j,f||"*",!0).attrDecoder(j,function(a){a&&i(a,this[b])}).attrEncoder(j,function(){for(var a=[],c=this[b],d=0,e=c.length;e>d;d++)a.push(c[d].$pk);return a})}return this}};return f.mixin(function(){this.extend("attrAsCollection",j.attrAsCollection,["hasMany","path","source","inverseOf","params","hooks"]).extend("attrAsResource",j.attrAsResource,["hasOne","path","source","inverseOf","hooks"]).extend("attrAsReference",j.attrAsReference,["belongsTo","key","prefetch"]).extend("attrAsReferenceToMany",j.attrAsReferenceToMany,["belongsToMany","keys"])})}]),c.factory("RMModelFactory",["$injector","$log","inflector","RMUtils","RMScopeApi","RMCommonApi","RMRecordApi","RMListApi","RMCollectionApi","RMExtendedApi","RMSerializer","RMBuilder",function(c,d,e,f,g,h,i,j,k,l,m,n){var o=/(.*?)([^\/]+)\/?$/,p=f.extendOverriden;return function(c,q){function r(a,b){this.$scope=a||r,this.$pk=b,this.$initialize()}function s(a,b){var c=new B;return c.$scope=b||r,c.$params=a,c.$initialize(),c}function t(a,b,c){var d=E[a];f.assert(!!d,"Invalid api name $1",a),b?d[b]=f.override(d[b],c):f.extendOverriden(d,c)}c=f.cleanUrl(c);var u,v={primaryKey:"id",urlPrefix:null},w=new m(r),x=[],y=[],z={},A={};c&&(v.name=e.singularize(c.replace(o,"$2")));var B=f.buildArrayType(),C=f.buildArrayType(),D=function(a){this.$isCollection=a,this.$initialize()};p(r,{$$getDescription:function(a){return z[a]},$$chain:[],$type:r,$new:function(a,b){return new r(b||r,a)},$collection:s,$url:function(){return v.urlPrefix?f.joinUrl(v.urlPrefix,c):c},$dispatch:function(a,b,c){var d,e,f=A[a];if(f)for(d=0;e=f[d];d++)e.apply(c||this,b||[]);return this},inferKey:function(a){return a&&"undefined"!=typeof a[v.primaryKey]?a[v.primaryKey]:null},getProperty:function(a,c){var d=v[a];return d!==b?d:c},isNested:function(){return!c},single:function(a){return new r({$urlFor:function(){return v.urlPrefix?f.joinUrl(v.urlPrefix,a):a}},"")},dummy:function(a){return new D(a)},list:function(a){var b=new C;return a&&b.push.apply(b,a),b},identity:function(a){if(!a)return v.name;if(a){if(v.plural)return v.plural;if(v.name)return e.pluralize(v.name)}return null},mix:function(){return u.chain(arguments),this.$$chain.push.apply(this.$$chain,arguments),this},unpack:function(a,b){return b},pack:function(a,b){return b},decode:w.decode,encode:w.encode,decodeName:null,encodeName:null,encodeUrlName:function(a){return d.warn("Default paremeterization of urls will be disabled in 1.2, override Model.encodeUrlName with inflector.parameterize in your base model to keep the same behaviour."),e.parameterize(a)}},g),p(r.prototype,{$type:r,$initialize:function(){var a,b,c=this;for(b=0;a=x[b];b++)this[a[0]]="function"==typeof a[1]?a[1].apply(this):a[1];for(b=0;a=y[b];b++)Object.defineProperty(c,a[0],{enumerable:!0,get:a[1],set:function(){}})}},h,i,l),p(B.prototype,{$type:r,$new:function(a,b){return r.$new(a,b||this)},$collection:function(b,c){return b=this.$params?a.extend({},this.$params,b):b,s(b,c||this.$scope)}},j,g,h,k,l),p(C.prototype,{$type:r},j,h),p(D.prototype,{$type:r,$initialize:function(){}},h);var E={Model:r,Record:r.prototype,Collection:B.prototype,List:C.prototype,Dummy:D.prototype};return u=new n(a.extend(w.dsl(),{setProperty:function(a,b){return v[a]=b,this},attrDefault:function(a,b){return x.push([a,b]),this},attrComputed:function(a,b){return y.push([a,b]),this.attrMask(a,!0),this},attrMeta:function(a,b){return z[a]=p(z[a]||{},b),this},define:function(a,b){var c=!1,d="Record";switch("object"==typeof b&&b?d=a:(c=a.split("."),1===c.length?c=c[0]:(d=c[0],c=c[1])),d){case"List":t("Collection",c,b),t("List",c,b);break;case"Scope":t("Model",c,b),t("Collection",c,b);break;case"Resource":t("Record",c,b),t("Collection",c,b),t("List",c,b),t("Dummy",c,b);break;default:t(d,c,b)}return this},on:function(a,b){return(A[a]||(A[a]=[])).push(b),this}})),u.chain(q),r}}]),c.factory("RMFastQ",[function(){function b(a,f){return a&&d(a.then)?c(a):{simple:!0,then:function(c,d){return b(f?d(a):c(a))},"catch":e,"finally":function(e){var g=e();return g&&d(a.then)?c(a.then(function(){return f?b(a,!0):a},function(){return f?b(a,!0):a})):this}}}function c(a){if(a.simple)return a;var d;return a.then(function(a){d=b(a)},function(a){d=b(a,!0)}),{then:function(b,e){return d?d.then(b,e):c(a.then(b,e))},"catch":e,"finally":function(b){return d?d["finally"](b):c(a["finally"](b))}}}var d=a.isFunction,e=function(a){return this.then(null,a)};return{reject:function(a){return b(a,!0)},when:function(a){return b(a,!1)},wrap:c}}]),c.factory("RMPackerCache",[function(){var a;return{feed:function(b,c){a[b]=c},resolve:function(b){if(a){var c=b.$type,d=a[c.identity(!0)];if(d&&b.$pk)for(var e=0,f=d.length;f>e;e++)if(b.$pk===c.inferKey(d[e])){b.$decode(d[e]);break}}return b},prepare:function(){a={}},clear:function(){a=null}}}]),c.factory("RMSerializer",["$injector","inflector","$filter","RMUtils",function(c,d,e,f){function g(a,c){if(null===a&&c.length>1)return b;for(var d,e=0;a&&(d=c[e]);e++)a=a[d];return a}function h(a,b,c){for(var d=0,e=b.length-1;e>d;d++){var f=b[d];a=a[f]||(a[f]={})}a[b[b.length-1]]=c}return function(c){function d(a,b,c){if("function"==typeof b)return b(a);var d=n[a];return"function"==typeof d&&(d=d.call(c)),d&&(d===!0||-1!==d.indexOf(b))}function i(a,e,f,h,i){var k,l,m,n,o,p,s,t,u=f?f+".":"";if(o=r[f])for(s=0,t=o.length;t>s;s++)m=u+o[s].path,d(m,h,i)||(n=o[s].map?g(a,o[s].map):a[c.encodeName?c.encodeName(o[s].path):o[s].path],(o[s].forced||n!==b)&&(n=j(n,m,h,i),n!==b&&(e[o[s].path]=n)));for(k in a)if(a.hasOwnProperty(k)){if(l=c.decodeName?c.decodeName(k):k,"$"===l[0])continue;if(o){for(p=!1,s=0,t=o.length;t>s&&!(p=o[s].mapPath===k);s++);if(p)continue}if(m=u+l,q[m]||d(m,h,i))continue;n=j(a[k],m,h,i),n!==b&&(e[l]=n)}}function j(a,b,c,d){var e=o[b],f=a;if(e)f=e.call(d,a,c);else if("object"==typeof a)if(m(a)){f=[];for(var g=0,h=a.length;h>g;g++)f.push(j(a[g],b+"[]",c,d))}else a&&(f={},i(a,f,b,c,d));return f}function k(a,e,f,g,i){var j,k,m,n,o,p=f?f+".":"";for(j in a)if(a.hasOwnProperty(j)&&"$"!==j[0]){if(k=p+j,q[k]||d(k,g,i))continue;n=l(a[j],k,g,i),n!==b&&(m=c.encodeName?c.encodeName(j):j,e[m]=n),s[k]&&delete a[j]}if(o=r[f])for(var t=0,u=o.length;u>t;t++)k=p+o[t].path,d(k,g,i)||(n=a[o[t].path],(o[t].forced||n!==b)&&(n=l(n,k,g,i),n!==b&&(o[t].map?h(e,o[t].map,n):e[c.encodeName?c.encodeName(o[t].path):o[t].path]=n)))}function l(a,b,c,d){var e=p[b],f=a;if(e)f=e.call(d,a,c);else if(null!==a&&"object"==typeof a&&"function"!=typeof a.toJSON)if(m(a)){f=[];for(var g=0,h=a.length;h>g;g++)f.push(l(a[g],b+"[]",c,d))}else a&&(f={},k(a,f,b,c,d));return f}var m=a.isArray,n={},o={},p={},q={},r={},s={};return{decode:function(a,b,c){i(b,a,"",c,a)},encode:function(a,b){var c={};return k(a,c,"",b,a),c},dsl:function(){return{attrMap:function(a,b,c){var d=a.lastIndexOf("."),e=-1!==d?a.substr(0,d):"",f=-1!==d?a.substr(d+1):a;q[a]=!0;var g=r[e]||(r[e]=[]);return g.push({path:f,map:"*"===b?null:b.split("."),mapPath:b,forced:c}),this},attrMask:function(a,b){return b?n[a]=b:delete n[a],this},attrDecoder:function(a,b,c,d){if("string"==typeof b){var g=e(b);b=function(a){return g(a,c)}}return o[a]=d?f.chain(o[a],b):b,this},attrEncoder:function(a,b,c,d){if("string"==typeof b){var g=e(b);b=function(a){return g(a,c)}}return p[a]=d?f.chain(p[a],b):b,this},attrVolatile:function(a,c){return s[a]=c===b?!0:c,this}}}}}}]),c.factory("DefaultPacker",["restmod","inflector","RMPackerCache",function(b,c,d){function e(a,b,c){for(var d=0,e=b.length;e>d;d++)c(b[d],a[b[d]])}function f(a,b,c){for(var d in a)a.hasOwnProperty(d)&&-1===b.indexOf(d)&&c(d,a[d])}function g(b,c,d,g,h){if("."===d||d===!0){var i=[c];g&&i.push.apply(i,a.isArray(g)?g:[g]),f(b,i,h)}else"string"==typeof d?f(b[d],[],h):e(b,d,h)}return b.mixin(function(){this.define("Model.unpack",function(a,b){var c=null,e=this.getProperty("jsonLinks","included"),f=this.getProperty("jsonMeta","meta");return c=a.$isCollection?this.getProperty("jsonRootMany")||this.getProperty("jsonRoot")||this.identity(!0):this.getProperty("jsonRootSingle")||this.getProperty("jsonRoot")||this.identity(),f&&(a.$metadata={},g(b,c,f,e,function(b,c){a.$metadata[b]=c})),e&&g(b,c,e,f,function(a,b){d.feed(a,b)}),b[c]})})}]),c.factory("RMUtils",["$log",function(a){var b=[],c=function(){var a=function(){};return Object.setPrototypeOf?function(a,b){Object.setPrototypeOf(a,b)}:(new a).__proto__===a.prototype?function(a,b){a.__proto__=b}:void 0}(),d={CREATE_MASK:"C",UPDATE_MASK:"U",READ_MASK:"R",WRITE_MASK:"CU",FULL_MASK:"CRU",format:function(a,b){for(var c=0;b&&cd;d++)if(b(a[d]))return d;return-1},extendOverriden:function(a){for(var b=1;bparent.RestmodArray = Array;"),d=window.RestmodArray,delete window.RestmodArray;for(var g in Array.prototype)"function"!=typeof Array.prototype[g]||d.prototype[g]||(d.prototype[g]=Array.prototype[g]);document.body.removeChild(f),b.push(f)}return d}};return d}])}(angular); \ No newline at end of file +!function(a,b){"use strict";!function(a){a.module("platanus.inflector",[]).provider("inflector",[function(){function a(a,b,c){if(-1===c.indexOf(a.toLowerCase()))for(var d,e=0;d=b[e++];)if(a.match(d[0]))return a.replace(d[0],d[1]);return a}var b="en",c={en:{uncountable:["music","art","love","happiness","advice","furniture","luggage","sugar","butter","water","electricity","gas","power","currency","equipment","information","rice","money","species","series","fish","sheep","moose","deer","news"],plural:[[new RegExp("(m)an$","gi"),"$1en"],[new RegExp("(pe)rson$","gi"),"$1ople"],[new RegExp("(child)$","gi"),"$1ren"],[new RegExp("^(ox)$","gi"),"$1en"],[new RegExp("(ax|test)is$","gi"),"$1es"],[new RegExp("(octop|vir)us$","gi"),"$1i"],[new RegExp("(alias|status)$","gi"),"$1es"],[new RegExp("(bu)s$","gi"),"$1ses"],[new RegExp("(buffal|tomat|potat)o$","gi"),"$1oes"],[new RegExp("([ti])um$","gi"),"$1a"],[new RegExp("sis$","gi"),"ses"],[new RegExp("(?:([^f])fe|([lr])f)$","gi"),"$1$2ves"],[new RegExp("(hive)$","gi"),"$1s"],[new RegExp("([^aeiouy]|qu)y$","gi"),"$1ies"],[new RegExp("(x|ch|ss|sh)$","gi"),"$1es"],[new RegExp("(matr|vert|ind)ix|ex$","gi"),"$1ices"],[new RegExp("([m|l])ouse$","gi"),"$1ice"],[new RegExp("(quiz)$","gi"),"$1zes"],[new RegExp("s$","gi"),"s"],[new RegExp("$","gi"),"s"]],singular:[[new RegExp("(m)en$","gi"),"$1an"],[new RegExp("(pe)ople$","gi"),"$1rson"],[new RegExp("(child)ren$","gi"),"$1"],[new RegExp("([ti])a$","gi"),"$1um"],[new RegExp("((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$","gi"),"$1$2sis"],[new RegExp("(hive)s$","gi"),"$1"],[new RegExp("(tive)s$","gi"),"$1"],[new RegExp("(curve)s$","gi"),"$1"],[new RegExp("([lr])ves$","gi"),"$1f"],[new RegExp("([^fo])ves$","gi"),"$1fe"],[new RegExp("([^aeiouy]|qu)ies$","gi"),"$1y"],[new RegExp("(s)eries$","gi"),"$1eries"],[new RegExp("(m)ovies$","gi"),"$1ovie"],[new RegExp("(x|ch|ss|sh)es$","gi"),"$1"],[new RegExp("([m|l])ice$","gi"),"$1ouse"],[new RegExp("(bus)es$","gi"),"$1"],[new RegExp("(o)es$","gi"),"$1"],[new RegExp("(shoe)s$","gi"),"$1"],[new RegExp("(cris|ax|test)es$","gi"),"$1is"],[new RegExp("(octop|vir)i$","gi"),"$1us"],[new RegExp("(alias|status)es$","gi"),"$1"],[new RegExp("^(ox)en","gi"),"$1"],[new RegExp("(vert|ind)ices$","gi"),"$1ex"],[new RegExp("(matr)ices$","gi"),"$1ix"],[new RegExp("(quiz)zes$","gi"),"$1"],[new RegExp("s$","gi"),""]]}};return{registerLocale:function(a,b){c[a]=b},setLocale:function(a){b=a},$get:["$log",function(d){function e(a){a=a||b;var e=c[a];return e||d.warn("Invalid inflector locale "+a),e}return{camelize:function(a,b){return"string"!=typeof a?a:a.replace(/(?:^[-_\s]*|[-_\s]+)([A-Z\d])/gi,function(a,c,d){return b||0!==d?c.toUpperCase():c})},parameterize:function(a,b){return"string"!=typeof a?a:a.replace(/(?:[A-Z]+|[0-9]+)/g,function(a,c){return 0===c?a:(b||"-")+a}).toLowerCase()},dasherize:function(a,b){return a.replace(/[-_\s]+/g,b||"-")},singularize:function(b,c){var d=e(c);return d?a(b,d.singular,d.uncountable):b},pluralize:function(b,c){var d=e(c);return d?a(b,d.plural,d.uncountable):b}}}]}}])}(a);var c=a.module("restmod",["ng","platanus.inflector"]);c.provider("restmod",[function(){function b(a){return function(b){b.invoke(a,this,{$builder:this})}}var c=["RMBuilderExt","RMBuilderRelations","RMBuilderComputed"];return{rebase:function(){var d,e,f=arguments.length;for(e=0;f>e;e++)d=arguments[e],(a.isArray(d)||a.isFunction(d))&&(d=b(d)),c.push(d);return this},$get:["RMModelFactory","$log",function(a,b){var d=Array.prototype.slice,e={model:function(e){var f=a(e,c);return arguments.length>1&&(f.mix(d.call(arguments,1)),b.warn("Passing mixins and definitions in the model method will be deprecated in restmod 1.2, use restmod.model().mix() instead.")),f},mixin:function(){return{$isAbstract:!0,$$chain:d.call(arguments,0)}},singleton:function(a){return e.model.apply(this,arguments).single(a)}};return e}]}}]).factory("model",["restmod",function(a){return a.model}]).factory("mixin",["restmod",function(a){return a.mixin}]),c.factory("RMCollectionApi",["RMUtils",function(c){var d=a.extend;return{$isCollection:!0,$initialize:function(){this.$dispatch("after-collection-init")},$decode:function(b,d){c.assert(b&&a.isArray(b),"Collection $decode expected array");for(var e=0,f=b.length;f>e;e++)this.$buildRaw(b[e],d).$reveal();return this.$dispatch("after-feed-many",[b]),this},$encode:function(a){for(var b=[],c=0,d=this.length;d>c;c++)b.push(this[c].$encode(a));return this.$dispatch("before-render-many",[b]),b},$clear:function(){return this.$always(function(){this.length=0})},$fetch:function(a){return this.$action(function(){var b={method:"GET",url:this.$url("fetchMany"),params:this.$params};a&&(b.params=b.params?d(b.params,a):a),this.$dispatch("before-fetch-many",[b]).$send(b,function(a){this.$unwrap(a.data).$dispatch("after-fetch-many",[a])},function(a){this.$dispatch("after-fetch-many-error",[a])})})},$add:function(a,d){return c.assert(a.$type&&a.$type===this.$type,"Collection $add expects record of the same $type"),this.$action(function(){a.$position===b&&(d!==b?this.splice(d,0,a):this.push(a),a.$position=!0,this.$dispatch("after-add",[a]))})},$remove:function(a){return this.$action(function(){var c=this.$indexOf(a);-1!==c&&(this.splice(c,1),a.$position=b,this.$dispatch("after-remove",[a]))})},$indexOf:function(a,b){var d="function"!=typeof a?function(b){return b===a}:a;return c.indexWhere(this,d,b)}}}]),c.factory("RMCommonApi",["$http","RMFastQ","$log","RMUtils",function(c,d,e,f){function g(a,c){var d=a.$dispatcher();return function(e){var f=a.$promise;a.$promise=b;try{a.$last=e;var g=d?a.$decorate(d,c,[a]):c.call(a,a);return g===b?a.$promise:g}finally{a.$promise=f}}}var h=[],i={$url:function(a){if(a){if(a="$"+a+"UrlFor",this.$scope[a])return this.$scope[a](this)}else if(this.$scope.$canonicalUrlFor)return this.$scope.$canonicalUrlFor(this);return this.$scope.$urlFor(this)},$dispatch:function(a,c,d){var e,f,g,i=this.$$dsp;if(d||(d=this),i&&(this.$$dsp=b,i(a,c,d)),this.$$cb&&(e=this.$$cb[a]))for(f=0;g=e[f];f++)g.apply(d,c||h);return this.$scope&&this.$scope.$dispatch?this.$scope.$dispatch(a,c,d):this.$type&&this.$type.$dispatch(a,c,d),this.$$dsp=i,this},$on:function(a,b){var c=(this.$$cb||(this.$$cb={}))[a]||(this.$$cb[a]=[]);return c.push(b),this},$off:function(a,b){if(this.$$cb&&this.$$cb[a]){var c=f.indexWhere(this.$$cb[a],function(a){return a===b});-1!==c&&this.$$cb[a].splice(c,1)}return this},$decorate:function(a,b,c){var d=this.$$dsp;this.$$dsp="function"!=typeof a&&a?function(b,c,e){d&&d.apply(null,arguments);var f=a[b];f&&f.apply(e,c||h)}:a;try{return b.apply(this,c)}finally{this.$$dsp=d}},$dispatcher:function(){return this.$$dsp},$asPromise:function(){var a=this;return this.$promise?this.$promise.then(function(){return a},function(){return d.reject(a)}):d.when(this)},$then:function(a,b){return this.$promise=this.$promise?this.$promise.then(a?g(this,a):a,b?g(this,b):b):d.when(g(this,a)(this)),this},$always:function(a){return this.$then(a,a)},$finally:function(a){return this.$promise=this.$promise["finally"](g(this,a)),this},$send:function(a,b,f){this.$type.getProperty("style")||e.warn("No API style base was selected, see the Api Integration FAQ for more information on this warning");var h=this.$$action;return this.$always(function(){return this.$response=null,this.$status="pending",this.$dispatch("before-request",[a]),c(a).then(g(this,function(){return h&&h.canceled?(this.$status="canceled",this.$dispatch("after-request-cancel",[]),d.reject(this)):(this.$status="ok",this.$response=this.$last,this.$dispatch("after-request",[this.$response]),b&&b.call(this,this.$response),void 0)}),g(this,function(){return h&&h.canceled?(this.$status="canceled",this.$dispatch("after-request-cancel",[])):(this.$status="error",this.$response=this.$last,this.$dispatch("after-request-error",[this.$response]),f&&f.call(this,this.$response)),d.reject(this)}))})},$action:function(a){var b={canceled:!1},c=this.$pending||(this.$pending=[]);return c.push(b),this.$always(function(){var c=this.$$action;try{return b.canceled?d.reject(this):(this.$$action=b,a.call(this))}finally{this.$$action=c}}).$finally(function(){c.splice(c.indexOf(b),1)})},$cancel:function(){return this.$pending&&a.forEach(this.$pending,function(a){a.canceled=!0}),this},$hasPendingActions:function(){var b=0;return this.$pending&&a.forEach(this.$pending,function(a){a.canceled||b++}),b>0}};return i}]),c.factory("RMExtendedApi",["$q","RMPackerCache",function(a,b){return{$decode:function(a,b){return this.$resolved===!1&&this.$clear&&this.$clear(),this.$super(a,b),this.$resolved=!0,this},$unwrap:function(a,c){try{return b.prepare(),a=this.$type.unpack(this,a),this.$decode(a,c)}finally{b.clear()}},$wrap:function(a){var b=this.$encode(a);return b=this.$type.pack(this,b)},$reset:function(){return this.$cancel().$action(function(){this.$resolved=!1})},$resolve:function(a){return this.$action(function(){this.$dispatch("before-resolve",[]),this.$resolved||this.$fetch(a)})},$refresh:function(a){return this.$reset().$fetch(a)}}}]),c.factory("RMListApi",[function(){return{$asList:function(a){var b=this.$type.list(),c=this.$asPromise();return b.$promise=c.then(function(c){b.push.apply(b,a?a(c):c)}),b}}}]),c.factory("RMRecordApi",["RMUtils",function(a){var c=function(b,c,d){this.$scope=b,this.$target=c,this.$partial=a.cleanUrl(d)};return c.prototype={$nestedUrl:function(){return a.joinUrl(this.$scope.$url(),this.$partial)},$urlFor:function(a){return a.$isCollection||this.$target.isNested()?this.$nestedUrl():this.$target.$urlFor(a)},$fetchUrlFor:function(){return this.$nestedUrl()},$createUrlFor:function(){return null}},{$initialize:function(){this.$super(),this.$dispatch("after-init")},$isNew:function(){return this.$pk===b||null===this.$pk},$buildUrl:function(b){return this.$isNew()?null:a.joinUrl(b.$url(),this.$pk+"")},$buildScope:function(a,b){return a.$buildOwnScope?void 0:new c(this,a,b)},$each:function(a,b){for(var c in this)this.hasOwnProperty(c)&&"$"!==c[0]&&a.call(b||this[c],this[c],c);return this},$decode:function(b,c){return a.assert(b&&"object"==typeof b,"Record $decode expected an object"),this.$type.decode(this,b,c||a.READ_MASK),this.$isNew()&&(this.$pk=this.$type.inferKey(b)),this.$dispatch("after-feed",[b]),this},$encode:function(b){var c=this.$type.encode(this,b||a.CREATE_MASK);return this.$dispatch("before-render",[c]),c},$fetch:function(b){return this.$action(function(){var c=this.$url("fetch");a.assert(!!c,"Cant $fetch if resource is not bound");var d={method:"GET",url:c,params:b};this.$dispatch("before-fetch",[d]),this.$send(d,function(a){this.$unwrap(a.data),this.$dispatch("after-fetch",[a])},function(a){this.$dispatch("after-fetch-error",[a])})})},$extend:function(a){return this.$action(function(){for(var b in a)a.hasOwnProperty(b)&&"$"!==b[0]&&(this[b]=a[b])})},$update:function(a){return this.$extend(a).$save()},$save:function(c){return this.$action(function(){var d,e=this.$url("update");e?(d=c?{method:this.$type.getProperty("patchMethod","PATCH"),url:e,data:this.$wrap(function(a){a=a.replace("[]","");for(var b=0,d=c.length;d>b;b++)if(a===c[b]||0===a.indexOf(c[b]+".")||0===c[b].indexOf(a+"."))return!1;return!0})}:{method:"PUT",url:e,data:this.$wrap(a.UPDATE_MASK)},this.$dispatch("before-update",[d,!!c]).$dispatch("before-save",[d]).$send(d,function(a){a.data&&this.$unwrap(a.data),this.$dispatch("after-update",[a,!!c]).$dispatch("after-save",[a])},function(a){this.$dispatch("after-update-error",[a,!!c]).$dispatch("after-save-error",[a])})):(e=this.$url("create")||this.$scope.$url(),a.assert(!!e,"Cant $create if parent scope is not bound"),d={method:"POST",url:e,data:this.$wrap(a.CREATE_MASK)},this.$dispatch("before-save",[d]).$dispatch("before-create",[d]).$send(d,function(a){a.data&&this.$unwrap(a.data),this.$scope.$isCollection&&this.$position===b&&!this.$preventReveal&&this.$scope.$add(this,this.$revealAt),this.$dispatch("after-create",[a]).$dispatch("after-save",[a])},function(a){this.$dispatch("after-create-error",[a]).$dispatch("after-save-error",[a])}))})},$destroy:function(){return this.$action(function(){var a=this.$url("destroy");if(a){var b={method:"DELETE",url:a};this.$dispatch("before-destroy",[b]).$send(b,function(a){this.$scope.$remove&&this.$scope.$remove(this),this.$dispatch("after-destroy",[a])},function(a){this.$dispatch("after-destroy-error",[a])})}else this.$scope.$remove&&this.$scope.$remove(this)})},$moveTo:function(a){return this.$position!==b||(this.$revealAt=a),this},$reveal:function(a){return a===b||a?this.$scope.$add(this,this.$revealAt):this.$preventReveal=!0,this}}}]),c.factory("RMScopeApi",["RMUtils",function(){return{$urlFor:function(a){var b=this.$type.isNested()?this:this.$type;return"function"==typeof a.$buildUrl?a.$buildUrl(b):b.$url()},$new:function(a,b){return this.$super(a,b)},$build:function(a){return this.$new().$extend(a)},$buildRaw:function(a,b){var c=this.$new(this.$type.inferKey(a));return c.$decode(a,b),c},$find:function(a,b){return this.$new(a).$resolve(b)},$create:function(a){return this.$build(a).$save()},$collection:function(a,b){return this.$super(a,b)},$search:function(a){return this.$collection(a).$fetch()}}}]),c.factory("RMBuilder",["$injector","inflector","$log","RMUtils",function(b,c,d,e){function f(a){var b=[{fun:"attrDefault",sign:["init"]},{fun:"attrMask",sign:["ignore"]},{fun:"attrMask",sign:["mask"]},{fun:"attrMap",sign:["map","force"]},{fun:"attrDecoder",sign:["decode","param","chain"]},{fun:"attrEncoder",sign:["encode","param","chain"]},{fun:"attrVolatile",sign:["volatile"]}];this.dsl=k(a,{describe:function(a){return g(a,function(a,b){switch(b.charAt(0)){case"@":d.warn("Usage of @ in description objects will be removed in 1.2, use a $extend block instead"),this.define("Scope."+b.substring(1),a);break;case"~":b=c.parameterize(b.substring(1)),d.warn("Usage of ~ in description objects will be removed in 1.2, use a $hooks block instead"),this.on(b,a);break;default:if("$config"===b)for(var e in a)a.hasOwnProperty(e)&&this.setProperty(e,a[e]);else if("$extend"===b)for(var e in a)a.hasOwnProperty(e)&&this.define(e,a[e]);else if("$hooks"===b)for(var e in a)a.hasOwnProperty(e)&&this.on(e,a[e]);else l.test(b)?(d.warn("Usage of ~ in description objects will be removed in 1.2, use a $config block instead"),b=c.camelize(b.toLowerCase()),this.setProperty(b,a)):h(a)?this.attribute(b,a):j(a)?this.define(b,a):this.attrDefault(b,a)}},this),this},extend:function(a,c,d){return"string"==typeof a?(this[a]=e.override(this[name],c),d&&b.push({fun:a,sign:d})):e.extendOverriden(this,a),this},attribute:function(a,c){for(var d,e=0;d=b[e++];)if(c.hasOwnProperty(d.sign[0])){for(var f=[a],g=0;gb;b++)this.mixin(a[b])},mixin:function(a){a.$$chain?this.chain(a.$$chain):"string"==typeof a?this.mixin(b.get(a)):i(a)?this.chain(a):j(a)?a.call(this.dsl,b):this.dsl.describe(a)}},f}]),c.factory("RMBuilderComputed",["restmod",function(a){var b={attrAsComputed:function(a,b){return this.attrComputed(a,b),this}};return a.mixin(function(){this.extend("attrAsComputed",b.attrAsComputed,["computed"])})}]),c.factory("RMBuilderExt",["$injector","$parse","inflector","$log","restmod",function(b,c,d,e,f){var g=a.bind,h=a.isFunction,i={setUrlPrefix:function(a){return this.setProperty("urlPrefix",a)},setPrimaryKey:function(a){return this.setProperty("primaryKey",a)},attrSerializer:function(a,c,e){return"string"==typeof c&&(c=b.get(d.camelize(c,!0)+"Serializer")),h(c)&&(c=c(e)),c.decode&&this.attrDecoder(a,g(c,c.decode)),c.encode&&this.attrEncoder(a,g(c,c.encode)),this},attrExpression:function(a,b){var d=c(b);return this.on("after-feed",function(){this[a]=d(this)})}};return f.mixin(function(){this.extend("setUrlPrefix",i.setUrlPrefix).extend("setPrimaryKey",i.setPrimaryKey).extend("attrSerializer",i.attrSerializer,["serialize"])})}]),c.factory("RMBuilderRelations",["$injector","inflector","$log","RMUtils","restmod","RMPackerCache",function(a,c,d,e,f,g){function h(a,b){return function(){var c=this.$owner;this.$owner=b;try{return a.apply(this,arguments)}finally{this.$owner=c}}}function i(a,b,c){for(var d in b)b.hasOwnProperty(d)&&a.$on(d,h(b[d],c))}var j={attrAsCollection:function(b,c,f,g,h,j,k){var l,m;return this.attrDefault(b,function(){if("string"==typeof c&&(c=a.get(c),l=c.getProperty("hasMany",{}),m=l.hooks,h)){var e=c.$$getDescription(h);e&&"belongs_to"===e.relation||(d.warn("Must define an inverse belongsTo relation for inverseOf to work"),h=!1)}var g,n=this.$buildScope(c,f||c.encodeUrlName(b));if(g=c.$collection(j||null,n),m&&i(g,m,this),k&&i(g,k,this),g.$dispatch("after-has-many-init"),h){var o=this;g.$on("after-add",function(a){a[h]=o})}return g}),(g||f)&&this.attrMap(b,g||f),this.attrDecoder(b,function(a){this[b].$reset().$decode(a||[])}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"has_many"}),this},attrAsResource:function(b,c,f,g,h,j){var k,l;return this.attrDefault(b,function(){if("string"==typeof c&&(c=a.get(c),k=c.getProperty("hasOne",{}),l=k.hooks,h)){var e=c.$$getDescription(h);e&&"belongs_to"===e.relation||(d.warn("Must define an inverse belongsTo relation for inverseOf to work"),h=!1)}var g,m=this.$buildScope(c,f||c.encodeUrlName(b));return g=c.$new(null,m),l&&i(g,l,this),j&&i(g,j,this),g.$dispatch("after-has-one-init"),h&&(g[h]=this),g}),(g||f)&&this.attrMap(b,g||f),this.attrDecoder(b,function(a){this[b].$decode(a||{})}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"has_one"}),this},attrAsReference:function(c,d,f,h){function i(){"string"==typeof d&&(d=a.get(d))}return this.attrDefault(c,null).attrMask(c,e.WRITE_MASK).attrMeta(c,{relation:"belongs_to"}),this.attrDecoder(c,function(a){return null===a?null:(i(),void(this[c]&&this[c].$pk===d.inferKey(a)?this[c].$decode(a):this[c]=d.$buildRaw(a)))}),f!==!1&&this.attrMap(c+"Id",f||"*",!0).attrDecoder(c+"Id",function(a){a!==b&&(this[c]&&this[c].$pk===a||(null!==a&&a!==!1?(i(),this[c]=g.resolve(d.$new(a)),h&&this[c].$fetch()):this[c]=null))}).attrEncoder(c+"Id",function(){return this[c]?this[c].$pk:null}),this},attrAsReferenceToMany:function(b,d,f){function h(){"string"==typeof d&&(d=a.get(d))}function i(a,b){h(),b.length=0;for(var c=0,e=a.length;e>c;c++)b.push("object"==typeof a[c]?d.$buildRaw(a[c]):g.resolve(d.$new(a[c])))}if(this.attrDefault(b,function(){return[]}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"belongs_to_many"}),this.attrDecoder(b,function(a){a&&i(a,this[b])}),f!==!1){var j=c.singularize(b)+"Ids";this.attrMap(j,f||"*",!0).attrDecoder(j,function(a){a&&i(a,this[b])}).attrEncoder(j,function(){for(var a=[],c=this[b],d=0,e=c.length;e>d;d++)a.push(c[d].$pk);return a})}return this}};return f.mixin(function(){this.extend("attrAsCollection",j.attrAsCollection,["hasMany","path","source","inverseOf","params","hooks"]).extend("attrAsResource",j.attrAsResource,["hasOne","path","source","inverseOf","hooks"]).extend("attrAsReference",j.attrAsReference,["belongsTo","key","prefetch"]).extend("attrAsReferenceToMany",j.attrAsReferenceToMany,["belongsToMany","keys"])})}]),c.factory("RMModelFactory",["$injector","$log","inflector","RMUtils","RMScopeApi","RMCommonApi","RMRecordApi","RMListApi","RMCollectionApi","RMExtendedApi","RMSerializer","RMBuilder",function(c,d,e,f,g,h,i,j,k,l,m,n){var o=/(.*?)([^\/]+)\/?$/,p=f.extendOverriden;return function(c,q){function r(a,b){this.$scope=a||r,this.$pk=b,this.$initialize()}function s(a,b){var c=new B;return c.$scope=b||r,c.$params=a,c.$initialize(),c}function t(a,b,c){var d=E[a];f.assert(!!d,"Invalid api name $1",a),b?d[b]=f.override(d[b],c):f.extendOverriden(d,c)}c=f.cleanUrl(c);var u,v={primaryKey:"id",urlPrefix:null},w=new m(r),x=[],y=[],z={},A={};c&&(v.name=e.singularize(c.replace(o,"$2")));var B=f.buildArrayType(),C=f.buildArrayType(),D=function(a){this.$isCollection=a,this.$initialize()};p(r,{$$getDescription:function(a){return z[a]},$$chain:[],$type:r,$new:function(a,b){return new r(b||r,a)},$collection:s,$url:function(){return v.urlPrefix?f.joinUrl(v.urlPrefix,c):c},$dispatch:function(a,b,c){var d,e,f=A[a];if(f)for(d=0;e=f[d];d++)e.apply(c||this,b||[]);return this},inferKey:function(a){return a&&"undefined"!=typeof a[v.primaryKey]?a[v.primaryKey]:null},getProperty:function(a,c){var d=v[a];return d!==b?d:c},isNested:function(){return!c},single:function(a){return new r({$urlFor:function(){return v.urlPrefix?f.joinUrl(v.urlPrefix,a):a}},"")},dummy:function(a){return new D(a)},list:function(a){var b=new C;return a&&b.push.apply(b,a),b},identity:function(a){if(!a)return v.name;if(a){if(v.plural)return v.plural;if(v.name)return e.pluralize(v.name)}return null},mix:function(){return u.chain(arguments),this.$$chain.push.apply(this.$$chain,arguments),this},unpack:function(a,b){return b},pack:function(a,b){return b},decode:w.decode,encode:w.encode,decodeName:null,encodeName:null,encodeUrlName:function(a){return d.warn("Default paremeterization of urls will be disabled in 1.2, override Model.encodeUrlName with inflector.parameterize in your base model to keep the same behaviour."),e.parameterize(a)}},g),p(r.prototype,{$type:r,$initialize:function(){var a,b,c=this;for(b=0;a=x[b];b++)this[a[0]]="function"==typeof a[1]?a[1].apply(this):a[1];for(b=0;a=y[b];b++)Object.defineProperty(c,a[0],{enumerable:!0,get:a[1],set:function(){}})}},h,i,l),p(B.prototype,{$type:r,$new:function(a,b){return r.$new(a,b||this)},$collection:function(b,c){return b=this.$params?a.extend({},this.$params,b):b,s(b,c||this.$scope)}},j,g,h,k,l),p(C.prototype,{$type:r},j,h),p(D.prototype,{$type:r,$initialize:function(){}},h);var E={Model:r,Record:r.prototype,Collection:B.prototype,List:C.prototype,Dummy:D.prototype};return u=new n(a.extend(w.dsl(),{setProperty:function(a,b){return v[a]=b,this},attrDefault:function(a,b){return x.push([a,b]),this},attrComputed:function(a,b){return y.push([a,b]),this.attrMask(a,!0),this},attrMeta:function(a,b){return z[a]=p(z[a]||{},b),this},define:function(a,b){var c=!1,d="Record";switch("object"==typeof b&&b?d=a:(c=a.split("."),1===c.length?c=c[0]:(d=c[0],c=c[1])),d){case"List":t("Collection",c,b),t("List",c,b);break;case"Scope":t("Model",c,b),t("Collection",c,b);break;case"Resource":t("Record",c,b),t("Collection",c,b),t("List",c,b),t("Dummy",c,b);break;default:t(d,c,b)}return this},on:function(a,b){return(A[a]||(A[a]=[])).push(b),this}})),u.chain(q),r}}]),c.factory("RMFastQ",[function(){function b(a,f){return a&&d(a.then)?c(a):{simple:!0,then:function(c,d){return b(f?d(a):c(a))},"catch":e,"finally":function(e){var g=e();return g&&d(a.then)?c(a.then(function(){return f?b(a,!0):a},function(){return f?b(a,!0):a})):this}}}function c(a){if(a.simple)return a;var d;return a.then(function(a){d=b(a)},function(a){d=b(a,!0)}),{then:function(b,e){return d?d.then(b,e):c(a.then(b,e))},"catch":e,"finally":function(b){return d?d["finally"](b):c(a["finally"](b))}}}var d=a.isFunction,e=function(a){return this.then(null,a)};return{reject:function(a){return b(a,!0)},when:function(a){return b(a,!1)},wrap:c}}]),c.factory("RMPackerCache",[function(){var a;return{feed:function(b,c){a[b]=c},resolve:function(b){if(a){var c=b.$type,d=a[c.identity(!0)];if(d&&b.$pk)for(var e=0,f=d.length;f>e;e++)if(b.$pk===c.inferKey(d[e])){b.$decode(d[e]);break}}return b},prepare:function(){a={}},clear:function(){a=null}}}]),c.factory("RMSerializer",["$injector","inflector","$filter","RMUtils",function(c,d,e,f){function g(a,c){if(null===a&&c.length>1)return b;for(var d,e=0;a&&(d=c[e]);e++)a=a[d];return a}function h(a,b,c){for(var d=0,e=b.length-1;e>d;d++){var f=b[d];a=a[f]||(a[f]={})}a[b[b.length-1]]=c}return function(c){function d(a,b,c){if("function"==typeof b)return b(a);var d=n[a];return"function"==typeof d&&(d=d.call(c)),d&&(d===!0||-1!==d.indexOf(b))}function i(a,e,f,h,i){var k,l,m,n,o,p,s,t,u=f?f+".":"";if(o=r[f])for(s=0,t=o.length;t>s;s++)m=u+o[s].path,d(m,h,i)||(n=o[s].map?g(a,o[s].map):a[c.encodeName?c.encodeName(o[s].path):o[s].path],(o[s].forced||n!==b)&&(n=j(n,m,h,i),n!==b&&(e[o[s].path]=n)));for(k in a)if(a.hasOwnProperty(k)){if(l=c.decodeName?c.decodeName(k):k,"$"===l[0])continue;if(o){for(p=!1,s=0,t=o.length;t>s&&!(p=o[s].mapPath===k);s++);if(p)continue}if(m=u+l,q[m]||d(m,h,i))continue;n=j(a[k],m,h,i),n!==b&&(e[l]=n)}}function j(a,b,c,d){var e=o[b],f=a;if(e)f=e.call(d,a,c);else if("object"==typeof a)if(m(a)){f=[];for(var g=0,h=a.length;h>g;g++)f.push(j(a[g],b+"[]",c,d))}else a&&(f={},i(a,f,b,c,d));return f}function k(a,e,f,g,i){var j,k,m,n,o,p=f?f+".":"";for(j in a)if(a.hasOwnProperty(j)&&"$"!==j[0]){if(k=p+j,q[k]||d(k,g,i))continue;n=l(a[j],k,g,i),n!==b&&(m=c.encodeName?c.encodeName(j):j,e[m]=n),s[k]&&delete a[j]}if(o=r[f])for(var t=0,u=o.length;u>t;t++)k=p+o[t].path,d(k,g,i)||(n=a[o[t].path],(o[t].forced||n!==b)&&(n=l(n,k,g,i),n!==b&&(o[t].map?h(e,o[t].map,n):e[c.encodeName?c.encodeName(o[t].path):o[t].path]=n)))}function l(a,b,c,d){var e=p[b],f=a;if(e)f=e.call(d,a,c);else if(null!==a&&"object"==typeof a&&"function"!=typeof a.toJSON)if(m(a)){f=[];for(var g=0,h=a.length;h>g;g++)f.push(l(a[g],b+"[]",c,d))}else a&&(f={},k(a,f,b,c,d));return f}var m=a.isArray,n={},o={},p={},q={},r={},s={};return{decode:function(a,b,c){i(b,a,"",c,a)},encode:function(a,b){var c={};return k(a,c,"",b,a),c},dsl:function(){return{attrMap:function(a,b,c){var d=a.lastIndexOf("."),e=-1!==d?a.substr(0,d):"",f=-1!==d?a.substr(d+1):a;q[a]=!0;var g=r[e]||(r[e]=[]);return g.push({path:f,map:"*"===b?null:b.split("."),mapPath:b,forced:c}),this},attrMask:function(a,b){return b?n[a]=b:delete n[a],this},attrDecoder:function(a,b,c,d){if("string"==typeof b){var g=e(b);b=function(a){return g(a,c)}}return o[a]=d?f.chain(o[a],b):b,this},attrEncoder:function(a,b,c,d){if("string"==typeof b){var g=e(b);b=function(a){return g(a,c)}}return p[a]=d?f.chain(p[a],b):b,this},attrVolatile:function(a,c){return s[a]=c===b?!0:c,this}}}}}}]),c.factory("DefaultPacker",["restmod","inflector","RMPackerCache",function(b,c,d){function e(a,b,c){for(var d=0,e=b.length;e>d;d++)c(b[d],a[b[d]])}function f(a,b,c){for(var d in a)a.hasOwnProperty(d)&&-1===b.indexOf(d)&&c(d,a[d])}function g(b,c,d,g,h){if("."===d||d===!0){var i=[c];g&&i.push.apply(i,a.isArray(g)?g:[g]),f(b,i,h)}else"string"==typeof d?f(b[d],[],h):e(b,d,h)}return b.mixin(function(){this.define("Model.unpack",function(a,b){var c=null,e=this.getProperty("jsonLinks","included"),f=this.getProperty("jsonMeta","meta");return c=a.$isCollection?this.getProperty("jsonRootMany")||this.getProperty("jsonRoot")||this.identity(!0):this.getProperty("jsonRootSingle")||this.getProperty("jsonRoot")||this.identity(),f&&(a.$metadata={},g(b,c,f,e,function(b,c){a.$metadata[b]=c})),e&&g(b,c,e,f,function(a,b){d.feed(a,b)}),b[c]})})}]),c.factory("RMUtils",["$log",function(a){var b=[],c=function(){var a=function(){};return Object.setPrototypeOf?function(a,b){Object.setPrototypeOf(a,b)}:(new a).__proto__===a.prototype?function(a,b){a.__proto__=b}:void 0}(),d={CREATE_MASK:"C",UPDATE_MASK:"U",READ_MASK:"R",WRITE_MASK:"CU",FULL_MASK:"CRU",format:function(a,b){for(var c=0;b&&cd;d++)if(b(a[d]))return d;return-1},extendOverriden:function(a){for(var b=1;bparent.RestmodArray = Array;"),d=window.RestmodArray,delete window.RestmodArray;for(var g in Array.prototype)"function"!=typeof Array.prototype[g]||d.prototype[g]||(d.prototype[g]=Array.prototype[g]);document.body.removeChild(f),b.push(f)}return d}};return d}])}(angular); \ No newline at end of file diff --git a/dist/angular-restmod.js b/dist/angular-restmod.js index 94b82c8..e387b8c 100644 --- a/dist/angular-restmod.js +++ b/dist/angular-restmod.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT @@ -1800,6 +1800,7 @@ RMModule.factory('RMBuilder', ['$injector', 'inflector', '$log', 'RMUtils', func var mappings = [ { fun: 'attrDefault', sign: ['init'] }, { fun: 'attrMask', sign: ['ignore'] }, + { fun: 'attrMask', sign: ['mask'] }, { fun: 'attrMap', sign: ['map', 'force'] }, { fun: 'attrDecoder', sign: ['decode', 'param', 'chain'] }, { fun: 'attrEncoder', sign: ['encode', 'param', 'chain'] }, diff --git a/dist/angular-restmod.min.js b/dist/angular-restmod.min.js index 528d685..12f977b 100644 --- a/dist/angular-restmod.min.js +++ b/dist/angular-restmod.min.js @@ -1,8 +1,8 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT */ -!function(a,b){"use strict";var c=a.module("restmod",["ng","platanus.inflector"]);c.provider("restmod",[function(){function b(a){return function(b){b.invoke(a,this,{$builder:this})}}var c=["RMBuilderExt","RMBuilderRelations","RMBuilderComputed"];return{rebase:function(){var d,e,f=arguments.length;for(e=0;f>e;e++)d=arguments[e],(a.isArray(d)||a.isFunction(d))&&(d=b(d)),c.push(d);return this},$get:["RMModelFactory","$log",function(a,b){var d=Array.prototype.slice,e={model:function(e){var f=a(e,c);return arguments.length>1&&(f.mix(d.call(arguments,1)),b.warn("Passing mixins and definitions in the model method will be deprecated in restmod 1.2, use restmod.model().mix() instead.")),f},mixin:function(){return{$isAbstract:!0,$$chain:d.call(arguments,0)}},singleton:function(a){return e.model.apply(this,arguments).single(a)}};return e}]}}]).factory("model",["restmod",function(a){return a.model}]).factory("mixin",["restmod",function(a){return a.mixin}]),c.factory("RMCollectionApi",["RMUtils",function(c){var d=a.extend;return{$isCollection:!0,$initialize:function(){this.$dispatch("after-collection-init")},$decode:function(b,d){c.assert(b&&a.isArray(b),"Collection $decode expected array");for(var e=0,f=b.length;f>e;e++)this.$buildRaw(b[e],d).$reveal();return this.$dispatch("after-feed-many",[b]),this},$encode:function(a){for(var b=[],c=0,d=this.length;d>c;c++)b.push(this[c].$encode(a));return this.$dispatch("before-render-many",[b]),b},$clear:function(){return this.$always(function(){this.length=0})},$fetch:function(a){return this.$action(function(){var b={method:"GET",url:this.$url("fetchMany"),params:this.$params};a&&(b.params=b.params?d(b.params,a):a),this.$dispatch("before-fetch-many",[b]).$send(b,function(a){this.$unwrap(a.data).$dispatch("after-fetch-many",[a])},function(a){this.$dispatch("after-fetch-many-error",[a])})})},$add:function(a,d){return c.assert(a.$type&&a.$type===this.$type,"Collection $add expects record of the same $type"),this.$action(function(){a.$position===b&&(d!==b?this.splice(d,0,a):this.push(a),a.$position=!0,this.$dispatch("after-add",[a]))})},$remove:function(a){return this.$action(function(){var c=this.$indexOf(a);-1!==c&&(this.splice(c,1),a.$position=b,this.$dispatch("after-remove",[a]))})},$indexOf:function(a,b){var d="function"!=typeof a?function(b){return b===a}:a;return c.indexWhere(this,d,b)}}}]),c.factory("RMCommonApi",["$http","RMFastQ","$log","RMUtils",function(c,d,e,f){function g(a,c){var d=a.$dispatcher();return function(e){var f=a.$promise;a.$promise=b;try{a.$last=e;var g=d?a.$decorate(d,c,[a]):c.call(a,a);return g===b?a.$promise:g}finally{a.$promise=f}}}var h=[],i={$url:function(a){if(a){if(a="$"+a+"UrlFor",this.$scope[a])return this.$scope[a](this)}else if(this.$scope.$canonicalUrlFor)return this.$scope.$canonicalUrlFor(this);return this.$scope.$urlFor(this)},$dispatch:function(a,c,d){var e,f,g,i=this.$$dsp;if(d||(d=this),i&&(this.$$dsp=b,i(a,c,d)),this.$$cb&&(e=this.$$cb[a]))for(f=0;g=e[f];f++)g.apply(d,c||h);return this.$scope&&this.$scope.$dispatch?this.$scope.$dispatch(a,c,d):this.$type&&this.$type.$dispatch(a,c,d),this.$$dsp=i,this},$on:function(a,b){var c=(this.$$cb||(this.$$cb={}))[a]||(this.$$cb[a]=[]);return c.push(b),this},$off:function(a,b){if(this.$$cb&&this.$$cb[a]){var c=f.indexWhere(this.$$cb[a],function(a){return a===b});-1!==c&&this.$$cb[a].splice(c,1)}return this},$decorate:function(a,b,c){var d=this.$$dsp;this.$$dsp="function"!=typeof a&&a?function(b,c,e){d&&d.apply(null,arguments);var f=a[b];f&&f.apply(e,c||h)}:a;try{return b.apply(this,c)}finally{this.$$dsp=d}},$dispatcher:function(){return this.$$dsp},$asPromise:function(){var a=this;return this.$promise?this.$promise.then(function(){return a},function(){return d.reject(a)}):d.when(this)},$then:function(a,b){return this.$promise=this.$promise?this.$promise.then(a?g(this,a):a,b?g(this,b):b):d.when(g(this,a)(this)),this},$always:function(a){return this.$then(a,a)},$finally:function(a){return this.$promise=this.$promise["finally"](g(this,a)),this},$send:function(a,b,f){this.$type.getProperty("style")||e.warn("No API style base was selected, see the Api Integration FAQ for more information on this warning");var h=this.$$action;return this.$always(function(){return this.$response=null,this.$status="pending",this.$dispatch("before-request",[a]),c(a).then(g(this,function(){return h&&h.canceled?(this.$status="canceled",this.$dispatch("after-request-cancel",[]),d.reject(this)):(this.$status="ok",this.$response=this.$last,this.$dispatch("after-request",[this.$response]),b&&b.call(this,this.$response),void 0)}),g(this,function(){return h&&h.canceled?(this.$status="canceled",this.$dispatch("after-request-cancel",[])):(this.$status="error",this.$response=this.$last,this.$dispatch("after-request-error",[this.$response]),f&&f.call(this,this.$response)),d.reject(this)}))})},$action:function(a){var b={canceled:!1},c=this.$pending||(this.$pending=[]);return c.push(b),this.$always(function(){var c=this.$$action;try{return b.canceled?d.reject(this):(this.$$action=b,a.call(this))}finally{this.$$action=c}}).$finally(function(){c.splice(c.indexOf(b),1)})},$cancel:function(){return this.$pending&&a.forEach(this.$pending,function(a){a.canceled=!0}),this},$hasPendingActions:function(){var b=0;return this.$pending&&a.forEach(this.$pending,function(a){a.canceled||b++}),b>0}};return i}]),c.factory("RMExtendedApi",["$q","RMPackerCache",function(a,b){return{$decode:function(a,b){return this.$resolved===!1&&this.$clear&&this.$clear(),this.$super(a,b),this.$resolved=!0,this},$unwrap:function(a,c){try{return b.prepare(),a=this.$type.unpack(this,a),this.$decode(a,c)}finally{b.clear()}},$wrap:function(a){var b=this.$encode(a);return b=this.$type.pack(this,b)},$reset:function(){return this.$cancel().$action(function(){this.$resolved=!1})},$resolve:function(a){return this.$action(function(){this.$dispatch("before-resolve",[]),this.$resolved||this.$fetch(a)})},$refresh:function(a){return this.$reset().$fetch(a)}}}]),c.factory("RMListApi",[function(){return{$asList:function(a){var b=this.$type.list(),c=this.$asPromise();return b.$promise=c.then(function(c){b.push.apply(b,a?a(c):c)}),b}}}]),c.factory("RMRecordApi",["RMUtils",function(a){var c=function(b,c,d){this.$scope=b,this.$target=c,this.$partial=a.cleanUrl(d)};return c.prototype={$nestedUrl:function(){return a.joinUrl(this.$scope.$url(),this.$partial)},$urlFor:function(a){return a.$isCollection||this.$target.isNested()?this.$nestedUrl():this.$target.$urlFor(a)},$fetchUrlFor:function(){return this.$nestedUrl()},$createUrlFor:function(){return null}},{$initialize:function(){this.$super(),this.$dispatch("after-init")},$isNew:function(){return this.$pk===b||null===this.$pk},$buildUrl:function(b){return this.$isNew()?null:a.joinUrl(b.$url(),this.$pk+"")},$buildScope:function(a,b){return a.$buildOwnScope?void 0:new c(this,a,b)},$each:function(a,b){for(var c in this)this.hasOwnProperty(c)&&"$"!==c[0]&&a.call(b||this[c],this[c],c);return this},$decode:function(b,c){return a.assert(b&&"object"==typeof b,"Record $decode expected an object"),this.$type.decode(this,b,c||a.READ_MASK),this.$isNew()&&(this.$pk=this.$type.inferKey(b)),this.$dispatch("after-feed",[b]),this},$encode:function(b){var c=this.$type.encode(this,b||a.CREATE_MASK);return this.$dispatch("before-render",[c]),c},$fetch:function(b){return this.$action(function(){var c=this.$url("fetch");a.assert(!!c,"Cant $fetch if resource is not bound");var d={method:"GET",url:c,params:b};this.$dispatch("before-fetch",[d]),this.$send(d,function(a){this.$unwrap(a.data),this.$dispatch("after-fetch",[a])},function(a){this.$dispatch("after-fetch-error",[a])})})},$extend:function(a){return this.$action(function(){for(var b in a)a.hasOwnProperty(b)&&"$"!==b[0]&&(this[b]=a[b])})},$update:function(a){return this.$extend(a).$save()},$save:function(c){return this.$action(function(){var d,e=this.$url("update");e?(d=c?{method:this.$type.getProperty("patchMethod","PATCH"),url:e,data:this.$wrap(function(a){a=a.replace("[]","");for(var b=0,d=c.length;d>b;b++)if(a===c[b]||0===a.indexOf(c[b]+".")||0===c[b].indexOf(a+"."))return!1;return!0})}:{method:"PUT",url:e,data:this.$wrap(a.UPDATE_MASK)},this.$dispatch("before-update",[d,!!c]).$dispatch("before-save",[d]).$send(d,function(a){a.data&&this.$unwrap(a.data),this.$dispatch("after-update",[a,!!c]).$dispatch("after-save",[a])},function(a){this.$dispatch("after-update-error",[a,!!c]).$dispatch("after-save-error",[a])})):(e=this.$url("create")||this.$scope.$url(),a.assert(!!e,"Cant $create if parent scope is not bound"),d={method:"POST",url:e,data:this.$wrap(a.CREATE_MASK)},this.$dispatch("before-save",[d]).$dispatch("before-create",[d]).$send(d,function(a){a.data&&this.$unwrap(a.data),this.$scope.$isCollection&&this.$position===b&&!this.$preventReveal&&this.$scope.$add(this,this.$revealAt),this.$dispatch("after-create",[a]).$dispatch("after-save",[a])},function(a){this.$dispatch("after-create-error",[a]).$dispatch("after-save-error",[a])}))})},$destroy:function(){return this.$action(function(){var a=this.$url("destroy");if(a){var b={method:"DELETE",url:a};this.$dispatch("before-destroy",[b]).$send(b,function(a){this.$scope.$remove&&this.$scope.$remove(this),this.$dispatch("after-destroy",[a])},function(a){this.$dispatch("after-destroy-error",[a])})}else this.$scope.$remove&&this.$scope.$remove(this)})},$moveTo:function(a){return this.$position!==b||(this.$revealAt=a),this},$reveal:function(a){return a===b||a?this.$scope.$add(this,this.$revealAt):this.$preventReveal=!0,this}}}]),c.factory("RMScopeApi",["RMUtils",function(){return{$urlFor:function(a){var b=this.$type.isNested()?this:this.$type;return"function"==typeof a.$buildUrl?a.$buildUrl(b):b.$url()},$new:function(a,b){return this.$super(a,b)},$build:function(a){return this.$new().$extend(a)},$buildRaw:function(a,b){var c=this.$new(this.$type.inferKey(a));return c.$decode(a,b),c},$find:function(a,b){return this.$new(a).$resolve(b)},$create:function(a){return this.$build(a).$save()},$collection:function(a,b){return this.$super(a,b)},$search:function(a){return this.$collection(a).$fetch()}}}]),c.factory("RMBuilder",["$injector","inflector","$log","RMUtils",function(b,c,d,e){function f(a){var b=[{fun:"attrDefault",sign:["init"]},{fun:"attrMask",sign:["ignore"]},{fun:"attrMap",sign:["map","force"]},{fun:"attrDecoder",sign:["decode","param","chain"]},{fun:"attrEncoder",sign:["encode","param","chain"]},{fun:"attrVolatile",sign:["volatile"]}];this.dsl=k(a,{describe:function(a){return g(a,function(a,b){switch(b.charAt(0)){case"@":d.warn("Usage of @ in description objects will be removed in 1.2, use a $extend block instead"),this.define("Scope."+b.substring(1),a);break;case"~":b=c.parameterize(b.substring(1)),d.warn("Usage of ~ in description objects will be removed in 1.2, use a $hooks block instead"),this.on(b,a);break;default:if("$config"===b)for(var e in a)a.hasOwnProperty(e)&&this.setProperty(e,a[e]);else if("$extend"===b)for(var e in a)a.hasOwnProperty(e)&&this.define(e,a[e]);else if("$hooks"===b)for(var e in a)a.hasOwnProperty(e)&&this.on(e,a[e]);else l.test(b)?(d.warn("Usage of ~ in description objects will be removed in 1.2, use a $config block instead"),b=c.camelize(b.toLowerCase()),this.setProperty(b,a)):h(a)?this.attribute(b,a):j(a)?this.define(b,a):this.attrDefault(b,a)}},this),this},extend:function(a,c,d){return"string"==typeof a?(this[a]=e.override(this[name],c),d&&b.push({fun:a,sign:d})):e.extendOverriden(this,a),this},attribute:function(a,c){for(var d,e=0;d=b[e++];)if(c.hasOwnProperty(d.sign[0])){for(var f=[a],g=0;gb;b++)this.mixin(a[b])},mixin:function(a){a.$$chain?this.chain(a.$$chain):"string"==typeof a?this.mixin(b.get(a)):i(a)?this.chain(a):j(a)?a.call(this.dsl,b):this.dsl.describe(a)}},f}]),c.factory("RMBuilderComputed",["restmod",function(a){var b={attrAsComputed:function(a,b){return this.attrComputed(a,b),this}};return a.mixin(function(){this.extend("attrAsComputed",b.attrAsComputed,["computed"])})}]),c.factory("RMBuilderExt",["$injector","$parse","inflector","$log","restmod",function(b,c,d,e,f){var g=a.bind,h=a.isFunction,i={setUrlPrefix:function(a){return this.setProperty("urlPrefix",a)},setPrimaryKey:function(a){return this.setProperty("primaryKey",a)},attrSerializer:function(a,c,e){return"string"==typeof c&&(c=b.get(d.camelize(c,!0)+"Serializer")),h(c)&&(c=c(e)),c.decode&&this.attrDecoder(a,g(c,c.decode)),c.encode&&this.attrEncoder(a,g(c,c.encode)),this},attrExpression:function(a,b){var d=c(b);return this.on("after-feed",function(){this[a]=d(this)})}};return f.mixin(function(){this.extend("setUrlPrefix",i.setUrlPrefix).extend("setPrimaryKey",i.setPrimaryKey).extend("attrSerializer",i.attrSerializer,["serialize"])})}]),c.factory("RMBuilderRelations",["$injector","inflector","$log","RMUtils","restmod","RMPackerCache",function(a,c,d,e,f,g){function h(a,b){return function(){var c=this.$owner;this.$owner=b;try{return a.apply(this,arguments)}finally{this.$owner=c}}}function i(a,b,c){for(var d in b)b.hasOwnProperty(d)&&a.$on(d,h(b[d],c))}var j={attrAsCollection:function(b,c,f,g,h,j,k){var l,m;return this.attrDefault(b,function(){if("string"==typeof c&&(c=a.get(c),l=c.getProperty("hasMany",{}),m=l.hooks,h)){var e=c.$$getDescription(h);e&&"belongs_to"===e.relation||(d.warn("Must define an inverse belongsTo relation for inverseOf to work"),h=!1)}var g,n=this.$buildScope(c,f||c.encodeUrlName(b));if(g=c.$collection(j||null,n),m&&i(g,m,this),k&&i(g,k,this),g.$dispatch("after-has-many-init"),h){var o=this;g.$on("after-add",function(a){a[h]=o})}return g}),(g||f)&&this.attrMap(b,g||f),this.attrDecoder(b,function(a){this[b].$reset().$decode(a||[])}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"has_many"}),this},attrAsResource:function(b,c,f,g,h,j){var k,l;return this.attrDefault(b,function(){if("string"==typeof c&&(c=a.get(c),k=c.getProperty("hasOne",{}),l=k.hooks,h)){var e=c.$$getDescription(h);e&&"belongs_to"===e.relation||(d.warn("Must define an inverse belongsTo relation for inverseOf to work"),h=!1)}var g,m=this.$buildScope(c,f||c.encodeUrlName(b));return g=c.$new(null,m),l&&i(g,l,this),j&&i(g,j,this),g.$dispatch("after-has-one-init"),h&&(g[h]=this),g}),(g||f)&&this.attrMap(b,g||f),this.attrDecoder(b,function(a){this[b].$decode(a||{})}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"has_one"}),this},attrAsReference:function(c,d,f,h){function i(){"string"==typeof d&&(d=a.get(d))}return this.attrDefault(c,null).attrMask(c,e.WRITE_MASK).attrMeta(c,{relation:"belongs_to"}),this.attrDecoder(c,function(a){return null===a?null:(i(),void(this[c]&&this[c].$pk===d.inferKey(a)?this[c].$decode(a):this[c]=d.$buildRaw(a)))}),f!==!1&&this.attrMap(c+"Id",f||"*",!0).attrDecoder(c+"Id",function(a){a!==b&&(this[c]&&this[c].$pk===a||(null!==a&&a!==!1?(i(),this[c]=g.resolve(d.$new(a)),h&&this[c].$fetch()):this[c]=null))}).attrEncoder(c+"Id",function(){return this[c]?this[c].$pk:null}),this},attrAsReferenceToMany:function(b,d,f){function h(){"string"==typeof d&&(d=a.get(d))}function i(a,b){h(),b.length=0;for(var c=0,e=a.length;e>c;c++)b.push("object"==typeof a[c]?d.$buildRaw(a[c]):g.resolve(d.$new(a[c])))}if(this.attrDefault(b,function(){return[]}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"belongs_to_many"}),this.attrDecoder(b,function(a){a&&i(a,this[b])}),f!==!1){var j=c.singularize(b)+"Ids";this.attrMap(j,f||"*",!0).attrDecoder(j,function(a){a&&i(a,this[b])}).attrEncoder(j,function(){for(var a=[],c=this[b],d=0,e=c.length;e>d;d++)a.push(c[d].$pk);return a})}return this}};return f.mixin(function(){this.extend("attrAsCollection",j.attrAsCollection,["hasMany","path","source","inverseOf","params","hooks"]).extend("attrAsResource",j.attrAsResource,["hasOne","path","source","inverseOf","hooks"]).extend("attrAsReference",j.attrAsReference,["belongsTo","key","prefetch"]).extend("attrAsReferenceToMany",j.attrAsReferenceToMany,["belongsToMany","keys"])})}]),c.factory("RMModelFactory",["$injector","$log","inflector","RMUtils","RMScopeApi","RMCommonApi","RMRecordApi","RMListApi","RMCollectionApi","RMExtendedApi","RMSerializer","RMBuilder",function(c,d,e,f,g,h,i,j,k,l,m,n){var o=/(.*?)([^\/]+)\/?$/,p=f.extendOverriden;return function(c,q){function r(a,b){this.$scope=a||r,this.$pk=b,this.$initialize()}function s(a,b){var c=new B;return c.$scope=b||r,c.$params=a,c.$initialize(),c}function t(a,b,c){var d=E[a];f.assert(!!d,"Invalid api name $1",a),b?d[b]=f.override(d[b],c):f.extendOverriden(d,c)}c=f.cleanUrl(c);var u,v={primaryKey:"id",urlPrefix:null},w=new m(r),x=[],y=[],z={},A={};c&&(v.name=e.singularize(c.replace(o,"$2")));var B=f.buildArrayType(),C=f.buildArrayType(),D=function(a){this.$isCollection=a,this.$initialize()};p(r,{$$getDescription:function(a){return z[a]},$$chain:[],$type:r,$new:function(a,b){return new r(b||r,a)},$collection:s,$url:function(){return v.urlPrefix?f.joinUrl(v.urlPrefix,c):c},$dispatch:function(a,b,c){var d,e,f=A[a];if(f)for(d=0;e=f[d];d++)e.apply(c||this,b||[]);return this},inferKey:function(a){return a&&"undefined"!=typeof a[v.primaryKey]?a[v.primaryKey]:null},getProperty:function(a,c){var d=v[a];return d!==b?d:c},isNested:function(){return!c},single:function(a){return new r({$urlFor:function(){return v.urlPrefix?f.joinUrl(v.urlPrefix,a):a}},"")},dummy:function(a){return new D(a)},list:function(a){var b=new C;return a&&b.push.apply(b,a),b},identity:function(a){if(!a)return v.name;if(a){if(v.plural)return v.plural;if(v.name)return e.pluralize(v.name)}return null},mix:function(){return u.chain(arguments),this.$$chain.push.apply(this.$$chain,arguments),this},unpack:function(a,b){return b},pack:function(a,b){return b},decode:w.decode,encode:w.encode,decodeName:null,encodeName:null,encodeUrlName:function(a){return d.warn("Default paremeterization of urls will be disabled in 1.2, override Model.encodeUrlName with inflector.parameterize in your base model to keep the same behaviour."),e.parameterize(a)}},g),p(r.prototype,{$type:r,$initialize:function(){var a,b,c=this;for(b=0;a=x[b];b++)this[a[0]]="function"==typeof a[1]?a[1].apply(this):a[1];for(b=0;a=y[b];b++)Object.defineProperty(c,a[0],{enumerable:!0,get:a[1],set:function(){}})}},h,i,l),p(B.prototype,{$type:r,$new:function(a,b){return r.$new(a,b||this)},$collection:function(b,c){return b=this.$params?a.extend({},this.$params,b):b,s(b,c||this.$scope)}},j,g,h,k,l),p(C.prototype,{$type:r},j,h),p(D.prototype,{$type:r,$initialize:function(){}},h);var E={Model:r,Record:r.prototype,Collection:B.prototype,List:C.prototype,Dummy:D.prototype};return u=new n(a.extend(w.dsl(),{setProperty:function(a,b){return v[a]=b,this},attrDefault:function(a,b){return x.push([a,b]),this},attrComputed:function(a,b){return y.push([a,b]),this.attrMask(a,!0),this},attrMeta:function(a,b){return z[a]=p(z[a]||{},b),this},define:function(a,b){var c=!1,d="Record";switch("object"==typeof b&&b?d=a:(c=a.split("."),1===c.length?c=c[0]:(d=c[0],c=c[1])),d){case"List":t("Collection",c,b),t("List",c,b);break;case"Scope":t("Model",c,b),t("Collection",c,b);break;case"Resource":t("Record",c,b),t("Collection",c,b),t("List",c,b),t("Dummy",c,b);break;default:t(d,c,b)}return this},on:function(a,b){return(A[a]||(A[a]=[])).push(b),this}})),u.chain(q),r}}]),c.factory("RMFastQ",[function(){function b(a,f){return a&&d(a.then)?c(a):{simple:!0,then:function(c,d){return b(f?d(a):c(a))},"catch":e,"finally":function(e){var g=e();return g&&d(a.then)?c(a.then(function(){return f?b(a,!0):a},function(){return f?b(a,!0):a})):this}}}function c(a){if(a.simple)return a;var d;return a.then(function(a){d=b(a)},function(a){d=b(a,!0)}),{then:function(b,e){return d?d.then(b,e):c(a.then(b,e))},"catch":e,"finally":function(b){return d?d["finally"](b):c(a["finally"](b))}}}var d=a.isFunction,e=function(a){return this.then(null,a)};return{reject:function(a){return b(a,!0)},when:function(a){return b(a,!1)},wrap:c}}]),c.factory("RMPackerCache",[function(){var a;return{feed:function(b,c){a[b]=c},resolve:function(b){if(a){var c=b.$type,d=a[c.identity(!0)];if(d&&b.$pk)for(var e=0,f=d.length;f>e;e++)if(b.$pk===c.inferKey(d[e])){b.$decode(d[e]);break}}return b},prepare:function(){a={}},clear:function(){a=null}}}]),c.factory("RMSerializer",["$injector","inflector","$filter","RMUtils",function(c,d,e,f){function g(a,c){if(null===a&&c.length>1)return b;for(var d,e=0;a&&(d=c[e]);e++)a=a[d];return a}function h(a,b,c){for(var d=0,e=b.length-1;e>d;d++){var f=b[d];a=a[f]||(a[f]={})}a[b[b.length-1]]=c}return function(c){function d(a,b,c){if("function"==typeof b)return b(a);var d=n[a];return"function"==typeof d&&(d=d.call(c)),d&&(d===!0||-1!==d.indexOf(b))}function i(a,e,f,h,i){var k,l,m,n,o,p,s,t,u=f?f+".":"";if(o=r[f])for(s=0,t=o.length;t>s;s++)m=u+o[s].path,d(m,h,i)||(n=o[s].map?g(a,o[s].map):a[c.encodeName?c.encodeName(o[s].path):o[s].path],(o[s].forced||n!==b)&&(n=j(n,m,h,i),n!==b&&(e[o[s].path]=n)));for(k in a)if(a.hasOwnProperty(k)){if(l=c.decodeName?c.decodeName(k):k,"$"===l[0])continue;if(o){for(p=!1,s=0,t=o.length;t>s&&!(p=o[s].mapPath===k);s++);if(p)continue}if(m=u+l,q[m]||d(m,h,i))continue;n=j(a[k],m,h,i),n!==b&&(e[l]=n)}}function j(a,b,c,d){var e=o[b],f=a;if(e)f=e.call(d,a,c);else if("object"==typeof a)if(m(a)){f=[];for(var g=0,h=a.length;h>g;g++)f.push(j(a[g],b+"[]",c,d))}else a&&(f={},i(a,f,b,c,d));return f}function k(a,e,f,g,i){var j,k,m,n,o,p=f?f+".":"";for(j in a)if(a.hasOwnProperty(j)&&"$"!==j[0]){if(k=p+j,q[k]||d(k,g,i))continue;n=l(a[j],k,g,i),n!==b&&(m=c.encodeName?c.encodeName(j):j,e[m]=n),s[k]&&delete a[j]}if(o=r[f])for(var t=0,u=o.length;u>t;t++)k=p+o[t].path,d(k,g,i)||(n=a[o[t].path],(o[t].forced||n!==b)&&(n=l(n,k,g,i),n!==b&&(o[t].map?h(e,o[t].map,n):e[c.encodeName?c.encodeName(o[t].path):o[t].path]=n)))}function l(a,b,c,d){var e=p[b],f=a;if(e)f=e.call(d,a,c);else if(null!==a&&"object"==typeof a&&"function"!=typeof a.toJSON)if(m(a)){f=[];for(var g=0,h=a.length;h>g;g++)f.push(l(a[g],b+"[]",c,d))}else a&&(f={},k(a,f,b,c,d));return f}var m=a.isArray,n={},o={},p={},q={},r={},s={};return{decode:function(a,b,c){i(b,a,"",c,a)},encode:function(a,b){var c={};return k(a,c,"",b,a),c},dsl:function(){return{attrMap:function(a,b,c){var d=a.lastIndexOf("."),e=-1!==d?a.substr(0,d):"",f=-1!==d?a.substr(d+1):a;q[a]=!0;var g=r[e]||(r[e]=[]);return g.push({path:f,map:"*"===b?null:b.split("."),mapPath:b,forced:c}),this},attrMask:function(a,b){return b?n[a]=b:delete n[a],this},attrDecoder:function(a,b,c,d){if("string"==typeof b){var g=e(b);b=function(a){return g(a,c)}}return o[a]=d?f.chain(o[a],b):b,this},attrEncoder:function(a,b,c,d){if("string"==typeof b){var g=e(b);b=function(a){return g(a,c)}}return p[a]=d?f.chain(p[a],b):b,this},attrVolatile:function(a,c){return s[a]=c===b?!0:c,this}}}}}}]),c.factory("DefaultPacker",["restmod","inflector","RMPackerCache",function(b,c,d){function e(a,b,c){for(var d=0,e=b.length;e>d;d++)c(b[d],a[b[d]])}function f(a,b,c){for(var d in a)a.hasOwnProperty(d)&&-1===b.indexOf(d)&&c(d,a[d])}function g(b,c,d,g,h){if("."===d||d===!0){var i=[c];g&&i.push.apply(i,a.isArray(g)?g:[g]),f(b,i,h)}else"string"==typeof d?f(b[d],[],h):e(b,d,h)}return b.mixin(function(){this.define("Model.unpack",function(a,b){var c=null,e=this.getProperty("jsonLinks","included"),f=this.getProperty("jsonMeta","meta");return c=a.$isCollection?this.getProperty("jsonRootMany")||this.getProperty("jsonRoot")||this.identity(!0):this.getProperty("jsonRootSingle")||this.getProperty("jsonRoot")||this.identity(),f&&(a.$metadata={},g(b,c,f,e,function(b,c){a.$metadata[b]=c})),e&&g(b,c,e,f,function(a,b){d.feed(a,b)}),b[c]})})}]),c.factory("RMUtils",["$log",function(a){var b=[],c=function(){var a=function(){};return Object.setPrototypeOf?function(a,b){Object.setPrototypeOf(a,b)}:(new a).__proto__===a.prototype?function(a,b){a.__proto__=b}:void 0}(),d={CREATE_MASK:"C",UPDATE_MASK:"U",READ_MASK:"R",WRITE_MASK:"CU",FULL_MASK:"CRU",format:function(a,b){for(var c=0;b&&cd;d++)if(b(a[d]))return d;return-1},extendOverriden:function(a){for(var b=1;bparent.RestmodArray = Array;"),d=window.RestmodArray,delete window.RestmodArray;for(var g in Array.prototype)"function"!=typeof Array.prototype[g]||d.prototype[g]||(d.prototype[g]=Array.prototype[g]);document.body.removeChild(f),b.push(f)}return d}};return d}])}(angular); \ No newline at end of file +!function(a,b){"use strict";var c=a.module("restmod",["ng","platanus.inflector"]);c.provider("restmod",[function(){function b(a){return function(b){b.invoke(a,this,{$builder:this})}}var c=["RMBuilderExt","RMBuilderRelations","RMBuilderComputed"];return{rebase:function(){var d,e,f=arguments.length;for(e=0;f>e;e++)d=arguments[e],(a.isArray(d)||a.isFunction(d))&&(d=b(d)),c.push(d);return this},$get:["RMModelFactory","$log",function(a,b){var d=Array.prototype.slice,e={model:function(e){var f=a(e,c);return arguments.length>1&&(f.mix(d.call(arguments,1)),b.warn("Passing mixins and definitions in the model method will be deprecated in restmod 1.2, use restmod.model().mix() instead.")),f},mixin:function(){return{$isAbstract:!0,$$chain:d.call(arguments,0)}},singleton:function(a){return e.model.apply(this,arguments).single(a)}};return e}]}}]).factory("model",["restmod",function(a){return a.model}]).factory("mixin",["restmod",function(a){return a.mixin}]),c.factory("RMCollectionApi",["RMUtils",function(c){var d=a.extend;return{$isCollection:!0,$initialize:function(){this.$dispatch("after-collection-init")},$decode:function(b,d){c.assert(b&&a.isArray(b),"Collection $decode expected array");for(var e=0,f=b.length;f>e;e++)this.$buildRaw(b[e],d).$reveal();return this.$dispatch("after-feed-many",[b]),this},$encode:function(a){for(var b=[],c=0,d=this.length;d>c;c++)b.push(this[c].$encode(a));return this.$dispatch("before-render-many",[b]),b},$clear:function(){return this.$always(function(){this.length=0})},$fetch:function(a){return this.$action(function(){var b={method:"GET",url:this.$url("fetchMany"),params:this.$params};a&&(b.params=b.params?d(b.params,a):a),this.$dispatch("before-fetch-many",[b]).$send(b,function(a){this.$unwrap(a.data).$dispatch("after-fetch-many",[a])},function(a){this.$dispatch("after-fetch-many-error",[a])})})},$add:function(a,d){return c.assert(a.$type&&a.$type===this.$type,"Collection $add expects record of the same $type"),this.$action(function(){a.$position===b&&(d!==b?this.splice(d,0,a):this.push(a),a.$position=!0,this.$dispatch("after-add",[a]))})},$remove:function(a){return this.$action(function(){var c=this.$indexOf(a);-1!==c&&(this.splice(c,1),a.$position=b,this.$dispatch("after-remove",[a]))})},$indexOf:function(a,b){var d="function"!=typeof a?function(b){return b===a}:a;return c.indexWhere(this,d,b)}}}]),c.factory("RMCommonApi",["$http","RMFastQ","$log","RMUtils",function(c,d,e,f){function g(a,c){var d=a.$dispatcher();return function(e){var f=a.$promise;a.$promise=b;try{a.$last=e;var g=d?a.$decorate(d,c,[a]):c.call(a,a);return g===b?a.$promise:g}finally{a.$promise=f}}}var h=[],i={$url:function(a){if(a){if(a="$"+a+"UrlFor",this.$scope[a])return this.$scope[a](this)}else if(this.$scope.$canonicalUrlFor)return this.$scope.$canonicalUrlFor(this);return this.$scope.$urlFor(this)},$dispatch:function(a,c,d){var e,f,g,i=this.$$dsp;if(d||(d=this),i&&(this.$$dsp=b,i(a,c,d)),this.$$cb&&(e=this.$$cb[a]))for(f=0;g=e[f];f++)g.apply(d,c||h);return this.$scope&&this.$scope.$dispatch?this.$scope.$dispatch(a,c,d):this.$type&&this.$type.$dispatch(a,c,d),this.$$dsp=i,this},$on:function(a,b){var c=(this.$$cb||(this.$$cb={}))[a]||(this.$$cb[a]=[]);return c.push(b),this},$off:function(a,b){if(this.$$cb&&this.$$cb[a]){var c=f.indexWhere(this.$$cb[a],function(a){return a===b});-1!==c&&this.$$cb[a].splice(c,1)}return this},$decorate:function(a,b,c){var d=this.$$dsp;this.$$dsp="function"!=typeof a&&a?function(b,c,e){d&&d.apply(null,arguments);var f=a[b];f&&f.apply(e,c||h)}:a;try{return b.apply(this,c)}finally{this.$$dsp=d}},$dispatcher:function(){return this.$$dsp},$asPromise:function(){var a=this;return this.$promise?this.$promise.then(function(){return a},function(){return d.reject(a)}):d.when(this)},$then:function(a,b){return this.$promise=this.$promise?this.$promise.then(a?g(this,a):a,b?g(this,b):b):d.when(g(this,a)(this)),this},$always:function(a){return this.$then(a,a)},$finally:function(a){return this.$promise=this.$promise["finally"](g(this,a)),this},$send:function(a,b,f){this.$type.getProperty("style")||e.warn("No API style base was selected, see the Api Integration FAQ for more information on this warning");var h=this.$$action;return this.$always(function(){return this.$response=null,this.$status="pending",this.$dispatch("before-request",[a]),c(a).then(g(this,function(){return h&&h.canceled?(this.$status="canceled",this.$dispatch("after-request-cancel",[]),d.reject(this)):(this.$status="ok",this.$response=this.$last,this.$dispatch("after-request",[this.$response]),b&&b.call(this,this.$response),void 0)}),g(this,function(){return h&&h.canceled?(this.$status="canceled",this.$dispatch("after-request-cancel",[])):(this.$status="error",this.$response=this.$last,this.$dispatch("after-request-error",[this.$response]),f&&f.call(this,this.$response)),d.reject(this)}))})},$action:function(a){var b={canceled:!1},c=this.$pending||(this.$pending=[]);return c.push(b),this.$always(function(){var c=this.$$action;try{return b.canceled?d.reject(this):(this.$$action=b,a.call(this))}finally{this.$$action=c}}).$finally(function(){c.splice(c.indexOf(b),1)})},$cancel:function(){return this.$pending&&a.forEach(this.$pending,function(a){a.canceled=!0}),this},$hasPendingActions:function(){var b=0;return this.$pending&&a.forEach(this.$pending,function(a){a.canceled||b++}),b>0}};return i}]),c.factory("RMExtendedApi",["$q","RMPackerCache",function(a,b){return{$decode:function(a,b){return this.$resolved===!1&&this.$clear&&this.$clear(),this.$super(a,b),this.$resolved=!0,this},$unwrap:function(a,c){try{return b.prepare(),a=this.$type.unpack(this,a),this.$decode(a,c)}finally{b.clear()}},$wrap:function(a){var b=this.$encode(a);return b=this.$type.pack(this,b)},$reset:function(){return this.$cancel().$action(function(){this.$resolved=!1})},$resolve:function(a){return this.$action(function(){this.$dispatch("before-resolve",[]),this.$resolved||this.$fetch(a)})},$refresh:function(a){return this.$reset().$fetch(a)}}}]),c.factory("RMListApi",[function(){return{$asList:function(a){var b=this.$type.list(),c=this.$asPromise();return b.$promise=c.then(function(c){b.push.apply(b,a?a(c):c)}),b}}}]),c.factory("RMRecordApi",["RMUtils",function(a){var c=function(b,c,d){this.$scope=b,this.$target=c,this.$partial=a.cleanUrl(d)};return c.prototype={$nestedUrl:function(){return a.joinUrl(this.$scope.$url(),this.$partial)},$urlFor:function(a){return a.$isCollection||this.$target.isNested()?this.$nestedUrl():this.$target.$urlFor(a)},$fetchUrlFor:function(){return this.$nestedUrl()},$createUrlFor:function(){return null}},{$initialize:function(){this.$super(),this.$dispatch("after-init")},$isNew:function(){return this.$pk===b||null===this.$pk},$buildUrl:function(b){return this.$isNew()?null:a.joinUrl(b.$url(),this.$pk+"")},$buildScope:function(a,b){return a.$buildOwnScope?void 0:new c(this,a,b)},$each:function(a,b){for(var c in this)this.hasOwnProperty(c)&&"$"!==c[0]&&a.call(b||this[c],this[c],c);return this},$decode:function(b,c){return a.assert(b&&"object"==typeof b,"Record $decode expected an object"),this.$type.decode(this,b,c||a.READ_MASK),this.$isNew()&&(this.$pk=this.$type.inferKey(b)),this.$dispatch("after-feed",[b]),this},$encode:function(b){var c=this.$type.encode(this,b||a.CREATE_MASK);return this.$dispatch("before-render",[c]),c},$fetch:function(b){return this.$action(function(){var c=this.$url("fetch");a.assert(!!c,"Cant $fetch if resource is not bound");var d={method:"GET",url:c,params:b};this.$dispatch("before-fetch",[d]),this.$send(d,function(a){this.$unwrap(a.data),this.$dispatch("after-fetch",[a])},function(a){this.$dispatch("after-fetch-error",[a])})})},$extend:function(a){return this.$action(function(){for(var b in a)a.hasOwnProperty(b)&&"$"!==b[0]&&(this[b]=a[b])})},$update:function(a){return this.$extend(a).$save()},$save:function(c){return this.$action(function(){var d,e=this.$url("update");e?(d=c?{method:this.$type.getProperty("patchMethod","PATCH"),url:e,data:this.$wrap(function(a){a=a.replace("[]","");for(var b=0,d=c.length;d>b;b++)if(a===c[b]||0===a.indexOf(c[b]+".")||0===c[b].indexOf(a+"."))return!1;return!0})}:{method:"PUT",url:e,data:this.$wrap(a.UPDATE_MASK)},this.$dispatch("before-update",[d,!!c]).$dispatch("before-save",[d]).$send(d,function(a){a.data&&this.$unwrap(a.data),this.$dispatch("after-update",[a,!!c]).$dispatch("after-save",[a])},function(a){this.$dispatch("after-update-error",[a,!!c]).$dispatch("after-save-error",[a])})):(e=this.$url("create")||this.$scope.$url(),a.assert(!!e,"Cant $create if parent scope is not bound"),d={method:"POST",url:e,data:this.$wrap(a.CREATE_MASK)},this.$dispatch("before-save",[d]).$dispatch("before-create",[d]).$send(d,function(a){a.data&&this.$unwrap(a.data),this.$scope.$isCollection&&this.$position===b&&!this.$preventReveal&&this.$scope.$add(this,this.$revealAt),this.$dispatch("after-create",[a]).$dispatch("after-save",[a])},function(a){this.$dispatch("after-create-error",[a]).$dispatch("after-save-error",[a])}))})},$destroy:function(){return this.$action(function(){var a=this.$url("destroy");if(a){var b={method:"DELETE",url:a};this.$dispatch("before-destroy",[b]).$send(b,function(a){this.$scope.$remove&&this.$scope.$remove(this),this.$dispatch("after-destroy",[a])},function(a){this.$dispatch("after-destroy-error",[a])})}else this.$scope.$remove&&this.$scope.$remove(this)})},$moveTo:function(a){return this.$position!==b||(this.$revealAt=a),this},$reveal:function(a){return a===b||a?this.$scope.$add(this,this.$revealAt):this.$preventReveal=!0,this}}}]),c.factory("RMScopeApi",["RMUtils",function(){return{$urlFor:function(a){var b=this.$type.isNested()?this:this.$type;return"function"==typeof a.$buildUrl?a.$buildUrl(b):b.$url()},$new:function(a,b){return this.$super(a,b)},$build:function(a){return this.$new().$extend(a)},$buildRaw:function(a,b){var c=this.$new(this.$type.inferKey(a));return c.$decode(a,b),c},$find:function(a,b){return this.$new(a).$resolve(b)},$create:function(a){return this.$build(a).$save()},$collection:function(a,b){return this.$super(a,b)},$search:function(a){return this.$collection(a).$fetch()}}}]),c.factory("RMBuilder",["$injector","inflector","$log","RMUtils",function(b,c,d,e){function f(a){var b=[{fun:"attrDefault",sign:["init"]},{fun:"attrMask",sign:["ignore"]},{fun:"attrMask",sign:["mask"]},{fun:"attrMap",sign:["map","force"]},{fun:"attrDecoder",sign:["decode","param","chain"]},{fun:"attrEncoder",sign:["encode","param","chain"]},{fun:"attrVolatile",sign:["volatile"]}];this.dsl=k(a,{describe:function(a){return g(a,function(a,b){switch(b.charAt(0)){case"@":d.warn("Usage of @ in description objects will be removed in 1.2, use a $extend block instead"),this.define("Scope."+b.substring(1),a);break;case"~":b=c.parameterize(b.substring(1)),d.warn("Usage of ~ in description objects will be removed in 1.2, use a $hooks block instead"),this.on(b,a);break;default:if("$config"===b)for(var e in a)a.hasOwnProperty(e)&&this.setProperty(e,a[e]);else if("$extend"===b)for(var e in a)a.hasOwnProperty(e)&&this.define(e,a[e]);else if("$hooks"===b)for(var e in a)a.hasOwnProperty(e)&&this.on(e,a[e]);else l.test(b)?(d.warn("Usage of ~ in description objects will be removed in 1.2, use a $config block instead"),b=c.camelize(b.toLowerCase()),this.setProperty(b,a)):h(a)?this.attribute(b,a):j(a)?this.define(b,a):this.attrDefault(b,a)}},this),this},extend:function(a,c,d){return"string"==typeof a?(this[a]=e.override(this[name],c),d&&b.push({fun:a,sign:d})):e.extendOverriden(this,a),this},attribute:function(a,c){for(var d,e=0;d=b[e++];)if(c.hasOwnProperty(d.sign[0])){for(var f=[a],g=0;gb;b++)this.mixin(a[b])},mixin:function(a){a.$$chain?this.chain(a.$$chain):"string"==typeof a?this.mixin(b.get(a)):i(a)?this.chain(a):j(a)?a.call(this.dsl,b):this.dsl.describe(a)}},f}]),c.factory("RMBuilderComputed",["restmod",function(a){var b={attrAsComputed:function(a,b){return this.attrComputed(a,b),this}};return a.mixin(function(){this.extend("attrAsComputed",b.attrAsComputed,["computed"])})}]),c.factory("RMBuilderExt",["$injector","$parse","inflector","$log","restmod",function(b,c,d,e,f){var g=a.bind,h=a.isFunction,i={setUrlPrefix:function(a){return this.setProperty("urlPrefix",a)},setPrimaryKey:function(a){return this.setProperty("primaryKey",a)},attrSerializer:function(a,c,e){return"string"==typeof c&&(c=b.get(d.camelize(c,!0)+"Serializer")),h(c)&&(c=c(e)),c.decode&&this.attrDecoder(a,g(c,c.decode)),c.encode&&this.attrEncoder(a,g(c,c.encode)),this},attrExpression:function(a,b){var d=c(b);return this.on("after-feed",function(){this[a]=d(this)})}};return f.mixin(function(){this.extend("setUrlPrefix",i.setUrlPrefix).extend("setPrimaryKey",i.setPrimaryKey).extend("attrSerializer",i.attrSerializer,["serialize"])})}]),c.factory("RMBuilderRelations",["$injector","inflector","$log","RMUtils","restmod","RMPackerCache",function(a,c,d,e,f,g){function h(a,b){return function(){var c=this.$owner;this.$owner=b;try{return a.apply(this,arguments)}finally{this.$owner=c}}}function i(a,b,c){for(var d in b)b.hasOwnProperty(d)&&a.$on(d,h(b[d],c))}var j={attrAsCollection:function(b,c,f,g,h,j,k){var l,m;return this.attrDefault(b,function(){if("string"==typeof c&&(c=a.get(c),l=c.getProperty("hasMany",{}),m=l.hooks,h)){var e=c.$$getDescription(h);e&&"belongs_to"===e.relation||(d.warn("Must define an inverse belongsTo relation for inverseOf to work"),h=!1)}var g,n=this.$buildScope(c,f||c.encodeUrlName(b));if(g=c.$collection(j||null,n),m&&i(g,m,this),k&&i(g,k,this),g.$dispatch("after-has-many-init"),h){var o=this;g.$on("after-add",function(a){a[h]=o})}return g}),(g||f)&&this.attrMap(b,g||f),this.attrDecoder(b,function(a){this[b].$reset().$decode(a||[])}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"has_many"}),this},attrAsResource:function(b,c,f,g,h,j){var k,l;return this.attrDefault(b,function(){if("string"==typeof c&&(c=a.get(c),k=c.getProperty("hasOne",{}),l=k.hooks,h)){var e=c.$$getDescription(h);e&&"belongs_to"===e.relation||(d.warn("Must define an inverse belongsTo relation for inverseOf to work"),h=!1)}var g,m=this.$buildScope(c,f||c.encodeUrlName(b));return g=c.$new(null,m),l&&i(g,l,this),j&&i(g,j,this),g.$dispatch("after-has-one-init"),h&&(g[h]=this),g}),(g||f)&&this.attrMap(b,g||f),this.attrDecoder(b,function(a){this[b].$decode(a||{})}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"has_one"}),this},attrAsReference:function(c,d,f,h){function i(){"string"==typeof d&&(d=a.get(d))}return this.attrDefault(c,null).attrMask(c,e.WRITE_MASK).attrMeta(c,{relation:"belongs_to"}),this.attrDecoder(c,function(a){return null===a?null:(i(),void(this[c]&&this[c].$pk===d.inferKey(a)?this[c].$decode(a):this[c]=d.$buildRaw(a)))}),f!==!1&&this.attrMap(c+"Id",f||"*",!0).attrDecoder(c+"Id",function(a){a!==b&&(this[c]&&this[c].$pk===a||(null!==a&&a!==!1?(i(),this[c]=g.resolve(d.$new(a)),h&&this[c].$fetch()):this[c]=null))}).attrEncoder(c+"Id",function(){return this[c]?this[c].$pk:null}),this},attrAsReferenceToMany:function(b,d,f){function h(){"string"==typeof d&&(d=a.get(d))}function i(a,b){h(),b.length=0;for(var c=0,e=a.length;e>c;c++)b.push("object"==typeof a[c]?d.$buildRaw(a[c]):g.resolve(d.$new(a[c])))}if(this.attrDefault(b,function(){return[]}).attrMask(b,e.WRITE_MASK).attrMeta(b,{relation:"belongs_to_many"}),this.attrDecoder(b,function(a){a&&i(a,this[b])}),f!==!1){var j=c.singularize(b)+"Ids";this.attrMap(j,f||"*",!0).attrDecoder(j,function(a){a&&i(a,this[b])}).attrEncoder(j,function(){for(var a=[],c=this[b],d=0,e=c.length;e>d;d++)a.push(c[d].$pk);return a})}return this}};return f.mixin(function(){this.extend("attrAsCollection",j.attrAsCollection,["hasMany","path","source","inverseOf","params","hooks"]).extend("attrAsResource",j.attrAsResource,["hasOne","path","source","inverseOf","hooks"]).extend("attrAsReference",j.attrAsReference,["belongsTo","key","prefetch"]).extend("attrAsReferenceToMany",j.attrAsReferenceToMany,["belongsToMany","keys"])})}]),c.factory("RMModelFactory",["$injector","$log","inflector","RMUtils","RMScopeApi","RMCommonApi","RMRecordApi","RMListApi","RMCollectionApi","RMExtendedApi","RMSerializer","RMBuilder",function(c,d,e,f,g,h,i,j,k,l,m,n){var o=/(.*?)([^\/]+)\/?$/,p=f.extendOverriden;return function(c,q){function r(a,b){this.$scope=a||r,this.$pk=b,this.$initialize()}function s(a,b){var c=new B;return c.$scope=b||r,c.$params=a,c.$initialize(),c}function t(a,b,c){var d=E[a];f.assert(!!d,"Invalid api name $1",a),b?d[b]=f.override(d[b],c):f.extendOverriden(d,c)}c=f.cleanUrl(c);var u,v={primaryKey:"id",urlPrefix:null},w=new m(r),x=[],y=[],z={},A={};c&&(v.name=e.singularize(c.replace(o,"$2")));var B=f.buildArrayType(),C=f.buildArrayType(),D=function(a){this.$isCollection=a,this.$initialize()};p(r,{$$getDescription:function(a){return z[a]},$$chain:[],$type:r,$new:function(a,b){return new r(b||r,a)},$collection:s,$url:function(){return v.urlPrefix?f.joinUrl(v.urlPrefix,c):c},$dispatch:function(a,b,c){var d,e,f=A[a];if(f)for(d=0;e=f[d];d++)e.apply(c||this,b||[]);return this},inferKey:function(a){return a&&"undefined"!=typeof a[v.primaryKey]?a[v.primaryKey]:null},getProperty:function(a,c){var d=v[a];return d!==b?d:c},isNested:function(){return!c},single:function(a){return new r({$urlFor:function(){return v.urlPrefix?f.joinUrl(v.urlPrefix,a):a}},"")},dummy:function(a){return new D(a)},list:function(a){var b=new C;return a&&b.push.apply(b,a),b},identity:function(a){if(!a)return v.name;if(a){if(v.plural)return v.plural;if(v.name)return e.pluralize(v.name)}return null},mix:function(){return u.chain(arguments),this.$$chain.push.apply(this.$$chain,arguments),this},unpack:function(a,b){return b},pack:function(a,b){return b},decode:w.decode,encode:w.encode,decodeName:null,encodeName:null,encodeUrlName:function(a){return d.warn("Default paremeterization of urls will be disabled in 1.2, override Model.encodeUrlName with inflector.parameterize in your base model to keep the same behaviour."),e.parameterize(a)}},g),p(r.prototype,{$type:r,$initialize:function(){var a,b,c=this;for(b=0;a=x[b];b++)this[a[0]]="function"==typeof a[1]?a[1].apply(this):a[1];for(b=0;a=y[b];b++)Object.defineProperty(c,a[0],{enumerable:!0,get:a[1],set:function(){}})}},h,i,l),p(B.prototype,{$type:r,$new:function(a,b){return r.$new(a,b||this)},$collection:function(b,c){return b=this.$params?a.extend({},this.$params,b):b,s(b,c||this.$scope)}},j,g,h,k,l),p(C.prototype,{$type:r},j,h),p(D.prototype,{$type:r,$initialize:function(){}},h);var E={Model:r,Record:r.prototype,Collection:B.prototype,List:C.prototype,Dummy:D.prototype};return u=new n(a.extend(w.dsl(),{setProperty:function(a,b){return v[a]=b,this},attrDefault:function(a,b){return x.push([a,b]),this},attrComputed:function(a,b){return y.push([a,b]),this.attrMask(a,!0),this},attrMeta:function(a,b){return z[a]=p(z[a]||{},b),this},define:function(a,b){var c=!1,d="Record";switch("object"==typeof b&&b?d=a:(c=a.split("."),1===c.length?c=c[0]:(d=c[0],c=c[1])),d){case"List":t("Collection",c,b),t("List",c,b);break;case"Scope":t("Model",c,b),t("Collection",c,b);break;case"Resource":t("Record",c,b),t("Collection",c,b),t("List",c,b),t("Dummy",c,b);break;default:t(d,c,b)}return this},on:function(a,b){return(A[a]||(A[a]=[])).push(b),this}})),u.chain(q),r}}]),c.factory("RMFastQ",[function(){function b(a,f){return a&&d(a.then)?c(a):{simple:!0,then:function(c,d){return b(f?d(a):c(a))},"catch":e,"finally":function(e){var g=e();return g&&d(a.then)?c(a.then(function(){return f?b(a,!0):a},function(){return f?b(a,!0):a})):this}}}function c(a){if(a.simple)return a;var d;return a.then(function(a){d=b(a)},function(a){d=b(a,!0)}),{then:function(b,e){return d?d.then(b,e):c(a.then(b,e))},"catch":e,"finally":function(b){return d?d["finally"](b):c(a["finally"](b))}}}var d=a.isFunction,e=function(a){return this.then(null,a)};return{reject:function(a){return b(a,!0)},when:function(a){return b(a,!1)},wrap:c}}]),c.factory("RMPackerCache",[function(){var a;return{feed:function(b,c){a[b]=c},resolve:function(b){if(a){var c=b.$type,d=a[c.identity(!0)];if(d&&b.$pk)for(var e=0,f=d.length;f>e;e++)if(b.$pk===c.inferKey(d[e])){b.$decode(d[e]);break}}return b},prepare:function(){a={}},clear:function(){a=null}}}]),c.factory("RMSerializer",["$injector","inflector","$filter","RMUtils",function(c,d,e,f){function g(a,c){if(null===a&&c.length>1)return b;for(var d,e=0;a&&(d=c[e]);e++)a=a[d];return a}function h(a,b,c){for(var d=0,e=b.length-1;e>d;d++){var f=b[d];a=a[f]||(a[f]={})}a[b[b.length-1]]=c}return function(c){function d(a,b,c){if("function"==typeof b)return b(a);var d=n[a];return"function"==typeof d&&(d=d.call(c)),d&&(d===!0||-1!==d.indexOf(b))}function i(a,e,f,h,i){var k,l,m,n,o,p,s,t,u=f?f+".":"";if(o=r[f])for(s=0,t=o.length;t>s;s++)m=u+o[s].path,d(m,h,i)||(n=o[s].map?g(a,o[s].map):a[c.encodeName?c.encodeName(o[s].path):o[s].path],(o[s].forced||n!==b)&&(n=j(n,m,h,i),n!==b&&(e[o[s].path]=n)));for(k in a)if(a.hasOwnProperty(k)){if(l=c.decodeName?c.decodeName(k):k,"$"===l[0])continue;if(o){for(p=!1,s=0,t=o.length;t>s&&!(p=o[s].mapPath===k);s++);if(p)continue}if(m=u+l,q[m]||d(m,h,i))continue;n=j(a[k],m,h,i),n!==b&&(e[l]=n)}}function j(a,b,c,d){var e=o[b],f=a;if(e)f=e.call(d,a,c);else if("object"==typeof a)if(m(a)){f=[];for(var g=0,h=a.length;h>g;g++)f.push(j(a[g],b+"[]",c,d))}else a&&(f={},i(a,f,b,c,d));return f}function k(a,e,f,g,i){var j,k,m,n,o,p=f?f+".":"";for(j in a)if(a.hasOwnProperty(j)&&"$"!==j[0]){if(k=p+j,q[k]||d(k,g,i))continue;n=l(a[j],k,g,i),n!==b&&(m=c.encodeName?c.encodeName(j):j,e[m]=n),s[k]&&delete a[j]}if(o=r[f])for(var t=0,u=o.length;u>t;t++)k=p+o[t].path,d(k,g,i)||(n=a[o[t].path],(o[t].forced||n!==b)&&(n=l(n,k,g,i),n!==b&&(o[t].map?h(e,o[t].map,n):e[c.encodeName?c.encodeName(o[t].path):o[t].path]=n)))}function l(a,b,c,d){var e=p[b],f=a;if(e)f=e.call(d,a,c);else if(null!==a&&"object"==typeof a&&"function"!=typeof a.toJSON)if(m(a)){f=[];for(var g=0,h=a.length;h>g;g++)f.push(l(a[g],b+"[]",c,d))}else a&&(f={},k(a,f,b,c,d));return f}var m=a.isArray,n={},o={},p={},q={},r={},s={};return{decode:function(a,b,c){i(b,a,"",c,a)},encode:function(a,b){var c={};return k(a,c,"",b,a),c},dsl:function(){return{attrMap:function(a,b,c){var d=a.lastIndexOf("."),e=-1!==d?a.substr(0,d):"",f=-1!==d?a.substr(d+1):a;q[a]=!0;var g=r[e]||(r[e]=[]);return g.push({path:f,map:"*"===b?null:b.split("."),mapPath:b,forced:c}),this},attrMask:function(a,b){return b?n[a]=b:delete n[a],this},attrDecoder:function(a,b,c,d){if("string"==typeof b){var g=e(b);b=function(a){return g(a,c)}}return o[a]=d?f.chain(o[a],b):b,this},attrEncoder:function(a,b,c,d){if("string"==typeof b){var g=e(b);b=function(a){return g(a,c)}}return p[a]=d?f.chain(p[a],b):b,this},attrVolatile:function(a,c){return s[a]=c===b?!0:c,this}}}}}}]),c.factory("DefaultPacker",["restmod","inflector","RMPackerCache",function(b,c,d){function e(a,b,c){for(var d=0,e=b.length;e>d;d++)c(b[d],a[b[d]])}function f(a,b,c){for(var d in a)a.hasOwnProperty(d)&&-1===b.indexOf(d)&&c(d,a[d])}function g(b,c,d,g,h){if("."===d||d===!0){var i=[c];g&&i.push.apply(i,a.isArray(g)?g:[g]),f(b,i,h)}else"string"==typeof d?f(b[d],[],h):e(b,d,h)}return b.mixin(function(){this.define("Model.unpack",function(a,b){var c=null,e=this.getProperty("jsonLinks","included"),f=this.getProperty("jsonMeta","meta");return c=a.$isCollection?this.getProperty("jsonRootMany")||this.getProperty("jsonRoot")||this.identity(!0):this.getProperty("jsonRootSingle")||this.getProperty("jsonRoot")||this.identity(),f&&(a.$metadata={},g(b,c,f,e,function(b,c){a.$metadata[b]=c})),e&&g(b,c,e,f,function(a,b){d.feed(a,b)}),b[c]})})}]),c.factory("RMUtils",["$log",function(a){var b=[],c=function(){var a=function(){};return Object.setPrototypeOf?function(a,b){Object.setPrototypeOf(a,b)}:(new a).__proto__===a.prototype?function(a,b){a.__proto__=b}:void 0}(),d={CREATE_MASK:"C",UPDATE_MASK:"U",READ_MASK:"R",WRITE_MASK:"CU",FULL_MASK:"CRU",format:function(a,b){for(var c=0;b&&cd;d++)if(b(a[d]))return d;return-1},extendOverriden:function(a){for(var b=1;bparent.RestmodArray = Array;"),d=window.RestmodArray,delete window.RestmodArray;for(var g in Array.prototype)"function"!=typeof Array.prototype[g]||d.prototype[g]||(d.prototype[g]=Array.prototype[g]);document.body.removeChild(f),b.push(f)}return d}};return d}])}(angular); \ No newline at end of file diff --git a/dist/plugins/debounced.js b/dist/plugins/debounced.js index 103ef65..92d3d85 100644 --- a/dist/plugins/debounced.js +++ b/dist/plugins/debounced.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/debounced.min.js b/dist/plugins/debounced.min.js index 312ea98..facee89 100644 --- a/dist/plugins/debounced.min.js +++ b/dist/plugins/debounced.min.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/dirty.js b/dist/plugins/dirty.js index 5e3a9e2..54b25e4 100644 --- a/dist/plugins/dirty.js +++ b/dist/plugins/dirty.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/dirty.min.js b/dist/plugins/dirty.min.js index f09f091..a5f3a66 100644 --- a/dist/plugins/dirty.min.js +++ b/dist/plugins/dirty.min.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/find-many.js b/dist/plugins/find-many.js index 573b4a8..7942352 100644 --- a/dist/plugins/find-many.js +++ b/dist/plugins/find-many.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/find-many.min.js b/dist/plugins/find-many.min.js index 332bc96..36d3839 100644 --- a/dist/plugins/find-many.min.js +++ b/dist/plugins/find-many.min.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/nested-dirty.js b/dist/plugins/nested-dirty.js index 7ed9ba4..6229e4b 100644 --- a/dist/plugins/nested-dirty.js +++ b/dist/plugins/nested-dirty.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/nested-dirty.min.js b/dist/plugins/nested-dirty.min.js index 3545b37..3861b19 100644 --- a/dist/plugins/nested-dirty.min.js +++ b/dist/plugins/nested-dirty.min.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/paged.js b/dist/plugins/paged.js index 67da5b3..1a74009 100644 --- a/dist/plugins/paged.js +++ b/dist/plugins/paged.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/paged.min.js b/dist/plugins/paged.min.js index bfaca30..a9605ee 100644 --- a/dist/plugins/paged.min.js +++ b/dist/plugins/paged.min.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/preload.js b/dist/plugins/preload.js index 4422d5f..8f4fa00 100644 --- a/dist/plugins/preload.js +++ b/dist/plugins/preload.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/plugins/preload.min.js b/dist/plugins/preload.min.js index c3f7d16..8336351 100644 --- a/dist/plugins/preload.min.js +++ b/dist/plugins/preload.min.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/styles/ams.js b/dist/styles/ams.js index 70c3546..ec82582 100644 --- a/dist/styles/ams.js +++ b/dist/styles/ams.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/dist/styles/ams.min.js b/dist/styles/ams.min.js index 7da883b..b7dd47f 100644 --- a/dist/styles/ams.min.js +++ b/dist/styles/ams.min.js @@ -1,6 +1,6 @@ /** * API Bound Models for AngularJS - * @version v1.1.10 - 2015-10-24 + * @version v1.1.11 - 2015-10-26 * @link https://github.com/angular-platanus/restmod * @author Ignacio Baixas * @license MIT License, http://www.opensource.org/licenses/MIT diff --git a/package.json b/package.json index c54d35c..ce430a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-restmod", - "version": "1.1.10", + "version": "1.1.11", "description": "API Bound Models for AngularJS", "license": "MIT", "homepage": "https://github.com/angular-platanus/restmod",