example/example_9.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_8.cgi ↑ Summary blib/lib/HTML/EditableTable.pm »
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 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 @tableData2 = @tableData;
57  
58 my @tableFields =
59 (
60 {
61 'editOnly' => 1,
62 'formElement' => 'deleteRowButton',
63 },
64 {
65 'dbfield' => 'part_id',
66 'label' => 'Part Id',
67 'viewOnly' => 1,
68 },
69 {
70 'dbfield' => 'catalog_id',
71 'label' => 'Catalog Id',
72 'formElement' => 'textfield',
73 'size' => 15,
74 'uniquifierField' => 'part_id',
75 'tooltip' => '2010 Catalog Id',
76 },
77 {
78 'dbfield' => 'addition_date',
79 'label' => 'Available From',
80 'formElement' => 'calendar',
81 'uniquifierField' => 'part_id',
82 },
83 {
84 'dbfield' => 'part_name',
85 'label' => 'Part Name',
86 'formElement' => 'textfield',
87 'size' => 20,
88 'uniquifierField' => 'part_id',
89 },
90 {
91 'dbfield' => 'vendor',
92 'label' => 'Vendor',
93 'formElement' => 'popup',
94 'selectionList' => ['', 'Amexx', 'Armscor', 'Consolidated', 'Gentine', 'Oroco', 'Praxis', 'Shellalco', 'Subarashii',],
95 'uniquifierField' => 'part_id',
96 },
97 {
98 'dbfield' => 'description',
99 'label' => 'Part Description',
100 'formElement' => 'textarea',
101 'subBr' => 1,
102 'drillDownTruncate' => 60,
103 'uniquifierField' => 'part_id',
104 },
105 {
106 'dbfield' => 'qa_results',
107 'label' => 'QA Results',
108 'formElement' => 'textfield',
109 'linkifyContentOnView' => 1,
110 'uniquifierField' => 'part_id',
111 },
112 {
113 'dbfield' => 'qoh',
114 'label' => 'Quantity',
115 'formElement' => 'textfield',
116 'size' => 5,
117 'uniquifierField' => 'part_id',
118 },
119 {
120 'dbfield' => 'rohs_category',
121 'label' => 'RoHS',
122 'formElement' => 'popup',
123 'selectionList' => ['',1..10],
124 'selectionLabels' => {
125 1 => 'Large and small household appliances',
126 2 => 'IT equipment',
127 3 => 'Telecommunications equipment',
128 4 => 'Consumer equipment',
129 5 => 'Lighting equipment',
130 6 => 'Electronic and electrical tools',
131 7 => 'Toys, leisure, and sports equipment',
132 8 => 'Medical devices',
133 9 => 'Monitoring and control instruments',
134 10 => 'Automatic dispensers',
135 },
136 'uniquifierField' => 'part_id',
137 },
138 {
139 'dbfield' => 'reorder_class',
140 'label' => 'Reorder Class',
141 'formElement' => 'popup',
142 'selectionList' => ['', 'A', 'B', 'C'],
143 'uniquifierField' => 'part_id',
144 },
145 {
146 'dbfield' => 'last_order_date',
147 'label' => 'Last Ordered',
148 'formElement' => 'calendar',
149 'uniquifierField' => 'part_id',
150 },
151 );
152  
153 my @tableFields2 = @tableFields;
154  
155 ######## CGI Controller ##########
156  
157 our $t = CGI->new();
158 print $t->header();
159  
160 print "<h3>" . "Example using EditableTable::Horizontal" . "</h3>";
161  
162 my $context = $t->param('context') || 'view';
163  
164 # might be getting a context from command-line if the script is being run in the test suite
165  
166 my %opts = ();
167  
168 getopts('c:', \%opts);
169  
170 if ($opts{c}) { $context = $opts{c}; }
171  
172 my $tabIndex = 100;
173  
174 my $table = HTML::EditableTable::Horizontal->new
175 (
176 {
177 'tableFields' => \@tableFields,
178 'width' => '100%',
179 'jsAddData' => 1,
180 'editMode' => $context,
181 'data' => \@tableData,
182 'tabindex' => \$tabIndex,
183 'style' => "border-width:5px;",
184 'jsSortHeader' => 1,
185 }
186 );
187  
188 print "<form method=post>";
189  
190 print "<h2>Table 1</h2>";
191 $table->htmlDisplay();
192  
193 $tabIndex = 500;
194  
195 my $table2 = HTML::EditableTable::Horizontal->new
196 (
197 {
198 'tableFields' => \@tableFields2,
199 'width' => '100%',
200 'jsAddData' => 1,
201 'editMode' => $context,
202 'data' => \@tableData2,
203 'tabindex' => \$tabIndex,
204 'style' => "border-width:5px;",
205 'sortHeader' => "example_9.cgi?context=$context&",
206 'sortData' => 1,
207 }
208 );
209  
210 print "<h2>Table 2</h2>";
211 $table2->htmlDisplay();
212  
213 my $nextContext = $context eq 'view' ? 'edit' : 'view';
214  
215 print "<input type=submit name=context value=$nextContext>";
216 print "</form>";
217  
218
« example/example_8.cgi ↑ Summary blib/lib/HTML/EditableTable.pm »