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 $i18n = WebGUI::International->new($session, 'Asset_MatrixListing');
|
||||||
my $func = $session->form->process("func");
|
my $func = $session->form->process("func");
|
||||||
|
|
||||||
# TODO: Change to FormBuilder
|
my $form = WebGUI::FormBuilder->new($session);
|
||||||
my $form = WebGUI::HTMLForm->new($session);
|
|
||||||
|
|
||||||
if ($func eq "add" || ( $func eq "editSave" && $session->form->process("assetId") eq "new")) {
|
if ($func eq "add" || ( $func eq "editSave" && $session->form->process("assetId") eq "new")) {
|
||||||
$form->hidden(
|
$form->addField( "hidden",
|
||||||
-name => 'assetId',
|
name => 'assetId',
|
||||||
-value => 'new',
|
value => 'new',
|
||||||
);
|
);
|
||||||
$form->hidden(
|
$form->addField( "hidden",
|
||||||
-name => 'class',
|
name => 'class',
|
||||||
-value => 'WebGUI::Asset::MatrixListing',
|
value => 'WebGUI::Asset::MatrixListing',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$form->hidden(
|
$form->addField( "hidden",
|
||||||
-name =>'func',
|
name =>'func',
|
||||||
-value =>'editSave',
|
value =>'editSave',
|
||||||
);
|
);
|
||||||
$form->text(
|
$form->addField( "text",
|
||||||
-name =>'title',
|
name =>'title',
|
||||||
-defaultValue =>'Untitled',
|
defaultValue =>'Untitled',
|
||||||
-label =>$i18n->get("product name label"),
|
label =>$i18n->get("product name label"),
|
||||||
-hoverHelp =>$i18n->get('product name description'),
|
hoverHelp =>$i18n->get('product name description'),
|
||||||
-value =>$self->title,
|
value =>$self->title,
|
||||||
);
|
);
|
||||||
|
|
||||||
$form->image(
|
$form->addField( "image",
|
||||||
-name =>'screenshots',
|
name =>'screenshots',
|
||||||
-defaultValue =>undef,
|
defaultValue =>undef,
|
||||||
-maxAttachments =>20,
|
maxAttachments =>20,
|
||||||
-label =>$i18n->get("screenshots label"),
|
label =>$i18n->get("screenshots label"),
|
||||||
-hoverHelp =>$i18n->get("screenshots description"),,
|
hoverHelp =>$i18n->get("screenshots description"),,
|
||||||
-value =>$self->screenshots,
|
value =>$self->screenshots,
|
||||||
);
|
);
|
||||||
$form->HTMLArea(
|
$form->addField( "HTMLArea",
|
||||||
-name =>'description',
|
name =>'description',
|
||||||
-defaultValue =>undef,
|
defaultValue =>undef,
|
||||||
-label =>$i18n->get("description label"),
|
label =>$i18n->get("description label"),
|
||||||
-hoverHelp =>$i18n->get("description description"),
|
hoverHelp =>$i18n->get("description description"),
|
||||||
-value =>$self->description,
|
value =>$self->description,
|
||||||
);
|
);
|
||||||
if ($self->getParent->canEdit) {
|
if ($self->getParent->canEdit) {
|
||||||
$form->user(
|
$form->addField( "user",
|
||||||
name =>"ownerUserId",
|
name =>"ownerUserId",
|
||||||
value =>$self->ownerUserId,
|
value =>$self->ownerUserId,
|
||||||
label =>$i18n->get('maintainer label'),
|
label =>$i18n->get('maintainer label'),
|
||||||
|
|
@ -265,42 +264,42 @@ sub getEditForm {
|
||||||
else{
|
else{
|
||||||
$userId = $self->get('ownerUserId');
|
$userId = $self->get('ownerUserId');
|
||||||
}
|
}
|
||||||
$form->hidden(
|
$form->addField( "hidden",
|
||||||
-name =>'ownerUserId',
|
name =>'ownerUserId',
|
||||||
-value =>$userId,
|
value =>$userId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$form->text(
|
$form->addField( "text",
|
||||||
-name =>'version',
|
name =>'version',
|
||||||
-defaultValue =>undef,
|
defaultValue =>undef,
|
||||||
-label =>$i18n->get("version label"),
|
label =>$i18n->get("version label"),
|
||||||
-hoverHelp =>$i18n->get("version description"),
|
hoverHelp =>$i18n->get("version description"),
|
||||||
-value =>$self->version,
|
value =>$self->version,
|
||||||
);
|
);
|
||||||
$form->text(
|
$form->addField( "text",
|
||||||
-name =>'manufacturerName',
|
name =>'manufacturerName',
|
||||||
-defaultValue =>undef,
|
defaultValue =>undef,
|
||||||
-label =>$i18n->get("manufacturerName label"),
|
label =>$i18n->get("manufacturerName label"),
|
||||||
-hoverHelp =>$i18n->get("manufacturerName description"),
|
hoverHelp =>$i18n->get("manufacturerName description"),
|
||||||
-value =>$self->manufacturerName,
|
value =>$self->manufacturerName,
|
||||||
);
|
);
|
||||||
$form->url(
|
$form->addField( "url",
|
||||||
-name =>'manufacturerURL',
|
name =>'manufacturerURL',
|
||||||
-defaultValue =>undef,
|
defaultValue =>undef,
|
||||||
-label =>$i18n->get("manufacturerURL label"),
|
label =>$i18n->get("manufacturerURL label"),
|
||||||
-hoverHelp =>$i18n->get("manufacturerURL description"),
|
hoverHelp =>$i18n->get("manufacturerURL description"),
|
||||||
-value =>$self->manufacturerURL,
|
value =>$self->manufacturerURL,
|
||||||
);
|
);
|
||||||
$form->url(
|
$form->addField( "url",
|
||||||
-name =>'productURL',
|
name =>'productURL',
|
||||||
-defaultValue =>undef,
|
defaultValue =>undef,
|
||||||
-label =>$i18n->get("productURL label"),
|
label =>$i18n->get("productURL label"),
|
||||||
-hoverHelp =>$i18n->get("productURL description"),
|
hoverHelp =>$i18n->get("productURL description"),
|
||||||
-value =>$self->productURL,
|
value =>$self->productURL,
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach my $category (keys %{$self->getParent->getCategories}) {
|
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 = ?",
|
my $attributes = $db->read("select * from Matrix_attribute where category = ? and assetId = ?",
|
||||||
[$category,$matrixId]);
|
[$category,$matrixId]);
|
||||||
while (my $attribute = $attributes->hashRef) {
|
while (my $attribute = $attributes->hashRef) {
|
||||||
|
|
@ -320,18 +319,16 @@ sub getEditForm {
|
||||||
$attribute->{options} = \%options;
|
$attribute->{options} = \%options;
|
||||||
$attribute->{extras} = "style='width:120px'";
|
$attribute->{extras} = "style='width:120px'";
|
||||||
}
|
}
|
||||||
$form->dynamicField(%{$attribute});
|
$fieldset->addField( delete $attribute->{fieldType}, %{$attribute});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$form->raw(
|
my $buttons = $form->addField( "ButtonGroup", name => "saveButtons", rowClass => "saveButtons" );
|
||||||
'<tr><td COLSPAN=2>'.
|
$buttons->addButton( "Submit", name => "submit" );
|
||||||
WebGUI::Form::Submit($session, {}).
|
$buttons->addButton( "Button",
|
||||||
WebGUI::Form::Button($session, {
|
name => "cancel",
|
||||||
-value => $i18n->get('cancel', 'WebGUI'),
|
value => $i18n->get('cancel', 'WebGUI'),
|
||||||
-extras => q|onclick="history.go(-1);" class="backwardButton"|
|
extras => q{onclick="history.go(-1);" class="backwardButton"},
|
||||||
}).
|
|
||||||
'</td></tr>'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
|
|
|
||||||
|
|
@ -14,20 +14,72 @@ use strict;
|
||||||
|
|
||||||
use WebGUI::Test;
|
use WebGUI::Test;
|
||||||
use WebGUI::Session;
|
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::Wobject::Matrix;
|
||||||
use WebGUI::Asset::MatrixListing;
|
use WebGUI::Asset::MatrixListing;
|
||||||
|
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
$session->user({ userId => 3 });
|
||||||
my ($matrix, $matrixListing);
|
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'});
|
$matrixListing = $matrix->addChild({className=>'WebGUI::Asset::MatrixListing'});
|
||||||
|
|
||||||
# Test for sane object types
|
# Test for sane object types
|
||||||
isa_ok($matrix, 'WebGUI::Asset::Wobject::Matrix');
|
isa_ok($matrix, 'WebGUI::Asset::Wobject::Matrix');
|
||||||
isa_ok($matrixListing, 'WebGUI::Asset::MatrixListing');
|
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
|
# Try to add content under a MatrixListing asset
|
||||||
#my $article = $matrixListing->addChild({className=>'WebGUI::Asset::Wobject::Article'});
|
#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.");
|
#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