[Rt-commit] rt branch, admin_ui, updated. 7fb53013d18f992002dc874b5be49842b2054879
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed Dec 16 02:34:09 EST 2009
The branch, admin_ui has been updated
via 7fb53013d18f992002dc874b5be49842b2054879 (commit)
from 5631a47529ad5f895b9d8e560d18a337a1baed6d (commit)
Summary of changes:
lib/RT/Action/EditWorkflowMappings.pm | 130 +++++++++++++++++++++++++++++++++
1 files changed, 130 insertions(+), 0 deletions(-)
create mode 100644 lib/RT/Action/EditWorkflowMappings.pm
- Log -----------------------------------------------------------------
commit 7fb53013d18f992002dc874b5be49842b2054879
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Dec 16 15:33:48 2009 +0800
add action EditWorkflowMappings
diff --git a/lib/RT/Action/EditWorkflowMappings.pm b/lib/RT/Action/EditWorkflowMappings.pm
new file mode 100644
index 0000000..2c86e31
--- /dev/null
+++ b/lib/RT/Action/EditWorkflowMappings.pm
@@ -0,0 +1,130 @@
+use strict;
+use warnings;
+
+package RT::Action::EditWorkflowMappings;
+use base qw/RT::Action Jifty::Action/;
+use RT::Workflow;
+use Scalar::Defer;
+
+__PACKAGE__->mk_accessors('from', 'to');
+
+sub arguments {
+ my $self = shift;
+ return {} unless $self->from && $self->to;
+ my $args = {};
+ for (qw/from to/) {
+ $args->{$_} = {
+ render_as => 'hidden',
+ default_value => $self->$_,
+ };
+ }
+
+ my $from_schema = RT::Workflow->new->load($self->from);
+ my $to_schema = RT::Workflow->new->load( $self->to );
+ return $args unless $from_schema && $to_schema;
+
+
+ for my $status ( $from_schema->valid ) {
+ $args->{"from_$status"} = {
+ default_value => defer {
+ my $current = $from_schema->map($to_schema)->{ lc $status };
+ unless ($current) {
+ if ( $to_schema->is_valid($status) ) {
+ $current = $status;
+ }
+ else {
+ $current =
+ ( $to_schema->valid( $from_schema->from_set($status) ) )
+ [0];
+ }
+ }
+ return $current;
+ },
+ available_values => defer {
+ [ map { { display => _($_), value => $_ } } $to_schema->valid ];
+ },
+ label => _($status) . ' -> ',
+ render_as => 'Select',
+ };
+ }
+
+ for my $status ( $to_schema->valid ) {
+ $args->{"to_$status"} = {
+ default_value => defer {
+ my $current = $to_schema->map($from_schema)->{ lc $status };
+ unless ($current) {
+ if ( $from_schema->is_valid($status) ) {
+ $current = $status;
+ }
+ else {
+ $current =
+ ( $from_schema->valid( $to_schema->from_set($status) ) )
+ [0];
+ }
+ }
+ return $current;
+ },
+ available_values => defer {
+ [ map { { display => _($_), value => $_ } } $from_schema->valid ];
+ },
+ label => _($status) . ' -> ',
+ render_as => 'Select',
+ };
+ }
+ return $args;
+}
+
+=head2 take_action
+
+=cut
+
+sub take_action {
+ my $self = shift;
+
+ my $from = $self->argument_value('from');
+ my $to = $self->argument_value('to');
+ return unless $from && $to;
+
+ my $from_schema = RT::Workflow->new->load($from);
+ my $to_schema = RT::Workflow->new->load($to);
+
+ my %map = ();
+ foreach my $s ( $from_schema->valid ) {
+ $map{ lc $s } = $self->argument_value("from_$s");
+ }
+ my ( $status, $msg ) = $from_schema->set_map( $to_schema, %map );
+ unless ($status) {
+ Jifty->log->error(
+ "failed to set mapping for workflow $from -> $to: " . $msg );
+ return;
+ }
+
+ %map = ();
+ foreach my $s ( $to_schema->valid ) {
+ $map{ lc $s } = $self->argument_value("to_$s");
+ }
+
+ ( $status, $msg ) = $to_schema->set_map( $from_schema, %map );
+ unless ($status) {
+ Jifty->log->error(
+ "failed to set mapping for workflow $to -> $from " . $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