diff options
Diffstat (limited to 'app/assets/javascripts/services/notes.js')
-rw-r--r-- | app/assets/javascripts/services/notes.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/app/assets/javascripts/services/notes.js b/app/assets/javascripts/services/notes.js index b1b4e90..bfa0b03 100644 --- a/app/assets/javascripts/services/notes.js +++ b/app/assets/javascripts/services/notes.js @@ -3,7 +3,13 @@ angular .factory('NoteService', [ '$resource', function($resource) { - var Note = $resource('/notes/:id.json', { id: '@id' }); + var Note = $resource('/notes/:id.json', + { id: '@id' }, + { + save: { + method: 'PUT' + } + }); return { notes: [], @@ -14,15 +20,32 @@ angular }, get_note: function(note) { - this.current_note = Note.get({ id: note.id }); + this.current_note = note; }, save: function() { + console.log(this.current_note.body); Note.save({ id: this.current_note.id, title: this.current_note.title, body: this.current_note.body }); + }, + + create: function () { + var _this = this; + + if (this.new_note_title) { + Note.save({ + title: this.new_note_title, + body: '' + }, function(response) { + _this.show_create = false; + delete _this.new_note_title; + _this.current_note = response; + _this.get_notes(); + }); + } } }; } |