ende 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/component.json +1 -1
  3. data/lib/assets/javascripts/aura/extensions/devise.js.coffee +7 -4
  4. data/lib/assets/javascripts/aura/extensions/routes.js.coffee +16 -8
  5. data/lib/assets/javascripts/aura/extensions/widget/lifecycleable.js.coffee +10 -5
  6. data/lib/assets/javascripts/widgets/authenticator/main.js.coffee +4 -8
  7. data/lib/assets/javascripts/widgets/authenticator/presenter.js.coffee +4 -4
  8. data/lib/assets/javascripts/widgets/authenticator/states/default.html +1 -1
  9. data/lib/assets/javascripts/widgets/tray/main.js.coffee +26 -0
  10. data/lib/ende/version.rb +1 -1
  11. data/lib/tasks/component.thor +1 -1
  12. data/vendor/assets/javascripts/ende/build.js +10008 -8202
  13. data/vendor/components/KapIT-observe-utils/component.json +16 -0
  14. data/vendor/components/KapIT-observe-utils/lib/observe-utils.js +780 -0
  15. data/vendor/components/chaijs-assertion-error/component.json +18 -0
  16. data/vendor/components/chaijs-assertion-error/index.js +110 -0
  17. data/vendor/components/chaijs-chai/component.json +47 -0
  18. data/vendor/components/chaijs-chai/index.js +1 -0
  19. data/vendor/components/chaijs-chai/lib/chai/assertion.js +130 -0
  20. data/vendor/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
  21. data/vendor/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
  22. data/vendor/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
  23. data/vendor/components/chaijs-chai/lib/chai/interface/should.js +76 -0
  24. data/vendor/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
  25. data/vendor/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
  26. data/vendor/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
  27. data/vendor/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
  28. data/vendor/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
  29. data/vendor/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
  30. data/vendor/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
  31. data/vendor/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
  32. data/vendor/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
  33. data/vendor/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
  34. data/vendor/components/chaijs-chai/lib/chai/utils/index.js +108 -0
  35. data/vendor/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
  36. data/vendor/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
  37. data/vendor/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
  38. data/vendor/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
  39. data/vendor/components/chaijs-chai/lib/chai/utils/test.js +26 -0
  40. data/vendor/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
  41. data/vendor/components/chaijs-chai/lib/chai/utils/type.js +45 -0
  42. data/vendor/components/chaijs-chai/lib/chai.js +80 -0
  43. data/vendor/components/chaijs-deep-eql/component.json +18 -0
  44. data/vendor/components/chaijs-deep-eql/lib/eql.js +257 -0
  45. data/vendor/components/chaijs-type-detect/component.json +16 -0
  46. data/vendor/components/chaijs-type-detect/lib/type.js +142 -0
  47. data/vendor/components/component-bind/component.json +14 -0
  48. data/vendor/components/component-bind/index.js +24 -0
  49. data/vendor/components/component-delegate/component.json +19 -0
  50. data/vendor/components/component-delegate/index.js +42 -0
  51. data/vendor/components/component-event/component.json +13 -0
  52. data/vendor/components/component-event/index.js +40 -0
  53. data/vendor/components/component-jquery/component.json +14 -0
  54. data/vendor/components/component-jquery/index.js +9601 -0
  55. data/vendor/components/component-link-delegate/component.json +23 -0
  56. data/vendor/components/component-link-delegate/index.js +60 -0
  57. data/vendor/components/component-matches-selector/component.json +20 -0
  58. data/vendor/components/component-matches-selector/index.js +45 -0
  59. data/vendor/components/component-query/component.json +21 -0
  60. data/vendor/components/component-query/index.js +21 -0
  61. data/vendor/components/component-type/component.json +18 -0
  62. data/vendor/components/component-type/index.js +32 -0
  63. data/vendor/components/component-url/component.json +17 -0
  64. data/vendor/components/component-url/index.js +63 -0
  65. data/vendor/components/components-modernizr/component.json +18 -0
  66. data/vendor/components/components-modernizr/modernizr.js +1393 -0
  67. data/vendor/components/discore-closest/component.json +14 -0
  68. data/vendor/components/discore-closest/index.js +18 -0
  69. data/vendor/components/indefinido-advisable/component.json +21 -0
  70. data/vendor/components/indefinido-advisable/index.js +1 -0
  71. data/vendor/components/indefinido-advisable/lib/advisable.js +60 -0
  72. data/vendor/components/indefinido-indemma/component.json +40 -0
  73. data/vendor/components/indefinido-indemma/index.js +1 -0
  74. data/vendor/components/indefinido-indemma/lib/extensions/rivets.js +23 -0
  75. data/vendor/components/indefinido-indemma/lib/record/associable.js +217 -0
  76. data/vendor/components/indefinido-indemma/lib/record/maid.js +24 -0
  77. data/vendor/components/indefinido-indemma/lib/record/resource.js +104 -0
  78. data/vendor/components/indefinido-indemma/lib/record/rest.js +36 -0
  79. data/vendor/components/indefinido-indemma/lib/record/restfulable.js +326 -0
  80. data/vendor/components/indefinido-indemma/lib/record/scopable.js +279 -0
  81. data/vendor/components/indefinido-indemma/lib/record/translationable.js +19 -0
  82. data/vendor/components/indefinido-indemma/lib/record/validatable.js +216 -0
  83. data/vendor/components/indefinido-indemma/lib/record/validations/associated.js +30 -0
  84. data/vendor/components/indefinido-indemma/lib/record/validations/confirmation.js +19 -0
  85. data/vendor/components/indefinido-indemma/lib/record/validations/cpf.js +60 -0
  86. data/vendor/components/indefinido-indemma/lib/record/validations/presence.js +19 -0
  87. data/vendor/components/indefinido-indemma/lib/record/validations/remote.js +71 -0
  88. data/vendor/components/indefinido-indemma/lib/record.js +167 -0
  89. data/vendor/components/indefinido-indemma/vendor/sinon.js +4290 -0
  90. data/vendor/components/indefinido-indemma/vendor/stampit.js +392 -0
  91. data/vendor/components/indefinido-observable/component.json +25 -0
  92. data/vendor/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
  93. data/vendor/components/indefinido-observable/index.js +1 -0
  94. data/vendor/components/indefinido-observable/lib/adapters/rivets.js +26 -0
  95. data/vendor/components/indefinido-observable/lib/observable.js +320 -0
  96. data/vendor/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
  97. data/vendor/components/indefinido-observable/vendor/shims/accessors.js +173 -0
  98. data/vendor/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
  99. data/vendor/components/indefinido-observable/vendor/shims/object.create.js +77 -0
  100. data/vendor/components/mikeric-rivets/component.json +15 -0
  101. data/vendor/components/mikeric-rivets/dist/rivets.js +1239 -0
  102. data/vendor/components/paulmillr-es6-shim/component.json +17 -0
  103. data/vendor/components/paulmillr-es6-shim/es6-shim.js +985 -0
  104. data/vendor/components/pluma-assimilate/component.json +25 -0
  105. data/vendor/components/pluma-assimilate/dist/assimilate.js +87 -0
  106. data/vendor/components/segmentio-extend/component.json +13 -0
  107. data/vendor/components/segmentio-extend/index.js +15 -0
  108. metadata +98 -2
