2017-08-24 08:09:28 +08:00
|
|
|
const keybindings = {
|
|
|
|
"insert": function(node) {
|
2017-09-05 01:27:54 +08:00
|
|
|
const parentKey = getParentKey(node);
|
2017-09-09 10:43:02 +08:00
|
|
|
const encryption = getParentEncryption(node);
|
2017-08-24 08:09:28 +08:00
|
|
|
|
2017-09-09 10:43:02 +08:00
|
|
|
createNote(node, parentKey, 'after', encryption);
|
2017-08-24 08:09:28 +08:00
|
|
|
},
|
|
|
|
"ctrl+insert": function(node) {
|
2017-09-09 10:43:02 +08:00
|
|
|
createNote(node, node.key, 'into', node.data.encryption);
|
2017-08-24 08:09:28 +08:00
|
|
|
},
|
|
|
|
"del": function(node) {
|
2017-09-05 01:22:24 +08:00
|
|
|
deleteNode(node);
|
2017-08-24 08:09:28 +08:00
|
|
|
},
|
|
|
|
"shift+up": function(node) {
|
2017-09-05 00:02:34 +08:00
|
|
|
const beforeNode = node.getPrevSibling();
|
|
|
|
|
|
|
|
if (beforeNode !== null) {
|
|
|
|
moveBeforeNode(node, beforeNode);
|
2017-08-24 08:09:28 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"shift+down": function(node) {
|
2017-09-05 00:02:34 +08:00
|
|
|
let afterNode = node.getNextSibling();
|
|
|
|
if (afterNode !== null) {
|
|
|
|
moveAfterNode(node, afterNode);
|
2017-08-24 08:09:28 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"shift+left": function(node) {
|
2017-09-10 00:06:15 +08:00
|
|
|
moveNodeUp(node);
|
2017-08-24 08:09:28 +08:00
|
|
|
},
|
|
|
|
"shift+right": function(node) {
|
2017-09-05 00:02:34 +08:00
|
|
|
let toNode = node.getPrevSibling();
|
2017-08-24 08:09:28 +08:00
|
|
|
|
2017-09-05 00:02:34 +08:00
|
|
|
if (toNode !== null) {
|
|
|
|
moveToNode(node, toNode);
|
2017-08-24 08:09:28 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"return": function(node) {
|
|
|
|
// doesn't work :-/
|
|
|
|
$('#noteDetail').summernote('focus');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-04 06:50:56 +08:00
|
|
|
let globalAllNoteIds = [];
|
2017-08-24 08:09:28 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
const globalTree = $("#tree");
|
2017-09-04 03:08:17 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
let globalClipboardNoteId = null;
|
2017-09-04 03:08:17 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
function prepareNoteTree(notes) {
|
|
|
|
for (const note of notes) {
|
|
|
|
globalAllNoteIds.push(note.note_id);
|
2017-09-04 03:08:17 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
if (note.encryption > 0) {
|
|
|
|
note.title = "[encrypted]";
|
2017-09-04 03:08:17 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
note.extraClasses = "encrypted";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
note.title = note.note_title;
|
|
|
|
|
|
|
|
if (note.is_clone) {
|
|
|
|
note.title += " (clone)";
|
|
|
|
}
|
|
|
|
}
|
2017-09-04 03:08:17 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
note.key = note.note_id;
|
|
|
|
note.expanded = note.is_expanded;
|
2017-09-04 03:08:17 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
if (note.children && note.children.length > 0) {
|
|
|
|
prepareNoteTree(note.children);
|
|
|
|
}
|
|
|
|
}
|
2017-09-04 03:08:17 +08:00
|
|
|
}
|
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
function setExpandedToServer(note_id, is_expanded) {
|
|
|
|
expanded_num = is_expanded ? 1 : 0;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: baseUrl + 'notes/' + note_id + '/expanded/' + expanded_num,
|
|
|
|
type: 'PUT',
|
|
|
|
contentType: "application/json",
|
|
|
|
success: function(result) {}
|
|
|
|
});
|
|
|
|
}
|
2017-09-05 01:22:24 +08:00
|
|
|
|
2017-06-12 04:04:07 +08:00
|
|
|
$(function(){
|
2017-08-23 09:23:10 +08:00
|
|
|
$.get(baseUrl + 'tree').then(resp => {
|
|
|
|
const notes = resp.notes;
|
2017-08-23 09:32:03 +08:00
|
|
|
let startNoteId = resp.start_note_id;
|
|
|
|
|
|
|
|
if (document.location.hash) {
|
|
|
|
startNoteId = document.location.hash.substr(1); // strip initial #
|
|
|
|
}
|
2017-08-23 09:23:10 +08:00
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
prepareNoteTree(notes);
|
2017-09-09 11:14:42 +08:00
|
|
|
|
2017-09-04 03:08:17 +08:00
|
|
|
globalTree.fancytree({
|
2017-08-23 09:23:10 +08:00
|
|
|
autoScroll: true,
|
2017-09-05 00:02:34 +08:00
|
|
|
extensions: ["hotkeys", "filter", "dnd"],
|
2017-06-12 04:04:07 +08:00
|
|
|
source: notes,
|
|
|
|
activate: function(event, data){
|
2017-08-16 09:29:12 +08:00
|
|
|
const node = data.node.data;
|
2017-06-12 04:04:07 +08:00
|
|
|
|
2017-08-24 09:43:02 +08:00
|
|
|
saveNoteIfChanged(() => loadNote(node.note_id));
|
2017-06-12 04:04:07 +08:00
|
|
|
},
|
|
|
|
expand: function(event, data) {
|
2017-09-10 00:06:15 +08:00
|
|
|
setExpandedToServer(data.node.key, true);
|
2017-06-12 04:04:07 +08:00
|
|
|
},
|
|
|
|
collapse: function(event, data) {
|
2017-09-10 00:06:15 +08:00
|
|
|
setExpandedToServer(data.node.key, false);
|
2017-06-12 04:04:07 +08:00
|
|
|
},
|
2017-08-23 09:23:10 +08:00
|
|
|
init: function(event, data) {
|
|
|
|
if (startNoteId) {
|
|
|
|
data.tree.activateKey(startNoteId);
|
|
|
|
}
|
2017-09-06 11:48:41 +08:00
|
|
|
|
|
|
|
$(window).resize();
|
2017-08-23 09:23:10 +08:00
|
|
|
},
|
2017-06-12 04:04:07 +08:00
|
|
|
hotkeys: {
|
2017-08-24 08:09:28 +08:00
|
|
|
keydown: keybindings
|
2017-08-29 11:10:04 +08:00
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
autoApply: true, // Re-apply last filter if lazy data is loaded
|
|
|
|
autoExpand: true, // Expand all branches that contain matches while filtered
|
|
|
|
counter: false, // Show a badge with number of matching child nodes near parent icons
|
|
|
|
fuzzy: false, // Match single characters in order, e.g. 'fb' will match 'FooBar'
|
|
|
|
hideExpandedCounter: true, // Hide counter badge if parent is expanded
|
|
|
|
hideExpanders: false, // Hide expanders if all child nodes are hidden by filter
|
|
|
|
highlight: true, // Highlight matches by wrapping inside <mark> tags
|
|
|
|
leavesOnly: false, // Match end nodes only
|
|
|
|
nodata: true, // Display a 'no data' status node if result is empty
|
|
|
|
mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
|
2017-09-05 00:02:34 +08:00
|
|
|
},
|
2017-09-10 00:06:15 +08:00
|
|
|
dnd: dragAndDropSetup
|
2017-09-05 01:22:24 +08:00
|
|
|
});
|
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
globalTree.contextmenu(contextMenuSetup);
|
2017-06-12 04:04:07 +08:00
|
|
|
});
|
2017-08-29 11:10:04 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$("input[name=search]").keyup(function (e) {
|
2017-08-30 10:58:44 +08:00
|
|
|
const searchString = $(this).val();
|
2017-08-29 11:10:04 +08:00
|
|
|
|
2017-08-30 10:58:44 +08:00
|
|
|
if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchString) === "") {
|
2017-08-29 11:10:04 +08:00
|
|
|
$("button#btnResetSearch").click();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-30 10:58:44 +08:00
|
|
|
if (e && e.which === $.ui.keyCode.ENTER) {
|
|
|
|
$.get(baseUrl + 'notes?search=' + searchString).then(resp => {
|
|
|
|
console.log("search: ", resp);
|
|
|
|
|
|
|
|
// Pass a string to perform case insensitive matching
|
2017-09-07 09:34:54 +08:00
|
|
|
const tree = globalTree.fancytree("getTree");
|
2017-08-30 10:58:44 +08:00
|
|
|
tree.filterBranches(function(node) {
|
|
|
|
return resp.includes(node.data.note_id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-08-29 11:10:04 +08:00
|
|
|
}).focus();
|
|
|
|
|
|
|
|
$("button#btnResetSearch").click(function () {
|
|
|
|
$("input[name=search]").val("");
|
|
|
|
|
2017-09-07 09:34:54 +08:00
|
|
|
const tree = globalTree.fancytree("getTree");
|
2017-08-29 11:10:04 +08:00
|
|
|
tree.clearFilter();
|
2017-08-30 08:58:53 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
function collapseTree() {
|
2017-09-07 09:34:54 +08:00
|
|
|
globalTree.fancytree("getRootNode").visit(function(node){
|
2017-08-30 08:58:53 +08:00
|
|
|
node.setExpanded(false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).bind('keydown', 'alt+c', collapseTree);
|