last version with tabbed form description

This commit is contained in:
daviddelikat 2009-10-20 09:06:19 -05:00
parent 9805541a6e
commit 378c73dd31
3 changed files with 330 additions and 81 deletions

View file

@ -52,7 +52,7 @@ These methods are available from this class:
=cut =cut
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 _generateFields ( tabform, targetField ) =head2 _generateFields ( tabform, targetField, formDescription )
adds input fields to the tab based on the target field adds input fields to the tab based on the target field
TODO: I should put this in the EMSSubmissionForm module instead TODO: I should put this in the EMSSubmissionForm module instead
@ -65,6 +65,10 @@ must be a tabform object
this is the definition of the field being described by the fields in the tab this is the definition of the field being described by the fields in the tab
=head3 formDescription
HASHREF to the current description
=cut =cut
my $generators; my $generators;
@ -77,13 +81,14 @@ sub _generateFields {
my $formDescription = shift; my $formDescription = shift;
my $fieldId = $targetField->{fieldId}; my $fieldId = $targetField->{fieldId};
my $fieldDescription = $formDescription->{$fieldId}; my $fieldDescription = $formDescription->{$fieldId};
my $dummy = $generators->{dummy}; my $dummy = $generators->{dummy}{generate};
my $tab = $tabform->getTab($targetField->{fieldId}); my $tab = $tabform->getTab($targetField->{fieldId});
dav::log '_generateFields::fieldId:', $targetField->{fieldId}; dav::log '_generateFields::fieldId:', $targetField->{fieldId};
# TODO internationalize these
$tab->checkbox(label => 'turn this field on', $tab->checkbox(label => 'turn this field on',
name => 'fieldSwitchList', name => 'activeFields',
value => $fieldId, value => $fieldId,
checked => $fieldDescription->{on} || 0, checked => $fieldDescription->{on} || 0,
); );
@ -91,7 +96,7 @@ dav::log '_generateFields::fieldId:', $targetField->{fieldId};
name => $fieldId . '_displayOrder', name => $fieldId . '_displayOrder',
value => $fieldDescription->{displayOrder} || 0, value => $fieldDescription->{displayOrder} || 0,
); );
($generators->{$targetField->{fieldType}} || $dummy)->($tab,$targetField,$fieldDescription); (($generators->{$targetField->{fieldType}}||{})->{generate} || $dummy)->($tab,$fieldId,$fieldDescription);
$tab->checkbox(label => 'value is required', $tab->checkbox(label => 'value is required',
name => 'requiredFields', name => 'requiredFields',
value => $fieldId, value => $fieldId,
@ -109,111 +114,329 @@ dav::log '_generateFields::fieldId:', $targetField->{fieldId};
name => $fieldId . '_overrideHelp', name => $fieldId . '_overrideHelp',
value => $fieldDescription->{overrideHelp} || '', value => $fieldDescription->{overrideHelp} || '',
); );
$tab->hidden(
name => $fieldId . '_fieldType',
value => $targetField->{fieldType} || '',
);
} }
#-------------------------------------------------------------------
=head2 _readFields ( form, fieldId, formDescription )
copy field description values from session->form to description
=head3 form
the current session->form object
=head3 fieldId
fieldId for the field we are processing
=head3 formDescription
HASHREF to the current description
=cut
sub _readFields {
my $form = shift;
my $fieldId = shift;
my $formDescription = shift;
my $fieldDescription = $formDescription->{$fieldId} ||= {fieldType => $targetField->{fieldType}};
my $dummy = $generators->{dummy}{readForm};
# we get the default value even if the field is not active...
$fieldDescription->{defaultValue} = $form->get($fieldId . '_defaultValue');
return if ! grep $fieldId, ( @{$formDescription->{activeFields}} );
$fieldDescription->{on} = 1;
$fieldDescription->{required} = grep $fieldId, ( @{$formDescription->{requiredFields}} );
$fieldDescription->{displayOrder} = $form->get( $fieldId . '_displayOrder' );
$fieldDescription->{overrideLabel} = $form->get($fieldId . '_overrideLabel');
$fieldDescription->{overrideHelp} = $form->get($fieldId . '_overrideHelp');
$fieldDescription->{fieldType} = $form->get($fieldId . '_fieldType');
(($generators->{$description->{fieldType}}||{})->{readForm} || $dummy)->($form,$targetField,$fieldDescription);
}
# FUTURE: this list of functions shouldbe defined in the control classes themselves # FUTURE: this list of functions shouldbe defined in the control classes themselves
$generators = { $generators = {
dummy => sub { dummy => { generate => sub {
my $tab = shift; my $tab = shift;
my $field = shift; my $fieldId = shift;
my $description = shift; my $description = shift;
$tab->readOnly( $tab->readOnly(
label => 'ERROR', label => 'ERROR',
value => $field->{fieldType} . ' is not defined in EMS Submission Form generators list', value => $description->{fieldType} . ' is not defined in EMS Submission Form generators list',
); );
}, },
dateTime => sub { readForm => sub {
# nothing to do here...
} },
dateTime => { generate => sub {
my $tab = shift; my $tab = shift;
my $field = shift; my $fieldId = shift;
my $description = shift;
$tab->selectList(
name => $fieldId . '_dateSelect',
multiple => 0,
size => 2,
options => {
# TODO internationalize this
selectList => 'select list',
dateSelect => 'date select',
},
defaultValue => $description->{dateSelect} || ['dateSelect'],
label => 'datetime selection label',
hoverHelp => 'datetime selection help',
);
$tab->textarea(
name => $fieldId . '_dateTextArea',
label => 'datetime textarea label',
hoverHelp => 'datetime textarea help',
defaultValue => $description->{dateTextArea} || '',
)
},
readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
$description->{dateSelect} = $form->get($fieldId . '_dateSelect');
my @options;
for my $item ( split( , $form->get($fieldId . '_dateTextArea') ) {
push @options, WebGUI::DateTime->new($item)->epoch;
}
$description->{dateTextArea} = [ @options ];
# TODO perhaps we need to verify the text area is valid?
}, },
checkList => { generate => sub {
my $tab = shift;
my $fieldId = shift;
my $description = shift;
$tab->textarea(
name => $fieldId . '_dateTextArea',
label => 'checklist textarea label',
hoverHelp => 'checklist textarea help',
defaultValue => $description->{checkListTextArea} || '',
);
},
readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
$description->{checkListTextArea} = $form->get($fieldId . '_checkListTextArea');
}, },
combo => { generate => sub {
my $tab = shift;
my $fieldId = shift;
my $description = shift; my $description = shift;
$tab->readOnly( $tab->readOnly(
label => 'TODO', label => 'TODO',
value => $field->{fieldType} . ' needs work<br> value => 'combo needs work<br>
add selectlist, range or date-select options ',
);
},
checkList => sub {
my $tab = shift;
my $field = shift;
my $description = shift;
$tab->readOnly(
label => 'TODO',
value => $field->{fieldType} . ' needs work<br>
add textarea for a list of options',
);
},
combo => sub {
my $tab = shift;
my $field = shift;
my $description = shift;
$tab->readOnly(
label => 'TODO',
value => $field->{fieldType} . ' needs work<br>
hmmm, needs some thought...', hmmm, needs some thought...',
); );
}, },
integer => sub { readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
# add the correct variables to the description hash that is passed in
}, },
integer => { generate => sub {
my $tab = shift; my $tab = shift;
my $field = shift; my $fieldId = shift;
my $description = shift;
$tab->text(
name => $fieldId . '_integerMin',
label => 'integer min label',
hoverHelp => 'integer min help',
defaultValue => $description->{integerMin} || '',
);
$tab->text(
name => $fieldId . '_integerMax',
label => 'integer max label',
hoverHelp => 'integer max help',
defaultValue => $description->{integerMax} || '',
);
},
readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
$description->{integerMax} = $form->get($fieldId . '_integerMax');
$description->{integerMin} = $form->get($fieldId . '_integerMin');
}, },
float => { generate => sub {
my $tab = shift;
my $fieldId = shift;
my $description = shift;
$tab->text(
name => $fieldId . '_floatMin',
label => 'float min label',
hoverHelp => 'float min help',
defaultValue => $description->{floatMin} || '',
);
$tab->text(
name => $fieldId . '_floatMax',
label => 'float max label',
hoverHelp => 'float max help',
defaultValue => $description->{floatMax} || '',
);
},
readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
$description->{floatMax} = $form->get($fieldId . '_floatMax');
$description->{floatMin} = $form->get($fieldId . '_floatMin');
}, },
vendor => { generate => sub {
my $tab = shift;
my $fieldId = shift;
my $description = shift; my $description = shift;
$tab->readOnly( $tab->readOnly(
label => 'TODO', label => 'TODO',
value => $field->{fieldType} . ' needs work<br> value => 'vendor needs work -- this might get eliminated',
add max and min options (each needs a checkbox)',
); );
}, },
float => sub { readForm => sub {
my $tab = shift; my $form = shift;
my $field = shift; my $fieldId = shift;
my $description = shift; my $description = shift;
$tab->readOnly( # add the correct variables to the description hash that is passed in
label => 'TODO', }, },
value => $field->{fieldType} . ' needs work<br> yesNo => { generate => sub {
add max and min options (each needs a checkbox)<br>
add precision default = 1',
);
},
vendor => sub {
my $tab = shift; my $tab = shift;
my $field = shift; my $fieldId = shift;
my $description = shift; my $description = shift;
$tab->readOnly( # nothing here...
label => 'TODO', #$tab->readOnly(
value => $field->{fieldType} . ' needs work -- this might get eliminated', # label => 'TODO',
); # value => $field->{fieldType} . ' needs work -- possibly no extra options',
# );
}, },
yesNo => sub { readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
# nothing here...
}, },
text => { generate => sub {
my $tab = shift; my $tab = shift;
my $field = shift; my $fieldId = shift;
my $description = shift; my $description = shift;
$tab->readOnly( $tab->list(
label => 'TODO', name => $fieldId . '_textSelect',
value => $field->{fieldType} . ' needs work -- possibly no extra options', multiple => 0,
options => {
# TODO internationalize this
selectList => 'select list',
freeText => 'free text',
},
defaultValue => $description->{dateSelect} || ['freeText'],
label => 'text selection label',
hoverHelp => 'text selection help',
);
$tab->textarea(
name => $fieldId . '_textTextArea',
label => 'text textarea label',
hoverHelp => 'text textarea help',
defaultValue => $description->{textTextArea} || '',
); );
}, },
text => sub { readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
$description->{textSelect} = $form->get($fieldId . '_textSelect');
$description->{textTextArea} = $form->get($fieldId . '_textTextArea');
}, },
textarea => { generate => sub {
my $tab = shift; my $tab = shift;
my $field = shift; my $fieldId = shift;
my $description = shift; my $description = shift;
$tab->readOnly( # nothing here...
label => 'TODO', #$tab->readOnly(
value => $field->{fieldType} . ' needs work -- might get eliminated or have no options', # label => 'TODO',
); # value => $field->{fieldType} . ' needs work -- might get eliminated or have no options',
# );
}, },
HTMLArea => sub { readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
# nothing here...
}, },
file => { generate => sub {
my $tab = shift; my $tab = shift;
my $field = shift; my $fieldId = shift;
my $description = shift; my $description = shift;
$tab->readOnly( # nothing here...
label => 'TODO', #$tab->readOnly(
value => $field->{fieldType} . ' needs work -- might get eliminated or have no options', # label => 'TODO',
); # value => $field->{fieldType} . ' needs work -- might get eliminated or have no options',
# );
}, },
readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
# nothing here...
}, },
HTMLArea => { generate => sub {
my $tab = shift;
my $fieldId = shift;
my $description = shift;
# nothing here...
#$tab->readOnly(
# label => 'TODO',
# value => $field->{fieldType} . ' needs work -- might get eliminated or have no options',
# );
},
readForm => sub {
my $form = shift;
my $fieldId = shift;
my $description = shift;
# nothing here...
}, },
# TODO add all of the other control types # TODO add all of the other control types
}; };
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 _readForm ( parent, @fieldIds )
reads the form description out of the session->form
=head3 parent
the parent of the form
=head3 fieldIds
list of fieldIds that are in the form
=cut
sub _readForm {
my $parent = shift;
my $form = shift;
my $fieldList = shift;
my $formDescription;
$formDescription->{activeFields} = [ split ' ', $form->get('activeFields') ];
$formDescription->{requiredFields} = [ split ' ', $form->get('requiredFields') ];
for my $fieldId ( split ' ', $fieldList ) {
_readFields($form,$fieldId,$formDescription);
}
}
#-------------------------------------------------------------------
=head2 addSubmission =head2 addSubmission
Creates an EMSSubmission object based on the params Creates an EMSSubmission object based on the params
@ -239,7 +462,7 @@ sub addSubmission {
=head2 addRevision =head2 addRevision
This method exists for demonstration purposes only. The superclass This me>thod exists for demonstration purposes only. The superclass
handles revisions to NewAsset Assets. handles revisions to NewAsset Assets.
=cut =cut
@ -533,20 +756,39 @@ sub validateSubmissionField {
} }
if( $fieldDef->{required} && $value eq '' ) { if( $fieldDef->{required} && $value eq '' ) {
$target->{isvalid} = 0; $target->{isvalid} = 0;
push @{$target->{errors}}, $name . ' is a required field'; push @{$target->{errors}}, $name . ' is a required field'; # TODO internationalize
return 0; return 0;
} }
my $type = $fieldDef->{type}; my $type = $fieldDef->{type};
if( $type eq 'url' ) { if( $type eq 'url' ) {
if( $value !~ /^http:/ ) { # TODO get a better test for Earls if( $value !~ /^http:/ ) { # TODO get a better test for Earls
$target->{isValid} = 0; $target->{isValid} = 0;
push @{$target->{errors}}, $name . ' is not a valid Url'; push @{$target->{errors}}, $name . ' is not a valid Url'; # TODO internationalize
return 0; return 0;
} }
} elsif( $type eq 'integer' ) { } elsif( $type eq 'integer' ) {
$value = int( $value ); $value = int( $value );
if( $fieldDef{integerMin} ne '' && $value < $fieldDef{integerMin} ) {
$target->{isValid} = 0;
push @{$target->{errors}}, $name . ' is less than the minimum allowed'; # TODO internationalize
return 0;
}
if( $fieldDef{integerMax} ne '' && $value > $fieldDef{integerMax} ) {
$target->{isValid} = 0;
push @{$target->{errors}}, $name . ' is greater than the maximum allowed'; # TODO internationalize
return 0;
}
} elsif( $type eq 'float' ) { } elsif( $type eq 'float' ) {
; # there is no test here... if( $fieldDef{floatMin} ne '' && $value < $fieldDef{floatMin} ) {
$target->{isValid} = 0;
push @{$target->{errors}}, $name . ' is less than the minimum allowed'; # TODO internationalize
return 0;
}
if( $fieldDef{floatMax} ne '' && $value > $fieldDef{floatMax} ) {
$target->{isValid} = 0;
push @{$target->{errors}}, $name . ' is greater than the maximum allowed'; # TODO internationalize
return 0;
}
} elsif( $type eq 'text' ) { } elsif( $type eq 'text' ) {
; # there is no test here... ; # there is no test here...
} elsif( $type eq 'textarea' ) { } elsif( $type eq 'textarea' ) {
@ -630,8 +872,7 @@ sub editSubmissionForm {
my $tabform = WebGUI::TabForm->new($session,undef,undef,$parent->getUrl()); my $tabform = WebGUI::TabForm->new($session,undef,undef,$parent->getUrl());
my $fields; my $fields;
# fixed order for the regular tabs # fixed order for the regular tabs
my @fieldNames = qw/startDate duration seatsAvailable location my @fieldNames = qw/startDate duration seatsAvailable location /;
relatedBadgeGroups sku vendorId shipsSeparately price/;
my @defs = reverse @{WebGUI::Asset::EMSSubmission->definition($session)}; my @defs = reverse @{WebGUI::Asset::EMSSubmission->definition($session)};
dav::dump 'editSubmissionForm::definition:', [@defs]; dav::dump 'editSubmissionForm::definition:', [@defs];
for my $def ( @defs ) { for my $def ( @defs ) {
@ -658,6 +899,7 @@ dav::dump 'editSubmissionForm::definition:', [@defs];
$tabform->addTab($tabname, $fields->{$tabname}{label}, $0 ); $tabform->addTab($tabname, $fields->{$tabname}{label}, $0 );
} }
my $maintab = $tabform->getTab('main'); my $maintab = $tabform->getTab('main');
$maintab->hidden(name => 'fieldList', value => join( ' ', @fieldNames ) );
@defs = reverse @{WebGUI::Asset::EMSSubmissionForm->definition($session)}; @defs = reverse @{WebGUI::Asset::EMSSubmissionForm->definition($session)};
dav::dump 'editSubmissionForm::dump submission form def', \@defs ; dav::dump 'editSubmissionForm::dump submission form def', \@defs ;
for my $def ( @defs ) { for my $def ( @defs ) {
@ -675,8 +917,9 @@ dav::dump 'editSubmissionForm::properties for ', $fieldName, \%param ;
} }
dav::dump 'editSubmissionForm::dump before generate:',$fields; dav::dump 'editSubmissionForm::dump before generate:',$fields;
my $formDescription; my $formDescription;
if( $form->get('formDescription') ) { # TODO move the fieldList to session scratch or something on the server... - this is a security issue...
$formDescription = JSON->new->decode($form->get('formDescription')); if( my $fieldList = $form->get('fieldList') ) { # if this form variable exists then the form was submitted...
$formDescription = _readForm($parent,$form,$fieldList); # so we get the description from the form
} else { } else {
$formDescription = $self ? $self->getFormDescription : { }; $formDescription = $self ? $self->getFormDescription : { };
} }

View file

@ -850,7 +850,9 @@ sub www_editSubmissionFormSave {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit; return $self->session->privilege->insufficient() unless $self->canEdit;
my $form = $self->session->form; my $form = $self->session->form;
# TOOD call addSubmissionForm or update the submission form... return WebGUI::Asset::EMSSubmissionForm->processForm($self,); # TODO this function does not exist yet
# it should read the form and verify the data
# TODO call addSubmissionForm or update the submission form...
# call edit if it fails # call edit if it fails
return $self->www_view; # TODO where to go after this??? return $self->www_view; # TODO where to go after this???
} }

View file

@ -69,8 +69,10 @@ sub logout { $session->user({userId => 1}); }
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# put your tests here # put your tests here
use_ok 'WebGUI::Asset::EMSSubmissionForm'; my $useform = use_ok 'WebGUI::Asset::EMSSubmissionForm';
use_ok 'WebGUI::Asset::EMSSubmission'; my $usesubmiss = use_ok 'WebGUI::Asset::EMSSubmission';
SKIP: { skip 'package compile failed!', 50 unless $useform && $usesubmiss;
loginAdmin; loginAdmin;
@ -343,13 +345,15 @@ is( $sub2, undef, 'approval created a ticket');
# TODO add a test to cleanup denied and created entries # TODO add a test to cleanup denied and created entries
} # end of skip } # end of create submission skip
$versionTag->commit; $versionTag->commit;
# TODO either remove this or make it a real test. # TODO either remove this or make it a real test.
loginAdmin; #loginAdmin;
print $ems->www_addSubmissionForm; #print $ems->www_addSubmissionForm;
} # end of use packages skip
#done_testing(); #done_testing();
#print 'press return to complete test' ; <>; #print 'press return to complete test' ; <>;