This commit was generated by cvs2svn to compensate for changes in r4407,
[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 $mode_uri        = $mode.'URI';
99     my $local_type      = 'Local'.$mode;
100
101     return sub {
102         map {
103             \'<A HREF="',
104             $_->$mode_uri->Resolver->HREF,
105             \'">',
106             ( $_->$mode_uri->IsLocal ? $_->$local_type : $_->$mode ),
107             \'</A><BR>',
108         } @{ $_[0]->Links($mode,$type)->ItemsArrayRef }
109     }
110 }
111
112 $COLUMN_MAP = {
113     QueueName => {
114         attribute => 'Queue',
115         title     => 'Queue',
116         value     => sub { return $_[0]->QueueObj->Name }
117     },
118     OwnerName => {
119         title     => 'Owner',
120         attribute => 'Owner',
121         value     => sub { return $_[0]->OwnerObj->Name }
122     },
123     id => {
124         attribute => 'id',
125         align     => 'right',
126         value     => sub { return $_[0]->id }
127     },
128     Status => {
129         attribute => 'Status',
130         value     => sub { return loc($_[0]->Status) }
131     },
132     Subject => {
133         attribute => 'Subject',
134         value => sub { return $_[0]->Subject || "(" . loc('No subject') . ")" }
135     },
136     ExtendedStatus => {
137         title     => 'Status',
138         attribute => 'Status',
139         value     => sub {
140             my $Ticket = shift;
141
142             if ( $Ticket->HasUnresolvedDependencies ) {
143                 if (   $Ticket->HasUnresolvedDependencies( Type => 'approval' )
144                     or $Ticket->HasUnresolvedDependencies( Type => 'code' ) )
145                 {
146                     return \'<em>', loc('(pending approval)'), \'</em>';
147                 }
148                 else {
149                     return \'<em>', loc('(pending other Collection)'), \'</em>';
150                 }
151             }
152             else {
153                 return loc( $Ticket->Status );
154             }
155
156           }
157     },
158     Priority => {
159         attribute => 'Priority',
160         value     => sub { return $_[0]->Priority }
161     },
162     InitialPriority => {
163         attribute => 'InitialPriority',
164         name => 'Initial Priority',
165         value     => sub { return $_[0]->InitialPriority }
166     },
167     FinalPriority => {
168         attribute => 'FinalPriority',
169         name => 'Final Priority',
170         value     => sub { return $_[0]->FinalPriority }
171     },
172     EffectiveId => {
173         attribute => 'EffectiveId',
174         value     => sub { return $_[0]->EffectiveId }
175     },
176     Type => {
177         attribute => 'Type',
178         value     => sub { return $_[0]->Type }
179     },
180     TimeWorked => {
181         attribute => 'TimeWorked',
182         title => 'Time Worked',
183         value     => sub { return $_[0]->TimeWorked }
184     },
185     TimeLeft => {
186         attribute => 'TimeLeft',
187         title     => 'Time Left',
188         value     => sub { return $_[0]->TimeLeft }
189     },
190     TimeEstimated => {
191         attribute => 'TimeEstimated',
192         title => 'Time Estimated',
193         value     => sub { return $_[0]->TimeEstimated }
194     },
195     Requestors => {
196         value => sub { return $_[0]->Requestors->MemberEmailAddressesAsString }
197     },
198     Cc => {
199         value => sub { return $_[0]->Cc->MemberEmailAddressesAsString }
200     },
201     AdminCc => {
202         value => sub { return $_[0]->AdminCc->MemberEmailAddressesAsString }
203     },
204     StartsRelative => {
205         title     => 'Starts',
206         attribute => 'Starts',
207         value     => sub { return $_[0]->StartsObj->AgeAsString }
208     },
209     StartedRelative => {
210         title     => 'Started',
211         attribute => 'Started',
212         value     => sub { return $_[0]->StartedObj->AgeAsString }
213     },
214     CreatedRelative => {
215         title     => 'Created',
216         attribute => 'Created',
217         value     => sub { return $_[0]->CreatedObj->AgeAsString }
218     },
219     LastUpdatedRelative => {
220         title     => 'Last Updated',
221         attribute => 'LastUpdated',
222         value     => sub { return $_[0]->LastUpdatedObj->AgeAsString }
223     },
224     ToldRelative => {
225         title     => 'Told',
226         attribute => 'Told',
227         value     => sub { return $_[0]->ToldObj->AgeAsString }
228     },
229     DueRelative => {
230         title     => 'Due',
231         attribute => 'Due',
232         value     => sub { 
233             my $date = $_[0]->DueObj;
234             if ($date && $date->Unix > 0 && $date->Unix < time()) {
235                 return (\'<span class="overdue">' , $date->AgeAsString , \'</span>');
236             } else {
237                 return $date->AgeAsString;
238             }
239         }
240     },
241     ResolvedRelative => {
242         title     => 'Resolved',
243         attribute => 'Resolved',
244         value     => sub { return $_[0]->ResolvedObj->AgeAsString }
245     },
246     Starts => {
247         attribute => 'Starts',
248         value     => sub { return $_[0]->StartsObj->AsString }
249     },
250     Started => {
251         attribute => 'Started',
252         value     => sub { return $_[0]->StartedObj->AsString }
253     },
254     Created => {
255         attribute => 'Created',
256         value     => sub { return $_[0]->CreatedObj->AsString }
257     },
258     CreatedBy => {
259         attribute => 'CreatedBy',
260         title => 'Created By',
261         value     => sub { return $_[0]->CreatorObj->Name }
262     },
263     LastUpdated => {
264         attribute => 'LastUpdated',
265         title     => 'Last Updated',
266         value     => sub { return $_[0]->LastUpdatedObj->AsString }
267     },
268     LastUpdatedBy => {
269         attribute => 'LastUpdatedBy',
270         title     => 'Last Updated By',
271         value     => sub { return $_[0]->LastUpdatedByObj->Name }
272     },
273     Told => {
274         attribute => 'Told',
275         value     => sub { return $_[0]->ToldObj->AsString }
276     },
277     Due => {
278         attribute => 'Due',
279         value     => sub { return $_[0]->DueObj->AsString }
280     },
281     Resolved => {
282         attribute => 'Resolved',
283         value     => sub { return $_[0]->ResolvedObj->AsString }
284     },
285
286     # Everything from LINKTYPEMAP
287     (map {
288         $_ => { value => LinkCallback( $_ ) }
289     } keys %RT::Ticket::LINKTYPEMAP),
290
291     '_CLASS' => {
292         value => sub { return $_[1] % 2 ? 'oddline' : 'evenline' }
293     },
294
295 };
296 </%ONCE>
297 <%init>
298 $m->comp( '/Elements/Callback', COLUMN_MAP    => $COLUMN_MAP, _CallbackName => 'ColumnMap');
299 return ColumnMap($Name, $Attr);
300 </%init>