1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2019 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 my ($COLUMN_MAP, $WCOLUMN_MAP);
58 $WCOLUMN_MAP = $COLUMN_MAP = {
63 value => sub { return $_[0]->id }
67 attribute => 'Created',
68 title => 'Created', # loc
69 value => sub { return $_[0]->CreatedObj },
72 attribute => 'Created',
73 title => 'Created', # loc
74 value => sub { return $_[0]->CreatedObj->AgeAsString }
77 attribute => 'Creator',
78 title => 'Created By', # loc
79 value => sub { return $_[0]->CreatorObj->Name }
82 attribute => 'LastUpdated',
83 title => 'Last Updated', # loc
84 value => sub { return $_[0]->LastUpdatedObj },
86 LastUpdatedRelative => {
87 attribute => 'LastUpdated',
88 title => 'Last Updated', # loc
89 value => sub { return $_[0]->LastUpdatedObj->AgeAsString }
92 attribute => 'LastUpdatedBy',
93 title => 'Last Updated By', # loc
94 value => sub { return $_[0]->LastUpdatedByObj->Name }
98 attribute => sub { return shift @_ },
99 title => sub { return pop @_ },
101 my $self = $WCOLUMN_MAP->{CustomField};
102 my $cf = $self->{load}->(@_);
103 return unless $cf->Id;
104 return $self->{render}->( $cf, $cf->ValuesForObject($_[0])->ItemsArrayRef );
107 # Cache the CF object on a per-request basis, to avoid
108 # having to load it for every row
109 my $key = join("-","CF",
110 $_[0]->CustomFieldLookupType,
111 $_[0]->CustomFieldLookupId,
114 my $cf = $m->notes($key);
116 $cf = $_[0]->LoadCustomFieldByIdentifier($_[-1]);
117 RT->Logger->debug("Unable to load $_[-1] for ".$_[0]->CustomFieldLookupType." ".$_[0]->CustomFieldLookupId)
119 $m->notes($key, $cf);
125 my ($cf, $ocfvs) = @_;
126 my $comp = $m->comp_exists("/Elements/ShowCustomField".$cf->Type)
127 ? "/Elements/ShowCustomField".$cf->Type
132 ? \($m->scomp( $comp, Object => $_ ))
137 for my $value (splice @values) {
138 push @values, \"<li>", $value, \"</li> \n";
140 @values = (\"<ul class='cf-values'>", @values, \"</ul>");
148 my $name = $_[1] || 'SelectedTickets';
149 my $checked = $DECODED_ARGS->{ $name .'All' }? 'checked="checked"': '';
151 return \qq{<input type="checkbox" name="}, $name, \qq{All" value="1" $checked
152 onclick="setCheckbox(this, },
153 $m->interp->apply_escapes($name,'j'),
159 my $name = $_[2] || 'SelectedTickets';
160 return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" checked="checked" />}
161 if $DECODED_ARGS->{ $name . 'All'};
163 my $arg = $DECODED_ARGS->{ $name };
165 if ( $arg && ref $arg ) {
166 $checked = 'checked="checked"' if grep $_ == $id, grep { defined and length } @$arg;
169 $checked = 'checked="checked"' if $arg == $id;
171 return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" $checked />}
179 my $name = $_[2] || 'SelectedTicket';
180 my $arg = $DECODED_ARGS->{ $name };
182 $checked = 'checked="checked"' if $arg && $arg == $id;
183 return \qq{<input type="radio" name="}, $name, \qq{" value="$id" $checked />};
187 my $value = RT->Config->Get($_);
188 $_ => { value => sub { return \$value } };
190 } qw(WebPath WebBaseURL WebURL)),
191 WebRequestPath => { value => sub { substr( $m->request_path, 1 ) } },
192 WebRequestPathDir => { value => sub { substr( $m->request_comp->dir_path, 1 ) } },
195 my $path = RT->Config->Get("WebPath");
196 if (not $session{CurrentUser}->Privileged) {
197 $path .= "/SelfService";
202 CurrentUser => { value => sub { $session{CurrentUser}->id } },
203 CurrentUserName => { value => sub { $session{CurrentUser}->Name } },
206 $COLUMN_MAP->{'CF'} = $COLUMN_MAP->{'CustomField'};
208 Scalar::Util::weaken($WCOLUMN_MAP);
214 $m->callback( COLUMN_MAP => $COLUMN_MAP, CallbackName => 'Once', CallbackOnce => 1 );
216 my $generic_with_roles;
219 my $RecordClass = $Class;
220 $RecordClass =~ s/_/:/g;
221 if ($RecordClass->DOES("RT::Record::Role::Roles")) {
222 unless ($ROLE_MAP->{$RecordClass}) {
223 for my $role ($RecordClass->Roles) {
224 my $attrs = $RecordClass->Role($role);
225 $ROLE_MAP->{$RecordClass}{$role} = {
227 attribute => $attrs->{Column} || "$role.EmailAddress",
228 value => sub { return \($m->scomp("/Elements/ShowPrincipal", Object => $_[0]->RoleGroup($role) ) ) },
230 $ROLE_MAP->{$RecordClass}{$role . "s"} = $ROLE_MAP->{$RecordClass}{$role}
231 unless $attrs->{Single};
234 $generic_with_roles = { %{$COLUMN_MAP}, %{$ROLE_MAP->{$RecordClass}} };
236 $generic_with_roles = { %{$COLUMN_MAP} };
239 $m->callback( COLUMN_MAP => $generic_with_roles );
241 # first deal with class specific things
242 if (RT::Interface::Web->ComponentPathIsSafe($Class) and $m->comp_exists("/Elements/$Class/ColumnMap")) {
243 my $class_map = $m->comp("/Elements/$Class/ColumnMap", Attr => $Attr, Name => $Name, GenericMap => $generic_with_roles );
244 return $class_map if defined $class_map;
247 return GetColumnMapEntry( Map => $generic_with_roles, Name => $Name, Attribute => $Attr );