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