2017-11-05 07:38:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
const noteHistory = (function() {
|
|
|
|
const dialogEl = $("#note-history-dialog");
|
|
|
|
const listEl = $("#note-history-list");
|
|
|
|
const contentEl = $("#note-history-content");
|
|
|
|
const titleEl = $("#note-history-title");
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
let historyItems = [];
|
2017-10-09 23:28:56 +08:00
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
async function showCurrentNoteHistory() {
|
2017-11-05 05:54:27 +08:00
|
|
|
await showNoteHistoryDialog(noteEditor.getCurrentNoteId());
|
2017-11-05 01:55:46 +08:00
|
|
|
}
|
|
|
|
|
2018-01-29 08:38:05 +08:00
|
|
|
async function showNoteHistoryDialog(noteId, noteRevisionId) {
|
2017-11-05 05:03:15 +08:00
|
|
|
glob.activeDialog = dialogEl;
|
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
dialogEl.dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 800,
|
|
|
|
height: 700
|
|
|
|
});
|
2017-09-22 10:20:10 +08:00
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
listEl.empty();
|
|
|
|
contentEl.empty();
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2017-11-29 09:52:38 +08:00
|
|
|
historyItems = await server.get('notes-history/' + noteId);
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
for (const item of historyItems) {
|
2018-01-29 08:30:14 +08:00
|
|
|
const dateModified = parseDate(item.dateModifiedFrom);
|
2017-09-22 10:20:10 +08:00
|
|
|
|
2017-12-27 08:54:43 +08:00
|
|
|
listEl.append($('<option>', {
|
2018-01-29 08:38:05 +08:00
|
|
|
value: item.noteRevisionId,
|
2017-11-05 01:55:46 +08:00
|
|
|
text: formatDateTime(dateModified)
|
|
|
|
}));
|
|
|
|
}
|
2017-09-22 10:20:10 +08:00
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
if (historyItems.length > 0) {
|
2018-01-29 08:38:05 +08:00
|
|
|
if (!noteRevisionId) {
|
|
|
|
noteRevisionId = listEl.find("option:first").val();
|
2017-09-22 10:20:10 +08:00
|
|
|
}
|
2017-10-03 11:38:05 +08:00
|
|
|
|
2018-01-29 08:38:05 +08:00
|
|
|
listEl.val(noteRevisionId).trigger('change');
|
2017-11-05 01:55:46 +08:00
|
|
|
}
|
2017-12-27 08:54:43 +08:00
|
|
|
else {
|
|
|
|
titleEl.text("No history for this note yet...");
|
|
|
|
}
|
2017-11-05 01:55:46 +08:00
|
|
|
}
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2017-12-19 12:44:20 +08:00
|
|
|
$(document).bind('keydown', 'alt+h', e => {
|
|
|
|
showCurrentNoteHistory();
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
2017-10-25 08:00:54 +08:00
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
listEl.on('change', () => {
|
|
|
|
const optVal = listEl.find(":selected").val();
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2018-01-29 08:38:05 +08:00
|
|
|
const historyItem = historyItems.find(r => r.noteRevisionId === optVal);
|
2017-11-03 11:36:58 +08:00
|
|
|
|
2018-01-29 08:30:14 +08:00
|
|
|
titleEl.html(historyItem.title);
|
|
|
|
contentEl.html(historyItem.content);
|
2017-11-05 01:55:46 +08:00
|
|
|
});
|
2017-11-03 11:36:58 +08:00
|
|
|
|
2017-11-05 05:03:15 +08:00
|
|
|
$(document).on('click', "a[action='note-history']", event => {
|
|
|
|
const linkEl = $(event.target);
|
2017-11-22 09:04:06 +08:00
|
|
|
const noteId = linkEl.attr('note-path');
|
2018-01-29 08:38:05 +08:00
|
|
|
const noteRevisionId = linkEl.attr('note-history-id');
|
2017-11-05 05:03:15 +08:00
|
|
|
|
2018-01-29 08:38:05 +08:00
|
|
|
showNoteHistoryDialog(noteId, noteRevisionId);
|
2017-11-05 05:03:15 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2017-11-05 01:55:46 +08:00
|
|
|
return {
|
2017-11-05 05:03:15 +08:00
|
|
|
showCurrentNoteHistory
|
2017-11-05 01:55:46 +08:00
|
|
|
};
|
|
|
|
})();
|