example/example_8.cgi

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