Debian Codegraph @

Embperl/Form/Control/tabs.pm

raw
1
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2014 Gerald Richter
6 #
7 # You may distribute under the terms of either the GNU General Public
8 # License or the Artistic License, as specified in the Perl README file.
9 #
10 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 #
14 # $Id$
15 #
16 ###################################################################################
17
18 package Embperl::Form::Control::tabs ;
19
20 use strict ;
21 use vars qw{%fdat} ;
22
23 use Embperl::Form::ControlMultValue ;
24 use base 'Embperl::Form::ControlMultValue' ;
25
26 use Embperl::Inline ;
27
28 # ---------------------------------------------------------------------------
29 #
30 # new - create a new control
31 #
32
33
34 sub new
35
36 {
37 my ($class, $args) = @_ ;
38
39 my $self = Embperl::Form::ControlMultValue -> new($args) ;
40 bless $self, $class ;
41
42 $self -> {width} = 1 ;
43 $self -> {nameprefix} ||= 'tab:' ;
44
45 return $self ;
46 }
47
48 # ---------------------------------------------------------------------------
49 #
50 # noframe - do not draw frame border if this is the first control
51 #
52
53
54 sub noframe
55
56 {
57 return 1 ;
58 }
59
60 # ---------------------------------------------------------------------------
61 #
62 # get_active_id - get the id of the value which is currently active
63 #
64
65 sub get_active_id
66
67 {
68 my ($self, $req) = @_ ;
69
70 my $key = "active_id:$self" ;
71 my $id ;
72 return $id if ($id = $req -> {$key}) ;
73
74 my ($values, $options) = $self -> get_values ($req) ;
75 my $name = $self -> {name} ;
76 my $dataval = $fdat{$name} || $req -> {query}{$name} || $values -> [0] ;
77 my $activeid ;
78
79 my $i = 0 ;
80 foreach my $val (@$values)
81 {
82 if ($val eq $dataval || $self -> {subids}[$i] eq $dataval)
83 {
84 $activeid = $self -> {subids}[$i] ;
85 last ;
86 }
87 $i++ ;
88 }
89 return $req -> {$key} = $activeid || $self -> {subids}[0];
90 }
91
92
93 1 ;
94
95 __EMBPERL__
96
97 [$ syntax EmbperlBlocks $]
98
99 [ ---------------------------------------------------------------------------
100 #
101 # show_controls_begin - output begin of form controls area
102 #]
103
104 [$ sub show_subform_controls_begin ($self, $form, $req, $activeid)
105
106 my $parent = $form -> parent_form ;
107 my $class = $parent -> {noframe}?'ef-tabs-border-u':'ef-tabs-border' ;
108 $]
109
110 <div _ef_name="[+ $form->{id} +]" class="ef-tabs-content"
111 [$if ($activeid && $form->{id} ne $activeid) $] style="display: none" [$endif$]
112 >
113
114 [$if (!$form -> {noframe}) $]
115 <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="Verstecken/Anzeigen"></span><span class="ef-tabs-separator-header-text">[+ $form -> {text} +]</span></div>
116 [#<table class="ef-tabs-border-cell [+ $class +]"><tr><td class="ef-tabs-content-cell"> #]
117 <div class="ef-tabs-border-cell [+ $class +]"><div class="ef-tabs-content-cell">
118
119 [$endif$]
120
121 [$endsub$]
122
123 [# ---------------------------------------------------------------------------
124 #
125 # show_controls_end - output end of form controls area
126 #]
127
128 [$sub show_subform_controls_end ($self, $form, $req)
129 $]
130
131 [# [$ if (!$form -> {noframe}) $]</td></tr></table> [$endif$] #]
132 [$ if (!$form -> {noframe}) $]</div></div> [$endif$]
133 </div>
134 [$endsub$]
135
136
137
138 [# ---------------------------------------------------------------------------
139 #
140 # show - output the control
141 #]
142
143 [$ sub show ($self, $req)
144
145 my ($values, $options) = $self -> get_values ($req) ;
146 my $span = ($self->{width_percent}) ;
147 my $name = $self -> {name} ;
148 my $dataval = $fdat{$name} || $values -> [0] ;
149 my $activeid = $self -> get_active_id ($req) ;
150 my $form = $self -> form ;
151 my $nsprefix = $form -> {jsnamespace} ;
152 my $tabs_per_line = $self -> {'tabs_per_line'} || 99;
153 $tabs_per_line = [$tabs_per_line, $tabs_per_line, $tabs_per_line, $tabs_per_line]
154 if (!ref $tabs_per_line) ;
155
156 my $val ;
157 my $i = 0 ;
158 my $j = 0 ;
159 my $more = 1 ;
160 my $start_i = 0 ;
161 my $line = 0 ;
162 $]
163
164 <div class="ef-tabs-content-cell" colspan="[+ $span +]" _ef_attach="ef_tabs">
165 [$ while ($more) $]
166 <table class="ef-tabs-selector" ><tr class="ef-tabs-selector-row">
167 [*
168 $more = 0 ;
169 my $tabs = $tabs_per_line -> [$line++] ;
170 *]
171 [$ while ($j < @$values) $]
172 [*
173 if ($self -> {subobjects}[ $j ] -> is_disabled ($req))
174 {
175 $j++ ;
176 next ;
177 }
178 $val = $values -> [$j] ;
179 my $id = $self -> {subids}[$j] ;
180 my $cellclass = $id eq $activeid?'ef-tabs-cell-on':'ef-tabs-cell-off' ;
181 my $divclass = $id eq $activeid?'ef-tabs-div-on':'ef-tabs-div-off' ;
182
183 my @switch_code ;
184
185 foreach my $sub (@{$form -> {controls}})
186 {
187 my $code = $sub -> get_on_show_code ;
188 push @switch_code, $code if ($code) ;
189 }
190 my $js = join (';', @switch_code) ;
191 *]
192 <td class="[+ $cellclass +]"><div class="ef-tabs-div [+ $divclass +]"
193 [$ if $i - $start_i == 0 $]style="border-left: black 1px solid" [$endif$]
194 >[+ $options ->[$j] || $val +]
195 </div></td>
196 [* $i++ ;
197 $j++ ;
198 if ($i - $start_i >= $tabs && @$values > $j)
199 {
200 $more = 1 ;
201 $start_i = $i ;
202 last ;
203 }
204 *]
205 [$endwhile $]
206 [$if ($j == @$values) $]<td class="ef-tabs-cell-blank ef-tabs-view-all">&nbsp;</td>[$endif$]
207 </tr></table>
208 [$endwhile$]
209 [#<input type="hidden" name="[+ $name +]" id="[+ $fullname +]" class="ef-field-tab_select" value="[+ $uid +]_[+ $activeid +]">#]
210 </div>
211 [$endsub$]
212
213 __END__
214
215 =pod
216
217 =head1 NAME
218
219 Embperl::Form::Control::tabs - A tab control inside an Embperl Form
220
221
222 =head1 SYNOPSIS
223
224 Embperl::Form -> add_tabs (
225 [
226 {
227 text => 'First Tab',
228 fields => [
229 ...
230 ]
231 },
232 {
233 text => 'Second Tab',
234 fields => [
235 ...
236 ]
237 }
238 ])
239
240
241
242 =head1 DESCRIPTION
243
244 Control to display tabs at the top of the form and control the switching between sub forms.
245 The switching is done by Javascript, so it can only be used in environment where
246 Javascript is available.
247
248 You can use the method Embperl::Form -> add_tabs
249 to setup a tabbed form.
250 See Embperl::Form on how to specify parameters.
251
252 =head2 PARAMETER
253
254
255 =head3 text
256
257 Text that will be displayed on the tab
258
259 =head3 fields
260
261 List of fields that should be displayed in this subform.
262 Given in the same form as form Embperl::Form.
263
264
265 =head1 Author
266
267 G. Richter (richter at embperl dot org)
268
269 =head1 See Also
270
271 perl(1), Embperl, Embperl::Form
272
273