[Rt-commit] rt branch, 4.4/ajax-preview-scrips, repushed

? sunnavy sunnavy at bestpractical.com
Tue Jul 15 01:04:13 EDT 2014


The branch 4.4/ajax-preview-scrips was deleted and repushed:
       was 3af73070f35733de64f5fc4289aefea49a9c24bc
       now 40bf9a930bda99d47070232d2269122d05f5fe2b

1:  9b43949 ! 1:  40bf9a9 ajaxify PrviewScrips and ShowSimplifiedRecipients on ticket update page
    @@ -1,6 +1,12 @@
     Author: sunnavy <sunnavy at bestpractical.com>
     
         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/Helpers/PreviewScrips b/share/html/Helpers/PreviewScrips
     new file mode 100644
    @@ -57,21 +63,21 @@
     +<%init>
     +my $TicketObj = RT::Ticket->new($session{CurrentUser});
     +$TicketObj->Load($ARGS{id});
    -+return unless $TicketObj->id && $ARGS{UpdateType};
    -+
    -+return unless $TicketObj->CurrentUserHasRight('ShowOutgoingEmail');
    ++$m->abort unless $TicketObj->id && $ARGS{UpdateType};
    ++
    ++$m->abort unless $TicketObj->CurrentUserHasRight('ShowOutgoingEmail');
     +if ( $ARGS{UpdateType} eq 'private' ) {
    -+    return
    ++    $m->abort
     +      unless $TicketObj->CurrentUserHasRight( 'CommentOnTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
     +}
     +else {
    -+    return
    ++    $m->abort
     +      unless $TicketObj->CurrentUserHasRight( 'ReplyToTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
     +}
     +
     +my $Object = $TicketObj->DryRun(%ARGS);
     +my %recips;
    -+return unless $Object;
    ++$m->abort unless $Object;
     +
     +my %squelched = ProcessTransactionSquelching( \%ARGS );
     +</%init>
    @@ -92,7 +98,8 @@
     +          <&|/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) {
    @@ -100,9 +107,26 @@
     +%                 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>
    @@ -197,30 +221,37 @@
     +%#
     +%# END BPS TAGGED BLOCK }}}
     +<%init>
    -+return unless RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'});
    ++$m->abort unless RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'});
     +
     +my $TicketObj = RT::Ticket->new($session{CurrentUser});
     +$TicketObj->Load($ARGS{id});
    -+return unless $TicketObj->id && $ARGS{UpdateType};
    ++$m->abort unless $TicketObj->id && $ARGS{UpdateType};
     +
     +if ( $ARGS{UpdateType} eq 'private' ) {
    -+    return
    ++    $m->abort
     +      unless $TicketObj->CurrentUserHasRight( 'CommentOnTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
     +}
     +else {
    -+    return
    ++    $m->abort
     +      unless $TicketObj->CurrentUserHasRight( 'ReplyToTicket' ) || $TicketObj->CurrentUserHasRight( 'ModifyTicket' );
     +}
     +
     +my $Object = $TicketObj->DryRun(%ARGS);
    -+return unless $Object;
    ++$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;
    ++                }
    ++            }
     +        }
     +    }
     +}
    @@ -237,7 +268,7 @@
     +</%init>
     +<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">
    @@ -250,6 +281,15 @@
     +%         $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 );
    @@ -263,7 +303,6 @@
     +    <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/PreviewScrips b/share/html/Ticket/Elements/PreviewScrips
     deleted file mode 100644
    @@ -524,25 +563,6 @@
      <div id="ticket-update-message">
     -  <& /Ticket/Elements/ShowSimplifiedRecipients, TicketObj => $TicketObj, %ARGS &>
     +% if ( RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'}) ) {
    -+<script type="text/javascript">
    -+jQuery( function() {
    -+   jQuery('#UpdateType').change( function() {
    -+       jQuery('#recipients div.titlebox-content').load( '<% RT->Config->Get('WebPath')%>/Helpers/ShowSimplifiedRecipients',
    -+           jQuery('form[name=TicketUpdate]').serialize(),
    -+           function() {
    -+% unless ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
    -+               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'));
    -+               });
    -+% }
    -+        });
    -+   });
    -+% unless ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
    -+   jQuery('#UpdateType').change();
    -+% }
    -+});
    -+</script>
    -+
     +    <&|/Widgets/TitleBox, title => loc('Recipients'), id => 'recipients' &>
     +    </&>
     +%}
    @@ -550,25 +570,8 @@
        <&|/Widgets/TitleBox, title => loc('Message'), class => 'messagedetails' &>
        <table width="100%" border="0">
     @@
    - % $m->callback( %ARGS, CallbackName => 'BeforeScrips', Ticket => $TicketObj );
      
      % if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
    -+<script type="text/javascript">
    -+jQuery( function() {
    -+   jQuery('#UpdateType').change( function() {
    -+       jQuery('#previewscrips div.titlebox-content').load( '<% RT->Config->Get('WebPath')%>/Helpers/PreviewScrips',
    -+           jQuery('form[name=TicketUpdate]').serialize(),
    -+           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'));
    -+               });
    -+           }
    -+       );
    -+   });
    -+   jQuery('#UpdateType').change();
    -+});
    -+</script>
    -+
        <&|/Widgets/TitleBox, title => loc('Scrips and Recipients'), id => 'previewscrips', rolledup => RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'}) &>
     -    <& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>
        </&>
    @@ -584,4 +587,57 @@
      </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
    +--- a/share/static/css/base/ticket-form.css
    ++++ b/share/static/css/base/ticket-form.css
    +@@
    +     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
    +--- a/share/static/js/autocomplete.js
    ++++ b/share/static/js/autocomplete.js
    +@@
    +                 }
    +                 terms.push(''); // add trailing delimeter so user can input another value directly
    +                 this.value = terms.join(what == 'Tickets' ? ' ' : ", ");
    ++                jQuery(this).change();
    +                 return false;
    +             }
    +         }
2:  355ed02 < -:  ------- trigger ajax call for all inputs in "Ticket and Transaction"
3:  e79c9a6 < -:  ------- respect one-time Cc/Bcc too
4:  cb750e1 < -:  ------- "return" still emits the footer, incorrectly. thanks to chmrr++
5:  7d52fbc < -:  ------- Don't show checkboxes for one-time Ccs unless they are actually squelchable
6:  3af7307 < -:  ------- Unify recipients and previews javascript



More information about the rt-commit mailing list