comparison Lib/IMPL/Web/TT/Form.pm @ 126:c8dfbbdd8005

Several bug fixes Forms support pre-alfa version
author wizard
date Fri, 11 Jun 2010 04:29:51 +0400
parents e30bdd040fe3
children 0dce0470a3d8
comparison
equal deleted inserted replaced
125:a4b0a819bbda 126:c8dfbbdd8005
5 5
6 use IMPL::Class::Property; 6 use IMPL::Class::Property;
7 use IMPL::DOM::Navigator::SchemaNavigator; 7 use IMPL::DOM::Navigator::SchemaNavigator;
8 use IMPL::DOM::Property qw(_dom); 8 use IMPL::DOM::Property qw(_dom);
9 9
10 __PACKAGE__->PasssThroughArgs; 10 __PACKAGE__->PassThroughArgs;
11 11
12 BEGIN { 12 BEGIN {
13 public property base => prop_all; 13 public property base => prop_all;
14 public property schema => prop_all; 14 public property schema => prop_all;
15 public property errors => prop_all; 15 public property errors => prop_all;
24 die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName) 24 die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName)
25 unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) }; 25 unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) };
26 26
27 die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base) 27 die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base)
28 unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base }); 28 unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base });
29
30 $this->errors([]) unless $this->errors;
29 } 31 }
30 32
31 sub createControl { 33 sub makeControlArgs{
32 my ($this, $path, $class, $hashArgs) = @_; 34 my ($this,$path) = @_;
33 35
34 my $navi = new IMPL::DOM::Navigator::SchemaNavigator($this->schema); 36 my $navi = new IMPL::DOM::Navigator::SchemaNavigator($this->schema);
37 my @path = ($this->base, split /\./,$path);
35 38
36 $navi->NavigateName($_) or die new IMPL::InvalidAgrumentException( 39 $navi->NavigateName($_) or die new IMPL::InvalidArgumentException(
37 "Can't find a definition for an element", 40 "Can't find a definition for an element",
38 $_, 41 $_,
39 $path, 42 $path,
40 $this->element 43 $this->element,
41 ) foreach $this->base, split /\./,$path; 44 ) foreach @path;
42 45
43 my $schema = $navi->Current; 46 my $schema = $navi->Current;
44 my @errors = grep $_->Source == $navi->SourceSchemaNode 47 my $node = $this->data->selectSingleNode(@path);
48
49 my @errors;
50
51 if ($node) {
52 @errors = grep { ( $_->Node || $_->Parent) == $node } @{$this->errors};
53 }
54
55 return {
56 schema => $schema,
57 sourceSchema => $navi->SourceSchemaNode,
58 errors => \@errors,
59 data => $node,
60 formParameter => join '/', @path
61 };
62 }
63
64 sub formErrors {
65 my ($this) = @_;
66
67 if (my $node = $this->data->selectSingleNode($this->base) ) {
68 return [
69 grep {
70 ( $_->Node || $_->Parent) == $node
71 } @{$this->errors}
72 ];
73 } else {
74 return [];
75 }
45 } 76 }
46 77
47 78
48 1; 79 1;
49 80