annotate Lib/IMPL/Web/TT/Form.pm @ 138:c5bc900eefd3

IMPL::Web::Application: Fixed file uploading Minor improvements in the IMPL::Web::TT::Form
author wizard
date Thu, 01 Jul 2010 04:25:07 +0400
parents 0dce0470a3d8
children b56ebc31bf18
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) {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
64 @errors = grep { ( $_->Node || $_->Parent) == $node } @{$this->errors};
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
65 }
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
66
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
67 return {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
68 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
69 sourceSchema => $sourceSchema,
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
70 errors => \@errors,
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
71 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
72 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
73 queryParameter => $queryParameter
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
74 };
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
75 }
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
76
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
77 sub formErrors {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
78 my ($this) = @_;
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
79
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
80 if (my $node = $this->data ) {
126
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
81 return [
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
82 grep {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
83 ( $_->Node || $_->Parent) == $node
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
84 } @{$this->errors}
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
85 ];
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
86 } else {
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
87 return [];
c8dfbbdd8005 Several bug fixes
wizard
parents: 124
diff changeset
88 }
124
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
89 }
e30bdd040fe3 IMPL::Web::TT::Form concept
wizard
parents: 122
diff changeset
90
122
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 1;
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 __END__
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
95
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
96 =pod
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
97
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
98 =head1 NAME
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
99
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
100 C<IMPL::Web::TT::Form> - Форма с элементами
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
101
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
102 =head1 DESCRIPTION
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
103
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
104 Является элементом управления, тоесть для своего преобразования ипользует
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
105 шаблон
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
106
a7efb3117295 Fixed bug in IMPL::DOM::Navigator::selectNodes
wizard
parents:
diff changeset
107 =cut