| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # EditableTable Example 6 | ||
| 4 | # demonstrates the Horizontal table with String Output | ||
| 5 | |||
| 6 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use CGI; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | use CGI::Carp qw(fatalsToBrowser); | ||
| 9 | use Getopt::Std; | ||
| 10 | use HTML::EditableTable; | ||
| 11 | use HTML::EditableTable::Horizontal; | ||
| 12 | |||
| 13 | my @tableData = | ||
| 14 | ( | ||
| 15 | { | ||
| 16 | 'part_id' => 7765, | ||
| 17 | 'catalog_id' => 'UX35AT', | ||
| 18 | 'addition_date' => '2008-10-10', | ||
| 19 | 'part_name' => 'control module', | ||
| 20 | 'vendor' => 'Praxis', | ||
| 21 | 'description' => 'ABS package with revA firmware. Used in low-cost applications and as replacement for model UX34AT. Includes adaptor wiring harness for UX34AT', | ||
| 22 | 'qa_results' => 'see http://yoururl.com/index.cgi?context=qa', | ||
| 23 | 'qoh' => '65', | ||
| 24 | 'rohs_category' => 2, | ||
| 25 | 'reorder_class' => 'C', | ||
| 26 | 'last_order_date' => '2010-06-10', | ||
| 27 | }, | ||
| 28 | { | ||
| 29 | 'part_id' => 7961, | ||
| 30 | 'catalog_id' => 'ZX42AT', | ||
| 31 | 'addition_date' => '2009-03-01', | ||
| 32 | 'part_name' => 'power regulator', | ||
| 33 | 'vendor' => 'Armscor', | ||
| 34 | 'description' => 'Minature power supply with redundant relays', | ||
| 35 | 'qa_results' => '2ppm confirmed', | ||
| 36 | 'qoh' => '32', | ||
| 37 | 'rohs_category' => 2, | ||
| 38 | 'reorder_class' => 'A', | ||
| 39 | 'last_order_date' => '2009-12-17', | ||
| 40 | }, | ||
| 41 | { | ||
| 42 | 'part_id' => 8055, | ||
| 43 | 'catalog_id' => 'UX24AT', | ||
| 44 | 'addition_date' => '2007-04-08', | ||
| 45 | 'part_name' => 'control module', | ||
| 46 | 'vendor' => 'Subarashii', | ||
| 47 | 'description' => 'Obsolete control module for A45 overthruster. Requires UX27AZ conditioner and 3F buffering caps if the overthruster runs >18psi', | ||
| 48 | 'qa_results' => 'see http://yoururl.com/index.cgi?context=qa', | ||
| 49 | 'qoh' => '2', | ||
| 50 | 'rohs_category' => 4, | ||
| 51 | 'reorder_class' => 'A', | ||
| 52 | 'last_order_date' => '2005-08-19', | ||
| 53 | }, | ||
| 54 | ); | ||
| 55 | |||
| 56 | my @tableFields = | ||
| 57 | ( | ||
| 58 | { | ||
| 59 | 'editOnly' => 1, | ||
| 60 | 'formElement' => 'deleteRowButton', | ||
| 61 | }, | ||
| 62 | { | ||
| 63 | 'dbfield' => 'part_id', | ||
| 64 | 'label' => 'Part Id', | ||
| 65 | 'viewOnly' => 1, | ||
| 66 | }, | ||
| 67 | { | ||
| 68 | 'dbfield' => 'catalog_id', | ||
| 69 | 'label' => 'Catalog Id', | ||
| 70 | 'formElement' => 'textfield', | ||
| 71 | 'size' => 15, | ||
| 72 | 'uniquifierField' => 'part_id', | ||
| 73 | }, | ||
| 74 | { | ||
| 75 | 'dbfield' => 'addition_date', | ||
| 76 | 'label' => 'Available From', | ||
| 77 | 'formElement' => 'calendar', | ||
| 78 | 'uniquifierField' => 'part_id', | ||
| 79 | }, | ||
| 80 | { | ||
| 81 | 'dbfield' => 'part_name', | ||
| 82 | 'label' => 'Part Name', | ||
| 83 | 'formElement' => 'textfield', | ||
| 84 | 'size' => 20, | ||
| 85 | 'uniquifierField' => 'part_id', | ||
| 86 | }, | ||
| 87 | { | ||
| 88 | 'dbfield' => 'vendor', | ||
| 89 | 'label' => 'Vendor', | ||
| 90 | 'formElement' => 'popup', | ||
| 91 | 'selectionList' => ['', 'Amexx', 'Armscor', 'Consolidated', 'Gentine', 'Oroco', 'Praxis', 'Shellalco', 'Subarashii',], | ||
| 92 | 'uniquifierField' => 'part_id', | ||
| 93 | }, | ||
| 94 | { | ||
| 95 | 'dbfield' => 'description', | ||
| 96 | 'label' => 'Part Description', | ||
| 97 | 'formElement' => 'textarea', | ||
| 98 | 'subBr' => 1, | ||
| 99 | 'drillDownTruncate' => 60, | ||
| 100 | 'uniquifierField' => 'part_id', | ||
| 101 | }, | ||
| 102 | { | ||
| 103 | 'dbfield' => 'qa_results', | ||
| 104 | 'label' => 'QA Results', | ||
| 105 | 'formElement' => 'textfield', | ||
| 106 | 'linkifyContentOnView' => 1, | ||
| 107 | 'uniquifierField' => 'part_id', | ||
| 108 | }, | ||
| 109 | { | ||
| 110 | 'dbfield' => 'qoh', | ||
| 111 | 'label' => 'Quantity', | ||
| 112 | 'formElement' => 'textfield', | ||
| 113 | 'size' => 5, | ||
| 114 | 'uniquifierField' => 'part_id', | ||
| 115 | }, | ||
| 116 | { | ||
| 117 | 'dbfield' => 'rohs_category', | ||
| 118 | 'label' => 'RoHS', | ||
| 119 | 'formElement' => 'popup', | ||
| 120 | 'selectionList' => ['',1..10], | ||
| 121 | 'selectionLabels' => { | ||
| 122 | 1 => 'Large and small household appliances', | ||
| 123 | 2 => 'IT equipment', | ||
| 124 | 3 => 'Telecommunications equipment', | ||
| 125 | 4 => 'Consumer equipment', | ||
| 126 | 5 => 'Lighting equipment', | ||
| 127 | 6 => 'Electronic and electrical tools', | ||
| 128 | 7 => 'Toys, leisure, and sports equipment', | ||
| 129 | 8 => 'Medical devices', | ||
| 130 | 9 => 'Monitoring and control instruments', | ||
| 131 | 10 => 'Automatic dispensers', | ||
| 132 | }, | ||
| 133 | 'uniquifierField' => 'part_id', | ||
| 134 | }, | ||
| 135 | { | ||
| 136 | 'dbfield' => 'reorder_class', | ||
| 137 | 'label' => 'Reorder Class', | ||
| 138 | 'formElement' => 'popup', | ||
| 139 | 'selectionList' => ['', 'A', 'B', 'C'], | ||
| 140 | 'uniquifierField' => 'part_id', | ||
| 141 | }, | ||
| 142 | { | ||
| 143 | 'dbfield' => 'last_order_date', | ||
| 144 | 'label' => 'Last Ordered', | ||
| 145 | 'formElement' => 'calendar', | ||
| 146 | 'uniquifierField' => 'part_id', | ||
| 147 | }, | ||
| 148 | ); | ||
| 149 | |||
| 150 | ######## CGI Controller ########## | ||
| 151 | |||
| 152 | our $t = CGI->new(); | ||
| 153 | print $t->header(); | ||
| 154 | |||
| 155 | print "<h3>" . "Example using EditableTable::Horizontal" . "</h3>"; | ||
| 156 | |||
| 157 | my $context = $t->param('context') || 'view'; | ||
| 158 | |||
| 159 | # might be getting a context from command-line if the script is being run in the test suite | ||
| 160 | |||
| 161 | my %opts = (); | ||
| 162 | |||
| 163 | getopts('c:', \%opts); | ||
| 164 | |||
| 165 | if ($opts{c}) { $context = $opts{c}; } | ||
| 166 | |||
| 167 | my $tabIndex = 100; | ||
| 168 | |||
| 169 | my $table = HTML::EditableTable::Horizontal->new | ||
| 170 | ( | ||
| 171 | { | ||
| 172 | 'tableFields' => \@tableFields, | ||
| 173 | 'width' => '100%', | ||
| 174 | 'jsAddData' => 1, | ||
| 175 | 'editMode' => $context, | ||
| 176 | 'data' => \@tableData, | ||
| 177 | 'tabindex' => \$tabIndex, | ||
| 178 | 'style' => "border-width:5px;", | ||
| 179 | 'jsSortHeader' => 1, | ||
| 180 | } | ||
| 181 | ); | ||
| 182 | |||
| 183 | $table->setStringOutput(1); | ||
| 184 | |||
| 185 | print "<form method=post>"; | ||
| 186 | |||
| 187 | my $html = $table->htmlDisplay(); | ||
| 188 | |||
| 189 | print $html . "\n"; | ||
| 190 | |||
| 191 | my $nextContext = $context eq 'view' ? 'edit' : 'view'; | ||
| 192 | |||
| 193 | print "<input type=submit name=context value=$nextContext>"; | ||
| 194 | print "</form>"; | ||
| 195 | |||
| 196 | |||