package Template::Parser::Form; $Template::Parser::Form::VERSION = 2.07; # use strict coding pragma use strict; # make expt traces for diagnostic debug use expt_handler; # -------------------------------------------------------- # Constructor # -------------------------------------------------------- sub new { my($class) = shift; my(%in) = @_; my($this) = {}; my($name) = __PACKAGE__; # ------------------------------------------- # bless object ref into the class' namespace # ------------------------------------------- bless($this, $class); # ------------------------------------------- # begin setting up class attributes # ------------------------------------------- $this->{'name'} = $name; $this->{'pcom'} = $in{'main'} || undef; $this->{'parser'} = $in{'parser'} || undef; $this->{'cgi'} = $in{'cgi'} || undef; $this->{'expt'} = expt_handler->new(); # ------------------------------------------- # finish by verifying class attributes # ------------------------------------------- $this->verify_attributes(); # return object reference return($this); } # -------------------------------------------------------- # Template::Parser::Form::verify_attributes() # -------------------------------------------------------- sub verify_attributes { my($this) = shift; my($name) = $this->{'name'}; my($expt) = $this->{'expt'}; $expt-> belly_up ( qq[$name needs a PCOM object] ) if not ($this->{'pcom'}); $expt-> belly_up ( qq[$name needs a CGI object] ) if (not $this->{'cgi'}); $expt-> belly_up ( qq[$name needs a Template::Parser object] ) if (not $this->{'parser'}); return(1); } # -------------------------------------------------------- # Template::Parser::Form::make_form() # -------------------------------------------------------- sub make_form { my($this) = shift; my(%in) = @_; my($pcom) = $this->{'pcom'}; my($parser) = $this->{'parser'}; my($cgi) = $this->{'cgi'}; my($def) = $in{'def preloaded'}; my($object) = $pcom->{'DIR'}{'objects'}.'/'.$in{'object'}; my($layout) = $parser->load_object( $object ); my($form) = $in{'form'}; my($option) = ''; my($field) = ''; my($i) = 0; $parser-> set_object ( 'name' => 'live_cmpts', 'value' => $layout, ); if (length($def) == 0) { $def = $pcom->{'DIR'}{'defs'}.'/minidefs/'.$in{'def'}.'.mdef'; $def = $parser->load_file( $def ); } $parser-> set_object ( 'name' => 'form', 'value' => $form, ); $def = $parser->parse( $def ); $this-> {'expt'}-> fwarn ( $def ) if ($this->{'verbose'}); if (CORE::eval($def)) { $def = CORE::eval( $def ); } else { warn($@); } foreach $field (@{ $def->{'fields'} }) { ++$i; $field->{'iterator'} = $i; $parser-> set_object ( 'name' => 'formfield', 'value' => $field, ); if (($field->{'type'} ne 'hidden') && ($field->{'type'} ne 'select')) { $layout->{'tmp'} .= $parser->parse( $layout->{'body'} ); next; } if ($field->{'type'} eq 'hidden') { $layout->{'hiddenfields'} .= $parser->parse( $layout->{'hidden'} ); } elsif ($field->{'type'} eq 'select') { my($sel) = ''; foreach $option (@{ $field->{'options'} }) { $parser-> set_object ( 'name' => 'option', 'value' => $option, ); $sel .= $parser->parse( $layout->{'option'} ); } $parser-> set_object ( 'name' => 'select', 'param' => 'options', 'value' => $sel, ); $layout->{'tmp'} .= $parser->parse( $layout->{'body'} ); } } $parser-> set_object ( 'name' => 'form', 'param' => 'hidden', 'value' => $layout->{'hiddenfields'}, ); if ($layout->{'tmp'}) { # put cap and toe on the just-conglommerated layout body $layout-> {'parsed'} = $parser->parse($layout->{'header'}). $layout->{'tmp'}. $parser->parse( $layout->{'footer'}); } else { # or put cap and toe on the empty return $layout-> {'parsed'} = $parser-> parse ( $layout->{'header'}. $layout->{'empty'}. $layout->{'footer'} ); } # return the parsed object now return($layout->{'parsed'}); } # -------------------------------------------------------- # Template::Parser::Form::get_form() # -------------------------------------------------------- sub get_form { my($this) = shift; my(%in) = @_; my($def) = $in{'def'}; my($object) = $in{'object'}; my($form) = { 'name' => $in{'object'}, 'action' => $in{'action'}, 'method' => $in{'method'} || 'post', }; return ( $this-> make_form ( 'def' => $def, 'object' => $object, 'form' => $form, ) ); } # -------------------------------------------------------- # Template::Parser::Form::DESTROY() # -------------------------------------------------------- sub DESTROY {} 1; $Template::Parser::Form::cmpos = {}; $Template::Parser::Form::cmpos = { 'body' => <<'__cmpo__', {'input-width'} ||= '250'; $formfield->{'label-width'} ||= '150'; # take care of formfields that have null styles if (!$formfield->{'label-tdstyle'}) { if ($formfield->{'iterator'} % 2) { $formfield->{'label-tdstyle'} = 'greybak'; } else { $formfield->{'label-tdstyle'} = 'whitebak'; } } if (!$formfield->{'input-tdstyle'}) { if ($formfield->{'iterator'} % 2) { $formfield->{'input-tdstyle'} = 'greybak'; } else { $formfield->{'input-tdstyle'} = 'whitebak'; } } # now that this is done, make sure that special # formfields are parsed in their own files so # that colspans and all that don't get messed up # in the table holding our form... if ( $formfield->{'type'} eq 'title' ) { $formfield->{'title table cell'} = qq[ ]. q[
 
]; return ( $formfield->{'title table cell'}. $parser->parse( $live_cmpts->{'title'} ). '
 
' ); } elsif ( $formfield->{'type'} eq 'subtitle' ) { # !! we override subtitle td styles for now !! $formfield->{'tdstyle'} = 'lightgreybak'; $formfield->{'subtitle table cell'} = qq[ ]; return ( $formfield->{'subtitle table cell'}. $parser->parse( $live_cmpts->{'subtitle'} ).'' ); } elsif ( $formfield->{'type'} eq 'submit' ) { $formfield->{'submit table cell'} = qq[ ] .q[
 
]; return ( $formfield->{'submit table cell'}. $parser->parse( $live_cmpts->{'sumbit'} ). q[
 
] ); } # once we have sent any special formfield types # to their respective files, treat the current # formfield normally... $formfield->{'left table cell'} = qq[ ]; if (length($formfield->{'desc'}) > 0) { $formfield->{'leftside'} = qq[ $formfield->{'label'}

