blib/lib/Embperl/Form/Control/tabs.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 96 CC 3 SCAR 16.1
CC
3
Cov
0%
get_active_id
12.0
new
2.0
noframe
2.0
CRAP 5.0
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::tabs ;
20  
21 use strict ;
22 use vars qw{%fdat} ;
23  
24 use Embperl::Form::ControlMultValue ;
25 use base 'Embperl::Form::ControlMultValue' ;
26  
27 use Embperl::Inline ;
28  
29 # ---------------------------------------------------------------------------
30 #
31 # new - create a new control
32 #
33  
34  
35 sub new
36  
37 {
38 my ($class, $args) = @_ ;
39  
40 my $self = Embperl::Form::ControlMultValue -> new($args) ;
41 bless $self, $class ;
42  
43 $self -> {width} = 1 ;
44 $self -> {nameprefix} ||= 'tab:' ;
45  
46 return $self ;
47 }
48  
49 # ---------------------------------------------------------------------------
50 #
51 # noframe - do not draw frame border if this is the first control
52 #
53  
54  
55 sub noframe
56  
57 {
58 return 1 ;
59 }
60  
61 # ---------------------------------------------------------------------------
62 #
63 # get_active_id - get the id of the value which is currently active
64 #
65  
66 sub get_active_id
67  
68 {
69 my ($self, $req) = @_ ;
70  
71 my $key = "active_id:$self" ;
72 my $id ;
73 return $id if ($id = $req -> {$key}) ;
74
75 my ($values, $options) = $self -> get_values ($req) ;
76 my $name = $self -> {name} ;
77 my $dataval = $fdat{$name} || $req -> {query}{$name} || $values -> [0] ;
78 my $activeid ;
79  
80 my $i = 0 ;
81 foreach my $val (@$values)
82 {
83 if ($val eq $dataval || $self -> {subids}[$i] eq $dataval)
84 {
85 $activeid = $self -> {subids}[$i] ;
86 last ;
87 }
88 $i++ ;
89 }
90 return $req -> {$key} = $activeid || $self -> {subids}[0];
91 }
92  
93  
94 1 ;
95  
96 __EMBPERL__
97  
98 [$ syntax EmbperlBlocks $]
99  
100 [ ---------------------------------------------------------------------------
101 #
102 # show_controls_begin - output begin of form controls area
103 #]
104  
105 [$ sub show_subform_controls_begin ($self, $form, $req, $activeid)
106  
107 my $parent = $form -> parent_form ;
108 my $class = $parent -> {noframe}?'ef-tabs-border-u':'ef-tabs-border' ;
109 $]
110  
111 <div _ef_name="[+ $form->{id} +]" class="ef-tabs-content"
112 [$if ($activeid && $form->{id} ne $activeid) $] style="display: none" [$endif$]
113 >
114  
115 [$if (!$form -> {noframe}) $]
116 [$if !$self -> is_disabled ($req) $]
117 <div class="ef-tabs-separator ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-top"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s ef-icon" title="[+ $form -> convert_text ({}, 'ctl:show_hide', 'Verstecken/Anzeigen', $req) +]"></span><span class="ef-tabs-separator-header-text">[+ $form -> convert_text ({}, 'tab:' . $form->{id}, $from -> {text}, $req) +]</span></div>
118 [$endif$]
119 [#<table class="ef-tabs-border-cell [+ $class +]"><tr><td class="ef-tabs-content-cell"> #]
120 <div class="ef-tabs-border-cell [+ $class +]"><div class="ef-tabs-content-cell">
121
122 [$endif$]
123  
124 [$endsub$]
125  
126 [# ---------------------------------------------------------------------------
127 #
128 # show_controls_end - output end of form controls area
129 #]
130  
131 [$sub show_subform_controls_end ($self, $form, $req)
132 $]
133  
134 [# [$ if (!$form -> {noframe}) $]</td></tr></table> [$endif$] #]
135 [$ if (!$form -> {noframe}) $]</div></div> [$endif$]
136 </div>
137 [$endsub$]
138  
139  
140  
141 [# ---------------------------------------------------------------------------
142 #
143 # show - output the control
144 #]
145  
146 [$ sub show ($self, $req)
147  
148 my ($values, $options) = $self -> get_values ($req) ;
149 my $span = ($self->{width_percent}) ;
150 my $name = $self -> {name} ;
151 my $dataval = $fdat{$name} || $values -> [0] ;
152 my $activeid = $self -> get_active_id ($req) ;
153 my $form = $self -> form ;
154 my $nsprefix = $form -> {jsnamespace} ;
155 my $tabs_per_line = $self -> {'tabs_per_line'} || 99;
156 $tabs_per_line = [$tabs_per_line, $tabs_per_line, $tabs_per_line, $tabs_per_line]
157 if (!ref $tabs_per_line) ;
158  
159 my $val ;
160 my $i = 0 ;
161 my $j = 0 ;
162 my $more = 1 ;
163 my $start_i = 0 ;
164 my $line = 0 ;
165 $]
166  
167 <div class="ef-tabs-content-cell" colspan="[+ $span +]" _ef_attach="ef_tabs">
168 [$ while ($more) $]
169 <table class="ef-tabs-selector" ><tr class="ef-tabs-selector-row">
170 [*
171 $more = 0 ;
172 my $tabs = $tabs_per_line -> [$line++] ;
173 *]
174 [$ while ($j < @$values) $]
175 [*
176 if ($self -> {subobjects}[ $j ] -> is_disabled ($req))
177 {
178 $j++ ;
179 next ;
180 }
181 $val = $values -> [$j] ;
182 my $id = $self -> {subids}[$j] ;
183 my $cellclass = $id eq $activeid?'ef-tabs-cell-on':'ef-tabs-cell-off' ;
184 my $divclass = $id eq $activeid?'ef-tabs-div-on':'ef-tabs-div-off' ;
185 if ($i - $start_i == 0)
186 {
187 $cellclass .= ' ef-tabs-cell-left' ;
188 $divclass .= ' ef-tabs-div-left' ;
189 }
190 elsif ($i - $start_i == -1 || $j == @$values - 1)
191 {
192 $cellclass .= ' ef-tabs-cell-right' ;
193 $divclass .= ' ef-tabs-div-right' ;
194 }
195  
196 my @switch_code ;
197  
198 foreach my $sub (@{$form -> {controls}})
199 {
200 my $code = $sub -> get_on_show_code ;
201 push @switch_code, $code if ($code) ;
202 }
203 my $js = join (';', @switch_code) ;
204 *]
205 <td class="[+ $cellclass +]"><div class="ef-tabs-div [+ $divclass +]"
206 [# [$ if $i - $start_i == 0 $]style="border-left: black 1px solid" [$endif$] #]
207 >[+ $options ->[$j] || $val +]
208 </div></td>
209 [* $i++ ;
210 $j++ ;
211 if ($i - $start_i >= $tabs && @$values > $j)
212 {
213 $more = 1 ;
214 $start_i = $i ;
215 last ;
216 }
217 *]
218 [$endwhile $]
219 [$if ($j == @$values) $]<td class="ef-tabs-cell-blank ef-tabs-view-all">&nbsp;</td>[$endif$]
220 </tr></table>
221 [$endwhile$]
222 [#<input type="hidden" name="[+ $name +]" id="[+ $fullname +]" class="ef-field-tab_select" value="[+ $uid +]_[+ $activeid +]">#]
223 </div>
224 [$endsub$]
225  
226 __END__