Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Last active August 29, 2015 14:00
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/11182785 to your computer and use it in GitHub Desktop.
Save scottmessinger/11182785 to your computer and use it in GitHub Desktop.
es6 and ember
import SortableListMixin from '../mixins/sortable-list';
import Part from '../models/part';
import Section from '../models/section';
var PartsController = Ember.ArrayController.extend(SortableListMixin, {
init: function(){
this._super()
// ISSUE #1 - probably unrelated the es6 change.
// Shouldn't the content be set automatically to an array?
if (Ember.isNone(this.get('content'))){
this.set('content', [])
this.set('arrangedContent', [])
}
},
sortProperties: ['position'],
sortAscending : true,
actions: {
addAbove: function(part){
var newPart = Part.create()
// ISSUE #2:
// newPart.toString() == "(subclass of Ember.Model)"
// instead of "<app@model:part:>"
newPart.set('section', Section.create({_parent: newPart}))
newPart.set('_parent', this.get('content'))
this.addModelAbove(part, newPart)
},
}
});
export default PartsController;
import Course from './course';
import Section from './section';
var Part = Ember.Model.extend({
/*
*
* Attributes
*
*/
courseId: Ember.attr(),
position: Ember.attr(Number),
/*
*
* Relationships
*
*/
section: Ember.belongsTo(Section, {embedded: true, key: 'section'}),
course: Ember.belongsTo(Course, {key: 'courseId'}),
courseDate: function(){
return this.get('parentModel.date')
}.property('courseId', 'parentModel.date'),
})
export default Part;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment