Master to 4.2.8
[usit-rt.git] / share / html / Elements / RT__CustomField / ColumnMap
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
320f0092 5%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
84fb5b46
MKG
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$Name => undef
50$Attr => undef
af59614d 51$GenericMap => {}
84fb5b46
MKG
52</%ARGS>
53<%ONCE>
54my $COLUMN_MAP = {
84fb5b46 55 Disabled => {
c33a4027 56 title => 'Status', # loc
84fb5b46
MKG
57 attribute => 'Disabled',
58 value => sub { return $_[0]->Disabled? $_[0]->loc('Disabled'): $_[0]->loc('Enabled') },
59 },
60
61 map(
62 { my $c = $_; $c => {
63 title => $c, attribute => $c,
af59614d 64 value => sub { return $_[0]->$c() },
84fb5b46
MKG
65 } }
66 qw(Name Description Type LookupType Pattern)
67 ),
68 map(
69 { my $c = $_; my $short = $c; $short =~ s/^Friendly//;
70 $c => {
71 title => $short, attribute => $short,
af59614d 72 value => sub { return $_[0]->$c() },
84fb5b46
MKG
73 } }
74 qw(FriendlyLookupType FriendlyType FriendlyPattern)
75 ),
76 MaxValues => {
77 title => 'MaxValues', # loc
af59614d
MKG
78 attribute => 'MaxValues',
79 value => sub {
84fb5b46
MKG
80 my $v = $_[0]->MaxValues;
81 return !$v ? $_[0]->loc('unlimited') : $v == 0 ? $_[0]->loc('one') : $v;
82 },
83 },
af59614d
MKG
84 AddedTo => {
85 title => 'Added', # loc
86 value => sub {
87 if ( $_[0]->IsGlobal ) {
84fb5b46
MKG
88 return $_[0]->loc('Global');
89 }
90
af59614d 91 my $collection = $_[0]->AddedTo;
84fb5b46
MKG
92 return '' unless $collection;
93
94 $collection->RowsPerPage(10);
95
96 my $found = 0;
97 my $res = '';
98 while ( my $record = $collection->Next ) {
99 $res .= ', ' if $res;
100
101 my $id = '';
320f0092 102 $id = $record->Name if $record->_Accessible('Name','read');
84fb5b46
MKG
103 $id ||= "#". $record->id;
104 $res .= $id;
105
106 $found++;
107 }
108 $res .= ', ...' if $found >= 10;
109 return $res;
110 },
111
112 },
113 RemoveCheckBox => {
114 title => sub {
115 my $name = 'RemoveCustomField';
dab09ea8 116 my $checked = $DECODED_ARGS->{ $name .'All' }? 'checked="checked"': '';
84fb5b46
MKG
117
118 return \qq{<input type="checkbox" name="}, $name, \qq{All" value="1" $checked
af59614d 119 onclick="setCheckbox(this, },
84fb5b46 120 $m->interp->apply_escapes($name,'j'),
af59614d 121 \qq{)" />};
84fb5b46
MKG
122 },
123 value => sub {
124 my $id = $_[0]->id;
af59614d 125 return '' if $_[0]->IsGlobal;
84fb5b46
MKG
126
127 my $name = 'RemoveCustomField';
dab09ea8 128 my $arg = $DECODED_ARGS->{ $name };
84fb5b46
MKG
129
130 my $checked = '';
131 if ( $arg && ref $arg ) {
132 $checked = 'checked="checked"' if grep $_ == $id, @$arg;
133 }
134 elsif ( $arg ) {
135 $checked = 'checked="checked"' if $arg == $id;
136 }
137 return \qq{<input type="checkbox" name="}, $name, \qq{" value="$id" $checked />}
138 },
139 },
140 MoveCF => {
141 title => 'Move',
142 value => sub {
143 my $id = $_[0]->id;
144
145 my $context = $_[2] || 0;
af59614d 146 return '' unless $_[0]->IsAdded( $context );
84fb5b46
MKG
147
148 my $name = 'MoveCustomField';
149 my $args = $m->caller_args( 1 );
150 my @pass = ref $args->{'PassArguments'}
151 ? @{$args->{'PassArguments'}}
152 : ($args->{'PassArguments'});
153 my %pass = map { $_ => $args->{$_} } grep exists $args->{$_}, @pass;
154
155 my $uri = RT->Config->Get('WebPath') . $m->request_path;
156
157 my @res = (
158 \'<a href="',
159 $uri .'?'. $m->comp("/Elements/QueryString", %pass, MoveCustomFieldUp => $id ),
403d7b0b 160 \'">', loc('~[Up~]'), \'</a>',
84fb5b46
MKG
161 \' <a href="',
162 $uri .'?'. $m->comp("/Elements/QueryString", %pass, MoveCustomFieldDown => $id ),
403d7b0b 163 \'">', loc('~[Down~]'), \'</a>'
84fb5b46
MKG
164 );
165
166 return @res;
167 },
168 },
169};
170
af59614d
MKG
171$COLUMN_MAP->{'AppliedTo'} = $COLUMN_MAP->{'AddedTo'};
172
84fb5b46
MKG
173</%ONCE>
174<%INIT>
af59614d 175$m->callback( GenericMap => $GenericMap, COLUMN_MAP => $COLUMN_MAP, CallbackName => 'ColumnMap', CallbackOnce => 1 );
84fb5b46
MKG
176return GetColumnMapEntry( Map => $COLUMN_MAP, Name => $Name, Attribute => $Attr );
177</%INIT>