joosy 1.2.0.alpha.73 → 1.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Gruntfile.coffee +56 -18
  3. data/bower.json +1 -1
  4. data/build/joosy/form.js +1 -0
  5. data/build/joosy/resources.js +1 -0
  6. data/build/joosy.js +2 -2774
  7. data/package.json +5 -4
  8. data/source/joosy/application.coffee +9 -7
  9. data/source/joosy/{extensions/resources-form/form.coffee → form.coffee} +58 -51
  10. data/source/joosy/helpers/form.coffee +241 -0
  11. data/source/joosy/helpers/index.coffee +3 -0
  12. data/source/joosy/helpers/routes.coffee +3 -1
  13. data/source/joosy/helpers/view.coffee +9 -9
  14. data/source/joosy/joosy.coffee +3 -5
  15. data/source/joosy/module.coffee +9 -4
  16. data/source/joosy/modules/dom.coffee +33 -31
  17. data/source/joosy/modules/events.coffee +24 -20
  18. data/source/joosy/modules/filters.coffee +38 -35
  19. data/source/joosy/modules/page/title.coffee +3 -3
  20. data/source/joosy/modules/renderer.coffee +23 -18
  21. data/source/joosy/modules/resources/identity_map.coffee +45 -0
  22. data/source/joosy/modules/resources/model.coffee +146 -0
  23. data/source/joosy/modules/widgets_manager.coffee +8 -8
  24. data/source/joosy/resources/array.coffee +0 -5
  25. data/source/joosy/resources/hash.coffee +8 -13
  26. data/source/joosy/resources/index.coffee +2 -0
  27. data/source/joosy/{extensions/resources → resources}/rest.coffee +48 -19
  28. data/source/joosy/resources/scalar.coffee +8 -10
  29. data/source/joosy/router.coffee +13 -12
  30. data/source/joosy/templaters/jst.coffee +3 -2
  31. data/source/joosy/widget.coffee +17 -15
  32. data/source/joosy.coffee +2 -0
  33. data/source/vendor/es5-shim.js +1316 -0
  34. data/source/vendor/inflections.js +598 -0
  35. data/source/vendor/metamorph.js +457 -0
  36. data/spec/helpers/matchers.coffee +4 -4
  37. data/spec/joosy/core/application_spec.coffee +1 -1
  38. data/spec/joosy/core/helpers/view_spec.coffee +2 -2
  39. data/spec/joosy/core/joosy_spec.coffee +8 -4
  40. data/spec/joosy/core/modules/dom_spec.coffee +7 -7
  41. data/spec/joosy/core/modules/events_spec.coffee +2 -2
  42. data/spec/joosy/core/modules/filters_spec.coffee +7 -8
  43. data/spec/joosy/core/modules/module_spec.coffee +5 -5
  44. data/spec/joosy/core/router_spec.coffee +3 -3
  45. data/spec/joosy/core/widget_spec.coffee +6 -6
  46. data/spec/joosy/environments/amd_spec.coffee +4 -2
  47. data/spec/joosy/environments/global_spec.coffee +1 -1
  48. data/spec/joosy/{extensions/form → form}/form_spec.coffee +9 -16
  49. data/spec/joosy/{extensions/form → form}/helpers/forms_spec.coffee +5 -5
  50. data/spec/joosy/{core/resources → resources}/array_spec.coffee +2 -2
  51. data/spec/joosy/{core/resources → resources}/hash_spec.coffee +0 -8
  52. data/spec/joosy/{core/modules/resources → resources/modules}/cacher_spec.coffee +0 -0
  53. data/spec/joosy/resources/modules/identity_map_spec.coffee +47 -0
  54. data/spec/joosy/{extensions/resources/base_spec.coffee → resources/modules/model_spec.coffee} +28 -48
  55. data/spec/joosy/{extensions/resources → resources}/rest_spec.coffee +29 -22
  56. data/spec/joosy/{core/resources → resources}/scalar_spec.coffee +8 -8
  57. data/templates/application/application.coffee.tt +0 -2
  58. data/templates/environment/app/haml/index.haml +2 -2
  59. data/templates/environment/package.json +1 -1
  60. metadata +23 -19
  61. data/build/joosy/extensions/resources-form.js +0 -590
  62. data/build/joosy/extensions/resources.js +0 -561
  63. data/source/joosy/extensions/resources/base.coffee +0 -282
  64. data/source/joosy/extensions/resources/index.coffee +0 -1
  65. data/source/joosy/extensions/resources-form/helpers/form.coffee +0 -104
  66. data/source/joosy/extensions/resources-form/index.coffee +0 -1
  67. data/source/metamorph.coffee +0 -410
