Skip to content

Commit

Permalink
Update recipients/scrips only once for more multiple concurrent changes
Browse files Browse the repository at this point in the history
We already wait 100ms before updating recipients/scrips on ticket update
page, so we can simply make one update for changes happening in the time
period.
  • Loading branch information
sunnavy committed Dec 12, 2024
1 parent 4efa5c4 commit 0cf78c2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,7 @@ function checkRefreshState(elt) {
}
}

let _ticket_preparing_recipients = 0;
function ticketUpdateRecipients(evt) {
if ( evt && evt.type === 'htmx:load' ) {
if ( document.querySelector('.htmx-indicator') ) {
Expand Down Expand Up @@ -1846,12 +1847,19 @@ function ticketUpdateRecipients(evt) {
}).prop("checked", jQuery(target).prop('checked'));
};

// In case there are multiple changes at the same time, we just want to update scrips once if possible
if ( _ticket_preparing_recipients ) {
return;
}
_ticket_preparing_recipients = 1;

jQuery('.ticket-info-recipients div.titlebox-content').addClass('refreshing');

// Wait a little bit in case user leaves related inputs(which
// could fire ticketUpdate...) by checking/unchecking recipient
// checkboxes, this is to get checkboxes' latest status
setTimeout(function() {
_ticket_preparing_recipients = 0;
var payload = jQuery('form[name=TicketUpdate]').serializeArray();

jQuery('.ticket-info-recipients div.titlebox-content div.card-body').load(RT.Config.WebPath + '/Helpers/ShowSimplifiedRecipients',
Expand All @@ -1874,6 +1882,7 @@ function ticketUpdateRecipients(evt) {
}, 100);
}

let _ticket_preparing_scrips = 0;
function ticketUpdateScrips(evt) {
if ( evt && evt.type === 'htmx:load' ) {
if ( document.querySelector('.htmx-indicator') ) {
Expand Down Expand Up @@ -1901,12 +1910,19 @@ function ticketUpdateScrips(evt) {
}).prop("checked", jQuery(target).prop('checked'));
};

// In case there are multiple changes at the same time, we just want to update scrips once if possible
if ( _ticket_preparing_scrips ) {
return;
}
_ticket_preparing_scrips = 1;

jQuery('.ticket-info-preview-scrips div.titlebox-content').addClass('refreshing');

// Wait a little bit in case user leaves related inputs(which
// could fire ticketUpdate...) by checking/unchecking recipient
// checkboxes, this is to get checkboxes' latest status
setTimeout(function() {
_ticket_preparing_scrips = 0;
var payload = jQuery('form[name=TicketUpdate]').serializeArray();

jQuery('.ticket-info-preview-scrips div.titlebox-content div.card-body').load(RT.Config.WebPath + '/Helpers/PreviewScrips',
Expand Down

0 comments on commit 0cf78c2

Please sign in to comment.