changeset 127:0dce0470a3d8

In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction added a relativeUrl function for a usage from a templates IMPL::Web::TT::Form now fully functional
author wizard
date Fri, 11 Jun 2010 20:21:07 +0400
parents c8dfbbdd8005
children 08753833173d
files Lib/IMPL/Exception.pm Lib/IMPL/Web/Application/ControllerUnit.pm Lib/IMPL/Web/QueryHandler/PageFormat.pm Lib/IMPL/Web/TT/Document.pm Lib/IMPL/Web/TT/Form.pm
diffstat 5 files changed, 36 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/Exception.pm	Fri Jun 11 04:29:51 2010 +0400
+++ b/Lib/IMPL/Exception.pm	Fri Jun 11 20:21:07 2010 +0400
@@ -118,4 +118,10 @@
     'IMPL::Exception' => sub { @_ ? @_ : "The method is deprecated" }
 );
 
+package IMPL::WrongDataException;
+our @ISA = qw(IMPL::Exception);
+our %CTOR = (
+    'IMPL::Exception' => sub { "The input data is wrong", @_ }
+);
+
 1;
--- a/Lib/IMPL/Web/Application/ControllerUnit.pm	Fri Jun 11 04:29:51 2010 +0400
+++ b/Lib/IMPL/Web/Application/ControllerUnit.pm	Fri Jun 11 20:21:07 2010 +0400
@@ -116,7 +116,18 @@
 		} else {
 			$result{state} = STATE_CORRECT;
 			my $unit = $self->new($action,\%result);
-			$result{result} = $unit->method();
+			
+			eval {
+				$result{result} = $unit->$method();
+			};
+			if (my $err = $@) {
+				$result{state} = STATE_INVALID;
+				if (eval { $err->isa(typeof IMPL::WrongDataException) } ) {
+					$result{formErrors} = $err->Args;
+				} else {
+					die $err;
+				}
+			} 
 		}
 	} else {
 		$result{state} = STATE_NEW;
--- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Fri Jun 11 04:29:51 2010 +0400
+++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Fri Jun 11 20:21:07 2010 +0400
@@ -39,11 +39,15 @@
 		}
 		local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget;
 		
-		my @path = split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
+		my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
+		
+		my @pathContainer = @path;
+		pop @pathContainer;
 		
 		$doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase );
 		$doc->AddVar( result => $nextHandler->() );
 		$doc->AddVar( absoluteUrl => sub { "$prefixRoot/$_[0]" } );
+		$doc->AddVar( relativeUrl => sub { join '/', $prefixRoot, @pathContainer,$_[0] } );
 		{
 			local $@;
 			$doc->AddVar( user => IMPL::Security::Context->current->principal );
--- a/Lib/IMPL/Web/TT/Document.pm	Fri Jun 11 04:29:51 2010 +0400
+++ b/Lib/IMPL/Web/TT/Document.pm	Fri Jun 11 20:21:07 2010 +0400
@@ -83,6 +83,12 @@
     }
 }
 
+sub resolveVar {
+	my ($this,$var) = @_;
+	
+	return $this->context->stash->get($var);
+}
+
 sub registerControlClass {
 	my ($this, $controlClass, $type, $args) = @_;
 	
--- a/Lib/IMPL/Web/TT/Form.pm	Fri Jun 11 04:29:51 2010 +0400
+++ b/Lib/IMPL/Web/TT/Form.pm	Fri Jun 11 20:21:07 2010 +0400
@@ -44,6 +44,9 @@
 	) foreach @path;
 	
 	my $schema = $navi->Current;
+	my $sourceSchema = $navi->SourceSchemaNode;
+	my $queryParameter = join '/', @path;
+	shift @path;
 	my $node = $this->data->selectSingleNode(@path);
 	
 	my @errors;
@@ -54,17 +57,18 @@
 	
 	return {
 		schema => $schema,
-		sourceSchema => $navi->SourceSchemaNode,
+		sourceSchema => $sourceSchema,
 		errors => \@errors,
 		data => $node,
-		formParameter => join '/', @path
+		nodeValue => $node && $node->nodeValue, # small hack set a non dom class property through
+		queryParameter => $queryParameter
 	};
 }
 
 sub formErrors {
 	my ($this) = @_;
 	
-	if (my $node = $this->data->selectSingleNode($this->base) ) {
+	if (my $node = $this->data ) {
 		return [
 			grep {
 				( $_->Node || $_->Parent) == $node