migrate PM editProject to FormBuilder

This commit is contained in:
Doug Bell 2011-02-03 16:05:37 -06:00
parent 0a2a010a95
commit db8b507b94
2 changed files with 170 additions and 64 deletions

View file

@ -1127,83 +1127,78 @@ sub www_editProject {
my $addEditText = ($projectId eq "new")?$i18n->get("create project"):$i18n->get("edit project"); my $addEditText = ($projectId eq "new")?$i18n->get("create project"):$i18n->get("edit project");
#Build Form #Build Form
my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl, -extras=>q|onsubmit="return checkform(this);"|); my $f = WebGUI::FormBuilder->new($self->session,
$f->hidden( action=>$self->getUrl,
-name=>"func", extras=>q|onsubmit="return checkform(this);"|
-value=>"editProjectSave" );
$f->addField( "hidden",
name=>"func",
value=>"editProjectSave"
); );
$f->hidden( $f->addField( "hidden",
-name=>"projectId", name=>"projectId",
-value=>$projectId value=>$projectId
); );
$f->readOnly( $f->addField( "readOnly",
-label=>$i18n->get("project id"), label=>$i18n->get("project id"),
-hoverHelp => $i18n->get('project name hoverhelp'), hoverHelp => $i18n->get('project name hoverhelp'),
-value=>$projectId value=>$projectId
); );
$f->text( $f->addField( "text",
-name => "name", name => "name",
-value => $form->get("name") || $project->{name}, value => $form->get("name") || $project->{name},
-hoverHelp => $i18n->get('project name hoverhelp'), hoverHelp => $i18n->get('project name hoverhelp'),
-label => $i18n->get('project name label') label => $i18n->get('project name label')
); );
$f->HTMLArea( $f->addField( "HTMLArea",
-name => "description", name => "description",
-value => $form->get("description") || $project->{description}, value => $form->get("description") || $project->{description},
-hoverHelp => $i18n->get('project description hoverhelp'), hoverHelp => $i18n->get('project description hoverhelp'),
-label => $i18n->get('project description label') label => $i18n->get('project description label')
); );
$f->group( $f->addField( "group",
-name=> "projectManager", name=> "projectManager",
-value=> $form->get("projectManager") || $project->{projectManager} || $self->groupToAdd, value=> $form->get("projectManager") || $project->{projectManager} || $self->groupToAdd,
-hoverHelp=> $i18n->get('project manager hoverhelp'), hoverHelp=> $i18n->get('project manager hoverhelp'),
-label => $i18n->get('project manager label') label => $i18n->get('project manager label')
); );
$f->group( $f->addField( "group",
-name=> "projectObserver", name=> "projectObserver",
-value=> $form->get("projectObserver") || $project->{projectObserver} || '7', value=> $form->get("projectObserver") || $project->{projectObserver} || '7',
-hoverHelp=> $i18n->get('project observer hoverhelp'), hoverHelp=> $i18n->get('project observer hoverhelp'),
-label => $i18n->get('project observer label') label => $i18n->get('project observer label')
); );
my $dunitValue = $form->get("durationUnits") || $project->{durationUnits} || "hours"; my $dunitValue = $form->get("durationUnits") || $project->{durationUnits} || "hours";
$f->selectBox( $f->addField( "selectBox",
-name=>"durationUnits", name=>"durationUnits",
-value=> $dunitValue, value=> $dunitValue,
-options=>$self->_getDurationUnitHash, options=>$self->_getDurationUnitHash,
-hoverHelp => $i18n->get('duration units hoverhelp'), hoverHelp => $i18n->get('duration units hoverhelp'),
-label => $i18n->get('duration units label'), label => $i18n->get('duration units label'),
-extras=> q|onchange="if(this.value == 'hours'){ document.getElementById('hoursper').style.display='' } else { document.getElementById('hoursper').style.display='none' }"| extras=> q|onchange="if(this.value == 'hours'){ document.getElementById('hoursper').style.display='' } else { document.getElementById('hoursper').style.display='none' }"|
); );
my $hpdLabel = $i18n->get('hours per day label');
my $hpdHoverHelp = $i18n->get('hours per day hoverhelp');
my $hpdValue = $form->get("hoursPerDay") || $project->{hoursPerDay} || "8.0";
my $hpdStyle = ($dunitValue eq "days"?"display:none":"");
my $html = qq| $f->addField( "text",
<tr id="hoursper" style="$hpdStyle"> name => 'hoursPerDay',
<td class="formDescription" valign="top" style="width: 180px;"> label => $i18n->get('hours per day label'),
<div class="wg-hoverhelp">$hpdHoverHelp</div> hoverHelp => $i18n->get('hours per day hoverhelp'),
<label for="hoursPerDay_formId">$hpdLabel</label> value => $form->get("hoursPerDay") || $project->{hoursPerDay} || "8.0",
</td> extras => ($dunitValue eq "days"? q{ style="display:none"} :""),
<td valign="top" class="tableData" style="width: *;"> );
<input id="hoursPerDay_formId" type="text" name="hoursPerDay" value="$hpdValue" size="11" maxlength="14" />
</td> $f->addField( "float",
</tr>|; name=>"targetBudget",
$f->raw($html); value=> $form->get("targetBudget") || $project->{targetBudget} || "0.00",
hoverHelp => $i18n->get('target budget hoverhelp'),
$f->float ( label=> $i18n->get('target budget label')
-name=>"targetBudget",
-value=> $form->get("targetBudget") || $project->{targetBudget} || "0.00",
-hoverHelp => $i18n->get('target budget hoverhelp'),
-label=> $i18n->get('target budget label')
); );
$f->submit( $f->addField( "submit",
-extras=>"name='subbutton'", extras=>"name='subbutton'",
-value=>$addEditText value=>$addEditText
); );
my $jscript = qq| my $jscript = qq|
@ -1221,8 +1216,8 @@ sub www_editProject {
my $errors = $self->processErrors($_[0]); my $errors = $self->processErrors($_[0]);
my $output = $jscript."\n".$errors.$f->print; my $output = $jscript."\n".$errors.$f->toHtml;
return $self->getAdminConsole->render($output,$addEditText); return '<h1>' . $addEditText . '</h1>' . $output;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -0,0 +1,111 @@
# 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 Project Manager
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/lib";
use Test::More;
use Test::Deep;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Test::Mechanize;
use WebGUI::Session;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
my $pm = WebGUI::Test->asset(
className => 'WebGUI::Asset::Wobject::ProjectManager',
groupToAdd => 3,
);
#----------------------------------------------------------------------------
# Tests
#----------------------------------------------------------------------------
# www_editProject
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
$mech->get_ok('/');
$mech->session->user({ userId => 3 });
# Add a new project
my %projectData = (
name => 'Build a Library',
description => 'Build a library to teach them how to be men.',
targetBudget => "80.00",
);
$mech->get_ok( $pm->getUrl( 'func=editProject;projectId=new' ) );
$mech->submit_form_ok( {
fields => { %projectData },
}, "create a new project"
);
# Check if created
my $pj = $session->db->quickHashRef(
"SELECT * FROM PM_project WHERE assetId=?",
[ $pm->getId ],
);
ok( $pj, "project exists" );
cmp_deeply(
$pj,
superhashof({
%projectData,
assetId => $pm->getId,
}),
"Project info correct",
);
# Initial milestone created too
my $task = $session->db->quickHashRef(
"SELECT * FROM PM_task WHERE projectId=?",
[ $pj->{projectId} ],
);
ok( keys %$task, "task exists" );
cmp_deeply(
$task,
superhashof({
projectId => $pj->{projectId},
taskType => "milestone",
}),
"Task info correct",
);
# Now edit it
$projectData{ description } = "Keep those heathens in their place.";
$mech->get_ok( $pm->getUrl( 'func=editProject;projectId=' . $pj->{projectId} ) );
$mech->submit_form_ok( {
fields => { %projectData },
}, "edit project"
);
# Check if edited
my $pj = $session->db->quickHashRef(
"SELECT * FROM PM_project WHERE assetId=?",
[ $pm->getId ],
);
ok( $pj, "edited project exists" );
cmp_deeply(
$pj,
superhashof({
%projectData,
assetId => $pm->getId,
}),
"edited Project info correct",
);
done_testing;
#vim:ft=perl