import rt 3.8.8
[freeside.git] / rt / html / Elements / RT__Ticket / ColumnMap
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
6 %#                                          <jesse@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 <%ARGS>
49 $Name => undef
50 $Attr => undef
51 </%ARGS>
52
53
54 <%ONCE>
55 our ( $COLUMN_MAP );
56
57 my $ColumnMap = sub {
58     my $name = shift;
59     my $attr = shift;
60
61     # First deal with the simple things from the map
62     if ( $COLUMN_MAP->{$name} ) {
63         return ( $COLUMN_MAP->{$name}->{$attr} );
64     }
65
66     # now, let's deal with harder things, like Custom Fields
67
68     elsif ( $name =~ /^(?:CF|CustomField)\.\{(.+)\}$/ ) {
69         my $field = $1;
70
71         if ( $attr eq 'attribute' ) {
72             return ("CF.{$field}");
73         }
74         elsif ( $attr eq 'title' ) {
75             return ( $field );
76         }
77         elsif ( $attr eq 'value' ) {
78             # Display custom field contents, separated by newlines.
79             # For Image custom fields we also show a thumbnail here.
80             return sub {
81                 my $values = $_[0]->CustomFieldValues($field);
82                 my @values =  map {
83                     (
84                         ($_->CustomFieldObj->Type eq 'Image')
85                             ? \($m->scomp( '/Elements/ShowCustomFieldImage', Object => $_ ))
86                             : $_->Content
87                     ),
88                     \'<br />',
89                 } @{ $values->ItemsArrayRef };
90             pop @values; # Remove that last <br />
91             return @values;
92             };
93         }
94     }
95 };
96
97 my $LinkCallback = sub {
98     my $method = shift;
99
100     my $mode            = $RT::Ticket::LINKTYPEMAP{$method}{Mode};
101     my $type            = $RT::Ticket::LINKTYPEMAP{$method}{Type};
102     my $other_mode      = ($mode eq "Target" ? "Base" : "Target");
103     my $mode_uri        = $mode.'URI';
104     my $local_type      = 'Local'.$mode;
105
106     return sub {
107         map {
108             \'<a href="',
109             $_->$mode_uri->Resolver->HREF,
110             \'">',
111             ( $_->$mode_uri->IsLocal ? $_->$local_type : $_->$mode ),
112             \'</a><br />',
113         } @{ $_[0]->Links($other_mode,$type)->ItemsArrayRef }
114     }
115 };
116
117 $COLUMN_MAP = {
118     Queue => {
119         attribute => 'Queue',
120         title     => 'Queue id',
121         value     => sub { return $_[0]->Queue }
122     },
123     QueueName => {
124         attribute => 'Queue',
125         title     => 'Queue',
126         value     => sub { return $_[0]->QueueObj->Name }
127     },
128     OwnerName => {
129         title     => 'Owner',
130         attribute => 'Owner',
131         value     => sub { return $_[0]->OwnerObj->Name }
132     },
133     id => {
134         attribute => 'id',
135         align     => 'right',
136         value     => sub { return $_[0]->id }
137     },
138     Status => {
139         attribute => 'Status',
140         value     => sub { return loc($_[0]->Status) }
141     },
142     Subject => {
143         attribute => 'Subject',
144         value => sub { return $_[0]->Subject || "(" . loc('No subject') . ")" }
145     },
146     ExtendedStatus => {
147         title     => 'Status',
148         attribute => 'Status',
149         value     => sub {
150             my $Ticket = shift;
151
152             if ( $Ticket->HasUnresolvedDependencies ) {
153                 if (   $Ticket->HasUnresolvedDependencies( Type => 'approval' )
154                     or $Ticket->HasUnresolvedDependencies( Type => 'code' ) )
155                 {
156                     return \'<em>', loc('(pending approval)'), \'</em>';
157                 }
158                 else {
159                     return \'<em>', loc('(pending other Collection)'), \'</em>';
160                 }
161             }
162             else {
163                 return loc( $Ticket->Status );
164             }
165
166           }
167     },
168     Priority => {
169         attribute => 'Priority',
170         value     => sub { return $_[0]->Priority }
171     },
172     InitialPriority => {
173         attribute => 'InitialPriority',
174         name => 'Initial Priority',
175         value     => sub { return $_[0]->InitialPriority }
176     },
177     FinalPriority => {
178         attribute => 'FinalPriority',
179         name => 'Final Priority',
180         value     => sub { return $_[0]->FinalPriority }
181     },
182     EffectiveId => {
183         attribute => 'EffectiveId',
184         value     => sub { return $_[0]->EffectiveId }
185     },
186     Type => {
187         attribute => 'Type',
188         value     => sub { return $_[0]->Type }
189     },
190     TimeWorked => {
191         attribute => 'TimeWorked',
192         title => 'Time Worked',
193         value     => sub { return $_[0]->TimeWorked }
194     },
195     TimeLeft => {
196         attribute => 'TimeLeft',
197         title     => 'Time Left',
198         value     => sub { return $_[0]->TimeLeft }
199     },
200     TimeEstimated => {
201         attribute => 'TimeEstimated',
202         title => 'Time Estimated',
203         value     => sub { return $_[0]->TimeEstimated }
204     },
205     Requestors => {
206         attribute => 'Requestor.EmailAddress',
207         value => sub { return $_[0]->Requestors->MemberEmailAddressesAsString }
208     },
209     Cc => {
210         attribute => 'Cc.EmailAddress',
211         value => sub { return $_[0]->Cc->MemberEmailAddressesAsString }
212     },
213     AdminCc => {
214         attribute => 'AdminCc.EmailAddress',
215         value => sub { return $_[0]->AdminCc->MemberEmailAddressesAsString }
216     },
217     StartsRelative => {
218         title     => 'Starts',
219         attribute => 'Starts',
220         value     => sub { return $_[0]->StartsObj->AgeAsString }
221     },
222     StartedRelative => {
223         title     => 'Started',
224         attribute => 'Started',
225         value     => sub { return $_[0]->StartedObj->AgeAsString }
226     },
227     CreatedRelative => {
228         title     => 'Created',
229         attribute => 'Created',
230         value     => sub { return $_[0]->CreatedObj->AgeAsString }
231     },
232     LastUpdatedRelative => {
233         title     => 'Last Updated',
234         attribute => 'LastUpdated',
235         value     => sub { return $_[0]->LastUpdatedObj->AgeAsString }
236     },
237     ToldRelative => {
238         title     => 'Told',
239         attribute => 'Told',
240         value     => sub { return $_[0]->ToldObj->AgeAsString }
241     },
242     DueRelative => {
243         title     => 'Due',
244         attribute => 'Due',
245         value     => sub { 
246             my $date = $_[0]->DueObj;
247             if ($date && $date->Unix > 0 && $date->Unix < time()) {
248                 return (\'<span class="overdue">' , $date->AgeAsString , \'</span>');
249             } else {
250                 return $date->AgeAsString;
251             }
252         }
253     },
254     ResolvedRelative => {
255         title     => 'Resolved',
256         attribute => 'Resolved',
257         value     => sub { return $_[0]->ResolvedObj->AgeAsString }
258     },
259     Starts => {
260         attribute => 'Starts',
261         value     => sub { return $_[0]->StartsObj->AsString }
262     },
263     Started => {
264         attribute => 'Started',
265         value     => sub { return $_[0]->StartedObj->AsString }
266     },
267     Created => {
268         attribute => 'Created',
269         value     => sub { return $_[0]->CreatedObj->AsString }
270     },
271     CreatedBy => {
272         attribute => 'Creator',
273         title => 'Created By',
274         value     => sub { return $_[0]->CreatorObj->Name }
275     },
276     LastUpdated => {
277         attribute => 'LastUpdated',
278         title     => 'Last Updated',
279         value     => sub { return $_[0]->LastUpdatedObj->AsString }
280     },
281     LastUpdatedBy => {
282         attribute => 'LastUpdatedBy',
283         title     => 'Last Updated By',
284         value     => sub { return $_[0]->LastUpdatedByObj->Name }
285     },
286     Told => {
287         attribute => 'Told',
288         value     => sub { return $_[0]->ToldObj->AsString }
289     },
290     Due => {
291         attribute => 'Due',
292         value     => sub { return $_[0]->DueObj->AsString }
293     },
294     Resolved => {
295         attribute => 'Resolved',
296         value     => sub { return $_[0]->ResolvedObj->AsString }
297     },
298
299     # Everything from LINKTYPEMAP
300     (map {
301         $_ => { value => $LinkCallback->( $_ ) }
302     } keys %RT::Ticket::LINKTYPEMAP),
303
304     '_CLASS' => {
305         value => sub { return $_[1] % 2 ? 'oddline' : 'evenline' }
306     },
307     '_CHECKBOX' => {
308         attribute => 'checkbox',
309         title => loc('Update'),
310         align     => 'right',
311         value     => sub { return \('<input type="checkbox" class="checkbox" name="UpdateTicket'.$_[0]->id.'" value="1" checked />') }
312     },
313
314 };
315 </%ONCE>
316 <%init>
317 $m->comp( '/Elements/Callback', COLUMN_MAP    => $COLUMN_MAP, _CallbackName => 'ColumnMap');
318 return $ColumnMap->( $Name, $Attr );
319 </%init>