move MatrixListing getEditForm to FormBuilder
This commit is contained in:
parent
5ece597592
commit
f209a52a2c
2 changed files with 119 additions and 70 deletions
|
|
@ -209,48 +209,47 @@ sub getEditForm {
|
|||
my $i18n = WebGUI::International->new($session, 'Asset_MatrixListing');
|
||||
my $func = $session->form->process("func");
|
||||
|
||||
# TODO: Change to FormBuilder
|
||||
my $form = WebGUI::HTMLForm->new($session);
|
||||
my $form = WebGUI::FormBuilder->new($session);
|
||||
|
||||
if ($func eq "add" || ( $func eq "editSave" && $session->form->process("assetId") eq "new")) {
|
||||
$form->hidden(
|
||||
-name => 'assetId',
|
||||
-value => 'new',
|
||||
$form->addField( "hidden",
|
||||
name => 'assetId',
|
||||
value => 'new',
|
||||
);
|
||||
$form->hidden(
|
||||
-name => 'class',
|
||||
-value => 'WebGUI::Asset::MatrixListing',
|
||||
$form->addField( "hidden",
|
||||
name => 'class',
|
||||
value => 'WebGUI::Asset::MatrixListing',
|
||||
);
|
||||
}
|
||||
$form->hidden(
|
||||
-name =>'func',
|
||||
-value =>'editSave',
|
||||
$form->addField( "hidden",
|
||||
name =>'func',
|
||||
value =>'editSave',
|
||||
);
|
||||
$form->text(
|
||||
-name =>'title',
|
||||
-defaultValue =>'Untitled',
|
||||
-label =>$i18n->get("product name label"),
|
||||
-hoverHelp =>$i18n->get('product name description'),
|
||||
-value =>$self->title,
|
||||
$form->addField( "text",
|
||||
name =>'title',
|
||||
defaultValue =>'Untitled',
|
||||
label =>$i18n->get("product name label"),
|
||||
hoverHelp =>$i18n->get('product name description'),
|
||||
value =>$self->title,
|
||||
);
|
||||
|
||||
$form->image(
|
||||
-name =>'screenshots',
|
||||
-defaultValue =>undef,
|
||||
-maxAttachments =>20,
|
||||
-label =>$i18n->get("screenshots label"),
|
||||
-hoverHelp =>$i18n->get("screenshots description"),,
|
||||
-value =>$self->screenshots,
|
||||
$form->addField( "image",
|
||||
name =>'screenshots',
|
||||
defaultValue =>undef,
|
||||
maxAttachments =>20,
|
||||
label =>$i18n->get("screenshots label"),
|
||||
hoverHelp =>$i18n->get("screenshots description"),,
|
||||
value =>$self->screenshots,
|
||||
);
|
||||
$form->HTMLArea(
|
||||
-name =>'description',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("description label"),
|
||||
-hoverHelp =>$i18n->get("description description"),
|
||||
-value =>$self->description,
|
||||
$form->addField( "HTMLArea",
|
||||
name =>'description',
|
||||
defaultValue =>undef,
|
||||
label =>$i18n->get("description label"),
|
||||
hoverHelp =>$i18n->get("description description"),
|
||||
value =>$self->description,
|
||||
);
|
||||
if ($self->getParent->canEdit) {
|
||||
$form->user(
|
||||
$form->addField( "user",
|
||||
name =>"ownerUserId",
|
||||
value =>$self->ownerUserId,
|
||||
label =>$i18n->get('maintainer label'),
|
||||
|
|
@ -265,42 +264,42 @@ sub getEditForm {
|
|||
else{
|
||||
$userId = $self->get('ownerUserId');
|
||||
}
|
||||
$form->hidden(
|
||||
-name =>'ownerUserId',
|
||||
-value =>$userId,
|
||||
$form->addField( "hidden",
|
||||
name =>'ownerUserId',
|
||||
value =>$userId,
|
||||
);
|
||||
}
|
||||
$form->text(
|
||||
-name =>'version',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("version label"),
|
||||
-hoverHelp =>$i18n->get("version description"),
|
||||
-value =>$self->version,
|
||||
$form->addField( "text",
|
||||
name =>'version',
|
||||
defaultValue =>undef,
|
||||
label =>$i18n->get("version label"),
|
||||
hoverHelp =>$i18n->get("version description"),
|
||||
value =>$self->version,
|
||||
);
|
||||
$form->text(
|
||||
-name =>'manufacturerName',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("manufacturerName label"),
|
||||
-hoverHelp =>$i18n->get("manufacturerName description"),
|
||||
-value =>$self->manufacturerName,
|
||||
$form->addField( "text",
|
||||
name =>'manufacturerName',
|
||||
defaultValue =>undef,
|
||||
label =>$i18n->get("manufacturerName label"),
|
||||
hoverHelp =>$i18n->get("manufacturerName description"),
|
||||
value =>$self->manufacturerName,
|
||||
);
|
||||
$form->url(
|
||||
-name =>'manufacturerURL',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("manufacturerURL label"),
|
||||
-hoverHelp =>$i18n->get("manufacturerURL description"),
|
||||
-value =>$self->manufacturerURL,
|
||||
$form->addField( "url",
|
||||
name =>'manufacturerURL',
|
||||
defaultValue =>undef,
|
||||
label =>$i18n->get("manufacturerURL label"),
|
||||
hoverHelp =>$i18n->get("manufacturerURL description"),
|
||||
value =>$self->manufacturerURL,
|
||||
);
|
||||
$form->url(
|
||||
-name =>'productURL',
|
||||
-defaultValue =>undef,
|
||||
-label =>$i18n->get("productURL label"),
|
||||
-hoverHelp =>$i18n->get("productURL description"),
|
||||
-value =>$self->productURL,
|
||||
$form->addField( "url",
|
||||
name =>'productURL',
|
||||
defaultValue =>undef,
|
||||
label =>$i18n->get("productURL label"),
|
||||
hoverHelp =>$i18n->get("productURL description"),
|
||||
value =>$self->productURL,
|
||||
);
|
||||
|
||||
foreach my $category (keys %{$self->getParent->getCategories}) {
|
||||
$form->raw('<tr><td colspan="2"><b>'.$category.'</b></td></tr>');
|
||||
my $fieldset = $form->addFieldset( name => $category, label => $category );
|
||||
my $attributes = $db->read("select * from Matrix_attribute where category = ? and assetId = ?",
|
||||
[$category,$matrixId]);
|
||||
while (my $attribute = $attributes->hashRef) {
|
||||
|
|
@ -320,18 +319,16 @@ sub getEditForm {
|
|||
$attribute->{options} = \%options;
|
||||
$attribute->{extras} = "style='width:120px'";
|
||||
}
|
||||
$form->dynamicField(%{$attribute});
|
||||
$fieldset->addField( delete $attribute->{fieldType}, %{$attribute});
|
||||
}
|
||||
}
|
||||
|
||||
$form->raw(
|
||||
'<tr><td COLSPAN=2>'.
|
||||
WebGUI::Form::Submit($session, {}).
|
||||
WebGUI::Form::Button($session, {
|
||||
-value => $i18n->get('cancel', 'WebGUI'),
|
||||
-extras => q|onclick="history.go(-1);" class="backwardButton"|
|
||||
}).
|
||||
'</td></tr>'
|
||||
my $buttons = $form->addField( "ButtonGroup", name => "saveButtons", rowClass => "saveButtons" );
|
||||
$buttons->addButton( "Submit", name => "submit" );
|
||||
$buttons->addButton( "Button",
|
||||
name => "cancel",
|
||||
value => $i18n->get('cancel', 'WebGUI'),
|
||||
extras => q{onclick="history.go(-1);" class="backwardButton"},
|
||||
);
|
||||
|
||||
return $form;
|
||||
|
|
|
|||
|
|
@ -14,20 +14,72 @@ use strict;
|
|||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 2; # increment this value for each test you create
|
||||
use Test::More tests => 14; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use WebGUI::Asset::Wobject::Matrix;
|
||||
use WebGUI::Asset::MatrixListing;
|
||||
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
$session->user({ userId => 3 });
|
||||
my ($matrix, $matrixListing);
|
||||
$matrix = WebGUI::Test->asset(className=>'WebGUI::Asset::Wobject::Matrix');
|
||||
$matrix = WebGUI::Test->asset(
|
||||
className => 'WebGUI::Asset::Wobject::Matrix',
|
||||
categories => "One\nTwo\nThree",
|
||||
groupIdEdit => '3',
|
||||
);
|
||||
|
||||
# Can't set attributeId here or new attributes won't get added
|
||||
my $styleId = $matrix->editAttributeSave( {
|
||||
assetId => $matrix->getId,
|
||||
category => "One",
|
||||
name => "Style",
|
||||
fieldType => "textarea",
|
||||
} );
|
||||
my $colorId = $matrix->editAttributeSave( {
|
||||
assetId => $matrix->getId,
|
||||
category => "One",
|
||||
name => "Color",
|
||||
fieldType => "text",
|
||||
} );
|
||||
my $shapeId = $matrix->editAttributeSave( {
|
||||
assetId => $matrix->getId,
|
||||
category => "Two",
|
||||
name => "Shape",
|
||||
fieldType => "selectBox",
|
||||
options => "square\ncircle\noval\ntriangle",
|
||||
} );
|
||||
my $sheepId = $matrix->editAttributeSave( {
|
||||
assetId => $matrix->getId,
|
||||
category => "Three",
|
||||
name => "Sheep",
|
||||
fieldType => "yesNo",
|
||||
} );
|
||||
$matrixListing = $matrix->addChild({className=>'WebGUI::Asset::MatrixListing'});
|
||||
|
||||
# Test for sane object types
|
||||
isa_ok($matrix, 'WebGUI::Asset::Wobject::Matrix');
|
||||
isa_ok($matrixListing, 'WebGUI::Asset::MatrixListing');
|
||||
|
||||
# Test for proper edit form
|
||||
my $fb = $matrixListing->getEditForm;
|
||||
|
||||
my ( $fieldset, $field );
|
||||
ok( $fieldset = $fb->getFieldset( "One" ), "getEditForm has fieldset for One category" );
|
||||
ok( $field = $fieldset->getField( "attribute_$styleId" ), "fieldset has field for style" );
|
||||
isa_ok( $field, 'WebGUI::Form::Textarea' );
|
||||
ok( $field = $fieldset->getField( "attribute_$colorId" ), "fieldset has field for color" );
|
||||
isa_ok( $field, 'WebGUI::Form::Text' );
|
||||
|
||||
ok( $fieldset = $fb->getFieldset( "Two" ), "getEditForm has fieldset for Two category" );
|
||||
ok( $field = $fieldset->getField( "attribute_$shapeId" ), "fieldset has field for shape" );
|
||||
isa_ok( $field, 'WebGUI::Form::SelectBox' );
|
||||
is( $field->get('options'), join("\n", "square", "circle", "oval", "triangle" ), "correct select options" );
|
||||
|
||||
ok( $fieldset = $fb->getFieldset( "Three" ), "getEditForm has fieldset for Three category" );
|
||||
ok( $field = $fieldset->getField( "attribute_$sheepId" ), 'fieldset has field for sheep' );
|
||||
isa_ok( $field, 'WebGUI::Form::YesNo' );
|
||||
|
||||
# Try to add content under a MatrixListing asset
|
||||
#my $article = $matrixListing->addChild({className=>'WebGUI::Asset::Wobject::Article'});
|
||||
#is($article, undef, "Can't add an Article wobject as a child to a Matrix Listing.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue