| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | # EditableTable Example 2 | ||
| 4 | # demonstrates the Vertical table with multiple columns 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 | 'octopus 1.0' => { | ||
| 17 | 'tps_uid' => '404', | ||
| 18 | 'green_checks' => '4', | ||
| 19 | 'green_yellow_checks' => undef, | ||
| 20 | 'tpsid' => 'm22z', | ||
| 21 | 'project_status' => 'review', | ||
| 22 | 'manf_target' => 'internal', | ||
| 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 | 'tps_approved' => 'Yes', | ||
| 39 | }, | ||
| 40 | 'shark 1.3' => { | ||
| 41 | 'tps_uid' => '442', | ||
| 42 | 'green_checks' => '2', | ||
| 43 | 'green_yellow_checks' => '1', | ||
| 44 | 'tpsid' => 'm56z', | ||
| 45 | 'project_status' => 'phase 1', | ||
| 46 | 'manf_target' => 'internal', | ||
| 47 | 'project_type' => 'new product', | ||
| 48 | 'creation_time' => '2009-01-09 10:34:00', | ||
| 49 | 'zpg_ref' => undef, | ||
| 50 | 'project_name' => 'Tiger Shark', | ||
| 51 | 'uid' => '103', | ||
| 52 | 'project_owner' => '1', | ||
| 53 | 'yellow_checks' => '3', | ||
| 54 | 'grey_checks' => undef, | ||
| 55 | 'design_name' => 'shark', | ||
| 56 | 'manf_site' => undef, | ||
| 57 | 'prod_date' => '2009-03-03 00:00:00', | ||
| 58 | 'comment' => '', | ||
| 59 | 'technology' => '3', | ||
| 60 | 'red_checks' => '1', | ||
| 61 | 'black_checks' => undef, | ||
| 62 | 'tps_approved' => 'Yes', | ||
| 63 | }, | ||
| 64 | 'eel 2.0' => { | ||
| 65 | 'tps_uid' => '490', | ||
| 66 | 'green_checks' => '8', | ||
| 67 | 'green_yellow_checks' => undef, | ||
| 68 | 'tpsid' => 'e56t', | ||
| 69 | 'project_status' => 'review', | ||
| 70 | 'manf_target' => 'external', | ||
| 71 | 'project_type' => 'special', | ||
| 72 | 'creation_time' => '2010-02-01 00:00:00', | ||
| 73 | 'zpg_ref' => '8796hh7', | ||
| 74 | 'project_name' => 'Code Name Tentacle', | ||
| 75 | 'uid' => '414', | ||
| 76 | 'project_owner' => '2', | ||
| 77 | 'yellow_checks' => undef, | ||
| 78 | 'grey_checks' => undef, | ||
| 79 | 'design_name' => 'octopus', | ||
| 80 | 'manf_site' => undef, | ||
| 81 | 'prod_date' => undef, | ||
| 82 | 'comment' => '', | ||
| 83 | 'technology' => '1', | ||
| 84 | 'red_checks' => undef, | ||
| 85 | 'black_checks' => undef, | ||
| 86 | 'tps_approved' => 'No', | ||
| 87 | } | ||
| 88 | }; | ||
| 89 | |||
| 90 | # the specification for the table fields - array of hash elements | ||
| 91 | |||
| 92 | my @tableFields = | ||
| 93 | ( | ||
| 94 | { | ||
| 95 | 'dbfield' => 'uid', | ||
| 96 | 'label' => 'project id', | ||
| 97 | }, | ||
| 98 | { | ||
| 99 | 'dbfield' => 'creation_time', | ||
| 100 | 'label' => 'Creation Date', | ||
| 101 | }, | ||
| 102 | { | ||
| 103 | 'dbfield' => 'tps_approved', | ||
| 104 | 'label' => 'TPS Approved', | ||
| 105 | 'formElement' => 'checkbox', | ||
| 106 | 'checkBehavior' => 'checkedOnTrue', | ||
| 107 | }, | ||
| 108 | { | ||
| 109 | 'dbfield' => 'tps_uid', | ||
| 110 | 'label' => 'tps id', | ||
| 111 | 'suppressCallbackOnEdit' => 1, | ||
| 112 | 'formElement' => 'textfield', | ||
| 113 | 'callback' => \&cbTPSUid, | ||
| 114 | }, | ||
| 115 | { | ||
| 116 | 'dbfield' => 'zpg_ref', | ||
| 117 | 'label' => 'ZPG Component Reference', | ||
| 118 | 'formElement' => 'textfield', | ||
| 119 | 'tooltip' => 'must be valid id from the Zorph database', | ||
| 120 | }, | ||
| 121 | { | ||
| 122 | 'dbfield' => 'project_name', | ||
| 123 | 'label' => 'project name', | ||
| 124 | 'tooltip' => 'poor project names will be punished', | ||
| 125 | }, | ||
| 126 | { | ||
| 127 | 'dbfield' => 'tpsid', | ||
| 128 | 'label' => 'tps report #', | ||
| 129 | 'formElement' => 'textfield', | ||
| 130 | }, | ||
| 131 | { | ||
| 132 | 'dbfield' => 'design_name', | ||
| 133 | 'label' => 'design name', | ||
| 134 | 'formElement' => 'textfield', | ||
| 135 | }, | ||
| 136 | { | ||
| 137 | 'dbfield' => 'project_owner', | ||
| 138 | 'label' => 'owner', | ||
| 139 | 'formElement' => 'popup', | ||
| 140 | 'selectionList' => [1,2,3,4], | ||
| 141 | 'selectionLabels' => {1=>'Andy', 2=>'Vishesh', 3=>'Vijay', 4=>'Sergei'}, | ||
| 142 | 'suppressCallbackOnEdit' => 1, | ||
| 143 | }, | ||
| 144 | { | ||
| 145 | 'dbfield' => 'project_type', | ||
| 146 | 'label' => 'project type', | ||
| 147 | 'formElement' => 'popup', | ||
| 148 | 'selectionList' => ['PTV', 'NPI', 'Revision'], | ||
| 149 | }, | ||
| 150 | { | ||
| 151 | 'dbfield' => 'technology', | ||
| 152 | 'label' => 'technology', | ||
| 153 | 'formElement' => 'popup', | ||
| 154 | 'selectionList' => [1,2,3,4], | ||
| 155 | 'selectionLabels' => {1=>'lfet24', 2=>'cmos17up', 3=>'hdtyos', 4=>'cmos22soi'}, | ||
| 156 | }, | ||
| 157 | { | ||
| 158 | 'dbfield' => 'manf_target', | ||
| 159 | 'label' => 'internal/external manf', | ||
| 160 | 'formElement' => 'popup', | ||
| 161 | 'selectionList' => ['internal', 'external'], | ||
| 162 | }, | ||
| 163 | { | ||
| 164 | 'dbfield' => 'project_status', | ||
| 165 | 'label' => 'project status', | ||
| 166 | 'formElement' => 'popup', | ||
| 167 | 'selectionList' => ['review', 'rejected', 'approved'], | ||
| 168 | }, | ||
| 169 | { | ||
| 170 | 'dbfield' => 'prod_date', | ||
| 171 | 'label' => 'design prod (YYYY-MM-DD)', | ||
| 172 | 'formElement' => 'calendar', | ||
| 173 | }, | ||
| 174 | { | ||
| 175 | 'dbfield' => 'comment', | ||
| 176 | 'label' => 'comment', | ||
| 177 | 'formElement' => 'textarea', | ||
| 178 | 'editOnly' => 1, | ||
| 179 | 'minimalEditSize' => 1, | ||
| 180 | } | ||
| 181 | |||
| 182 | ); | ||
| 183 | |||
| 184 | ######## CGI Controller ########## | ||
| 185 | |||
| 186 | our $t = CGI->new(); | ||
| 187 | print $t->header(); | ||
| 188 | |||
| 189 | print "<h3>" . "Example using EditableTable::Vertical" . "</h3>"; | ||
| 190 | |||
| 191 | my $context = $t->param('context') || 'view'; | ||
| 192 | |||
| 193 | # might be getting a context from command-line if the script is being run in the test suite | ||
| 194 | my %opts = (); | ||
| 195 | getopts('c:', \%opts); | ||
| 196 | if ($opts{c}) { $context = $opts{c}; } | ||
| 197 | |||
| 198 | my $table = HTML::EditableTable::Vertical->new(); | ||
| 199 | $table->setTableFields(\@tableFields); | ||
| 200 | $table->setSortHeader('false'); | ||
| 201 | $table->setData($data); | ||
| 202 | $table->setEditMode($context); | ||
| 203 | |||
| 204 | print "<form method=get>"; | ||
| 205 | |||
| 206 | $table->htmlDisplay(); | ||
| 207 | |||
| 208 | my $nextContext = $context eq 'view' ? 'edit' : 'view'; | ||
| 209 | |||
| 210 | print "<input type=submit name=context value=$nextContext>"; | ||
| 211 | |||
| 212 | print "</form>"; | ||
| 213 | |||
| 214 | ################################## | ||
| 215 | |||
| 216 | # calback which provides data to the table at runtime | ||
| 217 | |||
| 218 | sub cbTPSUid { | ||
| 219 | |||
| 220 | # table data available to the callback | ||
| 221 | my ($row, $colSpec, $editMode, $rowspanSubcounter) = shift @_; | ||
| 222 | |||
| 223 | return "<a href=example_2.cgi?context=view&id=$row->{tps_uid}>" . $row->{tps_uid} . "</a>"; | ||
| 224 | } | ||
| 225 | |||