Skip to content

Commit

Permalink
No need to update recipients/scrips if the form data doesn't actually…
Browse files Browse the repository at this point in the history
… change

It's possible that we trigger "change" event even if the input value
doesn't actually change. E.g. dragging a recipient and dropping it to its
original position triggers "change" event. When things like that happen,
recipients/scrips are the same, so it's safe to not fetch them again.
  • Loading branch information
sunnavy committed Dec 12, 2024
1 parent 0cf78c2 commit e9a4848
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,7 @@ function checkRefreshState(elt) {
}

let _ticket_preparing_recipients = 0;
let _ticket_update_recipients_data;
function ticketUpdateRecipients(evt) {
if ( evt && evt.type === 'htmx:load' ) {
if ( document.querySelector('.htmx-indicator') ) {
Expand Down Expand Up @@ -1853,14 +1854,17 @@ function ticketUpdateRecipients(evt) {
}
_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();
if ( JSON.stringify(payload) === _ticket_update_recipients_data ) {
return;
}
_ticket_update_recipients_data = JSON.stringify(payload);
jQuery('.ticket-info-recipients div.titlebox-content').addClass('refreshing');

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

let _ticket_preparing_scrips = 0;
let _ticket_update_scrips_data;
function ticketUpdateScrips(evt) {
if ( evt && evt.type === 'htmx:load' ) {
if ( document.querySelector('.htmx-indicator') ) {
Expand Down Expand Up @@ -1916,14 +1921,18 @@ function ticketUpdateScrips(evt) {
}
_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();
if ( JSON.stringify(payload) === _ticket_update_scrips_data ) {
return;
}
_ticket_update_scrips_data = JSON.stringify(payload);
jQuery('.ticket-info-preview-scrips div.titlebox-content').addClass('refreshing');

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

0 comments on commit e9a4848

Please sign in to comment.