2017-09-23 22:18:08 +08:00
|
|
|
let globalHistoryItems = null;
|
|
|
|
|
2017-10-03 11:38:05 +08:00
|
|
|
function showNoteHistoryDialog(noteId, noteHistoryId) {
|
2017-09-22 10:20:10 +08:00
|
|
|
$("#noteHistoryDialog").dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 800,
|
|
|
|
height: 700
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#noteHistoryList").empty();
|
|
|
|
$("#noteHistoryContent").empty();
|
|
|
|
|
|
|
|
$.ajax({
|
2017-10-03 11:38:05 +08:00
|
|
|
url: baseApiUrl + 'notes-history/' + noteId,
|
2017-09-22 10:20:10 +08:00
|
|
|
type: 'GET',
|
|
|
|
success: function (result) {
|
2017-09-23 22:18:08 +08:00
|
|
|
globalHistoryItems = result;
|
|
|
|
|
|
|
|
for (const row of result) {
|
2017-10-01 10:35:13 +08:00
|
|
|
const dateModified = getDateFromTS(row.date_modified);
|
2017-09-23 22:18:08 +08:00
|
|
|
|
|
|
|
$("#noteHistoryList").append($('<option>', {
|
|
|
|
value: row.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) {
|
|
|
|
noteHistoryId = $("#noteHistoryList option:first").val();
|
|
|
|
}
|
2017-09-22 10:20:10 +08:00
|
|
|
|
2017-10-03 11:38:05 +08:00
|
|
|
$("#noteHistoryList").val(noteHistoryId).trigger('change');
|
2017-09-22 10:20:10 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error: () => alert("Error getting note history.")
|
|
|
|
});
|
2017-10-03 11:38:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).bind('keydown', 'alt+h', function() {
|
|
|
|
showNoteHistoryDialog(globalCurrentNote.detail.note_id);
|
2017-09-23 22:18:08 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#noteHistoryList").on('change', () => {
|
|
|
|
const optVal = $("#noteHistoryList").find(":selected").val();
|
|
|
|
const historyItem = globalHistoryItems.find(r => r.id == optVal); // non-strict comparison is important here!!!s
|
|
|
|
|
|
|
|
$("#noteHistoryTitle").html(historyItem.note_title);
|
|
|
|
$("#noteHistoryContent").html(historyItem.note_text);
|
2017-09-22 10:20:10 +08:00
|
|
|
});
|