HTML-EditableTable

 view release on metacpan or  search on metacpan

example/example_5.cgi  view on Meta::CPAN

     3 => {
       'part_id' => 8055,
       'catalog_id' => 'UX24AT',
       'addition_date' => '2007-04-08',
       'part_name' => 'control module',
       'vendor' => 'Subarashii',
       'description' => 'Obsolete control module for A45 overthruster.  Requires UX27AZ conditioner and 3F buffering caps if the overthruster runs >18psi',
       'part_options' => 
	   [
	    { 
	      'option_id' => 'O76B',
	      'color' => 'blue',
	      'power_rating' => '76w',
	    },
	    {
	      'option_id' => 'O98O',
	      'color' => 'orange',
	      'power_rating' => '98w',
	    },
	    { 
	      'option_id' => 'Z103',
	      'color' => 'red',
	      'power_rating' => '103w',
	    },
	    {
	      'option_id' => 'Z120',
	      'color' => 'pink',
	      'power_rating' => '120w',
	    }
	   ],
       'rohs_category' => 4,
       'reorder_class' => 'A',
       'last_order_date' => '2005-08-19',
     },
    );

my @tableFields =
    (
     {
       'editOnly' => 1,
       'formElement' => 'deleteRowButton',
     },
     {
       'dbfield' => 'part_id',
       'label' => 'Part Id',
       'viewOnly' => 1,
       'callback'=> \&cbPartId,
     },
     {
       'dbfield' => 'catalog_id',
       'label' => 'Catalog Id',
       'formElement' => 'textfield',
       'size' => 15,
       'uniquifierField' => 'part_id',
       'rowspanArrayKeyForUniquification' => 'part_options',
       'rowspanArrayUniquifier' => 'option_id',
     },
     {
       'dbfield' => 'addition_date',
       'label' => 'Available From',
       'formElement' => 'calendar',
       'uniquifierField' => 'part_id',
     },
     {
       'dbfield' => 'part_name',
       'label' => 'Part Name',
       'formElement' => 'textfield',
       'size' => 20,
       'uniquifierField' => 'part_id',
     },
     {
       'dbfield' => 'vendor',
       'label' => 'Vendor',
       'formElement' => 'popup',
       'selectionList' => ['', 'Amexx', 'Armscor', 'Consolidated', 'Gentine', 'Oroco', 'Praxis',  'Shellalco', 'Subarashii',],
       'uniquifierField' => 'part_id',
     },
     {
       'dbfield' => 'description',
       'label' => 'Part Description',
       'formElement' => 'textarea',
       'subBr' => 1,
       'drillDownTruncate' => 60,
       'uniquifierField' => 'part_id',
       'style' => "font-family:'Times New Roman';font-size:12px;",     
     },
     {
       'dbfield' => 'part_options',
       'rowspanArrayKey' => 'option_id',
       'label' => 'Option #',
     },
     {
       'dbfield' => 'part_options',
       'rowspanArrayKey' => 'color',
       'uniquifierField' => 'part_id',
       'rowspanArrayUniquifier' => 'option_id',
       'label' => 'Color',
       'formElement' => 'popup',
       'selectionList' => ['blue', 'green', 'orange', 'pink', 'red', 'yellow'],
     },
     {
       'dbfield' => 'part_options',
       'rowspanArrayKey' => 'power_rating',
       'uniquifierField' => 'part_id',
       'rowspanArrayUniquifier' => 'option_id',
       'label' => 'Power Rating',
       'formElement' => 'textfield',
       'minimalEditSize' => 1,
     },
     {
       'dbfield' => 'rohs_category',
       'label' => 'RoHS',
       'formElement' => 'popup',
       'selectionList' => ['',1..10],
       'selectionLabels' => {
	 1 => 'Large and small household appliances',
	 2 => 'IT equipment',
	 3 => 'Telecommunications equipment',
	 4 => 'Consumer equipment',
	 5 => 'Lighting equipment',
	 6 => 'Electronic and electrical tools',
	 7 => 'Toys, leisure, and sports equipment',
	 8 => 'Medical devices',
	 9 => 'Monitoring and control instruments',
	 10 => 'Automatic dispensers',
       },
       'uniquifierField' => 'part_id',
     },
     {
       'dbfield' => 'reorder_class',
       'label' => 'Reorder Class',
       'formElement' => 'popup',
       'selectionList' => ['', 'A', 'B', 'C'],
       'uniquifierField' => 'part_id',
     },
     {
       'dbfield' => 'last_order_date',
       'label' => 'Last Ordered',
       'formElement' => 'calendar',
       'uniquifierField' => 'part_id',
     },     
    );

######## CGI Controller ##########

our $t = CGI->new();
print $t->header();

print "<h3>" . "Example using EditableTable::Horizontal" . "</h3>";

my $context = $t->param('context') || 'view';

# might be getting a context from command-line if the script is being run in the test suite
my %opts = ();
getopts('c:', \%opts);
if ($opts{c}) { $context = $opts{c}; }

my $tabIndex  = 100;

my $table = HTML::EditableTable::Horizontal->new
    (
     {
       'tableFields' => \@tableFields,
       'width' => '100%',
       'jsAddData' => 1,
       'editMode' => $context,
       'data' => \%tableData,
       'tabindex' => \$tabIndex,
       'sortOrder' => [2,3,1],
     }
    );

print "<form method=post>";

$table->htmlDisplay();

my $nextContext = $context eq 'view' ? 'edit' : 'view';

print "<input type=submit name=context value=$nextContext>";
print "</form>";

######## TABLE CALLBACKS ##########

sub cbPartId {
  my ($row, $colSpec, $editMode, $rowspanSubcounter) = shift @_;   
  return "<a href=example_5.cgi?context=view&uid=$row->{part_id}>" . $row->{part_id} . "</a>";
  
}

  



( run in 0.452 second using v1.01-cache-2.11-cpan-39bf76dae61 )