[Rt-commit] rt branch, 4.4/ajax-preview-scrips, created. rt-4.2.5-183-gdf919d2

Alex Vandiver alexmv at bestpractical.com
Mon Jul 21 19:10:54 EDT 2014


The branch, 4.4/ajax-preview-scrips has been created
        at  df919d23ea36c4a87a6e31ab848a79eb8969874b (commit)

- Log -----------------------------------------------------------------
commit 098c568fea06a7138cc8ef8e6e377ce27fbbc72f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jun 24 23:36:16 2014 +0800

    ajaxify PrviewScrips and ShowSimplifiedRecipients on ticket update page
    
    note that it's convenient to automatically update preview scrips when user
    selects autocomplete users, so we need to trigger the change on select.
    
    the css tweak is to make sure simplified recipients are vertical aligned,
    the normal preview scrips part doesn't have this issue.

diff --git a/share/html/Ticket/Elements/PreviewScrips b/share/html/Helpers/PreviewScrips
similarity index 76%
rename from share/html/Ticket/Elements/PreviewScrips
rename to share/html/Helpers/PreviewScrips
index 973fe0d..8cceb89 100644
--- a/share/html/Ticket/Elements/PreviewScrips
+++ b/share/html/Helpers/PreviewScrips
@@ -45,13 +45,24 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<%args>
-$TicketObj => undef
-</%args>
 <%init>
