@@ -72,36 +72,16 @@ builder.add('widgets','widgetNotifications', class extends builder.ComponentClas
7272
7373 // Create a footer
7474 this . _component . menu . footer = $ ( document . createElement ( 'div' ) ) . attr ( {
75- 'class' : 'footer px-3 py-2 border-top d-flex gap-2 align-items-center' ,
75+ 'class' : 'footer px-3 py-2 border-top d-flex align-items-center justify-content -center' ,
7676 } ) . appendTo ( this . _component . menu ) ;
77- this . _component . menu . footer . switch = $ ( document . createElement ( 'div' ) ) . attr ( {
78- 'class' : 'form-check form-switch mb-0' ,
79- } ) . appendTo ( this . _component . menu . footer ) ;
80- this . _component . menu . footer . switch . input = $ ( document . createElement ( 'input' ) ) . attr ( {
81- 'class' : 'form-check-input' ,
82- 'type' : 'checkbox' ,
83- 'id' : 'toggleHideLow' + this . _id ,
84- } ) . appendTo ( this . _component . menu . footer . switch ) . on ( 'change' , function ( ) {
85- self . _priority = this . checked ? self . _properties . priority : - 1 ;
86- localStorage . setItem (
87- 'notificationsMenuHideLowPriority' ,
88- this . checked ? '1' : '0'
89- ) ;
90- self . count ( ) ;
77+ this . _component . menu . footer . link = $ ( document . createElement ( 'button' ) ) . attr ( {
78+ 'type' : 'button' ,
79+ 'class' : 'btn btn-link btn-sm link-primary text-decoration-none' ,
80+ } ) . html ( '<i class="bi bi-trash me-2"></i>' + self . _builder . Locale . get ( 'Dismiss all' ) ) . appendTo ( this . _component . menu . footer ) . click ( function ( ) {
81+ for ( const [ key , notification ] of Object . entries ( self . _notifications ) ) {
82+ self . dismiss ( notification ) ;
83+ }
9184 } ) ;
92- if ( localStorage . getItem ( 'notificationsMenuHideLowPriority' ) === '1' ) {
93- this . _component . menu . footer . switch . input . prop ( 'checked' , true ) ;
94- this . _priority = this . _properties . priority ;
95- }
96- this . _component . menu . footer . switch . label = $ ( document . createElement ( 'label' ) ) . attr ( {
97- 'for' : 'toggleHideLow' + this . _id ,
98- 'class' : 'form-check-label small' ,
99- } ) . appendTo ( this . _component . menu . footer . switch ) ;
100- this . _component . menu . footer . switch . label . text ( self . _builder . Locale . get ( 'Hide low priority' ) ) ;
101- this . _component . menu . footer . link = $ ( document . createElement ( 'a' ) ) . attr ( {
102- 'href' : '/plugin/notifications' ,
103- 'class' : 'btn btn-link btn-sm link-primary text-decoration-none ms-auto' ,
104- } ) . html ( '<i class="bi bi-list-ul me-2"></i>' + self . _builder . Locale . get ( 'View all' ) ) . appendTo ( this . _component . menu . footer ) ;
10585
10686 // Check if autoStart is enabled
10787 if ( self . _properties . autoStart ) {
@@ -130,7 +110,7 @@ builder.add('widgets','widgetNotifications', class extends builder.ComponentClas
130110 API . endpoint ( '/notifications/fetchAll' ) . data ( {
131111 conditions : [
132112 { key : 'assignedTo' , operator : '=' , value : USER_ID } ,
133- { key : 'isDissmissed ' , operator : '<>' , value : 1 } ,
113+ { key : 'isDismissed ' , operator : '<>' , value : 1 } ,
134114 ] ,
135115 } ) . execute ( function ( response ) {
136116 for ( const [ key , record ] of Object . entries ( response . records ) ) {
@@ -220,9 +200,16 @@ builder.add('widgets','widgetNotifications', class extends builder.ComponentClas
220200 this . _component . menu . list . empty ( ) ;
221201
222202 // Append the sorted notifications to the list
223- notifications . forEach ( notification => {
224- notification . appendTo ( self . _component . menu . list ) . off ( 'click' ) . click ( function ( ) {
225- self . _builder . Widget ( 'notification' , { data : notification . data . id } ) . view ( ) ;
203+ notifications . forEach ( element => {
204+ const notification = this . _notifications [ element . attr ( 'data-notification-id' ) ] ;
205+ notification . appendTo ( self . _component . menu . list ) . off ( ) . hover ( function ( ) {
206+ notification . _hoverTimeout = setTimeout ( function ( ) {
207+ self . dismiss ( notification ) ;
208+ } , 2000 ) ;
209+ } , function ( ) {
210+ clearTimeout ( notification . _hoverTimeout ) ;
211+ } ) . click ( function ( ) {
212+ window . open ( notification . data . link ) ;
226213 } ) ;
227214 } ) ;
228215
@@ -389,4 +376,11 @@ builder.add('widgets','widgetNotifications', class extends builder.ComponentClas
389376 }
390377 return initials ;
391378 }
379+
380+ dismiss ( notification ) {
381+ const self = this ;
382+ API . endpoint ( '/notifications/dismiss' ) . data ( { notificationId : notification . data . id } ) . execute ( function ( response ) {
383+ self . delete ( notification . data . id ) ;
384+ } ) ;
385+ }
392386} ) ;
0 commit comments