[Rt-commit] rt branch, admin_ui, updated. 5c766b23f6c3574abeea65dc59bd9ff82dd25d23
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Tue Dec 15 00:20:55 EST 2009
The branch, admin_ui has been updated
via 5c766b23f6c3574abeea65dc59bd9ff82dd25d23 (commit)
from be1cb81ce51ec6ba2214e90f278ef0023ee0573b (commit)
Summary of changes:
lib/RT/Action/EditWorkflowInterface.pm | 101 ++++++++++++++++++++++++++++++++
1 files changed, 101 insertions(+), 0 deletions(-)
create mode 100644 lib/RT/Action/EditWorkflowInterface.pm
- Log -----------------------------------------------------------------
commit 5c766b23f6c3574abeea65dc59bd9ff82dd25d23
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Dec 15 13:20:08 2009 +0800
add EditWorkflowInterface action
diff --git a/lib/RT/Action/EditWorkflowInterface.pm b/lib/RT/Action/EditWorkflowInterface.pm
new file mode 100644
index 0000000..3d244ff
--- /dev/null
+++ b/lib/RT/Action/EditWorkflowInterface.pm
@@ -0,0 +1,101 @@
+use strict;
+use warnings;
+
+package RT::Action::EditWorkflowInterface;
+use base qw/RT::Action Jifty::Action/;
+use RT::Workflow;
+
+__PACKAGE__->mk_accessors('name');
+
+sub arguments {
+ my $self = shift;
+ return {} unless $self->name;
+ my $args = {
+ name => {
+ render_as => 'hidden',
+ default_value => $self->name,
+ },
+ };
+
+ my $schema = RT::Workflow->new->load( $self->name );
+ my @valid = $schema->valid;
+
+ for my $from (@valid) {
+ my @next = $schema->transitions($from);
+ for my $to (@next) {
+ $args->{ $from . '___label___' . $to } = {
+ default_value => $schema->transition_label( $from => $to ),
+ label => '',
+ };
+ }
+ }
+
+ for my $from (@valid) {
+ my @next = $schema->transitions($from);
+ for my $to (@next) {
+ $args->{ $from . '___action___' . $to } = {
+ default_value => $schema->transition_action( $from => $to ),
+ render_as => 'Select',
+ available_values => [
+ {
+ value => '',
+ display => _('no action')
+ },
+ map { { value => $_, display => _($_) } }
+ qw/hide comment respond/
+ ],
+ label => '',
+ };
+ }
+ }
+
+ return $args;
+}
+
+=head2 take_action
+
+=cut
+
+sub take_action {
+ my $self = shift;
+
+ my $name = $self->argument_value('name');
+ return unless $name;
+ my $schema = RT::Workflow->new->load( $name );
+ my %tmp = ();
+
+ my @valid = $schema->valid;
+ foreach my $from (@valid) {
+ foreach my $to (@valid) {
+ next if $from eq $to;
+ $tmp{ $from . ' -> ' . $to }[0] =
+ $self->argument_value( $from . '___label___' . $to );
+ $tmp{ $from . ' -> ' . $to }[1] =
+ $self->argument_value( $from . '___action___' . $to );
+ }
+ }
+
+ my ( $status, $msg ) = $schema->set_actions(%tmp);
+ unless ($status) {
+ Jifty->log->error(
+ 'failed to set actions for workflow ' . $name . ': ' . $msg );
+ return;
+ }
+
+ $self->report_success;
+ return 1;
+}
+
+=head2 report_success
+
+=cut
+
+sub report_success {
+ my $self = shift;
+
+ # Your success message here
+ $self->result->message('Success');
+}
+
+1;
+
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list