import rt 3.2.2
[freeside.git] / rt / html / Elements / RT__Ticket / ColumnMap
1 %# BEGIN LICENSE BLOCK;
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
10 %# from www.gnu.org.
11 %# 
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 %# General Public License for more details.
16 %# 
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24
25 <%ARGS>
26 $Name => undef
27 $Attr => undef
28 </%ARGS>
29
30 <%perl>
31 return ColumnMap($Name, $Attr);
32 </%perl>
33
34 <%INIT>
35 our ( $COLUMN_MAP, $CUSTOM_FIELD_MAP );
36
37 sub ColumnMap {
38     my $name = shift;
39     my $attr = shift;
40
41     # First deal with the simple things from the map
42     if ( $COLUMN_MAP->{$name} ) {
43         return ( $COLUMN_MAP->{$name}->{$attr} );
44     }
45
46     # now, let's deal with harder things, like Custom Fields
47
48     elsif ( $name =~ /^(?:CF|CustomField).(.*)$/ ) {
49         my $field = $1;
50         my $cf;
51         if ( $CUSTOM_FIELD_MAP->{$field} ) {
52             $cf = $CUSTOM_FIELD_MAP->{$field};
53         }
54         else {
55
56             $cf = RT::CustomField->new( $session{'CurrentUser'} );
57
58             if ( $field =~ /^(.+?)\.{(.+)}$/ ) {
59                 $cf->LoadByNameAndQueue( Queue => $1, Name => $2 );
60             }
61             else {
62                 $field = $1 if $field =~ /^{(.+)}$/;    # trim { }
63                 $cf->LoadByNameAndQueue( Queue => "0", Name => $field );
64             }
65             $CUSTOM_FIELD_MAP->{$field} = $cf if ( $cf->id );
66         }
67
68         unless ( $cf->id ) {
69             return undef;
70         }
71
72         if ( $attr eq 'attribute' ) {
73             return (undef);
74         }
75         elsif ( $attr eq 'title' ) {
76             return ( $cf->Name );
77         }
78         elsif ( $attr eq 'value' ) {
79             my $value = eval "sub {
80                     my \$values = \$_[0]->CustomFieldValues('" . $cf->id . "');
81                     return ( join( ', ', map { \$_->Content } \@{ \$values->ItemsArrayRef } ))
82                   }" || die $@;
83             return ($value);
84         }
85     }
86 }
87
88 $COLUMN_MAP = {
89     QueueName => {
90         attribute => 'Queue',
91         title     => 'Queue',
92         value     => sub { return $_[0]->QueueObj->Name }
93     },
94     OwnerName => {
95         title     => 'Owner',
96         attribute => 'Owner',
97         value     => sub { return $_[0]->OwnerObj->Name }
98     },
99     id => {
100         attribute => 'id',
101         align     => 'right',
102         value     => sub { return $_[0]->id }
103     },
104     Status => {
105         attribute => 'Status',
106         value     => sub { return $_[0]->Status }
107     },
108     Subject => {
109         attribute => 'Subject',
110         value => sub { return $_[0]->Subject || "(" . loc('No subject') . ")" }
111     },
112     ExtendedStatus => {
113         title     => 'Status',
114         attribute => 'Status',
115         value     => sub {
116             my $Ticket = shift;
117
118             if ( $Ticket->HasUnresolvedDependencies ) {
119                 if (   $Ticket->HasUnresolvedDependencies( Type => 'approval' )
120                     or $Ticket->HasUnresolvedDependencies( Type => 'code' ) )
121                 {
122                     return "<em>" . loc('(pending approval)') . "</em>";
123                 }
124                 else {
125                     return "<em>" . loc('(pending other Collection)') . "</em>";
126                 }
127             }
128             else {
129                 return loc( $Ticket->Status );
130             }
131
132           }
133     },
134     Priority => {
135         attribute => 'Priority',
136         value     => sub { return $_[0]->Priority }
137     },
138     InitialPriority => {
139         attribute => 'InitialPriority',
140         value     => sub { return $_[0]->InitialPriority }
141     },
142     FinalPriority => {
143         attribute => 'FinalPriority',
144         value     => sub { return $_[0]->FinalPriority }
145     },
146     EffectiveId => {
147         attribute => 'EffectiveId',
148         value     => sub { return $_[0]->EffectiveId }
149     },
150     Type => {
151         attribute => 'Type',
152         value     => sub { return $_[0]->Type }
153     },
154     TimeWorked => {
155         attribute => 'TimeWorked',
156         value     => sub { return $_[0]->TimeWorked }
157     },
158     TimeLeft => {
159         attribute => 'TimeLeft',
160         value     => sub { return $_[0]->TimeLeft }
161     },
162     TimeEstimated => {
163         attribute => 'TimeEstimated',
164         value     => sub { return $_[0]->TimeEstimated }
165     },
166     Requestors => {
167         value => sub { return $_[0]->Requestors->MemberEmailAddressesAsString }
168     },
169     Cc => {
170         value => sub { return $_[0]->Cc->MemberEmailAddressesAsString }
171     },
172     AdminCc => {
173         value => sub { return $_[0]->AdminCc->MemberEmailAddressesAsString }
174     },
175     StartsRelative => {
176         title     => 'Starts',
177         attribute => 'Starts',
178         value     => sub { return $_[0]->StartsObj->AgeAsString }
179     },
180     StartedRelative => {
181         title     => 'Started',
182         attribute => 'Started',
183         value     => sub { return $_[0]->StartedObj->AgeAsString }
184     },
185     CreatedRelative => {
186         title     => 'Created',
187         attribute => 'Created',
188         value     => sub { return $_[0]->CreatedObj->AgeAsString }
189     },
190     LastUpdatedRelative => {
191         title     => 'LastUpdated',
192         attribute => 'LastUpdated',
193         value     => sub { return $_[0]->LastUpdatedObj->AgeAsString }
194     },
195     ToldRelative => {
196         title     => 'Told',
197         attribute => 'Told',
198         value     => sub { return $_[0]->ToldObj->AgeAsString }
199     },
200     DueRelative => {
201         title     => 'Due',
202         attribute => 'Due',
203         value     => sub { 
204             my $date = $_[0]->DueObj;
205             if ($date && $date->Unix > 0 && $date->Unix < time()) {
206                 return '<span class="overdue">' . $date->AgeAsString . '</span>';
207             } else {
208                 return $date->AgeAsString;
209             }
210         }
211     },
212     ResolvedRelative => {
213         title     => 'Resolved',
214         attribute => 'Resolved',
215         value     => sub { return $_[0]->ResolvedObj->AgeAsString }
216     },
217     Starts => {
218         attribute => 'Starts',
219         value     => sub { return $_[0]->StartsObj->AsString }
220     },
221     Started => {
222         attribute => 'Started',
223         value     => sub { return $_[0]->StartedObj->AsString }
224     },
225     Created => {
226         attribute => 'Created',
227         value     => sub { return $_[0]->CreatedObj->AsString }
228     },
229     CreatedBy => {
230         attribute => 'CreatedBy',
231         value     => sub { return $_[0]->CreatorObj->Name }
232     },
233     LastUpdated => {
234         attribute => 'LastUpdated',
235         value     => sub { return $_[0]->LastUpdatedObj->AsString }
236     },
237     LastUpdatedBy => {
238         attribute => 'LastUpdatedBy',
239         value     => sub { return $_[0]->LastUpdatedByObj->Name }
240     },
241     Told => {
242         attribute => 'Told',
243         value     => sub { return $_[0]->ToldObj->AsString }
244     },
245     Due => {
246         attribute => 'Due',
247         value     => sub { return $_[0]->DueObj->AsString }
248     },
249     Resolved => {
250         attribute => 'Resolved',
251         value     => sub { return $_[0]->ResolvedObj->AsString }
252     },
253
254     DependedOnBy => {
255         value => sub {
256             my $links = $_[0]->DependedOnBy;
257             return (
258                 join(
259                     "<br>",
260                     map {
261                             '<A HREF="'
262                           . $_->BaseURI->Resolver->HREF . '">'
263                           . ( $_->BaseIsLocal ? $_->LocalBase : $_->Base )
264                           . '</A>'
265                       } @{ $links->ItemsArrayRef }
266                 )
267             );
268           }
269     },
270     Members => {
271         value => sub {
272             my $links = $_[0]->Members;
273             return (
274                 join(
275                     "<br>",
276                     map {
277                             '<A HREF="'
278                           . $_->BaseURI->Resolver->HREF . '">'
279                           . ( $_->BaseIsLocal ? $_->LocalBase : $_->Base )
280                           . '</A>'
281                       } @{ $links->ItemsArrayRef }
282                 )
283             );
284           }
285     },
286     Children => {
287         value => sub {
288             my $links = $_[0]->Members;
289             return (
290                 join(
291                     "<br>",
292                     map {
293                             '<A HREF="'
294                           . $_->BaseURI->Resolver->HREF . '">'
295                           . ( $_->BaseIsLocal ? $_->LocalBase : $_->Base )
296                           . '</A>'
297                       } @{ $links->ItemsArrayRef }
298                 )
299             );
300           }
301     },
302     ReferredToBy => {
303         value => sub {
304             my $links = $_[0]->ReferredToBy;
305             return (
306                 join(
307                     "<br>",
308                     map {
309                             '<A HREF="'
310                           . $_->BaseURI->Resolver->HREF . '">'
311                           . ( $_->BaseIsLocal ? $_->LocalBase : $_->Base )
312                           . '</A>'
313                       } @{ $links->ItemsArrayRef }
314                 )
315             );
316           }
317     },
318
319     DependsOn => {
320         value => sub {
321             my $links = $_[0]->DependsOn;
322             return (
323                 join(
324                     "<br>",
325                     map {
326                             '<A HREF="'
327                           . $_->TargetURI->Resolver->HREF . '">'
328                           . ( $_->TargetIsLocal ? $_->LocalTarget : $_->Target )
329                           . '</A>'
330                       } @{ $links->ItemsArrayRef }
331                 )
332             );
333           }
334     },
335     MemberOf => {
336         value => sub {
337             my $links = $_[0]->MemberOf;
338             return (
339                 join(
340                     "<br>",
341                     map {
342                             '<A HREF="'
343                           . $_->TargetURI->Resolver->HREF . '">'
344                           . ( $_->TargetIsLocal ? $_->LocalTarget : $_->Target )
345                           . '</A>'
346                       } @{ $links->ItemsArrayRef }
347                 )
348             );
349           }
350     },
351     Parents => {
352         value => sub {
353             my $links = $_[0]->MemberOf;
354             return (
355                 join(
356                     "<br>",
357                     map {
358                             '<A HREF="'
359                           . $_->TargetURI->Resolver->HREF . '">'
360                           . ( $_->TargetIsLocal ? $_->LocalTarget : $_->Target )
361                           . '</A>'
362                       } @{ $links->ItemsArrayRef }
363                 )
364             );
365           }
366     },
367     RefersTo => {
368         value => sub {
369             my $links = $_[0]->RefersTo;
370             return (
371                 join(
372                     "<br>",
373                     map {
374                             '<A HREF="'
375                           . $_->TargetURI->Resolver->HREF . '">'
376                           . ( $_->TargetIsLocal ? $_->LocalTarget : $_->Target )
377                           . '</A>'
378                       } @{ $links->ItemsArrayRef }
379                 )
380             );
381           }
382     },
383
384     '_CLASS' => {
385         value => sub { return $_[1] % 2 ? 'oddline' : 'evenline' }
386     },
387
388 };
389
390
391
392 # }}}
393 $m->comp( '/Elements/Callback', COLUMN_MAP    => $COLUMN_MAP, _CallbackName => 'ColumnMap');
394 </%INIT>