2017-09-10 00:06:15 +08:00
|
|
|
let globalRecentNotes = [];
|
|
|
|
|
|
|
|
function addRecentNote(noteTreeId, noteContentId) {
|
|
|
|
const origDate = new Date();
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
|
|
|
if (noteTreeId === globalCurrentNote.detail.note_id || noteContentId === globalCurrentNote.detail.note_id) {
|
|
|
|
// if it's already there, remove the note
|
|
|
|
globalRecentNotes = globalRecentNotes.filter(note => note !== noteTreeId);
|
|
|
|
|
|
|
|
globalRecentNotes.unshift(noteTreeId);
|
|
|
|
}
|
|
|
|
}, 1500);
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).bind('keydown', 'alt+q', function() {
|
2017-10-02 11:07:32 +08:00
|
|
|
$('#noteDetail').summernote('editor.saveRange');
|
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
$("#recentNotesDialog").dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 500
|
|
|
|
});
|
|
|
|
|
|
|
|
let recentNotesSelectBox = $('#recentNotesSelectBox');
|
|
|
|
|
|
|
|
recentNotesSelectBox.find('option').remove();
|
|
|
|
|
|
|
|
// remove the current note
|
|
|
|
let recNotes = globalRecentNotes.filter(note => note !== globalCurrentNote.detail.note_id);
|
|
|
|
|
|
|
|
$.each(recNotes, function(key, valueNoteId) {
|
|
|
|
let noteTitle = getFullName(valueNoteId);
|
|
|
|
|
|
|
|
if (!noteTitle) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let option = $("<option></option>")
|
|
|
|
.attr("value", valueNoteId)
|
|
|
|
.text(noteTitle);
|
|
|
|
|
|
|
|
// select the first one (most recent one) by default
|
|
|
|
if (key === 0) {
|
|
|
|
option.attr("selected", "selected");
|
|
|
|
}
|
|
|
|
|
|
|
|
recentNotesSelectBox.append(option);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-02 11:07:32 +08:00
|
|
|
function getSelectedNoteIdFromRecentNotes() {
|
|
|
|
return $("#recentNotesSelectBox option:selected").val();
|
|
|
|
}
|
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
function setActiveNoteBasedOnRecentNotes() {
|
2017-10-02 11:07:32 +08:00
|
|
|
const noteId = getSelectedNoteIdFromRecentNotes();
|
2017-09-10 00:06:15 +08:00
|
|
|
|
|
|
|
getNodeByKey(noteId).setActive();
|
|
|
|
|
|
|
|
$("#recentNotesDialog").dialog('close');
|
|
|
|
}
|
|
|
|
|
2017-10-02 11:07:32 +08:00
|
|
|
function addLinkBasedOnRecentNotes() {
|
|
|
|
const noteId = getSelectedNoteIdFromRecentNotes();
|
|
|
|
|
|
|
|
const linkTitle = getNoteTitle(noteId);
|
|
|
|
const noteDetail = $('#noteDetail');
|
|
|
|
|
|
|
|
$("#recentNotesDialog").dialog("close");
|
|
|
|
|
|
|
|
noteDetail.summernote('editor.restoreRange');
|
|
|
|
|
|
|
|
noteDetail.summernote('createLink', {
|
|
|
|
text: linkTitle,
|
|
|
|
url: 'app#' + noteId,
|
|
|
|
isNewWindow: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-10 00:06:15 +08:00
|
|
|
$('#recentNotesSelectBox').keydown(function(e) {
|
2017-10-02 11:07:32 +08:00
|
|
|
const key = e.which;
|
2017-09-10 00:06:15 +08:00
|
|
|
|
|
|
|
if (key === 13)// the enter key code
|
|
|
|
{
|
|
|
|
setActiveNoteBasedOnRecentNotes();
|
|
|
|
}
|
2017-10-02 11:07:32 +08:00
|
|
|
else if (key === 76 /* l */) {
|
|
|
|
addLinkBasedOnRecentNotes();
|
|
|
|
}
|
|
|
|
|
|
|
|
e.preventDefault();
|
2017-09-10 00:06:15 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#recentNotesSelectBox').dblclick(function(e) {
|
|
|
|
setActiveNoteBasedOnRecentNotes();
|
2017-10-02 11:07:32 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#recentNotesJumpTo').click(setActiveNoteBasedOnRecentNotes);
|
|
|
|
$('#recentNotesAddLink').click(addLinkBasedOnRecentNotes);
|