model manager refactor
This commit is contained in:
@@ -63,12 +63,12 @@ angular.module('app.frontend')
|
||||
}
|
||||
}
|
||||
})
|
||||
.controller('EditorCtrl', function ($sce, $timeout, apiController, modelManager, markdownRenderer, $rootScope) {
|
||||
.controller('EditorCtrl', function ($sce, $timeout, apiController, markdownRenderer, $rootScope) {
|
||||
|
||||
this.setNote = function(note, oldNote) {
|
||||
this.editorMode = 'edit';
|
||||
|
||||
if(note.content.text.length == 0 && note.dummy) {
|
||||
if(note.safeText().length == 0 && note.dummy) {
|
||||
this.focusTitle(100);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ angular.module('app.frontend')
|
||||
}
|
||||
|
||||
this.renderedContent = function() {
|
||||
return markdownRenderer.renderHtml(markdownRenderer.renderedContentForText(this.note.content.text));
|
||||
return markdownRenderer.renderHtml(markdownRenderer.renderedContentForText(this.note.safeText()));
|
||||
}
|
||||
|
||||
var statusTimeout;
|
||||
@@ -207,7 +207,7 @@ angular.module('app.frontend')
|
||||
|
||||
var original = this.note.presentation_name;
|
||||
this.note.presentation_name = this.url.token;
|
||||
modelManager.addDirtyItems([this.note]);
|
||||
this.note.dirty = true;
|
||||
|
||||
apiController.sync(function(response){
|
||||
if(!response) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -110,8 +110,8 @@ angular.module('app.frontend')
|
||||
|
||||
this.createNewNote = function() {
|
||||
var title = "New Note" + (this.tag.notes ? (" " + (this.tag.notes.length + 1)) : "");
|
||||
this.newNote = new Note({dummy: true});
|
||||
this.newNote.content.title = title;
|
||||
this.newNote = new Note({dummy: true, text: ""});
|
||||
this.newNote.title = title;
|
||||
this.selectNote(this.newNote);
|
||||
this.addNew()(this.newNote);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ angular.module('app.frontend')
|
||||
if(this.noteFilter.text.length == 0) {
|
||||
note.visible = true;
|
||||
} else {
|
||||
note.visible = note.content.title.toLowerCase().includes(this.noteFilter.text) || note.content.text.toLowerCase().includes(this.noteFilter.text);
|
||||
note.visible = note.title.toLowerCase().includes(this.noteFilter.text) || note.text.toLowerCase().includes(this.noteFilter.text);
|
||||
}
|
||||
return note.visible;
|
||||
}.bind(this)
|
||||
|
||||
@@ -62,8 +62,8 @@ angular.module('app.frontend')
|
||||
if(this.editingTag) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.newTag = new Tag();
|
||||
|
||||
this.newTag = new Tag({});
|
||||
this.selectedTag = this.newTag;
|
||||
this.editingTag = this.newTag;
|
||||
this.addNew()(this.newTag);
|
||||
@@ -71,7 +71,7 @@ angular.module('app.frontend')
|
||||
|
||||
var originalTagName = "";
|
||||
this.onTagTitleFocus = function(tag) {
|
||||
originalTagName = tag.content.title;
|
||||
originalTagName = tag.title;
|
||||
}
|
||||
|
||||
this.tagTitleDidChange = function(tag) {
|
||||
@@ -80,14 +80,14 @@ angular.module('app.frontend')
|
||||
|
||||
this.saveTag = function($event, tag) {
|
||||
this.editingTag = null;
|
||||
if(tag.content.title.length == 0) {
|
||||
tag.content.title = originalTagName;
|
||||
if(tag.title.length == 0) {
|
||||
tag.title = originalTagName;
|
||||
originalTagName = "";
|
||||
return;
|
||||
}
|
||||
|
||||
$event.target.blur();
|
||||
if(!tag.content.title || tag.content.title.length == 0) {
|
||||
if(!tag.title || tag.title.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user