Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.