[Rt-commit] r6513 - in rt/branches/3.6-RELEASE: html/Admin/Elements
html/Admin/Global html/Admin/Queues
ruz at bestpractical.com
ruz at bestpractical.com
Fri Nov 24 07:42:13 EST 2006
Author: ruz
Date: Fri Nov 24 07:42:09 2006
New Revision: 6513
Modified:
rt/branches/3.6-RELEASE/html/Admin/Elements/EditScrip
rt/branches/3.6-RELEASE/html/Admin/Global/Scrip.html
rt/branches/3.6-RELEASE/html/Admin/Queues/Scrip.html
rt/branches/3.6-RELEASE/lib/RT/Scrip_Overlay.pm
Log:
Scrip management
* error messages
* preserve values of the fields between calls
* correctly report id in the tab
* fix #7445
Modified: rt/branches/3.6-RELEASE/html/Admin/Elements/EditScrip
==============================================================================
--- rt/branches/3.6-RELEASE/html/Admin/Elements/EditScrip (original)
+++ rt/branches/3.6-RELEASE/html/Admin/Elements/EditScrip Fri Nov 24 07:42:09 2006
@@ -44,150 +44,95 @@
%#
%# END BPS TAGGED BLOCK }}}
<& /Elements/ListActions, actions => \@actions &>
-
<form method="post" action="Scrip.html">
-<input type="hidden" class="hidden" name="id" value="<%$id%>" />
-<input type="hidden" class="hidden" name="Queue" value="<%$Queue%>" />
+<input type="hidden" class="hidden" name="id" value="<% $id %>" />
+<input type="hidden" class="hidden" name="Queue" value="<% $Queue %>" />
+
<&| /Widgets/TitleBox, title => loc('Scrip Fields') &>
<table>
-<tr>
-<td align="right">
-<&|/l&>Description</&>:
-</td>
-<td>
-<input name="Scrip-<%$id%>-Description" value="<%$scrip->Description%>" />
-</tr>
-<tr>
-<td align="right">
-<&|/l&>Condition</&>:
-</td>
-<td>
-<& /Admin/Elements/SelectScripCondition, Name => "Scrip-$id-ScripCondition", Default => $scrip->ConditionObj->Id &><br />
-</td>
-</tr>
-<tr>
-<td align="right">
-<&|/l&>Action</&>:
-</td>
-<td>
-<& /Admin/Elements/SelectScripAction, Name => "Scrip-$id-ScripAction", Default => $scrip->ActionObj->Id &>
-</td>
-</tr>
-<tr>
-<td align="right">
-<&|/l&>Template</&>:
-</td>
-<td>
-<& /Admin/Elements/SelectTemplate, Name => "Scrip-$id-Template", Default => $scrip->TemplateObj->Id, Queue => $Queue &>
-</td>
-</tr>
-<tr>
-<td align="right">
-<&|/l&>Stage</&>:
-</td>
-<td>
-<& /Admin/Elements/SelectStage, Name => "Scrip-$id-Stage", Default => $scrip->Stage &>
-</td>
-</tr>
+
+<tr><td align="right"><&|/l&>Description</&>:</td><td>
+<input name="Scrip-<% $id %>-Description" value="<% $ARGS{"Scrip-$id-Description"} || $scrip->Description %>" />
+</td></tr>
+
+<tr><td align="right"><&|/l&>Condition</&>:</td><td>
+<& /Admin/Elements/SelectScripCondition,
+ Name => "Scrip-$id-ScripCondition",
+ Default => $ARGS{"Scrip-$id-ScripCondition"} || $scrip->ConditionObj->Id,
+&></td></tr>
+
+<tr><td align="right"><&|/l&>Action</&>:</td><td>
+<& /Admin/Elements/SelectScripAction,
+ Name => "Scrip-$id-ScripAction",
+ Default => $ARGS{"Scrip-$id-ScripAction"} || $scrip->ActionObj->Id,
+&></td></tr>
+
+<tr><td align="right"><&|/l&>Template</&>:</td><td>
+<& /Admin/Elements/SelectTemplate,
+ Name => "Scrip-$id-Template",
+ Default => $ARGS{"Scrip-$id-Template"} || $scrip->TemplateObj->Id,
+ Queue => $Queue,
+&></td></tr>
+
+<tr><td align="right"><&|/l&>Stage</&>:</td><td>
+<& /Admin/Elements/SelectStage,
+ Name => "Scrip-$id-Stage",
+ Default => $ARGS{"Scrip-$id-Stage"} || $scrip->Stage,
+&></td></tr>
+
</table>
</&>
-<& /Elements/Submit, Caption => loc("Be sure to save your changes"), Reset => 1 &>
-<br />
+<& /Elements/Submit,
+ Label => $SubmitLabel,
+ Caption => loc("Be sure to save your changes"),
+ Reset => 1,
+&><br />
+
<&| /Widgets/TitleBox, title => loc('User Defined conditions and actions') &>
<table>
-<tr>
-<td colspan="2">
+<tr><td colspan="2">
<i><&|/l&>(Use these fields when you choose 'User Defined' for a condition or action)</&></i>
-</td>
-</tr>
-<tr>
-<td class="labeltop">
-<&|/l&>Custom condition</&>:
-</td>
-<td>
-<textarea cols="80" rows="5" name="Scrip-<%$id%>-CustomIsApplicableCode"><%$scrip->CustomIsApplicableCode%></textarea>
-</td>
-</tr>
-<tr>
-<td class="labeltop">
-<&|/l&>Custom action preparation code</&>:
-</td>
-<td>
-<textarea cols="80" rows="5" name="Scrip-<%$id%>-CustomPrepareCode"><%$scrip->CustomPrepareCode%></textarea>
-</td>
-</tr>
-<tr>
-<td class="labeltop">
-<&|/l&>Custom action cleanup code</&>:
-</td>
-<td>
-<textarea cols="80" rows="5" name="Scrip-<%$id%>-CustomCommitCode"><%$scrip->CustomCommitCode%></textarea>
-</td>
-</tr>
+</td></tr>
+
+<tr><td class="labeltop"><&|/l&>Custom condition</&>:</td><td>
+<textarea cols="80" rows="5" name="Scrip-<% $id %>-CustomIsApplicableCode"><% $ARGS{"Scrip-$id-CustomIsApplicableCode"} || $scrip->CustomIsApplicableCode %></textarea>
+</td></tr>
+
+<tr><td class="labeltop"><&|/l&>Custom action preparation code</&>:</td><td>
+<textarea cols="80" rows="5" name="Scrip-<% $id %>-CustomPrepareCode"><% $ARGS{"Scrip-$id-CustomPrepareCode"} || $scrip->CustomPrepareCode %></textarea>
+</td></tr>
+
+<tr><td class="labeltop"><&|/l&>Custom action cleanup code</&>:</td><td>
+<textarea cols="80" rows="5" name="Scrip-<% $id %>-CustomCommitCode"><% $ARGS{"Scrip-$id-CustomCommitCode"} || $scrip->CustomCommitCode %></textarea>
+</td></tr>
+
</table>
</&>
-<& /Elements/Submit, Label => loc('Create'), Reset => 1 &>
+<& /Elements/Submit, Label => $SubmitLabel, Reset => 1 &>
</form>
<%init>
-my (@actions);
-
-my $scrip = new RT::Scrip($session{'CurrentUser'});
+my (@actions, $SubmitLabel);
-if ( $id eq 'new' ) {
+my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
- my ( $retval, $msg ) = $scrip->Create(
- Queue => $Queue,
- ScripAction => $ARGS{"Scrip-new-ScripAction"},
- ScripCondition => $ARGS{"Scrip-new-ScripCondition"},
- Template => $ARGS{"Scrip-new-Template"},
- Description => $ARGS{"Scrip-new-Description"},
- CustomPrepareCode => $ARGS{"Scrip-new-CustomPrepareCode"},
- CustomCommitCode => $ARGS{"Scrip-new-CustomCommitCode"},
- CustomIsApplicableCode => $ARGS{"Scrip-new-CustomIsApplicableCode"},
- );
- if ( defined $retval ) {
- push @actions, $msg;
- $id = $scrip->id;
- }
- else {
- Abort( $msg);
- }
-}
-elsif ($id) {
- my ($val,$msg) =$scrip->Load($id);
- if ($val) {
- $id = $scrip->id;
- } else {
- Abort ($msg);
+if ( $id ) {
+ $scrip->Load( $id );
+ unless ( $id = $scrip->id ) {
+ push @actions, loc("Couldn't load scrip #[_1]", $id);
}
- my @attribs = qw (
- Queue
- ScripAction
- ScripCondition
- Template
- Stage
- Description
- CustomPrepareCode
- CustomCommitCode
- CustomIsApplicableCode
- );
- my @results = UpdateRecordObject( AttributesRef => \@attribs,
- AttributePrefix => 'Scrip-'.$scrip->Id,
- Object => $scrip,
- ARGSRef => \%ARGS );
- push (@actions, @results);
+ $SubmitLabel = loc('Update');
}
-elsif ($ARGS{'create'}) {
+unless ( $id ) {
$id = 'new';
+ $SubmitLabel = loc('Create');
}
-# }}}
</%init>
<%ARGS>
@@ -195,3 +140,42 @@
$title => undef
$Queue => 0
</%ARGS>
+
+<%METHOD Process>
+<%ARGS>
+$id => undef
+$Queue => undef
+</%ARGS>
+<%INIT>
+return ($id) unless $id;
+
+my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
+if ( $id eq 'new' ) {
+ return $scrip->Create(
+ Queue => $Queue,
+ ScripAction => $ARGS{"Scrip-new-ScripAction"},
+ ScripCondition => $ARGS{"Scrip-new-ScripCondition"},
+ Template => $ARGS{"Scrip-new-Template"},
+ Description => $ARGS{"Scrip-new-Description"},
+ CustomPrepareCode => $ARGS{"Scrip-new-CustomPrepareCode"},
+ CustomCommitCode => $ARGS{"Scrip-new-CustomCommitCode"},
+ CustomIsApplicableCode => $ARGS{"Scrip-new-CustomIsApplicableCode"},
+ );
+}
+else {
+ $scrip->Load( $id );
+ return (undef, loc("Couldn't load scrip #[_1]", $id))
+ unless $scrip->id;
+
+ my @attribs = qw(Queue ScripAction ScripCondition Template Stage
+ Description CustomPrepareCode CustomCommitCode CustomIsApplicableCode);
+ my @results = UpdateRecordObject(
+ AttributesRef => \@attribs,
+ AttributePrefix => 'Scrip-'.$scrip->Id,
+ Object => $scrip,
+ ARGSRef => \%ARGS
+ );
+ return ($scrip->id, @results);
+}
+</%INIT>
+</%METHOD>
Modified: rt/branches/3.6-RELEASE/html/Admin/Global/Scrip.html
==============================================================================
--- rt/branches/3.6-RELEASE/html/Admin/Global/Scrip.html (original)
+++ rt/branches/3.6-RELEASE/html/Admin/Global/Scrip.html Fri Nov 24 07:42:09 2006
@@ -43,33 +43,40 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<& /Admin/Elements/Header, Title => $title &>
+<& /Admin/Elements/Header, Title => $title &>
<& /Admin/Elements/SystemTabs,
current_tab => 'Admin/Global/Scrips.html',
current_subtab => $current_subtab,
subtabs => $subtabs,
Title => $title &>
-<& /Admin/Elements/EditScrip, title => $title, %ARGS &>
+<& /Elements/ListActions, actions => \@results &>
+<& /Admin/Elements/EditScrip, title => $title, %ARGS, id => $id &>
<%init>
-my ($title, $current_subtab);
my $subtabs = {
- A => { title => loc('Select scrip'),
- path => "Admin/Global/Scrips.html",
- },
- B => { title => loc('New scrip'),
- path => "Admin/Global/Scrip.html?create=1&Queue=0",
- separator => 1,
- }
- };
+ A => {
+ title => loc('Select scrip'),
+ path => "Admin/Global/Scrips.html",
+ },
+ B => {
+ title => loc('New scrip'),
+ path => "Admin/Global/Scrip.html?create=1&Queue=0",
+ separator => 1,
+ },
+};
+
+my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
+my ($id, @results) = $m->comp( '/Admin/Elements/EditScrip:Process', %ARGS );
-if ($ARGS{'id'}) {
- $current_subtab = "Admin/Global/Scrip.html?id=".$ARGS{'id'}."&Queue=0";
+my ($title, $current_subtab);
+if ( $id ) {
+ $current_subtab = "Admin/Global/Scrip.html?id=$id&Queue=0";
$title = loc("Modify a scrip which applies to all queues");
- $subtabs->{"C"} = { title => loc('Scrip #[_1]', $ARGS{'id'}),
- path => "Admin/Global/Scrip.html?id=".$ARGS{'id'}."&Queue=0"
- }
+ $subtabs->{"C"} = {
+ title => loc('Scrip #[_1]', $id),
+ path => "Admin/Global/Scrip.html?id=$id&Queue=0",
+ };
}
else {
$current_subtab = "Admin/Global/Scrip.html?create=1&Queue=0";
Modified: rt/branches/3.6-RELEASE/html/Admin/Queues/Scrip.html
==============================================================================
--- rt/branches/3.6-RELEASE/html/Admin/Queues/Scrip.html (original)
+++ rt/branches/3.6-RELEASE/html/Admin/Queues/Scrip.html Fri Nov 24 07:42:09 2006
@@ -1,38 +1,38 @@
%# BEGIN BPS TAGGED BLOCK {{{
-%#
+%#
%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2006 Best Practical Solutions, LLC
+%#
+%# This software is Copyright (c) 1996-2006 Best Practical Solutions, LLC
%# <jesse at bestpractical.com>
-%#
+%#
%# (Except where explicitly superseded by other copyright notices)
-%#
-%#
+%#
+%#
%# LICENSE:
-%#
+%#
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
-%#
+%#
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%# General Public License for more details.
-%#
+%#
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
%# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-%#
-%#
+%#
+%#
%# CONTRIBUTION SUBMISSION POLICY:
-%#
+%#
%# (The following paragraph is not intended to limit the rights granted
%# to you to modify and distribute this software under the terms of
%# the GNU General Public License and is only of importance to you if
%# you choose to contribute your changes and enhancements to the
%# community by submitting them to Best Practical Solutions, LLC.)
-%#
+%#
%# By intentionally submitting any modifications, corrections or
%# derivatives to this work, or any other work intended for use with
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
@@ -41,49 +41,58 @@
%# royalty-free, perpetual, license to use, copy, create derivative
%# works based on those contributions, and sublicense and distribute
%# those contributions and any derivatives thereof.
-%#
+%#
%# END BPS TAGGED BLOCK }}}
<& /Admin/Elements/Header, Title => $title &>
-<& /Admin/Elements/QueueTabs, id => $QueueObj->Id,
- QueueObj => $QueueObj,
- current_tab => 'Admin/Queues/Scrips.html?id='.$QueueObj->id,
- current_subtab => $current_subtab,
- subtabs => $subtabs,
+<& /Admin/Elements/QueueTabs, id => $QueueObj->Id,
+ QueueObj => $QueueObj,
+ current_tab => 'Admin/Queues/Scrips.html?id='.$QueueObj->id,
+ current_subtab => $current_subtab,
+ subtabs => $subtabs,
Title => $title &>
-<& /Admin/Elements/EditScrip, title => $title, %ARGS &>
+<& /Elements/ListActions, actions => \@results &>
+<& /Admin/Elements/EditScrip, title => $title, %ARGS, id => $id &>
+
<%init>
-my $QueueObj = new RT::Queue($session{'CurrentUser'});
-$QueueObj->Load($Queue);
+my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
+$QueueObj->Load( $Queue );
+unless( $QueueObj->id ) {
+ Abort(loc("Queue [_1] not found", $id));
+}
my ($title, $current_subtab);
-my $subtabs = {
- A => { title => loc('Select scrip'),
- path => "Admin/Queues/Scrips.html?id=".$QueueObj->id,
- },
- B => { title => loc('New scrip'),
- path => "Admin/Queues/Scrip.html?create=1&Queue=".$QueueObj->id,
- separator => 1,
- },
- };
+my $subtabs = {
+ A => {
+ title => loc('Select scrip'),
+ path => "Admin/Queues/Scrips.html?id=".$QueueObj->id,
+ },
+ B => {
+ title => loc('New scrip'),
+ path => "Admin/Queues/Scrip.html?create=1&Queue=".$QueueObj->id,
+ separator => 1,
+ },
+};
-unless($QueueObj->id) {
- Abort(loc("Queue [_1] not found",$id));
-}
-if ($id) {
- $current_subtab = "Admin/Queues/Scrip.html?id=".$id."&Queue=".$QueueObj->id;
+my $scrip = RT::Scrip->new( $session{'CurrentUser'} );
+($id, my @results) = $m->comp( '/Admin/Elements/EditScrip:Process', %ARGS );
+
+if ( $id ) {
+ $current_subtab = "Admin/Queues/Scrip.html?id=$id&Queue=". $QueueObj->id;
$title = loc("Modify a scrip for queue [_1]", $QueueObj->Name);
- $subtabs->{"C"} = { title => loc("Scrip #[_1]",$id),
- path => "Admin/Queues/Scrip.html?id=$id&Queue=".$QueueObj->id };
+ $subtabs->{"C"} = {
+ title => loc("Scrip #[_1]",$id),
+ path => "Admin/Queues/Scrip.html?id=$id&Queue=".$QueueObj->id
+ };
} else {
$current_subtab = "Admin/Queues/Scrip.html?create=1&Queue=".$QueueObj->id;
$title = loc("Create a scrip for queue [_1]", $QueueObj->Name);
}
-
+
</%init>
<%ARGS>
-$id => undef
+$id => undef
$Queue => undef
</%ARGS>
Modified: rt/branches/3.6-RELEASE/lib/RT/Scrip_Overlay.pm
==============================================================================
--- rt/branches/3.6-RELEASE/lib/RT/Scrip_Overlay.pm (original)
+++ rt/branches/3.6-RELEASE/lib/RT/Scrip_Overlay.pm Fri Nov 24 07:42:09 2006
@@ -139,10 +139,10 @@
CustomPrepareCode => undef,
CustomCommitCode => undef,
CustomIsApplicableCode => undef,
+ @_
+ );
- @_ );
-
- if ( !$args{'Queue'} ) {
+ unless ( $args{'Queue'} ) {
unless ( $self->CurrentUser->HasRight( Object => $RT::System,
Right => 'ModifyScrips' )
) {
@@ -151,9 +151,9 @@
$args{'Queue'} = 0; # avoid undef sneaking in
}
else {
- my $QueueObj = new RT::Queue( $self->CurrentUser );
+ my $QueueObj = RT::Queue->new( $self->CurrentUser );
$QueueObj->Load( $args{'Queue'} );
- unless ( $QueueObj->id() ) {
+ unless ( $QueueObj->id ) {
return ( 0, $self->loc('Invalid queue') );
}
unless ( $QueueObj->CurrentUserHasRight('ModifyScrips') ) {
@@ -165,28 +165,28 @@
#TODO +++ validate input
require RT::ScripAction;
- my $action = new RT::ScripAction( $self->CurrentUser );
- if ( $args{'ScripAction'} ) {
- $action->Load( $args{'ScripAction'} );
- }
+ return ( 0, $self->loc("Action is mandatory argument") )
+ unless $args{'ScripAction'};
+ my $action = RT::ScripAction->new( $self->CurrentUser );
+ $action->Load( $args{'ScripAction'} );
return ( 0, $self->loc( "Action [_1] not found", $args{'ScripAction'} ) )
- unless $action->Id;
+ unless $action->Id;
require RT::Template;
- my $template = new RT::Template( $self->CurrentUser );
- if ( $args{'Template'} ) {
- $template->Load( $args{'Template'} );
- }
- return ( 0, $self->loc('Template not found') ) unless $template->Id;
+ return ( 0, $self->loc("Template is mandatory argument") )
+ unless $args{'Template'};
+ my $template = RT::Template->new( $self->CurrentUser );
+ $template->Load( $args{'Template'} );
+ return ( 0, $self->loc('Template not found') )
+ unless $template->Id;
require RT::ScripCondition;
- my $condition = new RT::ScripCondition( $self->CurrentUser );
- if ( $args{'ScripCondition'} ) {
- $condition->Load( $args{'ScripCondition'} );
- }
- unless ( $condition->Id ) {
- return ( 0, $self->loc('Condition not found') );
- }
+ return ( 0, $self->loc("Condition is mandatory argument") )
+ unless $args{'ScripCondition'};
+ my $condition = RT::ScripCondition->( $self->CurrentUser );
+ $condition->Load( $args{'ScripCondition'} );
+ return ( 0, $self->loc('Condition not found') )
+ unless $condition->Id;
my ( $id, $msg ) = $self->SUPER::Create(
Queue => $args{'Queue'},
@@ -198,9 +198,8 @@
CustomPrepareCode => $args{'CustomPrepareCode'},
CustomCommitCode => $args{'CustomCommitCode'},
CustomIsApplicableCode => $args{'CustomIsApplicableCode'},
-
);
- if ($id) {
+ if ( $id ) {
return ( $id, $self->loc('Scrip Created') );
}
else {
@@ -595,15 +594,17 @@
Principal => undef,
@_ );
- if ( ( defined $self->SUPER::_Value('Queue') )
- and ( $self->SUPER::_Value('Queue') != 0 ) ) {
- return ( $args{'Principal'}->HasRight( Right => $args{'Right'},
- Object => $self->QueueObj ) );
-
+ if ( $self->SUPER::_Value('Queue') ) {
+ return $args{'Principal'}->HasRight(
+ Right => $args{'Right'},
+ Object => $self->QueueObj
+ );
}
else {
- return ( $args{'Principal'}
- ->HasRight( Object => $RT::System, Right => $args{'Right'} ) );
+ return $args{'Principal'}->HasRight(
+ Object => $RT::System,
+ Right => $args{'Right'},
+ );
}
}
More information about the Rt-commit
mailing list