File: MyForm.pm

package info (click to toggle)
libembperl-perl 2.5.0-17
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 7,632 kB
  • sloc: ansic: 21,387; perl: 14,497; javascript: 4,280; cpp: 467; xml: 49; makefile: 35; sh: 24
file content (194 lines) | stat: -rw-r--r-- 4,791 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

package Embperl::MyForm ;

use Embperl::Form ;

use Embperl::Inline ;
use base 'Embperl::Form' ;


# ---------------------------------------------------------------------------

sub form_id { 'topdiv' }


# ---------------------------------------------------------------------------

sub setup_form_obj
    {
    my ($self, $options, $fields) = @_ ;

    my $key = ref $self ;
    
    return if (ref $self && $self -> {id}) ;
    return $epreq->{forms}{$key} if (exists $epreq->{forms}{$key}) ;
   
    $options ||= {} ;


    $self = $self -> new ($fields,
                  { formname    => 'myform',
		    valign      =>  'top',
                    jsnamespace => 'top',
                    language    => 'de',
                    %$options},
                    $self -> form_id) ;

    $self -> layout ;
    $key = ref $self ;

    return $epreq->{forms}{$key} = $self ;
    }        

# ---------------------------------------------------------------------------


sub on_prepare_fdat

    {
    my ($self, $epreq) = @_ ;

    $self = $self -> setup_form_obj ;
    
    $self -> prepare_fdat ($Embperl::req);
    }

# ---------------------------------------------------------------------------

sub showfields

    {
    my ($self, $fields, $options) = @_ ;

    $self = $self -> setup_form_obj($options, $fields) ;

    $self -> init_data ($Embperl::req) ;
    $self -> show_controls ($Embperl::req);
    }

# ---------------------------------------------------------------------------
#
#   get_control_packages
#
#   returns an array ref with packges where to search for controls
#

sub get_control_packages
    {
    my ($self) = @_ ;

    my $packages = $self ->SUPER::get_control_packages ;

    unshift @$packages, 'Embperl::MyForm::Control' ;
    return $packages ;
    }

# ---------------------------------------------------------------------------
#
#   get_datasrc_packages
#
#   returns an array ref with packges where to search for data source classes
#

sub get_datasrc_packages
    {
    my ($self) = @_ ;

    my $packages = $self ->SUPER::get_datasrc_packages ;

    unshift @$packages, 'Embperl::MyForm::DataSource' ;
    return $packages ;
    }

1 ;

__END__

##--> the following can be used to translate form content...

#------------------------------------------------------------------------------------------
#
#   convert_label
#
#   converts the label of a control to the text that should be outputed.
#   By default does return the text or name parameter of the control.
#   Can be overwritten to allow for example internationalization.
#
#   in $ctrl        Embperl::Form::Control object
#      $name        optional: name to translate, if not given take $ctrl -> {name}
#

sub convert_label
    {
    my ($self, $ctrl, $name, $text) = @_ ;
    
    my $prefix = $ctrl -> {nameprefix} ;
    
    return _t ($prefix . ($name || $ctrl->{basename})) if ($prefix =~ /:/)  ;
    return _t ('attr:' . $prefix . ($name || $ctrl->{basename}))  ;
    }

#------------------------------------------------------------------------------------------
#
#   convert_text
#
#   converts the text of a control to the text that should be outputed.
#   By default does return the text or name parameter of the control.
#   Can be overwritten to allow for example internationalization.
#
#   in $ctrl        Embperl::Form::Control object
#

sub convert_text
    {
    my ($self, $ctrl, $value, $text) = @_ ;
    
    my $prefix = $ctrl -> {nameprefix} ;
    $value ||= $ctrl->{basename} ;
    
    return _t ($value) if ($value =~ /:/) ;
    return _t ($prefix . $value) if ($prefix =~ /:/) ;
    return _t ('info:' . $prefix . $value)  ;
    }

#------------------------------------------------------------------------------------------
#
#   convert_options
#
#   converts the values of a control to the text that should be outputed.
#   By default does nothing.
#   Can be overwritten to allow for example internationalization.
#
#   in  $ctrl        Embperl::Form::Control object
#       $values     values of the control i.e. values that are submitted
#       $options    options of the control i.e. text that should be displayed
#

sub convert_options
    {
    my ($self, $ctrl, $values, $options) = @_ ;

    my @options ;
    my $prefix = $ctrl -> {nameprefix} ;
    my $prefix1 = "val:$ctrl->{nameprefix}$ctrl->{basename}:" ;
    my $prefix2 = $prefix =~ /:/?$prefix:"val:" ;
    
    foreach my $val (@$values)
        {
        my $value = ref $val?$val -> [0]:$val ;
        my $val1 = $prefix1 . $value ;
        my $val2 = $prefix2 . $value ;

        my $opt = _t ($val1) ;
        $opt = _t ($val2) if ($opt eq $val1) ;
            
        push @options, $opt eq $val2?"$val1 | $val2":$opt ;
        }
        
    return \@options ;
    }



1;