Master to 4.2.8
[usit-rt.git] / share / html / Admin / Elements / EditScrips
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<& /Elements/ListActions, actions => \@actions &>
49
50<form action="Scrips.html" method="post">
51<input type="hidden" class="hidden" name="id" value="<% $id %>" />
52
af59614d 53<h2><&|/l&>Scrips</&></h2>
320f0092 54<div class="admin-hint"><&|/l&>Scrips normally run after each individual change to a ticket.</&></div>
af59614d
MKG
55% my $scrips = $find_scrips->(Stage => 'TransactionCreate');
56<& /Elements/CollectionList, %common_applied_args, Collection => $scrips &>
57% unless ( $scrips->Count ) {
58<p><i><&|/l&>(No scrips)</&></i></p>
59% }
60
61<h2><&|/l&>Batch scrips</&></h2>
320f0092 62<div class="admin-hint"><&|/l&>Batch scrips run after a set of related changes to a ticket.</&></div>
af59614d
MKG
63% $scrips = $find_scrips->(Stage => 'TransactionBatch');
64<& /Elements/CollectionList, %common_applied_args, Collection => $scrips &>
65% unless ( $scrips->Count ) {
66<p><i><&|/l&>(No scrips)</&></i></p>
67% }
68
69<& /Elements/Submit,
70 Name => 'RemoveScrips',
71 Caption => loc("Un-apply selected scrips"),
72 Label => loc("Update"),
73&>
74
75<h2><&|/l&>Not applied scrips</&></h2>
76% $scrips = $find_scrips->(Added => 0);
84fb5b46 77<& /Elements/CollectionList,
c33a4027 78 Rows => $Rows,
af59614d 79 Page => 1,
84fb5b46 80 %ARGS,
af59614d
MKG
81 Collection => $scrips,
82 Format => $Format,
83 DisplayFormat => "__CheckBox.{AddScrip}__, $Format",
84fb5b46 84 AllowSorting => 1,
af59614d 85 PassArguments => [ qw(Format Rows Page Order OrderBy id) ],
84fb5b46 86&>
af59614d 87% unless ( $scrips->Count ) {
84fb5b46
MKG
88<p><i><&|/l&>(No scrips)</&></i></p>
89% }
af59614d
MKG
90
91<& SelectStageForAdded &>
92
84fb5b46 93<& /Elements/Submit,
af59614d
MKG
94 Name => 'AddScrips',
95 Caption => loc("Apply selected scrips"),
96 Label => loc("Update"),
84fb5b46 97&>
af59614d 98
84fb5b46
MKG
99</form>
100
101<%init>
102my (@actions);
103
84fb5b46 104if ( $id ) {
af59614d 105 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
84fb5b46 106 $QueueObj->Load( $id );
af59614d
MKG
107 Abort(loc("Couldn't load queue #[_1]", $id)) unless $QueueObj->id;
108}
109$id ||= 0;
110
111my $find_scrips = sub {
112 my %args = (Added => 1, @_);
113 my $scrips = RT::Scrips->new($session{'CurrentUser'});
114 $scrips->LimitByStage( $args{'Stage'} )
115 if $args{'Stage'};
116 my $method = $args{'Added'}? 'LimitToAdded' : 'LimitToNotAdded';
117 $scrips->$method(0, $id);
118 $scrips->ApplySortOrder if $args{'Added'};
119 $scrips->FindAllRows;
120 return $scrips;
121};
122
123$Format ||= RT->Config->Get('AdminSearchResultFormat')->{'Scrips'};
c33a4027 124my $Rows = RT->Config->Get('AdminSearchResultRows')->{'Scrips'} || 50;
af59614d
MKG
125my $DisplayFormat = $Format;
126if ( $id ) {
127 $DisplayFormat = "__RemoveCheckBox__, $DisplayFormat";
128} else {
129 $DisplayFormat = "__CheckBox.{RemoveScrip}__, $DisplayFormat";
84fb5b46 130}
af59614d
MKG
131$DisplayFormat .= ", __Move.{$id}__";
132
133my %common_applied_args = (
134 %ARGS,
135 Format => $Format,
136 DisplayFormat => $DisplayFormat,
137 Rows => 0,
138 Page => 1,
139 AllowSorting => 0,
140 PassArguments => [ qw(Format id) ],
141);
142
143if ( $RemoveScrips ) {
144 foreach my $sid ( @RemoveScrip ) {
145 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
146 $scrip->Load( $sid );
147 next unless $scrip->id;
84fb5b46 148
af59614d
MKG
149 my ($status, $msg) = $scrip->RemoveFromObject( $id );
150 push @actions, $msg;
151 }
84fb5b46 152}
af59614d
MKG
153
154if ( $AddScrips ) {
155 foreach my $sid ( @AddScrip ) {
156 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
157 $scrip->Load( $sid );
158 next unless $scrip->id;
159
160 my ($status, $msg) = $scrip->AddToObject( $id, Stage => $Stage );
161 push @actions, $msg;
162 }
84fb5b46
MKG
163}
164
af59614d
MKG
165if ( $MoveScripUp ) {
166 my $scrip = RT::ObjectScrip->new( $session{'CurrentUser'} );
167 $scrip->LoadByCols( Scrip => $MoveScripUp, ObjectId => $id );
168 if ( $scrip->id ) {
169 my ($status, $msg) = $scrip->MoveUp;
170 push @actions, $msg;
84fb5b46 171 }
af59614d
MKG
172}
173
174if ( $MoveScripDown ) {
175 my $scrip = RT::ObjectScrip->new( $session{'CurrentUser'} );
176 $scrip->LoadByCols( Scrip => $MoveScripDown, ObjectId => $id );
177 if ( $scrip->id ) {
178 my ($status, $msg) = $scrip->MoveDown;
84fb5b46
MKG
179 push @actions, $msg;
180 }
181}
af59614d 182
84fb5b46
MKG
183</%init>
184
185<%ARGS>
186$id => undef
187$title => undef
188$Format => undef
af59614d
MKG
189
190@RemoveScrip => ()
191$RemoveScrips => undef
192
193@AddScrip => ()
194$AddScrips => undef
195$Stage => 'TransactionCreate'
196
197$MoveScripUp => undef
198$MoveScripDown => undef
199
84fb5b46 200</%ARGS>