model manager refactor
This commit is contained in:
@@ -5,7 +5,7 @@ angular.module('app.frontend')
|
||||
var onUserSet = function() {
|
||||
apiController.setUser($scope.defaultUser);
|
||||
$scope.allTag = new Tag({all: true});
|
||||
$scope.allTag.content.title = "All";
|
||||
$scope.allTag.title = "All";
|
||||
$scope.tags = modelManager.tags;
|
||||
$scope.allTag.notes = modelManager.notes;
|
||||
|
||||
@@ -43,14 +43,18 @@ angular.module('app.frontend')
|
||||
|
||||
$scope.tagsSelectionMade = function(tag) {
|
||||
$scope.selectedTag = tag;
|
||||
|
||||
if($scope.selectedNote && $scope.selectedNote.dummy) {
|
||||
modelManager.removeItemLocally($scope.selectedNote);
|
||||
}
|
||||
}
|
||||
|
||||
$scope.tagsAddNew = function(tag) {
|
||||
modelManager.addTag(tag);
|
||||
modelManager.addItem(tag);
|
||||
}
|
||||
|
||||
$scope.tagsSave = function(tag, callback) {
|
||||
modelManager.addDirtyItems([tag]);
|
||||
tag.dirty = true;
|
||||
apiController.sync(callback);
|
||||
}
|
||||
|
||||
@@ -62,7 +66,7 @@ angular.module('app.frontend')
|
||||
|
||||
var originalNote = _.find(modelManager.notes, {uuid: noteCopy.uuid});
|
||||
if(!newTag.all) {
|
||||
modelManager.addTagToNote(newTag, originalNote);
|
||||
modelManager.createRelationshipBetweenItems(newTag, originalNote);
|
||||
}
|
||||
|
||||
apiController.sync(function(){});
|
||||
@@ -75,9 +79,9 @@ angular.module('app.frontend')
|
||||
$scope.notesRemoveTag = function(tag) {
|
||||
var validNotes = Note.filterDummyNotes(tag.notes);
|
||||
if(validNotes == 0) {
|
||||
modelManager.deleteTag(tag);
|
||||
modelManager.setItemToBeDeleted(tag);
|
||||
// if no more notes, delete tag
|
||||
apiController.deleteItem(tag, function(){
|
||||
apiController.sync(function(){
|
||||
// force scope tags to update on sub directives
|
||||
$scope.tags = [];
|
||||
$timeout(function(){
|
||||
@@ -94,10 +98,10 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
$scope.notesAddNew = function(note) {
|
||||
modelManager.addNote(note);
|
||||
modelManager.addItem(note);
|
||||
|
||||
if(!$scope.selectedTag.all) {
|
||||
modelManager.addTagToNote($scope.selectedTag, note);
|
||||
modelManager.createRelationshipBetweenItems($scope.selectedTag, note);
|
||||
$scope.updateAllTag();
|
||||
}
|
||||
}
|
||||
@@ -107,7 +111,7 @@ angular.module('app.frontend')
|
||||
*/
|
||||
|
||||
$scope.saveNote = function(note, callback) {
|
||||
modelManager.addDirtyItems(note);
|
||||
note.dirty = true;
|
||||
|
||||
apiController.sync(function(){
|
||||
note.hasChanges = false;
|
||||
@@ -120,17 +124,18 @@ angular.module('app.frontend')
|
||||
|
||||
$scope.deleteNote = function(note) {
|
||||
|
||||
modelManager.deleteNote(note);
|
||||
modelManager.setItemToBeDeleted(note);
|
||||
|
||||
if(note == $scope.selectedNote) {
|
||||
$scope.selectedNote = null;
|
||||
}
|
||||
|
||||
if(note.dummy) {
|
||||
modelManager.removeItemLocally(note);
|
||||
return;
|
||||
}
|
||||
|
||||
apiController.deleteItem(note, function(success){})
|
||||
apiController.sync(null);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user