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

filter: Statementstmt 0.0% 0 / 89 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 146 CC 5 SCAR 16.2
CC
5
Cov
0%
xprepare_fdat
12.0
get_std_control_attr
6.0
init_data
6.0
CRAP 5.1
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::selectdyn ;
20  
21 use strict ;
22 use vars qw{%fdat} ;
23 use base 'Embperl::Form::ControlMultValue' ;
24  
25 use Embperl::Inline ;
26  
27 # ------------------------------------------------------------------------------------------
28  
29 sub get_std_control_attr
30 {
31 my ($self, $req, $id, $type, $addclass) = @_ ;
32  
33 if ($type eq 'readonly')
34 {
35 $id = $req -> {uuid} . '_' . $self -> {name} ;
36 my $url = $self -> {showurl} ;
37 $url =~ s/<id>/$self -> get_id_from_value ($Embperl::fdat{$self -> {name}}, $req)/e ;
38 my $attr = $self -> SUPER::get_std_control_attr ($req, $id, $type, 'ef-control-selectdyn-readonly') ;
39 return $attr . qq{ onDblClick="\$('#$self->{use_ajax}').ef_document ('load', '$url');"} ;
40 }
41
42 return $self -> SUPER::get_std_control_attr ($req, $id, $type, $addclass) ;
43 }
44
45 # ------------------------------------------------------------------------------------------
46 #
47 # init_data - daten aufteilen
48 #
49  
50 sub init_data
51 {
52 my ($self, $req) = @_ ;
53  
54 my $val = $self -> get_value ($req) ;
55 if ($val ne '')
56 {
57 my $name = $self -> {name} ;
58 my $fdat = $req -> {docdata} || \%Embperl::fdat ;
59 $fdat -> {'_opt_' . $name} = $self -> get_option_from_value ($val, $req) ;
60 $fdat -> {'_id_' . $name} = $self -> get_id_from_value ($val, $req) ;
61 }
62 }
63
64 # ------------------------------------------------------------------------------------------
65 #
66 # prepare_fdat - daten zusammenfuehren
67 #
68  
69 sub xprepare_fdat
70 {
71 my ($self, $req) = @_ ;
72  
73 return if ($self -> is_readonly ($req)) ;
74  
75 my $fdat = $req -> {form} || \%fdat ;
76 my $name = $self->{name} ;
77 $fdat -> {$name} = '' if (exists ($fdat -> {"_opt_$name"}) && $fdat -> {"_opt_$name"} eq '') ;
78 delete $fdat -> {"_opt_$name"} ;
79 delete $fdat -> {"_id_$name"} ;
80 }
81  
82 # ---------------------------------------------------------------------------
83  
84 sub show_control_addons
85 {
86 my ($self, $req) = @_ ;
87  
88 }
89
90 # ---------------------------------------------------------------------------
91  
92 sub get_doctypes_for_new_menu
93 {
94 my ($self, $req) = @_ ;
95  
96 return ;
97 }
98
99 # ---------------------------------------------------------------------------
100  
101 sub get_datasource
102 {
103 my ($self) = @_ ;
104
105 return $self -> {datasrcobj} ;
106 }
107  
108 # ---------------------------------------------------------------------------
109  
110 sub add_query_param
111 {
112 my ($self, $req, $datasource) = @_ ;
113
114 return '' ;
115 }
116  
117 1 ;
118  
119 __EMBPERL__
120  
121  
122 [# ---------------------------------------------------------------------------
123 #
124 # show_control - output the control
125 #]
126  
127 [$ sub show_control ($self, $req, $filter)
128  
129 my $name = $self -> {name} ;
130 my $class = $self -> {class} ;
131  
132 my $doctypes ;
133 my $datasrc = $self -> {datasrc} ;
134 if ($datasrc)
135 {
136 my $datasource = $self -> get_datasource ;
137 if ($datasource)
138 {
139 $datasrc = $datasource -> datasource ;
140 if (!$self -> {no_new})
141 {
142 $doctypes = $self -> get_doctypes_for_new_menu ($req, $datasource) ;
143 }
144
145 my ($constrain, $without_constrain) = $datasource -> get_constrain_value ($req, $self) ;
146 $datasrc .= '&constrain=' . $epreq->Escape ($constrain,6) . '&without_constrain=' . ($without_constrain?1:0) if ($constrain) ;
147 $datasrc .= $self -> add_query_param ($req, $datasource) ;
148
149 ($self -> {url_from}, $self -> {url_to}) = $datasource -> get_url_modifier ($req, $self) ;
150 $self -> {dbname} = $datasource -> get_dbname ($req, $self) ;
151 }
152 }
153  
154 my $addtop = $self -> {addtop} ;
155 my $addbottom = $self -> {addbottom} ;
156 my $append = $self -> {datasrcurl_append} ;
157 if ($addtop)
158 {
159 $append .= '&' if ($append) ;
160 $append .= '&addtop=' . $epreq->Escape ($req -> {json} -> encode($addtop), 6) ;
161 }
162 if ($addbottom)
163 {
164 $append .= '&' if ($append) ;
165 $append .= '&addbottom=' . $epreq->Escape ($req -> {json} -> encode($addbottom), 6) ;
166 }
167
168 $]
169 <div class="ef-control-selectdyn-div">
170 <input name="_opt_[+ $name +]" [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, undef, undef, 'ef-context-menu ' . ($self -> {no_button}?'':'ef-control-selectdyn-has-ctrl' )) } +]
171 type="text" _ef_attach="ef_selectdyn"
172 [$if $self -> {size} $]size="[+ $self->{size} +]" [$endif$]
173 [$if $self -> {showurl} $]_ef_show_url="[+ $self -> {showurl} +]" [$endif$]
174 [$if $self -> {showurl_append} $]_ef_show_url_append="[+ $self -> {showurl_append} +]" [$endif$]
175 [$if $self -> {popupurl} $]_ef_popup_url="[+ $self -> {popupurl} +]" [$endif$]
176 [$if $self -> {datasrcurl} $]_ef_datasrc_url="[+ $self -> {datasrcurl} +]" [$endif$]
177 [$if $self -> {url_from} $]_ef_url_from="[+ $self -> {url_from} +]" [$endif$]
178 [$if $self -> {url_to} $]_ef_url_to="[+ $self -> {url_to} +]" [$endif$]
179 [$if $self -> {dbname} $][+ '_ef_dbname' +]="[+ $self -> {dbname} +]" [$endif$]
180 [$if $append $]_ef_datasrc_url_append="[+ $append +]" [$endif$]
181 [$if $datasrc $]_ef_datasrc_nam="[+ $datasrc +]" [$endif$]
182 [$if $self -> {datasrctermmax} $]_ef_datasrc_term_max="[+ $self -> {datasrctermmax} +]" [$endif$]
183 [$if $self -> {use_ajax} $]_ef_use_ajax="[+ $self -> {use_ajax} +]" [$endif$]
184 [$if $self -> {show_on_select} $]_ef_show_on_select="[+ $self -> {show_on_select}?'1':'' +]" [$endif$]
185 [$if $doctypes $]_ef_doctypes="[+ $doctypes +]" [$endif$]
186 >
187 [$if !$self -> {no_button} $]<span class="ui-icon ui-icon-triangle-1-s ef-icon ef-control-selectdyn-ctrl ef-context-menu [+ $self -> {state} +]"></span>[$endif$]
188 <input type="hidden" name="[+ $name +]">
189 <input type="hidden" name="_id_[+ $name +]">
190 </div>
191 [$endsub$]
192  
193  
194 __END__