some fixes in note moving

This commit is contained in:
azivner 2017-11-28 15:17:11 -05:00
parent 0cab4e3edd
commit 4d95eb0762
2 changed files with 35 additions and 24 deletions

View File

@ -344,17 +344,17 @@ const noteTree = (function() {
const beforeNode = node.getPrevSibling(); const beforeNode = node.getPrevSibling();
if (beforeNode !== null) { if (beforeNode !== null) {
treeChanges.moveBeforeNode(node, beforeNode); treeChanges.moveBeforeNode(node, beforeNode, false);
} }
}, },
"shift+down": node => { "shift+down": node => {
let afterNode = node.getNextSibling(); let afterNode = node.getNextSibling();
if (afterNode !== null) { if (afterNode !== null) {
treeChanges.moveAfterNode(node, afterNode); treeChanges.moveAfterNode(node, afterNode, false);
} }
}, },
"shift+left": node => { "shift+left": node => {
treeChanges.moveNodeUp(node); treeChanges.moveNodeUpInHierarchy(node);
}, },
"shift+right": node => { "shift+right": node => {
let toNode = node.getPrevSibling(); let toNode = node.getPrevSibling();

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
const treeChanges = (function() { const treeChanges = (function() {
async function moveBeforeNode(node, beforeNode) { async function moveBeforeNode(node, beforeNode, changeInPath = true) {
await $.ajax({ await $.ajax({
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveBefore/' + beforeNode.data.note_tree_id, url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveBefore/' + beforeNode.data.note_tree_id,
type: 'PUT', type: 'PUT',
@ -10,10 +10,14 @@ const treeChanges = (function() {
node.moveTo(beforeNode, 'before'); node.moveTo(beforeNode, 'before');
if (changeInPath) {
recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
}
noteTree.setCurrentNotePathToHash(node); noteTree.setCurrentNotePathToHash(node);
} }
async function moveAfterNode(node, afterNode) { async function moveAfterNode(node, afterNode, changeInPath = true) {
await $.ajax({ await $.ajax({
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + afterNode.data.note_tree_id, url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + afterNode.data.note_tree_id,
type: 'PUT', type: 'PUT',
@ -22,6 +26,10 @@ const treeChanges = (function() {
node.moveTo(afterNode, 'after'); node.moveTo(afterNode, 'after');
if (changeInPath) {
recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
}
noteTree.setCurrentNotePathToHash(node); noteTree.setCurrentNotePathToHash(node);
} }
@ -55,6 +63,8 @@ const treeChanges = (function() {
toNode.folder = true; toNode.folder = true;
toNode.renderTitle(); toNode.renderTitle();
recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
noteTree.setCurrentNotePathToHash(node); noteTree.setCurrentNotePathToHash(node);
} }
@ -88,7 +98,7 @@ const treeChanges = (function() {
node.getParent().renderTitle(); node.getParent().renderTitle();
} }
recentNotes.removeRecentNote(node.note_tree_id); recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
let next = node.getNextSibling(); let next = node.getNextSibling();
if (!next) { if (!next) {
@ -103,13 +113,17 @@ const treeChanges = (function() {
noteTree.setCurrentNotePathToHash(next); noteTree.setCurrentNotePathToHash(next);
} }
async function moveNodeUp(node) { async function moveNodeUpInHierarchy(node) {
if (node.getParent() !== null) { if (node.getParent() === null) {
$.ajax({ return;
}
await $.ajax({
url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + node.getParent().data.note_tree_id, url: baseApiUrl + 'notes/' + node.data.note_tree_id + '/moveAfter/' + node.getParent().data.note_tree_id,
type: 'PUT', type: 'PUT',
contentType: "application/json", contentType: "application/json",
success: () => { });
if (node.getParent() !== null && node.getParent().getChildren().length <= 1) { if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
node.getParent().folder = false; node.getParent().folder = false;
node.getParent().renderTitle(); node.getParent().renderTitle();
@ -119,16 +133,13 @@ const treeChanges = (function() {
noteTree.setCurrentNotePathToHash(node); noteTree.setCurrentNotePathToHash(node);
} }
});
}
}
return { return {
moveBeforeNode, moveBeforeNode,
moveAfterNode, moveAfterNode,
moveToNode, moveToNode,
deleteNode, deleteNode,
moveNodeUp, moveNodeUpInHierarchy,
cloneNoteAfter, cloneNoteAfter,
cloneNoteTo cloneNoteTo
}; };