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;
|
126
|
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 }
|
124
|
76 }
|
|
77
|
122
|
78
|
|
79 1;
|
|
80
|
|
81 __END__
|
|
82
|
|
83 =pod
|
|
84
|
|
85 =head1 NAME
|
|
86
|
|
87 C<IMPL::Web::TT::Form> - Форма с элементами
|
|
88
|
|
89 =head1 DESCRIPTION
|
|
90
|
|
91 Является элементом управления, тоесть для своего преобразования ипользует
|
|
92 шаблон
|
|
93
|
|
94 =cut |