diff --git a/frappe/public/js/frappe/ui/notifications/notifications.js b/frappe/public/js/frappe/ui/notifications/notifications.js index ffe0eb1ae9..d662419180 100644 --- a/frappe/public/js/frappe/ui/notifications/notifications.js +++ b/frappe/public/js/frappe/ui/notifications/notifications.js @@ -53,8 +53,8 @@ frappe.ui.Notifications = class Notifications { this.categories = [ { label: __("Notifications"), id: "notifications", view: NotificationsView }, - { label: __("Today's Events"), id: "todays_events", view: NotificationsView }, - { label: __("Open Documents"), id: "open_documents", view: NotificationsView } + { label: __("Today's Events"), id: "todays_events", view: EventsView }, + { label: __("Open Documents"), id: "open_documents", view: OpenDocsView } ]; let get_headers_html = (item) => { @@ -89,12 +89,17 @@ frappe.ui.Notifications = class Notifications { }); item.dom.addClass("active"); this.current_tab && this.current_tab.hide(); - this.tabs[item.id] ? this.tabs[item.id].show() : this.make_tab_view(item); + if (this.tabs[item.id]) { + this.tabs[item.id].show() + this.current_tab = this.tabs[item.id] + } else { + this.make_tab_view(item); + } } make_tab_view(item) { let tabView = new item.view({ - container: this.body, + wrapper: this.body, max_length: this.max_length }); this.tabs[item.id] = tabView; @@ -129,40 +134,6 @@ frappe.ui.Notifications = class Notifications { // ------------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------------ - - render_todays_events(e, $target) { - let hide = $target.next().hasClass('in'); - if (!hide) { - let today = frappe.datetime.get_today(); - frappe.xcall('frappe.desk.doctype.event.event.get_events', { - start: today, - end: today - }).then(event_list => { - this.render_events_html(event_list); - }); - } - } - - render_events_html(event_list) { - let html = ''; - if (event_list.length) { - let get_event_html = event => { - let time = frappe.datetime.get_time(event.starts_on); - return ` - ${time} - ${event.subject} - `; - }; - html = event_list.map(get_event_html).join(''); - } else { - html = `
  • - ${__('No Events Today')} -
  • `; - } - - this.$today_events.html(html); - } - get_open_document_config(e) { this.open_docs_config = { ToDo: { label: __('To Do') }, @@ -366,17 +337,6 @@ frappe.ui.Notifications = class Notifications { } }); } - - toggle_collapse_indicator($el) { - $el - .prev() - .find('.collapse-indicator') - .toggleClass('octicon-chevron-down'); - $el - .prev() - .find('.collapse-indicator') - .toggleClass('octicon-chevron-up'); - } }; @@ -410,19 +370,29 @@ frappe.ui.notifications = { } }; -class NotificationsView { +class BaseNotificaitonsView { constructor(opts) { // wrapper, max_length Object.assign(this, opts) + this.container = $(`
    `).appendTo(this.wrapper); this.make(); } show() { - console.log("show") + this.container.show() } hide() { - console.log("hide") + this.container.hide() + } +} + +class NotificationsView extends BaseNotificaitonsView { + make() { + this.get_notifications_list(this.max_length).then(list => { + this.dropdown_items = list; + this.render_notifications_dropdown(); + }); } get_dropdown_item_html(field) { @@ -447,7 +417,7 @@ class NotificationsView { let user_avatar = frappe.avatar(user, 'avatar-medium user-avatar'); let item_html = - ` + dropdown_html = `
  • ${__('Notifications Disabled')}
  • `; @@ -491,13 +461,6 @@ class NotificationsView { this.container.html(dropdown_html); } - make() { - this.get_notifications_list(this.max_length).then(list => { - this.dropdown_items = list; - this.render_notifications_dropdown(); - }); - } - get_notifications_list(limit) { return frappe.db.get_list('Notification Log', { fields: ['*'], @@ -517,3 +480,59 @@ class NotificationsView { ); } } + +class EventsView extends BaseNotificaitonsView { + make() { + let today = frappe.datetime.get_today(); + frappe.xcall('frappe.desk.doctype.event.event.get_events', { + start: today, + end: today + }).then(event_list => { + console.log(event_list); + this.render_events_html(event_list); + }); + } + + render_events_html(event_list) { + let html = ''; + if (event_list.length) { + let get_event_html = (event) => { + let time; + if (event.all_day) { + time = __("All Day") + } else { + let start_time = frappe.datetime.get_time(event.starts_on); + let days_diff = frappe.datetime.get_day_diff(event.ends_on, event.starts_on) + let end_time; + if (days_diff > 1) { + end_time = __("Rest of the Day"); + } else { + end_time = frappe.datetime.get_time(event.ends_on); + } + + time = `${start_time} - ${end_time}` + } + return `
    +
    +
    +
    ${event.subject}
    +
    ${time}
    +
    +
    `; + }; + html = event_list.map(get_event_html).join(''); + } else { + html = `
  • + ${__('No Events Today')} +
  • `; + } + + this.container.html(html); + } +} + +class OpenDocsView extends BaseNotificaitonsView { + make() { + console.log("docs hello"); + } +} \ No newline at end of file