changeset 138:c5bc900eefd3

IMPL::Web::Application: Fixed file uploading Minor improvements in the IMPL::Web::TT::Form
author wizard
date Thu, 01 Jul 2010 04:25:07 +0400
parents 6975cd4973d1
children 5a9f64890c31
files Lib/IMPL/Web/Application.pm Lib/IMPL/Web/Application/ControllerUnit.pm Lib/IMPL/Web/TT/Form.pm
diffstat 3 files changed, 36 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application.pm	Tue Jun 29 00:37:05 2010 +0400
+++ b/Lib/IMPL/Web/Application.pm	Thu Jul 01 04:25:07 2010 +0400
@@ -99,9 +99,13 @@
 
 use Encode;
 
+our $NO_DECODE = 0;
+
 sub param {
 	my $this = shift;
 	
+	return $this->SUPER::param(@_) if $NO_DECODE;
+	
 	if (wantarray) {
 		my @result = $this->SUPER::param(@_);
 		
@@ -114,6 +118,19 @@
 
 }
 
+sub upload {
+	my $this = shift;
+	
+	local $NO_DECODE = 1;
+	my $oldCharset = $this->charset();
+	$this->charset('ISO-8859-1');
+	
+	my $fh = $this->SUPER::upload(@_);
+	
+	$this->charset($oldCharset);
+	return $fh;
+}
+
 1;
 
 __END__
--- a/Lib/IMPL/Web/Application/ControllerUnit.pm	Tue Jun 29 00:37:05 2010 +0400
+++ b/Lib/IMPL/Web/Application/ControllerUnit.pm	Thu Jul 01 04:25:07 2010 +0400
@@ -140,6 +140,7 @@
 		$form
 	);
 	
+	$result{formName} = $form;
 	$result{formSchema} = $schema;
 	$result{formData} = $transform->Transform($action->query);
 	
--- a/Lib/IMPL/Web/TT/Form.pm	Tue Jun 29 00:37:05 2010 +0400
+++ b/Lib/IMPL/Web/TT/Form.pm	Thu Jul 01 04:25:07 2010 +0400
@@ -5,8 +5,6 @@
 
 use IMPL::Class::Property;
 use IMPL::DOM::Navigator::SchemaNavigator;
-use IMPL::DOM::Property qw(_dom);
-
 __PACKAGE__->PassThroughArgs;
 
 BEGIN {
@@ -14,19 +12,30 @@
 	public property schema => prop_all;
 	public property errors => prop_all;
 	public property data => prop_all;
+	public property state => prop_all;
+	public property formResult => prop_all;
 }
 
 sub CTOR {
 	my ($this) = @_;
 	
-	$this->base($this->nodeName) unless $this->base;
+	if (my $form = $this->formResult) {
+		$this->base($form->{formName});
+		$this->errors($form->{formErrors});
+		$this->data($form->{formData});
+		$this->schema($form->{formSchema});
+		$this->state($form->{state});
+	} else {
 	
-	die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName)
-		unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) };
-	
-	die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base)
-		unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base });
+		$this->base($this->nodeName) unless $this->base;
+		
+		die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName)
+			unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) };
 		
+		die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base)
+			unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base });
+	}
+			
 	$this->errors([]) unless $this->errors;
 }
 
@@ -47,7 +56,7 @@
 	my $sourceSchema = $navi->SourceSchemaNode;
 	my $queryParameter = join '/', @path;
 	shift @path;
-	my $node = $this->data->selectSingleNode(@path);
+	my $node = $this->data ? $this->data->selectSingleNode(@path) : undef;
 	
 	my @errors;