Skip to content

Instantly share code, notes, and snippets.

@64lines
Created October 19, 2013 17:26
Show Gist options
  • Save 64lines/7058793 to your computer and use it in GitHub Desktop.
Save 64lines/7058793 to your computer and use it in GitHub Desktop.
var Notes = Ember.Application.create({
});
/** Router **/
Notes.Router.map(function () {
this.resource('notes', {path: "/"}, function() {
this.route('note', {path: "/note/:note_id"});
});
});
Notes.NotesRoute = Ember.Route.extend({
model: function() {
return this.store.find('note');
}
});
Notes.NotesNoteRoute = Ember.Route.extend({
model: function(note) {
return this.store.find('note', note.note_id);
}
});
Notes.NotesController = Ember.ArrayController.extend({
newNoteName: null,
actions: {
createNewNote: function() {
var content = this.get('content');
var newNoteName = this.get('newNoteName');
var unique = newNoteName != null && newNoteName.length > 1;
content.forEach(function(note) {
if (newNoteName === note.get('name')) {
unique = false; return;
}
});
if (unique) {
var newNote = this.store.createRecord('note');
newNote.set('id', newNoteName);
newNote.set('name', newNoteName);
newNote.save();
this.set('newNoteName', null);
} else {
alert('Note must have a unique name of at least 2 characters!');
}
}
}
});
/** Ember Data **/
Notes.Note = DS.Model.extend({
name: DS.attr('string'),
value: DS.attr('string')
});
Notes.Store = DS.Store.extend({
adapter: DS.LSAdapter
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment