From fd48a97c6dd7549a22597e65948233ab4fa528b1 Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 4 Nov 2017 14:02:43 -0400 Subject: [PATCH] converted event log to module --- public/javascripts/event_log.js | 68 ++++++++++++++++++--------------- views/index.ejs | 2 +- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/public/javascripts/event_log.js b/public/javascripts/event_log.js index 8e8882114..bbc7ac8b8 100644 --- a/public/javascripts/event_log.js +++ b/public/javascripts/event_log.js @@ -1,41 +1,47 @@ -async function showEventLog() { - $("#event-log-dialog").dialog({ - modal: true, - width: 800, - height: 700 - }); +const eventLog = (function() { + const dialogEl = $("#event-log-dialog"); + const listEl = $("#event-log-list"); - const result = await $.ajax({ - url: baseApiUrl + 'event-log', - type: 'GET', - error: () => error("Error getting event log.") - }); + async function showDialog() { + dialogEl.dialog({ + modal: true, + width: 800, + height: 700 + }); - const eventLogList = $("#event-log-list"); - eventLogList.html(''); + const result = await $.ajax({ + url: baseApiUrl + 'event-log', + type: 'GET', + error: () => error("Error getting event log.") + }); - for (const event of result) { - const dateTime = formatDateTime(getDateFromTS(event.date_added)); + listEl.html(''); - if (event.note_id) { - const noteLink = $("", { - href: 'app#' + event.note_id, - text: getFullName(event.note_id) - }).prop('outerHTML'); + for (const event of result) { + const dateTime = formatDateTime(getDateFromTS(event.date_added)); - console.log(noteLink); + if (event.note_id) { + const noteLink = $("", { + href: 'app#' + event.note_id, + text: getFullName(event.note_id) + }).prop('outerHTML'); - event.comment = event.comment.replace('', noteLink); + event.comment = event.comment.replace('', noteLink); + } + + const eventEl = $('
  • ').html(dateTime + " - " + event.comment); + + listEl.append(eventEl); } - - const eventEl = $('
  • ').html(dateTime + " - " + event.comment); - - eventLogList.append(eventEl); } -} -$(document).on('click', '#event-log-dialog a', e => { - goToInternalNote(e, () => { - $("#event-log-dialog").dialog('close'); + $(document).on('click', '#event-log-dialog a', e => { + goToInternalNote(e, () => { + dialogEl.dialog('close'); + }); }); -}); \ No newline at end of file + + return { + showDialog + }; +})(); \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 241719ef7..74257a8d5 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -15,7 +15,7 @@ - +