qedproject 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,537 @@
1
+ /**
2
+ * @license AngularJS v1.1.5
3
+ * (c) 2010-2012 Google, Inc. http://angularjs.org
4
+ * License: MIT
5
+ */
6
+ (function(window, angular, undefined) {
7
+ 'use strict';
8
+
9
+ /**
10
+ * @ngdoc overview
11
+ * @name ngResource
12
+ * @description
13
+ */
14
+
15
+ /**
16
+ * @ngdoc object
17
+ * @name ngResource.$resource
18
+ * @requires $http
19
+ *
20
+ * @description
21
+ * A factory which creates a resource object that lets you interact with
22
+ * [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
23
+ *
24
+ * The returned resource object has action methods which provide high-level behaviors without
25
+ * the need to interact with the low level {@link ng.$http $http} service.
26
+ *
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!
37
+ *
38
+ * @param {string} url A parametrized URL template with parameters prefixed by `:` as in
39
+ * `/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')`.
42
+ *
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')`
46
+ * If the parameter before the suffix is empty, :resource_id in this case, then the `/.` will be
47
+ * collapsed down to a single `.`. If you need this sequence to appear and not collapse then you
48
+ * can escape it with `/\.`.
49
+ *
50
+ * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
51
+ * `actions` methods. If any of the parameter value is a function, it will be executed every time
52
+ * when a param value needs to be obtained for a request (unless the param was overridden).
53
+ *
54
+ * Each key value in the parameter object is first bound to url template if present and then any
55
+ * excess keys are appended to the url search query after the `?`.
56
+ *
57
+ * Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
58
+ * URL `/path/greet?salutation=Hello`.
59
+ *
60
+ * If the parameter value is prefixed with `@` then the value of that parameter is extracted from
61
+ * the data object (useful for non-GET operations).
62
+ *
63
+ * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
64
+ * default set of resource actions. The declaration should be created in the format of {@link
65
+ * ng.$http#Parameters $http.config}:
66
+ *
67
+ * {action1: {method:?, params:?, isArray:?, headers:?, ...},
68
+ * action2: {method:?, params:?, isArray:?, headers:?, ...},
69
+ * ...}
70
+ *
71
+ * Where:
72
+ *
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)>}` –
85
+ * transform function or an array of such functions. The transform function takes the http
86
+ * request body and headers and returns its transformed (typically serialized) version.
87
+ * - **`transformResponse`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
88
+ * transform function or an array of such functions. The transform function takes the http
89
+ * response body and headers and returns its transformed (typically deserialized) version.
90
+ * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
91
+ * GET request, otherwise if a cache instance built with
92
+ * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
93
+ * caching.
94
+ * - **`timeout`** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise} that
95
+ * should abort the request when resolved.
96
+ * - **`withCredentials`** - `{boolean}` - whether to to set the `withCredentials` flag on the
97
+ * XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5
98
+ * requests with credentials} for more information.
99
+ * - **`responseType`** - `{string}` - see {@link
100
+ * https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType requestType}.
101
+ *
102
+ * @returns {Object} A resource "class" object with methods for the default set of resource actions
103
+ * optionally extended with custom `actions`. The default set contains these actions:
104
+ *
105
+ * { 'get': {method:'GET'},
106
+ * 'save': {method:'POST'},
107
+ * 'query': {method:'GET', isArray:true},
108
+ * 'remove': {method:'DELETE'},
109
+ * 'delete': {method:'DELETE'} };
110
+ *
111
+ * Calling these methods invoke an {@link ng.$http} with the specified http method,
112
+ * destination and parameters. When the data is returned from the server then the object is an
113
+ * instance of the resource class. The actions `save`, `remove` and `delete` are available on it
114
+ * as methods with the `$` prefix. This allows you to easily perform CRUD operations (create,
115
+ * read, update, delete) on server-side data like this:
116
+ * <pre>
117
+ var User = $resource('/user/:userId', {userId:'@id'});
118
+ var user = User.get({userId:123}, function() {
119
+ user.abc = true;
120
+ user.$save();
121
+ });
122
+ </pre>
123
+ *
124
+ * It is important to realize that invoking a $resource object method immediately returns an
125
+ * empty reference (object or array depending on `isArray`). Once the data is returned from the
126
+ * server the existing reference is populated with the actual data. This is a useful trick since
127
+ * usually the resource is assigned to a model which is then rendered by the view. Having an empty
128
+ * object results in no rendering, once the data arrives from the server then the object is
129
+ * populated with the data and the view automatically re-renders itself showing the new data. This
130
+ * means that in most case one never has to write a callback function for the action methods.
131
+ *
132
+ * The action methods on the class object or instance object can be invoked with the following
133
+ * parameters:
134
+ *
135
+ * - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
136
+ * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
137
+ * - non-GET instance actions: `instance.$action([parameters], [success], [error])`
138
+ *
139
+ *
140
+ * The Resource instances and collection have these additional properties:
141
+ *
142
+ * - `$then`: the `then` method of a {@link ng.$q promise} derived from the underlying
143
+ * {@link ng.$http $http} call.
144
+ *
145
+ * The success callback for the `$then` method will be resolved if the underlying `$http` requests
146
+ * succeeds.
147
+ *
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.
151
+ *
152
+ * The error callback is called with the {@link ng.$http http response} object when an http
153
+ * error occurs.
154
+ *
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.
157
+ *
158
+ * @example
159
+ *
160
+ * # Credit card resource
161
+ *
162
+ * <pre>
163
+ // Define CreditCard class
164
+ var CreditCard = $resource('/user/:userId/card/:cardId',
165
+ {userId:123, cardId:'@id'}, {
166
+ charge: {method:'POST', params:{charge:true}}
167
+ });
168
+
169
+ // We can retrieve a collection from the server
170
+ var cards = CreditCard.query(function() {
171
+ // GET: /user/123/card
172
+ // server returns: [ {id:456, number:'1234', name:'Smith'} ];
173
+
174
+ var card = cards[0];
175
+ // each item is an instance of CreditCard
176
+ expect(card instanceof CreditCard).toEqual(true);
177
+ card.name = "J. Smith";
178
+ // non GET methods are mapped onto the instances
179
+ card.$save();
180
+ // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
181
+ // server returns: {id:456, number:'1234', name: 'J. Smith'};
182
+
183
+ // our custom method is mapped as well.
184
+ card.$charge({amount:9.99});
185
+ // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
186
+ });
187
+
188
+ // we can create an instance as well
189
+ var newCard = new CreditCard({number:'0123'});
190
+ newCard.name = "Mike Smith";
191
+ newCard.$save();
192
+ // POST: /user/123/card {number:'0123', name:'Mike Smith'}
193
+ // server returns: {id:789, number:'01234', name: 'Mike Smith'};
194
+ expect(newCard.id).toEqual(789);
195
+ * </pre>
196
+ *
197
+ * The object returned from this function execution is a resource "class" which has "static" method
198
+ * for each action in the definition.
199
+ *
200
+ * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and `headers`.
201
+ * When the data is returned from the server then the object is an instance of the resource type and
202
+ * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
203
+ * operations (create, read, update, delete) on server-side data.
204
+
205
+ <pre>
206
+ var User = $resource('/user/:userId', {userId:'@id'});
207
+ var user = User.get({userId:123}, function() {
208
+ user.abc = true;
209
+ user.$save();
210
+ });
211
+ </pre>
212
+ *
213
+ * It's worth noting that the success callback for `get`, `query` and other method gets passed
214
+ * in the response that came from the server as well as $http header getter function, so one
215
+ * could rewrite the above example and get access to http headers as:
216
+ *
217
+ <pre>
218
+ var User = $resource('/user/:userId', {userId:'@id'});
219
+ User.get({userId:123}, function(u, getResponseHeaders){
220
+ u.abc = true;
221
+ u.$save(function(u, putResponseHeaders) {
222
+ //u => saved user object
223
+ //putResponseHeaders => $http header getter
224
+ });
225
+ });
226
+ </pre>
227
+
228
+ * # Buzz client
229
+
230
+ Let's look at what a buzz client created with the `$resource` service looks like:
231
+ <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
+ );
241
+ }
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>
270
+ </div>
271
+ </doc:source>
272
+ <doc:scenario>
273
+ </doc:scenario>
274
+ </doc:example>
275
+ */
276
+ angular.module('ngResource', ['ng']).
277
+ factory('$resource', ['$http', '$parse', function($http, $parse) {
278
+ var DEFAULT_ACTIONS = {
279
+ 'get': {method:'GET'},
280
+ 'save': {method:'POST'},
281
+ 'query': {method:'GET', isArray:true},
282
+ 'remove': {method:'DELETE'},
283
+ 'delete': {method:'DELETE'}
284
+ };
285
+ var noop = angular.noop,
286
+ forEach = angular.forEach,
287
+ extend = angular.extend,
288
+ copy = angular.copy,
289
+ isFunction = angular.isFunction,
290
+ getter = function(obj, path) {
291
+ return $parse(path)(obj);
292
+ };
293
+
294
+ /**
295
+ * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
296
+ * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
297
+ * segments:
298
+ * segment = *pchar
299
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
300
+ * pct-encoded = "%" HEXDIG HEXDIG
301
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
302
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
303
+ * / "*" / "+" / "," / ";" / "="
304
+ */
305
+ function encodeUriSegment(val) {
306
+ return encodeUriQuery(val, true).
307
+ replace(/%26/gi, '&').
308
+ replace(/%3D/gi, '=').
309
+ replace(/%2B/gi, '+');
310
+ }
311
+
312
+
313
+ /**
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:
317
+ * query = *( pchar / "/" / "?" )
318
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
319
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
320
+ * pct-encoded = "%" HEXDIG HEXDIG
321
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
322
+ * / "*" / "+" / "," / ";" / "="
323
+ */
324
+ function encodeUriQuery(val, pctEncodeSpaces) {
325
+ return encodeURIComponent(val).
326
+ replace(/%40/gi, '@').
327
+ replace(/%3A/gi, ':').
328
+ replace(/%24/g, '$').
329
+ replace(/%2C/gi, ',').
330
+ replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
331
+ }
332
+
333
+ function Route(template, defaults) {
334
+ this.template = template;
335
+ this.defaults = defaults || {};
336
+ this.urlParams = {};
337
+ }
338
+
339
+ Route.prototype = {
340
+ setUrlParams: function(config, params, actionUrl) {
341
+ var self = this,
342
+ url = actionUrl || self.template,
343
+ val,
344
+ encodedVal;
345
+
346
+ var urlParams = self.urlParams = {};
347
+ forEach(url.split(/\W/), function(param){
348
+ if (param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
349
+ urlParams[param] = true;
350
+ }
351
+ });
352
+ url = url.replace(/\\:/g, ':');
353
+
354
+ params = params || {};
355
+ forEach(self.urlParams, function(_, urlParam){
356
+ val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
357
+ if (angular.isDefined(val) && val !== null) {
358
+ encodedVal = encodeUriSegment(val);
359
+ url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), encodedVal + "$1");
360
+ } else {
361
+ url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W|$)", "g"), function(match,
362
+ leadingSlashes, tail) {
363
+ if (tail.charAt(0) == '/') {
364
+ return tail;
365
+ } else {
366
+ return leadingSlashes + tail;
367
+ }
368
+ });
369
+ }
370
+ });
371
+
372
+ // strip trailing slashes and set the url
373
+ url = url.replace(/\/+$/, '');
374
+ // then replace collapse `/.` if found in the last URL path segment before the query
375
+ // E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
376
+ url = url.replace(/\/\.(?=\w+($|\?))/, '.');
377
+ // replace escaped `/\.` with `/.`
378
+ config.url = url.replace(/\/\\\./, '/.');
379
+
380
+
381
+ // set params - delegate param encoding to $http
382
+ forEach(params, function(value, key){
383
+ if (!self.urlParams[key]) {
384
+ config.params = config.params || {};
385
+ config.params[key] = value;
386
+ }
387
+ });
388
+ }
389
+ };
390
+
391
+
392
+ function ResourceFactory(url, paramDefaults, actions) {
393
+ var route = new Route(url);
394
+
395
+ actions = extend({}, DEFAULT_ACTIONS, actions);
396
+
397
+ function extractParams(data, actionParams){
398
+ var ids = {};
399
+ actionParams = extend({}, paramDefaults, actionParams);
400
+ forEach(actionParams, function(value, key){
401
+ if (isFunction(value)) { value = value(); }
402
+ ids[key] = value && value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
403
+ });
404
+ return ids;
405
+ }
406
+
407
+ function Resource(value){
408
+ copy(value || {}, this);
409
+ }
410
+
411
+ forEach(actions, function(action, name) {
412
+ action.method = angular.uppercase(action.method);
413
+ var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
414
+ Resource[name] = function(a1, a2, a3, a4) {
415
+ var params = {};
416
+ var data;
417
+ var success = noop;
418
+ var error = null;
419
+ var promise;
420
+
421
+ switch(arguments.length) {
422
+ case 4:
423
+ error = a4;
424
+ success = a3;
425
+ //fallthrough
426
+ case 3:
427
+ case 2:
428
+ if (isFunction(a2)) {
429
+ if (isFunction(a1)) {
430
+ success = a1;
431
+ error = a2;
432
+ break;
433
+ }
434
+
435
+ success = a2;
436
+ error = a3;
437
+ //fallthrough
438
+ } else {
439
+ params = a1;
440
+ data = a2;
441
+ success = a3;
442
+ break;
443
+ }
444
+ case 1:
445
+ if (isFunction(a1)) success = a1;
446
+ else if (hasBody) data = a1;
447
+ else params = a1;
448
+ break;
449
+ case 0: break;
450
+ default:
451
+ throw "Expected between 0-4 arguments [params, data, success, error], got " +
452
+ arguments.length + " arguments.";
453
+ }
454
+
455
+ var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
456
+ var httpConfig = {},
457
+ promise;
458
+
459
+ forEach(action, function(value, key) {
460
+ if (key != 'params' && key != 'isArray' ) {
461
+ httpConfig[key] = copy(value);
462
+ }
463
+ });
464
+ httpConfig.data = data;
465
+ route.setUrlParams(httpConfig, extend({}, extractParams(data, action.params || {}), params), action.url);
466
+
467
+ function markResolved() { value.$resolved = true; }
468
+
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;
476
+
477
+ if (data) {
478
+ if (action.isArray) {
479
+ value.length = 0;
480
+ forEach(data, function(item) {
481
+ value.push(new Resource(item));
482
+ });
483
+ } else {
484
+ copy(data, value);
485
+ value.$then = then;
486
+ value.$resolved = resolved;
487
+ }
488
+ }
489
+
490
+ (success||noop)(value, response.headers);
491
+
492
+ response.resource = value;
493
+ return response;
494
+ }, error).then;
495
+
496
+ return value;
497
+ };
498
+
499
+
500
+ Resource.prototype['$' + name] = function(a1, a2, a3) {
501
+ var params = extractParams(this),
502
+ success = noop,
503
+ error;
504
+
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.";
520
+ }
521
+ var data = hasBody ? this : undefined;
522
+ Resource[name].call(this, params, data, success, error);
523
+ };
524
+ });
525
+
526
+ Resource.bind = function(additionalParamDefaults){
527
+ return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
528
+ };
529
+
530
+ return Resource;
531
+ }
532
+
533
+ return ResourceFactory;
534
+ }]);
535
+
536
+
537
+ })(window, window.angular);
@@ -0,0 +1 @@
1
+ 1.5.2