diff --git a/app/assets/javascripts/app/controllers/editor.js b/app/assets/javascripts/app/controllers/editor.js index b54e52449..f5e9cadf2 100644 --- a/app/assets/javascripts/app/controllers/editor.js +++ b/app/assets/javascripts/app/controllers/editor.js @@ -3,7 +3,6 @@ angular.module('app') return { restrict: 'E', scope: { - save: "&", remove: "&", note: "=", updateTags: "&" @@ -130,7 +129,7 @@ angular.module('app') if(oldNote && oldNote != note) { if(oldNote.hasChanges) { - this.save()(oldNote, null); + this.saveNote(oldNote); } else if(oldNote.dummy) { this.remove()(oldNote); } @@ -243,7 +242,7 @@ angular.module('app') var statusTimeout; - this.saveNote = function($event) { + this.save = function($event) { var note = this.note; note.dummy = false; // Make sure the note exists. A safety measure, as toggling between tags triggers deletes for dummy notes. @@ -252,24 +251,46 @@ angular.module('app') alert("The note you are attempting to save can not be found or has been deleted. Changes you make will not be synced. Please copy this note's text and start a new note."); return; } - this.save()(note, function(success){ + + this.saveNote(note, (success) => { if(success) { if(statusTimeout) $timeout.cancel(statusTimeout); - statusTimeout = $timeout(function(){ + statusTimeout = $timeout(() => { this.showAllChangesSavedStatus(); - }.bind(this), 200) + }, 200) } else { if(statusTimeout) $timeout.cancel(statusTimeout); - statusTimeout = $timeout(function(){ + statusTimeout = $timeout(() => { this.showErrorStatus(); - }.bind(this), 200) + }, 200) } - }.bind(this)); + }); + } + + this.saveNote = function(note, callback) { + note.setDirty(true); + + syncManager.sync().then((response) => { + if(response && response.error) { + if(!this.didShowErrorAlert) { + this.didShowErrorAlert = true; + alert("There was an error saving your note. Please try again."); + } + $timeout(() => { + callback && callback(false); + }) + } else { + note.hasChanges = false; + $timeout(() => { + callback && callback(true); + }); + } + }) } this.saveTitle = function($event) { $event.target.blur(); - this.saveNote($event); + this.save($event); this.focusEditor(); } @@ -289,10 +310,10 @@ angular.module('app') if(saveTimeout) $timeout.cancel(saveTimeout); if(statusTimeout) $timeout.cancel(statusTimeout); - saveTimeout = $timeout(function(){ + saveTimeout = $timeout(() => { this.showSavingStatus(); - this.saveNote(); - }.bind(this), delay) + this.save(); + }, delay) } this.showSavingStatus = function() { diff --git a/app/assets/javascripts/app/controllers/footer.js b/app/assets/javascripts/app/controllers/footer.js index ee3669cbe..6491e40dd 100644 --- a/app/assets/javascripts/app/controllers/footer.js +++ b/app/assets/javascripts/app/controllers/footer.js @@ -10,7 +10,7 @@ angular.module('app') bindToController: true, link:function(scope, elem, attrs, ctrl) { - scope.$on("sync:updated_token", function(){ + scope.$on("sync:completed", function(){ ctrl.syncUpdated(); ctrl.findErrors(); ctrl.updateOfflineStatus(); diff --git a/app/assets/javascripts/app/controllers/home.js b/app/assets/javascripts/app/controllers/home.js index 1cb3fde8e..cbcf2f6fc 100644 --- a/app/assets/javascripts/app/controllers/home.js +++ b/app/assets/javascripts/app/controllers/home.js @@ -220,27 +220,6 @@ angular.module('app') Shared Callbacks */ - $scope.saveNote = function(note, callback) { - note.setDirty(true); - - syncManager.sync().then((response) => { - if(response && response.error) { - if(!$scope.didShowErrorAlert) { - $scope.didShowErrorAlert = true; - alert("There was an error saving your note. Please try again."); - } - $timeout(() => { - callback && callback(false); - }) - } else { - note.hasChanges = false; - $timeout(() => { - callback && callback(true); - }); - } - }) - } - $scope.safeApply = function(fn) { var phase = this.$root.$$phase; if(phase == '$apply' || phase == '$digest') diff --git a/app/assets/templates/home.html.haml b/app/assets/templates/home.html.haml index 54b834bd0..b8d03b4d3 100644 --- a/app/assets/templates/home.html.haml +++ b/app/assets/templates/home.html.haml @@ -6,6 +6,6 @@ %notes-section{"add-new" => "notesAddNew", "selection-made" => "notesSelectionMade", "tag" => "selectedTag"} - %editor-section{"note" => "selectedNote", "remove" => "deleteNote", "save" => "saveNote", "update-tags" => "updateTagsForNote"} + %editor-section{"note" => "selectedNote", "remove" => "deleteNote", "update-tags" => "updateTagsForNote"} %footer{"ng-if" => "!needsUnlock"}