[Rt-commit] rt branch, 4.2/scrips-correspond-selectall-checkbox, updated. rt-4.2.6-20-ga4e3f01
Wallace Reis
wreis at bestpractical.com
Mon Jul 21 09:04:17 EDT 2014
The branch, 4.2/scrips-correspond-selectall-checkbox has been updated
via a4e3f014ad2674723b4073b5af86a9a012cd2673 (commit)
from e162beeae689b63fb9f5d0d81429c5c06c172ef8 (commit)
Summary of changes:
share/html/Ticket/Elements/PreviewScrips | 2 +-
.../html/Ticket/Elements/ShowSimplifiedRecipients | 2 +-
share/static/js/util.js | 41 ++++++++++++++++++++--
3 files changed, 40 insertions(+), 5 deletions(-)
- Log -----------------------------------------------------------------
commit a4e3f014ad2674723b4073b5af86a9a012cd2673
Author: Wallace Reis <wreis at bestpractical.com>
Date: Mon Jul 21 10:01:11 2014 -0300
Make 'select all' check/uncheck bi-directional
If I uncheck "All $thing", and then I re-check all of the items by hand,
then "All $thing" pops back to being checked as soon as I re-checked
the last item.
diff --git a/share/html/Ticket/Elements/PreviewScrips b/share/html/Ticket/Elements/PreviewScrips
index 51293ca..665269d 100644
--- a/share/html/Ticket/Elements/PreviewScrips
+++ b/share/html/Ticket/Elements/PreviewScrips
@@ -88,7 +88,7 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
% my $checked = not $squelched{$addr->address};
% $m->callback(CallbackName => 'BeforeAddress', Ticket => $TicketObj, Address => $addr, Type => $type, Checked => \$checked);
% $recips{$addr->address}++;
- <b><%loc($type)%></b>: <input type="checkbox" class="checkbox" name="TxnSendMailTo" <% $checked ? 'checked="checked"' : '' |n%> value="<%$addr->address%>" id="TxnSendMailTo-<% $addr->address %>-<% $recips{$addr->address} %>" />
+ <b><%loc($type)%></b>: <input type="checkbox" class="checkbox" name="TxnSendMailTo" <% $checked ? 'checked="checked"' : '' |n%> value="<%$addr->address%>" id="TxnSendMailTo-<% $addr->address %>-<% $recips{$addr->address} %>" onclick="checkboxSetEvent(this,'TxnSendMailTo','TxnSendMailToAll')"/>
<label for="TxnSendMailTo-<% $addr->address %>-<% $recips{$addr->address} %>"><& /Elements/ShowUser, Address => $addr &></label>
% $m->callback(CallbackName => 'AfterAddress', Ticket => $TicketObj, Address => $addr, Type => $type);
</li>
diff --git a/share/html/Ticket/Elements/ShowSimplifiedRecipients b/share/html/Ticket/Elements/ShowSimplifiedRecipients
index cd82cbc..9cb7643 100644
--- a/share/html/Ticket/Elements/ShowSimplifiedRecipients
+++ b/share/html/Ticket/Elements/ShowSimplifiedRecipients
@@ -94,7 +94,7 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
% my $checked = not $squelched{$addr->address};
% $m->callback(CallbackName => 'BeforeAddress', Ticket => $TicketObj, Address => $addr, Type => $type, Checked => \$checked);
% $recips{$addr->address}++;
-<input type="checkbox" class="checkbox" name="TxnSendMailTo" <% $checked ? 'checked="checked"' : '' |n%> value="<%$addr->address%>" id="TxnSendMailTo-<% $addr->address %>-<% $recips{$addr->address} %>" />
+<input type="checkbox" class="checkbox" name="TxnSendMailTo" <% $checked ? 'checked="checked"' : '' |n%> value="<%$addr->address%>" id="TxnSendMailTo-<% $addr->address %>-<% $recips{$addr->address} %>" onclick="checkboxSetEvent(this,'TxnSendMailTo','TxnSendMailToAll')" />
<label for="TxnSendMailTo-<% $addr->address %>-<% $recips{$addr->address} %>"><& /Elements/ShowUser, Address => $addr &></label>
% $m->callback(CallbackName => 'AfterAddress', Ticket => $TicketObj, Address => $addr, Type => $type);
<br />
diff --git a/share/static/js/util.js b/share/static/js/util.js
index b665c0e..3aa12b6 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -80,12 +80,16 @@ function set_rollup_state(e,e2,state) {
/* other utils */
+function getClosestInputElements(input) {
+ // Find inputs within the current form or collection list, whichever is closest.
+ var container = jQuery(input).closest("form, table.collection-as-table").get(0);
+ return container.getElementsByTagName('input');
+}
+
function setCheckbox(input, name, val) {
if (val == null) val = input.checked;
- // Find inputs within the current form or collection list, whichever is closest.
- var container = jQuery(input).closest("form, table.collection-as-table").get(0);
- var myfield = container.getElementsByTagName('input');
+ var myfield = getClosestInputElements(input);
for ( var i = 0; i < myfield.length; i++ ) {
if ( myfield[i].type != 'checkbox' ) continue;
if ( name ) {
@@ -102,6 +106,37 @@ function setCheckbox(input, name, val) {
}
}
+function checkboxSetEvent(input, name, allname) {
+ var myfield = getClosestInputElements(input);
+ var checked_count = 0;
+ var field_count = 0;
+ for ( var i = 0; i < myfield.length; i++ ) {
+ if ( myfield[i].type != 'checkbox' ) continue;
+ if ( name ) {
+ if ( name instanceof RegExp ) {
+ if ( ! myfield[i].name.match( name ) ) continue;
+ }
+ else {
+ if ( myfield[i].name != name ) continue;
+ }
+
+ }
+
+ field_count++;
+ if ( myfield[i].checked ) {
+ checked_count++;
+ }
+ }
+
+ var allfield = jQuery('input[name=' + allname + ']');
+ if (field_count == checked_count) {
+ allfield.prop('checked', true);
+ }
+ else {
+ allfield.prop('checked', false);
+ }
+}
+
/* apply callback to nodes or elements */
function walkChildNodes(parent, callback)
-----------------------------------------------------------------------
More information about the rt-commit
mailing list