import rt 3.4.6
[freeside.git] / rt / html / Elements / RT__Ticket / ColumnMap
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2005 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., 675 Mass Ave, Cambridge, MA 02139, USA.
26 %# 
27 %# 
28 %# CONTRIBUTION SUBMISSION POLICY:
29 %# 
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
35 %# 
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
44 %# 
45 %# END BPS TAGGED BLOCK }}}
46 <%ARGS>
47 $Name => undef
48 $Attr => undef
49 </%ARGS>
50
51
52 <%ONCE>
53 our ( $COLUMN_MAP );
54
55 sub ColumnMap {
56     my $name = shift;
57     my $attr = shift;
58
59     # First deal with the simple things from the map
60     if ( $COLUMN_MAP->{$name} ) {
61         return ( $COLUMN_MAP->{$name}->{$attr} );
62     }
63
64     # now, let's deal with harder things, like Custom Fields
65
66     elsif ( $name =~ /^(?:CF|CustomField)\.\{(.+)\}$/ ) {
67         my $field = $1;
68
69         if ( $attr eq 'attribute' ) {
70             return (undef);
71         }
72         elsif ( $attr eq 'title' ) {
73             return ( $field );
74         }
75         elsif ( $attr eq 'value' ) {
76             # Display custom field contents, separated by newlines.
77             # For Image custom fields we also show a thumbnail here.
78             return sub {
79                 my $values = $_[0]->CustomFieldValues($field);
80                 return map {
81                     (
82                         ($_->CustomFieldObj->Type eq 'Image')
83                             ? \($m->scomp( '/Elements/ShowCustomFieldImage', Object => $_ ))
84                             : $_->Content
85                     ),
86                     \'<br>',
87                 } @{ $values->ItemsArrayRef }
88             };
89         }
90     }
91 }
92
93 sub LinkCallback {
94     my $method = shift;
95
96     my $mode            = $RT::Ticket::LINKTYPEMAP{$method}{Mode};
97     my $type            = $RT::Ticket::LINKTYPEMAP{$method}{Type};
98     my $other_mode      = ($mode eq "Target" ? "Base" : "Target");
99     my $mode_uri        = $mode.'URI';
100     my $local_type      = 'Local'.$mode;
101
102     return sub {
103         map {
104             \'<A HREF="',
105             $_->$mode_uri->Resolver->HREF,
106             \'">',
107             ( $_->$mode_uri->IsLocal ? $_->$local_type : $_->$mode ),
108             \'</A><BR>',
109         } @{ $_[0]->Links($other_mode,$type)->ItemsArrayRef }
110     }
111 }
112
113 $COLUMN_MAP = {
114     QueueName => {
115         attribute => 'Queue',
116         title     => 'Queue',
117         value     => sub { return $_[0]->QueueObj->Name }
118     },
119     OwnerName => {
120         title     => 'Owner',
121         attribute => 'Owner',
122         value     => sub { return $_[0]->OwnerObj->Name }
123     },
124     id => {
125         attribute => 'id',
126         align     => 'right',
127         value     => sub { return $_[0]->id }
128     },
129     Status => {
130         attribute => 'Status',
131         value     => sub { return loc($_[0]->Status) }
132     },
133     Subject => {
134         attribute => 'Subject',
135         value => sub { return $_[0]->Subject || "(" . loc('No subject') . ")" }
136     },
137     ExtendedStatus => {
138         title     => 'Status',
139         attribute => 'Status',
140         value     => sub {
141             my $Ticket = shift;
142
143             if ( $Ticket->HasUnresolvedDependencies ) {
144                 if (   $Ticket->HasUnresolvedDependencies( Type => 'approval' )
145                     or $Ticket->HasUnresolvedDependencies( Type => 'code' ) )
146                 {
147                     return \'<em>', loc('(pending approval)'), \'</em>';
148                 }
149                 else {
150                     return \'<em>', loc('(pending other Collection)'), \'</em>';
151                 }
152             }
153             else {
154                 return loc( $Ticket->Status );
155             }
156
157           }
158     },
159     Priority => {
160         attribute => 'Priority',
161         value     => sub { return $_[0]->Priority }
162     },
163     InitialPriority => {
164         attribute => 'InitialPriority',
165         name => 'Initial Priority',
166         value     => sub { return $_[0]->InitialPriority }
167     },
168     FinalPriority => {
169         attribute => 'FinalPriority',
170         name => 'Final Priority',
171         value     => sub { return $_[0]->FinalPriority }
172     },
173     EffectiveId => {
174         attribute => 'EffectiveId',
175         value     => sub { return $_[0]->EffectiveId }
176     },
177     Type => {
178         attribute => 'Type',
179         value     => sub { return $_[0]->Type }
180     },
181     TimeWorked => {
182         attribute => 'TimeWorked',
183         title => 'Time Worked',
184         value     => sub { return $_[0]->TimeWorked }
185     },
186     TimeLeft => {
187         attribute => 'TimeLeft',
188         title     => 'Time Left',
189         value     => sub { return $_[0]->TimeLeft }
190     },
191     TimeEstimated => {
192         attribute => 'TimeEstimated',
193         title => 'Time Estimated',
194         value     => sub { return $_[0]->TimeEstimated }
195     },
196     Requestors => {
197         value => sub { return $_[0]->Requestors->MemberEmailAddressesAsString }
198     },
199     Cc => {
200         value => sub { return $_[0]->Cc->MemberEmailAddressesAsString }
201     },
202     AdminCc => {
203         value => sub { return $_[0]->AdminCc->MemberEmailAddressesAsString }
204     },
205     StartsRelative => {
206         title     => 'Starts',
207         attribute => 'Starts',
208         value     => sub { return $_[0]->StartsObj->AgeAsString }
209     },
210     StartedRelative => {
211         title     => 'Started',
212         attribute => 'Started',
213         value     => sub { return $_[0]->StartedObj->AgeAsString }
214     },
215     CreatedRelative => {
216         title     => 'Created',
217         attribute => 'Created',
218         value     => sub { return $_[0]->CreatedObj->AgeAsString }
219     },
220     LastUpdatedRelative => {
221         title     => 'Last Updated',
222         attribute => 'LastUpdated',
223         value     => sub { return $_[0]->LastUpdatedObj->AgeAsString }
224     },
225     ToldRelative => {
226         title     => 'Told',
227         attribute => 'Told',
228         value     => sub { return $_[0]->ToldObj->AgeAsString }
229     },
230     DueRelative => {
231         title     => 'Due',
232         attribute => 'Due',
233         value     => sub { 
234             my $date = $_[0]->DueObj;
235             if ($date && $date->Unix > 0 && $date->Unix < time()) {
236                 return (\'<span class="overdue">' , $date->AgeAsString , \'</span>');
237             } else {
238                 return $date->AgeAsString;
239             }
240         }
241     },
242     ResolvedRelative => {
243         title     => 'Resolved',
244         attribute => 'Resolved',
245         value     => sub { return $_[0]->ResolvedObj->AgeAsString }
246     },
247     Starts => {
248         attribute => 'Starts',
249         value     => sub { return $_[0]->StartsObj->AsString }
250     },
251     Started => {
252         attribute => 'Started',
253         value     => sub { return $_[0]->StartedObj->AsString }
254     },
255     Created => {
256         attribute => 'Created',
257         value     => sub { return $_[0]->CreatedObj->AsString }
258     },
259     CreatedBy => {
260         attribute => 'CreatedBy',
261         title => 'Created By',
262         value     => sub { return $_[0]->CreatorObj->Name }
263     },
264     LastUpdated => {
265         attribute => 'LastUpdated',
266         title     => 'Last Updated',
267         value     => sub { return $_[0]->LastUpdatedObj->AsString }
268     },
269     LastUpdatedBy => {
270         attribute => 'LastUpdatedBy',
271         title     => 'Last Updated By',
272         value     => sub { return $_[0]->LastUpdatedByObj->Name }
273     },
274     Told => {
275         attribute => 'Told',
276         value     => sub { return $_[0]->ToldObj->AsString }
277     },
278     Due => {
279         attribute => 'Due',
280         value     => sub { return $_[0]->DueObj->AsString }
281     },
282     Resolved => {
283         attribute => 'Resolved',
284         value     => sub { return $_[0]->ResolvedObj->AsString }
285     },
286
287     # Everything from LINKTYPEMAP
288     (map {
289         $_ => { value => LinkCallback( $_ ) }
290     } keys %RT::Ticket::LINKTYPEMAP),
291
292     '_CLASS' => {
293         value => sub { return $_[1] % 2 ? 'oddline' : 'evenline' }
294     },
295
296 };
297 </%ONCE>
298 <%init>
299 $m->comp( '/Elements/Callback', COLUMN_MAP    => $COLUMN_MAP, _CallbackName => 'ColumnMap');
300 return ColumnMap($Name, $Attr);
301 </%init>