~ubuntu-branches/debian/sid/libembperl-perl/sid

« back to all changes in this revision

Viewing changes to Embperl/Form/Control.pm

  • Committer: Package Import Robot
  • Author(s): Florian Schlichting, Jonathan Yu, Salvatore Bonaccorso, Dominic Hargreaves, Ansgar Burchardt, Florian Schlichting
  • Date: 2012-10-02 22:39:09 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20121002223909-vhrio164s2xa8qd3
Tags: 2.5.0~rc2-1
[ Jonathan Yu ]
* Imported Upstream version 2.4.0.

[ Salvatore Bonaccorso ]
* debian/copyright: Re-add Ryan and Gregor to copyright for debian/*
  packaging.

[ Dominic Hargreaves ]
* Switch to dpkg-source 3.0 (quilt) format.
* Remove obsolete perl5.10.patch, perl5.12.patch.

[ Ansgar Burchardt ]
* debian/control: Convert Vcs-* fields to Git.

[ Florian Schlichting ]
* Imported Upstream version 2.5.0~rc2 (Closes: #624578, #666011).
* Patches forwarded upstream and thus obsoleted:
  german.patch, new_process_group.patch, utf8.patch, fix-pod-errors.patch,
  fix-whatis.patch, fix-string-typo.patch, fix-pod-unescaped-unicode.patch.
* Refreshed delay.patch (fuzz).
* Dropped modperl.patch, mod_perl versions < 2 are history.
* Dropped Makefile.PL.patch, divide et impera - style:
  + FORCEMP1 is no longer relevant, Makefile.PL can find Apache headers etc
    itself
  + replacing a custom prompt implementation is unnecessary
  + strip .pl suffix in debian/rules instead of Makefile.PL
  + with hardening flags enabled, there is nothing left in the output of
    `apxs2 -q CFLAGS` that makes a difference
* Bumped Standards-Version to 3.9.4 (using copyright-format 1.0) and updated
  upstream copyright holders.
* Switched dh compatibility to level 9 to enable passing of hardening flags.
* Switched to short-form debian/rules.
* Deleted obsolete README.source.
* Removed version on mod-perl dependency (no older version in the archive).
* Moved apache2-mpm-prefork from Suggests: to Recommends:.
* Updated short and long description.
* Replaced embedded code copy (prototype.js) by a symlink and suggest:
  libjs-prototype.
* Added myself to uploaders and copyright.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
###################################################################################
3
3
#
4
 
#   Embperl - Copyright (c) 1997-2005 Gerald Richter / ecos gmbh   www.ecos.de
 
4
#   Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh  www.ecos.de
 
5
#   Embperl - Copyright (c) 2008-2012 Gerald Richter
5
6
#
6
7
#   You may distribute under the terms of either the GNU General Public
7
8
#   License or the Artistic License, as specified in the Perl README file.
50
51
    {
51
52
    my ($self) = @_ ;
52
53
 
 
54
    my $eventattrs = '' ;
 
55
    if (my $e = $self -> {event}) 
 
56
        {
 
57
        for (my $i = 0; $i < @$e; $i += 2) 
 
58
            {
 
59
            $eventattrs .= $e -> [$i] . '="' . $e -> [$i+1] . '" ' ;
 
60
            }
 
61
        }
 
62
    $self -> {eventattrs} = $eventattrs ;
 
63
    $self -> {imagedir} ||= '/images' ;
 
64
    
53
65
    return $self ;
54
66
    }
55
67
 
75
87
    {
76
88
    my ($self, $req) = @_ ;
77
89
 
78
 
    return $self -> {disable} ;
 
90
    return $self -> {disable} || $req -> {form_options_masks}{$self->{name}}{disable} || $req -> {form_options_masks}{'*'}{disable} ;
79
91
    }
80
92
 
81
93
# ---------------------------------------------------------------------------
88
100
    {
89
101
    my ($self, $req) = @_ ;
90
102
 
91
 
    return $self -> {readonly} ;
 
103
    return $self -> {readonly}  || $req -> {form_options_masks}{$self->{name}}{readonly} || $req -> {form_options_masks}{'*'}{readonly}  ;
92
104
    }
93
105
 
94
106
# ---------------------------------------------------------------------------
95
107
#
96
 
#   show - output the whole control including the label
 
108
#   is_hidden - returns true if this is a hidden control
97
109
#
98
110
 
99
 
sub show
 
111
sub is_hidden
100
112
 
101
113
    {
102
114
    my ($self, $req) = @_ ;
103
115
 
104
 
    $fdat{$self -> {name}} = $self -> {default} if ($fdat{$self -> {name}} eq '' && exists ($self -> {default})) ;
105
 
    my $span = 0 ;
106
 
    $span += $self -> show_label_cell ($req, $span);
107
 
    return $self -> show_control_cell ($req, $span) ;
 
116
    return  ;
108
117
    }
109
118
 
 
119
 
110
120
# ---------------------------------------------------------------------------
111
121
#
112
122
#   get_on_show_code
144
154
 
145
155
# ---------------------------------------------------------------------------
146
156
#
 
157
#   load_form - load a form to a given formptr.
 
158
#
 
159
#   This class method should be overwritten, to load a form to a given
 
160
#   formptr, in case it is not already loaded
 
161
#   The formptr maybe passed in the options hash during form creation
 
162
#
 
163
#   in  $formptr
 
164
#
 
165
 
 
166
 
 
167
sub load_form
 
168
    {
 
169
    my ($class, $formptr) = @_ ;
 
170
    
 
171
    }
 
172
    
 
173
# ---------------------------------------------------------------------------
 
174
#
 
175
#   get_control_from_id
 
176
#
 
177
 
 
178
sub get_control_from_id
 
179
    {
 
180
    my ($class, $id) = @_ ;
 
181
    
 
182
    my ($formptr, $ctlid) = split /#/, $id ;
 
183
    my $form = $Embperl::FormData::forms{$formptr} ;
 
184
    
 
185
    if (!$form)
 
186
        {
 
187
        $class -> load_form ($formptr) ;
 
188
        $form = $Embperl::FormData::forms{$formptr} ;
 
189
        die "Form for '$formptr' is not available" if (!$form) ;
 
190
        }
 
191
    
 
192
    my $ctl  = $form -> {controlids}{$ctlid} ;
 
193
    die "Control '$ctlid' in Form '$formptr' is not available" if (!$ctl) ;
 
194
    
 
195
    return $ctl ;
 
196
    }
 
197
    
 
198
# ---------------------------------------------------------------------------
 
199
#
 
200
#   get_id_for_control
 
201
#
 
202
 
 
203
sub get_id_for_control
 
204
    {
 
205
    my ($self, $reqdata) = @_ ;
 
206
    
 
207
    return "$self->{formptr}#$self->{id}" ;
 
208
    }
 
209
    
 
210
# ---------------------------------------------------------------------------
 
211
#
 
212
#   label_text - return text of label
 
213
#
 
214
 
 
215
sub label_text
 
216
    {
 
217
    my ($self) = @_ ;
 
218
 
 
219
    return $self -> {label_text} if ($self -> {label_text}) ;
 
220
 
 
221
    return $self -> {label_text} = $self -> {showtext}?($self->{text} ||
 
222
                                   $self->{name}):$self -> form -> convert_label ($self) ;
 
223
    }
 
224
 
 
225
 
 
226
# ---------------------------------------------------------------------------
 
227
#
 
228
#   get_validate_auto_rules - get rules for validation, in case user did
 
229
#                             not specify any
 
230
#                             should be overwritten by control
 
231
#
 
232
 
 
233
sub get_validate_auto_rules
 
234
    {
 
235
    my ($self, $req) = @_ ;
 
236
    
 
237
    return if (!$self -> {required}) ;
 
238
    return [ required => 1 ] ;
 
239
    }
 
240
    
 
241
# ---------------------------------------------------------------------------
 
242
#
147
243
#   get_validate_rules - get rules for validation
148
244
#
149
245
 
154
250
    my @local_rules ;
155
251
    if ($self -> {validate})
156
252
        {
157
 
 
158
253
        @local_rules = ( -key => $self->{name} );
159
 
        push @local_rules, -name => $self->{text} if ($self -> {text}) ;
 
254
        push @local_rules, -name => $self -> label_text ;
160
255
        push @local_rules, @{$self -> {validate}};
161
256
        }
 
257
    else
 
258
        {
 
259
        my $auto = $self -> get_validate_auto_rules ($req) ;
 
260
        if ($auto)
 
261
            {
 
262
            @local_rules = ( -key => $self->{name} );
 
263
            push @local_rules, -name => $self -> label_text ;
 
264
            push @local_rules, @{$auto};
 
265
            }
 
266
        }    
162
267
    return \@local_rules ;
163
268
    }
164
269
 
165
 
 
 
270
# ---------------------------------------------------------------------------
 
271
#
 
272
#   has_auto_label_size - returns true if label should be auto sized for this control
 
273
#
 
274
 
 
275
sub has_auto_label_size
 
276
    {
 
277
    return 1 ;
 
278
    }
 
279
 
 
280
    
 
281
# ---------------------------------------------------------------------------
 
282
#
 
283
#   get_value - return the current value for the control
 
284
#               if dataprefix is set, every hash key within dataprefix is tried
 
285
#
 
286
 
 
287
sub get_value
 
288
    {
 
289
    my ($self, $req) = @_ ;
 
290
    
 
291
    my $fdat       = $req -> {docdata} || \%Embperl::fdat ;
 
292
    my $name       = $self -> {name} ;
 
293
    my $dataprefix = $self -> {dataprefix} ;
 
294
    return $fdat -> {$name} if (!$dataprefix) ;
 
295
    
 
296
    foreach my $prefix (@$dataprefix)
 
297
        {
 
298
        my $item = $prefix?$fdat -> {$prefix}{$name}:$fdat -> {$name} ;
 
299
        return $item if (defined ($item)) ;
 
300
        }
 
301
    
 
302
    return ;
 
303
    }
 
304
 
 
305
 
 
306
# ---------------------------------------------------------------------------
 
307
#
 
308
#   get_std_control_attr - return the default attributes for the control
 
309
#
 
310
#   ret     string with all standard attribute, already html escaped
 
311
#
 
312
 
 
313
sub get_std_control_attr
 
314
    {
 
315
    my ($self, $req, $id, $type, $addclass) = @_ ;
 
316
 
 
317
    my $name    = $self -> {force_name} || $self -> {name} ;
 
318
    my $ctrlid  = $id || ($req -> {uuid} . '_' . $name) ;
 
319
    my $class   = $self -> {class} ;
 
320
    my $width   = $self -> {width_percent} ;
 
321
    my $events  = $self -> {eventattrs} ;
 
322
    $type     ||= $self -> {type} ;
 
323
    my $state   = $self -> {state} ;
 
324
    
 
325
    my $attrs = qq{class="ef-control ef-control-width-$width ef-control-$type ef-control-$type-width-$width $addclass $class $state"  id="$ctrlid" $events} ;
 
326
    return wantarray?($attrs, $ctrlid, $name):$attrs ;
 
327
    }
 
328
 
 
329
    
166
330
1 ;
167
331
 
168
332
# ===========================================================================
171
335
 
172
336
[$syntax EmbperlBlocks $]
173
337
 
 
338
 
 
339
 
 
340
[# ---------------------------------------------------------------------------
 
341
#
 
342
#   show - output the whole control including the label
 
343
#]
 
344
 
 
345
[$sub show ($self, $req) 
 
346
 
 
347
$fdat{$self -> {name}} = $self -> {default} if ($fdat{$self -> {name}} eq '' && exists ($self -> {default})) ;
 
348
my $span = 0 ;
 
349
 
 
350
$]<table class="ef-element ef-element-width-[+ $self -> {width_percent} +] ef-element-[+ $self -> {type} +] [+ $self -> {state} +]">
 
351
  <tr>
 
352
    [-
 
353
    $span += $self -> show_label_cell ($req, $span);
 
354
    $self -> show_control_cell ($req, $span) ;
 
355
    -]
 
356
  </tr>
 
357
  </table>[$  
 
358
 endsub $]
 
359
 
174
360
[# ---------------------------------------------------------------------------
175
361
#
176
362
#   show_sub_begin - output begin of sub form
180
366
 
181
367
my $span = $self->{width_percent}  ;
182
368
$]
183
 
</tr><tr><td class="cBase cTabTD" colspan="[+ $span +]">
 
369
<!-- sub begin --></tr><tr><td class="cBase cTabTD" colspan="[+ $span +]">
184
370
[$endsub$]
185
371
 
186
372
[# ---------------------------------------------------------------------------
189
375
#]
190
376
 
191
377
[$sub show_sub_end ($self, $req) $]
192
 
</td>
 
378
</td><!-- sub end -->
193
379
[$endsub$]
194
380
 
195
381
[# ---------------------------------------------------------------------------
197
383
#   show - output the label
198
384
#]
199
385
 
200
 
[$ sub show_label ($self, $req) $][+ $self->{text} || $self->{name} +][$endsub$]
 
386
[$ sub show_label ($self, $req) $][-
 
387
 
 
388
    if ($self -> {showoptionslabel})
 
389
        {
 
390
        my $opts = $self -> form -> convert_options ($self, [$self -> {value}]) ;
 
391
        $self -> {text} = $opts -> [0] ;
 
392
        $self -> {showtext} = 1 ;
 
393
        }
 
394
-][+ $self -> label_text +][$endsub$]
201
395
 
202
396
[# ---------------------------------------------------------------------------
203
397
#
205
399
#]
206
400
 
207
401
[$sub show_label_icon ($self, $req) $]
208
 
[$if $self -> {sublines} $]&nbsp;<img src="/images/plus.png" style="vertical-align: middle;">[$endif$]
209
 
[$if $self -> {parentid} $]&nbsp;<img src="/images/vline.png" style="vertical-align: middle;">[$endif$]
 
402
[$if $self -> {xxsublines} $]&nbsp;<img src="/images/plus.png" style="vertical-align: middle;">[$endif$]
 
403
[$if $self -> {xxparentid} $]&nbsp;<img src="/images/vline.png" style="vertical-align: middle;">[$endif$]
210
404
[$endsub$]
211
405
 
212
406
[# ---------------------------------------------------------------------------
216
410
 
217
411
[$ sub show_label_cell ($self, $req)
218
412
 
219
 
my $style = "";
220
 
$style = "white-space:nowrap;" if ($self->{labelnowrap}) ;
221
 
 
 
413
my $style = '';
 
414
$style = 'white-space:nowrap; ' if ($self->{labelnowrap}) ;
 
415
$addclass = 'ef-label-box-width-' . ($self->{width_percent}) ;
 
416
$addclass2 = 'ef-label-width-' . ($self->{width_percent}) ;
222
417
$]
223
 
  <td class="cLabelBox[$ if $self->{labelclass} $][+ " $self->{labelclass}" +][$ endif $]"
224
 
      colspan="1" [$ if $style $]style="[+ $style +]"[$ endif $]>
 
418
   <td class="ef-label-box  [+ $addclass +] [$ if $self->{labelclass} $][+ " $self->{labelclass}" +][$ endif $]" [$ if $style $]style="[+ $style +]"[$ endif $]>
 
419
    <div class="ef-label [+ $addclass2 +]">
225
420
    [-
226
421
    $self -> show_label ($req);
227
422
    $self -> show_label_icon ($req) ;
228
423
    -]
 
424
    </div>
229
425
  </td>
230
 
  [- return 1; -]
 
426
  [- return $span ; -]
231
427
[$endsub$]
232
428
 
233
429
[# ---------------------------------------------------------------------------
235
431
#   show_control - output the control itself
236
432
#]
237
433
 
238
 
[$ sub show_control ($self, $req) $][+ $self->{value} +][$endsub$]
 
434
[$ sub show_control ($self, $req) $]<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req) } +]>[+ $self->{value} +]</div>[$endsub$]
239
435
 
240
436
[# ---------------------------------------------------------------------------
241
437
#
242
438
#   show_control_readonly - output the control as readonly
243
439
#]
244
440
 
245
 
[$ sub show_control_readonly ($self, $req) $][+ $self -> {value} || $fdat{$self -> {name}} +][$endsub$]
 
441
[$ sub show_control_readonly ($self, $req, $value) 
 
442
 
 
443
$value = $self -> {value} || $fdat{$self -> {name}} if (!defined($value)) ;
 
444
$]
 
445
<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, '', 'readonly') } +]>[+ $value +]</div>
 
446
[$endsub$]
 
447
 
 
448
[# ---------------------------------------------------------------------------
 
449
#
 
450
#   show_control_addons - output additional things after the control
 
451
#]
 
452
 
 
453
[$ sub show_control_addons ($self, $req) $][$endsub$]
246
454
 
247
455
 
248
456
[# ---------------------------------------------------------------------------
252
460
 
253
461
[$ sub show_control_cell ($self, $req, $x)
254
462
 
255
 
    my $span = $self->{width_percent} - $x ;
 
463
    my $ro = $self -> is_readonly ($req) ;
 
464
    my $addclass = 'ef-control-box-width-' . ($self->{width_percent} || 50 ) ;
 
465
    $addclass .= ' ef-control-box-readonly' if ($ro) ;    
256
466
$]
257
 
    <td class="cControlBox" colspan="[+ $span +]">
258
 
    [* my @ret = $self -> is_readonly?$self -> show_control_readonly($req):$self -> show_control ($req); *]
 
467
    <td class="ef-control-box [+ $addclass +]">
 
468
    [*
 
469
     my @ret = $ro?$self -> show_control_readonly($req):$self -> show_control ($req);
 
470
     $self -> show_control_addons ($req) ;
 
471
     *]
259
472
    </td>
260
473
[* return @ret ; *]
261
474
[$endsub$]
301
514
 
302
515
Could value of this control be changed ?
303
516
 
 
517
=head2 label_text
 
518
 
 
519
Returns the text of the label
 
520
 
304
521
=head2 show
305
522
 
306
523
Output the control
343
560
 
344
561
Output the control itself
345
562
 
 
563
=head2 show_control_readonly
 
564
 
 
565
Output the control itself as readonly
 
566
 
 
567
=head2 show_control_addons
 
568
 
 
569
output additional things after the control
 
570
 
346
571
=head2 show_control_cell
347
572
 
348
573
Output the table cell in which the control will be displayed
359
584
=head3 text
360
585
 
361
586
Will be used as label for the control, if not given
362
 
name is used as default
 
587
'name' is used as default.
 
588
 
 
589
Normaly the the name and text parameters are processed
 
590
by the method C<convert_label> of the C<Embperl::Form>
 
591
object. This method can be overwritten, to allow translation etc.
 
592
 
 
593
If the parameter C<showtext> is given a true value, C<convert_label>
 
594
is not called and the text is displayed as it is.
 
595
 
 
596
=head3 showtext
 
597
 
 
598
Display label without passing it through C<convert_label>. See C<text>.
363
599
 
364
600
=head2 labelnowrap
365
601
 
392
628
=head2 width_percent
393
629
 
394
630
With this parameter you can also specify the width of
395
 
the control in percent. This parameter take precendence over
 
631
the control in percent. This parameter take precedence over
396
632
C<width>
397
633
 
398
634
=head2 default
399
635
 
400
636
Default value of the control
401
637
 
 
638
=head2 imagedir
 
639
 
 
640
Basepath where to find images, in case the control uses images.
 
641
Default value is /images
 
642
 
 
643
=head2 trigger
 
644
 
 
645
When set will trigger state changes of other controls. See "state".
 
646
 
 
647
=head2 state
 
648
 
 
649
Can be used to hide/show disable/enable the control trigger by
 
650
other controls.
 
651
 
 
652
Checkbox define the following states:
 
653
 
 
654
=over
 
655
 
 
656
=item * <id-of-checkbox>-show
 
657
 
 
658
Show control if checkbox checked
 
659
 
 
660
=item * <id-of-checkbox>-hide
 
661
 
 
662
Hide control if checkbox checked
 
663
 
 
664
=item * <id-of-checkbox>-enable
 
665
 
 
666
Enable control if checkbox checked
 
667
 
 
668
=item * <id-of-checkbox>-disable
 
669
 
 
670
Disable control if checkbox checked
 
671
 
 
672
=back
 
673
 
 
674
 
 
675
 
402
676
=head1 AUTHOR
403
677
 
404
 
G. Richter (richter@dev.ecos.de)
 
678
G. Richter (richter at embperl dot org)
405
679
 
406
680
=head1 SEE ALSO
407
681