rt 4.2.14 (#13852)
[freeside.git] / rt / share / html / Elements / ShowTransaction
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC
6 %#                                          <sales@bestpractical.com>
7 %#
8 %# (Except where explicitly superseded by other copyright notices)
9 %#
10 %#
11 %# LICENSE:
12 %#
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %#
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %#
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %#
29 %#
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %#
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %#
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %#
47 %# END BPS TAGGED BLOCK }}}
48 <div class="<% join ' ', @classes %>">
49   <div class="metadata">
50     <span class="type">
51       <a name="txn-<% $Transaction->id %>" \
52 % if ( $DisplayPath ) {
53       href="<% $DisplayPath %>?id=<% $Object->id %>#txn-<% $Transaction->id %>" \
54 % }
55       >#</a>
56     </span>
57 % $m->callback( %ARGS, Transaction => $Transaction, CallbackName => 'AfterAnchor' );
58     <span class="date"><% $date |n %></span>
59     <span class="description">
60       <& /Elements/ShowUser, User => $Transaction->CreatorObj &> - <% $desc |n %>
61 % $m->callback( %ARGS, Transaction => $Transaction, CallbackName => 'AfterDescription' );
62     </span>
63     <span class="time-taken"><% $time %></span>
64 % if ( $actions ) {
65     <span class="actions"><% $actions |n %></span>
66 % }
67   </div>
68
69   <div class="content">
70 <%PERL>
71 $m->comp('/Elements/ShowCustomFields', Object => $Transaction, HideEmpty => 1 ) if $HasTxnCFs;
72 $m->comp(
73     'ShowTransactionAttachments',
74     %ARGS,
75     Parent => 0
76 ) if $ShowBody;
77 </%PERL>
78   </div>
79 % $m->callback( %ARGS, Transaction => $Transaction, CallbackName => 'AfterContent' );
80 </div>
81
82 <%ARGS>
83 $Transaction
84 $Object => $Transaction->Object
85
86 $Attachments => undef
87 $AttachmentContent => undef
88 $HasTxnCFs => 1
89
90 $ShowBody => 1
91 $ShowActions => 1
92 $RowNum => 1
93
94 $DisplayPath => undef
95 $AttachmentPath => undef
96 $UpdatePath => undef
97 $ForwardPath => undef
98 $EncryptionPath => undef
99 $EmailRecordPath => undef
100 </%ARGS>
101
102 <%ONCE>
103
104 </%ONCE>
105 <%INIT>
106 my $record_type = $Object->RecordType;
107 my $type_class  = $Object->ClassifyTransaction( $Transaction );
108
109 $m->callback(
110     CallbackName => 'MassageTypeClass',
111     Transaction  => $Transaction,
112     TypeClassRef => \$type_class,
113     ARGSRef      => \%ARGS,
114 );
115
116 my @classes = (
117     "transaction",
118     "$record_type-transaction",
119     $type_class,
120     ($RowNum % 2 ? 'odd' : 'even')
121 );
122
123 my $desc = $Transaction->BriefDescriptionAsHTML;
124 if ( $Object->id != $Transaction->ObjectId ) {
125     # merged objects
126     $desc = join " - ",
127         $m->interp->apply_escapes(
128             loc("[_1] #[_2]:", loc($record_type), $Transaction->ObjectId), 'h'),
129         $desc;
130 }
131
132 my $date = $Transaction->CreatedAsString;
133
134 my $time = '';
135 $time = loc('[quant,_1,minute,minutes]', $Transaction->TimeTaken)
136     if $Transaction->TimeTaken;
137
138 if ( $ShowBody && !$Attachments ) {
139     $ARGS{'Attachments'} = $Attachments = {};
140
141     my $attachments = $Transaction->Attachments( WithHeaders => 1 );
142     push @{ $Attachments->{ $_->Parent || 0 } ||= [] }, $_
143         foreach @{ $attachments->ItemsArrayRef };
144 }
145
146 my @actions = ();
147 my $txn_type = $Transaction->Type;
148 if ( $txn_type =~ /EmailRecord$/ ) {
149     push @actions, {
150         title  => loc('Show'),
151         target => '_blank',
152         path   => $EmailRecordPath
153             .'?id='. $Object->id
154             .'&Transaction='. $Transaction->id
155             .'&Attachment='. ( $Attachments->{0}[0] && $Attachments->{0}[0]->id ),
156     } if $EmailRecordPath;
157
158     $ShowBody = 0;
159 }
160
161 # If the transaction has anything attached to it at all
162 elsif ( %$Attachments && $ShowActions ) {
163     my %has_right = map {
164         $_ => RT::ACE->CanonicalizeRightName( $_ . $record_type )
165     } qw(Modify CommentOn ReplyTo);
166     $has_right{'Forward'} = RT::ACE->CanonicalizeRightName('ForwardMessage');
167
168     my $can_modify = $has_right{'Modify'}
169         && $Object->CurrentUserHasRight( $has_right{'Modify'} );
170
171     if ( $UpdatePath && $has_right{'ReplyTo'}
172         && ( $can_modify
173             || $Object->CurrentUserHasRight( $has_right{'ReplyTo'} )
174         )
175     ) {
176         push @actions, {
177             class  => "reply-link",
178             title  => loc('Reply'),
179             path   => $UpdatePath
180                 .'?id='. $Object->id
181                 .'&QuoteTransaction='. $Transaction->id
182                 .'&Action=Respond'
183             ,
184         };
185     }
186     if ( $UpdatePath && $has_right{'CommentOn'}
187         && ( $can_modify
188             || $Object->CurrentUserHasRight( $has_right{'CommentOn'} )
189         )
190     ) {
191         push @actions, {
192             class  => "comment-link",
193             title  => loc('Comment'),
194             path   => $UpdatePath
195                 .'?id='. $Object->id
196                 .'&QuoteTransaction='. $Transaction->id
197                 .'&Action=Comment'
198             ,
199         };
200     }
201     if ( $ForwardPath && $has_right{'Forward'}
202         && $Object->CurrentUserHasRight( $has_right{'Forward'} )
203     ) {
204         push @actions, {
205             class  => "forward-link",
206             title  => loc('Forward'),
207             path   => $ForwardPath
208                 .'?id='. $Object->id
209                 .'&QuoteTransaction='. $Transaction->id
210             ,
211         };
212     }
213     if ( $EncryptionPath && $can_modify
214         && RT->Config->Get('Crypt')->{'Enable'}
215         && RT->Config->Get('Crypt')->{'AllowEncryptDataInDB'}
216     ) {
217         push @actions, {
218             class  => "encryption-link",
219             title  => loc('Encrypt/Decrypt'),
220             path   => $EncryptionPath
221                 .'?id='. $Transaction->id
222                 .'&QuoteTransaction='. $Transaction->id
223             ,
224         };
225     }
226 }
227
228 $m->callback(
229     %ARGS,
230     Transaction => $Transaction,
231     Object      => $Object,
232
233     Classes     => \@classes,
234     Actions     => \@actions,
235     Created     => \$date,
236     TimeTaken   => \$time,
237     Description => \$desc,
238     ShowBody    => \$ShowBody,
239 );
240
241 my $actions = '';
242 if ( @actions ) {
243     my $i = $m->interp;
244
245     foreach my $a ( @actions ) {
246         $a = '<a'
247             .' href="'. $i->apply_escapes( $a->{'path'}, 'h' ) .'"'
248             . ($a->{'target'}
249                 ? ' target="'. $i->apply_escapes( $a->{'target'}, 'h' ) .'"'
250                 : ''
251             )
252             . ($a->{'class'}
253                 ? ' class="'. $i->apply_escapes( $a->{'class'}, 'h' ) .'"'
254                 : ''
255             )
256             .'>'. $i->apply_escapes( $a->{'title'}, 'h' ) .'</a>'
257         ;
258     }
259     $actions = join '&nbsp;', map "[$_]", @actions;
260 }
261
262 # make date unbreakable
263 $date = $m->interp->apply_escapes( $date, 'h' );
264 $date =~ s/\s/&nbsp;/g;
265 </%INIT>