Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Created April 23, 2014 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmessinger/11200608 to your computer and use it in GitHub Desktop.
Save scottmessinger/11200608 to your computer and use it in GitHub Desktop.
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