@ -1,5 +1,7 @@
const { AppSubUrl , csrf , NotificationSettings } = window . config ;
const { AppSubUrl , csrf , NotificationSettings } = window . config ;
let notificationSequenceNumber = 0 ;
export function initNotificationsTable ( ) {
export function initNotificationsTable ( ) {
$ ( '#notification_table .button' ) . on ( 'click' , async function ( ) {
$ ( '#notification_table .button' ) . on ( 'click' , async function ( ) {
const data = await updateNotification (
const data = await updateNotification (
@ -10,8 +12,10 @@ export function initNotificationsTable() {
$ ( this ) . data ( 'notification-id' ) ,
$ ( this ) . data ( 'notification-id' ) ,
) ;
) ;
if ( $ ( data ) . data ( 'sequence-number' ) === notificationSequenceNumber ) {
$ ( '#notification_div' ) . replaceWith ( data ) ;
$ ( '#notification_div' ) . replaceWith ( data ) ;
initNotificationsTable ( ) ;
initNotificationsTable ( ) ;
}
await updateNotificationCount ( ) ;
await updateNotificationCount ( ) ;
return false ;
return false ;
@ -139,12 +143,15 @@ async function updateNotificationTable() {
url : ` ${ AppSubUrl } /notifications? ${ notificationDiv . data ( 'params' ) } ` ,
url : ` ${ AppSubUrl } /notifications? ${ notificationDiv . data ( 'params' ) } ` ,
data : {
data : {
'div-only' : true ,
'div-only' : true ,
'sequence-number' : ++ notificationSequenceNumber ,
}
}
} ) ;
} ) ;
if ( $ ( data ) . data ( 'sequence-number' ) === notificationSequenceNumber ) {
notificationDiv . replaceWith ( data ) ;
notificationDiv . replaceWith ( data ) ;
initNotificationsTable ( ) ;
initNotificationsTable ( ) ;
}
}
}
}
}
async function updateNotificationCount ( ) {
async function updateNotificationCount ( ) {
const data = await $ . ajax ( {
const data = await $ . ajax ( {
@ -182,6 +189,7 @@ async function updateNotification(url, status, page, q, notificationID) {
page ,
page ,
q ,
q ,
noredirect : true ,
noredirect : true ,
'sequence-number' : ++ notificationSequenceNumber ,
} ,
} ,
} ) ;
} ) ;
}
}