1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2011 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">
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 align="right"><&|/l&>Description</&>:</td><td>
58 <input name="Scrip-<% $id %>-Description"
60 value="<% $ARGS{"Scrip-$id-Description"} || $scrip->Description || '' %>" />
63 <tr><td align="right"><&|/l&>Condition</&>:</td><td>
64 <& /Admin/Elements/SelectScripCondition,
65 Name => "Scrip-$id-ScripCondition",
66 Default => $ARGS{"Scrip-$id-ScripCondition"} || $scrip->ConditionObj->Id,
71 <& /Admin/Elements/EditScripOptions,
73 Default => $ARGS{"Scrip-$id-ConditionRules"} || $scrip->ConditionRules,
75 ScripX => $ARGS{"Scrip-$id-ScripCondition"} || $scrip->ConditionObj->Id,
78 <tr><td align="right"><&|/l&>Action</&>:</td><td>
79 <& /Admin/Elements/SelectScripAction,
80 Name => "Scrip-$id-ScripAction",
81 Default => $ARGS{"Scrip-$id-ScripAction"} || $scrip->ActionObj->Id,
86 <& /Admin/Elements/EditScripOptions,
88 Default => $ARGS{"Scrip-$id-ActionRules"} || $scrip->ActionRules,
90 ScripX => $ARGS{"Scrip-$id-ScripAction"} || $scrip->ActionObj->Id,
93 <tr><td align="right"><&|/l&>Template</&>:</td><td>
94 <& /Admin/Elements/SelectTemplate,
95 Name => "Scrip-$id-Template",
96 Default => $ARGS{"Scrip-$id-Template"} || $scrip->TemplateObj->Id,
100 <tr><td align="right"><&|/l&>Stage</&>:</td><td>
101 <& /Admin/Elements/SelectStage,
102 Name => "Scrip-$id-Stage",
103 Default => $ARGS{"Scrip-$id-Stage"} || $scrip->Stage,
110 Label => $SubmitLabel,
114 <&| /Widgets/TitleBox, title => loc('User Defined conditions and actions') &>
117 <i><&|/l&>(Use these fields when you choose 'User Defined' for a condition or action)</&></i>
120 <tr><td class="labeltop"><&|/l&>Custom condition</&>:</td><td>
121 % my $code = $ARGS{"Scrip-$id-CustomIsApplicableCode"} || $scrip->CustomIsApplicableCode || '';
122 % my $lines = @{[ $code =~ /\n/gs ]} + 3;
123 % $lines = $min_lines if $lines < $min_lines;
124 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id %>-CustomIsApplicableCode"><% $code %></textarea>
127 <tr><td class="labeltop"><&|/l&>Custom action preparation code</&>:</td><td>
128 % $code = $ARGS{"Scrip-$id-CustomPrepareCode"} || $scrip->CustomPrepareCode || '';
129 % $lines = @{[ $code =~ /\n/gs ]} + 3;
130 % $lines = $min_lines if $lines < $min_lines;
131 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id %>-CustomPrepareCode"><% $code %></textarea>
134 <tr><td class="labeltop"><&|/l&>Custom action cleanup code</&>:</td><td>
135 % $code = $ARGS{"Scrip-$id-CustomCommitCode"} || $scrip->CustomCommitCode || '';
136 % $lines = @{[ $code =~ /\n/gs ]} + 3;
137 % $lines = $min_lines if $lines < $min_lines;
138 <textarea cols="80" rows="<% $lines %>" name="Scrip-<% $id || '' %>-CustomCommitCode"><% $code %></textarea>
145 Label => $SubmitLabel,
152 my (@actions, $SubmitLabel);
153 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
157 unless ( $id = $scrip->id ) {
158 push @actions, loc("Couldn't load scrip #[_1]", $id);
160 $SubmitLabel = loc('Save Changes');
165 $SubmitLabel = loc('Create');
184 return ($id) unless $id;
186 my @rules = ('ConditionRules', 'ActionRules');
187 if ( exists($ARGS{"Scrip-$id-ScripCondition"}) ) {
188 foreach my $rules (@rules) {
189 my $prefix = join('-', 'Scrip', $id, $rules);
190 $ARGS{$prefix} = join("\n", map {
191 $_ =~ /^$rules-(.*)$/ ?
198 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
199 if ( $id eq 'new' ) {
200 return $scrip->Create(
202 ScripAction => $ARGS{"Scrip-new-ScripAction"},
203 ScripCondition => $ARGS{"Scrip-new-ScripCondition"},
204 Template => $ARGS{"Scrip-new-Template"},
205 Description => $ARGS{"Scrip-new-Description"},
206 CustomPrepareCode => $ARGS{"Scrip-new-CustomPrepareCode"},
207 CustomCommitCode => $ARGS{"Scrip-new-CustomCommitCode"},
208 CustomIsApplicableCode => $ARGS{"Scrip-new-CustomIsApplicableCode"},
209 Stage => $ARGS{"Scrip-new-Stage"},
210 ConditionRules => $ARGS{"Scrip-new-ConditionRules"},
211 ActionRules => $ARGS{"Scrip-new-ActionRules"},
216 return (undef, loc("Couldn't load scrip #[_1]", $id))
219 my @attribs = qw(Queue ScripAction ScripCondition Template Stage
220 Description CustomPrepareCode CustomCommitCode CustomIsApplicableCode
221 ConditionRules ActionRules);
222 my @results = UpdateRecordObject(
223 AttributesRef => \@attribs,
224 AttributePrefix => 'Scrip-'.$scrip->Id,
228 return ($scrip->id, @results);