diff --git a/src/templates/app.html b/src/templates/app.html
index e6b08826a..9f3262775 100644
--- a/src/templates/app.html
+++ b/src/templates/app.html
@@ -97,7 +97,7 @@
-
+
diff --git a/static/js/init.js b/static/js/init.js
index ae521b1ab..75348797e 100644
--- a/static/js/init.js
+++ b/static/js/init.js
@@ -29,7 +29,8 @@ $(document).bind('keydown', 'alt+h', function() {
$(document).bind('keydown', 'alt+q', function() {
$("#recentNotesDialog").dialog({
- modal: true
+ modal: true,
+ width: 500
});
let recentNotesSelectBox = $('#recentNotesSelectBox');
@@ -40,7 +41,7 @@ $(document).bind('keydown', 'alt+q', function() {
let recNotes = recentNotes.filter(note => note !== globalNote.detail.note_id);
$.each(recNotes, function(key, valueNoteId) {
- let noteTitle = globalNoteNames[valueNoteId];
+ let noteTitle = getFullName(valueNoteId);
if (!noteTitle) {
return;
@@ -62,7 +63,7 @@ $(document).bind('keydown', 'alt+q', function() {
function setActiveNoteBasedOnRecentNotes() {
let noteId = $("#recentNotesSelectBox option:selected").val();
- $("#tree").fancytree('getNodeByKey', noteId).setActive();
+ getNodeByKey(noteId).setActive();
$("#recentNotesDialog").dialog('close');
}
@@ -90,12 +91,22 @@ $(document).on('click', 'div.popover-content a', function(e) {
if (noteIdMatch !== null) {
const noteId = noteIdMatch[1];
- $("#tree").fancytree('getNodeByKey', noteId).setActive();
+ getNodeByKey(noteId).setActive();
e.preventDefault();
}
});
+function getNodeIdFromLabel(label) {
+ const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(label);
+
+ if (noteIdMatch !== null) {
+ return noteIdMatch[1];
+ }
+
+ return null;
+}
+
$(document).bind('keydown', 'alt+l', function() {
var range = $('#noteDetail').summernote('createRange');
console.log("range:", range);
@@ -107,43 +118,52 @@ $(document).bind('keydown', 'alt+l', function() {
noteDetail.summernote('editor.saveRange');
$("#insertLinkDialog").dialog({
- modal: true
+ modal: true,
+ width: 500
});
let autocompleteItems = [];
for (let noteId in globalNoteNames) {
+ let fullName = getFullName(noteId);
+
autocompleteItems.push({
- value: globalNoteNames[noteId] + " (" + noteId + ")",
- label: globalNoteNames[noteId]
+ value: fullName + " (" + noteId + ")",
+ label: fullName
});
}
+ function setDefaultLinkTitle() {
+ const val = $("#noteAutocomplete").val();
+ const noteId = getNodeIdFromLabel(val);
+
+ if (noteId) {
+ const note = getNodeByKey(noteId);
+ let noteTitle = note.title;
+
+ if (noteTitle.endsWith(" (clone)")) {
+ noteTitle = noteTitle.substr(0, noteTitle.length - 8);
+ }
+
+ $("#linkTitle").val(noteTitle);
+ }
+ }
+
$("#noteAutocomplete").autocomplete({
source: autocompleteItems,
minLength: 0,
- change: function() {
- let val = $("#noteAutocomplete").val();
-
- val = val.replace(/ \([A-Za-z0-9]{22}\)/, "");
-
- $("#linkTitle").val(val);
- },
- focus: function(event, ui) {
- $("#linkTitle").val(ui.item.label);
- }
+ change: setDefaultLinkTitle,
+ focus: setDefaultLinkTitle
});
});
$("#insertLinkForm").submit(function addLink() {
let val = $("#noteAutocomplete").val();
- const noteIdMatch = / \(([A-Za-z0-9]{22})\)/.exec(val);
+ const noteId = getNodeIdFromLabel(val);
- if (noteIdMatch !== null) {
- const noteId = noteIdMatch[1];
+ if (noteId) {
const linkTitle = $("#linkTitle").val();
-
const noteDetail = $('#noteDetail');
$("#insertLinkDialog").dialog("close");
diff --git a/static/js/note.js b/static/js/note.js
index 0db981077..c9b2d3551 100644
--- a/static/js/note.js
+++ b/static/js/note.js
@@ -38,7 +38,7 @@ function saveNoteIfChanged(callback) {
let title = $('#noteTitle').val();
- $("#tree").fancytree('getNodeByKey', note.detail.note_id).setTitle(title);
+ getNodeByKey(note.detail.note_id).setTitle(title);
note.detail.note_title = title;
diff --git a/static/js/tree.js b/static/js/tree.js
index 2019f6921..98dac160f 100644
--- a/static/js/tree.js
+++ b/static/js/tree.js
@@ -104,6 +104,28 @@ const keybindings = {
const globalNoteNames = {};
+let globalTree;
+
+function getNodeByKey(noteId) {
+ return globalTree.fancytree('getNodeByKey', noteId);
+}
+
+function getFullName(noteId) {
+ let note = getNodeByKey(noteId);
+ const path = [];
+
+ while (note) {
+ path.push(note.title);
+
+ note = note.getParent();
+ }
+
+ // remove "root" element
+ path.pop();
+
+ return path.reverse().join(" > ");
+}
+
$(function(){
$.get(baseUrl + 'tree').then(resp => {
const notes = resp.notes;
@@ -145,7 +167,8 @@ $(function(){
});
}
- $("#tree").fancytree({
+ globalTree = $("#tree");
+ globalTree.fancytree({
autoScroll: true,
extensions: ["hotkeys", "filter"],
source: notes,