trilium/public/javascripts/note_history.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

let globalHistoryItems = null;
2017-10-09 23:28:56 +08:00
function showCurrentNoteHistory() {
showNoteHistoryDialog(globalCurrentNote.detail.note_id);
}
function showNoteHistoryDialog(noteId, noteHistoryId) {
$("#note-history-dialog").dialog({
2017-09-22 10:20:10 +08:00
modal: true,
width: 800,
height: 700
});
$("#note-history-list").empty();
$("#note-history-content").empty();
2017-09-22 10:20:10 +08:00
$.ajax({
url: baseApiUrl + 'notes-history/' + noteId,
2017-09-22 10:20:10 +08:00
type: 'GET',
success: result => {
globalHistoryItems = result;
for (const row of result) {
const dateModified = getDateFromTS(row.date_modified);
$("#note-history-list").append($('<option>', {
value: row.id,
2017-09-27 11:23:03 +08:00
text: formatDateTime(dateModified)
}));
2017-09-22 10:20:10 +08:00
}
if (result.length > 0) {
if (!noteHistoryId) {
noteHistoryId = $("#note-history-list option:first").val();
}
2017-09-22 10:20:10 +08:00
$("#note-history-list").val(noteHistoryId).trigger('change');
2017-09-22 10:20:10 +08:00
}
},
error: () => alert("Error getting note history.")
});
}
2017-10-09 23:28:56 +08:00
$(document).bind('keydown', 'alt+h', showCurrentNoteHistory);
$("#note-history-list").on('change', () => {
const optVal = $("#note-history-list").find(":selected").val();
const historyItem = globalHistoryItems.find(r => r.id == optVal); // non-strict comparison is important here!!!
$("#note-history-title").html(historyItem.note_title);
$("#note-history-content").html(historyItem.note_text);
2017-09-22 10:20:10 +08:00
});