You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl-cvs@perl.apache.org by ri...@apache.org on 2012/07/11 19:53:22 UTC

svn commit: r1360320 - in /perl/embperl/trunk/Embperl/Form/Control: datetime.pm dynctrl.pm grid.pm selectdyn.pm

Author: richter
Date: Wed Jul 11 17:53:21 2012
New Revision: 1360320

URL: http://svn.apache.org/viewvc?rev=1360320&view=rev
Log:
dynamic control for Embperl::Forms

Added:
    perl/embperl/trunk/Embperl/Form/Control/dynctrl.pm
Modified:
    perl/embperl/trunk/Embperl/Form/Control/datetime.pm
    perl/embperl/trunk/Embperl/Form/Control/grid.pm
    perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm

Modified: perl/embperl/trunk/Embperl/Form/Control/datetime.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/datetime.pm?rev=1360320&r1=1360319&r2=1360320&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/datetime.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/datetime.pm Wed Jul 11 17:53:21 2012
@@ -59,22 +59,31 @@ sub init_data
     my $time    = $fdat->{$name} ;
     return if ($time eq '' || $req -> {"ef_datetime_init_done_$name"}) ;
 
+    if ($self -> {dynamic} && ($time =~ /^\s*((?:d|m|y)(?:\+|-)?(?:\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 @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]) ;
-       } ;
+        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 ;
-	}
+        {
+        $date = $time ;
+        }
 
     $fdat->{$name} = $date ;
     $req -> {"ef_datetime_init_done_$name"} = 1 ;
@@ -95,6 +104,14 @@ sub prepare_fdat
     my $name    = $self->{name} ;
     my $date    = $fdat -> {$name} ;
     return if ($date eq '') ;
+
+    if ($self -> {dynamic} && ($date =~ /^\s*((?:d|m|y)\s*(?:\+|-)?\s*(?:\d+)?)\s*$/))
+        {
+        $fdat->{$name} = $1 ;
+        $fdat->{$name} =~ s/\s//g ;
+        return ;
+        }
+    
     
     my ($year, $mon, $day, $hour, $min, $sec) ;
     if ($date eq '*' || $date eq '.')
@@ -168,7 +185,10 @@ $]
 [$if $self -> {maxlength} $]maxlength="[+ $self->{maxlength} +]"[$endif$]
 >
 <script type="text/javascript">
-    $('#[+ $fullid +]').datepicker ({ showWeek: true }) ;
+    $('#[+ $fullid +]').datepicker ({ showWeek: true,
+                                    [$if $self -> {dynamic} $]constrainInput: false, [$endif$]
+                                    showButtonPanel: true
+                                    }) ;
 </script>
 
 
