1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 %# CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/ListActions, actions => \@actions &>
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 %>" />
54 <&| /Widgets/TitleBox, title => loc('Scrip Fields') &>
57 <tr><td class="label"><&|/l&>Description</&>:</td><td class="value">\
59 <% $scrip->Description %> <i>(system scrip)</i>
60 <input type="hidden" name="Scrip-<% $id %>-Description" value="<% $scrip->Description %>">
62 <input name="Scrip-<% $id %>-Description" \
64 value="<% $ARGS{"Scrip-$id-Description"} || $scrip->Description || '' %>" />
68 <tr><td class="label"><&|/l&>Condition</&>:</td><td class="value">\
70 <% loc( $scrip->ConditionObj->Name ) %>
71 <input type="hidden" name="Scrip-<%$id%>-Condition" value="<% $scrip->ConditionObj->Id %>">
73 <& /Admin/Elements/SelectScripCondition,
74 Name => "Scrip-$id-ScripCondition",
75 Default => $ARGS{"Scrip-$id-ScripCondition"} || $scrip->ConditionObj->Id,
82 <& /Admin/Elements/EditScripOptions,
84 Default => $ARGS{"Scrip-$id-ConditionRules"} || $scrip->ConditionRules,
86 ScripX => $ARGS{"Scrip-$id-ScripCondition"} || $scrip->ConditionObj->Id,
89 <tr><td class="label"><&|/l&>Action</&>:</td><td class="value">\
91 <% loc( $scrip->ActionObj->Name ) %>
92 <input type="hidden" name="Scrip-<%$id%>-Action" value="<% $scrip->ActionObj->Id %>">
94 <& /Admin/Elements/SelectScripAction,
95 Name => "Scrip-$id-ScripAction",
96 Default => $ARGS{"Scrip-$id-ScripAction"} || $scrip->ActionObj->Id,
103 <& /Admin/Elements/EditScripOptions,
105 Default => $ARGS{"Scrip-$id-ActionRules"} || $scrip->ActionRules,
107 ScripX => $ARGS{"Scrip-$id-ScripAction"} || $scrip->ActionObj->Id,
110 <tr><td class="label"><&|/l&>Template</&>:</td><td class="value">\
111 %# immutable flag doesn't affect this
112 <& /Admin/Elements/SelectTemplate,
113 Name => "Scrip-$id-Template",
114 Default => $ARGS{"Scrip-$id-Template"} || $scrip->TemplateObj->Id,
119 <tr><td class="label"><&|/l&>Stage</&>:</td><td class="value">\
121 <& /Admin/Elements/SelectStage,
122 Name => "Scrip-$id-Stage",
123 Default => $ARGS{"Scrip-$id-Stage"} || $scrip->Stage,
129 % if ($session{CurrentUser}->HasRight(Object => $RT::System, Right => 'ExecuteCode')) {
131 Label => $SubmitLabel,
135 <&| /Widgets/TitleBox, title => loc('User Defined conditions and actions') &>
138 <i><&|/l&>(Use these fields when you choose 'User Defined' for a condition or action)</&></i>
141 <tr><td class="labeltop"><&|/l&>Custom condition</&>:</td><td class="value">
142 % my $code = $ARGS{"Scrip-$id-CustomIsApplicableCode"} || $scrip->CustomIsApplicableCode || '';
143 % my $lines = @{[ $code =~ /\n/gs ]} + 3;
144 % $lines = $min_lines if $lines < $min_lines;
145 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id %>-CustomIsApplicableCode"><% $code %></textarea>
148 <tr><td class="labeltop"><&|/l&>Custom action preparation code</&>:</td><td class="value">
149 % $code = $ARGS{"Scrip-$id-CustomPrepareCode"} || $scrip->CustomPrepareCode || '';
150 % $lines = @{[ $code =~ /\n/gs ]} + 3;
151 % $lines = $min_lines if $lines < $min_lines;
152 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id %>-CustomPrepareCode"><% $code %></textarea>
155 <tr><td class="labeltop"><&|/l&>Custom action cleanup code</&>:</td><td class="value">
156 % $code = $ARGS{"Scrip-$id-CustomCommitCode"} || $scrip->CustomCommitCode || '';
157 % $lines = @{[ $code =~ /\n/gs ]} + 3;
158 % $lines = $min_lines if $lines < $min_lines;
159 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id || '' %>-CustomCommitCode"><% $code %></textarea>
168 Label => $SubmitLabel,
175 my (@actions, $SubmitLabel);
176 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
181 unless ( $id = $scrip->id ) {
182 push @actions, loc("Couldn't load scrip #[_1]", $id);
184 $SubmitLabel = loc('Save Changes');
185 my $a = $scrip->FirstAttribute('Immutable');
186 if ( defined($a) and $a->Content ) {
193 $SubmitLabel = loc('Create');
198 my ($ok, $msg) = $scrip->CompileCheck;
199 push @actions, $msg if !$ok;
215 return ($id) unless $id;
217 my @rules = ('ConditionRules', 'ActionRules');
218 if ( exists($ARGS{"Scrip-$id-ScripCondition"}) ) {
219 foreach my $rules (@rules) {
220 my $prefix = join('-', 'Scrip', $id, $rules);
221 $ARGS{$prefix} = join("\n", map {
222 $_ =~ /^$rules-(.*)$/ ?
229 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
230 if ( $id eq 'new' ) {
231 return $scrip->Create(
233 ScripAction => $ARGS{"Scrip-new-ScripAction"},
234 ScripCondition => $ARGS{"Scrip-new-ScripCondition"},
235 Template => $ARGS{"Scrip-new-Template"},
236 Description => $ARGS{"Scrip-new-Description"},
237 CustomPrepareCode => $ARGS{"Scrip-new-CustomPrepareCode"},
238 CustomCommitCode => $ARGS{"Scrip-new-CustomCommitCode"},
239 CustomIsApplicableCode => $ARGS{"Scrip-new-CustomIsApplicableCode"},
240 Stage => $ARGS{"Scrip-new-Stage"},
241 ConditionRules => $ARGS{"Scrip-new-ConditionRules"},
242 ActionRules => $ARGS{"Scrip-new-ActionRules"},
247 return (undef, loc("Couldn't load scrip #[_1]", $id))
250 my @attribs = qw(Queue ScripAction ScripCondition Template Stage
251 Description CustomPrepareCode CustomCommitCode CustomIsApplicableCode
252 ConditionRules ActionRules);
253 my @results = UpdateRecordObject(
254 AttributesRef => \@attribs,
255 AttributePrefix => 'Scrip-'.$scrip->Id,
259 return ($scrip->id, @results);