@@ -0,0 +1,326 @@
1
+ var $, merge, model, observable, record, rest, restful, type, util,
2
+ __slice = [].slice;
3
+
4
+ merge = require('assimilate').withStrategy('deep');
5
+
6
+ type = require('type');
7
+
8
+ observable = require('observable').mixin;
9
+
10
+ $ = require('jquery');
11
+
12
+ rest = require('./rest.js');
13
+
14
+ util = {
15
+ model: {
16
+ map: function(models) {
17
+ var model, _i, _len, _results;
18
+
19
+ _results = [];
20
+ for (_i = 0, _len = models.length; _i < _len; _i++) {
21
+ model = models[_i];
22
+ _results.push(this(model));
23
+ }
24
+ return _results;
25
+ }
26
+ }
27
+ };
28
+
29
+ restful = {
30
+ model: {
31
+ create: function() {
32
+ var attributes, callback, params, record, _i, _j, _len, _results;
33
+
34
+ params = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), callback = arguments[_i++];
35
+ if (!arguments.length) {
36
+ throw new TypeError("No arguments provided for " + this.resource + ".create");
37
+ }
38
+ if (typeof callback !== 'function') {
39
+ params.push(callback);
40
+ }
41
+ if (!params.length) {
42
+ params.unshift({});
43
+ }
44
+ _results = [];
45
+ for (_j = 0, _len = params.length; _j < _len; _j++) {
46
+ attributes = params[_j];
47
+ record = this(attributes);
48
+ record.dirty = true;
49
+ _results.push(record.save(callback));
50
+ }
51
+ return _results;
52
+ },
53
+ all: function(conditions, callback) {
54
+ if (conditions == null) {
55
+ conditions = {};
56
+ }
57
+ if (typeof conditions === 'function') {
58
+ callback = conditions;
59
+ conditions = {};
60
+ }
61
+ return $.when(rest.get.call(this, conditions)).then(util.model.map).done(callback);
62
+ },
63
+ first: function(conditions, callback) {
64
+ var namespaced;
65
+
66
+ if (conditions == null) {
67
+ conditions = {};
68
+ }
69
+ if (typeof conditions === 'function') {
70
+ callback = conditions;
71
+ conditions = {};
72
+ }
73
+ namespaced = conditions[this.resource] || {};
74
+ namespaced.limit = 1;
75
+ namespaced.order = 'desc';
76
+ return this.all(conditions, callback);
77
+ },
78
+ get: function(action, data) {
79
+ var old_route, payload, promise, resource, route;
80
+
81
+ old_route = this.route;
82
+ this.route = "/" + (model.pluralize(this.resource.name)) + "/" + action;
83
+ resource = data.resource;
84
+ if (data && data.json) {
85
+ data = data.json();
86
+ }
87
+ if (resource != null) {
88
+ payload = data;
89
+ data = {};
90
+ data[resource] = payload;
91
+ }
92
+ promise = rest.get.call(this, data);
93
+ route = old_route;
94
+ return promise;
95
+ }
96
+ },
97
+ record: {
98
+ reload: function() {
99
+ var argument, promise, _i, _len;
100
+
101
+ promise = rest.get.call(this);
102
+ promise.done(this.assign_attributes);
103
+ promise.fail(this.failed);
104
+ for (_i = 0, _len = arguments.length; _i < _len; _i++) {
105
+ argument = arguments[_i];
106
+ if (type(argument) === 'function') {
107
+ promise.done(argument);
108
+ }
109
+ }
110
+ return promise;
111
+ },
112
+ assign_attributes: function(attributes) {
113
+ var association, association_attributes, association_name, associations_attributes, attribute, message, singular_resource, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _results;
114
+
115
+ _ref = model[this.resource.toString()].has_many;
116
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
117
+ association_name = _ref[_i];
118
+ associations_attributes = attributes[association_name];
119
+ delete attributes[association_name];
120
+ association = this[association_name];
121
+ if (association == null) {
122
+ message = "Association '" + association_name + "' not found. \n";
123
+ message += "For record with resource " + this.resource + ". \n";
124
+ message += "Probably defined on server side but not on client side.\n";
125
+ message += "Skipping association assignment!";
126
+ console.warn(message);
127
+ continue;
128
+ }
129
+ if (association.length) {
130
+ Array.prototype.splice.call(association, 0);
131
+ }
132
+ if (!((associations_attributes != null) && associations_attributes.length)) {
133
+ continue;
134
+ }
135
+ singular_resource = model.singularize(association_name);
136
+ for (_j = 0, _len1 = associations_attributes.length; _j < _len1; _j++) {
137
+ association_attributes = associations_attributes[_j];
138
+ _ref1 = model[singular_resource].has_many;
139
+ for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
140
+ association_name = _ref1[_k];
141
+ association_attributes["" + association_name + "_attributes"] = association_attributes[association_name];
142
+ delete association_attributes[association_name];
143
+ }
144
+ }
145
+ association.add.apply(association, associations_attributes);
146
+ }
147
+ _ref2 = model[this.resource.toString()].has_one;
148
+ for (_l = 0, _len3 = _ref2.length; _l < _len3; _l++) {
149
+ association_name = _ref2[_l];
150
+ association_attributes = attributes[association_name];
151
+ delete attributes[association_name];
152
+ if (association_attributes) {
153
+ this[association_name] = this["build_" + association_name](association_attributes);
154
+ }
155
+ }
156
+ _results = [];
157
+ for (attribute in attributes) {
158
+ _results.push(this[attribute] = attributes[attribute]);
159
+ }
160
+ return _results;
161
+ },
162
+ save: function(doned, failed, data) {
163
+ var promise;
164
+
165
+ if (!this.dirty) {
166
+ return $.Deferred().resolve();
167
+ }
168
+ promise = rest[this._id ? 'put' : 'post'].call(this, data);
169
+ promise.done(this.saved);
170
+ promise.fail(this.failed);
171
+ promise.done(doned);
172
+ promise.fail(failed);
173
+ this.lock = JSON.stringify(this.json());
174
+ return promise;
175
+ },
176
+ saved: function(data) {
177
+ var callback, _i, _len, _ref, _results;
178
+
179
+ if (this.lock === JSON.stringify(this.json())) {
180
+ this.dirty = false;
181
+ delete this.lock;
182
+ } else {
183
+ return this.save();
184
+ }
185
+ if (data != null) {
186
+ this.assign_attributes(data);
187
+ }
188
+ if (this.after_save) {
189
+ _ref = this.after_save;
190
+ _results = [];
191
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
192
+ callback = _ref[_i];
193
+ throw "Not supported after_save callback: " + callback;
194
+ }
195
+ return _results;
196
+ }
197
+ },
198
+ failed: function(xhr, error, status) {
199
+ var attribute_name, definition, e, message, messages, payload, _ref, _results;
200
+
201
+ payload = xhr.responseJSON;
202
+ try {
203
+ payload || (payload = JSON.parse(xhr.responseText));
204
+ } catch (_error) {
205
+ e = _error;
206
+ }
207
+ payload || (payload = xhr.responseText);
208
+ switch (xhr.status) {
209
+ case 422:
210
+ definition = model[this.resource];
211
+ _ref = payload.errors;
212
+ _results = [];
213
+ for (attribute_name in _ref) {
214
+ messages = _ref[attribute_name];
215
+ if (!(this.hasOwnProperty(attribute_name) || definition.hasOwnProperty(attribute_name))) {
216
+ message = "Server returned an validation error message for a attribute that is not defined in your model.\n";
217
+ message += "The attribute was '" + attribute_name + "', the model resource was '" + this.resource + "'.\n";
218
+ message += "The model definition keys were '" + (JSON.stringify(Object.keys(definition))) + "'.\n";
219
+ message += "Please remove server validation, or update your model definition.";
220
+ throw new TypeError(message);
221
+ }
222
+ _results.push((function() {
223
+ var _i, _len, _results1;
224
+
225
+ _results1 = [];
226
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
227
+ message = messages[_i];
228
+ _results1.push(this.errors.add(attribute_name, 'server', {
229
+ server_message: message
230
+ }));
231
+ }
232
+ return _results1;
233
+ }).call(this));
234
+ }
235
+ return _results;
236
+ break;
237
+ default:
238
+ message = "Fail in " + this.resource + ".save:\n";
239
+ message += "Record: " + this + "\n";
240
+ message += "Status: " + status + " (" + (payload.status || xhr.status) + ")\n";
241
+ return message += "Error : " + (payload.error || payload.message || payload);
242
+ }
243
+ },
244
+ toString: function() {
245
+ var serialized;
246
+
247
+ serialized = {};
248
+ serialized[this.resource] = this.json();
249
+ return JSON.stringify(serialized);
250
+ },
251
+ json: function() {
252
+ var attribute, json, name, value, _i, _len, _ref;
253
+
254
+ json = {};
255
+ for (name in this) {
256
+ value = this[name];
257
+ if (!(type(value) !== 'function')) {
258
+ continue;
259
+ }
260
+ if (value == null) {
261
+ continue;
262
+ }
263
+ if (type(value) === 'object') {
264
+ if (value.toJSON != null) {
265
+ json[name] = value.toJSON();
266
+ } else {
267
+ _ref = this.nested_attributes;
268
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
269
+ attribute = _ref[_i];
270
+ if (attribute === name) {
271
+ json["" + name + "_attributes"] = value.json();
272
+ }
273
+ }
274
+ }
275
+ } else {
276
+ json[name] = value;
277
+ }
278
+ }
279
+ observable.unobserve(json);
280
+ delete json.dirty;
281
+ delete json.resource;
282
+ delete json.route;
283
+ delete json.initial_route;
284
+ delete json.after_initialize;
285
+ delete json.parent_resource;
286
+ delete json.nested_attributes;
287
+ delete json.on_save;
288
+ delete json.element;
289
+ delete json["default"];
290
+ delete json.lock;
291
+ delete json.validated;
292
+ return json;
293
+ }
294
+ }
295
+ };
296
+
297
+ restful.toJSON = restful.json;
298
+
299
+ model = window.model;
300
+
301
+ record = window.record;
302
+
303
+ model.restfulable = true;
304
+
305
+ record.mix(function(recordable) {
306
+ return merge(recordable, restful.record);
307
+ });
308
+
309
+ model.mix(function(modelable) {
310
+ return merge(modelable, restful.model);
311
+ });
312
+
313
+ model.associable && model.associable.mix(function(singular_association, plural_association) {
314
+ plural_association.get = function() {
315
+ if (this.parent != null) {
316
+ this.route || (this.route = "" + this.parent.route + "/" + this.parent._id + "/" + (model.pluralize(this.resource.name)));
317
+ }
318
+ return rest.get.apply(this, arguments);
319
+ };
320
+ return plural_association.post = function() {
321
+ if (this.parent != null) {
322
+ this.route || (this.route = "" + this.parent.route + "/" + this.parent._id + "/" + (model.pluralize(this.resource.name)));
323
+ }
324
+ return rest.post.apply(this, arguments);
325
+ };
326
+ });
@@ -0,0 +1,279 @@
1
+ var $, builders, defaults, extend, merge, model, record, rest, scopable, stampit,
2
+ __slice = [].slice;
3
+
4
+ require('./restfulable');
5
+
6
+ require('./resource');
7
+
8
+ stampit = require('../../vendor/stampit');
9
+
10
+ extend = require('assimilate');
11
+
12
+ merge = extend.withStrategy('deep');
13
+
14
+ $ = require('jquery');
15
+
16
+ rest = require('./rest');
17
+
18
+ scopable = {
19
+ builder: stampit().enclose(function() {
20
+ return stampit.mixIn(function(name, type) {
21
+ var builder;
22
+
23
+ if ($.type(type) === 'function') {
24
+ this["$" + name] = type() || new type;
25
+ type = $.type(this["$" + name]);
26
+ } else {
27
+ this["$" + name] = defaults[type] || type;
28
+ }
29
+ if ($.type(type) !== 'string') {
30
+ type = $.type(type);
31
+ }
32
+ builder = builders[type];
33
+ if (builder == null) {
34
+ throw "Unknown scope type " + type + " for model with resource " + model.resource;
35
+ }
36
+ this.scope.declared.push(name);
37
+ return this[name] = builder({
38
+ name: name
39
+ });
40
+ }, {
41
+ data: {},
42
+ then: [],
43
+ fail: [],
44
+ declared: [],
45
+ fetch: function(data, done, fail) {
46
+ var promise, scope;
47
+
48
+ scope = extend({}, this.scope.data);
49
+ promise = rest.get.call(this, extend(scope, data)).done(this.scope.then.concat(done)).fail([this.scope.fail, fail]);
50
+ this.scope.clear();
51
+ return promise;
52
+ },
53
+ clear: function() {
54
+ this.data = {};
55
+ return this.callbacks = [];
56
+ }
57
+ });
58
+ }),
59
+ base: stampit().state({
60
+ name: 'unamed_scope'
61
+ }),
62
+ record: {
63
+ failed: function(xhr, error, status) {
64
+ var e, message, payload;
65
+
66
+ payload = xhr.responseJSON;
67
+ try {
68
+ payload || (payload = JSON.parse(xhr.responseText));
69
+ } catch (_error) {
70
+ e = _error;
71
+ }
72
+ payload || (payload = xhr.responseText);
73
+ switch (xhr.status) {
74
+ case 422:
75
+ this.valid = false;
76
+ return this.errors = payload.errors;
77
+ default:
78
+ message = "Fail in " + this.resource + ".save:\n";
79
+ message += "Record: " + this + "\n";
80
+ message += "Status: " + status + " (" + (payload.status || xhr.status) + ")\n";
81
+ message += "Error : " + (payload.error || payload.message || payload);
82
+ }
83
+ return console.error(message);
84
+ }
85
+ },
86
+ model: {
87
+ fetch: function(data, done, fail) {
88
+ return this.scope.fetch.call(this, data, done, fail);
89
+ },
90
+ forward_scopes_to_associations: function() {
91
+ var associated_factory, associated_resource, association, association_name, factory, forwarder, generate_forwarder, scope, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4;
92
+
93
+ factory = model[this.resource];
94
+ _ref = factory.has_many;
95
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
96
+ association_name = _ref[_i];
97
+ associated_resource = model.singularize(association_name);
98
+ associated_factory = model[associated_resource];
99
+ if (!model[associated_resource]) {
100
+ console.warn("Associated factory not found for associated resource: " + associated_resource);
101
+ continue;
102
+ }
103
+ association = this[association_name];
104
+ association.scope = scopable.builder(association);
105
+ _ref1 = associated_factory.scope.declared;
106
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
107
+ scope = _ref1[_j];
108
+ association.scope(scope, associated_factory["$" + scope]);
109
+ }
110
+ }
111
+ _ref2 = factory.has_one;
112
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
113
+ associated_resource = _ref2[_k];
114
+ if (!model[associated_resource]) {
115
+ console.warn("Associated factory not found for associated resource: " + associated_resource);
116
+ continue;
117
+ }
118
+ _ref3 = model[associated_resource].scope.declared;
119
+ for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
120
+ scope = _ref3[_l];
121
+ this[associated_resource][scope] = factory[scope];
122
+ }
123
+ }
124
+ if (factory.belongs_to.length) {
125
+ generate_forwarder = function(associated_resource) {
126
+ var declared_scopes;
127
+
128
+ associated_factory = model[associated_resource];
129
+ if (!associated_factory) {
130
+ return console.warn("Associated factory not found for associated resource: " + associated_resource);
131
+ }
132
+ declared_scopes = associated_factory.scope.declared;
133
+ return function() {
134
+ var _len4, _m, _results;
135
+
136
+ _results = [];
137
+ for (_m = 0, _len4 = declared_scopes.length; _m < _len4; _m++) {
138
+ scope = declared_scopes[_m];
139
+ _results.push(this[associated_resource][scope] = associated_factory[scope]);
140
+ }
141
+ return _results;
142
+ };
143
+ };
144
+ _ref4 = factory.belongs_to;
145
+ for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {
146
+ associated_resource = _ref4[_m];
147
+ forwarder = generate_forwarder(associated_resource);
148
+ this.after("build_" + associated_resource, forwarder);
149
+ }
150
+ }
151
+ return true;
152
+ }
153
+ },
154
+ after_mix: function() {
155
+ var name, property, type, _results;
156
+
157
+ this.scope = scopable.builder(this);
158
+ _results = [];
159
+ for (property in this) {
160
+ type = this[property];
161
+ if (property.charAt(0) === '$') {
162
+ name = property.substring(1);
163
+ _results.push(this.scope(name, type));
164
+ } else {
165
+ _results.push(void 0);
166
+ }
167
+ }
168
+ return _results;
169
+ }
170
+ };
171
+
172
+ builders = {
173
+ boolean: stampit().enclose(function() {
174
+ var base;
175
+
176
+ base = scopable.base(this);
177
+ return stampit.mixIn(function() {
178
+ var callbacks, value, _base, _name;
179
+
180
+ value = arguments[0], callbacks = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
181
+ callbacks.length && (this.scope.then = this.scope.then.concat(callbacks));
182
+ (_base = this.scope.data)[_name = base.name] || (_base[_name] = value != null ? value : this["$" + base.name]);
183
+ return this;
184
+ });
185
+ }),
186
+ array: stampit().enclose(function() {
187
+ var base;
188
+
189
+ base = scopable.base(this);
190
+ return stampit.mixIn(function() {
191
+ var values, _base, _name;
192
+
193
+ values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
194
+ (_base = this.scope.data)[_name = base.name] || (_base[_name] = values != null ? values : this["$" + base.name]);
195
+ return this;
196
+ });
197
+ })
198
+ };
199
+
200
+ defaults = {
201
+ boolean: true,
202
+ array: []
203
+ };
204
+
205
+ model = window.model;
206
+
207
+ record = window.record;
208
+
209
+ model.scopable = true;
210
+
211
+ model.mix(function(modelable) {
212
+ merge(modelable, scopable.model);
213
+ return modelable.after_mix.push(scopable.after_mix);
214
+ });
215
+
216
+ if (model.associable) {
217
+ model.mix(function(modelable) {
218
+ return modelable.record.after_initialize.push(function() {
219
+ return scopable.model.forward_scopes_to_associations.call(this);
220
+ });
221
+ });
222
+ model.associable.mix(function(singular_association, plural_association) {
223
+ plural_association.all = plural_association.reload = function(data, done, fail) {
224
+ var promises, reload;
225
+
226
+ if (this.parent != null) {
227
+ this.route || (this.route = "" + this.parent.route + "/" + this.parent._id + "/" + (model.pluralize(this.resource)));
228
+ }
229
+ promises = [];
230
+ if (typeof data === 'function') {
231
+ done = data;
232
+ data = void 0;
233
+ }
234
+ promises.push(this.scope.fetch.call(this, data, null, scopable.record.failed));
235
+ reload = $.when.apply(jQuery, promises);
236
+ reload.done(function(records, status) {
237
+ var association_name, singular_resource, _i, _j, _len, _len1, _ref;
238
+
239
+ Array.prototype.splice.call(this, 0);
240
+ if (!records.length) {
241
+ return;
242
+ }
243
+ singular_resource = model.singularize(this.resource);
244
+ for (_i = 0, _len = records.length; _i < _len; _i++) {
245
+ record = records[_i];
246
+ _ref = model[singular_resource].has_many;
247
+ for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
248
+ association_name = _ref[_j];
249
+ record["" + association_name + "_attributes"] = record[association_name];
250
+ delete record[association_name];
251
+ }
252
+ }
253
+ this.add.apply(this, records);
254
+ records.splice(0);
255
+ return records.push.apply(records, this);
256
+ });
257
+ reload.done(done);
258
+ reload.fail(fail);
259
+ return reload;
260
+ };
261
+ return plural_association.each = function(callback) {
262
+ var _this = this;
263
+
264
+ if (this.parent != null) {
265
+ this.route || (this.route = "" + this.parent.route + "/" + this.parent._id + "/" + (model.pluralize(this.resource)));
266
+ }
267
+ return this.get().done(function(records) {
268
+ var _i, _len, _results;
269
+
270
+ _results = [];
271
+ for (_i = 0, _len = _this.length; _i < _len; _i++) {
272
+ record = _this[_i];
273
+ _results.push(callback(record));
274
+ }
275
+ return _results;
276
+ });
277
+ };
278
+ });
279
+ }
@@ -0,0 +1,19 @@
1
+ var extend, extensions, root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ extend = require('assimilate');
6
+
7
+ extensions = {
8
+ model: {
9
+ human_attribute_name: function(attribute_name) {
10
+ var _ref, _ref1;
11
+
12
+ return ((_ref = this.translation) != null ? (_ref1 = _ref.attributes) != null ? _ref1[attribute_name] : void 0 : void 0) || attribute_name;
13
+ }
14
+ }
15
+ };
16
+
17
+ model.mix(function(modelable) {
18
+ return extend(modelable, extensions.model);
19
+ });