angular-gem 1.2.19 → 1.2.20

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