2017-09-23 22:18:08 +08:00
|
|
|
let globalHistoryItems = null;
|
|
|
|
|
2017-10-09 23:28:56 +08:00
|
|
|
function showCurrentNoteHistory() {
|
|
|
|
showNoteHistoryDialog(globalCurrentNote.detail.note_id);
|
|
|
|
}
|
|
|
|
|
2017-10-03 11:38:05 +08:00
|
|
|
function showNoteHistoryDialog(noteId, noteHistoryId) {
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#note-history-dialog").dialog({
|
2017-09-22 10:20:10 +08:00
|
|
|
modal: true,
|
|
|
|
width: 800,
|
|
|
|
height: 700
|
|
|
|
});
|
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#note-history-list").empty();
|
|
|
|
$("#note-history-content").empty();
|
2017-09-22 10:20:10 +08:00
|
|
|
|
|
|
|
$.ajax({
|
2017-10-03 11:38:05 +08:00
|
|
|
url: baseApiUrl + 'notes-history/' + noteId,
|
2017-09-22 10:20:10 +08:00
|
|
|
type: 'GET',
|
2017-10-10 06:53:11 +08:00
|
|
|
success: result => {
|
2017-09-23 22:18:08 +08:00
|
|
|
globalHistoryItems = result;
|
|
|
|
|
|
|
|
for (const row of result) {
|
2017-10-25 07:36:37 +08:00
|
|
|
const dateModified = getDateFromTS(row.date_modified_to);
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#note-history-list").append($('<option>', {
|
2017-11-03 11:36:58 +08:00
|
|
|
value: row.note_history_id,
|
2017-09-27 11:23:03 +08:00
|
|
|
text: formatDateTime(dateModified)
|
2017-09-23 22:18:08 +08:00
|
|
|
}));
|
2017-09-22 10:20:10 +08:00
|
|
|
}
|
|
|
|
|
2017-09-23 22:18:08 +08:00
|
|
|
if (result.length > 0) {
|
2017-10-03 11:38:05 +08:00
|
|
|
if (!noteHistoryId) {
|
2017-10-11 08:19:16 +08:00
|
|
|
noteHistoryId = $("#note-history-list option:first").val();
|
2017-10-03 11:38:05 +08:00
|
|
|
}
|
2017-09-22 10:20:10 +08:00
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#note-history-list").val(noteHistoryId).trigger('change');
|
2017-09-22 10:20:10 +08:00
|
|
|
}
|
|
|
|
},
|
2017-11-04 10:08:27 +08:00
|
|
|
error: () => error("Error getting note history.")
|
2017-09-22 10:20:10 +08:00
|
|
|
});
|
2017-10-03 11:38:05 +08:00
|
|
|
}
|
|
|
|
|
2017-10-09 23:28:56 +08:00
|
|
|
$(document).bind('keydown', 'alt+h', showCurrentNoteHistory);
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2017-10-11 08:19:16 +08:00
|
|
|
$("#note-history-list").on('change', () => {
|
|
|
|
const optVal = $("#note-history-list").find(":selected").val();
|
2017-10-25 08:00:54 +08:00
|
|
|
|
2017-11-03 11:36:58 +08:00
|
|
|
const historyItem = globalHistoryItems.find(r => r.note_history_id === optVal);
|
2017-09-23 22:18:08 +08:00
|
|
|
|
2017-11-03 11:36:58 +08:00
|
|
|
let noteTitle = historyItem.note_title;
|
|
|
|
let noteText = historyItem.note_text;
|
|
|
|
|
|
|
|
if (historyItem.encryption > 0) {
|
|
|
|
noteTitle = decryptString(noteTitle);
|
|
|
|
noteText = decryptString(noteText);
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#note-history-title").html(noteTitle);
|
|
|
|
$("#note-history-content").html(noteText);
|
2017-09-22 10:20:10 +08:00
|
|
|
});
|