[Rt-commit] rt branch, 4.4/all-recipients-call-ajax-once, created. rt-4.4.3-44-g365d374f7

? sunnavy sunnavy at bestpractical.com
Mon Sep 17 13:20:10 EDT 2018


The branch, 4.4/all-recipients-call-ajax-once has been created
        at  365d374f781aa71d096a2f2ca6f7c53b0e944ce2 (commit)

- Log -----------------------------------------------------------------
commit 365d374f781aa71d096a2f2ca6f7c53b0e944ce2
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Sep 18 00:28:56 2018 +0800

    Trigger UpdateCc/UpdateBcc input change only once when clicking "All recipients"
    
    Clicking "All recipients" will check/uncheck all the suggested Cc/Bcc
    address checkboxes, and each address checkbox change will trigger the
    UpdateCc/UpdateBcc input change accordingly.
    
    It's not just unnecessary to trigger UpdateCc/UpdateBcc input change
    multiple times for a single click, but also harmful: each change will
    fire an ajax call to update page sections "Recipients" and "Scrips and
    Recipients", so if there are multiple ajax calls happening at nearly the
    same time, as ajax responses could easily come back in different order,
    this could make data in sections "Recipients" and "Scrips and
    Recipients" out of date.

diff --git a/share/html/Ticket/Elements/UpdateCc b/share/html/Ticket/Elements/UpdateCc
index 9f988f718..5d6423079 100644
--- a/share/html/Ticket/Elements/UpdateCc
+++ b/share/html/Ticket/Elements/UpdateCc
@@ -59,7 +59,7 @@
         <div class="OneTimeCcs hidden">
 %   }
 <i class="label">(<&|/l&>check to add</&>)</i>
-<input type="checkbox" class="checkbox" id="AllSuggestedCc" name="AllSuggestedCc" value="1" onclick="setCheckbox(this, /^UpdateCc-/, null, true)">
+<input type="checkbox" class="checkbox" id="AllSuggestedCc" name="AllSuggestedCc" value="1" onclick="setCheckbox(this, /^UpdateCc-/); checkboxesToInput('UpdateCc', 'input[name^=UpdateCc-]:checkbox');">
 <label for="AllSuggestedCc"><% loc('All recipients') %></label>
 %}
 %foreach my $addr ( @one_time_Ccs ) {
@@ -71,6 +71,7 @@
     type="checkbox"
 % my $clean_addr = $txn_addresses{$addr}->format;
     onClick="checkboxToInput('UpdateCc', <% "UpdateCc-$addr" |n,j%>, <%$clean_addr|n,j%> );"
+    data-address="<% $clean_addr %>"
     <% $ARGS{'UpdateCc-'.$addr} ? 'checked="checked"' : ''%> >
       <label for="UpdateCc-<%$addr%>"><& /Elements/ShowUser, Address => $txn_addresses{$addr}&></label>
 </span>
@@ -88,7 +89,7 @@
         <div class="OneTimeCcs hidden">
 %   }
 <i class="label">(<&|/l&>check to add</&>)</i>
-<input type="checkbox" class="checkbox" id="AllSuggestedBcc" name="AllSuggestedBcc" value="1" onclick="setCheckbox(this, /^UpdateBcc-/, null, true)">
+<input type="checkbox" class="checkbox" id="AllSuggestedBcc" name="AllSuggestedBcc" value="1" onclick="setCheckbox(this, /^UpdateBcc-/); checkboxesToInput('UpdateBcc', 'input[name^=UpdateBcc-]:checkbox');">
 <label for="AllSuggestedBcc"><% loc('All recipients') %></label>
 %}
 %foreach my $addr ( @one_time_Ccs ) {
@@ -100,6 +101,7 @@
     type="checkbox"
 % my $clean_addr = $txn_addresses{$addr}->format;
     onClick="checkboxToInput('UpdateBcc', <% "UpdateBcc-$addr" |n,j%>, <%$clean_addr|n,j%> );"
+    data-address="<% $clean_addr %>"
     <% $ARGS{'UpdateBcc-'.$addr} ? 'checked="checked"' : ''%> >
       <label for="UpdateBcc-<%$addr%>"><& /Elements/ShowUser, Address => $txn_addresses{$addr}&></label>
 </span>
diff --git a/share/static/js/util.js b/share/static/js/util.js
index d5bf84562..ef8888d43 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -216,6 +216,29 @@ function checkboxToInput(target,checkbox,val){
     tar.change();
 }
 
+function checkboxesToInput(target,checkboxes) {
+    var tar = jQuery('#' + escapeCssSelector(target));
+
+    jQuery(checkboxes).each(function(index, checkbox) {
+        var val = jQuery(checkbox).attr('data-address');
+        if(jQuery(checkbox).prop('checked')){
+            if (tar.val()==''){
+                tar.val(val);
+            }
+            else{
+                tar.val(val+', '+ tar.val());
+            }
+        }
+        else{
+            tar.val(tar.val().replace(val+', ',''));
+            tar.val(tar.val().replace(val,''));
+        }
+    });
+
+    jQuery('#UpdateIgnoreAddressCheckboxes').val(true);
+    tar.change();
+}
+
 // ahah for back compatibility as plugins may still use it
 function ahah( url, id ) {
     jQuery('#'+id).load(url);

-----------------------------------------------------------------------


More information about the rt-commit mailing list