annotate Lib/IMPL/Web/TT/Form.pm @ 146:60fd224f3e3c

fixed cgi parameters processing Added parameters inflating feature Added preprocessed templates, reformatting output
author wizard
date Mon, 26 Jul 2010 03:19:06 +0400
parents bd10093bb122
children e6447ad85cb4
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;
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
8 __PACKAGE__->PassThroughArgs;
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
9
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
10 BEGIN {
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
11 public property base => prop_all;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
12 public property schema => prop_all;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
13 public property errors => prop_all;
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
14 public property data => prop_all;
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
15 public property state => prop_all;
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
16 public property formResult => prop_all;
124
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
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
22 if (my $form = $this->formResult) {
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
23 $this->base($form->{formName});
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
24 $this->errors($form->{formErrors});
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
25 $this->data($form->{formData});
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
26 $this->schema($form->{formSchema});
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
27 $this->state($form->{state});
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
28 } else {
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
29
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
30 $this->base($this->nodeName) unless $this->base;
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
31
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
32 die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName)
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
33 unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) };
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
34
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
35 die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base)
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
36 unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base });
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
37 }
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
38
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
39 $this->errors([]) unless $this->errors;
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
40 }
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
41
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
42 sub makeControlArgs{
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
43 my ($this,$path) = @_;
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
44
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
45 my $navi = new IMPL::DOM::Navigator::SchemaNavigator($this->schema);
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
46 my @path = ($this->base, split /\./,$path);
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
47
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
48 $navi->NavigateName($_) or die new IMPL::InvalidArgumentException(
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
49 "Can't find a definition for an element",
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
50 $_,
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
51 $path,
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
52 $this->element,
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
53 ) foreach @path;
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
54
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
55 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
56 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
57 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
58 shift @path;
138
c5bc900eefd3 IMPL::Web::Application: Fixed file uploading
wizard
parents: 127
diff changeset
59 my $node = $this->data ? $this->data->selectSingleNode(@path) : undef;
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
60
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
61 my @errors;
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
62
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
63 if ($node) {
144
b56ebc31bf18 Empty nodes no more created while transforming a post request to the DOM document
wizard
parents: 138
diff changeset
64 @errors = grep { ($_->Node || $_->Parent) == $node } @{$this->errors};
b56ebc31bf18 Empty nodes no more created while transforming a post request to the DOM document
wizard
parents: 138
diff changeset
65 } else {
b56ebc31bf18 Empty nodes no more created while transforming a post request to the DOM document
wizard
parents: 138
diff changeset
66 @errors = grep $_->Schema == $sourceSchema, @{$this->errors};
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
67 }
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
68
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
69 return {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
70 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
71 sourceSchema => $sourceSchema,
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
72 errors => \@errors,
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
73 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
74 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
75 queryParameter => $queryParameter
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
76 };
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
77 }
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
78
145
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
79 sub makeContent {
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
80 my ($this,$mappings) = @_;
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
81
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
82 my $formSchema = $this->schema->selectSingleNode(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base } )
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
83 or die new Exception("Cant find a schema element for the specified form", $this->base);
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
84
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
85 my $doc = $this->document;
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
86 foreach my $itemSchema ( $formSchema->content->childNodes ) {
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
87 my $itemName = $itemSchema->name;
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
88 if (my $controlClass = $mappings->{$itemName} ) {
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
89 my $contorl = $doc->CreateControl($itemName,$controlClass,$this->makeControlArgs($itemName));
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
90 $this->appendChild($contorl);
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
91 }
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
92 }
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
93 return;
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
94 }
bd10093bb122 Minor changes
wizard
parents: 144
diff changeset
95
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
96 sub formErrors {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
97 my ($this) = @_;
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
98
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
99 if (my $node = $this->data ) {
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
100 return [
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
101 grep {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
102 ( $_->Node || $_->Parent) == $node
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
103 } @{$this->errors}
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
104 ];
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
105 } else {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
106 return [];
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
107 }
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
108 }
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
109
122
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
110
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
111 1;
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
112
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
113 __END__
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
114
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
115 =pod
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
116
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
117 =head1 NAME
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
118
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
119 C<IMPL::Web::TT::Form> - Форма с элементами
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
120
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
121 =head1 DESCRIPTION
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
122
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
123 Является элементом управления, тоесть для своего преобразования ипользует
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
124 шаблон
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
125
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
126 =cut