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-15 12:01:23 +08:00
|
|
|
function getParentProtectedStatus(node) {
|
2017-12-24 01:19:15 +08:00
|
|
|
return isTopLevelNode(node) ? 0 : node.getParent().data.is_protected;
|
2017-11-05 10:18:36 +08:00
|
|
|
}
|
2017-09-10 00:06:15 +08:00
|
|
|
|
2017-11-19 06:05:50 +08:00
|
|
|
function getNodeByKey(key) {
|
|
|
|
return treeEl.fancytree('getNodeByKey', key);
|
2017-10-02 11:07:32 +08:00
|
|
|
}
|
|
|
|
|
2017-11-20 01:06:48 +08:00
|
|
|
function getNoteIdFromNotePath(notePath) {
|
|
|
|
const path = notePath.split("/");
|
2017-10-02 11:07:32 +08:00
|
|
|
|
2017-11-20 01:06:48 +08:00
|
|
|
return path[path.length - 1];
|
|
|
|
}
|
2017-09-19 08:48:02 +08:00
|
|
|
|
2017-11-19 21:47:22 +08:00
|
|
|
function getNotePath(node) {
|
|
|
|
const path = [];
|
|
|
|
|
2017-12-24 01:19:15 +08:00
|
|
|
while (node && !isRootNode(node)) {
|
2017-11-20 00:28:46 +08:00
|
|
|
if (node.data.note_id) {
|
|
|
|
path.push(node.data.note_id);
|
2017-11-19 21:47:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
node = node.getParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return path.reverse().join("/");
|
|
|
|
}
|
|
|
|
|
2017-11-28 23:17:30 +08:00
|
|
|
function setNodeTitleWithPrefix(node) {
|
|
|
|
const noteTitle = noteTree.getNoteTitle(node.data.note_id);
|
|
|
|
const prefix = node.data.prefix;
|
|
|
|
|
|
|
|
const title = (prefix ? (prefix + " - ") : "") + noteTitle;
|
|
|
|
|
2017-12-29 08:00:31 +08:00
|
|
|
node.setTitle(escapeHtml(title));
|
2017-11-28 23:17:30 +08:00
|
|
|
}
|
|
|
|
|
2017-11-05 10:18:36 +08:00
|
|
|
return {
|
2017-11-15 12:01:23 +08:00
|
|
|
getParentProtectedStatus,
|
2017-11-05 10:18:36 +08:00
|
|
|
getNodeByKey,
|
2017-11-20 01:06:48 +08:00
|
|
|
getNotePath,
|
2017-11-28 23:17:30 +08:00
|
|
|
getNoteIdFromNotePath,
|
|
|
|
setNodeTitleWithPrefix
|
2017-11-05 10:18:36 +08:00
|
|
|
};
|
|
|
|
})();
|