annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
122
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
1 use strict;
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
2 package IMPL::Web::TT::Form;
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
3
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
4 use base qw(IMPL::Web::TT::Control);
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
5
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
6 use IMPL::Class::Property;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
7 use IMPL::DOM::Navigator::SchemaNavigator;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
8 use IMPL::DOM::Property qw(_dom);
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
9
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
10 __PACKAGE__->PassThroughArgs;
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
11
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
12 BEGIN {
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
13 public property base => prop_all;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
14 public property schema => prop_all;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
15 public property errors => prop_all;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
16 public property data => prop_all;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
17 }
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
18
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
19 sub CTOR {
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
20 my ($this) = @_;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
21
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
22 $this->base($this->nodeName) unless $this->base;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
23
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
24 die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName)
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
25 unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) };
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
26
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
27 die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base)
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
28 unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base });
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
29
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
30 $this->errors([]) unless $this->errors;
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
31 }
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
32
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
33 sub makeControlArgs{
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
34 my ($this,$path) = @_;
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
35
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
36 my $navi = new IMPL::DOM::Navigator::SchemaNavigator($this->schema);
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
37 my @path = ($this->base, split /\./,$path);
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
38
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
39 $navi->NavigateName($_) or die new IMPL::InvalidArgumentException(
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
40 "Can't find a definition for an element",
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
41 $_,
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
42 $path,
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
43 $this->element,
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
44 ) foreach @path;
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
45
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
46 my $schema = $navi->Current;
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
47 my $node = $this->data->selectSingleNode(@path);
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
48
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
49 my @errors;
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
50
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
51 if ($node) {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
52 @errors = grep { ( $_->Node || $_->Parent) == $node } @{$this->errors};
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
53 }
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
54
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
55 return {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
56 schema => $schema,
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
57 sourceSchema => $navi->SourceSchemaNode,
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
58 errors => \@errors,
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
59 data => $node,
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
60 formParameter => join '/', @path
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
61 };
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
62 }
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
63
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
64 sub formErrors {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
65 my ($this) = @_;
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
66
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
67 if (my $node = $this->data->selectSingleNode($this->base) ) {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
68 return [
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
69 grep {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
70 ( $_->Node || $_->Parent) == $node
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
71 } @{$this->errors}
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
72 ];
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
73 } else {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
74 return [];
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
75 }
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
76 }
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
77
122
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
78
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
79 1;
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
80
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
81 __END__
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
82
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
83 =pod
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
84
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
85 =head1 NAME
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
86
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
87 C<IMPL::Web::TT::Form> - Форма с элементами
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
88
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
89 =head1 DESCRIPTION
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
90
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
91 Является элементом управления, тоесть для своего преобразования ипользует
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
92 шаблон
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
93
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
94 =cut