@@ -221,7 +241,16 @@ Gives the size in characters. (Default: 
 
 =head3 notime
 
-doe not display time
+does not display time
+
+=head3 dynamic
+
+allows the following values to be entered:
+
+d, m, y, d-N, d+N, m-N, m+N, y-N, y+N
+
+N is any number. This values are simply passed through and need
+to be process somewhere else.
 
 =head1 Author
 

Added: perl/embperl/trunk/Embperl/Form/Control/dynctrl.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/dynctrl.pm?rev=1360320&view=auto
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/dynctrl.pm (added)
+++ perl/embperl/trunk/Embperl/Form/Control/dynctrl.pm Wed Jul 11 17:53:21 2012
@@ -0,0 +1,202 @@
+
+###################################################################################
+#
+#   Embperl - Copyright (c) 1997-2012 Gerald Richter / ecos gmbh   www.ecos.de
+#
+#   You may distribute under the terms of either the GNU General Public
+#   License or the Artistic License, as specified in the Perl README file.
+#
+#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+#
+#   $Id$
+#
+###################################################################################
+
+package Embperl::Form::Control::dynctrl ;
+
+use strict ;
+use base 'Embperl::Form::Control' ;
+
+use Embperl::Inline ;
+
+# ----------------------------------------------------------------------------
+#
+#   creatre_ctrl - creates the dynamic control based on the current data
+#
+
+sub create_ctrl
+    {
+    my ($self, $req) = @_ ;
+    
+    my $fdat = ($req -> {form} && keys (%{$req -> {form}}) > 0)?$req -> {form}:\%Embperl::fdat ;
+    my $id   = $self -> {id} . $self -> {name} ;
+::dbg('create_control id = ', $id, ' name = ', $self -> {name}, ' value = ', $fdat -> {$self -> {name}}, $req -> {form}, \%Embperl::fdat, $fdat) ;    
+    return $req -> {"dynctrl_$id"} if ($req -> {"dynctrl_$id"}) ;
+    
+    my $ctrl  ;
+    my $ctrlattr = $self -> {ctrlattr} ;
+    if (ref $ctrlattr eq 'CODE')
+        {
+        $ctrl = &{$ctrlattr}($self, $fdat) ;
+        }
+    else
+        {
+        my $ctrl = {} ;
+        foreach my $f (keys %$ctrlattr)
+            {
+            my $val = $ctrlattr -> {$f} ;
+            if (ref $val eq 'CODE')
+                {
+                $val = &{$val}($self, $fdat) ;
+                }
+                
+            $ctrl -> {$f} = $val ;
+            }
+        }
+
+    foreach my $attr (keys %$self)
+        {
+        $ctrl -> {$attr} = $self -> {$attr} 
+                if ($attr ne 'ctrlattr' && 
+                    $attr ne 'type' && 
+                    !exists ($ctrl -> {$attr})) ;
+        }
+     
+    $ctrl -> {text} = $ctrl -> {textprefix} . $ctrl -> {text} if ($ctrl -> {textprefix}) ;
+    my $form = $self -> form ;
+    my $ctrlform = [$ctrl] ;
+    $form -> new_controls ($ctrlform, undef, undef, undef, undef, undef, undef, 1) ;
+
+    return $req -> {"dynctrl_$id"} = $ctrlform -> [0] ;
+    }
+    
+# ----------------------------------------------------------------------------
+
+sub show 
+    {
+    my $self = shift ;
+    my $ctrl = $self -> create_ctrl ($_[0]) ;
+    $ctrl -> show (@_) if ($ctrl) ;
+    }
+
+# ----------------------------------------------------------------------------
+
+sub show_control 
+    {
+    my $self = shift ;
+    my $ctrl = $self -> create_ctrl ($_[0]) ;
+    $ctrl -> show_control (@_) if ($ctrl) ;
+    }
+
+
+# ----------------------------------------------------------------------------
+
+sub show_readonly
+    {
+    my $self = shift ;
+    my $ctrl = $self -> create_ctrl ($_[0]) ;
+    $ctrl -> show_readonly (@_) if ($ctrl) ;
+    }
+
+# ----------------------------------------------------------------------------
+
+sub init_data 
+    {
+    my $self = shift ;
+    my $ctrl = $self -> create_ctrl ($_[0]) ;
+
+    $ctrl -> init_data (@_)  if ($ctrl && $ctrl -> can ('init_data'));
+    }
+
+# ----------------------------------------------------------------------------
+
+sub prepare_fdat 
+    {
+    my $self = shift ;
+    my $ctrl = $self -> create_ctrl ($_[0]) ;
+
+    $ctrl -> prepare_fdat (@_) if ($ctrl && $ctrl -> can ('prepare_fdat')) ;
+    }
+
+
+1 ;
+
+__EMBPERL__
+
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Embperl::Form::Control::dynctrl - A dynamic control which is build depending on form data inside an Embperl Form
+
+
+=head1 SYNOPSIS
+
+  { 
+  type      => 'dynctrl',
+  text      => 'blabla', 
+  name      => 'foo',
+  ctrlattr  => 
+        {
+        type => sub { my ($ctrl, $fdat) = @_ ; return $fdat{foo} },
+        size => sub { my ($ctrl, $fdat) = @_ ; return $fdat{bar} },
+        }
+  }
+
+or
+
+  { 
+  type      => 'dynctrl',
+  text      => 'blabla', 
+  name      => 'foo',
+  ctrlattr  => sub { my ($ctrl, $fdat) = @_ ; return { type => $fdat{foo}, size => $fdat{bar} },
+  }
+  
+  
+  
+=head1 DESCRIPTION
+
+Used to create a dynamic control which is build depending on form data inside an Embperl Form.
+See Embperl::Form on how to specify parameters.
+
+Use the ctrlattr parameter to specify a callback that delviers the control parameter 
+at runtime.
+
+=head2 PARAMETER
+
+=head3 type
+
+Needs to be 'dynctrl'
+
+=head3 name
+
+Specifies the name of the control
+
+=head3 text 
+
+Will be used as label for the text input control
+
+
+=head3 ctrlattr
+
+Code Referenz or hash of values and code references which returns the
+attributes for the real control.
+
+=head3 textprefix
+
+Prefix for text 
+
+=head1 Author
+
+G. Richter (richter@dev.ecos.de)
+
+=head1 See Also
+
+perl(1), Embperl, Embperl::Form
+
+

Modified: perl/embperl/trunk/Embperl/Form/Control/grid.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/grid.pm?rev=1360320&r1=1360319&r2=1360320&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/grid.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/grid.pm Wed Jul 11 17:53:21 2012
@@ -143,7 +143,7 @@ sub init_data
         $i++ ;
         }
     $fdat->{"__${name}_max"} = $i?$i:1;
-	$self -> {rowclasses} = \@rowclass ;
+	$self -> {rowclasses} ||= \@rowclass ;
 	}
 
 # ------------------------------------------------------------------------------------------
