]> git.uio.no Git - usit-rt.git/blob - share/html/Admin/Elements/EditScrips
Upgrade to 4.2.2
[usit-rt.git] / share / html / Admin / Elements / EditScrips
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2014 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 => 50,
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 $DisplayFormat = $Format;
125 if ( $id ) {
126     $DisplayFormat = "__RemoveCheckBox__, $DisplayFormat";
127 } else {
128     $DisplayFormat = "__CheckBox.{RemoveScrip}__, $DisplayFormat";
129 }
130 $DisplayFormat .= ", __Move.{$id}__";
131
132 my %common_applied_args = (
133     %ARGS,
134     Format => $Format,
135     DisplayFormat => $DisplayFormat,
136     Rows => 0,
137     Page => 1,
138     AllowSorting => 0,
139     PassArguments => [ qw(Format id) ],
140 );
141
142 if ( $RemoveScrips ) {
143     foreach my $sid ( @RemoveScrip ) {
144         my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
145         $scrip->Load( $sid );
146         next unless $scrip->id;
147
148         my ($status, $msg) = $scrip->RemoveFromObject( $id );
149         push @actions, $msg;
150     }
151 }
152
153 if ( $AddScrips ) {
154     foreach my $sid ( @AddScrip ) {
155         my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
156         $scrip->Load( $sid );
157         next unless $scrip->id;
158
159         my ($status, $msg) = $scrip->AddToObject( $id, Stage => $Stage );
160         push @actions, $msg;
161     }
162 }
163
164 if ( $MoveScripUp ) {
165     my $scrip = RT::ObjectScrip->new( $session{'CurrentUser'} );
166     $scrip->LoadByCols( Scrip => $MoveScripUp, ObjectId => $id );
167     if ( $scrip->id ) {
168         my ($status, $msg) = $scrip->MoveUp;
169         push @actions, $msg;
170     }
171 }
172
173 if ( $MoveScripDown ) {
174     my $scrip = RT::ObjectScrip->new( $session{'CurrentUser'} );
175     $scrip->LoadByCols( Scrip => $MoveScripDown, ObjectId => $id );
176     if ( $scrip->id ) {
177         my ($status, $msg) = $scrip->MoveDown;
178         push @actions, $msg;
179     }
180 }
181
182 </%init>
183
184 <%ARGS>
185 $id => undef
186 $title => undef
187 $Format => undef
188
189 @RemoveScrip => ()
190 $RemoveScrips => undef
191
192 @AddScrip => ()
193 $AddScrips => undef
194 $Stage     => 'TransactionCreate'
195
196 $MoveScripUp => undef
197 $MoveScripDown => undef
198
199 </%ARGS>