no need for FS calendar buttons in RT 4.2
[freeside.git] / rt / share / html / Elements / ColumnMap
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2017 Best Practical Solutions, LLC
6 %#                                          <sales@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 $Class => 'RT__Ticket'
50 $Name
51 $Attr  => undef
52 </%ARGS>
53 <%ONCE>
54
55 use Scalar::Util;
56
57 # This is scary and should totally be refactored -- jesse
58 my ($COLUMN_MAP, $WCOLUMN_MAP);
59 $WCOLUMN_MAP = $COLUMN_MAP = {
60     id => {
61         attribute => 'id',
62         title     => '#', # loc
63         align     => 'right',
64         value     => sub { return $_[0]->id }
65     },
66
67     Created => {
68         attribute => 'Created',
69         title     => 'Created', # loc
70         value     => sub { return $_[0]->CreatedObj },
71     },
72     CreatedRelative => {
73         attribute => 'Created',
74         title     => 'Created', # loc
75         value     => sub { return $_[0]->CreatedObj->AgeAsString }
76     },
77     CreatedBy => {
78         attribute => 'Creator',
79         title     => 'Created By', # loc
80         value     => sub { return $_[0]->CreatorObj->Name }
81     },
82     LastUpdated => {
83         attribute => 'LastUpdated',
84         title     => 'Last Updated', # loc
85         value     => sub { return $_[0]->LastUpdatedObj },
86     },
87     LastUpdatedRelative => {
88         attribute => 'LastUpdated',
89         title     => 'Last Updated', # loc
90         value     => sub { return $_[0]->LastUpdatedObj->AgeAsString }
91     },
92     LastUpdatedBy => {
93         attribute => 'LastUpdatedBy',
94         title     => 'Last Updated By', # loc
95         value     => sub { return $_[0]->LastUpdatedByObj->Name }
96     },
97
98     CustomField => {
99         attribute => sub { return shift @_ },
100         title     => sub { return pop @_ },
101         value     => sub {
102             my $self = $WCOLUMN_MAP->{CustomField};
103             my $cf   = $self->{load}->(@_);
104             return unless $cf->Id;
105             return $self->{render}->( $cf, $cf->ValuesForObject($_[0])->ItemsArrayRef );
106         },
107         load      => sub {
108             # Cache the CF object on a per-request basis, to avoid
109             # having to load it for every row
110             my $key = join("-","CF",
111                            $_[0]->CustomFieldLookupType,
112                            $_[0]->CustomFieldLookupId,
113                            $_[-1]);
114
115             my $cf = $m->notes($key);
116             unless ($cf) {
117                 $cf = $_[0]->LoadCustomFieldByIdentifier($_[-1]);
118                 RT->Logger->debug("Unable to load $_[-1] for ".$_[0]->CustomFieldLookupType." ".$_[0]->CustomFieldLookupId)
119                     unless $cf->Id;
120                 $m->notes($key, $cf);
121             }
122
123             return $cf;
124           },
125           render    => sub {
126             my ($cf, $ocfvs) = @_;
127             my $comp = $m->comp_exists("/Elements/ShowCustomField".$cf->Type)
128                      ? "/Elements/ShowCustomField".$cf->Type
129                      : undef;
130
131             my @values = map {
132                 $comp
133                     ? \($m->scomp( $comp, Object => $_ ))
134                     : $_->Content
135             } @$ocfvs;
136
137             if (@values > 1) {
138                 for my $value (splice @values) {
139                     push @values, \"<li>", $value, \"</li> \n";
140                 }
141                 @values = (\"<ul class='cf-values'>", @values, \"</ul>");
142             }
143             return @values;
144         },
145     },
146
147     CheckBox => {
148         title => sub {
149             my $name = $_[1] || 'SelectedTickets';
150             my $checked = $DECODED_ARGS->{ $name .'All' }? 'checked="checked"': '';
151
152             return \qq{<input type="checkbox" name="}, $name, \qq{All" value="1" $checked
153                               onclick="setCheckbox(this, },
154                               $m->interp->apply_escapes($name,'j'),
155                               \qq{)" />};
156         },
157         value => sub {
158             my $id = $_[0]->id;
159
160             my $name = $_[2] || 'SelectedTickets';
161             return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" checked="checked" />}
162                 if $DECODED_ARGS->{ $name . 'All'};
163
164             my $arg = $DECODED_ARGS->{ $name };
165             my $checked = '';
166             if ( $arg && ref $arg ) {
167                 $checked = 'checked="checked"' if grep $_ == $id, grep { defined and length } @$arg;
168             }
169             elsif ( $arg ) {
170                 $checked = 'checked="checked"' if $arg == $id;
171             }
172             return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" $checked />}
173         },
174     },
175     RadioButton => {
176         title => \'&nbsp;',
177         value => sub {
178             my $id = $_[0]->id;
179
180             my $name = $_[2] || 'SelectedTicket';
181             my $arg = $DECODED_ARGS->{ $name };
182             my $checked = '';
183             $checked = 'checked="checked"' if $arg && $arg == $id;
184             return \qq{<input type="radio" name="}, $name, \qq{" value="$id" $checked />};
185         },
186     },
187     (map {
188         my $value = RT->Config->Get($_);
189         $_ => { value => sub { return \$value } };
190     
191     } qw(WebPath WebBaseURL WebURL)),
192     WebRequestPath    => { value => sub { substr( $m->request_path, 1 ) } },
193     WebRequestPathDir => { value => sub { substr( $m->request_comp->dir_path, 1 ) } },
194     WebHomePath       => {
195         value => sub {
196             my $path = RT->Config->Get("WebPath");
197             if (not $session{CurrentUser}->Privileged) {
198                 $path .= "/SelfService";
199             }
200             return \$path;
201         },
202     },
203     CurrentUser       => { value => sub { $session{CurrentUser}->id } },
204     CurrentUserName   => { value => sub { $session{CurrentUser}->Name } },
205 };
206
207 $COLUMN_MAP->{'CF'} = $COLUMN_MAP->{'CustomField'};
208
209 Scalar::Util::weaken($WCOLUMN_MAP);
210
211 my $ROLE_MAP = {};
212
213 </%ONCE>
214 <%INIT>
215 $m->callback( COLUMN_MAP => $COLUMN_MAP, CallbackName => 'Once', CallbackOnce => 1 );
216
217 my $generic_with_roles;
218
219 # Add in roles
220 my $RecordClass = $Class;
221 $RecordClass =~ s/_/:/g;
222 if ($RecordClass->DOES("RT::Record::Role::Roles")) {
223     unless ($ROLE_MAP->{$RecordClass}) {
224         for my $role ($RecordClass->Roles) {
225             my $attrs = $RecordClass->Role($role);
226             $ROLE_MAP->{$RecordClass}{$role} = {
227                 title => $role,
228                 attribute => $attrs->{Column} || "$role.EmailAddress",
229                 value => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->RoleGroup($role) ) ) },
230             };
231             $ROLE_MAP->{$RecordClass}{$role . "s"} = $ROLE_MAP->{$RecordClass}{$role}
232                 unless $attrs->{Single};
233         }
234     }
235     $generic_with_roles = { %{$COLUMN_MAP}, %{$ROLE_MAP->{$RecordClass}} };
236 } else {
237     $generic_with_roles = { %{$COLUMN_MAP} };
238 }
239
240 $m->callback( COLUMN_MAP => $generic_with_roles );
241
242 # first deal with class specific things
243 if (RT::Interface::Web->ComponentPathIsSafe($Class) and $m->comp_exists("/Elements/$Class/ColumnMap")) {
244     my $class_map = $m->comp("/Elements/$Class/ColumnMap", Attr => $Attr, Name => $Name, GenericMap => $generic_with_roles );
245     return $class_map if defined $class_map;
246 }
247
248 return GetColumnMapEntry( Map => $generic_with_roles, Name => $Name, Attribute => $Attr );
249
250 </%INIT>