-my $Object = $m->notes("DryRun-".$TicketObj->Id) || $TicketObj->DryRun(%ARGS);
-my %recips = %{ $m->notes("DryRun-Recipients-".$TicketObj->Id) || {} };
-return unless $Object;
+my $TicketObj = RT::Ticket->new($session{CurrentUser});
+$TicketObj->Load($ARGS{id});
+$m->abort unless $TicketObj->id && $ARGS{UpdateType};
+
+$m->abort unless $TicketObj->CurrentUserHasRight('ShowOutgoingEmail');
+if ( $ARGS{UpdateType} eq 'private' ) {
+    $m->abort
+      unless $TicketObj->CurrentUserHasRight( 'CommentOnTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
+}
+else {
+    $m->abort
+      unless $TicketObj->CurrentUserHasRight( 'ReplyToTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
+}
+
+my $Object = $TicketObj->DryRun(%ARGS);
+my %recips;
+$m->abort unless $Object;
 
 my %squelched = ProcessTransactionSquelching( \%ARGS );
 </%init>
@@ -72,7 +83,8 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
           <&|/l, loc($scrip->ConditionObj->Name), loc($scrip->ActionObj->Name), loc($scrip->Template)&>[_1] [_2] with template [_3]</&>
           <br />
 %         for my $type (qw(To Cc Bcc)) {
-%             my @addresses =  $scrip->ActionObj->Action->$type();
+%             my $action = $scrip->ActionObj->Action;
+%             my @addresses =  $action->$type();
 %             next unless @addresses;
               <ul>
 %             for my $addr (@addresses) {
@@ -80,9 +92,26 @@ 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>:
+%                 my $show_checkbox = 1;
+%                 if ( grep {$_ eq $addr} @{$action->{NoSquelch}{$type}} ) {
+%                     $show_checkbox = 0;
+%                 }
+
+%                 if ( $show_checkbox ) {
+                      <input type="checkbox" class="checkbox" name="TxnSendMailTo" <% $checked ? 'checked="checked"' : '' |n%> value="<%$addr->address%>" id="TxnSendMailTo-<% $addr->address %>-<% $recips{$addr->address} %>" />
+%                 }
+
                   <label for="TxnSendMailTo-<% $addr->address %>-<% $recips{$addr->address} %>"><& /Elements/ShowUser, Address => $addr &></label>
 %                 $m->callback(CallbackName => 'AfterAddress', Ticket => $TicketObj, Address => $addr, Type => $type);
+%                 unless ( $show_checkbox ) {
+%                     if ( $type eq 'Cc' ) {
+                          (<&|/l&>explicit one-time Cc</&>)
+%                     }
+%                     else {
+                          (<&|/l&>explicit one-time Bcc</&>)
+%                     }
+%                 }
                   </li>
 %             }
               </ul>
@@ -120,4 +149,5 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
 
 % $m->callback( CallbackName => 'AfterRecipients', TicketObj => $TicketObj );
 
-% $m->notes("DryRun-Recipients-".$TicketObj->Id, \%recips);
+<input type="hidden" name="TxnRecipients" value="<% join ",",sort keys %recips %>" />
+% $m->abort();
\ No newline at end of file
diff --git a/share/html/Ticket/Elements/ShowSimplifiedRecipients b/share/html/Helpers/ShowSimplifiedRecipients
similarity index 71%
rename from share/html/Ticket/Elements/ShowSimplifiedRecipients
rename to share/html/Helpers/ShowSimplifiedRecipients
index bc662b2..26d5ead 100644
--- a/share/html/Ticket/Elements/ShowSimplifiedRecipients
+++ b/share/html/Helpers/ShowSimplifiedRecipients
@@ -45,22 +45,38 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<%args>
-$TicketObj
-</%args>
 <%init>
-return unless RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'});
+$m->abort unless RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'});
 
-my $Object = $m->notes("DryRun-".$TicketObj->Id) || $TicketObj->DryRun(%ARGS);
-$m->notes("DryRun-".$TicketObj->Id, $Object);
-return unless $Object;
+my $TicketObj = RT::Ticket->new($session{CurrentUser});
+$TicketObj->Load($ARGS{id});
+$m->abort unless $TicketObj->id && $ARGS{UpdateType};
+
+if ( $ARGS{UpdateType} eq 'private' ) {
+    $m->abort
+      unless $TicketObj->CurrentUserHasRight( 'CommentOnTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
+}
+else {
+    $m->abort
+      unless $TicketObj->CurrentUserHasRight( 'ReplyToTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
+}
+
+my $Object = $TicketObj->DryRun(%ARGS);
+$m->abort unless $Object;
 
 my %headers = (To => {}, Cc => {}, Bcc => {});
+my %no_squelch = (To => {}, Cc => {}, Bcc => {});
 if ($Object->Scrips) {
     for my $scrip (grep $_->ActionObj->Action->isa('RT::Action::SendEmail'), @{$Object->Scrips->Prepared}) {
+        my $action = $scrip->ActionObj->Action;
         for my $type (qw(To Cc Bcc)) {
-            $headers{$type}{$_->address} = $_
-                for $scrip->ActionObj->Action->$type();
+            for my $addr ($action->$type()) {
+                if (grep {$addr->address eq $_} @{$action->{NoSquelch}{$type} || []}) {
+                    $no_squelch{$type}{$addr->address} = $addr;
+                } else {
+                    $headers{$type}{$addr->address} = $addr;
+                }
+            }
         }
     }
 }
@@ -75,10 +91,9 @@ if ($Object->Rules) {
 my %recips;
 my %squelched = ProcessTransactionSquelching( \%ARGS );
 </%init>
-<&|/Widgets/TitleBox, title => loc('Recipients'), id => 'recipients' &>
 <table>
 % for my $type (qw(To Cc Bcc)) {
-%     next unless keys %{$headers{$type}};
+%     next unless keys %{$headers{$type}} or keys %{$no_squelch{$type}};
 <tr>
 <td valign="top"><% $type %>:</td>
 <td valign="top">
@@ -91,6 +106,15 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
 %         $m->callback(CallbackName => 'AfterAddress', Ticket => $TicketObj, Address => $addr, Type => $type);
 <br />
 %     }
+%     for my $addr (sort {$a->address cmp $b->address} values %{$no_squelch{$type}}) {
+<label><& /Elements/ShowUser, Address => $addr &></label>
+%         if ( $type eq 'Cc' ) {
+(<&|/l&>explicit one-time Cc</&>)
+%         } else {
+(<&|/l&>explicit one-time Bcc</&>)
+%         }
+<br />
+%     }
 </td></tr>
 % }
 % $m->callback( CallbackName => 'AfterRecipients', TicketObj => $TicketObj );
@@ -99,5 +123,8 @@ my %squelched = ProcessTransactionSquelching( \%ARGS );
 <&|/l, RT->Config->Get('WebPath')."/Ticket/ModifyPeople.html?id=".$TicketObj->Id,
 &>Uncheck boxes to disable notifications to the listed recipients <b>for this transaction only</b>; persistent squelching is managed on the <a href="[_1]">People page</a>.</&>
 </p>
-</&>
-% $m->notes("DryRun-Recipients-".$TicketObj->Id, \%recips);
+
+% unless ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
+    <input type="hidden" name="TxnRecipients" value="<% join ",",sort keys %recips %>" />
+% }
+% $m->abort();
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 3e610bc..30ff35f 100644
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -89,11 +89,6 @@
                 .addClass("action-"+ev.target.value);
         });
     });
-    jQuery(function() {
-        jQuery("input[name=TxnSendMailTo]").change(function(ev) {
-            jQuery("input[name=TxnSendMailTo]").filter( function() { return this.value == ev.target.value; } ).prop("checked",jQuery(ev.target).prop('checked'));
-        });
-    });
 </script>
 
 % $m->callback( %ARGS, CallbackName => 'AfterUpdateType' );
@@ -141,7 +136,10 @@
 </div>
 
 <div id="ticket-update-message">
-  <& /Ticket/Elements/ShowSimplifiedRecipients, TicketObj => $TicketObj, %ARGS &>
+% if ( RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'}) ) {
+    <&|/Widgets/TitleBox, title => loc('Recipients'), id => 'recipients' &>
+    </&>
+%}
 
   <&|/Widgets/TitleBox, title => loc('Message'), class => 'messagedetails' &>
   <table width="100%" border="0">
