Author: richter
Date: Tue Jan  7 09:27:45 2014
New Revision: 1556157

URL: http://svn.apache.org/r1556157
Log:
Attachment handling in Embperl::Form

Modified:
    perl/embperl/trunk/Embperl/Form/Control/attachment.pm

Modified: perl/embperl/trunk/Embperl/Form/Control/attachment.pm
URL: 
http://svn.apache.org/viewvc/perl/embperl/trunk/Embperl/Form/Control/attachment.pm?rev=1556157&r1=1556156&r2=1556157&view=diff
==============================================================================
--- perl/embperl/trunk/Embperl/Form/Control/attachment.pm (original)
+++ perl/embperl/trunk/Embperl/Form/Control/attachment.pm Tue Jan  7 09:27:45 
2014
@@ -26,6 +26,43 @@ use strict ;    
 
 use Embperl::Inline ;
 
+use vars qw{%fdat} ;
+
+
+# 
------------------------------------------------------------------------------------------
+#
+#   init_data - daten aufteilen
+#
+
+our @divs =
+    (
+    1000 * 1000 * 1000 => 'GB',    
+    1000 * 1000 => 'MB',    
+    1000 => 'KB',    
+    1    => 'B',    
+    ) ;
+
+
+sub init_data
+    {
+    my ($self, $req, $parentctrl, $force) = @_ ;
+    
+    my $fdat  = $req -> {docdata} || \%fdat ;
+    my $name    = $self->{name} ;
+    my $val     = $fdat->{$name} ;
+    return if ($val eq '' || ($val !~ /^\d+$/)) ;
+
+    for (my $i = 0; $i < @divs; $i +=2)
+        {
+        if ($val >= $divs[$i])
+            {
+            $fdat->{$name} = int ($val /$divs[$i]) . ' ' . $divs[$i+1] ;
+            return ;
+            }
+        }
+    
+    return ;    
+    }
 
 1 ;
 
@@ -39,18 +76,15 @@ __EMBPERL__
 
 [$ sub show_control ($self, $req)
 
-my $name     = $self->{name};
-my $form     = $self -> form ;
-my $showoptions = $self -> {showoptions} ;
-my $state    = $self -> {state} ;
+my $name     = $self -> {name};
 
 $]
-<div class="[+ $state +]" [+ do { local $escmode = 0 ; $self -> 
get_std_control_attr($req) } +] _ef_attach="ef_attachment" _ef_dynid="<_id>" 
_ef_attr="[+ $name +]">
+<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req) } +] 
_ef_attach="ef_attachment" _ef_dynid="<_id>"  _ef_attr="[+ $name +]">
     <a class="ef-attachment-download" href="#">Download</a>&nbsp;  
     <a class="ef-attachment-upload" href="#">Upload</a>&nbsp;  
     <a class="ef-attachment-delete" href="#">L&ouml;schen</a>&nbsp;  
-    <input type="file" multiple style="display: none">&nbsp;
-    <span class="ef-attachment-info"></span>
+    <input type="file" multiple style="display: none" name=[+ $name +]>&nbsp;
+    <div _ef_divname="[+ $name +]" class="ef-attachment-info"></div>
 </div>
 [$ endsub $]
  
@@ -61,15 +95,12 @@ $]
 
 [$ sub show_control_readonly ($self, $req)
 
-my $name     = $self->{name};
-my $form     = $self -> form ;
-my $showoptions = $self -> {showoptions} ;
-my $state    = $self -> {state} ;
+my $name     = $self -> {name};
 
 $]
-<div class="[+ $state +]" [+ do { local $escmode = 0 ; $self -> 
get_std_control_attr($req) } +] _ef_attach="ef_attachment" _ef_dynid="<_id>" 
_ef_attr="[+ $name +]">
+<div [+ do { local $escmode = 0 ; $self -> get_std_control_attr($req) } +] 
_ef_attach="ef_attachment" _ef_dynid="<_id>" _ef_attr="[+ $name +]">
     <a class="ef-attachment-download" href="#">Download</a>&nbsp;  
-    <input type="file" multiple style="display: none">&nbsp;
-    <span class="ef-attachment-info"></span>
+    <input type="file" multiple style="display: none" name=[+ $name +]>&nbsp;
+    <div _ef_divname="[+ $name +]" class="ef-attachment-info"></div>
 </div>
 [$ endsub $]



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

Reply via email to