rt 4.2.13 ticket#13852
[freeside.git] / rt / share / html / Admin / Elements / EditScrips
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2016 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 <& /Elements/ListActions, actions => \@actions &>
49
50 <form action="Scrips.html" method="post">
51 <input type="hidden" class="hidden" name="id" value="<% $id %>" />
52
53 <h2><&|/l&>Scrips</&></h2>
54 <div class="admin-hint"><&|/l&>Scrips normally run after each individual change to a ticket.</&></div>
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>
62 <div class="admin-hint"><&|/l&>Batch scrips run after a set of related changes to a ticket.</&></div>
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);
77 <& /Elements/CollectionList,
78     Rows => $Rows,
79     Page => 1,
80     %ARGS,
81     Collection => $scrips,
82     Format     => $Format,
83     DisplayFormat => "__CheckBox.{AddScrip}__, $Format",
84     AllowSorting => 1,
85     PassArguments => [ qw(Format Rows Page Order OrderBy id) ],
86 &>
87 % unless ( $scrips->Count ) {
88 <p><i><&|/l&>(No scrips)</&></i></p>
89 % }
90
91 <& SelectStageForAdded &>
92
93 <& /Elements/Submit,
94     Name => 'AddScrips',
95     Caption => loc("Apply selected scrips"),
96     Label => loc("Update"),
97 &>
98
99 </form>
100
101 <%init>
102 my (@actions);
103
104 if ( $id ) {
105     my $QueueObj = RT::Queue->new($session{'CurrentUser'});
106     $QueueObj->Load( $id );
107     Abort(loc("Couldn't load queue #[_1]", $id)) unless $QueueObj->id;
108 }
109 $id ||= 0;
110
111 my $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'};
124 my $Rows = RT->Config->Get('AdminSearchResultRows')->{'Scrips'} || 50;
125 my $DisplayFormat = $Format;
126 if ( $id ) {
127     $DisplayFormat = "__RemoveCheckBox__, $DisplayFormat";
128 } else {
129     $DisplayFormat = "__CheckBox.{RemoveScrip}__, $DisplayFormat";
130 }
131 $DisplayFormat .= ", __Move.{$id}__";
132
133 my %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
143 if ( $RemoveScrips ) {
144     foreach my $sid ( @RemoveScrip ) {
145         my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
146         $scrip->Load( $sid );
147         next unless $scrip->id;
148
149         my ($status, $msg) = $scrip->RemoveFromObject( $id );
150         push @actions, $msg;
151     }
152 }
153
154 if ( $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     }
163 }
164
165 if ( $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;
171     }
172 }
173
174 if ( $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;
179         push @actions, $msg;
180     }
181 }
182
183 </%init>
184
185 <%ARGS>
186 $id => undef
187 $title => undef
188 $Format => undef
189
190 @RemoveScrip => ()
191 $RemoveScrips => undef
192
193 @AddScrip => ()
194 $AddScrips => undef
195 $Stage     => 'TransactionCreate'
196
197 $MoveScripUp => undef
198 $MoveScripDown => undef
199
200 </%ARGS>