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