angular-gem 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/lib/angular-gem/version.rb +1 -1
  2. data/lib/tasks/copy.rake +22 -11
  3. data/lib/tasks/tag.rake +2 -11
  4. data/vendor/assets/javascripts/1.2.0/angular-animate.js +1226 -0
  5. data/vendor/assets/javascripts/1.2.0/angular-animate.min.js +21 -0
  6. data/vendor/assets/javascripts/1.2.0/angular-animate.min.js.map +8 -0
  7. data/vendor/assets/javascripts/{angular-cookies-unstable.js → 1.2.0/angular-cookies.js} +21 -4
  8. data/vendor/assets/javascripts/1.2.0/angular-cookies.min.js +8 -0
  9. data/vendor/assets/javascripts/1.2.0/angular-cookies.min.js.map +8 -0
  10. data/vendor/assets/javascripts/1.2.0/angular-csp.css +24 -0
  11. data/vendor/assets/javascripts/{angular-loader-unstable.js → 1.2.0/angular-loader.js} +48 -29
  12. data/vendor/assets/javascripts/1.2.0/angular-loader.min.js +8 -0
  13. data/vendor/assets/javascripts/1.2.0/angular-loader.min.js.map +8 -0
  14. data/vendor/assets/javascripts/{angular-mocks-unstable.js → 1.2.0/angular-mocks.js} +460 -216
  15. data/vendor/assets/javascripts/{angular-resource-unstable.js → 1.2.0/angular-resource.js} +189 -148
  16. data/vendor/assets/javascripts/1.2.0/angular-resource.min.js +12 -0
  17. data/vendor/assets/javascripts/1.2.0/angular-resource.min.js.map +8 -0
  18. data/vendor/assets/javascripts/1.2.0/angular-route.js +880 -0
  19. data/vendor/assets/javascripts/1.2.0/angular-route.min.js +14 -0
  20. data/vendor/assets/javascripts/1.2.0/angular-route.min.js.map +8 -0
  21. data/vendor/assets/javascripts/{angular-sanitize-unstable.js → 1.2.0/angular-sanitize.js} +142 -123
  22. data/vendor/assets/javascripts/1.2.0/angular-sanitize.min.js +14 -0
  23. data/vendor/assets/javascripts/1.2.0/angular-sanitize.min.js.map +8 -0
  24. data/vendor/assets/javascripts/{angular-scenario-unstable.js → 1.2.0/angular-scenario.js} +15978 -12405
  25. data/vendor/assets/javascripts/{angular-mobile-unstable.js → 1.2.0/angular-touch.js} +214 -111
  26. data/vendor/assets/javascripts/1.2.0/angular-touch.min.js +13 -0
  27. data/vendor/assets/javascripts/1.2.0/angular-touch.min.js.map +8 -0
  28. data/vendor/assets/javascripts/{angular-unstable.js → 1.2.0/angular.js} +10167 -7012
  29. data/vendor/assets/javascripts/1.2.0/angular.min.js +200 -0
  30. data/vendor/assets/javascripts/1.2.0/angular.min.js.map +8 -0
  31. data/vendor/assets/javascripts/1.2.0/errors.json +1 -0
  32. data/vendor/assets/javascripts/1.2.0/version.json +1 -0
  33. data/vendor/assets/javascripts/1.2.0/version.txt +1 -0
  34. data/vendor/assets/javascripts/angular-animate.js +1226 -0
  35. data/vendor/assets/javascripts/angular-animate.min.js +21 -0
  36. data/vendor/assets/javascripts/angular-cookies.js +21 -4
  37. data/vendor/assets/javascripts/angular-cookies.min.js +8 -0
  38. data/vendor/assets/javascripts/angular-loader.js +63 -17
  39. data/vendor/assets/javascripts/angular-loader.min.js +8 -0
  40. data/vendor/assets/javascripts/angular-mocks.js +553 -211
  41. data/vendor/assets/javascripts/angular-resource.js +268 -147
  42. data/vendor/assets/javascripts/angular-resource.min.js +12 -0
  43. data/vendor/assets/javascripts/angular-route.js +880 -0
  44. data/vendor/assets/javascripts/angular-route.min.js +14 -0
  45. data/vendor/assets/javascripts/angular-sanitize.js +165 -125
  46. data/vendor/assets/javascripts/angular-sanitize.min.js +14 -0
  47. data/vendor/assets/javascripts/angular-scenario.js +16615 -10889
  48. data/vendor/assets/javascripts/angular-touch.js +563 -0
  49. data/vendor/assets/javascripts/angular-touch.min.js +13 -0
  50. data/vendor/assets/javascripts/angular.js +9717 -4533
  51. data/vendor/assets/javascripts/angular.min.js +200 -0
  52. metadata +44 -21
  53. data/test/dummy/log/test.log +0 -2
  54. data/test/dummy/tmp/cache/assets/D65/250/sprockets%2F54a960d46bb0b354e8bd46fa03f5e0e4 +0 -0
  55. data/test/dummy/tmp/cache/assets/D6A/FB0/sprockets%2F92721e9941b77adcfdfba3d060622de2 +0 -0
  56. data/test/dummy/tmp/cache/assets/E07/040/sprockets%2Ff55b8ce9d0f28ce36b768a1c7aeb2ef3 +0 -0
  57. data/test/tmp/app/assets/javascripts/application.js +0 -5
