| 1 | |||
| 2 | ################################################################################### | ||
| 3 | # | ||
| 4 | # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de | ||
| 5 | # Embperl - Copyright (c) 2008-2015 Gerald Richter | ||
| 6 | # Embperl - Copyright (c) 2015-2023 actevy.io | ||
| 7 | # | ||
| 8 | # You may distribute under the terms of either the GNU General Public | ||
| 9 | # License or the Artistic License, as specified in the Perl README file. | ||
| 10 | # | ||
| 11 | # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR | ||
| 12 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||
| 13 | # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
| 14 | # | ||
| 15 | # $Id$ | ||
| 16 | # | ||
| 17 | ################################################################################### | ||
| 18 | |||
| 19 | package Embperl::Form::Control::table ; | ||
| 20 | |||
| 21 | use strict ; | ||
| 22 | use base 'Embperl::Form::Control' ; | ||
| 23 | |||
| 24 | use Embperl::Inline ; | ||
| 25 | |||
| 26 | sub cellstyle { '' } ; | ||
| 27 | |||
| 28 | sub show | ||
| 29 | |||
| 30 | { | ||
| 31 | my ($self, $req) = @_ ; | ||
| 32 | |||
| 33 | my $name = $self -> {name} ; | ||
| 34 | my $data = $Embperl::fdat{$name} ; | ||
| 35 | $self -> show_table ($data, $req) ; | ||
| 36 | } | ||
| 37 | |||
| 38 | 1 ; | ||
| 39 | |||
| 40 | __EMBPERL__ | ||
| 41 | |||
| 42 | [$ syntax EmbperlBlocks $] | ||
| 43 | |||
| 44 | |||
| 45 | [# --------------------------------------------------------------------------- | ||
| 46 | # | ||
| 47 | # show_table_head | ||
| 48 | #] | ||
| 49 | |||
| 50 | [$ sub show_table_head ($self, $req) $] | ||
| 51 | |||
| 52 | <table width="100%" id="_table_[+ $self->{id} +]"> | ||
| 53 | |||
| 54 | [# --- heading columns --- #] | ||
| 55 | [- $i = 0 -] | ||
| 56 | <thead> | ||
| 57 | [$foreach $line (@{$self->{columns}}) $] | ||
| 58 | <tr style="background: white"> | ||
| 59 | [$foreach $c (@$line) $] | ||
| 60 | <td colspan="[+ ref $c?$c -> [2] || 1:1 +]" class="[+$self -> {line2} || (@{$self->{columns}} > 1 && $i == 0)?'cGridLabelBox':'cControlBox'+] cLdapReportColumnHead">[+ $showtext?(ref $c?$c -> [1] || $c -> [0]:$c):$self -> form -> convert_label ($self, undef, ref $c?$c -> [1]:$c, $req) +]</td> | ||
| 61 | [$endforeach$] | ||
| 62 | [- $i++ -] | ||
| 63 | </tr> | ||
| 64 | [$endforeach$] | ||
| 65 | </thead> | ||
| 66 | <tbody> | ||
| 67 | [$endsub $] | ||
| 68 | |||
| 69 | |||
| 70 | [# --------------------------------------------------------------------------- | ||
| 71 | # | ||
| 72 | # show_table_foot | ||
| 73 | #] | ||
| 74 | |||
| 75 | [$ sub show_table_foot ($self) $] | ||
| 76 | |||
| 77 | </tbody> | ||
| 78 | </table> | ||
| 79 | |||
| 80 | [$endsub $] | ||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | [# --------------------------------------------------------------------------- | ||
| 85 | # | ||
| 86 | # show_table_row | ||
| 87 | #] | ||
| 88 | |||
| 89 | [$ sub show_table_row ($self, $r, $o, $dataprefix) $] | ||
| 90 | |||
| 91 | [- | ||
| 92 | #use Data::Dumper ; | ||
| 93 | #print STDERR "show_table_row ", Dumper ($self, $r, $o, $dataprefix) ; | ||
| 94 | |||
| 95 | -] | ||
| 96 | |||
| 97 | |||
| 98 | [- $i = 0 -] | ||
| 99 | [$foreach $line (@{$self->{columns}}) $] | ||
| 100 | [- $colnum = 0 -] | ||
| 101 | <tr style="background: white"> | ||
| 102 | [$foreach $c (@$line) $][- | ||
| 103 | $attr = ref $c?$c -> [0]:$c ; | ||
| 104 | if (ref ($o) eq 'ARRAY') | ||
| 105 | { | ||
| 106 | $item = $o -> [$attr] ; | ||
| 107 | } | ||
| 108 | else | ||
| 109 | { | ||
| 110 | foreach my $prefix (@$dataprefix) | ||
| 111 | { | ||
| 112 | last if ($prefix?($item = $o -> {$prefix}{$attr}):($item = $o -> {$attr})) | ||
| 113 | } | ||
| 114 | } | ||
| 115 | $item = ref $item?join ('; ',@$item):$item ; | ||
| 116 | if ($filter = $c -> [6]) | ||
| 117 | { | ||
| 118 | die "unknown filter '$filter'" if (!($filtercode = $self -> {filters}{$filter})) ; | ||
| 119 | $item = &{$filtercode}($item, $c, $o, $epreq) ; | ||
| 120 | } | ||
| 121 | $id = undef ; | ||
| 122 | -]<td colspan="[+ ref $c?$c -> [2] || 1:1 +]" class="[# +$self -> {line2} || (@{$self->{columns}} > 1 && $i == 0)?'cGridLabelBox':'cControlBox'+ #] cLdapReportTd" style="[+ $self -> cellstyle ($item, $o, $r, $i, $attr) +]"> | ||
| 123 | [$ if $c -> [3] && ($item =~ /^&(.*?),(.*?),(.*)$/) $] | ||
| 124 | [$ if $1 eq 'checkbox' $]<input type="checkbox" name="[+ $2 +]" value="[+ $3 +]">[$endif$] | ||
| 125 | [$ if $1 eq 'radio' $]<input type="radio" name="[+ $2 +]" value="[+ $3 +]">[$endif$] | ||
| 126 | [$else $][- | ||
| 127 | $href = undef ; | ||
| 128 | $link = $c -> [4] ; | ||
| 129 | if (ref $link eq 'CODE') | ||
| 130 | { | ||
| 131 | $href = &$link ($o, $self) ; | ||
| 132 | } | ||
| 133 | elsif ($link) | ||
| 134 | { | ||
| 135 | $href = $o -> {$link} ; | ||
| 136 | } | ||
| 137 | $link = $c -> [7] ; | ||
| 138 | if (ref $link eq 'CODE') | ||
| 139 | { | ||
| 140 | $id = &$link ($o, $self) ; | ||
| 141 | } | ||
| 142 | -][$ if ($href && $self->{use_ajax}) | ||
| 143 | $]<a href="#" [$if ($id) $] id="[+ "$self->{name}_${attr}_$r" +]" [$endif$] onClick="$('#[+ $self->{use_ajax} +]').load ('[+ $href +]')">[+ ref $item?join ('; ',@$item):$item +]</a> | ||
| 144 | [$elsif ($href) | ||
| 145 | $]<a href="[+ do { local $escmode = 0 ; $href } +]" target="[+ $c -> [5] +]" [$if ($id) $]id="[+ "$self->{name}_${attr}_$r" +]"[$endif$]>[+ ref $item?join ('; ',@$item):$item +]</a> | ||
| 146 | [$else | ||
| 147 | $][+ ref $item?join ('; ',@$item):$item | ||
| 148 | +][$endif$] | ||
| 149 | [$endif$][$ | ||
| 150 | if ($id) $]<script>add_qtip($('[+ "#$self->{name}_${attr}_$r"+]'), '[+ $id +]')</script>[$endif$] | ||
| 151 | </td> | ||
| 152 | [- $colnum++ -] | ||
| 153 | [$endforeach$] | ||
| 154 | [- $i++ -] | ||
| 155 | </tr> | ||
| 156 | [$endforeach$] | ||
| 157 | [$if $self -> {line2} $] | ||
| 158 | [- | ||
| 159 | $attr = $self -> {line2} ; | ||
| 160 | if (ref ($o) eq 'ARRAY') | ||
| 161 | { | ||
| 162 | $item = $o -> [$attr] ; | ||
| 163 | } | ||
| 164 | else | ||
| 165 | { | ||
| 166 | foreach my $prefix (@$dataprefix) | ||
| 167 | { | ||
| 168 | last if ($prefix?($item = $o -> {$prefix}{$attr}):($item = $o -> {$attr})) | ||
| 169 | } | ||
| 170 | } | ||
| 171 | $item = [$item] if (!ref $item) ; | ||
| 172 | -] | ||
| 173 | <tr> | ||
| 174 | <td class="cControlBox" colspan="[+ scalar(@{$self->{columns}})+]">[+ join ('<br>', @$item) +]</td> | ||
| 175 | </tr> | ||
| 176 | [$endif$] | ||
| 177 | |||
| 178 | |||
| 179 | [$endsub $] | ||
| 180 | |||
| 181 | |||
| 182 | [# --------------------------------------------------------------------------- | ||
| 183 | # | ||
| 184 | # show_table - output the control | ||
| 185 | #] | ||
| 186 | |||
| 187 | [$ sub show_table ($self, $data, $req) | ||
| 188 | |||
| 189 | my $span = ($self->{width_percent}) ; | ||
| 190 | my $showtext = $self -> {showtext} ; | ||
| 191 | my $dataprefix = $self -> {dataprefix} || [''] ; | ||
| 192 | $] | ||
| 193 | <td class="cBase cTabTD" colspan="[+ $span +]"> | ||
| 194 | [$if $self -> {text} $] | ||
| 195 | [# --- heading text --- #] | ||
| 196 | <table width="100%"><tr><td class="cLabelBox"> | ||
| 197 | [+ $self -> {showtext}?($self->{text} || $self->{name}):$self -> form -> convert_label ($self, undef, undef, $req) +]<br> | ||
| 198 | </td></tr></table> | ||
| 199 | [$endif$] | ||
| 200 | |||
| 201 | [- $self -> show_table_head ($req) -] | ||
| 202 | |||
| 203 | [# --- data --- #] | ||
| 204 | [- $r = 0 -] | ||
| 205 | [$foreach $o (@$data) $] | ||
| 206 | [- $self -> show_table_row ($r, $o, $dataprefix) -] | ||
| 207 | [- $r++ -] | ||
| 208 | [$endforeach$] | ||
| 209 | [- $self -> show_table_foot -] | ||
| 210 | </td> | ||
| 211 | |||
| 212 | [$endsub$] | ||
| 213 | |||
| 214 | __END__ |