@@ -284,7 +284,7 @@ $]<table class="ef-element ef-element-wi
   </table>
   [- $self -> show_grid_title ($req)
             if ($max > $self -> {header_bottom} && !$self -> {disable_controls}) -]
-  <table id="__[+ $self -> {fullid} +]_newrow" style="display: none" class="[+ $self -> {state} +]">
+  <table id="__[+ $self -> {fullid} +]_newrow" style="display: none">
     [-
     local $req -> {epf_no_script} = 1 ;
     $self -> show_grid_table_row ($req, '%row%') ;

Modified: perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm
URL: http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm?rev=1360320&r1=1360319&r2=1360320&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/selectdyn.pm Wed Jul 11 17:53:21 2012
@@ -151,22 +151,28 @@ control_link_setup($( "#_inp_[+ $self ->
     $self -> {datasrcurl}   ||= '/epfctrl/datasrc.json?datasrc=%datasrc%' ;
      my $class = $self -> {class} ;
 $]
-<div class="ui-widget">
+[# <div class="ui-widget"> #]
 [# --- input --- #]
 <input name="_inp_[+ $name +]" [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req, "_inp_$jsname") } +] type="text"
 [$if $self -> {size} $]size="[+ $self->{size} +]"[$endif$]
 value="[+ $initval +]"
 >
+
 <input type="hidden" name="[+ $name +]" id="[+ $jsname +]" >
+[#
 <input type="hidden" name="[+ "_id_$jsname" +]" id="[+ "_id_$jsname" +]" value="[+ $self -> get_id_from_value ($fdat{$name}) +]">
+#]
 <[$if $noscript $]x-[$endif$]script type="text/javascript">
-autocomplete_setup($( "#_inp_[+ $jsname +]" ), {
-                        showurl:  '[+ do { local $escmode = 0 ; $self -> {showurl} } +]',
-                        popupurl:  '[+ do { local $escmode = 0 ; $self -> {popupurl} } +]',
-                        datasrcurl:  '[+ do { local $escmode = 0 ; $self -> {datasrcurl} } +]',
+$( "#_inp_[+ $jsname +]" ).ef_selectdyn(
+                        {
+                        show_url:  '[+ do { local $escmode = 0 ; $self -> {showurl} } +]',
+                        popup_url:  '[+ do { local $escmode = 0 ; $self -> {popupurl} } +]',
+                        datasrc_url:  '[+ do { local $escmode = 0 ; $self -> {datasrcurl} } +]',
                         datasrc:     '[+ $self->{datasrc} +]',
                         use_ajax:     '[+ $self->{use_ajax} +]',
-                        show_on_select: [+ $self->{show_on_select}?'true':'false' +]
+                        show_on_select: [+ $self->{show_on_select}?'true':'false' +],
+                        initial_id:     "[+ $self -> get_id_from_value ($fdat{$name}) +]",
+                        input_value:    $('#[+ $jsname +]')
                         }) ;
 </[$if $noscript $]x-[$endif$]script >
 



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-cvs-help@perl.apache.org