$formfield->{'desc'}
] } else { $formfield->{'leftside'} = $formfield->{'label'}; } if ($formfield->{'type'} eq 'readonly') { $formfield->{'leftside'} = ''. $formfield->{'leftside'}. ''; } $formfield->{'left table cell'} .= $formfield->{'leftside'}.''; $formfield->{'right table cell'} = qq[
]; $formfield->{'rightside'} = $parser->parse( $live_cmpts->{ $formfield->{'type'} } ); $formfield->{'right table cell'} .= $formfield->{'rightside'}.qq[\n
]; return($formfield->{'left table cell'} .$formfield->{'right table cell'}); ?> __cmpo__ 'value-as-text' => <<'__cmpo__',
{'css-class'}) ? qq[ class="$formfield->{'css-class'}" : '' ?>>{'value'} ?>
__cmpo__ 'text' => <<'__cmpo__', {'comments'}) ? qq[ $formfield->{'comments'}] : '' ?> {'css-class'}) ? qq[ class="$formfield->{'css-class'}" : q[ class="240px"] ?>{'js'}) ? qq[$formfield->{'js'}] : '' ?> />{'required'}) ? qq[ *] : '' ?>{'required'}) ? qq[ ] : '' ?> __cmpo__ 'select-header' => <<'__cmpo__', {'comments'}) ? qq[ $formfield->{'comments'}] : '' ?> {'css-class'}) ? qq[ class="$formfield->{'css-class'}"] : q[ class="button"] ?>{'css'} ?>{'js'} ?> />{'required'}) ? qq[ ] : '' ?> __cmpo__ 'subtitle' => <<'__cmpo__',
{'title'} ?>
__cmpo__ 'readonly' => <<'__cmpo__',
{'css-class'}) ? qq[ class="$formfield->{'css-class'}"] : '' ?>>{'vmask'} || $formfield->{'value'}) ?>
{'required'}) ? qq[ ] : '' ?> __cmpo__ 'header' => <<'__cmpo__',
{'hidden'} ?>
__cmpo__ 'select-footer' => <<'__cmpo__', {'required'}) ? qq[ *] : '' ?>{'required'}) ? qq[ ] : '' ?> __cmpo__ 'empty' => <<'__cmpo__', __cmpo__ 'title' => <<'__cmpo__',
{'title'} ?>
__cmpo__ 'hidden' => <<'__cmpo__', {'css'} ?>{'js'} ?> /> __cmpo__ 'footer' => <<'__cmpo__',
[ERROR] {'name'} ?> didn't get anything from the parsing...
__cmpo__ 'checkbox' => <<'__cmpo__', {'comments'}) ? qq[ $formfield->{'comments'}] : '' ?>{'checked'} ?>{'css'} ?>{'css-class'}) ? qq[ class="$formfield->{'css-class'}" : '' ?>{'js'} ?> />{'required'}) ? qq[ *] : '' ?>{'label'} ?>{'required'}) ? qq[ ] : '' ?> __cmpo__ 'password' => <<'__cmpo__', {'comments'}) ? qq[ $formfield->{'comments'}] : '' ?> {'css-class'}) ? qq[ class="$formfield->{'css-class'}" : q[ class="240px"] ?>{'js'}) ? qq[\n$formfield->{'js'}] : '' ?> />{'required'}) ? qq[ *] : '' ?>{'required'}) ? qq[ ] : '' ?> __cmpo__ 'option.html' => <<'__cmpo__', __cmpo__ 'sep' => <<'__cmpo__',   __cmpo__ 'radio' => <<'__cmpo__', {'comments'}) ? qq[ $formfield->{'comments'}] : '' ?> {'checked'} ?>{'css-class'}) ? qq[ class="$formfield->{'css-class'}" : '' ?>{'css'} ?>{'js'} ?> />{'required'}) ? qq[ ] : ''?> __cmpo__ 'submit' => <<'__cmpo__', {'comments'} ?> {'css-class'}) ? qq[ class="$formfield->{'css-class'}"] : qq[ class="button"] ?>{'css'} ?>{'js'} ?> />     __cmpo__ }; 1;