Mercurial > pub > Impl
annotate Lib/IMPL/Web/TT/Form.pm @ 134:44977efed303
Significant performance optimizations
Fixed recursion problems due converting objects to JSON
Added cache support for the templates
Added discovery feature for the web methods
| author | wizard |
|---|---|
| date | Mon, 21 Jun 2010 02:39:53 +0400 |
| parents | 0dce0470a3d8 |
| children | c5bc900eefd3 |
| rev | line source |
|---|---|
| 122 | 1 use strict; |
| 2 package IMPL::Web::TT::Form; | |
| 3 | |
| 4 use base qw(IMPL::Web::TT::Control); | |
| 5 | |
| 124 | 6 use IMPL::Class::Property; |
| 7 use IMPL::DOM::Navigator::SchemaNavigator; | |
| 8 use IMPL::DOM::Property qw(_dom); | |
| 9 | |
| 126 | 10 __PACKAGE__->PassThroughArgs; |
| 124 | 11 |
| 12 BEGIN { | |
| 13 public property base => prop_all; | |
| 14 public property schema => prop_all; | |
| 15 public property errors => prop_all; | |
| 16 public property data => prop_all; | |
| 17 } | |
| 18 | |
| 19 sub CTOR { | |
| 20 my ($this) = @_; | |
| 21 | |
| 22 $this->base($this->nodeName) unless $this->base; | |
| 23 | |
| 24 die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName) | |
| 25 unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) }; | |
| 26 | |
| 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 }); | |
| 126 | 29 |
| 30 $this->errors([]) unless $this->errors; | |
| 124 | 31 } |
| 32 | |
| 126 | 33 sub makeControlArgs{ |
| 34 my ($this,$path) = @_; | |
| 124 | 35 |
| 36 my $navi = new IMPL::DOM::Navigator::SchemaNavigator($this->schema); | |
| 126 | 37 my @path = ($this->base, split /\./,$path); |
| 124 | 38 |
| 126 | 39 $navi->NavigateName($_) or die new IMPL::InvalidArgumentException( |
| 124 | 40 "Can't find a definition for an element", |
| 41 $_, | |
| 42 $path, | |
| 126 | 43 $this->element, |
| 44 ) foreach @path; | |
| 124 | 45 |
| 46 my $schema = $navi->Current; | |
|
127
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
126
diff
changeset
|
47 my $sourceSchema = $navi->SourceSchemaNode; |
|
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
126
diff
changeset
|
48 my $queryParameter = join '/', @path; |
|
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
126
diff
changeset
|
49 shift @path; |
| 126 | 50 my $node = $this->data->selectSingleNode(@path); |
| 51 | |
| 52 my @errors; | |
| 53 | |
| 54 if ($node) { | |
| 55 @errors = grep { ( $_->Node || $_->Parent) == $node } @{$this->errors}; | |
| 56 } | |
| 57 | |
| 58 return { | |
| 59 schema => $schema, | |
|
127
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
126
diff
changeset
|
60 sourceSchema => $sourceSchema, |
| 126 | 61 errors => \@errors, |
| 62 data => $node, | |
|
127
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
126
diff
changeset
|
63 nodeValue => $node && $node->nodeValue, # small hack set a non dom class property through |
|
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
126
diff
changeset
|
64 queryParameter => $queryParameter |
| 126 | 65 }; |
| 66 } | |
| 67 | |
| 68 sub formErrors { | |
| 69 my ($this) = @_; | |
| 70 | |
|
127
0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents:
126
diff
changeset
|
71 if (my $node = $this->data ) { |
| 126 | 72 return [ |
| 73 grep { | |
| 74 ( $_->Node || $_->Parent) == $node | |
| 75 } @{$this->errors} | |
| 76 ]; | |
| 77 } else { | |
| 78 return []; | |
| 79 } | |
| 124 | 80 } |
| 81 | |
| 122 | 82 |
| 83 1; | |
| 84 | |
| 85 __END__ | |
| 86 | |
| 87 =pod | |
| 88 | |
| 89 =head1 NAME | |
| 90 | |
| 91 C<IMPL::Web::TT::Form> - Форма с элементами | |
| 92 | |
| 93 =head1 DESCRIPTION | |
| 94 | |
| 95 Является элементом управления, тоесть для своего преобразования ипользует | |
| 96 шаблон | |
| 97 | |
| 98 =cut |
