rt 4.2.16
[freeside.git] / rt / share / html / Elements / RT__Scrip / ColumnMap
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2019 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 $Name
50 $Attr => undef
51 $GenericMap => {}
52 </%ARGS>
53 <%ONCE>
54 my $COLUMN_MAP = {
55     Queue => {
56         title     => 'Queue', # loc
57         value     => sub {
58             return $_[0]->loc('Global') if $_[0]->IsGlobal;
59             return join(", ", map {$_->Name} @{$_[0]->AddedTo->ItemsArrayRef});
60         },
61     },
62     QueueId => {
63         title     => 'Queue', # loc
64         value     => sub {
65             return 0 if $_[0]->IsGlobal;
66             return join(", ", map {$_->Id} @{$_[0]->AddedTo->ItemsArrayRef});
67         },
68     },
69     From => {
70         title     => 'Queue',
71         value     => sub {
72             my $request_path = $HTML::Mason::Commands::r->path_info;
73             my $queue_id = $m->request_args->{'id'};
74             if ( $request_path =~ m{/Admin/Queues/Scrips\.html} and $queue_id ) {
75                 return '&From=' . $queue_id;
76             } elsif ( $request_path =~ m{/Admin/Global/Scrips\.html} ) {
77                 return '&From=Global';
78             }
79             else {
80                 return q{};
81             }
82         },
83     },
84     Condition => {
85         title     => 'Condition', # loc
86         value     => sub { return $_[0]->loc( $_[0]->ScripConditionObj->Name ) },
87     },
88     Action => {
89         title     => 'Action', # loc
90         value     => sub { return $_[0]->loc( $_[0]->ScripActionObj->Name ) },
91     },
92     Template => {
93         title     => 'Template', # loc
94         value     => sub { return $_[0]->loc( $_[0]->Template ) },
95     },
96     AutoDescription => {
97         title     => 'Condition, Action and Template', # loc
98         value     => sub { return $_[0]->loc( "[_1] [_2] with template [_3]",
99             $_[0]->loc($_[0]->ConditionObj->Name),
100             $_[0]->loc($_[0]->ActionObj->Name),
101             $_[0]->loc($_[0]->Template),
102         ) },
103     },
104     Description => {
105         title     => 'Description', # loc
106         attribute => 'Description',
107         value     => sub { return $_[0]->Description() },
108     },
109     Disabled => {
110         title     => 'Status', # loc
111         attribute => 'Disabled',
112         value     => sub { return $_[0]->Disabled? $_[0]->loc('Disabled'): $_[0]->loc('Enabled') },
113     },
114     RemoveCheckBox => {
115         title => sub {
116             my $name = 'RemoveScrip';
117             my $checked = $m->request_args->{ $name .'All' }? 'checked="checked"': '';
118
119             return \qq{<input type="checkbox" name="${name}All" value="1" $checked
120                               onclick="setCheckbox(this, '$name')" />};
121         },
122         value => sub {
123             my $id = $_[0]->id;
124             return '' if $_[0]->IsGlobal;
125
126             my $name = 'RemoveScrip';
127             my $arg = $m->request_args->{ $name };
128
129             my $checked = '';
130             if ( $arg && ref $arg ) {
131                 $checked = 'checked="checked"' if grep $_ == $id, @$arg;
132             }
133             elsif ( $arg ) {
134                 $checked = 'checked="checked"' if $arg == $id;
135             }
136             return \qq{<input type="checkbox" name="$name" value="$id" $checked />}
137         },
138     },
139     Move => {
140         title => 'Move',   # loc
141         value => sub {
142             my $id = $_[0]->id;
143
144             my $context = $_[2] || 0;
145             return '' unless $_[0]->IsAdded( $context );
146
147             my $name = 'MoveScrip';
148             my $args = $m->caller_args( 1 );
149             my @pass = ref $args->{'PassArguments'}
150                 ? @{$args->{'PassArguments'}}
151                 : ($args->{'PassArguments'});
152             my %pass = map { $_ => $args->{$_} } grep exists $args->{$_}, @pass;
153
154             my $uri = RT->Config->Get('WebPath') . $m->request_path;
155
156             my @res = (
157                 \'<a href="',
158                 $uri .'?'. $m->comp("/Elements/QueryString", %pass, MoveScripUp => $id ),
159                 \'">', loc('[Up]'), \'</a>',
160                 \' <a href="',
161                 $uri .'?'. $m->comp("/Elements/QueryString", %pass, MoveScripDown => $id ),
162                 \'">', loc('[Down]'), \'</a>'
163             );
164
165             return @res;
166         },
167     },
168     Stage => {
169         title => 'Stage', # loc
170         value => sub {
171             my $os = RT::ObjectScrip->new( $_[0]->CurrentUser );
172             my $id = $_[0]->IsGlobal ? 0 : $_[-1];
173             $os->LoadByCols( Scrip =>  $_[0]->id, ObjectId => $id );
174             return $_[0]->loc( $os->FriendlyStage );
175         },
176     },
177 };
178
179 </%ONCE>
180 <%INIT>
181 $m->callback( GenericMap => $GenericMap, COLUMN_MAP => $COLUMN_MAP, CallbackName => 'ColumnMap', CallbackOnce => 1 );
182 return GetColumnMapEntry( Map => $COLUMN_MAP, Name => $Name, Attribute => $Attr );
183 </%INIT>