migrate Activity getEditForm to FormBuilder
This commit is contained in:
parent
37f392b4c8
commit
9ab36a72ee
3 changed files with 108 additions and 10 deletions
|
|
@ -385,14 +385,15 @@ sub www_editWorkflowActivity {
|
|||
$activity = WebGUI::Workflow::Activity->new($session, $session->form->get("activityId"));
|
||||
}
|
||||
my $form = $activity->getEditForm;
|
||||
$form->hidden( name=>"op", value=>"editWorkflowActivitySave");
|
||||
$form->hidden( name=>"workflowId", value=>$session->form->get("workflowId"));
|
||||
$form->submit;
|
||||
$form->action( $session->url->page );
|
||||
$form->addField( "hidden", name=>"op", value=>"editWorkflowActivitySave");
|
||||
$form->addField( "hidden", name=>"workflowId", value=> scalar $session->form->get("workflowId"));
|
||||
$form->addField( "submit", name => "submit" );
|
||||
my $i18n = WebGUI::International->new($session, "Workflow");
|
||||
my $ac = WebGUI::AdminConsole->new($session,"workflow");
|
||||
$ac->addSubmenuItem($session->url->page("op=addWorkflow"), $i18n->get("add a new workflow"));
|
||||
$ac->addSubmenuItem($session->url->page("op=manageWorkflows"), $i18n->get("manage workflows"));
|
||||
return $ac->render($form->print,$activity->getName);
|
||||
return $ac->render($form->toHtml,$activity->getName);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ package WebGUI::Workflow::Activity;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::FormBuilder;
|
||||
use WebGUI::Pluggable;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -235,12 +235,17 @@ Returns the form that will be used to edit the properties of an activity.
|
|||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $form = WebGUI::HTMLForm->new($self->session);
|
||||
$form->submit;
|
||||
$form->hidden(name=>"activityId", value=>$self->getId);
|
||||
$form->hidden(name=>"className", value=>$self->get("className"));
|
||||
my $form = WebGUI::FormBuilder->new($self->session);
|
||||
$form->addField( "submit", name => "submit" );
|
||||
$form->addField( "hidden", name=>"activityId", value=>$self->getId);
|
||||
$form->addField( "hidden", name=>"className", value=>$self->get("className"));
|
||||
my $fullDefinition = $self->definition($self->session);
|
||||
$form->dynamicForm($fullDefinition, "properties", $self);
|
||||
for my $hash ( map { $_->{properties} } @{$fullDefinition} ) {
|
||||
for my $fieldName ( keys %$hash ) {
|
||||
my $field = $hash->{ $fieldName };
|
||||
$form->addField( delete $field->{fieldType}, name => $fieldName, %$field );
|
||||
}
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
|||
92
t/Operation/Workflow.t
Normal file
92
t/Operation/Workflow.t
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Test the forms for Workflow editing
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/lib";
|
||||
use Test::More;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Test::Mechanize;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 14; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Add a workflow
|
||||
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
|
||||
$mech->get_ok( '/' );
|
||||
$mech->session->user({ userId => 3 });
|
||||
|
||||
$mech->get_ok( '?op=addWorkflow' );
|
||||
$mech->submit_form_ok({
|
||||
fields => {
|
||||
type => "None",
|
||||
},
|
||||
},
|
||||
"Add a new workflow"
|
||||
);
|
||||
|
||||
my $workflowId = $mech->value( 'workflowId' );
|
||||
ok( $workflowId, "workflow id in edit form" );
|
||||
ok( my $workflow = WebGUI::Workflow->new( $mech->session, $workflowId ), "can be instanced" );
|
||||
WebGUI::Test::addToCleanup( $workflow );
|
||||
is( $workflow->get('type'), "None", "type set correctly" );
|
||||
|
||||
my %workflowFields = (
|
||||
title => 'New Test Workflow',
|
||||
description => 'Descriptive',
|
||||
);
|
||||
$mech->submit_form_ok({
|
||||
fields => \%workflowFields,
|
||||
},
|
||||
"Update the new workflow's name and settings",
|
||||
);
|
||||
|
||||
$workflow = WebGUI::Workflow->new( $mech->session, $workflowId );
|
||||
is( $workflow->get('title'), $workflowFields{title}, "title set correctly" );
|
||||
is( $workflow->get('description'), $workflowFields{description}, "description set correctly" );
|
||||
|
||||
# Add an activity
|
||||
$mech->follow_link_ok(
|
||||
{
|
||||
url_regex => qr/WebGUI::Workflow::Activity::DeleteExpiredSessions/,
|
||||
},
|
||||
"Add a DeleteExpiredSessions activity",
|
||||
);
|
||||
|
||||
my %activityFields = (
|
||||
title => 'New Workflow Activity',
|
||||
description => 'As if you needed one.',
|
||||
);
|
||||
$mech->submit_form_ok({
|
||||
fields => \%activityFields,
|
||||
},
|
||||
"Edit the activity properties",
|
||||
);
|
||||
|
||||
my $activities = $workflow->getActivities;
|
||||
is( @$activities, 1, 'workflow has one activity' );
|
||||
is( $activities->[0]->get('title'), $activityFields{title}, "activity title set" );
|
||||
is( $activities->[0]->get('description'), $activityFields{description}, "activity description set" );
|
||||
|
||||
|
||||
#vim:ft=perl
|
||||
Loading…
Add table
Add a link
Reference in a new issue