ember-model-rails 0.0.1.1 → 0.0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
|
|
1
|
-
// Last commit:
|
1
|
+
// Last commit: 3e0ddb7 (2013-06-07 17:04:43 -0500)
|
2
2
|
|
3
3
|
|
4
4
|
(function() {
|
@@ -208,10 +208,63 @@ Ember.FilteredRecordArray = Ember.RecordArray.extend({
|
|
208
208
|
|
209
209
|
|
210
210
|
|
211
|
+
(function() {
|
212
|
+
var get = Ember.get;
|
213
|
+
|
214
|
+
Ember.HasManyArray = Ember.RecordArray.extend({
|
215
|
+
_records: null,
|
216
|
+
|
217
|
+
objectAtContent: function(idx) {
|
218
|
+
var klass = get(this, 'modelClass'),
|
219
|
+
content = get(this, 'content');
|
220
|
+
|
221
|
+
if (!content.length) { return; }
|
222
|
+
|
223
|
+
var attrs = content.objectAt(idx);
|
224
|
+
|
225
|
+
// TODO: Create a LazilyMaterializedRecordArray class and test it
|
226
|
+
if (this._records && this._records[idx]) { return this._records[idx]; }
|
227
|
+
|
228
|
+
var record = klass.create();
|
229
|
+
|
230
|
+
if (!this._records) { this._records = {}; }
|
231
|
+
this._records[idx] = record;
|
232
|
+
|
233
|
+
Ember.run(record, record.load, attrs.id, attrs); // FIXME
|
234
|
+
|
235
|
+
return record;
|
236
|
+
},
|
237
|
+
|
238
|
+
create: function(attrs) {
|
239
|
+
var klass = get(this, 'modelClass'),
|
240
|
+
record = klass.create(attrs);
|
241
|
+
|
242
|
+
this.pushObject(attrs);
|
243
|
+
|
244
|
+
// TODO: Create a LazilyMaterializedRecordArray class and test it
|
245
|
+
if (!this._records) { this._records = {}; }
|
246
|
+
this._records[get(this, 'length') - 1] = record;
|
247
|
+
|
248
|
+
return record; // FIXME: inject parent's id
|
249
|
+
},
|
250
|
+
|
251
|
+
save: function() {
|
252
|
+
// TODO: loop over dirty records only
|
253
|
+
return Ember.RSVP.all(this.map(function(record) {
|
254
|
+
return record.save();
|
255
|
+
}));
|
256
|
+
}
|
257
|
+
});
|
258
|
+
})();
|
259
|
+
|
260
|
+
|
261
|
+
|
211
262
|
(function() {
|
212
263
|
var get = Ember.get,
|
213
264
|
set = Ember.set,
|
214
|
-
|
265
|
+
setProperties = Ember.setProperties,
|
266
|
+
meta = Ember.meta,
|
267
|
+
underscore = Ember.String.underscore;
|
215
268
|
|
216
269
|
function contains(array, element) {
|
217
270
|
for (var i = 0, l = array.length; i < l; i++) {
|
@@ -238,32 +291,46 @@ Ember.Model = Ember.Object.extend(Ember.Evented, Ember.DeferredMixin, {
|
|
238
291
|
isDeleted: false,
|
239
292
|
_dirtyAttributes: null,
|
240
293
|
|
241
|
-
// TODO: rewrite w/o volatile
|
242
294
|
isDirty: Ember.computed(function() {
|
243
295
|
var attributes = this.attributes,
|
244
|
-
dirtyAttributes =
|
296
|
+
dirtyAttributes = Ember.A(), // just for removeObject
|
245
297
|
key, cachedValue, dataValue, desc, descMeta, type, isDirty;
|
298
|
+
|
246
299
|
for (var i = 0, l = attributes.length; i < l; i++) {
|
247
300
|
key = attributes[i];
|
248
301
|
cachedValue = this.cacheFor(key);
|
249
|
-
dataValue = get(this, 'data.'+key);
|
302
|
+
dataValue = get(this, 'data.'+this.dataKey(key));
|
250
303
|
desc = meta(this).descs[key];
|
251
304
|
descMeta = desc && desc.meta();
|
252
305
|
type = descMeta.type;
|
253
|
-
|
254
|
-
if (
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
}
|
306
|
+
|
307
|
+
if (type && type.isEqual) {
|
308
|
+
isDirty = !type.isEqual(dataValue, cachedValue || dataValue);
|
309
|
+
} else if (dataValue !== (cachedValue || dataValue)) {
|
310
|
+
isDirty = true;
|
311
|
+
} else {
|
312
|
+
isDirty = false;
|
261
313
|
}
|
262
314
|
|
315
|
+
if (isDirty) {
|
316
|
+
dirtyAttributes.push(key);
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
if (dirtyAttributes.length) {
|
321
|
+
this._dirtyAttributes = dirtyAttributes;
|
322
|
+
return true;
|
323
|
+
} else {
|
324
|
+
this._dirtyAttributes = [];
|
325
|
+
return false;
|
263
326
|
}
|
264
|
-
return dirtyAttributes && dirtyAttributes.length !== 0;
|
265
327
|
}).property().volatile(),
|
266
328
|
|
329
|
+
dataKey: function(key) {
|
330
|
+
var camelizeKeys = get(this.constructor, 'camelizeKeys');
|
331
|
+
return camelizeKeys ? underscore(key) : key;
|
332
|
+
},
|
333
|
+
|
267
334
|
init: function() {
|
268
335
|
if (!get(this, 'isNew')) { this.resolve(this); }
|
269
336
|
this._super();
|
@@ -303,10 +370,27 @@ Ember.Model = Ember.Object.extend(Ember.Evented, Ember.DeferredMixin, {
|
|
303
370
|
} else {
|
304
371
|
var deferred = Ember.Deferred.create();
|
305
372
|
deferred.resolve(this);
|
373
|
+
set(this, 'isSaving', false);
|
306
374
|
return deferred;
|
307
375
|
}
|
308
376
|
},
|
309
377
|
|
378
|
+
reload: function() {
|
379
|
+
return this.constructor.reload(this.get('id'));
|
380
|
+
},
|
381
|
+
|
382
|
+
revert: function() {
|
383
|
+
if (this.get('isDirty')) {
|
384
|
+
var data = get(this, 'data'),
|
385
|
+
reverts = {};
|
386
|
+
for (var i = 0; i < this._dirtyAttributes.length; i++) {
|
387
|
+
var attr = this._dirtyAttributes[i];
|
388
|
+
reverts[attr] = data[attr];
|
389
|
+
}
|
390
|
+
setProperties(this, reverts);
|
391
|
+
}
|
392
|
+
},
|
393
|
+
|
310
394
|
didCreateRecord: function() {
|
311
395
|
set(this, 'isNew', false);
|
312
396
|
this.load(this.get('id'), this.getProperties(this.attributes));
|
@@ -318,7 +402,7 @@ Ember.Model = Ember.Object.extend(Ember.Evented, Ember.DeferredMixin, {
|
|
318
402
|
didSaveRecord: function() {
|
319
403
|
set(this, 'isSaving', false);
|
320
404
|
this.trigger('didSaveRecord');
|
321
|
-
this._copyDirtyAttributesToData();
|
405
|
+
if (this.get('isDirty')) { this._copyDirtyAttributesToData(); }
|
322
406
|
},
|
323
407
|
|
324
408
|
deleteRecord: function() {
|
@@ -344,7 +428,7 @@ Ember.Model = Ember.Object.extend(Ember.Evented, Ember.DeferredMixin, {
|
|
344
428
|
for (var i = 0, l = dirtyAttributes.length; i < l; i++) {
|
345
429
|
// TODO: merge Object.create'd object into prototype
|
346
430
|
key = dirtyAttributes[i];
|
347
|
-
data[key] = this.cacheFor(key);
|
431
|
+
data[this.dataKey(key)] = this.cacheFor(key);
|
348
432
|
}
|
349
433
|
this._dirtyAttributes = [];
|
350
434
|
}
|
@@ -400,24 +484,37 @@ Ember.Model.reopenClass({
|
|
400
484
|
_currentBatchRecordArrays: null,
|
401
485
|
|
402
486
|
findById: function(id) {
|
403
|
-
var record = this.cachedRecordForId(id)
|
404
|
-
adapter = get(this, 'adapter');
|
487
|
+
var record = this.cachedRecordForId(id);
|
405
488
|
|
406
489
|
if (!get(record, 'isLoaded')) {
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
490
|
+
this._fetchById(record, id);
|
491
|
+
}
|
492
|
+
return record;
|
493
|
+
},
|
494
|
+
|
495
|
+
reload: function(id) {
|
496
|
+
var record = this.cachedRecordForId(id);
|
497
|
+
|
498
|
+
this._fetchById(record, id);
|
414
499
|
|
415
|
-
|
500
|
+
return record;
|
501
|
+
},
|
502
|
+
|
503
|
+
_fetchById: function(record, id) {
|
504
|
+
var adapter = get(this, 'adapter');
|
505
|
+
|
506
|
+
if (adapter.findMany) {
|
507
|
+
if (this._currentBatchIds) {
|
508
|
+
if (!contains(this._currentBatchIds, id)) { this._currentBatchIds.push(id); }
|
416
509
|
} else {
|
417
|
-
|
510
|
+
this._currentBatchIds = [id];
|
511
|
+
this._currentBatchRecordArrays = [];
|
418
512
|
}
|
513
|
+
|
514
|
+
Ember.run.scheduleOnce('data', this, this._executeBatch);
|
515
|
+
} else {
|
516
|
+
adapter.find(record, id);
|
419
517
|
}
|
420
|
-
return record;
|
421
518
|
},
|
422
519
|
|
423
520
|
_executeBatch: function() {
|
@@ -487,7 +584,12 @@ Ember.Model.reopenClass({
|
|
487
584
|
|
488
585
|
// FIXME
|
489
586
|
findFromCacheOrLoad: function(data) {
|
490
|
-
var record
|
587
|
+
var record;
|
588
|
+
if (!data.id) {
|
589
|
+
record = this.create({isLoaded: false});
|
590
|
+
} else {
|
591
|
+
record = this.cachedRecordForId(data.id);
|
592
|
+
}
|
491
593
|
// set(record, 'data', data);
|
492
594
|
record.load(data.id, data);
|
493
595
|
return record;
|
@@ -524,47 +626,69 @@ Ember.Model.reopenClass({
|
|
524
626
|
|
525
627
|
|
526
628
|
|
629
|
+
(function() {
|
630
|
+
var get = Ember.get;
|
631
|
+
|
632
|
+
Ember.hasMany = function(klass, key) {
|
633
|
+
return Ember.computed(function() {
|
634
|
+
return Ember.HasManyArray.create({
|
635
|
+
parent: this,
|
636
|
+
modelClass: klass,
|
637
|
+
content: get(this, 'data.' + key)
|
638
|
+
});
|
639
|
+
}).property();
|
640
|
+
};
|
641
|
+
})();
|
642
|
+
|
643
|
+
|
644
|
+
|
527
645
|
(function() {
|
528
646
|
var get = Ember.get,
|
529
647
|
set = Ember.set,
|
530
648
|
meta = Ember.meta;
|
531
649
|
|
650
|
+
function wrapObject(value) {
|
651
|
+
if (Ember.isArray(value)) {
|
652
|
+
var clonedArray = value.slice();
|
653
|
+
|
654
|
+
// TODO: write test for recursive cloning
|
655
|
+
for (var i = 0, l = clonedArray.length; i < l; i++) {
|
656
|
+
clonedArray[i] = wrapObject(clonedArray[i]);
|
657
|
+
}
|
658
|
+
|
659
|
+
return Ember.A(clonedArray);
|
660
|
+
} else if (value && typeof value === "object") {
|
661
|
+
var clone = Ember.create(value), property;
|
662
|
+
|
663
|
+
for (property in value) {
|
664
|
+
if (value.hasOwnProperty(property) && typeof value[property] === "object") {
|
665
|
+
clone[property] = wrapObject(value[property]);
|
666
|
+
}
|
667
|
+
}
|
668
|
+
return clone;
|
669
|
+
} else {
|
670
|
+
return value;
|
671
|
+
}
|
672
|
+
}
|
673
|
+
|
532
674
|
Ember.attr = function(type) {
|
533
675
|
return Ember.computed(function(key, value) {
|
534
676
|
var data = get(this, 'data'),
|
535
|
-
|
677
|
+
dataKey = this.dataKey(key),
|
678
|
+
dataValue = data && get(data, dataKey),
|
536
679
|
beingCreated = meta(this).proto === this;
|
537
680
|
|
538
681
|
if (arguments.length === 2) {
|
539
|
-
if (beingCreated) {
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
data[key] = value;
|
544
|
-
}
|
545
|
-
return value;
|
682
|
+
if (beingCreated && !data) {
|
683
|
+
data = {};
|
684
|
+
set(this, 'data', data);
|
685
|
+
data[dataKey] = value;
|
546
686
|
}
|
547
687
|
|
548
|
-
|
549
|
-
if (type && type.isEqual) {
|
550
|
-
isEqual = type.isEqual(dataValue, value);
|
551
|
-
} else {
|
552
|
-
isEqual = dataValue === value;
|
553
|
-
}
|
554
|
-
|
555
|
-
if (!isEqual) {
|
556
|
-
if (!this._dirtyAttributes) { this._dirtyAttributes = Ember.A(); }
|
557
|
-
this._dirtyAttributes.push(key);
|
558
|
-
} else {
|
559
|
-
if (this._dirtyAttributes) { this._dirtyAttributes.removeObject(key); }
|
560
|
-
}
|
561
|
-
return value;
|
688
|
+
return wrapObject(value);
|
562
689
|
}
|
563
690
|
|
564
|
-
|
565
|
-
dataValue = Ember.create(dataValue);
|
566
|
-
}
|
567
|
-
return dataValue;
|
691
|
+
return wrapObject(dataValue);
|
568
692
|
}).property('data').meta({isAttribute: true, type: type});
|
569
693
|
};
|
570
694
|
|
@@ -581,7 +705,7 @@ Ember.RESTAdapter = Ember.Adapter.extend({
|
|
581
705
|
self = this;
|
582
706
|
|
583
707
|
return this.ajax(url).then(function(data) {
|
584
|
-
self.didFind
|
708
|
+
self.didFind(record, id, data);
|
585
709
|
});
|
586
710
|
},
|
587
711
|
|
@@ -597,7 +721,7 @@ Ember.RESTAdapter = Ember.Adapter.extend({
|
|
597
721
|
self = this;
|
598
722
|
|
599
723
|
return this.ajax(url).then(function(data) {
|
600
|
-
self.didFindAll
|
724
|
+
self.didFindAll(klass, records, data);
|
601
725
|
});
|
602
726
|
},
|
603
727
|
|
@@ -613,7 +737,7 @@ Ember.RESTAdapter = Ember.Adapter.extend({
|
|
613
737
|
self = this;
|
614
738
|
|
615
739
|
return this.ajax(url, params).then(function(data) {
|
616
|
-
self.didFindQuery
|
740
|
+
self.didFindQuery(klass, records, params, data);
|
617
741
|
});
|
618
742
|
},
|
619
743
|
|
@@ -629,13 +753,16 @@ Ember.RESTAdapter = Ember.Adapter.extend({
|
|
629
753
|
self = this;
|
630
754
|
|
631
755
|
return this.ajax(url, record.toJSON(), "POST").then(function(data) {
|
632
|
-
self.didCreateRecord
|
756
|
+
self.didCreateRecord(record, data);
|
633
757
|
});
|
634
758
|
},
|
635
759
|
|
636
760
|
didCreateRecord: function(record, data) {
|
761
|
+
var rootKey = get(record.constructor, 'rootKey'),
|
762
|
+
dataToLoad = rootKey ? data[rootKey] : data;
|
763
|
+
|
637
764
|
Ember.run(function() {
|
638
|
-
record.load(
|
765
|
+
record.load(dataToLoad.id, dataToLoad); // FIXME: hardcoded ID
|
639
766
|
record.didCreateRecord();
|
640
767
|
});
|
641
768
|
},
|
@@ -645,7 +772,7 @@ Ember.RESTAdapter = Ember.Adapter.extend({
|
|
645
772
|
self = this;
|
646
773
|
|
647
774
|
return this.ajax(url, record.toJSON(), "PUT").then(function(data) { // TODO: Some APIs may or may not return data
|
648
|
-
self.didSaveRecord
|
775
|
+
self.didSaveRecord(record, data);
|
649
776
|
});
|
650
777
|
},
|
651
778
|
|
@@ -658,7 +785,7 @@ Ember.RESTAdapter = Ember.Adapter.extend({
|
|
658
785
|
self = this;
|
659
786
|
|
660
787
|
return this.ajax(url, record.toJSON(), "DELETE").then(function(data) { // TODO: Some APIs may or may not return data
|
661
|
-
self.didDeleteRecord
|
788
|
+
self.didDeleteRecord(record, data);
|
662
789
|
});
|
663
790
|
},
|
664
791
|
|
@@ -688,9 +815,13 @@ Ember.RESTAdapter = Ember.Adapter.extend({
|
|
688
815
|
dataType: "json"
|
689
816
|
};
|
690
817
|
|
691
|
-
if (params
|
692
|
-
|
693
|
-
|
818
|
+
if (params) {
|
819
|
+
if (method === "GET") {
|
820
|
+
settings.data = params;
|
821
|
+
} else {
|
822
|
+
settings.contentType = "application/json; charset=utf-8";
|
823
|
+
settings.data = JSON.stringify(params);
|
824
|
+
}
|
694
825
|
}
|
695
826
|
|
696
827
|
return Ember.$.ajax(settings);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ember-model-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 79
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 1
|
10
|
-
-
|
11
|
-
version: 0.0.1.
|
10
|
+
- 2
|
11
|
+
version: 0.0.1.2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Alex Auritt
|
@@ -16,11 +16,10 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-06-
|
19
|
+
date: 2013-06-11 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: railties
|
23
|
-
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
@@ -32,6 +31,7 @@ dependencies:
|
|
32
31
|
- 1
|
33
32
|
version: "3.1"
|
34
33
|
type: :runtime
|
34
|
+
prerelease: false
|
35
35
|
version_requirements: *id001
|
36
36
|
description: put the models...
|
37
37
|
email:
|
@@ -46,7 +46,6 @@ files:
|
|
46
46
|
- lib/ember-model-rails/version.rb
|
47
47
|
- lib/ember-model-rails.rb
|
48
48
|
- vendor/assets/javascripts/ember-model.js
|
49
|
-
- vendor/assets/javascripts/ember-model.min.js
|
50
49
|
- LICENSE.txt
|
51
50
|
- README.md
|
52
51
|
homepage: ""
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// ==========================================================================
|
2
|
-
// Project: Ember Data
|
3
|
-
// Copyright: ©2011-2012 Tilde Inc. and contributors.
|
4
|
-
// Portions ©2011 Living Social Inc. and contributors.
|
5
|
-
// License: Licensed under MIT license (see license.js)
|
6
|
-
// ==========================================================================
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
// Last commit: 7656e63 (2013-05-28 17:06:31 -0700)
|
11
|
-
|
12
|
-
|
13
|
-
(function(){Ember.Adapter=Ember.Object.extend({find:function(){throw new Error("Ember.Adapter subclasses must implement find")},findQuery:function(){throw new Error("Ember.Adapter subclasses must implement findQuery")},findMany:function(){throw new Error("Ember.Adapter subclasses must implement findMany")},findAll:function(){throw new Error("Ember.Adapter subclasses must implement findAll")},load:function(r,e,t){r.load(e,t)},createRecord:function(){throw new Error("Ember.Adapter subclasses must implement createRecord")},saveRecord:function(){throw new Error("Ember.Adapter subclasses must implement saveRecord")},deleteRecord:function(){throw new Error("Ember.Adapter subclasses must implement deleteRecord")}})})(),function(){Ember.FixtureAdapter=Ember.Adapter.extend({find:function(r,e){var t=r.constructor.FIXTURES,i=Ember.A(t).find(function(r){return r.id===e});r.get("isLoaded")||setTimeout(function(){Ember.run(r,r.load,e,i)})},findMany:function(r,e,t){for(var i=r.FIXTURES,n=[],o=0,d=t.length;d>o;o++)n.push(i[o]);setTimeout(function(){Ember.run(e,e.load,r,n)})},findAll:function(r,e){var t=r.FIXTURES;setTimeout(function(){Ember.run(e,e.load,r,t)})},createRecord:function(r){var e=r.constructor,t=e.FIXTURES;return setTimeout(function(){Ember.run(function(){t.push(e.findFromCacheOrLoad(r.toJSON())),r.didCreateRecord()})}),r},saveRecord:function(r){var e=Ember.Deferred.create();return e.then(function(){r.didSaveRecord()}),setTimeout(function(){Ember.run(e,e.resolve,r)}),e},deleteRecord:function(r){var e=Ember.Deferred.create();return e.then(function(){r.didDeleteRecord()}),setTimeout(function(){Ember.run(e,e.resolve,r)}),e}})}(),function(){var r=Ember.get,e=Ember.set;Ember.RecordArray=Ember.ArrayProxy.extend(Ember.Evented,Ember.DeferredMixin,{isLoaded:!1,isLoading:Ember.computed.not("isLoaded"),load:function(r,t){e(this,"content",this.materializeData(r,t)),this.notifyLoaded()},loadForFindMany:function(t){var i=r(this,"_ids").map(function(r){return t.cachedRecordForId(r)});e(this,"content",Ember.A(i)),this.notifyLoaded()},notifyLoaded:function(){e(this,"isLoaded",!0),this.trigger("didLoad"),this.resolve(this)},materializeData:function(r,e){return Ember.A(e.map(function(e){return r.findFromCacheOrLoad(e)}))}})}(),function(){var r=Ember.get;Ember.FilteredRecordArray=Ember.RecordArray.extend({init:function(){if(!r(this,"modelClass"))throw new Error("FilteredRecordArrays must be created with a modelClass");if(!r(this,"filterFunction"))throw new Error("FilteredRecordArrays must be created with a filterFunction");if(!r(this,"filterProperties"))throw new Error("FilteredRecordArrays must be created with filterProperties");var e=r(this,"modelClass");e.registerRecordArray(this),this.registerObservers(),this.updateFilter()},updateFilter:function(){var e=this,t=[];r(this,"modelClass").forEachCachedRecord(function(r){e.filterFunction(r)&&t.push(r)}),this.set("content",Ember.A(t))},updateFilterForRecord:function(e){var t=r(this,"content");this.filterFunction(e)&&t.pushObject(e)},registerObservers:function(){var e=this;r(this,"modelClass").forEachCachedRecord(function(r){e.registerObserversOnRecord(r)})},registerObserversOnRecord:function(e){for(var t=this,i=r(this,"filterProperties"),n=0,o=r(i,"length");o>n;n++)e.addObserver(i[n],t,"updateFilterForRecord")}})}(),function(){function r(r,e){for(var t=0,i=r.length;i>t;t++)if(r[t]===e)return!0;return!1}function e(e,t){for(var i,n=0,o=t.length;o>n;n++)i=t[n],r(e,i)||e.push(i);return e}var t=Ember.get,i=Ember.set,n=Ember.meta;Ember.run.queues.push("data"),Ember.Model=Ember.Object.extend(Ember.Evented,Ember.DeferredMixin,{isLoaded:!0,isLoading:Ember.computed.not("isLoaded"),isNew:!0,isDeleted:!1,_dirtyAttributes:null,isDirty:Ember.computed(function(){for(var r,e,i,o,d,s,a,c=this.attributes,u=this._dirtyAttributes,h=0,f=c.length;f>h;h++)r=c[h],e=this.cacheFor(r),i=t(this,"data."+r),o=n(this).descs[r],d=o&&o.meta(),s=d.type,a=u&&-1!==u.indexOf(r),!a&&s&&s.isEqual&&(s.isEqual(i,e||i)||(u||(u=this._dirtyAttributes=Ember.A()),u.push(r)));return u&&0!==u.length}).property().volatile(),init:function(){t(this,"isNew")||this.resolve(this),this._super()},load:function(r,e){var t=Ember.merge({id:r},e);i(this,"data",t),i(this,"isLoaded",!0),i(this,"isNew",!1),this.trigger("didLoad"),this.resolve(this)},didDefineProperty:function(r,e,t){if(t instanceof Ember.Descriptor){var i=t.meta();i.isAttribute&&(r.attributes||(r.attributes=[]),r.attributes.push(e))}},toJSON:function(){return this.getProperties(this.attributes)},save:function(){var r=this.constructor.adapter;if(i(this,"isSaving",!0),t(this,"isNew"))return r.createRecord(this);if(t(this,"isDirty"))return r.saveRecord(this);var e=Ember.Deferred.create();return e.resolve(this),e},didCreateRecord:function(){i(this,"isNew",!1),this.load(this.get("id"),this.getProperties(this.attributes)),this.constructor.addToRecordArrays(this),this.trigger("didCreateRecord"),this.didSaveRecord()},didSaveRecord:function(){i(this,"isSaving",!1),this.trigger("didSaveRecord"),this._copyDirtyAttributesToData()},deleteRecord:function(){return this.constructor.adapter.deleteRecord(this)},didDeleteRecord:function(){this.constructor.removeFromRecordArrays(this),i(this,"isDeleted",!0),this.trigger("didDeleteRecord")},_copyDirtyAttributesToData:function(){if(this._dirtyAttributes){var r,e=this._dirtyAttributes,n=t(this,"data");n||(n={},i(this,"data",n));for(var o=0,d=e.length;d>o;o++)r=e[o],n[r]=this.cacheFor(r);this._dirtyAttributes=[]}}}),Ember.Model.reopenClass({adapter:Ember.Adapter.create(),find:function(r){return arguments.length?Ember.isArray(r)?this.findMany(r):"object"==typeof r?this.findQuery(r):this.findById(r):this.findAll()},findMany:function(r){var t=Ember.RecordArray.create({_ids:r});return this.recordArrays||(this.recordArrays=[]),this.recordArrays.push(t),this._currentBatchIds?(e(this._currentBatchIds,r),this._currentBatchRecordArrays.push(t)):(this._currentBatchIds=e([],r),this._currentBatchRecordArrays=[t]),Ember.run.scheduleOnce("data",this,this._executeBatch),t},findAll:function(){if(this._findAllRecordArray)return this._findAllRecordArray;var r=this._findAllRecordArray=Ember.RecordArray.create();return this.adapter.findAll(this,r),r},_currentBatchIds:null,_currentBatchRecordArrays:null,findById:function(e){var i=this.cachedRecordForId(e),n=t(this,"adapter");return t(i,"isLoaded")||(n.findMany?(this._currentBatchIds?r(this._currentBatchIds,e)||this._currentBatchIds.push(e):(this._currentBatchIds=[e],this._currentBatchRecordArrays=[]),Ember.run.scheduleOnce("data",this,this._executeBatch)):n.find(i,e)),i},_executeBatch:function(){var r,e=this._currentBatchIds,i=this._currentBatchRecordArrays,n=this;this._currentBatchIds=null,this._currentBatchRecordArrays=null,1===e.length?t(this,"adapter").find(this.cachedRecordForId(e[0]),e[0]):(r=Ember.RecordArray.create({_ids:e}),t(this,"adapter").findMany(this,r,e),r.then(function(){for(var r=0,e=i.length;e>r;r++)i[r].loadForFindMany(n)}))},findQuery:function(r){var e=Ember.RecordArray.create();return this.adapter.findQuery(this,e,r),e},cachedRecordForId:function(r){this.recordCache||(this.recordCache={});var e=this.sideloadedData&&this.sideloadedData[r],t=this.recordCache[r]||(e?this.create(e):this.create({isLoaded:!1}));return this.recordCache[r]||(this.recordCache[r]=t),t},addToRecordArrays:function(r){this._findAllRecordArray&&this._findAllRecordArray.pushObject(r),this.recordArrays&&this.recordArrays.forEach(function(e){e instanceof Ember.FilteredRecordArray?(e.registerObserversOnRecord(r),e.updateFilter()):e.pushObject(r)})},removeFromRecordArrays:function(r){this._findAllRecordArray&&this._findAllRecordArray.removeObject(r),this.recordArrays&&this.recordArrays.forEach(function(e){e.removeObject(r)})},findFromCacheOrLoad:function(r){var e=this.cachedRecordForId(r.id);return e.load(r.id,r),e},registerRecordArray:function(r){this.recordArrays||(this.recordArrays=[]),this.recordArrays.push(r)},unregisterRecordArray:function(r){this.recordArrays&&Ember.A(this.recordArrays).removeObject(r)},forEachCachedRecord:function(r){if(!this.recordCache)return Ember.A([]);var e=Object.keys(this.recordCache);e.map(function(r){return this.recordCache[parseInt(r,10)]},this).forEach(r)},load:function(r){this.sideloadedData||(this.sideloadedData={});for(var e=0,t=r.length;t>e;e++){var i=r[e];this.sideloadedData[i.id]=i}}})}(),function(){var r=Ember.get,e=Ember.set,t=Ember.meta;Ember.attr=function(i){return Ember.computed(function(n,o){var d=r(this,"data"),s=d&&r(d,n),a=t(this).proto===this;if(2===arguments.length){if(a)return d||(d={},e(this,"data",d),d[n]=o),o;var c;return c=i&&i.isEqual?i.isEqual(s,o):s===o,c?this._dirtyAttributes&&this._dirtyAttributes.removeObject(n):(this._dirtyAttributes||(this._dirtyAttributes=Ember.A()),this._dirtyAttributes.push(n)),o}return s&&"object"==typeof s&&(s=Ember.create(s)),s}).property("data").meta({isAttribute:!0,type:i})}}(),function(){var r=Ember.get;Ember.RESTAdapter=Ember.Adapter.extend({find:function(r,e){var t=this.buildURL(r.constructor,e),i=this;return this.ajax(t).then(function(t){i.didFind.call(i,r,e,t)})},didFind:function(e,t,i){var n=r(e.constructor,"rootKey"),o=n?i[n]:i;Ember.run(e,e.load,t,o)},findAll:function(r,e){var t=this.buildURL(r),i=this;return this.ajax(t).then(function(t){i.didFindAll.call(i,r,e,t)})},didFindAll:function(e,t,i){var n=r(e,"collectionKey"),o=n?i[n]:i;Ember.run(t,t.load,e,o)},findQuery:function(r,e,t){var i=this.buildURL(r),n=this;return this.ajax(i,t).then(function(i){n.didFindQuery.call(n,r,e,t,i)})},didFindQuery:function(e,t,i,n){var o=r(e,"collectionKey"),d=o?n[o]:n;Ember.run(t,t.load,e,d)},createRecord:function(r){var e=this.buildURL(r.constructor),t=this;return this.ajax(e,r.toJSON(),"POST").then(function(e){t.didCreateRecord.call(t,r,e)})},didCreateRecord:function(r,e){Ember.run(function(){r.load(e.id,e),r.didCreateRecord()})},saveRecord:function(e){var t=this.buildURL(e.constructor,r(e,"id")),i=this;return this.ajax(t,e.toJSON(),"PUT").then(function(r){i.didSaveRecord.call(i,e,r)})},didSaveRecord:function(r){Ember.run(r,r.didSaveRecord)},deleteRecord:function(e){var t=this.buildURL(e.constructor,r(e,"id")),i=this;return this.ajax(t,e.toJSON(),"DELETE").then(function(r){i.didDeleteRecord.call(i,e,r)})},didDeleteRecord:function(r){Ember.run(r,r.didDeleteRecord)},ajax:function(r,e,t){return this._ajax(r,e,t||"GET")},buildURL:function(e,t){var i=r(e,"url");if(!i)throw new Error("Ember.RESTAdapter requires a `url` property to be specified");return t?i+"/"+t+".json":i+".json"},_ajax:function(r,e,t){var i={url:r,type:t,dataType:"json"};return e&&"GET"!==t&&(i.contentType="application/json; charset=utf-8",i.data=JSON.stringify(e)),Ember.$.ajax(i)}})}(),"undefined"==typeof location||"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname||console.warn("You are running a production build of Ember on localhost and won't receive detailed error messages. If you want full error messages please use the non-minified build provided on the Ember website.");
|