@@ -1,561 +0,0 @@
1
- (function() {
2
- var __hasProp = {}.hasOwnProperty,
3
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
4
-
5
- Joosy.Resources.Base = (function(_super) {
6
- __extends(Base, _super);
7
-
8
- Base.include(Joosy.Modules.Log);
9
-
10
- Base.include(Joosy.Modules.Events);
11
-
12
- Base.include(Joosy.Modules.Filters);
13
-
14
- Base.prototype.__primaryKey = 'id';
15
-
16
- Base.resetIdentity = function() {
17
- return Joosy.Resources.Base.identity = {};
18
- };
19
-
20
- Base.registerPlainFilters('beforeLoad');
21
-
22
- Base.primaryKey = function(primaryKey) {
23
- return this.prototype.__primaryKey = primaryKey;
24
- };
25
-
26
- Base.entity = function(name) {
27
- return this.prototype.__entityName = name;
28
- };
29
-
30
- Base.map = function(name, klass) {
31
- if (klass == null) {
32
- klass = false;
33
- }
34
- if (!klass) {
35
- klass = window[name.singularize().camelize()];
36
- }
37
- if (!klass) {
38
- throw new Error("" + (Joosy.Module.__className(this)) + "> class can not be detected for '" + name + "' mapping");
39
- }
40
- return this.beforeLoad(function(data) {
41
- if (!Joosy.Module.hasAncestor(klass, Joosy.Resources.Base)) {
42
- klass = klass();
43
- }
44
- return this.__map(data, name, klass);
45
- });
46
- };
47
-
48
- Base.build = function(data) {
49
- var id, klass, _base, _base1, _base2;
50
- if (data == null) {
51
- data = {};
52
- }
53
- if (Object.isNumber(data) || Object.isString(data)) {
54
- id = data;
55
- data = {};
56
- data[this.prototype.__primaryKey] = id;
57
- }
58
- klass = this.prototype.__entityName;
59
- id = data[this.prototype.__primaryKey];
60
- if ((klass != null) && (id != null)) {
61
- if ((_base = Joosy.Resources.Base).identity == null) {
62
- _base.identity = {};
63
- }
64
- if ((_base1 = Joosy.Resources.Base.identity)[klass] == null) {
65
- _base1[klass] = {};
66
- }
67
- if ((_base2 = Joosy.Resources.Base.identity[klass])[id] == null) {
68
- _base2[id] = new this({
69
- id: id
70
- });
71
- }
72
- return Joosy.Resources.Base.identity[klass][id].load(data);
73
- } else {
74
- return new this(data);
75
- }
76
- };
77
-
78
- Base.grab = function(form) {
79
- return this.build({}).grab(form);
80
- };
81
-
82
- function Base(data) {
83
- if (data == null) {
84
- data = {};
85
- }
86
- return Base.__super__.constructor.call(this, function() {
87
- return this.__fillData(data, false);
88
- });
89
- }
90
-
91
- Base.prototype.id = function() {
92
- var _ref;
93
- return (_ref = this.data) != null ? _ref[this.__primaryKey] : void 0;
94
- };
95
-
96
- Base.prototype.knownAttributes = function() {
97
- return Object.keys(this.data);
98
- };
99
-
100
- Base.prototype.load = function(data, clear) {
101
- if (clear == null) {
102
- clear = false;
103
- }
104
- if (clear) {
105
- this.data = {};
106
- }
107
- this.__fillData(data);
108
- return this;
109
- };
110
-
111
- Base.prototype.grab = function(form) {
112
- var data, field, _i, _len, _ref;
113
- data = {};
114
- _ref = $(form).serializeArray();
115
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
116
- field = _ref[_i];
117
- if (!data[field.name]) {
118
- data[field.name] = field.value;
119
- } else {
120
- if (!(data[field.name] instanceof Array)) {
121
- data[field.name] = [data[field.name]];
122
- }
123
- data[field.name].push(field.value);
124
- }
125
- }
126
- return this.load(data);
127
- };
128
-
129
- Base.prototype.__get = function(path) {
130
- var target;
131
- target = this.__callTarget(path, true);
132
- if (!target) {
133
- return void 0;
134
- } else if (target[0] instanceof Joosy.Resources.Base) {
135
- return target[0](target[1]);
136
- } else {
137
- return target[0][target[1]];
138
- }
139
- };
140
-
141
- Base.prototype.__set = function(path, value) {
142
- var target;
143
- target = this.__callTarget(path);
144
- if (target[0] instanceof Joosy.Resources.Base) {
145
- target[0](target[1], value);
146
- } else {
147
- target[0][target[1]] = value;
148
- }
149
- this.trigger('changed');
150
- return null;
151
- };
152
-
153
- Base.prototype.__callTarget = function(path, safe) {
154
- var keyword, part, target, _i, _len;
155
- if (safe == null) {
156
- safe = false;
157
- }
158
- if (path.has(/\./) && (this.data[path] == null)) {
159
- path = path.split('.');
160
- keyword = path.pop();
161
- target = this.data;
162
- for (_i = 0, _len = path.length; _i < _len; _i++) {
163
- part = path[_i];
164
- if (safe && (target[part] == null)) {
165
- return false;
166
- }
167
- target[part] || (target[part] = {});
168
- if (target instanceof Joosy.Resources.Base) {
169
- target = target(part);
170
- } else {
171
- target = target[part];
172
- }
173
- }
174
- return [target, keyword];
175
- } else {
176
- return [this.data, path];
177
- }
178
- };
179
-
180
- Base.prototype.__call = function(path, value) {
181
- if (arguments.length > 1) {
182
- return this.__set(path, value);
183
- } else {
184
- return this.__get(path);
185
- }
186
- };
187
-
188
- Base.prototype.__fillData = function(data, notify) {
189
- if (notify == null) {
190
- notify = true;
191
- }
192
- this.raw = data;
193
- if (!this.hasOwnProperty('data')) {
194
- this.data = {};
195
- }
196
- Joosy.Module.merge(this.data, this.__prepareData(data));
197
- if (notify) {
198
- this.trigger('changed');
199
- }
200
- return null;
201
- };
202
-
203
- Base.prototype.__prepareData = function(data) {
204
- var name;
205
- if (Object.isObject(data) && Object.keys(data).length === 1 && this.__entityName) {
206
- name = this.__entityName.camelize(false);
207
- if (data[name]) {
208
- data = data[name];
209
- }
210
- }
211
- return this.__applyBeforeLoads(data);
212
- };
213
-
214
- Base.prototype.__map = function(data, name, klass) {
215
- var entries;
216
- if (Object.isArray(data[name])) {
217
- entries = data[name].map(function(x) {
218
- return klass.build(x);
219
- });
220
- data[name] = (function(func, args, ctor) {
221
- ctor.prototype = func.prototype;
222
- var child = new ctor, result = func.apply(child, args);
223
- return Object(result) === result ? result : child;
224
- })(Joosy.Resources.Array, entries, function(){});
225
- } else if (Object.isObject(data[name])) {
226
- data[name] = klass.build(data[name]);
227
- }
228
- return data;
229
- };
230
-
231
- Base.prototype.toString = function() {
232
- return "<Resource " + this.__entityName + "> " + (JSON.stringify(this.data));
233
- };
234
-
235
- return Base;
236
-
237
- })(Joosy.Function);
238
-
239
- }).call(this);
240
- (function() {
241
- var _ref,
242
- __hasProp = {}.hasOwnProperty,
243
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
244
- __slice = [].slice;
245
-
246
- Joosy.Resources.REST = (function(_super) {
247
- __extends(REST, _super);
248
-
249
- function REST() {
250
- _ref = REST.__super__.constructor.apply(this, arguments);
251
- return _ref;
252
- }
253
-
254
- REST.requestOptions = function(options) {
255
- return this.prototype.__requestOptions = options;
256
- };
257
-
258
- REST.source = function(location) {
259
- return this.__source = location;
260
- };
261
-
262
- REST.__atWrapper = function() {
263
- var args, definer,
264
- _this = this;
265
- definer = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
266
- if (args.length === 1 && Object.isArray(args[0])) {
267
- return this.__atWrapper.apply(this, [definer].concat(__slice.call(args[0])));
268
- } else {
269
- return definer(function(clone) {
270
- clone.__source = args.reduce(function(path, arg) {
271
- return path += arg instanceof Joosy.Resources.REST ? arg.memberPath() : arg.replace(/^\/?/, '/');
272
- }, '');
273
- return clone.__source += '/' + _this.prototype.__entityName.pluralize();
274
- });
275
- }
276
- };
277
-
278
- REST.at = function() {
279
- var args,
280
- _this = this;
281
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
282
- return this.__atWrapper.apply(this, [function(callback) {
283
- var Clone, _ref1;
284
- return Clone = (function(_super1) {
285
- __extends(Clone, _super1);
286
-
287
- function Clone() {
288
- _ref1 = Clone.__super__.constructor.apply(this, arguments);
289
- return _ref1;
290
- }
291
-
292
- callback(Clone);
293
-
294
- return Clone;
295
-
296
- })(_this);
297
- }].concat(__slice.call(args)));
298
- };
299
-
300
- REST.prototype.at = function() {
301
- var args, _ref1;
302
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
303
- return new ((_ref1 = this.constructor).at.apply(_ref1, args))(this.data);
304
- };
305
-
306
- REST.prototype.__interpolatePath = function(source, ids) {
307
- if (!Object.isArray(ids)) {
308
- ids = [ids];
309
- }
310
- return ids.reduce(function(path, id) {
311
- if (id instanceof Joosy.Resources.REST) {
312
- id = id.id();
313
- }
314
- return path.replace(/:[^\/]+/, id);
315
- }, source);
316
- };
317
-
318
- REST.collectionPath = function() {
319
- var args, _ref1;
320
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
321
- return (_ref1 = this.prototype).collectionPath.apply(_ref1, args);
322
- };
323
-
324
- REST.prototype.collectionPath = function(ids, options) {
325
- var path, source;
326
- if (ids == null) {
327
- ids = [];
328
- }
329
- if (options == null) {
330
- options = {};
331
- }
332
- if (Object.isObject(ids)) {
333
- options = ids;
334
- ids = [];
335
- }
336
- if (options.url) {
337
- return options.url;
338
- }
339
- source = this.__source || this.constructor.__source;
340
- if (source) {
341
- path = this.__interpolatePath(source, ids);
342
- } else {
343
- path = '/';
344
- if (this.constructor.__namespace__.length > 0) {
345
- path += this.constructor.__namespace__.map(String.prototype.underscore).join('/') + '/';
346
- }
347
- path += this.__entityName.pluralize();
348
- }
349
- if (options.action) {
350
- path += "/" + options.action;
351
- }
352
- return path;
353
- };
354
-
355
- REST.memberPath = function() {
356
- var args, _ref1;
357
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
358
- return (_ref1 = this.prototype).memberPath.apply(_ref1, args);
359
- };
360
-
361
- REST.prototype.memberPath = function(ids, options) {
362
- var action, id, path;
363
- if (ids == null) {
364
- ids = [];
365
- }
366
- if (options == null) {
367
- options = {};
368
- }
369
- if (Object.isObject(ids)) {
370
- options = ids;
371
- ids = [];
372
- }
373
- if (options.url) {
374
- return options.url;
375
- }
376
- if (!Object.isArray(ids)) {
377
- ids = [ids];
378
- }
379
- id = this.id() || ids.pop();
380
- action = options.action;
381
- ids.push(this.id());
382
- path = this.collectionPath(ids, Object.merge(options, {
383
- action: void 0
384
- })) + ("/" + id);
385
- if (action != null) {
386
- path += "/" + action;
387
- }
388
- return path;
389
- };
390
-
391
- REST.get = function(options, callback) {
392
- var _ref1;
393
- _ref1 = this.prototype.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
394
- return this.__query(this.collectionPath(options), 'GET', options.params, callback);
395
- };
396
-
397
- REST.post = function(options, callback) {
398
- var _ref1;
399
- _ref1 = this.prototype.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
400
- return this.__query(this.collectionPath(options), 'POST', options.params, callback);
401
- };
402
-
403
- REST.put = function(options, callback) {
404
- var _ref1;
405
- _ref1 = this.prototype.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
406
- return this.__query(this.collectionPath(options), 'PUT', options.params, callback);
407
- };
408
-
409
- REST["delete"] = function(options, callback) {
410
- var _ref1;
411
- _ref1 = this.prototype.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
412
- return this.__query(this.collectionPath(options), 'DELETE', options.params, callback);
413
- };
414
-
415
- REST.prototype.get = function(options, callback) {
416
- var _ref1;
417
- _ref1 = this.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
418
- return this.constructor.__query(this.memberPath(options), 'GET', options.params, callback);
419
- };
420
-
421
- REST.prototype.post = function(options, callback) {
422
- var _ref1;
423
- _ref1 = this.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
424
- return this.constructor.__query(this.memberPath(options), 'POST', options.params, callback);
425
- };
426
-
427
- REST.prototype.put = function(options, callback) {
428
- var _ref1;
429
- _ref1 = this.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
430
- return this.constructor.__query(this.memberPath(options), 'PUT', options.params, callback);
431
- };
432
-
433
- REST.prototype["delete"] = function(options, callback) {
434
- var _ref1;
435
- _ref1 = this.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
436
- return this.constructor.__query(this.memberPath(options), 'DELETE', options.params, callback);
437
- };
438
-
439
- REST.prototype.reload = function(options, callback) {
440
- var _ref1,
441
- _this = this;
442
- if (options == null) {
443
- options = {};
444
- }
445
- if (callback == null) {
446
- callback = false;
447
- }
448
- _ref1 = this.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
449
- return this.constructor.__query(this.memberPath(options), 'GET', options.params, function(error, data, xhr) {
450
- if (data != null) {
451
- _this.load(data);
452
- }
453
- return typeof callback === "function" ? callback(error, _this, data, xhr) : void 0;
454
- });
455
- };
456
-
457
- REST.find = function(where, options, callback) {
458
- var id, result, _ref1,
459
- _this = this;
460
- if (options == null) {
461
- options = {};
462
- }
463
- if (callback == null) {
464
- callback = false;
465
- }
466
- _ref1 = this.prototype.__extractOptionsAndCallback(options, callback), options = _ref1[0], callback = _ref1[1];
467
- id = where instanceof Array ? where[where.length - 1] : where;
468
- result = this.build(id);
469
- if (where instanceof Array && where.length > 1) {
470
- result.__source = this.collectionPath(where);
471
- }
472
- this.__query(this.memberPath(where, options), 'GET', options.params, function(error, data, xhr) {
473
- if (data != null) {
474
- result.load(data);
475
- }
476
- return typeof callback === "function" ? callback(error, result, data, xhr) : void 0;
477
- });
478
- return result;
479
- };
480
-
481
- REST.all = function(where, options, callback) {
482
- var result, _ref1, _ref2,
483
- _this = this;
484
- if (options == null) {
485
- options = {};
486
- }
487
- if (callback == null) {
488
- callback = false;
489
- }
490
- if (Object.isFunction(where) || Object.isObject(where)) {
491
- _ref1 = this.prototype.__extractOptionsAndCallback(where, options), options = _ref1[0], callback = _ref1[1];
492
- where = [];
493
- } else {
494
- _ref2 = this.prototype.__extractOptionsAndCallback(options, callback), options = _ref2[0], callback = _ref2[1];
495
- }
496
- result = new Joosy.Resources.Array;
497
- this.__query(this.collectionPath(where, options), 'GET', options.params, function(error, rawData, xhr) {
498
- var data;
499
- if ((data = rawData) != null) {
500
- if (Object.isObject(data) && !(data = data[_this.prototype.__entityName.pluralize()])) {
501
- throw new Error("Invalid data for `all` received: " + (JSON.stringify(data)));
502
- }
503
- data = data.map(function(x) {
504
- var instance;
505
- instance = _this.build(x);
506
- if (where.length > 1) {
507
- instance.__source = _this.collectionPath(where);
508
- }
509
- return instance;
510
- });
511
- result.load.apply(result, data);
512
- }
513
- return typeof callback === "function" ? callback(error, result, rawData, xhr) : void 0;
514
- });
515
- return result;
516
- };
517
-
518
- REST.__query = function(path, method, params, callback) {
519
- var options;
520
- options = {
521
- url: path,
522
- data: params,
523
- type: method,
524
- cache: false,
525
- dataType: 'json'
526
- };
527
- if (Object.isFunction(callback)) {
528
- options.success = function(data, _, xhr) {
529
- return callback(false, data, xhr);
530
- };
531
- options.error = function(xhr) {
532
- return callback(xhr);
533
- };
534
- } else {
535
- Joosy.Module.merge(options, callback);
536
- }
537
- if (this.prototype.__requestOptions instanceof Function) {
538
- this.prototype.__requestOptions(options);
539
- } else if (this.prototype.__requestOptions) {
540
- Joosy.Module.merge(options, this.prototype.__requestOptions);
541
- }
542
- return $.ajax(options);
543
- };
544
-
545
- REST.prototype.__extractOptionsAndCallback = function(options, callback) {
546
- if (Object.isFunction(options)) {
547
- callback = options;
548
- options = {};
549
- }
550
- return [options, callback];
551
- };
552
-
553
- return REST;
554
-
555
- })(Joosy.Resources.Base);
556
-
557
- }).call(this);
558
- (function() {
559
-
560
-
561
- }).call(this);