diff --git a/bower.json b/bower.json index 7b540078..1d951b9c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "restangular", - "version": "1.1.6", + "version": "1.1.7", "main": "./dist/restangular.min.js", "description": "Restful Resources service for AngularJS apps", "repository": { diff --git a/dist/restangular.js b/dist/restangular.js index 44e025d9..8cb0f5e2 100644 --- a/dist/restangular.js +++ b/dist/restangular.js @@ -1,6 +1,6 @@ /** * Restful Resources service for AngularJS apps - * @version v1.1.6 - 2013-11-09 + * @version v1.1.7 - 2013-11-09 * @link https://github.com/mgonto/restangular * @author Martin Gontovnikas * @license MIT License, http://www.opensource.org/licenses/MIT @@ -474,7 +474,7 @@ module.provider('Restangular', function() { return resource; } - BaseCreator.prototype.resource = function(current, $http, $httpConfig, callHeaders, callParams, what, etag, operation) { + BaseCreator.prototype.resource = function(current, $http, localHttpConfig, callHeaders, callParams, what, etag, operation) { var params = _.defaults(callParams || {}, this.config.defaultRequestParams.common); var headers = _.defaults(callHeaders || {}, this.config.defaultHeaders); @@ -503,7 +503,7 @@ module.provider('Restangular', function() { url += this.config.suffix; } - var localHttpConfig = $httpConfig; + current[this.config.restangularFields.httpConfig] = undefined; @@ -918,7 +918,7 @@ module.provider('Restangular', function() { callObj = stripRestangular(callObj); } var request = config.fullRequestInterceptor(callObj, operation, route, fetchUrl, - headers || {}, resParams || {}); + headers || {}, resParams || {}, this[config.restangularFields.httpConfig] || {}); var okCallback = function(response) { var resData = response.data; diff --git a/dist/restangular.min.js b/dist/restangular.min.js index 539d9c89..80d9e942 100644 --- a/dist/restangular.min.js +++ b/dist/restangular.min.js @@ -1,8 +1,8 @@ /** * Restful Resources service for AngularJS apps - * @version v1.1.6 - 2013-11-09 + * @version v1.1.7 - 2013-11-09 * @link https://github.com/mgonto/restangular * @author Martin Gontovnikas * @license MIT License, http://www.opensource.org/licenses/MIT */ -!function(){var a=angular.module("restangular",[]);a.provider("Restangular",function(){var a={};a.init=function(a,b){function c(a,b,c,d){var e={};return _.each(_.keys(d),function(f){var g=d[f];g.params=_.extend({},g.params,a.defaultRequestParams[g.method.toLowerCase()]),_.isEmpty(g.params)&&delete g.params,e[f]=a.isSafe(g.method)?function(){return b(_.extend(g,{url:c}))}:function(a){return b(_.extend(g,{url:c,data:a}))}}),e}a.configuration=b;var d=["get","head","options","trace"];b.isSafe=function(a){return _.contains(d,a.toLowerCase())};var e=/^https?:\/\//i;b.isAbsoluteUrl=function(a){return a&&e.test(a)},b.baseUrl=_.isUndefined(b.baseUrl)?"":b.baseUrl,a.setBaseUrl=function(a){return b.baseUrl=/\/$/.test(a)?a.substring(0,a.length-1):a,this},b.extraFields=b.extraFields||[],a.setExtraFields=function(a){return b.extraFields=a,this},b.defaultHttpFields=b.defaultHttpFields||{},a.setDefaultHttpFields=function(a){return b.defaultHttpFields=a,this},b.withHttpValues=function(a,c){return _.defaults(c,a,b.defaultHttpFields)},b.encodeIds=_.isUndefined(b.encodeIds)?!0:b.encodeIds,a.setEncodeIds=function(a){b.encodeIds=a},b.defaultRequestParams=b.defaultRequestParams||{get:{},post:{},put:{},remove:{},common:{}},a.setDefaultRequestParams=function(a,c){var d=[],e=c||a;return _.isUndefined(c)?d.push("common"):_.isArray(a)?d=a:d.push(a),_.each(d,function(a){b.defaultRequestParams[a]=e}),this},a.requestParams=b.defaultRequestParams,b.defaultHeaders=b.defaultHeaders||{},a.setDefaultHeaders=function(c){return b.defaultHeaders=c,a.defaultHeaders=b.defaultHeaders,this},a.defaultHeaders=b.defaultHeaders,b.methodOverriders=b.methodOverriders||[],a.setMethodOverriders=function(a){var c=_.extend([],a);return b.isOverridenMethod("delete",c)&&c.push("remove"),b.methodOverriders=c,this},b.isOverridenMethod=function(a,c){var d=c||b.methodOverriders;return!_.isUndefined(_.find(d,function(b){return b.toLowerCase()===a.toLowerCase()}))},b.urlCreator=b.urlCreator||"path",a.setUrlCreator=function(a){if(!_.has(b.urlCreatorFactory,a))throw new Error("URL Path selected isn't valid");return b.urlCreator=a,this},b.restangularFields=b.restangularFields||{id:"id",route:"route",parentResource:"parentResource",restangularCollection:"restangularCollection",cannonicalId:"__cannonicalId",etag:"restangularEtag",selfLink:"href",get:"get",getList:"getList",put:"put",post:"post",remove:"remove",head:"head",trace:"trace",options:"options",patch:"patch",getRestangularUrl:"getRestangularUrl",putElement:"putElement",addRestangularMethod:"addRestangularMethod",getParentList:"getParentList",clone:"clone",ids:"ids",httpConfig:"_$httpConfig"},a.setRestangularFields=function(a){return b.restangularFields=_.extend(b.restangularFields,a),this},b.setFieldToElem=function(a,b,c){var d=a.split("."),e=b;return _.each(_.initial(d),function(a){e[a]={},e=e[a]}),e[_.last(d)]=c,this},b.getFieldFromElem=function(a,b){var c=a.split("."),d=angular.copy(b);return _.each(c,function(a){d&&(d=d[a])}),d},b.setIdToElem=function(a,c){return b.setFieldToElem(b.restangularFields.id,a,c),this},b.getIdFromElem=function(a){return b.getFieldFromElem(b.restangularFields.id,a)},b.isValidId=function(a){return""!==a&&!_.isUndefined(a)&&!_.isNull(a)},b.setUrlToElem=function(a,c){return b.setFieldToElem(b.restangularFields.selfLink,a,c),this},b.getUrlFromElem=function(a){return b.getFieldFromElem(b.restangularFields.selfLink,a)},b.useCannonicalId=_.isUndefined(b.useCannonicalId)?!1:b.useCannonicalId,a.setUseCannonicalId=function(a){return b.useCannonicalId=a,this},b.getCannonicalIdFromElem=function(a){var c=a[b.restangularFields.cannonicalId],d=b.isValidId(c)?c:b.getIdFromElem(a);return d},b.responseExtractor=b.responseExtractor||function(a){return a},a.setResponseExtractor=function(a){return b.responseExtractor=a,this},a.setResponseInterceptor=a.setResponseExtractor,b.fullRequestInterceptor=b.fullRequestInterceptor||function(a,b,c,d,e,f,g){return{element:a,headers:e,params:f,httpConfig:g}},a.setRequestInterceptor=function(a){return b.fullRequestInterceptor=function(b,c,d,e,f,g,h){return{headers:f,params:g,element:a(b,c,d,e),httpConfig:h}},this},a.setFullRequestInterceptor=function(a){return b.fullRequestInterceptor=a,this},b.errorInterceptor=b.errorInterceptor||function(){},a.setErrorInterceptor=function(a){return b.errorInterceptor=a,this},b.onBeforeElemRestangularized=b.onBeforeElemRestangularized||function(a){return a},a.setOnBeforeElemRestangularized=function(a){return b.onBeforeElemRestangularized=a,this},b.onElemRestangularized=b.onElemRestangularized||function(a){return a},a.setOnElemRestangularized=function(a){return b.onElemRestangularized=a,this},a.setListTypeIsArray=function(){},b.shouldSaveParent=b.shouldSaveParent||function(){return!0},a.setParentless=function(a){return _.isArray(a)?b.shouldSaveParent=function(b){return!_.contains(a,b)}:_.isBoolean(a)&&(b.shouldSaveParent=function(){return!a}),this},b.suffix=_.isUndefined(b.suffix)?null:b.suffix,a.setRequestSuffix=function(a){return b.suffix=a,this},b.transformers=b.transformers||{},a.addElementTransformer=function(a,c,d){var e=null,f=null;2===arguments.length?f=c:(f=d,e=c);var g=b.transformers[a];g||(g=b.transformers[a]=[]),g.push(function(a,b){return _.isNull(e)||a==e?f(b):b})},a.extendCollection=function(b,c){return a.addElementTransformer(b,!0,c)},a.extendModel=function(b,c){return a.addElementTransformer(b,!1,c)},b.transformElem=function(a,c,d,e){var f=b.transformers[d],g=a;return f&&_.each(f,function(a){g=a(c,g)}),b.onElemRestangularized(g,c,d,e)},b.fullResponse=_.isUndefined(b.fullResponse)?!1:b.fullResponse,a.setFullResponse=function(a){return b.fullResponse=a,this},b.urlCreatorFactory={};var f=function(){};f.prototype.setConfig=function(a){return this.config=a,this},f.prototype.parentsArray=function(a){for(var b=[];a;)b.push(a),a=a[this.config.restangularFields.parentResource];return b.reverse()},f.prototype.resource=function(a,d,e,f,g,h,i,j){var k=_.defaults(g||{},this.config.defaultRequestParams.common),l=_.defaults(f||{},this.config.defaultHeaders);i&&(b.isSafe(j)?l["If-None-Match"]=i:l["If-Match"]=i);var m=this.base(a);if(h){var n="";/\/$/.test(m)||(n+="/"),n+=h,m+=n}this.config.suffix&&-1===m.indexOf(this.config.suffix,m.length-suffix.length)&&(m+=this.config.suffix);var o=e;return a[this.config.restangularFields.httpConfig]=void 0,c(this.config,d,m,{getList:this.config.withHttpValues(o,{method:"GET",params:k,headers:l}),get:this.config.withHttpValues(o,{method:"GET",params:k,headers:l}),put:this.config.withHttpValues(o,{method:"PUT",params:k,headers:l}),post:this.config.withHttpValues(o,{method:"POST",params:k,headers:l}),remove:this.config.withHttpValues(o,{method:"DELETE",params:k,headers:l}),head:this.config.withHttpValues(o,{method:"HEAD",params:k,headers:l}),trace:this.config.withHttpValues(o,{method:"TRACE",params:k,headers:l}),options:this.config.withHttpValues(o,{method:"OPTIONS",params:k,headers:l}),patch:this.config.withHttpValues(o,{method:"PATCH",params:k,headers:l})})};var g=function(){};g.prototype=new f,g.prototype.base=function(a){var c=this;return _.reduce(this.parentsArray(a),function(a,d){var e,f=c.config.getUrlFromElem(d);if(f){if(c.config.isAbsoluteUrl(f))return f;e=f}else if(e=d[c.config.restangularFields.route],d[c.config.restangularFields.restangularCollection]){var g=d[c.config.restangularFields.ids];g&&(e+="/"+g.join(","))}else{var h;h=c.config.useCannonicalId?c.config.getCannonicalIdFromElem(d):c.config.getIdFromElem(d),b.isValidId(h)&&(e+="/"+(c.config.encodeIds?encodeURIComponent(h):h))}return a+"/"+e},this.config.baseUrl)},g.prototype.fetchUrl=function(a,b){var c=this.base(a);return b&&(c+="/"+b),c},b.urlCreatorFactory.path=g};var b={};a.init(this,b),this.$get=["$http","$q",function(c,d){function e(f){function g(a,b,c){if(b[f.restangularFields.route]=c,b[f.restangularFields.getRestangularUrl]=_.bind(N.fetchUrl,N,b),b[f.restangularFields.addRestangularMethod]=_.bind(K,b),b[f.restangularFields.clone]=_.bind(s,b,b),b.withHttpConfig=_.bind(z,b),b.one=_.bind(h,b,b),b.all=_.bind(i,b,b),b.several=_.bind(j,b,b),b.oneUrl=_.bind(k,b,b),b.allUrl=_.bind(l,b,b),a&&f.shouldSaveParent(c)){var d=f.getIdFromElem(a),e=f.getUrlFromElem(a),g=_.union(_.values(_.pick(f.restangularFields,["route","parentResource"])),f.extraFields),m=_.pick(a,g);f.isValidId(d)&&f.setIdToElem(m,d),f.isValidId(e)&&f.setUrlToElem(m,e),b[f.restangularFields.parentResource]=m}else b[f.restangularFields.parentResource]=null;return b}function h(a,b,c){var d={};return f.setIdToElem(d,c),t(a,d,b)}function i(a,b){return u(a,[],b,!0)}function j(a,b){var c=[];return c[f.restangularFields.ids]=Array.prototype.splice.call(arguments,2),u(a,c,b,!0)}function k(a,b,c){var d={};return f.setUrlToElem(d,c),t(a,d,b)}function l(a,b,c){var d={};return f.setUrlToElem(d,c),u(a,d,b,!0)}function m(a,b){return a.call=_.bind(n,a),a.get=_.bind(o,a),a[f.restangularFields.restangularCollection]=b,b&&(a.push=_.bind(n,a,"push")),a}function n(a){var b=d.defer(),c=arguments;return this.then(function(d){var e=Array.prototype.slice.call(c,1),f=d[a];f.apply(d,e),b.resolve(d)}),m(b.promise,this[f.restangularFields.restangularCollection])}function o(a){var b=d.defer();return this.then(function(c){b.resolve(c[a])}),m(b.promise,this[f.restangularFields.restangularCollection])}function p(a,b,c){return f.fullResponse?a.resolve(_.extend(b,{data:c})):(a.resolve(c),void 0)}function q(a){return _.omit(a,_.values(_.omit(f.restangularFields,"id")))}function r(a){a.customOperation=_.bind(J,a),_.each(["put","post","get","delete"],function(b){_.each(["do","custom"],function(c){var d,e="delete"===b?"remove":b,f=c+b.toUpperCase();d="put"!==e&&"post"!==e?J:function(a,b,c,d,e){return _.bind(J,this)(a,c,d,e,b)},a[f]=_.bind(d,a,e)})}),a.customGETLIST=_.bind(y,a),a.doGETLIST=a.customGETLIST}function s(a){var b=angular.copy(a);return t(b[f.restangularFields.parentResource],b,b[f.restangularFields.route])}function t(a,b,c,d){var e=f.onBeforeElemRestangularized(b,!1,c),h=g(a,e,c);return f.useCannonicalId&&(h[f.restangularFields.cannonicalId]=f.getIdFromElem(h)),d&&(h[f.restangularFields.getParentList]=function(){return d}),h[f.restangularFields.restangularCollection]=!1,h[f.restangularFields.get]=_.bind(B,h),h[f.restangularFields.getList]=_.bind(y,h),h[f.restangularFields.put]=_.bind(D,h),h[f.restangularFields.post]=_.bind(E,h),h[f.restangularFields.remove]=_.bind(C,h),h[f.restangularFields.head]=_.bind(F,h),h[f.restangularFields.trace]=_.bind(G,h),h[f.restangularFields.options]=_.bind(H,h),h[f.restangularFields.patch]=_.bind(I,h),r(h),f.transformElem(h,!1,c,M)}function u(a,b,c){var d=f.onBeforeElemRestangularized(b,!0,c),e=g(a,d,c);return e[f.restangularFields.restangularCollection]=!0,e[f.restangularFields.post]=_.bind(E,e,null),e[f.restangularFields.head]=_.bind(F,e),e[f.restangularFields.trace]=_.bind(G,e),e[f.restangularFields.putElement]=_.bind(w,e),e[f.restangularFields.options]=_.bind(H,e),e[f.restangularFields.patch]=_.bind(I,e),e[f.restangularFields.get]=_.bind(v,e),e[f.restangularFields.getList]=_.bind(y,e,null),r(e),f.transformElem(e,!0,c,M)}function v(a,b,c){return this.customGET(a.toString(),b,c)}function w(a,b,c){var e=this,f=this[a],g=d.defer();return f.put(b,c).then(function(b){var c=s(e);c[a]=b,g.resolve(c)},function(a){g.reject(a)}),m(g.promise,!0)}function x(a,b,c,d,e,g){var h=f.responseExtractor(a,b,c,d,e,g),i=e.headers("ETag");return h&&i&&(h[f.restangularFields.etag]=i),h}function y(a,b,e){var g=this,h=d.defer(),i="getList",j=N.fetchUrl(this,a),k=a||g[f.restangularFields.route],l=f.fullRequestInterceptor(null,i,k,j,e||{},b||{},this[f.restangularFields.httpConfig]||{});return N.resource(this,c,l.httpConfig,l.headers,l.params,a,this[f.restangularFields.etag],i).getList().then(function(b){var c=b.data,d=x(c,i,k,j,b,h),e=_.map(d,function(b){return g[f.restangularFields.restangularCollection]?t(g[f.restangularFields.parentResource],b,g[f.restangularFields.route],d):t(g,b,a,d)});e=_.extend(d,e),g[f.restangularFields.restangularCollection]?p(h,b,u(g[f.restangularFields.parentResource],e,g[f.restangularFields.route])):p(h,b,u(g,e,a))},function(a){f.errorInterceptor(a)!==!1&&h.reject(a)}),m(h.promise,!0)}function z(a){return this[f.restangularFields.httpConfig]=a,this}function A(a,b,e,g,h){var i=this,j=d.defer(),k=e||{},l=b||this[f.restangularFields.route],n=N.fetchUrl(this,b),o=g||this,r=o[f.restangularFields.etag];_.isObject(o)&&(o=q(o));var s=f.fullRequestInterceptor(o,a,l,n,h||{},k||{}),u=function(c){var d=c.data,e=x(d,a,l,n,c,j);e?"post"!==a||i[f.restangularFields.restangularCollection]?p(j,c,t(i[f.restangularFields.parentResource],e,i[f.restangularFields.route])):p(j,c,t(i,e,b)):p(j,c,void 0)},v=function(a){f.errorInterceptor(a)!==!1&&j.reject(a)},w=a,y=_.extend({},s.headers),z=f.isOverridenMethod(a);return z&&(w="post",y=_.extend(y,{"X-HTTP-Method-Override":"remove"===a?"DELETE":a})),f.isSafe(a)?z?N.resource(this,c,s.httpConfig,y,s.params,b,r,w)[w]({}).then(u,v):N.resource(this,c,s.httpConfig,y,s.params,b,r,w)[w]().then(u,v):N.resource(this,c,s.httpConfig,y,s.params,b,r,w)[w](s.element).then(u,v),m(j.promise)}function B(a,b){return _.bind(A,this)("get",void 0,a,void 0,b)}function C(a,b){return _.bind(A,this)("remove",void 0,a,void 0,b)}function D(a,b){return _.bind(A,this)("put",void 0,a,void 0,b)}function E(a,b,c,d){return _.bind(A,this)("post",a,c,b,d)}function F(a,b){return _.bind(A,this)("head",void 0,a,void 0,b)}function G(a,b){return _.bind(A,this)("trace",void 0,a,void 0,b)}function H(a,b){return _.bind(A,this)("options",void 0,a,void 0,b)}function I(a,b,c){return _.bind(A,this)("patch",void 0,b,a,c)}function J(a,b,c,d,e){return _.bind(A,this)(a,b,c,e,d)}function K(a,b,c,d,e,g){var h;h="getList"===b?_.bind(y,this,c):_.bind(J,this,b,c);var i=function(a,b,c){var f=_.defaults({params:a,headers:b,elem:c},{params:d,headers:e,elem:g});return h(f.params,f.headers,f.elem)};this[a]=f.isSafe(b)?i:function(a,b,c){return i(b,c,a)}}function L(c){var d=angular.copy(b);return a.init(d,d),c(d),e(d)}var M={},N=new f.urlCreatorFactory[f.urlCreator];return N.setConfig(f),a.init(M,f),M.copy=_.bind(s,M),M.withConfig=_.bind(L,M),M.one=_.bind(h,M,null),M.all=_.bind(i,M,null),M.several=_.bind(j,M,null),M.oneUrl=_.bind(k,M,null),M.allUrl=_.bind(l,M,null),M.restangularizeElement=_.bind(t,M),M.restangularizeCollection=_.bind(u,M),M}return e(b)}]})}(); \ No newline at end of file +!function(){var a=angular.module("restangular",[]);a.provider("Restangular",function(){var a={};a.init=function(a,b){function c(a,b,c,d){var e={};return _.each(_.keys(d),function(f){var g=d[f];g.params=_.extend({},g.params,a.defaultRequestParams[g.method.toLowerCase()]),_.isEmpty(g.params)&&delete g.params,e[f]=a.isSafe(g.method)?function(){return b(_.extend(g,{url:c}))}:function(a){return b(_.extend(g,{url:c,data:a}))}}),e}a.configuration=b;var d=["get","head","options","trace"];b.isSafe=function(a){return _.contains(d,a.toLowerCase())};var e=/^https?:\/\//i;b.isAbsoluteUrl=function(a){return a&&e.test(a)},b.baseUrl=_.isUndefined(b.baseUrl)?"":b.baseUrl,a.setBaseUrl=function(a){return b.baseUrl=/\/$/.test(a)?a.substring(0,a.length-1):a,this},b.extraFields=b.extraFields||[],a.setExtraFields=function(a){return b.extraFields=a,this},b.defaultHttpFields=b.defaultHttpFields||{},a.setDefaultHttpFields=function(a){return b.defaultHttpFields=a,this},b.withHttpValues=function(a,c){return _.defaults(c,a,b.defaultHttpFields)},b.encodeIds=_.isUndefined(b.encodeIds)?!0:b.encodeIds,a.setEncodeIds=function(a){b.encodeIds=a},b.defaultRequestParams=b.defaultRequestParams||{get:{},post:{},put:{},remove:{},common:{}},a.setDefaultRequestParams=function(a,c){var d=[],e=c||a;return _.isUndefined(c)?d.push("common"):_.isArray(a)?d=a:d.push(a),_.each(d,function(a){b.defaultRequestParams[a]=e}),this},a.requestParams=b.defaultRequestParams,b.defaultHeaders=b.defaultHeaders||{},a.setDefaultHeaders=function(c){return b.defaultHeaders=c,a.defaultHeaders=b.defaultHeaders,this},a.defaultHeaders=b.defaultHeaders,b.methodOverriders=b.methodOverriders||[],a.setMethodOverriders=function(a){var c=_.extend([],a);return b.isOverridenMethod("delete",c)&&c.push("remove"),b.methodOverriders=c,this},b.isOverridenMethod=function(a,c){var d=c||b.methodOverriders;return!_.isUndefined(_.find(d,function(b){return b.toLowerCase()===a.toLowerCase()}))},b.urlCreator=b.urlCreator||"path",a.setUrlCreator=function(a){if(!_.has(b.urlCreatorFactory,a))throw new Error("URL Path selected isn't valid");return b.urlCreator=a,this},b.restangularFields=b.restangularFields||{id:"id",route:"route",parentResource:"parentResource",restangularCollection:"restangularCollection",cannonicalId:"__cannonicalId",etag:"restangularEtag",selfLink:"href",get:"get",getList:"getList",put:"put",post:"post",remove:"remove",head:"head",trace:"trace",options:"options",patch:"patch",getRestangularUrl:"getRestangularUrl",putElement:"putElement",addRestangularMethod:"addRestangularMethod",getParentList:"getParentList",clone:"clone",ids:"ids",httpConfig:"_$httpConfig"},a.setRestangularFields=function(a){return b.restangularFields=_.extend(b.restangularFields,a),this},b.setFieldToElem=function(a,b,c){var d=a.split("."),e=b;return _.each(_.initial(d),function(a){e[a]={},e=e[a]}),e[_.last(d)]=c,this},b.getFieldFromElem=function(a,b){var c=a.split("."),d=angular.copy(b);return _.each(c,function(a){d&&(d=d[a])}),d},b.setIdToElem=function(a,c){return b.setFieldToElem(b.restangularFields.id,a,c),this},b.getIdFromElem=function(a){return b.getFieldFromElem(b.restangularFields.id,a)},b.isValidId=function(a){return""!==a&&!_.isUndefined(a)&&!_.isNull(a)},b.setUrlToElem=function(a,c){return b.setFieldToElem(b.restangularFields.selfLink,a,c),this},b.getUrlFromElem=function(a){return b.getFieldFromElem(b.restangularFields.selfLink,a)},b.useCannonicalId=_.isUndefined(b.useCannonicalId)?!1:b.useCannonicalId,a.setUseCannonicalId=function(a){return b.useCannonicalId=a,this},b.getCannonicalIdFromElem=function(a){var c=a[b.restangularFields.cannonicalId],d=b.isValidId(c)?c:b.getIdFromElem(a);return d},b.responseExtractor=b.responseExtractor||function(a){return a},a.setResponseExtractor=function(a){return b.responseExtractor=a,this},a.setResponseInterceptor=a.setResponseExtractor,b.fullRequestInterceptor=b.fullRequestInterceptor||function(a,b,c,d,e,f,g){return{element:a,headers:e,params:f,httpConfig:g}},a.setRequestInterceptor=function(a){return b.fullRequestInterceptor=function(b,c,d,e,f,g,h){return{headers:f,params:g,element:a(b,c,d,e),httpConfig:h}},this},a.setFullRequestInterceptor=function(a){return b.fullRequestInterceptor=a,this},b.errorInterceptor=b.errorInterceptor||function(){},a.setErrorInterceptor=function(a){return b.errorInterceptor=a,this},b.onBeforeElemRestangularized=b.onBeforeElemRestangularized||function(a){return a},a.setOnBeforeElemRestangularized=function(a){return b.onBeforeElemRestangularized=a,this},b.onElemRestangularized=b.onElemRestangularized||function(a){return a},a.setOnElemRestangularized=function(a){return b.onElemRestangularized=a,this},a.setListTypeIsArray=function(){},b.shouldSaveParent=b.shouldSaveParent||function(){return!0},a.setParentless=function(a){return _.isArray(a)?b.shouldSaveParent=function(b){return!_.contains(a,b)}:_.isBoolean(a)&&(b.shouldSaveParent=function(){return!a}),this},b.suffix=_.isUndefined(b.suffix)?null:b.suffix,a.setRequestSuffix=function(a){return b.suffix=a,this},b.transformers=b.transformers||{},a.addElementTransformer=function(a,c,d){var e=null,f=null;2===arguments.length?f=c:(f=d,e=c);var g=b.transformers[a];g||(g=b.transformers[a]=[]),g.push(function(a,b){return _.isNull(e)||a==e?f(b):b})},a.extendCollection=function(b,c){return a.addElementTransformer(b,!0,c)},a.extendModel=function(b,c){return a.addElementTransformer(b,!1,c)},b.transformElem=function(a,c,d,e){var f=b.transformers[d],g=a;return f&&_.each(f,function(a){g=a(c,g)}),b.onElemRestangularized(g,c,d,e)},b.fullResponse=_.isUndefined(b.fullResponse)?!1:b.fullResponse,a.setFullResponse=function(a){return b.fullResponse=a,this},b.urlCreatorFactory={};var f=function(){};f.prototype.setConfig=function(a){return this.config=a,this},f.prototype.parentsArray=function(a){for(var b=[];a;)b.push(a),a=a[this.config.restangularFields.parentResource];return b.reverse()},f.prototype.resource=function(a,d,e,f,g,h,i,j){var k=_.defaults(g||{},this.config.defaultRequestParams.common),l=_.defaults(f||{},this.config.defaultHeaders);i&&(b.isSafe(j)?l["If-None-Match"]=i:l["If-Match"]=i);var m=this.base(a);if(h){var n="";/\/$/.test(m)||(n+="/"),n+=h,m+=n}return this.config.suffix&&-1===m.indexOf(this.config.suffix,m.length-suffix.length)&&(m+=this.config.suffix),a[this.config.restangularFields.httpConfig]=void 0,c(this.config,d,m,{getList:this.config.withHttpValues(e,{method:"GET",params:k,headers:l}),get:this.config.withHttpValues(e,{method:"GET",params:k,headers:l}),put:this.config.withHttpValues(e,{method:"PUT",params:k,headers:l}),post:this.config.withHttpValues(e,{method:"POST",params:k,headers:l}),remove:this.config.withHttpValues(e,{method:"DELETE",params:k,headers:l}),head:this.config.withHttpValues(e,{method:"HEAD",params:k,headers:l}),trace:this.config.withHttpValues(e,{method:"TRACE",params:k,headers:l}),options:this.config.withHttpValues(e,{method:"OPTIONS",params:k,headers:l}),patch:this.config.withHttpValues(e,{method:"PATCH",params:k,headers:l})})};var g=function(){};g.prototype=new f,g.prototype.base=function(a){var c=this;return _.reduce(this.parentsArray(a),function(a,d){var e,f=c.config.getUrlFromElem(d);if(f){if(c.config.isAbsoluteUrl(f))return f;e=f}else if(e=d[c.config.restangularFields.route],d[c.config.restangularFields.restangularCollection]){var g=d[c.config.restangularFields.ids];g&&(e+="/"+g.join(","))}else{var h;h=c.config.useCannonicalId?c.config.getCannonicalIdFromElem(d):c.config.getIdFromElem(d),b.isValidId(h)&&(e+="/"+(c.config.encodeIds?encodeURIComponent(h):h))}return a+"/"+e},this.config.baseUrl)},g.prototype.fetchUrl=function(a,b){var c=this.base(a);return b&&(c+="/"+b),c},b.urlCreatorFactory.path=g};var b={};a.init(this,b),this.$get=["$http","$q",function(c,d){function e(f){function g(a,b,c){if(b[f.restangularFields.route]=c,b[f.restangularFields.getRestangularUrl]=_.bind(N.fetchUrl,N,b),b[f.restangularFields.addRestangularMethod]=_.bind(K,b),b[f.restangularFields.clone]=_.bind(s,b,b),b.withHttpConfig=_.bind(z,b),b.one=_.bind(h,b,b),b.all=_.bind(i,b,b),b.several=_.bind(j,b,b),b.oneUrl=_.bind(k,b,b),b.allUrl=_.bind(l,b,b),a&&f.shouldSaveParent(c)){var d=f.getIdFromElem(a),e=f.getUrlFromElem(a),g=_.union(_.values(_.pick(f.restangularFields,["route","parentResource"])),f.extraFields),m=_.pick(a,g);f.isValidId(d)&&f.setIdToElem(m,d),f.isValidId(e)&&f.setUrlToElem(m,e),b[f.restangularFields.parentResource]=m}else b[f.restangularFields.parentResource]=null;return b}function h(a,b,c){var d={};return f.setIdToElem(d,c),t(a,d,b)}function i(a,b){return u(a,[],b,!0)}function j(a,b){var c=[];return c[f.restangularFields.ids]=Array.prototype.splice.call(arguments,2),u(a,c,b,!0)}function k(a,b,c){var d={};return f.setUrlToElem(d,c),t(a,d,b)}function l(a,b,c){var d={};return f.setUrlToElem(d,c),u(a,d,b,!0)}function m(a,b){return a.call=_.bind(n,a),a.get=_.bind(o,a),a[f.restangularFields.restangularCollection]=b,b&&(a.push=_.bind(n,a,"push")),a}function n(a){var b=d.defer(),c=arguments;return this.then(function(d){var e=Array.prototype.slice.call(c,1),f=d[a];f.apply(d,e),b.resolve(d)}),m(b.promise,this[f.restangularFields.restangularCollection])}function o(a){var b=d.defer();return this.then(function(c){b.resolve(c[a])}),m(b.promise,this[f.restangularFields.restangularCollection])}function p(a,b,c){return f.fullResponse?a.resolve(_.extend(b,{data:c})):(a.resolve(c),void 0)}function q(a){return _.omit(a,_.values(_.omit(f.restangularFields,"id")))}function r(a){a.customOperation=_.bind(J,a),_.each(["put","post","get","delete"],function(b){_.each(["do","custom"],function(c){var d,e="delete"===b?"remove":b,f=c+b.toUpperCase();d="put"!==e&&"post"!==e?J:function(a,b,c,d,e){return _.bind(J,this)(a,c,d,e,b)},a[f]=_.bind(d,a,e)})}),a.customGETLIST=_.bind(y,a),a.doGETLIST=a.customGETLIST}function s(a){var b=angular.copy(a);return t(b[f.restangularFields.parentResource],b,b[f.restangularFields.route])}function t(a,b,c,d){var e=f.onBeforeElemRestangularized(b,!1,c),h=g(a,e,c);return f.useCannonicalId&&(h[f.restangularFields.cannonicalId]=f.getIdFromElem(h)),d&&(h[f.restangularFields.getParentList]=function(){return d}),h[f.restangularFields.restangularCollection]=!1,h[f.restangularFields.get]=_.bind(B,h),h[f.restangularFields.getList]=_.bind(y,h),h[f.restangularFields.put]=_.bind(D,h),h[f.restangularFields.post]=_.bind(E,h),h[f.restangularFields.remove]=_.bind(C,h),h[f.restangularFields.head]=_.bind(F,h),h[f.restangularFields.trace]=_.bind(G,h),h[f.restangularFields.options]=_.bind(H,h),h[f.restangularFields.patch]=_.bind(I,h),r(h),f.transformElem(h,!1,c,M)}function u(a,b,c){var d=f.onBeforeElemRestangularized(b,!0,c),e=g(a,d,c);return e[f.restangularFields.restangularCollection]=!0,e[f.restangularFields.post]=_.bind(E,e,null),e[f.restangularFields.head]=_.bind(F,e),e[f.restangularFields.trace]=_.bind(G,e),e[f.restangularFields.putElement]=_.bind(w,e),e[f.restangularFields.options]=_.bind(H,e),e[f.restangularFields.patch]=_.bind(I,e),e[f.restangularFields.get]=_.bind(v,e),e[f.restangularFields.getList]=_.bind(y,e,null),r(e),f.transformElem(e,!0,c,M)}function v(a,b,c){return this.customGET(a.toString(),b,c)}function w(a,b,c){var e=this,f=this[a],g=d.defer();return f.put(b,c).then(function(b){var c=s(e);c[a]=b,g.resolve(c)},function(a){g.reject(a)}),m(g.promise,!0)}function x(a,b,c,d,e,g){var h=f.responseExtractor(a,b,c,d,e,g),i=e.headers("ETag");return h&&i&&(h[f.restangularFields.etag]=i),h}function y(a,b,e){var g=this,h=d.defer(),i="getList",j=N.fetchUrl(this,a),k=a||g[f.restangularFields.route],l=f.fullRequestInterceptor(null,i,k,j,e||{},b||{},this[f.restangularFields.httpConfig]||{});return N.resource(this,c,l.httpConfig,l.headers,l.params,a,this[f.restangularFields.etag],i).getList().then(function(b){var c=b.data,d=x(c,i,k,j,b,h),e=_.map(d,function(b){return g[f.restangularFields.restangularCollection]?t(g[f.restangularFields.parentResource],b,g[f.restangularFields.route],d):t(g,b,a,d)});e=_.extend(d,e),g[f.restangularFields.restangularCollection]?p(h,b,u(g[f.restangularFields.parentResource],e,g[f.restangularFields.route])):p(h,b,u(g,e,a))},function(a){f.errorInterceptor(a)!==!1&&h.reject(a)}),m(h.promise,!0)}function z(a){return this[f.restangularFields.httpConfig]=a,this}function A(a,b,e,g,h){var i=this,j=d.defer(),k=e||{},l=b||this[f.restangularFields.route],n=N.fetchUrl(this,b),o=g||this,r=o[f.restangularFields.etag];_.isObject(o)&&(o=q(o));var s=f.fullRequestInterceptor(o,a,l,n,h||{},k||{},this[f.restangularFields.httpConfig]||{}),u=function(c){var d=c.data,e=x(d,a,l,n,c,j);e?"post"!==a||i[f.restangularFields.restangularCollection]?p(j,c,t(i[f.restangularFields.parentResource],e,i[f.restangularFields.route])):p(j,c,t(i,e,b)):p(j,c,void 0)},v=function(a){f.errorInterceptor(a)!==!1&&j.reject(a)},w=a,y=_.extend({},s.headers),z=f.isOverridenMethod(a);return z&&(w="post",y=_.extend(y,{"X-HTTP-Method-Override":"remove"===a?"DELETE":a})),f.isSafe(a)?z?N.resource(this,c,s.httpConfig,y,s.params,b,r,w)[w]({}).then(u,v):N.resource(this,c,s.httpConfig,y,s.params,b,r,w)[w]().then(u,v):N.resource(this,c,s.httpConfig,y,s.params,b,r,w)[w](s.element).then(u,v),m(j.promise)}function B(a,b){return _.bind(A,this)("get",void 0,a,void 0,b)}function C(a,b){return _.bind(A,this)("remove",void 0,a,void 0,b)}function D(a,b){return _.bind(A,this)("put",void 0,a,void 0,b)}function E(a,b,c,d){return _.bind(A,this)("post",a,c,b,d)}function F(a,b){return _.bind(A,this)("head",void 0,a,void 0,b)}function G(a,b){return _.bind(A,this)("trace",void 0,a,void 0,b)}function H(a,b){return _.bind(A,this)("options",void 0,a,void 0,b)}function I(a,b,c){return _.bind(A,this)("patch",void 0,b,a,c)}function J(a,b,c,d,e){return _.bind(A,this)(a,b,c,e,d)}function K(a,b,c,d,e,g){var h;h="getList"===b?_.bind(y,this,c):_.bind(J,this,b,c);var i=function(a,b,c){var f=_.defaults({params:a,headers:b,elem:c},{params:d,headers:e,elem:g});return h(f.params,f.headers,f.elem)};this[a]=f.isSafe(b)?i:function(a,b,c){return i(b,c,a)}}function L(c){var d=angular.copy(b);return a.init(d,d),c(d),e(d)}var M={},N=new f.urlCreatorFactory[f.urlCreator];return N.setConfig(f),a.init(M,f),M.copy=_.bind(s,M),M.withConfig=_.bind(L,M),M.one=_.bind(h,M,null),M.all=_.bind(i,M,null),M.several=_.bind(j,M,null),M.oneUrl=_.bind(k,M,null),M.allUrl=_.bind(l,M,null),M.restangularizeElement=_.bind(t,M),M.restangularizeCollection=_.bind(u,M),M}return e(b)}]})}(); \ No newline at end of file diff --git a/dist/restangular.zip b/dist/restangular.zip index f6fd71b8..103b62f1 100644 Binary files a/dist/restangular.zip and b/dist/restangular.zip differ diff --git a/package.json b/package.json index f4f827b4..0dd97cec 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "restangular", "description": "Restful Resources service for AngularJS apps", - "version": "1.1.6", + "version": "1.1.7", "filename": "restangular.min.js", "main": "./dist/restangular.min.js", "homepage": "https://github.com/mgonto/restangular",