From 33b3a5b32d1dbd5090fd771d08296cd52c0c8b3e Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 30 Jul 2020 21:27:51 +0530 Subject: [PATCH] feat: add mark as read function --- .../frappe/ui/notifications/notifications.js | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/frappe/public/js/frappe/ui/notifications/notifications.js b/frappe/public/js/frappe/ui/notifications/notifications.js index 75680304d0..2dfc1c396a 100644 --- a/frappe/public/js/frappe/ui/notifications/notifications.js +++ b/frappe/public/js/frappe/ui/notifications/notifications.js @@ -273,6 +273,15 @@ class NotificationsView extends BaseNotificaitonsView { }); } + mark_as_read(docname, $el) { + frappe.call( + 'frappe.desk.doctype.notification_log.notification_log.mark_as_read', + { docname: docname } + ).then(() => { + $el.removeClass('unread'); + }); + } + insert_into_dropdown() { let new_item = this.dropdown_items[0]; let new_item_html = this.get_dropdown_item_html(new_item); @@ -301,7 +310,7 @@ class NotificationsView extends BaseNotificaitonsView { let user_avatar = frappe.avatar(user, 'avatar-medium user-avatar'); let item_html = - ` @@ -311,41 +320,46 @@ class NotificationsView extends BaseNotificaitonsView {
-
`; + `); + + item_html.find('.mark-as-read').on('click', (e) => { + e.stopImmediatePropagation(); + if (!field.read) { + this.mark_as_read(field.name, item_html); + } + }); + + item_html.on('click', (e) => { + if (!field.read) { + this.mark_as_read(field.name, item_html); + } + }); return item_html; } render_notifications_dropdown() { - let body_html = ''; - let view_full_log_html = ''; - let dropdown_html; - if (this.notifications_settings && !this.notifications_settings.enabled) { - dropdown_html = `
  • + this.container.html(`
  • ${__('Notifications Disabled')} -
  • `; + `); } else { if (this.dropdown_items.length) { this.dropdown_items.forEach(field => { - let item_html = this.get_dropdown_item_html(field); - if (item_html) body_html += item_html; + this.container.append(this.get_dropdown_item_html(field)); }); - view_full_log_html = `
    ${__('See all Activity')}
    -
    `; + `); } else { - body_html += `
  • + this.container.append($(`
  • ${__('No activity')} -
  • `; + `)); } - dropdown_html = body_html + view_full_log_html; } - - this.container.html(dropdown_html); } get_notifications_list(limit) {