Mercurial > pub > Impl
changeset 126:c8dfbbdd8005
Several bug fixes
Forms support pre-alfa version
author | wizard |
---|---|
date | Fri, 11 Jun 2010 04:29:51 +0400 |
parents | a4b0a819bbda |
children | 0dce0470a3d8 |
files | Lib/IMPL/DOM/Schema.pm Lib/IMPL/DOM/Transform/PostToDOM.pm Lib/IMPL/Web/Application/ControllerUnit.pm Lib/IMPL/Web/TT/Control.pm Lib/IMPL/Web/TT/Form.pm |
diffstat | 5 files changed, 50 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema.pm Thu Jun 10 17:43:51 2010 +0400 +++ b/Lib/IMPL/DOM/Schema.pm Fri Jun 11 04:29:51 2010 +0400 @@ -114,7 +114,7 @@ if ( my ($schemaNode) = $this->selectNodes(sub { $_->isa('IMPL::DOM::Schema::Node') and $_[0]->name eq $node->nodeName })) { $schemaNode->Validate($node); } else { - return new IMPL::DOM::Schema::ValidationError(Message=> "A specified document doesn't match the schema"); + return new IMPL::DOM::Schema::ValidationError(Node => $node, Message=> "A specified document (%Node.nodeName%) doesn't match the schema"); } }
--- a/Lib/IMPL/DOM/Transform/PostToDOM.pm Thu Jun 10 17:43:51 2010 +0400 +++ b/Lib/IMPL/DOM/Transform/PostToDOM.pm Fri Jun 11 04:29:51 2010 +0400 @@ -63,7 +63,7 @@ sub TransformCGI { my ($this,$query) = @_; - + my $data={}; my $prefix = $this->prefix;
--- a/Lib/IMPL/Web/Application/ControllerUnit.pm Thu Jun 10 17:43:51 2010 +0400 +++ b/Lib/IMPL/Web/Application/ControllerUnit.pm Fri Jun 11 04:29:51 2010 +0400 @@ -106,7 +106,8 @@ ); $result{formSchema} = $schema; - $result{formData} = $transform->Transform($self->query); + $result{formData} = $transform->Transform($action->query); + if ($process) { $result{formErrors} = $transform->Errors->as_list; @@ -127,9 +128,13 @@ sub loadSchema { my ($self,$name) = @_; - my ($vol,$dir,$file) = File::Spec->splitpath( Class::Inspector->resolved_filename(ref $self || $self) ); - - return IMPL::DOM::Schema->LoadSchema(File::Spec->catfile($vol,$dir,$name)); + if (-f $name) { + return IMPL::DOM::Schema->LoadSchema($name); + } else { + my ($vol,$dir,$file) = File::Spec->splitpath( Class::Inspector->resolved_filename(ref $self || $self) ); + + return IMPL::DOM::Schema->LoadSchema(File::Spec->catfile($vol,$dir,$name)); + } } 1;
--- a/Lib/IMPL/Web/TT/Control.pm Thu Jun 10 17:43:51 2010 +0400 +++ b/Lib/IMPL/Web/TT/Control.pm Fri Jun 11 04:29:51 2010 +0400 @@ -22,7 +22,7 @@ # load a template $args{template} = $this->document->context->template($args{template}) if ($args{template} and not ref $args{template}); } - $this->template($args{template}) if $args{template}; + #$this->template($args{template}) if $args{template}; $this->id($this->nodeName . '-' . $nextId++); $this->controlClass($args{controlClass} || 'Control');
--- a/Lib/IMPL/Web/TT/Form.pm Thu Jun 10 17:43:51 2010 +0400 +++ b/Lib/IMPL/Web/TT/Form.pm Fri Jun 11 04:29:51 2010 +0400 @@ -7,7 +7,7 @@ use IMPL::DOM::Navigator::SchemaNavigator; use IMPL::DOM::Property qw(_dom); -__PACKAGE__->PasssThroughArgs; +__PACKAGE__->PassThroughArgs; BEGIN { public property base => prop_all; @@ -26,22 +26,53 @@ 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; } -sub createControl { - my ($this, $path, $class, $hashArgs) = @_; +sub makeControlArgs{ + my ($this,$path) = @_; my $navi = new IMPL::DOM::Navigator::SchemaNavigator($this->schema); + my @path = ($this->base, split /\./,$path); - $navi->NavigateName($_) or die new IMPL::InvalidAgrumentException( + $navi->NavigateName($_) or die new IMPL::InvalidArgumentException( "Can't find a definition for an element", $_, $path, - $this->element - ) foreach $this->base, split /\./,$path; + $this->element, + ) foreach @path; my $schema = $navi->Current; - my @errors = grep $_->Source == $navi->SourceSchemaNode + my $node = $this->data->selectSingleNode(@path); + + my @errors; + + if ($node) { + @errors = grep { ( $_->Node || $_->Parent) == $node } @{$this->errors}; + } + + return { + schema => $schema, + sourceSchema => $navi->SourceSchemaNode, + errors => \@errors, + data => $node, + formParameter => join '/', @path + }; +} + +sub formErrors { + my ($this) = @_; + + if (my $node = $this->data->selectSingleNode($this->base) ) { + return [ + grep { + ( $_->Node || $_->Parent) == $node + } @{$this->errors} + ]; + } else { + return []; + } }