Author: richter Date: Mon Apr 21 07:59:38 2014 New Revision: 1588856 URL: http://svn.apache.org/r1588856 Log: init_data is not called anymore for readonly fields, use get_display_text instead
Modified: perl/embperl/trunk/Embperl/Form.pm perl/embperl/trunk/Embperl/Form/Control.pm perl/embperl/trunk/Embperl/Form/Control/checkbox.pm perl/embperl/trunk/Embperl/Form/Control/datetime.pm perl/embperl/trunk/Embperl/Form/Control/mult.pm perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm perl/embperl/trunk/Embperl/Form/ControlMultValue.pm perl/embperl/trunk/Embperl/Form/DataSource.pm Modified: perl/embperl/trunk/Embperl/Form.pm URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form.pm?rev=1588856&r1=1588855&r2=1588856&view=diff ============================================================================== --- perl/embperl/trunk/Embperl/Form.pm (original) +++ perl/embperl/trunk/Embperl/Form.pm Mon Apr 21 07:59:38 2014 @@ -629,7 +629,7 @@ sub init_data } foreach my $control (@{$self -> {init_data}}) { - $control -> init_data ($req) if (!$control -> is_disabled ($req)) ; + $control -> init_data ($req) if (!$control -> is_disabled ($req) && !$control -> is_readonly ($req)) ; } } Modified: perl/embperl/trunk/Embperl/Form/Control.pm URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control.pm?rev=1588856&r1=1588855&r2=1588856&view=diff ============================================================================== --- perl/embperl/trunk/Embperl/Form/Control.pm (original) +++ perl/embperl/trunk/Embperl/Form/Control.pm Mon Apr 21 07:59:38 2014 @@ -445,6 +445,18 @@ sub get_display_text return $value ; } +# ------------------------------------------------------------------------------------------ +# +# get_sort_value - returns the value that should be used to sort +# + +sub get_sort_value + { + my ($self, $req, $value) = @_ ; + + return lc($self -> get_display_text ($req, $value)) ; + } + # --------------------------------------------------------------------------- # # get_id_from_value - returns id for a given value @@ -453,7 +465,7 @@ sub get_display_text sub get_id_from_value { - #my ($self, $value) = @_ ; + #my ($self, $value, $req) = @_ ; return ; } @@ -681,6 +693,45 @@ Do not display this control at all. Could value of this control be changed ? +=héad2 prepare_fdat + +Is called when the form is submitted back. Can be used to convert the value +that the user has entered in the form to the format that is used +internally. E.g. convert a human readable date/time format, which might +be different depending on the locale, to the interal datetime format. + +=head2 init_data + +Is called when the control should be displayed. Can be used to convert +the internal format of the value to the format that the user +should see in the input control. E.g. convert internal datetime +representation to a human readable date/time format, which might +be different depending on the locale. + +This method is not called if the control is readonly. + +=head2 get_display_text + +Returns the value that should be displayed inside a readonly +control or inside a table. This is similar to init_data, but +for readonly controls. + +This method is only called if the control is readonly. + +=head2 get_sort_value + +returns the value that should be used to sort + +=head2 get_id_from_value + +returns the id that is associated with value if any + +=head2 init_markup + +This method is called instaed of show, if only the control data is sent +to the browser and not the whole markup. This can be used to insert +dynamic markup. + =head2 label_text Returns the text of the label Modified: perl/embperl/trunk/Embperl/Form/Control/checkbox.pm URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/checkbox.pm?rev=1588856&r1=1588855&r2=1588856&view=diff ============================================================================== --- perl/embperl/trunk/Embperl/Form/Control/checkbox.pm (original) +++ perl/embperl/trunk/Embperl/Form/Control/checkbox.pm Mon Apr 21 07:59:38 2014 @@ -87,6 +87,22 @@ sub show_control_readonly $self -> SUPER::show_control_readonly ($req, $fdat{$name} eq $val?'X':'-') ; } +# ------------------------------------------------------------------------------------------ +# +# get_display_text - returns the text that should be displayed +# + +sub get_display_text + { + my ($self, $req, $value) = @_ ; + + my $fdat = $req -> {docdata} || \%fdat ; + my $name = $self -> {name} ; + my $val = $self -> {value} ; + $val = 1 if ($val eq '') ; + + return $fdat->{$name} eq $val?'X':'-' ; + } 1 ; Modified: perl/embperl/trunk/Embperl/Form/Control/datetime.pm URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/datetime.pm?rev=1588856&r1=1588855&r2=1588856&view=diff ============================================================================== --- perl/embperl/trunk/Embperl/Form/Control/datetime.pm (original) +++ perl/embperl/trunk/Embperl/Form/Control/datetime.pm Mon Apr 21 07:59:38 2014 @@ -46,6 +46,44 @@ sub init return $self ; } +# ------------------------------------------------------------------------------------------ +# +# get_display_text - returns the text that should be displayed +# + +sub get_display_text + { + my ($self, $req, $time) = @_ ; + + $time = $self -> get_value ($req) if (!defined ($time)) ; + + return if ($time eq '') ; + + if ($self -> {dynamic} && ($time =~ /^\s*((?:d|m|y|q)(?:\+|-)?(?:\d+)?)\s*$/)) + { + return $1 ; + } + + my ($y, $m, $d, $h, $min, $s, $z) = ($time =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(.)/) ; + + # Getting the local timezone + + my $date = eval + { + my @time = gmtime(timegm_nocheck($s,$min,$h,$d,$m-1,$y-1900)+($tz_local*60)); + + my $format = $self -> {notime} || ($s == 0 && $h == 0 && $min == 0)?'%d.%m.%Y':'%d.%m.%Y, %H:%M' ; + strftime ($format, @time[0..5]) ; + } ; + + if ($time && !$date && ($time =~ /\d+\.\d+\.\d+/)) + { + $date = $time ; + } + + return $date ; + } + # ------------------------------------------------------------------------------------------ # # init_data - daten aufteilen @@ -60,33 +98,7 @@ sub init_data my $time = $fdat->{$name} ; return if ($time eq '' || ($req -> {"ef_datetime_init_done_$name"} && !$force)) ; - if ($self -> {dynamic} && ($time =~ /^\s*((?:d|m|y|q)(?:\+|-)?(?:\d+)?)\s*$/)) - { - $fdat->{$name} = $1 ; - - $req -> {"ef_datetime_init_done_$name"} = 1 ; - return ; - } - - - my ($y, $m, $d, $h, $min, $s, $z) = ($time =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(.)/) ; - - # Getting the local timezone - - my $date = eval - { - my @time = gmtime(timegm_nocheck($s,$min,$h,$d,$m-1,$y-1900)+($tz_local*60)); - - my $format = $self -> {notime} || ($s == 0 && $h == 0 && $min == 0)?'%d.%m.%Y':'%d.%m.%Y, %H:%M' ; - strftime ($format, @time[0..5]) ; - } ; - - if ($time && !$date && ($time =~ /\d+\.\d+\.\d+/)) - { - $date = $time ; - } - - $fdat->{$name} = $date ; + $fdat->{$name} = $self -> get_display_text ($req, $time) ; $req -> {"ef_datetime_init_done_$name"} = 1 ; } Modified: perl/embperl/trunk/Embperl/Form/Control/mult.pm URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/mult.pm?rev=1588856&r1=1588855&r2=1588856&view=diff ============================================================================== --- perl/embperl/trunk/Embperl/Form/Control/mult.pm (original) +++ perl/embperl/trunk/Embperl/Form/Control/mult.pm Mon Apr 21 07:59:38 2014 @@ -100,7 +100,7 @@ sub init_data sub prepare_fdat { my ($self, $req) = @_ ; - my $fdat = $req -> {form} || \%fdat ; + my $fdat = $req -> {form} || \%fdat ; my $name = $self->{name} ; my $max = $fdat->{"__${name}_max"} || 1 ; Modified: perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm?rev=1588856&r1=1588855&r2=1588856&view=diff ============================================================================== --- perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm (original) +++ perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm Mon Apr 21 07:59:38 2014 @@ -33,7 +33,7 @@ sub get_std_control_attr { $id = $req -> {uuid} . '_' . $self -> {name} ; my $url = $self -> {showurl} ; - $url =~ s/<id>/$self -> get_id_from_value ($Embperl::fdat{$self -> {name}})/e ; + $url =~ s/<id>/$self -> get_id_from_value ($Embperl::fdat{$self -> {name}}, $req)/e ; my $attr = $self -> SUPER::get_std_control_attr ($req, $id, $type, 'ef-control-selectdyn-readonly') ; return $attr . qq{ onDblClick="\$('#$self->{use_ajax}').ef_document ('load', '$url');"} ; } Modified: perl/embperl/trunk/Embperl/Form/ControlMultValue.pm URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/ControlMultValue.pm?rev=1588856&r1=1588855&r2=1588856&view=diff ============================================================================== --- perl/embperl/trunk/Embperl/Form/ControlMultValue.pm (original) +++ perl/embperl/trunk/Embperl/Form/ControlMultValue.pm Mon Apr 21 07:59:38 2014 @@ -200,10 +200,10 @@ sub get_datasource_controls sub get_id_from_value { - my ($self, $value) = @_ ; + my ($self, $value, $req) = @_ ; return if (!$self -> {datasrcobj}) ; - return $self -> {datasrcobj} -> get_id_from_value ($value) ; + return $self -> {datasrcobj} -> get_id_from_value ($value, $req) ; } # --------------------------------------------------------------------------- Modified: perl/embperl/trunk/Embperl/Form/DataSource.pm URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/DataSource.pm?rev=1588856&r1=1588855&r2=1588856&view=diff ============================================================================== --- perl/embperl/trunk/Embperl/Form/DataSource.pm (original) +++ perl/embperl/trunk/Embperl/Form/DataSource.pm Mon Apr 21 07:59:38 2014 @@ -131,7 +131,7 @@ sub get_option_from_value sub get_id_from_value { - my ($self, $value) = @_ ; + my ($self, $value, $req) = @_ ; return $value ; } --------------------------------------------------------------------- To unsubscribe, e-mail: embperl-cvs-unsubscr...@perl.apache.org For additional commands, e-mail: embperl-cvs-h...@perl.apache.org