RT 4.0.13
[freeside.git] / rt / share / html / Admin / Elements / EditScrip
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2013 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 method="post" action="Scrip.html" id="ModifyScrip" name="ModifyScrip">
51 <input type="hidden" class="hidden" name="id" value="<% $id %>" />
52 <input type="hidden" class="hidden" name="Queue" value="<% $Queue %>" />
53
54 <&| /Widgets/TitleBox, title => loc('Scrip Fields') &>
55 <table>
56
57 <tr><td align="right"><&|/l&>Description</&>:</td><td>
58 <tr><td class="label"><&|/l&>Description</&>:</td><td class="value">\
59 <input name="Scrip-<% $id %>-Description" \
60     size="60" \
61     value="<% $ARGS{"Scrip-$id-Description"} || $scrip->Description || '' %>" />
62 </td></tr>
63
64 <tr><td class="label"><&|/l&>Condition</&>:</td><td class="value">\
65 <& /Admin/Elements/SelectScripCondition,
66     Name => "Scrip-$id-ScripCondition",
67     Default => $ARGS{"Scrip-$id-ScripCondition"} || $scrip->ConditionObj->Id,
68     ScripObj => $scrip,
69     Queue => $Queue,
70 &></td></tr>
71
72 <& /Admin/Elements/EditScripOptions,
73     Name => "Condition",
74     Default => $ARGS{"Scrip-$id-ConditionRules"} || $scrip->ConditionRules,
75     Queue => $Queue,
76     ScripX => $ARGS{"Scrip-$id-ScripCondition"} || $scrip->ConditionObj->Id,
77 &>
78
79 <tr><td class="label"><&|/l&>Action</&>:</td><td class="value">\
80 <& /Admin/Elements/SelectScripAction,
81     Name => "Scrip-$id-ScripAction",
82     Default => $ARGS{"Scrip-$id-ScripAction"} || $scrip->ActionObj->Id,
83     ScripObj => $scrip,
84     Queue => $Queue,
85 &></td></tr>
86
87 <& /Admin/Elements/EditScripOptions,
88     Name => "Action",
89     Default => $ARGS{"Scrip-$id-ActionRules"} || $scrip->ActionRules,
90     Queue => $Queue,
91     ScripX => $ARGS{"Scrip-$id-ScripAction"} || $scrip->ActionObj->Id,
92 &>
93
94 <tr><td class="label"><&|/l&>Template</&>:</td><td class="value">\
95 <& /Admin/Elements/SelectTemplate,
96     Name => "Scrip-$id-Template",
97     Default => $ARGS{"Scrip-$id-Template"} || $scrip->TemplateObj->Id,
98     Queue => $Queue,
99 &></td></tr>
100
101 <tr><td class="label"><&|/l&>Stage</&>:</td><td class="value">\
102 <& /Admin/Elements/SelectStage,
103     Name => "Scrip-$id-Stage",
104     Default => $ARGS{"Scrip-$id-Stage"} || $scrip->Stage,
105 &></td></tr>
106
107 </table>
108 </&>
109
110 % if ($session{CurrentUser}->HasRight(Object => $RT::System, Right => 'ExecuteCode')) {
111 <& /Elements/Submit,
112     Label => $SubmitLabel,
113     Reset => 1,
114 &><br />
115
116 <&| /Widgets/TitleBox, title => loc('User Defined conditions and actions') &>
117 <table>
118 <tr><td colspan="2">
119 <i><&|/l&>(Use these fields when you choose 'User Defined' for a condition or action)</&></i>
120 </td></tr>
121
122 <tr><td class="labeltop"><&|/l&>Custom condition</&>:</td><td class="value">
123 % my $code = $ARGS{"Scrip-$id-CustomIsApplicableCode"} || $scrip->CustomIsApplicableCode || '';
124 % my $lines = @{[ $code =~ /\n/gs ]} + 3;
125 % $lines = $min_lines if $lines < $min_lines;
126 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id %>-CustomIsApplicableCode"><% $code %></textarea>
127 </td></tr>
128
129 <tr><td class="labeltop"><&|/l&>Custom action preparation code</&>:</td><td class="value">
130 % $code = $ARGS{"Scrip-$id-CustomPrepareCode"} || $scrip->CustomPrepareCode || '';
131 % $lines = @{[ $code =~ /\n/gs ]} + 3;
132 % $lines = $min_lines if $lines < $min_lines;
133 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id %>-CustomPrepareCode"><% $code %></textarea>
134 </td></tr>
135
136 <tr><td class="labeltop"><&|/l&>Custom action cleanup code</&>:</td><td class="value">
137 % $code = $ARGS{"Scrip-$id-CustomCommitCode"} || $scrip->CustomCommitCode || '';
138 % $lines = @{[ $code =~ /\n/gs ]} + 3;
139 % $lines = $min_lines if $lines < $min_lines;
140 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id || '' %>-CustomCommitCode"><% $code %></textarea>
141 </td></tr>
142
143 </table>
144 </&>
145
146 % }
147
148 <& /Elements/Submit,
149     Label => $SubmitLabel,
150     Reset => 1,
151 &>
152
153 </form>
154 <%init>
155
156 my (@actions, $SubmitLabel);
157 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
158
159 if ( $id ) {
160     $scrip->Load( $id );
161     unless ( $id = $scrip->id ) {
162         push @actions, loc("Couldn't load scrip #[_1]", $id);
163     }
164     $SubmitLabel = loc('Save Changes');
165 }
166
167 unless ( $id ) {
168     $id = 'new';
169     $SubmitLabel = loc('Create');
170 }
171
172 my $min_lines = 10;
173
174 my ($ok, $msg) = $scrip->CompileCheck;
175 push @actions, $msg if !$ok;
176
177 </%init>
178
179 <%ARGS>
180 $id => undef
181 $title => undef
182 $Queue => 0
183 </%ARGS>
184
185 <%METHOD Process>
186 <%ARGS>
187 $id => undef
188 $Queue => undef
189 </%ARGS>
190 <%INIT>
191 return ($id) unless $id;
192
193 my @rules = ('ConditionRules', 'ActionRules');
194 if ( exists($ARGS{"Scrip-$id-ScripCondition"}) ) {
195   foreach my $rules (@rules) {
196     my $prefix = join('-', 'Scrip', $id, $rules);
197     $ARGS{$prefix} = join("\n", map {
198       $_ =~ /^$rules-(.*)$/ ? 
199             ($1, $ARGS{$_}) : ()
200     } keys(%ARGS)
201     );
202   }
203 }
204
205 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
206 if ( $id eq 'new' ) {
207     return $scrip->Create(
208         Queue                  => $Queue,
209         ScripAction            => $ARGS{"Scrip-new-ScripAction"},
210         ScripCondition         => $ARGS{"Scrip-new-ScripCondition"},
211         Template               => $ARGS{"Scrip-new-Template"},
212         Description            => $ARGS{"Scrip-new-Description"},
213         CustomPrepareCode      => $ARGS{"Scrip-new-CustomPrepareCode"},
214         CustomCommitCode       => $ARGS{"Scrip-new-CustomCommitCode"},
215         CustomIsApplicableCode => $ARGS{"Scrip-new-CustomIsApplicableCode"},
216         Stage                  => $ARGS{"Scrip-new-Stage"},
217         ConditionRules         => $ARGS{"Scrip-new-ConditionRules"},
218         ActionRules            => $ARGS{"Scrip-new-ActionRules"},
219     );
220 }
221 else {
222     $scrip->Load( $id );
223     return (undef, loc("Couldn't load scrip #[_1]", $id))
224         unless $scrip->id;
225
226     my @attribs = qw(Queue ScripAction ScripCondition Template Stage
227         Description CustomPrepareCode CustomCommitCode CustomIsApplicableCode
228         ConditionRules ActionRules);
229     my @results = UpdateRecordObject(
230         AttributesRef   => \@attribs,
231         AttributePrefix => 'Scrip-'.$scrip->Id,
232         Object          => $scrip,
233         ARGSRef         => \%ARGS
234     );
235     return ($scrip->id, @results);
236 }
237 </%INIT>
238 </%METHOD>