example/example_1.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
« blib/lib/HTML/EditableTable/Javascript.pm ↑ Summary example/example_2.cgi »
1 #!/usr/bin/perl
2  
3 # EditableTable Example 1
4 # demonstrates the Vertical table with a single column of data
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::Vertical;
12  
13 # this is a example of the editable vertical table. The most basic form of this ths stores the data in a hash
14  
15 my $data = {
16 'tps_uid' => '404',
17 'green_checks' => '4',
18 'green_yellow_checks' => undef,
19 'tpsid' => 'm22h',
20 'project_status' => 'review',
21 'manf_target' => 'internal',
22 'ready_for_prod_time' => undef,
23 'project_type' => 'revision',
24 'creation_time' => '2007-11-09 10:25:11',
25 'zpg_ref' => undef,
26 'project_name' => 'm22z_octopus_revision_r7',
27 'uid' => '414',
28 'project_owner' => '2',
29 'yellow_checks' => '1',
30 'grey_checks' => undef,
31 'design_name' => 'octopus',
32 'manf_site' => undef,
33 'prod_date' => '2008-01-14 00:00:00',
34 'comment' => '',
35 'technology' => '2',
36 'red_checks' => undef,
37 'black_checks' => undef,
38 };
39  
40 # the specification for the table fields - array of hash elements
41  
42 my @tableFields =
43 (
44 {
45 'dbfield' => 'uid',
46 'label' => 'project id',
47 },
48 {
49 'dbfield' => 'creation_time',
50 'label' => 'Creation Date',
51 },
52 {
53 'dbfield' => 'tps_uid',
54 'label' => 'tps id',
55 'suppressCallbackOnEdit' => 1,
56 'formElement' => 'textfield',
57 'callback' => \&cbTPSUid,
58 },
59 {
60 'dbfield' => 'zpg_ref',
61 'label' => 'ZPG Component Reference',
62 'formElement' => 'textfield',
63 'tooltip' => 'must be valid id from the Zorph database',
64 },
65 {
66 'dbfield' => 'project_name',
67 'label' => 'project name',
68 'tooltip' => 'poor project names will be punished',
69 },
70 {
71 'dbfield' => 'tpsid',
72 'label' => 'tps report #',
73 'formElement' => 'textfield',
74 },
75 {
76 'dbfield' => 'design_name',
77 'label' => 'design name',
78 'formElement' => 'textfield',
79 },
80 {
81 'dbfield' => 'project_owner',
82 'label' => 'owner',
83 'formElement' => 'popup',
84 'selectionList' => [1,2,3,4],
85 'selectionLabels' => {1=>'Andy', 2=>'Vishesh', 3=>'Vijay', 4=>'Sergei'},
86 'suppressCallbackOnEdit' => 1,
87 },
88 {
89 'dbfield' => 'project_type',
90 'label' => 'project type',
91 'formElement' => 'popup',
92 'selectionList' => ['PTV', 'NPI', 'Revision'],
93 },
94 {
95 'dbfield' => 'technology',
96 'label' => 'technology',
97 'formElement' => 'popup',
98 'selectionList' => [1,2,3,4],
99 'selectionLabels' => {1=>'lfet24', 2=>'cmos17up', 3=>'hdtyos', 4=>'cmos22soi'},
100 },
101 {
102 'dbfield' => 'manf_target',
103 'label' => 'internal/external manf',
104 'formElement' => 'popup',
105 'selectionList' => ['internal', 'external'],
106 },
107 {
108 'dbfield' => 'project_status',
109 'label' => 'project status',
110 'formElement' => 'popup',
111 'selectionList' => ['review', 'rejected', 'approved'],
112 },
113 {
114 'dbfield' => 'prod_date',
115 'label' => 'design prod (YYYY-MM-DD)',
116 'formElement' => 'calendar',
117 },
118 {
119 'dbfield' => 'ready_for_prod_time',
120 'label' => 'ready for prod date',
121 'viewOnly' => 1,
122 },
123 {
124 'dbfield' => 'comment',
125 'label' => 'comment',
126 'formElement' => 'textarea',
127 'editOnly' => 1,
128 }
129
130 );
131  
132 ######## CGI Controller ##########
133  
134 our $t = CGI->new();
135 print $t->header();
136  
137 print "<h3>" . "Example using EditableTable::Vertical" . "</h3>";
138  
139 my $context = $t->param('context') || 'view';
140  
141 # might be getting a context from command-line if the script is being run in the test suite
142 my %opts = ();
143 getopts('c:', \%opts);
144 if ($opts{c}) { $context = $opts{c}; }
145  
146 my $table = HTML::EditableTable::Vertical->new();
147 $table->setTableFields(\@tableFields);
148 $table->setSortHeader('false');
149 $table->setData($data);
150 $table->setEditMode($context);
151 $table->setTitle('Products');
152  
153 print "<form method=get>";
154  
155 $table->htmlDisplay();
156  
157 my $nextContext = $context eq 'view' ? 'edit' : 'view';
158  
159 print "<input type=submit name=context value=$nextContext>";
160  
161 print "</form>";
162  
163 ##################################
164  
165 # calback which provides data to the table at runtime
166  
167 sub cbTPSUid {
168
169 # table data available to the callback
170 my ($row, $colSpec, $editMode, $rowspanSubcounter) = shift @_;
171  
172 return "<a href=example_1.cgi?context=view&id=$row->{tps_uid}>" . $row->{tps_uid} . "</a>";
173 }
174  
« blib/lib/HTML/EditableTable/Javascript.pm ↑ Summary example/example_2.cgi »