Created
April 23, 2014 02:07
-
-
Save scottmessinger/11200608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.PlanbookDate = Ember.Model.extend({ | |
/** | |
* Computed Property | |
* This property returns a routine. If the routine is pristine, | |
* it creates a routine then adds parts from the routine template to it. | |
* | |
* If the routine is not pristine, it just returns the routine. | |
* | |
*/ | |
routine: function(){ | |
if (this.get('routineIsPristine')){ | |
routine = App.Routine.create({id: this.get('routineId')}) | |
routine.set('planbookDate', this) | |
var template = App.Routine.find(this.get('routineTemplateId')) | |
template.on('didLoad', function(){ | |
template.get('parts').forEach(function(part){ | |
routine.get('parts').addObject(PartModel.create(part._data)) | |
}) | |
routine.set('_dirtyAttributes', []) | |
}) | |
} else { | |
routine = App.Routine.find(this.get('routineId')) | |
routine.set('planbookDate', this) | |
} | |
return routine | |
}.property('routineId', 'isLoaded'), | |
}) | |
App.Routine = Ember.Model.extend({ | |
id: Ember.attr(), | |
parts: Ember.hasMany('part', {embedded: true, key: 'parts'}), | |
lessons: Ember.computed.filterBy('parts', 'type', 'lesson'), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment