aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts/services
diff options
context:
space:
mode:
authorTeddy Wing2015-01-25 17:34:05 -0500
committerTeddy Wing2015-01-25 17:34:05 -0500
commitb75ef2c502bf0da050bd290a2ad1cc7aa0dcc408 (patch)
treebf3bb8b56a2f289aba5fe0d3467368279a7c87ad /app/assets/javascripts/services
parent005e7cca168c6b4eeb06e314046f58b516c13aec (diff)
parent28e22a02c8c326df93093644d9de3fa71185ffe4 (diff)
downloadNotes-angular-demo-b75ef2c502bf0da050bd290a2ad1cc7aa0dcc408.tar.bz2
Merge branch 'angular-app'
Conflicts: app/assets/stylesheets/layouts/_global.scss app/views/home/main.html.erb
Diffstat (limited to 'app/assets/javascripts/services')
-rw-r--r--app/assets/javascripts/services/notes.js47
1 files changed, 47 insertions, 0 deletions
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();
+ });
+ }
+ }
+ };
+ }
+ ]);