example/example_7.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_6.cgi ↑ Summary example/example_8.cgi »
1 #!/usr/bin/perl
2  
3 # EditableTable Example 7
4 # demonstrates the Horizontal table with string output and external call to javascript object along with other calls
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 HTML::EditableTable;
12 use HTML::EditableTable::Horizontal;
13  
14 my @tableData =
15 (
16 {
17 'part_id' => 7765,
18 'catalog_id' => 'UX35AT',
19 'addition_date' => '2008-10-10',
20 'part_name' => 'control module',
21 'vendor' => 'Praxis',
22 'description' => 'ABS package with revA firmware. Used in low-cost applications and as replacement for model UX34AT. Includes adaptor wiring harness for UX34AT',
23 'qa_results' => 'see http://yoururl.com/index.cgi?context=qa',
24 'qoh' => '65',
25 'rohs_category' => 2,
26 'reorder_class' => 'C',
27 'last_order_date' => '2010-06-10',
28 },
29 {
30 'part_id' => 7961,
31 'catalog_id' => 'ZX42AT',
32 'addition_date' => '2009-03-01',
33 'part_name' => 'power regulator',
34 'vendor' => 'Armscor',
35 'description' => 'Minature power supply with redundant relays',
36 'qa_results' => '2ppm confirmed',
37 'qoh' => '32',
38 'rohs_category' => 2,
39 'reorder_class' => 'A',
40 'last_order_date' => '2009-12-17',
41 },
42 {
43 'part_id' => 8055,
44 'catalog_id' => 'UX24AT',
45 'addition_date' => '2007-04-08',
46 'part_name' => 'control module',
47 'vendor' => 'Subarashii',
48 'description' => 'Obsolete control module for A45 overthruster. Requires UX27AZ conditioner and 3F buffering caps if the overthruster runs >18psi',
49 'qa_results' => 'see http://yoururl.com/index.cgi?context=qa',
50 'qoh' => '2',
51 'rohs_category' => 4,
52 'reorder_class' => 'A',
53 'last_order_date' => '2005-08-19',
54 },
55 );
56  
57 my @tableFields =
58 (
59 {
60 'editOnly' => 1,
61 'formElement' => 'deleteRowButton',
62 },
63 {
64 'dbfield' => 'part_id',
65 'label' => 'Part Id',
66 'viewOnly' => 1,
67 },
68 {
69 'dbfield' => 'catalog_id',
70 'label' => 'Catalog Id',
71 'formElement' => 'textfield',
72 'size' => 15,
73 'uniquifierField' => 'part_id',
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 $table->setTableFields(\@tableFields);
172 $table->setWidth('100%');
173 $table->setJsAddData('true');
174 $table->setEditMode($context);
175 $table->setData(\@tableData);
176 $table->setTabindex(\$tabIndex);
177 $table->setStyle("border-width:5px;");
178 $table->setJsSortHeader('true');
179 $table->setStringOutput('true');
180  
181 print "<form method=post>";
182  
183 # separate call for javascript (optional - if not done htmlDisplay() will do this if necessary)
184 my $jsHtml = $table->htmlJavascriptDisplay();
185 print $jsHtml . "\n";
186  
187 my $tableHtml = $table->htmlDisplay();
188 print $tableHtml . "\n";
189  
190 my $nextContext = $context eq 'view' ? 'edit' : 'view';
191  
192 print "<input type=submit name=context value=$nextContext>";
193 print "</form>";
194  
195
« example/example_6.cgi ↑ Summary example/example_8.cgi »