migrate EMS www_importEvents to FormBuilder

This commit is contained in:
Doug Bell 2011-01-31 20:38:34 -06:00
parent 8ca685e089
commit f077c28c98
2 changed files with 61 additions and 14 deletions

View file

@ -2013,18 +2013,18 @@ sub www_importEvents {
}
# create the form
my $f = WebGUI::HTMLForm->new( $self->session, action => $self->getUrl("func=importEventsSave"), enctype => 'multipart/form-data' );
my $f = WebGUI::FormBuilder->new( $self->session, action => $self->getUrl("func=importEventsSave"), enctype => 'multipart/form-data' );
$f->file(
-label => $i18n->get('choose a file to import'),
-hoverHelp => $i18n->get('import hoverhelp file'),
-name => 'file',
$f->addField( "file",
label => $i18n->get('choose a file to import'),
hoverHelp => $i18n->get('import hoverhelp file'),
name => 'file',
);
$f->yesNo(
-label => $i18n->get('ignore first line'),
-name => 'ignore_first_line',
-hoverHelp => $i18n->get('import hoverhelp first line'),
-defaultValue => scalar $form->param('ignore_first_line'),
$f->addField( "yesNo",
label => $i18n->get('ignore first line'),
name => 'ignore_first_line',
hoverHelp => $i18n->get('import hoverhelp first line'),
defaultValue => scalar $form->param('ignore_first_line'),
);
# create the std & meta fields part of the form
@ -2034,7 +2034,7 @@ sub www_importEvents {
$importableFields{$field->{name}} = $field->{label};
}
my @defaultImportableFields = keys %importableFields;
$f->checkList(
$f->addField( "checkList",
vertical => 1,
showSelectAllButton => 1,
label => 'Fields',
@ -2044,9 +2044,9 @@ sub www_importEvents {
value => scalar $form->get('fieldsToImport'),
);
$f->submit(-value=>$i18n->get('import events'));
$f->addField( "submit", name => "submit", value=>$i18n->get('import events'));
return $self->processStyle($page_header.'<p/>'.$f->print);
return $self->processStyle($page_header.'<p/>'.$f->toHtml);
}
@ -2127,7 +2127,7 @@ $|=1;
foreach my $field (@{$fields}) {
next unless $field->{name} ~~ @import;
$out->print("\tAdding field ".$field->{label}."\n",1);
my $type = $field->{type};
my $type = $field->{type} || "Text";
##Force the use of Form::DateTime and MySQL Format
if ($field->{name} eq 'startDate') {
$type = 'dateTime';

View file

@ -744,3 +744,50 @@ cmp_deeply(
'getEventFieldsForImport contains correct items',
);
#----------------------------------------------------------------------------
# www_importEvents
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
$mech->get_ok('/');
$mech->session->user({ userId => 3 });
$mech->get_ok( $ems->getUrl( 'func=importEvents' ), 'get form to import events' );
$mech->set_fields(
file_file => WebGUI::Test::collateral( "ems_events.csv" ),
ignore_first_line => 1,
);
# Remove the fields we don't have
my @unticks = qw( assetId vendorId seatsAvailable price eventNumber location relatedBadgeGroups
relatedRibbons
);
for my $val ( @unticks ) {
$mech->untick( 'fieldsToImport', $val );
}
$mech->click_ok( "submit", "import files" );
# Events exist
my $events = $ems->getLineage( ['children'], {
includeOnlyClasses => ['WebGUI::Asset::Sku::EMSTicket'],
returnObjects => 1,
} );
is( scalar @$events, 2, '2 events added' );
cmp_deeply(
[ map { $_->get } sort { $a->title cmp $b->title } @$events ],
[ superhashof(
{
title => "One",
description => "Oneness",
startDate => WebGUI::DateTime->new( $session, mysql => '2010-01-01 00:00:00', time_zone => DateTime::TimeZone::Local->TimeZone() )->toMysql,
duration => 2,
}
),
superhashof(
{
title => 'Two',
description => 'Twoness',
startDate => WebGUI::DateTime->new( $session, mysql => '2010-02-02 00:00:00', time_zone => DateTime::TimeZone::Local->TimeZone() )->toMysql,
duration => 3,
}
),
],
'correct asset props are set'
);