@@ -191,22 +189,38 @@
 
 % if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
   <&|/Widgets/TitleBox, title => loc('Scrips and Recipients'), id => 'previewscrips', rolledup => RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'}) &>
-    <& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>
   </&>
 % }
 </div>
 
 % $m->callback( %ARGS, CallbackName => 'AfterScrips', Ticket => $TicketObj );
 
-% if (my $recips = $m->notes("DryRun-Recipients-".$TicketObj->Id)) {
-<input type="hidden" name="TxnRecipients" value="<% join ",",sort keys %{$recips} %>" />
-% }
-
 </form>
 <hr class="clear" />
 
 % $m->callback( %ARGS, CallbackName => 'AfterForm', Ticket => $TicketObj );
 
+% if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail') or RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'})) {
+<script type="text/javascript">
+jQuery( function() {
+   var updateScrips = function() {
+       var syncCheckboxes = function(ev) {
+           jQuery("input[name=TxnSendMailTo]").filter( function() { return this.value == ev.target.value; } ).prop("checked",jQuery(ev.target).prop('checked'));
+       };
+       jQuery('#recipients div.titlebox-content').load( '<% RT->Config->Get('WebPath')%>/Helpers/ShowSimplifiedRecipients',
+           jQuery('form[name=TicketUpdate]').serialize(),
+           function() { jQuery("#recipients input[name=TxnSendMailTo]").change( syncCheckboxes ); }
+       );
+       jQuery('#previewscrips div.titlebox-content').load( '<% RT->Config->Get('WebPath')%>/Helpers/PreviewScrips',
+           jQuery('form[name=TicketUpdate]').serialize(),
+           function() { jQuery("#previewscrips input[name=TxnSendMailTo]").change( syncCheckboxes ); }
+       );
+   };
+   updateScrips();
+   jQuery("#ticket-update-metadata :input, input[name^=UpdateCc], input[name^=UpdateBcc]").change( updateScrips );
+});
+</script>
+% }
 <%INIT>
 my $CanRespond = 0;
 my $CanComment = 0;
diff --git a/share/static/css/base/ticket-form.css b/share/static/css/base/ticket-form.css
index 11d1fdd..15ce713 100644
--- a/share/static/css/base/ticket-form.css
+++ b/share/static/css/base/ticket-form.css
@@ -73,3 +73,11 @@ iframe.richtext-editor {
     float: right;
 }
 
+#recipients label {
+    padding-left: 2em;
+}
+
+#recipients input.checkbox {
+    position: absolute;
+    margin-left: 0.5em;
+}
diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index d5a8af6..957d6f2 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -56,6 +56,7 @@ window.RT.Autocomplete.bind = function(from) {
                 }
                 terms.push(''); // add trailing delimeter so user can input another value directly
                 this.value = terms.join(what == 'Tickets' ? ' ' : ", ");
+                jQuery(this).change();
                 return false;
             }
         }

commit df919d23ea36c4a87a6e31ab848a79eb8969874b
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jul 18 17:26:21 2014 -0400

    Pass the just-submitted squelching information to the first AJAX request
    
    If "Add more files" is pressed, the set of selected squelched recipients
    is submitted; on the sebsequent page display, however, that information
    does not appear in the initial form that is serialized and passed to the
    helpers; as such, the state of the checkboxes is lost.
    
    Preserve that information by ensuring that the squelching information is
    present on the page during the first page load, before the AJAX
    requests, by placing it within the area to be replaced.  This ensures
    that the form elements will not be duplicated once the initial AJAX
    request returns, but provides the query parameters for the initial call
    to jQuery('form[name=TicketUpdate]').serialize().

diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 30ff35f..73c7318 100644
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -138,6 +138,12 @@
 <div id="ticket-update-message">
 % if ( RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'}) ) {
     <&|/Widgets/TitleBox, title => loc('Recipients'), id => 'recipients' &>
+%   unless ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
+%     for my $address (grep {defined} ref $ARGS{TxnSendMailTo} ? @{$ARGS{TxnSendMailTo}} : $ARGS{TxnSendMailTo}) {
+        <input type="hidden" name="TxnSendMailTo" value="<% $address %>" />
+%     }
+      <input type="hidden" name="TxnRecipients" value="<% $ARGS{TxnRecipients} || '' %>" />
+%   }
     </&>
 %}
 
@@ -189,6 +195,10 @@
 
 % if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
   <&|/Widgets/TitleBox, title => loc('Scrips and Recipients'), id => 'previewscrips', rolledup => RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'}) &>
+%   for my $address (grep {defined} ref $ARGS{TxnSendMailTo} ? @{$ARGS{TxnSendMailTo}} : $ARGS{TxnSendMailTo}) {
+      <input type="hidden" name="TxnSendMailTo" value="<% $address %>" />
+%   }
+    <input type="hidden" name="TxnRecipients" value="<% $ARGS{TxnRecipients} || '' %>" />
   </&>
 % }
 </div>

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


More information about the rt-commit mailing list