diff options
| author | Teddy Wing | 2015-01-24 10:41:07 -0500 | 
|---|---|---|
| committer | Teddy Wing | 2015-01-24 10:41:07 -0500 | 
| commit | 154fb936beb820d5e8db616899a6a95bc8d1c080 (patch) | |
| tree | c45eab082b4e1ef37320a6608f6850c9871e6c1c /app/assets/javascripts/services | |
| parent | 384167b6122e44971aac7f98a0131f8cad1ef47f (diff) | |
| download | Notes-angular-demo-154fb936beb820d5e8db616899a6a95bc8d1c080.tar.bz2 | |
main view: Create & update work
Add hooks to create new notes and save existing notes from the
interface.
Diffstat (limited to 'app/assets/javascripts/services')
| -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(); +						}); +					}  				}  			};  		}  | 
