From 154fb936beb820d5e8db616899a6a95bc8d1c080 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 24 Jan 2015 10:41:07 -0500 Subject: main view: Create & update work Add hooks to create new notes and save existing notes from the interface. --- app/assets/javascripts/services/notes.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'app/assets/javascripts/services/notes.js') 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(); + }); + } } }; } -- cgit v1.2.3