import rt 3.6.4
[freeside.git] / rt / html / Elements / RT__Ticket / ColumnMap
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2007 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/copyleft/gpl.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 (undef);
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     QueueName => {
119         attribute => 'Queue',
120         title     => 'Queue',
121         value     => sub { return $_[0]->QueueObj->Name }
122     },
123     OwnerName => {
124         title     => 'Owner',
125         attribute => 'Owner',
126         value     => sub { return $_[0]->OwnerObj->Name }
127     },
128     id => {
129         attribute => 'id',
130         align     => 'right',
131         value     => sub { return $_[0]->id }
132     },
133     Status => {
134         attribute => 'Status',
135         value     => sub { return loc($_[0]->Status) }
136     },
137     Subject => {
138         attribute => 'Subject',
139         value => sub { return $_[0]->Subject || "(" . loc('No subject') . ")" }
140     },
141     ExtendedStatus => {
142         title     => 'Status',
143         attribute => 'Status',
144         value     => sub {
145             my $Ticket = shift;
146
147             if ( $Ticket->HasUnresolvedDependencies ) {
148                 if (   $Ticket->HasUnresolvedDependencies( Type => 'approval' )
149                     or $Ticket->HasUnresolvedDependencies( Type => 'code' ) )
150                 {
151                     return \'<em>', loc('(pending approval)'), \'</em>';
152                 }
153                 else {
154                     return \'<em>', loc('(pending other Collection)'), \'</em>';
155                 }
156             }
157             else {
158                 return loc( $Ticket->Status );
159             }
160
161           }
162     },
163     Priority => {
164         attribute => 'Priority',
165         value     => sub { return $_[0]->Priority }
166     },
167     InitialPriority => {
168         attribute => 'InitialPriority',
169         name => 'Initial Priority',
170         value     => sub { return $_[0]->InitialPriority }
171     },
172     FinalPriority => {
173         attribute => 'FinalPriority',
174         name => 'Final Priority',
175         value     => sub { return $_[0]->FinalPriority }
176     },
177     EffectiveId => {
178         attribute => 'EffectiveId',
179         value     => sub { return $_[0]->EffectiveId }
180     },
181     Type => {
182         attribute => 'Type',
183         value     => sub { return $_[0]->Type }
184     },
185     TimeWorked => {
186         attribute => 'TimeWorked',
187         title => 'Time Worked',
188         value     => sub { return $_[0]->TimeWorked }
189     },
190     TimeLeft => {
191         attribute => 'TimeLeft',
192         title     => 'Time Left',
193         value     => sub { return $_[0]->TimeLeft }
194     },
195     TimeEstimated => {
196         attribute => 'TimeEstimated',
197         title => 'Time Estimated',
198         value     => sub { return $_[0]->TimeEstimated }
199     },
200     Requestors => {
201         attribute => 'Requestor.EmailAddress',
202         value => sub { return $_[0]->Requestors->MemberEmailAddressesAsString }
203     },
204     Cc => {
205         attribute => 'Cc.EmailAddress',
206         value => sub { return $_[0]->Cc->MemberEmailAddressesAsString }
207     },
208     AdminCc => {
209         attribute => 'AdminCc.EmailAddress',
210         value => sub { return $_[0]->AdminCc->MemberEmailAddressesAsString }
211     },
212     StartsRelative => {
213         title     => 'Starts',
214         attribute => 'Starts',
215         value     => sub { return $_[0]->StartsObj->AgeAsString }
216     },
217     StartedRelative => {
218         title     => 'Started',
219         attribute => 'Started',
220         value     => sub { return $_[0]->StartedObj->AgeAsString }
221     },
222     CreatedRelative => {
223         title     => 'Created',
224         attribute => 'Created',
225         value     => sub { return $_[0]->CreatedObj->AgeAsString }
226     },
227     LastUpdatedRelative => {
228         title     => 'Last Updated',
229         attribute => 'LastUpdated',
230         value     => sub { return $_[0]->LastUpdatedObj->AgeAsString }
231     },
232     ToldRelative => {
233         title     => 'Told',
234         attribute => 'Told',
235         value     => sub { return $_[0]->ToldObj->AgeAsString }
236     },
237     DueRelative => {
238         title     => 'Due',
239         attribute => 'Due',
240         value     => sub { 
241             my $date = $_[0]->DueObj;
242             if ($date && $date->Unix > 0 && $date->Unix < time()) {
243                 return (\'<span class="overdue">' , $date->AgeAsString , \'</span>');
244             } else {
245                 return $date->AgeAsString;
246             }
247         }
248     },
249     ResolvedRelative => {
250         title     => 'Resolved',
251         attribute => 'Resolved',
252         value     => sub { return $_[0]->ResolvedObj->AgeAsString }
253     },
254     Starts => {
255         attribute => 'Starts',
256         value     => sub { return $_[0]->StartsObj->AsString }
257     },
258     Started => {
259         attribute => 'Started',
260         value     => sub { return $_[0]->StartedObj->AsString }
261     },
262     Created => {
263         attribute => 'Created',
264         value     => sub { return $_[0]->CreatedObj->AsString }
265     },
266     CreatedBy => {
267         attribute => 'CreatedBy',
268         title => 'Created By',
269         value     => sub { return $_[0]->CreatorObj->Name }
270     },
271     LastUpdated => {
272         attribute => 'LastUpdated',
273         title     => 'Last Updated',
274         value     => sub { return $_[0]->LastUpdatedObj->AsString }
275     },
276     LastUpdatedBy => {
277         attribute => 'LastUpdatedBy',
278         title     => 'Last Updated By',
279         value     => sub { return $_[0]->LastUpdatedByObj->Name }
280     },
281     Told => {
282         attribute => 'Told',
283         value     => sub { return $_[0]->ToldObj->AsString }
284     },
285     Due => {
286         attribute => 'Due',
287         value     => sub { return $_[0]->DueObj->AsString }
288     },
289     Resolved => {
290         attribute => 'Resolved',
291         value     => sub { return $_[0]->ResolvedObj->AsString }
292     },
293
294     # Everything from LINKTYPEMAP
295     (map {
296         $_ => { value => $LinkCallback->( $_ ) }
297     } keys %RT::Ticket::LINKTYPEMAP),
298
299     '_CLASS' => {
300         value => sub { return $_[1] % 2 ? 'oddline' : 'evenline' }
301     },
302     '_CHECKBOX' => {
303         attribute => 'checkbox',
304         title => loc('Update'),
305         align     => 'right',
306         value     => sub { return \('<input type="checkbox" class="checkbox" name="UpdateTicket'.$_[0]->id.'" value="1" checked />') }
307     },
308
309 };
310 </%ONCE>
311 <%init>
312 $m->comp( '/Elements/Callback', COLUMN_MAP    => $COLUMN_MAP, _CallbackName => 'ColumnMap');
313 return $ColumnMap->( $Name, $Attr );
314 </%init>