create ticket on custom field change, RT#10139
[freeside.git] / rt / share / html / Admin / Elements / EditScrip
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %# 
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %#                                          <jesse@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">
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 <input name="Scrip-<% $id %>-Description" 
59     size="60"
60     value="<% $ARGS{"Scrip-$id-Description"} || $scrip->Description || '' %>" />
61 </td></tr>
62
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,
67     ScripObj => $scrip,
68     Queue => $Queue,
69 &></td></tr>
70
71 <& /Admin/Elements/EditScripOptions,
72     Name => "Condition",
73     Default => $ARGS{"Scrip-$id-ConditionRules"} || $scrip->ConditionRules,
74     Queue => $Queue,
75     ScripX => $ARGS{"Scrip-$id-ScripCondition"} || $scrip->ConditionObj->Id,
76 &>
77
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,
82     ScripObj => $scrip,
83     Queue => $Queue,
84 &></td></tr>
85
86 <& /Admin/Elements/EditScripOptions,
87     Name => "Action",
88     Default => $ARGS{"Scrip-$id-ActionRules"} || $scrip->ActionRules,
89     Queue => $Queue,
90     ScripX => $ARGS{"Scrip-$id-ScripAction"} || $scrip->ActionObj->Id,
91 &>
92
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,
97     Queue => $Queue,
98 &></td></tr>
99
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,
104 &></td></tr>
105
106 </table>
107 </&>
108
109 <& /Elements/Submit,
110     Label => $SubmitLabel,
111     Reset => 1,
112 &><br />
113
114 <&| /Widgets/TitleBox, title => loc('User Defined conditions and actions') &>
115 <table>
116 <tr><td colspan="2">
117 <i><&|/l&>(Use these fields when you choose 'User Defined' for a condition or action)</&></i>
118 </td></tr>
119
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>
125 </td></tr>
126
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>
132 </td></tr>
133
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>
139 </td></tr>
140
141 </table>
142 </&>
143
144 <& /Elements/Submit,
145     Label => $SubmitLabel,
146     Reset => 1,
147 &>
148
149 </form>
150 <%init>
151
152 my (@actions, $SubmitLabel);
153 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
154
155 if ( $id ) {
156     $scrip->Load( $id );
157     unless ( $id = $scrip->id ) {
158         push @actions, loc("Couldn't load scrip #[_1]", $id);
159     }
160     $SubmitLabel = loc('Save Changes');
161 }
162
163 unless ( $id ) {
164     $id = 'new';
165     $SubmitLabel = loc('Create');
166 }
167
168 my $min_lines = 10;
169
170 </%init>
171
172 <%ARGS>
173 $id => undef
174 $title => undef
175 $Queue => 0
176 </%ARGS>
177
178 <%METHOD Process>
179 <%ARGS>
180 $id => undef
181 $Queue => undef
182 </%ARGS>
183 <%INIT>
184 return ($id) unless $id;
185
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-(.*)$/ ? 
192             ($1, $ARGS{$_}) : ()
193     } keys(%ARGS)
194     );
195   }
196 }
197
198 my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
199 if ( $id eq 'new' ) {
200     return $scrip->Create(
201         Queue                  => $Queue,
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"},
212     );
213 }
214 else {
215     $scrip->Load( $id );
216     return (undef, loc("Couldn't load scrip #[_1]", $id))
217         unless $scrip->id;
218
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,
225         Object          => $scrip,
226         ARGSRef         => \%ARGS
227     );
228     return ($scrip->id, @results);
229 }
230 </%INIT>
231 </%METHOD>