2017-11-05 07:38:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
const treeUtils = (function() {
|
|
|
|
const treeEl = $("#tree");
|
2017-11-05 07:28:49 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
function getParentKey(node) {
|
|
|
|
return (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key;
|
|
|
|
}
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
function getParentEncryption(node) {
|
|
|
|
return node.getParent() === null ? 0 : node.getParent().data.encryption;
|
|
|
|
}
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
function getNodeByKey(noteId) {
|
|
|
|
return treeEl.fancytree('getNodeByKey', noteId);
|
2017-10-02 11:07:32 +08:00
|
|
|
}
|
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
function activateNode(noteId) {
|
|
|
|
const node = treeUtils.getNodeByKey(noteId);
|
2017-10-02 11:07:32 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
node.setActive();
|
2017-10-02 11:07:32 +08:00
|
|
|
}
|
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
function getNoteTitle(noteId) {
|
|
|
|
const note = treeUtils.getNodeByKey(noteId);
|
|
|
|
if (!note) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-02 11:07:32 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
let noteTitle = note.title;
|
2017-09-19 08:48:02 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
if (noteTitle.endsWith(" (clone)")) {
|
|
|
|
noteTitle = noteTitle.substr(0, noteTitle.length - 8);
|
|
|
|
}
|
2017-10-12 07:41:45 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
return noteTitle;
|
2017-09-19 08:48:02 +08:00
|
|
|
}
|
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
function getFullName(noteId) {
|
|
|
|
let note = treeUtils.getNodeByKey(noteId);
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
if (note === null) {
|
|
|
|
return "[unknown]";
|
2017-11-04 23:32:05 +08:00
|
|
|
}
|
2017-11-05 10:18:36 +08:00
|
|
|
|
|
|
|
// why?
|
|
|
|
if (note.data.is_clone) {
|
|
|
|
return null;
|
2017-11-04 23:32:05 +08:00
|
|
|
}
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
const path = [];
|
|
|
|
|
|
|
|
while (note) {
|
|
|
|
if (note.data.encryption > 0 && !encryption.isEncryptionAvailable()) {
|
|
|
|
path.push("[encrypted]");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
path.push(note.title);
|
|
|
|
}
|
|
|
|
|
|
|
|
note = note.getParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove "root" element
|
|
|
|
path.pop();
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
return path.reverse().join(" > ");
|
|
|
|
}
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
return {
|
|
|
|
getParentKey,
|
|
|
|
getParentEncryption,
|
|
|
|
getNodeByKey,
|
|
|
|
activateNode,
|
|
|
|
getNoteTitle,
|
|
|
|
getFullName
|
|
|
|
};
|
|
|
|
})();
|