1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 %# CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 %# END BPS TAGGED BLOCK }}}
49 $Class => 'RT__Ticket'
57 # This is scary and should totally be refactored -- jesse
58 my ($COLUMN_MAP, $WCOLUMN_MAP);
59 $WCOLUMN_MAP = $COLUMN_MAP = {
64 value => sub { return $_[0]->id }
68 attribute => 'Created',
69 title => 'Created', # loc
70 value => sub { return $_[0]->CreatedObj },
73 attribute => 'Created',
74 title => 'Created', # loc
75 value => sub { return $_[0]->CreatedObj->AgeAsString }
78 attribute => 'Creator',
79 title => 'Created By', # loc
80 value => sub { return $_[0]->CreatorObj->Name }
83 attribute => 'LastUpdated',
84 title => 'Last Updated', # loc
85 value => sub { return $_[0]->LastUpdatedObj },
87 LastUpdatedRelative => {
88 attribute => 'LastUpdated',
89 title => 'Last Updated', # loc
90 value => sub { return $_[0]->LastUpdatedObj->AgeAsString }
93 attribute => 'LastUpdatedBy',
94 title => 'Last Updated By', # loc
95 value => sub { return $_[0]->LastUpdatedByObj->Name }
99 attribute => sub { return shift @_ },
100 title => sub { return pop @_ },
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 );
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,
115 my $cf = $m->notes($key);
117 $cf = $_[0]->LoadCustomFieldByIdentifier($_[-1]);
118 RT->Logger->notice("Unable to load $_[-1] for ".$_[0]->CustomFieldLookupType." ".$_[0]->CustomFieldLookupId)
120 $m->notes($key, $cf);
126 my ($cf, $ocfvs) = @_;
127 my $comp = $m->comp_exists("/Elements/ShowCustomField".$cf->Type)
128 ? "/Elements/ShowCustomField".$cf->Type
133 ? \($m->scomp( $comp, Object => $_ ))
138 for my $value (splice @values) {
139 push @values, \"<li>", $value, \"</li> \n";
141 @values = (\"<ul class='cf-values'>", @values, \"</ul>");
149 my $name = $_[1] || 'SelectedTickets';
150 my $checked = $DECODED_ARGS->{ $name .'All' }? 'checked="checked"': '';
152 return \qq{<input type="checkbox" name="}, $name, \qq{All" value="1" $checked
153 onclick="setCheckbox(this, },
154 $m->interp->apply_escapes($name,'j'),
160 my $name = $_[2] || 'SelectedTickets';
161 return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" checked="checked" />}
162 if $DECODED_ARGS->{ $name . 'All'};
164 my $arg = $DECODED_ARGS->{ $name };
166 if ( $arg && ref $arg ) {
167 $checked = 'checked="checked"' if grep $_ == $id, grep { defined and length } @$arg;
170 $checked = 'checked="checked"' if $arg == $id;
172 return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" $checked />}
180 my $name = $_[2] || 'SelectedTicket';
181 my $arg = $DECODED_ARGS->{ $name };
183 $checked = 'checked="checked"' if $arg && $arg == $id;
184 return \qq{<input type="radio" name="}, $name, \qq{" value="$id" $checked />};
188 my $value = RT->Config->Get($_);
189 $_ => { value => sub { return \$value } };
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 ) } },
196 my $path = RT->Config->Get("WebPath");
197 if (not $session{CurrentUser}->Privileged) {
198 $path .= "/SelfService";
203 CurrentUser => { value => sub { $session{CurrentUser}->id } },
204 CurrentUserName => { value => sub { $session{CurrentUser}->Name } },
207 $COLUMN_MAP->{'CF'} = $COLUMN_MAP->{'CustomField'};
209 Scalar::Util::weaken($WCOLUMN_MAP);
215 $m->callback( COLUMN_MAP => $COLUMN_MAP, CallbackName => 'Once', CallbackOnce => 1 );
217 my $generic_with_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} = {
228 attribute => $attrs->{Column} || "$role.EmailAddress",
229 value => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->RoleGroup($role) ) ) },
231 $ROLE_MAP->{$RecordClass}{$role . "s"} = $ROLE_MAP->{$RecordClass}{$role}
232 unless $attrs->{Single};
235 $generic_with_roles = { %{$COLUMN_MAP}, %{$ROLE_MAP->{$RecordClass}} };
237 $generic_with_roles = { %{$COLUMN_MAP} };
240 $m->callback( COLUMN_MAP => $generic_with_roles );
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;
248 return GetColumnMapEntry( Map => $generic_with_roles, Name => $Name, Attribute => $Attr );