# HG changeset patch # User wizard # Date 1276273267 -14400 # Node ID 0dce0470a3d80f42e814ec1c7a7cd0792179864c # Parent c8dfbbdd80056b10f45b05d8df049f294ff09361 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 diff -r c8dfbbdd8005 -r 0dce0470a3d8 Lib/IMPL/Exception.pm --- 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; diff -r c8dfbbdd8005 -r 0dce0470a3d8 Lib/IMPL/Web/Application/ControllerUnit.pm --- 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; diff -r c8dfbbdd8005 -r 0dce0470a3d8 Lib/IMPL/Web/QueryHandler/PageFormat.pm --- 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 ); diff -r c8dfbbdd8005 -r 0dce0470a3d8 Lib/IMPL/Web/TT/Document.pm --- 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) = @_; diff -r c8dfbbdd8005 -r 0dce0470a3d8 Lib/IMPL/Web/TT/Form.pm --- 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