angular-gem 1.2.24 → 1.2.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,627 @@
1
+ /**
2
+ * @license AngularJS v1.2.25
3
+ * (c) 2010-2014 Google, Inc. http://angularjs.org
4
+ * License: MIT
5
+ */
6
+ (function(window, angular, undefined) {'use strict';
7
+
8
+ var $resourceMinErr = angular.$$minErr('$resource');
9
+
10
+ // Helper functions and regex to lookup a dotted path on an object
11
+ // stopping at undefined/null. The path must be composed of ASCII
12
+ // identifiers (just like $parse)
13
+ var MEMBER_NAME_REGEX = /^(\.[a-zA-Z_$][0-9a-zA-Z_$]*)+$/;
14
+
15
+ function isValidDottedPath(path) {
16
+ return (path != null && path !== '' && path !== 'hasOwnProperty' &&
17
+ MEMBER_NAME_REGEX.test('.' + path));
18
+ }
19
+
20
+ function lookupDottedPath(obj, path) {
21
+ if (!isValidDottedPath(path)) {
22
+ throw $resourceMinErr('badmember', 'Dotted member path "@{0}" is invalid.', path);
23
+ }
24
+ var keys = path.split('.');
25
+ for (var i = 0, ii = keys.length; i < ii && obj !== undefined; i++) {
26
+ var key = keys[i];
27
+ obj = (obj !== null) ? obj[key] : undefined;
28
+ }
29
+ return obj;
30
+ }
31
+
32
+ /**
33
+ * Create a shallow copy of an object and clear other fields from the destination
34
+ */
35
+ function shallowClearAndCopy(src, dst) {
36
+ dst = dst || {};
37
+
38
+ angular.forEach(dst, function(value, key){
39
+ delete dst[key];
40
+ });
41
+
42
+ for (var key in src) {
43
+ if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
44
+ dst[key] = src[key];
45
+ }
46
+ }
47
+
48
+ return dst;
49
+ }
50
+
51
+ /**
52
+ * @ngdoc module
53
+ * @name ngResource
54
+ * @description
55
+ *
56
+ * # ngResource
57
+ *
58
+ * The `ngResource` module provides interaction support with RESTful services
59
+ * via the $resource service.
60
+ *
61
+ *
62
+ * <div doc-module-components="ngResource"></div>
63
+ *
64
+ * See {@link ngResource.$resource `$resource`} for usage.
65
+ */
66
+
67
+ /**
68
+ * @ngdoc service
69
+ * @name $resource
70
+ * @requires $http
71
+ *
72
+ * @description
73
+ * A factory which creates a resource object that lets you interact with
74
+ * [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
75
+ *
76
+ * The returned resource object has action methods which provide high-level behaviors without
77
+ * the need to interact with the low level {@link ng.$http $http} service.
78
+ *
79
+ * Requires the {@link ngResource `ngResource`} module to be installed.
80
+ *
81
+ * @param {string} url A parametrized URL template with parameters prefixed by `:` as in
82
+ * `/user/:username`. If you are using a URL with a port number (e.g.
83
+ * `http://example.com:8080/api`), it will be respected.
84
+ *
85
+ * If you are using a url with a suffix, just add the suffix, like this:
86
+ * `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')`
87
+ * or even `$resource('http://example.com/resource/:resource_id.:format')`
88
+ * If the parameter before the suffix is empty, :resource_id in this case, then the `/.` will be
89
+ * collapsed down to a single `.`. If you need this sequence to appear and not collapse then you
90
+ * can escape it with `/\.`.
91
+ *
92
+ * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
93
+ * `actions` methods. If any of the parameter value is a function, it will be executed every time
94
+ * when a param value needs to be obtained for a request (unless the param was overridden).
95
+ *
96
+ * Each key value in the parameter object is first bound to url template if present and then any
97
+ * excess keys are appended to the url search query after the `?`.
98
+ *
99
+ * Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
100
+ * URL `/path/greet?salutation=Hello`.
101
+ *
102
+ * If the parameter value is prefixed with `@` then the value for that parameter will be extracted
103
+ * from the corresponding property on the `data` object (provided when calling an action method). For
104
+ * example, if the `defaultParam` object is `{someParam: '@someProp'}` then the value of `someParam`
105
+ * will be `data.someProp`.
106
+ *
107
+ * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend
108
+ * the default set of resource actions. The declaration should be created in the format of {@link
109
+ * ng.$http#usage_parameters $http.config}:
110
+ *
111
+ * {action1: {method:?, params:?, isArray:?, headers:?, ...},
112
+ * action2: {method:?, params:?, isArray:?, headers:?, ...},
113
+ * ...}
114
+ *
115
+ * Where:
116
+ *
117
+ * - **`action`** – {string} – The name of action. This name becomes the name of the method on
118
+ * your resource object.
119
+ * - **`method`** – {string} – Case insensitive HTTP method (e.g. `GET`, `POST`, `PUT`,
120
+ * `DELETE`, `JSONP`, etc).
121
+ * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of
122
+ * the parameter value is a function, it will be executed every time when a param value needs to
123
+ * be obtained for a request (unless the param was overridden).
124
+ * - **`url`** – {string} – action specific `url` override. The url templating is supported just
125
+ * like for the resource-level urls.
126
+ * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array,
127
+ * see `returns` section.
128
+ * - **`transformRequest`** –
129
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
130
+ * transform function or an array of such functions. The transform function takes the http
131
+ * request body and headers and returns its transformed (typically serialized) version.
132
+ * By default, transformRequest will contain one function that checks if the request data is
133
+ * an object and serializes to using `angular.toJson`. To prevent this behavior, set
134
+ * `transformRequest` to an empty array: `transformRequest: []`
135
+ * - **`transformResponse`** –
136
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
137
+ * transform function or an array of such functions. The transform function takes the http
138
+ * response body and headers and returns its transformed (typically deserialized) version.
139
+ * By default, transformResponse will contain one function that checks if the response looks like
140
+ * a JSON string and deserializes it using `angular.fromJson`. To prevent this behavior, set
141
+ * `transformResponse` to an empty array: `transformResponse: []`
142
+ * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
143
+ * GET request, otherwise if a cache instance built with
144
+ * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
145
+ * caching.
146
+ * - **`timeout`** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise} that
147
+ * should abort the request when resolved.
148
+ * - **`withCredentials`** - `{boolean}` - whether to set the `withCredentials` flag on the
149
+ * XHR object. See
150
+ * [requests with credentials](https://developer.mozilla.org/en/http_access_control#section_5)
151
+ * for more information.
152
+ * - **`responseType`** - `{string}` - see
153
+ * [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType).
154
+ * - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
155
+ * `response` and `responseError`. Both `response` and `responseError` interceptors get called
156
+ * with `http response` object. See {@link ng.$http $http interceptors}.
157
+ *
158
+ * @returns {Object} A resource "class" object with methods for the default set of resource actions
159
+ * optionally extended with custom `actions`. The default set contains these actions:
160
+ * ```js
161
+ * { 'get': {method:'GET'},
162
+ * 'save': {method:'POST'},
163
+ * 'query': {method:'GET', isArray:true},
164
+ * 'remove': {method:'DELETE'},
165
+ * 'delete': {method:'DELETE'} };
166
+ * ```
167
+ *
168
+ * Calling these methods invoke an {@link ng.$http} with the specified http method,
169
+ * destination and parameters. When the data is returned from the server then the object is an
170
+ * instance of the resource class. The actions `save`, `remove` and `delete` are available on it
171
+ * as methods with the `$` prefix. This allows you to easily perform CRUD operations (create,
172
+ * read, update, delete) on server-side data like this:
173
+ * ```js
174
+ * var User = $resource('/user/:userId', {userId:'@id'});
175
+ * var user = User.get({userId:123}, function() {
176
+ * user.abc = true;
177
+ * user.$save();
178
+ * });
179
+ * ```
180
+ *
181
+ * It is important to realize that invoking a $resource object method immediately returns an
182
+ * empty reference (object or array depending on `isArray`). Once the data is returned from the
183
+ * server the existing reference is populated with the actual data. This is a useful trick since
184
+ * usually the resource is assigned to a model which is then rendered by the view. Having an empty
185
+ * object results in no rendering, once the data arrives from the server then the object is
186
+ * populated with the data and the view automatically re-renders itself showing the new data. This
187
+ * means that in most cases one never has to write a callback function for the action methods.
188
+ *
189
+ * The action methods on the class object or instance object can be invoked with the following
190
+ * parameters:
191
+ *
192
+ * - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
193
+ * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
194
+ * - non-GET instance actions: `instance.$action([parameters], [success], [error])`
195
+ *
196
+ * Success callback is called with (value, responseHeaders) arguments. Error callback is called
197
+ * with (httpResponse) argument.
198
+ *
199
+ * Class actions return empty instance (with additional properties below).
200
+ * Instance actions return promise of the action.
201
+ *
202
+ * The Resource instances and collection have these additional properties:
203
+ *
204
+ * - `$promise`: the {@link ng.$q promise} of the original server interaction that created this
205
+ * instance or collection.
206
+ *
207
+ * On success, the promise is resolved with the same resource instance or collection object,
208
+ * updated with data from server. This makes it easy to use in
209
+ * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view
210
+ * rendering until the resource(s) are loaded.
211
+ *
212
+ * On failure, the promise is resolved with the {@link ng.$http http response} object, without
213
+ * the `resource` property.
214
+ *
215
+ * If an interceptor object was provided, the promise will instead be resolved with the value
216
+ * returned by the interceptor.
217
+ *
218
+ * - `$resolved`: `true` after first server interaction is completed (either with success or
219
+ * rejection), `false` before that. Knowing if the Resource has been resolved is useful in
220
+ * data-binding.
221
+ *
222
+ * @example
223
+ *
224
+ * # Credit card resource
225
+ *
226
+ * ```js
227
+ // Define CreditCard class
228
+ var CreditCard = $resource('/user/:userId/card/:cardId',
229
+ {userId:123, cardId:'@id'}, {
230
+ charge: {method:'POST', params:{charge:true}}
231
+ });
232
+
233
+ // We can retrieve a collection from the server
234
+ var cards = CreditCard.query(function() {
235
+ // GET: /user/123/card
236
+ // server returns: [ {id:456, number:'1234', name:'Smith'} ];
237
+
238
+ var card = cards[0];
239
+ // each item is an instance of CreditCard
240
+ expect(card instanceof CreditCard).toEqual(true);
241
+ card.name = "J. Smith";
242
+ // non GET methods are mapped onto the instances
243
+ card.$save();
244
+ // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
245
+ // server returns: {id:456, number:'1234', name: 'J. Smith'};
246
+
247
+ // our custom method is mapped as well.
248
+ card.$charge({amount:9.99});
249
+ // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
250
+ });
251
+
252
+ // we can create an instance as well
253
+ var newCard = new CreditCard({number:'0123'});
254
+ newCard.name = "Mike Smith";
255
+ newCard.$save();
256
+ // POST: /user/123/card {number:'0123', name:'Mike Smith'}
257
+ // server returns: {id:789, number:'0123', name: 'Mike Smith'};
258
+ expect(newCard.id).toEqual(789);
259
+ * ```
260
+ *
261
+ * The object returned from this function execution is a resource "class" which has "static" method
262
+ * for each action in the definition.
263
+ *
264
+ * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and
265
+ * `headers`.
266
+ * When the data is returned from the server then the object is an instance of the resource type and
267
+ * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
268
+ * operations (create, read, update, delete) on server-side data.
269
+
270
+ ```js
271
+ var User = $resource('/user/:userId', {userId:'@id'});
272
+ User.get({userId:123}, function(user) {
273
+ user.abc = true;
274
+ user.$save();
275
+ });
276
+ ```
277
+ *
278
+ * It's worth noting that the success callback for `get`, `query` and other methods gets passed
279
+ * in the response that came from the server as well as $http header getter function, so one
280
+ * could rewrite the above example and get access to http headers as:
281
+ *
282
+ ```js
283
+ var User = $resource('/user/:userId', {userId:'@id'});
284
+ User.get({userId:123}, function(u, getResponseHeaders){
285
+ u.abc = true;
286
+ u.$save(function(u, putResponseHeaders) {
287
+ //u => saved user object
288
+ //putResponseHeaders => $http header getter
289
+ });
290
+ });
291
+ ```
292
+ *
293
+ * You can also access the raw `$http` promise via the `$promise` property on the object returned
294
+ *
295
+ ```
296
+ var User = $resource('/user/:userId', {userId:'@id'});
297
+ User.get({userId:123})
298
+ .$promise.then(function(user) {
299
+ $scope.user = user;
300
+ });
301
+ ```
302
+
303
+ * # Creating a custom 'PUT' request
304
+ * In this example we create a custom method on our resource to make a PUT request
305
+ * ```js
306
+ * var app = angular.module('app', ['ngResource', 'ngRoute']);
307
+ *
308
+ * // Some APIs expect a PUT request in the format URL/object/ID
309
+ * // Here we are creating an 'update' method
310
+ * app.factory('Notes', ['$resource', function($resource) {
311
+ * return $resource('/notes/:id', null,
312
+ * {
313
+ * 'update': { method:'PUT' }
314
+ * });
315
+ * }]);
316
+ *
317
+ * // In our controller we get the ID from the URL using ngRoute and $routeParams
318
+ * // We pass in $routeParams and our Notes factory along with $scope
319
+ * app.controller('NotesCtrl', ['$scope', '$routeParams', 'Notes',
320
+ function($scope, $routeParams, Notes) {
321
+ * // First get a note object from the factory
322
+ * var note = Notes.get({ id:$routeParams.id });
323
+ * $id = note.id;
324
+ *
325
+ * // Now call update passing in the ID first then the object you are updating
326
+ * Notes.update({ id:$id }, note);
327
+ *
328
+ * // This will PUT /notes/ID with the note object in the request payload
329
+ * }]);
330
+ * ```
331
+ */
332
+ angular.module('ngResource', ['ng']).
333
+ factory('$resource', ['$http', '$q', function($http, $q) {
334
+
335
+ var DEFAULT_ACTIONS = {
336
+ 'get': {method:'GET'},
337
+ 'save': {method:'POST'},
338
+ 'query': {method:'GET', isArray:true},
339
+ 'remove': {method:'DELETE'},
340
+ 'delete': {method:'DELETE'}
341
+ };
342
+ var noop = angular.noop,
343
+ forEach = angular.forEach,
344
+ extend = angular.extend,
345
+ copy = angular.copy,
346
+ isFunction = angular.isFunction;
347
+
348
+ /**
349
+ * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
350
+ * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
351
+ * segments:
352
+ * segment = *pchar
353
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
354
+ * pct-encoded = "%" HEXDIG HEXDIG
355
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
356
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
357
+ * / "*" / "+" / "," / ";" / "="
358
+ */
359
+ function encodeUriSegment(val) {
360
+ return encodeUriQuery(val, true).
361
+ replace(/%26/gi, '&').
362
+ replace(/%3D/gi, '=').
363
+ replace(/%2B/gi, '+');
364
+ }
365
+
366
+
367
+ /**
368
+ * This method is intended for encoding *key* or *value* parts of query component. We need a
369
+ * custom method because encodeURIComponent is too aggressive and encodes stuff that doesn't
370
+ * have to be encoded per http://tools.ietf.org/html/rfc3986:
371
+ * query = *( pchar / "/" / "?" )
372
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
373
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
374
+ * pct-encoded = "%" HEXDIG HEXDIG
375
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
376
+ * / "*" / "+" / "," / ";" / "="
377
+ */
378
+ function encodeUriQuery(val, pctEncodeSpaces) {
379
+ return encodeURIComponent(val).
380
+ replace(/%40/gi, '@').
381
+ replace(/%3A/gi, ':').
382
+ replace(/%24/g, '$').
383
+ replace(/%2C/gi, ',').
384
+ replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
385
+ }
386
+
387
+ function Route(template, defaults) {
388
+ this.template = template;
389
+ this.defaults = defaults || {};
390
+ this.urlParams = {};
391
+ }
392
+
393
+ Route.prototype = {
394
+ setUrlParams: function(config, params, actionUrl) {
395
+ var self = this,
396
+ url = actionUrl || self.template,
397
+ val,
398
+ encodedVal;
399
+
400
+ var urlParams = self.urlParams = {};
401
+ forEach(url.split(/\W/), function(param){
402
+ if (param === 'hasOwnProperty') {
403
+ throw $resourceMinErr('badname', "hasOwnProperty is not a valid parameter name.");
404
+ }
405
+ if (!(new RegExp("^\\d+$").test(param)) && param &&
406
+ (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
407
+ urlParams[param] = true;
408
+ }
409
+ });
410
+ url = url.replace(/\\:/g, ':');
411
+
412
+ params = params || {};
413
+ forEach(self.urlParams, function(_, urlParam){
414
+ val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
415
+ if (angular.isDefined(val) && val !== null) {
416
+ encodedVal = encodeUriSegment(val);
417
+ url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), function(match, p1) {
418
+ return encodedVal + p1;
419
+ });
420
+ } else {
421
+ url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W|$)", "g"), function(match,
422
+ leadingSlashes, tail) {
423
+ if (tail.charAt(0) == '/') {
424
+ return tail;
425
+ } else {
426
+ return leadingSlashes + tail;
427
+ }
428
+ });
429
+ }
430
+ });
431
+
432
+ // strip trailing slashes and set the url
433
+ url = url.replace(/\/+$/, '') || '/';
434
+ // then replace collapse `/.` if found in the last URL path segment before the query
435
+ // E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
436
+ url = url.replace(/\/\.(?=\w+($|\?))/, '.');
437
+ // replace escaped `/\.` with `/.`
438
+ config.url = url.replace(/\/\\\./, '/.');
439
+
440
+
441
+ // set params - delegate param encoding to $http
442
+ forEach(params, function(value, key){
443
+ if (!self.urlParams[key]) {
444
+ config.params = config.params || {};
445
+ config.params[key] = value;
446
+ }
447
+ });
448
+ }
449
+ };
450
+
451
+
452
+ function resourceFactory(url, paramDefaults, actions) {
453
+ var route = new Route(url);
454
+
455
+ actions = extend({}, DEFAULT_ACTIONS, actions);
456
+
457
+ function extractParams(data, actionParams){
458
+ var ids = {};
459
+ actionParams = extend({}, paramDefaults, actionParams);
460
+ forEach(actionParams, function(value, key){
461
+ if (isFunction(value)) { value = value(); }
462
+ ids[key] = value && value.charAt && value.charAt(0) == '@' ?
463
+ lookupDottedPath(data, value.substr(1)) : value;
464
+ });
465
+ return ids;
466
+ }
467
+
468
+ function defaultResponseInterceptor(response) {
469
+ return response.resource;
470
+ }
471
+
472
+ function Resource(value){
473
+ shallowClearAndCopy(value || {}, this);
474
+ }
475
+
476
+ forEach(actions, function(action, name) {
477
+ var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
478
+
479
+ Resource[name] = function(a1, a2, a3, a4) {
480
+ var params = {}, data, success, error;
481
+
482
+ /* jshint -W086 */ /* (purposefully fall through case statements) */
483
+ switch(arguments.length) {
484
+ case 4:
485
+ error = a4;
486
+ success = a3;
487
+ //fallthrough
488
+ case 3:
489
+ case 2:
490
+ if (isFunction(a2)) {
491
+ if (isFunction(a1)) {
492
+ success = a1;
493
+ error = a2;
494
+ break;
495
+ }
496
+
497
+ success = a2;
498
+ error = a3;
499
+ //fallthrough
500
+ } else {
501
+ params = a1;
502
+ data = a2;
503
+ success = a3;
504
+ break;
505
+ }
506
+ case 1:
507
+ if (isFunction(a1)) success = a1;
508
+ else if (hasBody) data = a1;
509
+ else params = a1;
510
+ break;
511
+ case 0: break;
512
+ default:
513
+ throw $resourceMinErr('badargs',
514
+ "Expected up to 4 arguments [params, data, success, error], got {0} arguments",
515
+ arguments.length);
516
+ }
517
+ /* jshint +W086 */ /* (purposefully fall through case statements) */
518
+
519
+ var isInstanceCall = this instanceof Resource;
520
+ var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data));
521
+ var httpConfig = {};
522
+ var responseInterceptor = action.interceptor && action.interceptor.response ||
523
+ defaultResponseInterceptor;
524
+ var responseErrorInterceptor = action.interceptor && action.interceptor.responseError ||
525
+ undefined;
526
+
527
+ forEach(action, function(value, key) {
528
+ if (key != 'params' && key != 'isArray' && key != 'interceptor') {
529
+ httpConfig[key] = copy(value);
530
+ }
531
+ });
532
+
533
+ if (hasBody) httpConfig.data = data;
534
+ route.setUrlParams(httpConfig,
535
+ extend({}, extractParams(data, action.params || {}), params),
536
+ action.url);
537
+
538
+ var promise = $http(httpConfig).then(function (response) {
539
+ var data = response.data,
540
+ promise = value.$promise;
541
+
542
+ if (data) {
543
+ // Need to convert action.isArray to boolean in case it is undefined
544
+ // jshint -W018
545
+ if (angular.isArray(data) !== (!!action.isArray)) {
546
+ throw $resourceMinErr('badcfg',
547
+ 'Error in resource configuration. Expected ' +
548
+ 'response to contain an {0} but got an {1}',
549
+ action.isArray ? 'array' : 'object',
550
+ angular.isArray(data) ? 'array' : 'object');
551
+ }
552
+ // jshint +W018
553
+ if (action.isArray) {
554
+ value.length = 0;
555
+ forEach(data, function (item) {
556
+ if (typeof item === "object") {
557
+ value.push(new Resource(item));
558
+ } else {
559
+ // Valid JSON values may be string literals, and these should not be converted
560
+ // into objects. These items will not have access to the Resource prototype
561
+ // methods, but unfortunately there
562
+ value.push(item);
563
+ }
564
+ });
565
+ } else {
566
+ shallowClearAndCopy(data, value);
567
+ value.$promise = promise;
568
+ }
569
+ }
570
+
571
+ value.$resolved = true;
572
+
573
+ response.resource = value;
574
+
575
+ return response;
576
+ }, function(response) {
577
+ value.$resolved = true;
578
+
579
+ (error||noop)(response);
580
+
581
+ return $q.reject(response);
582
+ });
583
+
584
+ promise = promise.then(
585
+ function(response) {
586
+ var value = responseInterceptor(response);
587
+ (success||noop)(value, response.headers);
588
+ return value;
589
+ },
590
+ responseErrorInterceptor);
591
+
592
+ if (!isInstanceCall) {
593
+ // we are creating instance / collection
594
+ // - set the initial promise
595
+ // - return the instance / collection
596
+ value.$promise = promise;
597
+ value.$resolved = false;
598
+
599
+ return value;
600
+ }
601
+
602
+ // instance call
603
+ return promise;
604
+ };
605
+
606
+
607
+ Resource.prototype['$' + name] = function(params, success, error) {
608
+ if (isFunction(params)) {
609
+ error = success; success = params; params = {};
610
+ }
611
+ var result = Resource[name].call(this, params, this, success, error);
612
+ return result.$promise || result;
613
+ };
614
+ });
615
+
616
+ Resource.bind = function(additionalParamDefaults){
617
+ return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
618
+ };
619
+
620
+ return Resource;
621
+ }
622
+
623
+ return resourceFactory;
624
+ }]);
625
+
626
+
627
+ })(window, window.angular);