trilium/static/js/tree_mutations.js

85 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-09-10 00:34:20 +08:00
function moveBeforeNode(node, beforeNode) {
$.ajax({
2017-09-30 22:05:12 +08:00
url: baseApiUrl + 'notes/' + node.key + '/moveBefore/' + beforeNode.key,
2017-09-10 00:34:20 +08:00
type: 'PUT',
contentType: "application/json",
success: function () {
node.moveTo(beforeNode, 'before');
}
});
}
function moveAfterNode(node, afterNode) {
$.ajax({
2017-09-30 22:05:12 +08:00
url: baseApiUrl + 'notes/' + node.key + '/moveAfter/' + afterNode.key,
2017-09-10 00:34:20 +08:00
type: 'PUT',
contentType: "application/json",
success: function () {
node.moveTo(afterNode, 'after');
}
});
}
function moveToNode(node, toNode) {
$.ajax({
2017-09-30 22:05:12 +08:00
url: baseApiUrl + 'notes/' + node.key + '/moveTo/' + toNode.key,
2017-09-10 00:34:20 +08:00
type: 'PUT',
contentType: "application/json",
success: function () {
node.moveTo(toNode);
toNode.setExpanded(true);
toNode.folder = true;
toNode.renderTitle();
}
});
}
function deleteNode(node) {
if (confirm('Are you sure you want to delete note "' + node.title + '"?')) {
$.ajax({
2017-09-30 22:05:12 +08:00
url: baseApiUrl + 'notes/' + node.key,
2017-09-10 00:34:20 +08:00
type: 'DELETE',
success: function () {
if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
node.getParent().folder = false;
node.getParent().renderTitle();
}
globalAllNoteIds = globalAllNoteIds.filter(e => e !== node.key);
// remove from recent notes
globalRecentNotes = globalRecentNotes.filter(note => note !== node.key);
let next = node.getNextSibling();
if (!next) {
next = node.getParent();
}
node.remove();
// activate next element after this one is deleted so we don't lose focus
next.setActive();
}
});
}
}
function moveNodeUp(node) {
if (node.getParent() !== null) {
$.ajax({
2017-09-30 22:05:12 +08:00
url: baseApiUrl + 'notes/' + node.key + '/moveAfter/' + node.getParent().key,
2017-09-10 00:34:20 +08:00
type: 'PUT',
contentType: "application/json",
success: function () {
if (node.getParent() !== null && node.getParent().getChildren().length <= 1) {
node.getParent().folder = false;
node.getParent().renderTitle();
}
node.moveTo(node.getParent(), 'after');
}
});
}
}