diff options
Diffstat (limited to 'app/assets')
| -rw-r--r-- | app/assets/javascripts/application.js | 2 | ||||
| -rw-r--r-- | app/assets/javascripts/notes.coffee | 3 | ||||
| -rw-r--r-- | app/assets/javascripts/notes.js | 15 | ||||
| -rw-r--r-- | app/assets/javascripts/services/notes.js | 47 | 
4 files changed, 64 insertions, 3 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9e42736..f1823cb 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,4 +14,6 @@  //= require jquery_ujs  //= require turbolinks  //= require angular/angular +//= require angular-resource/angular-resource +//= require_tree ./services  //= require_tree . diff --git a/app/assets/javascripts/notes.coffee b/app/assets/javascripts/notes.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/notes.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js new file mode 100644 index 0000000..9a92f3e --- /dev/null +++ b/app/assets/javascripts/notes.js @@ -0,0 +1,15 @@ +(function() { +	angular +		.module('nt.Notes', [ +			'nt.NoteService' +		]) +		.controller('MainController', [ +			'$scope', +			'NoteService', +			function($scope, NoteService) { +				$scope.noteService = NoteService; +				 +				$scope.noteService.get_notes(); +			} +		]); +})(); diff --git a/app/assets/javascripts/services/notes.js b/app/assets/javascripts/services/notes.js new file mode 100644 index 0000000..bda6ae7 --- /dev/null +++ b/app/assets/javascripts/services/notes.js @@ -0,0 +1,47 @@ +angular +	.module('nt.NoteService', ['ngResource']) +	.factory('NoteService', [ +		'$resource', +		function($resource) { +			var Note = $resource('/notes/:id.json', +				{ id: '@id' }, +				{ +					update: { +						method: 'PUT' +					} +				}); +			 +			return { +				notes: [], +				current_note: null, +				 +				get_notes: function() { +					this.notes = Note.query(); +				}, +				 +				get_note: function(note) { +					this.current_note = note; +				}, +				 +				update: function() { +					this.current_note.$update(); +				}, +				 +				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(); +						}); +					} +				} +			}; +		} +	]);  | 
