Move save function from home into editor controller
This commit is contained in:
@@ -3,7 +3,6 @@ angular.module('app')
|
|||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: {
|
scope: {
|
||||||
save: "&",
|
|
||||||
remove: "&",
|
remove: "&",
|
||||||
note: "=",
|
note: "=",
|
||||||
updateTags: "&"
|
updateTags: "&"
|
||||||
@@ -130,7 +129,7 @@ angular.module('app')
|
|||||||
|
|
||||||
if(oldNote && oldNote != note) {
|
if(oldNote && oldNote != note) {
|
||||||
if(oldNote.hasChanges) {
|
if(oldNote.hasChanges) {
|
||||||
this.save()(oldNote, null);
|
this.saveNote(oldNote);
|
||||||
} else if(oldNote.dummy) {
|
} else if(oldNote.dummy) {
|
||||||
this.remove()(oldNote);
|
this.remove()(oldNote);
|
||||||
}
|
}
|
||||||
@@ -243,7 +242,7 @@ angular.module('app')
|
|||||||
|
|
||||||
var statusTimeout;
|
var statusTimeout;
|
||||||
|
|
||||||
this.saveNote = function($event) {
|
this.save = function($event) {
|
||||||
var note = this.note;
|
var note = this.note;
|
||||||
note.dummy = false;
|
note.dummy = false;
|
||||||
// Make sure the note exists. A safety measure, as toggling between tags triggers deletes for dummy notes.
|
// 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.");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
this.save()(note, function(success){
|
|
||||||
|
this.saveNote(note, (success) => {
|
||||||
if(success) {
|
if(success) {
|
||||||
if(statusTimeout) $timeout.cancel(statusTimeout);
|
if(statusTimeout) $timeout.cancel(statusTimeout);
|
||||||
statusTimeout = $timeout(function(){
|
statusTimeout = $timeout(() => {
|
||||||
this.showAllChangesSavedStatus();
|
this.showAllChangesSavedStatus();
|
||||||
}.bind(this), 200)
|
}, 200)
|
||||||
} else {
|
} else {
|
||||||
if(statusTimeout) $timeout.cancel(statusTimeout);
|
if(statusTimeout) $timeout.cancel(statusTimeout);
|
||||||
statusTimeout = $timeout(function(){
|
statusTimeout = $timeout(() => {
|
||||||
this.showErrorStatus();
|
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) {
|
this.saveTitle = function($event) {
|
||||||
$event.target.blur();
|
$event.target.blur();
|
||||||
this.saveNote($event);
|
this.save($event);
|
||||||
this.focusEditor();
|
this.focusEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,10 +310,10 @@ angular.module('app')
|
|||||||
|
|
||||||
if(saveTimeout) $timeout.cancel(saveTimeout);
|
if(saveTimeout) $timeout.cancel(saveTimeout);
|
||||||
if(statusTimeout) $timeout.cancel(statusTimeout);
|
if(statusTimeout) $timeout.cancel(statusTimeout);
|
||||||
saveTimeout = $timeout(function(){
|
saveTimeout = $timeout(() => {
|
||||||
this.showSavingStatus();
|
this.showSavingStatus();
|
||||||
this.saveNote();
|
this.save();
|
||||||
}.bind(this), delay)
|
}, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.showSavingStatus = function() {
|
this.showSavingStatus = function() {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ angular.module('app')
|
|||||||
bindToController: true,
|
bindToController: true,
|
||||||
|
|
||||||
link:function(scope, elem, attrs, ctrl) {
|
link:function(scope, elem, attrs, ctrl) {
|
||||||
scope.$on("sync:updated_token", function(){
|
scope.$on("sync:completed", function(){
|
||||||
ctrl.syncUpdated();
|
ctrl.syncUpdated();
|
||||||
ctrl.findErrors();
|
ctrl.findErrors();
|
||||||
ctrl.updateOfflineStatus();
|
ctrl.updateOfflineStatus();
|
||||||
|
|||||||
@@ -220,27 +220,6 @@ angular.module('app')
|
|||||||
Shared Callbacks
|
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) {
|
$scope.safeApply = function(fn) {
|
||||||
var phase = this.$root.$$phase;
|
var phase = this.$root.$$phase;
|
||||||
if(phase == '$apply' || phase == '$digest')
|
if(phase == '$apply' || phase == '$digest')
|
||||||
|
|||||||
@@ -6,6 +6,6 @@
|
|||||||
|
|
||||||
%notes-section{"add-new" => "notesAddNew", "selection-made" => "notesSelectionMade", "tag" => "selectedTag"}
|
%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"}
|
%footer{"ng-if" => "!needsUnlock"}
|
||||||
|
|||||||
Reference in New Issue
Block a user