@@ -1,15 +1,27 @@
1
1
  /**
2
- * @license AngularJS v1.1.5
2
+ * @license AngularJS v1.2.0
3
3
  * (c) 2010-2012 Google, Inc. http://angularjs.org
4
4
  * License: MIT
5
5
  */
6
- (function(window, angular, undefined) {
7
- 'use strict';
6
+ (function(window, angular, undefined) {'use strict';
7
+
8
+ var $resourceMinErr = angular.$$minErr('$resource');
8
9
 
9
10
  /**
10
11
  * @ngdoc overview
11
12
  * @name ngResource
12
13
  * @description
14
+ *
15
+ * # ngResource
16
+ *
17
+ * The `ngResource` module provides interaction support with RESTful services
18
+ * via the $resource service.
19
+ *
20
+ * {@installModule resource}
21
+ *
22
+ * <div doc-module-components="ngResource"></div>
23
+ *
24
+ * See {@link ngResource.$resource `$resource`} for usage.
13
25
  */
14
26
 
15
27
  /**
@@ -24,25 +36,15 @@
24
36
  * The returned resource object has action methods which provide high-level behaviors without
25
37
  * the need to interact with the low level {@link ng.$http $http} service.
26
38
  *
27
- * # Installation
28
- * To use $resource make sure you have included the `angular-resource.js` that comes in Angular
29
- * package. You can also find this file on Google CDN, bower as well as at
30
- * {@link http://code.angularjs.org/ code.angularjs.org}.
31
- *
32
- * Finally load the module in your application:
33
- *
34
- * angular.module('app', ['ngResource']);
35
- *
36
- * and you are ready to get started!
39
+ * Requires the {@link ngResource `ngResource`} module to be installed.
37
40
  *
38
41
  * @param {string} url A parametrized URL template with parameters prefixed by `:` as in
39
42
  * `/user/:username`. If you are using a URL with a port number (e.g.
40
- * `http://example.com:8080/api`), you'll need to escape the colon character before the port
41
- * number, like this: `$resource('http://example.com\\:8080/api')`.
43
+ * `http://example.com:8080/api`), it will be respected.
42
44
  *
43
- * If you are using a url with a suffix, just add the suffix, like this:
44
- * `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')
45
- * or even `$resource('http://example.com/resource/:resource_id.:format')`
45
+ * If you are using a url with a suffix, just add the suffix, like this:
46
+ * `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')`
47
+ * or even `$resource('http://example.com/resource/:resource_id.:format')`
46
48
  * If the parameter before the suffix is empty, :resource_id in this case, then the `/.` will be
47
49
  * collapsed down to a single `.`. If you need this sequence to appear and not collapse then you
48
50
  * can escape it with `/\.`.
@@ -62,7 +64,7 @@
62
64
  *
63
65
  * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
64
66
  * default set of resource actions. The declaration should be created in the format of {@link
65
- * ng.$http#Parameters $http.config}:
67
+ * ng.$http#usage_parameters $http.config}:
66
68
  *
67
69
  * {action1: {method:?, params:?, isArray:?, headers:?, ...},
68
70
  * action2: {method:?, params:?, isArray:?, headers:?, ...},
@@ -70,21 +72,23 @@
70
72
  *
71
73
  * Where:
72
74
  *
73
- * - **`action`** – {string} – The name of action. This name becomes the name of the method on your
74
- * resource object.
75
- * - **`method`** – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`,
76
- * and `JSONP`.
77
- * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of the
78
- * parameter value is a function, it will be executed every time when a param value needs to be
79
- * obtained for a request (unless the param was overridden).
80
- * - **`url`** – {string} – action specific `url` override. The url templating is supported just like
81
- * for the resource-level urls.
82
- * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array, see
83
- * `returns` section.
84
- * - **`transformRequest`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
75
+ * - **`action`** – {string} – The name of action. This name becomes the name of the method on
76
+ * your resource object.
77
+ * - **`method`** – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`,
78
+ * `DELETE`, and `JSONP`.
79
+ * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of
80
+ * the parameter value is a function, it will be executed every time when a param value needs to
81
+ * be obtained for a request (unless the param was overridden).
82
+ * - **`url`** – {string} – action specific `url` override. The url templating is supported just
83
+ * like for the resource-level urls.
84
+ * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array,
85
+ * see `returns` section.
86
+ * - **`transformRequest`** –
87
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
85
88
  * transform function or an array of such functions. The transform function takes the http
86
89
  * request body and headers and returns its transformed (typically serialized) version.
87
- * - **`transformResponse`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
90
+ * - **`transformResponse`** –
91
+ * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
88
92
  * transform function or an array of such functions. The transform function takes the http
89
93
  * response body and headers and returns its transformed (typically deserialized) version.
90
94
  * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
@@ -93,11 +97,14 @@
93
97
  * caching.
94
98
  * - **`timeout`** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise} that
95
99
  * should abort the request when resolved.
96
- * - **`withCredentials`** - `{boolean}` - whether to to set the `withCredentials` flag on the
100
+ * - **`withCredentials`** - `{boolean}` - whether to set the `withCredentials` flag on the
97
101
  * XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5
98
102
  * requests with credentials} for more information.
99
103
  * - **`responseType`** - `{string}` - see {@link
100
104
  * https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType requestType}.
105
+ * - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
106
+ * `response` and `responseError`. Both `response` and `responseError` interceptors get called
107
+ * with `http response` object. See {@link ng.$http $http interceptors}.
101
108
  *
102
109
  * @returns {Object} A resource "class" object with methods for the default set of resource actions
103
110
  * optionally extended with custom `actions`. The default set contains these actions:
@@ -136,24 +143,28 @@
136
143
  * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
137
144
  * - non-GET instance actions: `instance.$action([parameters], [success], [error])`
138
145
  *
146
+ * Success callback is called with (value, responseHeaders) arguments. Error callback is called
147
+ * with (httpResponse) argument.
139
148
  *
140
- * The Resource instances and collection have these additional properties:
149
+ * Class actions return empty instance (with additional properties below).
150
+ * Instance actions return promise of the action.
141
151
  *
142
- * - `$then`: the `then` method of a {@link ng.$q promise} derived from the underlying
143
- * {@link ng.$http $http} call.
152
+ * The Resource instances and collection have these additional properties:
144
153
  *
145
- * The success callback for the `$then` method will be resolved if the underlying `$http` requests
146
- * succeeds.
154
+ * - `$promise`: the {@link ng.$q promise} of the original server interaction that created this
155
+ * instance or collection.
147
156
  *
148
- * The success callback is called with a single object which is the {@link ng.$http http response}
149
- * object extended with a new property `resource`. This `resource` property is a reference to the
150
- * result of the resource action resource object or array of resources.
157
+ * On success, the promise is resolved with the same resource instance or collection object,
158
+ * updated with data from server. This makes it easy to use in
159
+ * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view
160
+ * rendering until the resource(s) are loaded.
151
161
  *
152
- * The error callback is called with the {@link ng.$http http response} object when an http
153
- * error occurs.
162
+ * On failure, the promise is resolved with the {@link ng.$http http response} object, without
163
+ * the `resource` property.
154
164
  *
155
- * - `$resolved`: true if the promise has been resolved (either with success or rejection);
156
- * Knowing if the Resource has been resolved is useful in data-binding.
165
+ * - `$resolved`: `true` after first server interaction is completed (either with success or
166
+ * rejection), `false` before that. Knowing if the Resource has been resolved is useful in
167
+ * data-binding.
157
168
  *
158
169
  * @example
159
170
  *
@@ -197,7 +208,8 @@
197
208
  * The object returned from this function execution is a resource "class" which has "static" method
198
209
  * for each action in the definition.
199
210
  *
200
- * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and `headers`.
211
+ * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and
212
+ * `headers`.
201
213
  * When the data is returned from the server then the object is an instance of the resource type and
202
214
  * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
203
215
  * operations (create, read, update, delete) on server-side data.
@@ -210,7 +222,7 @@
210
222
  });
211
223
  </pre>
212
224
  *
213
- * It's worth noting that the success callback for `get`, `query` and other method gets passed
225
+ * It's worth noting that the success callback for `get`, `query` and other methods gets passed
214
226
  * in the response that came from the server as well as $http header getter function, so one
215
227
  * could rewrite the above example and get access to http headers as:
216
228
  *
@@ -229,52 +241,56 @@
229
241
 
230
242
  Let's look at what a buzz client created with the `$resource` service looks like:
231
243
  <doc:example>
232
- <doc:source jsfiddle="false">
233
- <script>
234
- function BuzzController($resource) {
235
- this.userId = 'googlebuzz';
236
- this.Activity = $resource(
237
- 'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
238
- {alt:'json', callback:'JSON_CALLBACK'},
239
- {get:{method:'JSONP', params:{visibility:'@self'}}, replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}}
240
- );
244
+ <doc:source jsfiddle="false">
245
+ <script>
246
+ function BuzzController($resource) {
247
+ this.userId = 'googlebuzz';
248
+ this.Activity = $resource(
249
+ 'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
250
+ {alt:'json', callback:'JSON_CALLBACK'},
251
+ {
252
+ get:{method:'JSONP', params:{visibility:'@self'}},
253
+ replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}
241
254
  }
242
-
243
- BuzzController.prototype = {
244
- fetch: function() {
245
- this.activities = this.Activity.get({userId:this.userId});
246
- },
247
- expandReplies: function(activity) {
248
- activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
249
- }
250
- };
251
- BuzzController.$inject = ['$resource'];
252
- </script>
253
-
254
- <div ng-controller="BuzzController">
255
- <input ng-model="userId"/>
256
- <button ng-click="fetch()">fetch</button>
257
- <hr/>
258
- <div ng-repeat="item in activities.data.items">
259
- <h1 style="font-size: 15px;">
260
- <img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
261
- <a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
262
- <a href ng-click="expandReplies(item)" style="float: right;">Expand replies: {{item.links.replies[0].count}}</a>
263
- </h1>
264
- {{item.object.content | html}}
265
- <div ng-repeat="reply in item.replies.data.items" style="margin-left: 20px;">
266
- <img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
267
- <a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
268
- </div>
269
- </div>
255
+ );
256
+ }
257
+
258
+ BuzzController.prototype = {
259
+ fetch: function() {
260
+ this.activities = this.Activity.get({userId:this.userId});
261
+ },
262
+ expandReplies: function(activity) {
263
+ activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
264
+ }
265
+ };
266
+ BuzzController.$inject = ['$resource'];
267
+ </script>
268
+
269
+ <div ng-controller="BuzzController">
270
+ <input ng-model="userId"/>
271
+ <button ng-click="fetch()">fetch</button>
272
+ <hr/>
273
+ <div ng-repeat="item in activities.data.items">
274
+ <h1 style="font-size: 15px;">
275
+ <img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
276
+ <a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
277
+ <a href ng-click="expandReplies(item)" style="float: right;">Expand replies:
278
+ {{item.links.replies[0].count}}</a>
279
+ </h1>
280
+ {{item.object.content | html}}
281
+ <div ng-repeat="reply in item.replies.data.items" style="margin-left: 20px;">
282
+ <img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
283
+ <a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
270
284
  </div>
271
- </doc:source>
272
- <doc:scenario>
273
- </doc:scenario>
285
+ </div>
286
+ </div>
287
+ </doc:source>
288
+ <doc:scenario>
289
+ </doc:scenario>
274
290
  </doc:example>
275
291
  */
276
292
  angular.module('ngResource', ['ng']).
277
- factory('$resource', ['$http', '$parse', function($http, $parse) {
293
+ factory('$resource', ['$http', '$parse', '$q', function($http, $parse, $q) {
278
294
  var DEFAULT_ACTIONS = {
279
295
  'get': {method:'GET'},
280
296
  'save': {method:'POST'},
@@ -311,9 +327,9 @@ angular.module('ngResource', ['ng']).
311
327
 
312
328
 
313
329
  /**
314
- * This method is intended for encoding *key* or *value* parts of query component. We need a custom
315
- * method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
316
- * encoded per http://tools.ietf.org/html/rfc3986:
330
+ * This method is intended for encoding *key* or *value* parts of query component. We need a
331
+ * custom method because encodeURIComponent is too aggressive and encodes stuff that doesn't
332
+ * have to be encoded per http://tools.ietf.org/html/rfc3986:
317
333
  * query = *( pchar / "/" / "?" )
318
334
  * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
319
335
  * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
@@ -345,8 +361,12 @@ angular.module('ngResource', ['ng']).
345
361
 
346
362
  var urlParams = self.urlParams = {};
347
363
  forEach(url.split(/\W/), function(param){
348
- if (param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
349
- urlParams[param] = true;
364
+ if (param === 'hasOwnProperty') {
365
+ throw $resourceMinErr('badname', "hasOwnProperty is not a valid parameter name.");
366
+ }
367
+ if (!(new RegExp("^\\d+$").test(param)) && param &&
368
+ (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
369
+ urlParams[param] = true;
350
370
  }
351
371
  });
352
372
  url = url.replace(/\\:/g, ':');
@@ -376,7 +396,7 @@ angular.module('ngResource', ['ng']).
376
396
  url = url.replace(/\/\.(?=\w+($|\?))/, '.');
377
397
  // replace escaped `/\.` with `/.`
378
398
  config.url = url.replace(/\/\\\./, '/.');
379
-
399
+
380
400
 
381
401
  // set params - delegate param encoding to $http
382
402
  forEach(params, function(value, key){
@@ -389,7 +409,7 @@ angular.module('ngResource', ['ng']).
389
409
  };
390
410
 
391
411
 
392
- function ResourceFactory(url, paramDefaults, actions) {
412
+ function resourceFactory(url, paramDefaults, actions) {
393
413
  var route = new Route(url);
394
414
 
395
415
  actions = extend({}, DEFAULT_ACTIONS, actions);
@@ -399,25 +419,27 @@ angular.module('ngResource', ['ng']).
399
419
  actionParams = extend({}, paramDefaults, actionParams);
400
420
  forEach(actionParams, function(value, key){
401
421
  if (isFunction(value)) { value = value(); }
402
- ids[key] = value && value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
422
+ ids[key] = value && value.charAt && value.charAt(0) == '@' ?
423
+ getter(data, value.substr(1)) : value;
403
424
  });
404
425
  return ids;
405
426
  }
406
427
 
428
+ function defaultResponseInterceptor(response) {
429
+ return response.resource;
430
+ }
431
+
407
432
  function Resource(value){
408
433
  copy(value || {}, this);
409
434
  }
410
435
 
411
436
  forEach(actions, function(action, name) {
412
- action.method = angular.uppercase(action.method);
413
- var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
437
+ var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
438
+
414
439
  Resource[name] = function(a1, a2, a3, a4) {
415
- var params = {};
416
- var data;
417
- var success = noop;
418
- var error = null;
419
- var promise;
440
+ var params = {}, data, success, error;
420
441
 
442
+ /* jshint -W086 */ /* (purposefully fall through case statements) */
421
443
  switch(arguments.length) {
422
444
  case 4:
423
445
  error = a4;
@@ -448,33 +470,44 @@ angular.module('ngResource', ['ng']).
448
470
  break;
449
471
  case 0: break;
450
472
  default:
451
- throw "Expected between 0-4 arguments [params, data, success, error], got " +
452
- arguments.length + " arguments.";
473
+ throw $resourceMinErr('badargs',
474
+ "Expected up to 4 arguments [params, data, success, error], got {0} arguments",
475
+ arguments.length);
453
476
  }
477
+ /* jshint +W086 */ /* (purposefully fall through case statements) */
454
478
 
455
- var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
456
- var httpConfig = {},
457
- promise;
479
+ var isInstanceCall = data instanceof Resource;
480
+ var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data));
481
+ var httpConfig = {};
482
+ var responseInterceptor = action.interceptor && action.interceptor.response ||
483
+ defaultResponseInterceptor;
484
+ var responseErrorInterceptor = action.interceptor && action.interceptor.responseError ||
485
+ undefined;
458
486
 
459
487
  forEach(action, function(value, key) {
460
- if (key != 'params' && key != 'isArray' ) {
488
+ if (key != 'params' && key != 'isArray' && key != 'interceptor') {
461
489
  httpConfig[key] = copy(value);
462
490
  }
463
491
  });
464
- httpConfig.data = data;
465
- route.setUrlParams(httpConfig, extend({}, extractParams(data, action.params || {}), params), action.url);
466
492
 
467
- function markResolved() { value.$resolved = true; }
493
+ if (hasBody) httpConfig.data = data;
494
+ route.setUrlParams(httpConfig,
495
+ extend({}, extractParams(data, action.params || {}), params),
496
+ action.url);
468
497
 
469
- promise = $http(httpConfig);
470
- value.$resolved = false;
471
-
472
- promise.then(markResolved, markResolved);
473
- value.$then = promise.then(function(response) {
474
- var data = response.data;
475
- var then = value.$then, resolved = value.$resolved;
498
+ var promise = $http(httpConfig).then(function(response) {
499
+ var data = response.data,
500
+ promise = value.$promise;
476
501
 
477
502
  if (data) {
503
+ // Need to convert action.isArray to boolean in case it is undefined
504
+ // jshint -W018
505
+ if ( angular.isArray(data) !== (!!action.isArray) ) {
506
+ throw $resourceMinErr('badcfg', 'Error in resource configuration. Expected ' +
507
+ 'response to contain an {0} but got an {1}',
508
+ action.isArray?'array':'object', angular.isArray(data)?'array':'object');
509
+ }
510
+ // jshint +W018
478
511
  if (action.isArray) {
479
512
  value.length = 0;
480
513
  forEach(data, function(item) {
@@ -482,55 +515,63 @@ angular.module('ngResource', ['ng']).
482
515
  });
483
516
  } else {
484
517
  copy(data, value);
485
- value.$then = then;
486
- value.$resolved = resolved;
518
+ value.$promise = promise;
487
519
  }
488
520
  }
489
521
 
490
- (success||noop)(value, response.headers);
522
+ value.$resolved = true;
491
523
 
492
524
  response.resource = value;
525
+
493
526
  return response;
494
- }, error).then;
527
+ }, function(response) {
528
+ value.$resolved = true;
495
529
 
496
- return value;
497
- };
530
+ (error||noop)(response);
498
531
 
532
+ return $q.reject(response);
533
+ });
499
534
 
500
- Resource.prototype['$' + name] = function(a1, a2, a3) {
501
- var params = extractParams(this),
502
- success = noop,
503
- error;
535
+ promise = promise.then(
536
+ function(response) {
537
+ var value = responseInterceptor(response);
538
+ (success||noop)(value, response.headers);
539
+ return value;
540
+ },
541
+ responseErrorInterceptor);
542
+
543
+ if (!isInstanceCall) {
544
+ // we are creating instance / collection
545
+ // - set the initial promise
546
+ // - return the instance / collection
547
+ value.$promise = promise;
548
+ value.$resolved = false;
549
+
550
+ return value;
551
+ }
504
552
 
505
- switch(arguments.length) {
506
- case 3: params = a1; success = a2; error = a3; break;
507
- case 2:
508
- case 1:
509
- if (isFunction(a1)) {
510
- success = a1;
511
- error = a2;
512
- } else {
513
- params = a1;
514
- success = a2 || noop;
515
- }
516
- case 0: break;
517
- default:
518
- throw "Expected between 1-3 arguments [params, success, error], got " +
519
- arguments.length + " arguments.";
553
+ // instance call
554
+ return promise;
555
+ };
556
+
557
+
558
+ Resource.prototype['$' + name] = function(params, success, error) {
559
+ if (isFunction(params)) {
560
+ error = success; success = params; params = {};
520
561
  }
521
- var data = hasBody ? this : undefined;
522
- Resource[name].call(this, params, data, success, error);
562
+ var result = Resource[name](params, this, success, error);
563
+ return result.$promise || result;
523
564
  };
524
565
  });
525
566
 
526
567
  Resource.bind = function(additionalParamDefaults){
527
- return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
568
+ return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
528
569
  };
529
570
 
530
571
  return Resource;
531
572
  }
532
573
 
533
- return ResourceFactory;
574
+ return resourceFactory;
534
575
  }]);
535
576
 
536
577