annotate lib/IMPL/Web/View/Metadata/FormMeta.pm @ 413:af8d359ee4cc ref20150831

working on di container
author cin
date Thu, 24 Sep 2015 12:19:30 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::Web::View::Metadata::FormMeta;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4 use IMPL::lang;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 Exception => 'IMPL::Exception',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 ArgException => '-IMPL::InvalidArgumentException',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 OpException => '-IMPL::InvalidOperationException',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 SchemaNavigator => 'IMPL::DOM::Navigator::SchemaNavigator',
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 DOMNode => '-IMPL::DOM::Node'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 'IMPL::Web::View::Metadata::BaseMeta' => '@_'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 nodes => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 decl => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 schema => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 errors => PROP_RO,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 group => PROP_RO
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26 use constant {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 Meta => __PACKAGE__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 my ($this,$model,$type,$args) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 if ($args) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(decl schema nodes errors group);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 $this->$_() || die ArgException->new($_ => "The $_ is required")
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 foreach qw(schema);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 sub GetSchemaProperty {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 my ($this,$name) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 return $this->decl ? $this->decl->nodeProperty($name) || $this->schema->nodeProperty($name) : $this->schema->nodeProperty($name);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 sub template {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 shift->GetSchemaProperty('template');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 sub label {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 shift->GetSchemaProperty('label');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 sub inputType {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 shift->GetSchemaProperty('inputType');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59 sub inputValue {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 if($this->isMultiple) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 return [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 map {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65 $_ ? $_->nodeValue || $_->nodeProperty('rawValue') : undef
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 @{$this->model || []}
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 return $this->model ? $this->model->nodeValue || $this->model->nodeProperty('rawValue') : undef;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74 sub isMultiple {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76 $this->decl && $this->decl->isMultiple;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79 sub isOptional {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81 not($this->decl) || $this->decl->isOptional;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84 sub GetOwnErrors {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87 my $nodes = $this->nodes;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89 my $errors = [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
90 grep _IsOwnError($nodes,$this->decl,$_), @{$this->errors || []}
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
91 ];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
92
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
93 return $errors;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
94 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
95
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
96 sub _IsOwnError {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
97 my ($nodes,$source,$err) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
98
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
99 return 1 if ($err->node && grep($err->node == $_, @$nodes)) || (not(@$nodes) && $err->schemaNode && $err->schemaNode == $source );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
100
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
101 return 0;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
102 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
103
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
104 sub _IsErrorRelates {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
105 my ($nodes,$source,$err) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
106
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
107 # this is an own error
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
108 return 1 if _IsOwnError($nodes,$source,$err);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
109
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
110 # this error relates to the child control
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
111
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
112 return 0 unless @$nodes;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
113
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
114 for (my $n = $err->parent; $n ; $n = $n->parentNode) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
115 return 1 if grep($n == $_, @$nodes);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
116 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
117
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
118 return 0;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
119 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
120
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
121 sub PopulateProperties {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
122 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
123
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
124 my @props;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
125
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
126 # return empty list of properties in case of multiple values
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
127 return \@props if $this->isMultiple;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
128
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
129 my $navi = SchemaNavigator->new($this->schema);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
130
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
131 foreach my $decl (@{$this->schema->content->childNodes}) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
132
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
133 my $schema = $navi->NavigateName($decl->name);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
134 $navi->SchemaBack();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
135
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
136 my @nodes = $this->model && $this->model->selectNodes( sub { $_->schemaNode == $decl } );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
137
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
138 my %args = (
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
139 name => $decl->name,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
140 decl => $decl,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
141 schema => $schema,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
142 nodes => [@nodes],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
143 errors => [grep _IsErrorRelates(\@nodes,$decl,$_), @{$this->errors || []}]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
144 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
145
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
146 my ($model,$type);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
147
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
148 if ($decl->isMultiple) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
149 $model = [@nodes];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
150 $type = 'ARRAY';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
151 $args{holdingType} = $schema->type;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
152 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
153 $model = shift @nodes;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
154 $type = $schema->type;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
155 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
156
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
157 push @props, Meta->new($model,$type,\%args);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
158 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
159
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
160 return \@props;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
161 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
162
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
163 sub GetItems {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
164 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
165
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
166 die OpException->new("The operation must be performed on the container")
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
167 unless $this->isMultiple;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
168
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
169 my $i = 0;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
170
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
171 return [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
172 map $this->_GetItemMeta($_,$i++), @{$this->nodes}
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
173 ];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
174 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
175
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
176 sub GetItem {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
177 my ($this,$index) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
178
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
179 die OpException->new("The operation must be performed on the container")
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
180 unless $this->isMultiple;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
181
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
182 my $node = $this->nodes->[$index];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
183
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
184 return $this->_GetItemMeta($node,$index);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
185 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
186
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
187 sub _GetItemMeta {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
188 my ($this,$node,$index) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
189
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
190 my @nodes;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
191 push @nodes,$node if $node;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
192
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
193 return Meta->new(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
194 $node,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
195 $this->schema->type,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
196 {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
197 name => $index,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
198 schema => $this->schema,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
199 errors => [grep _IsErrorRelates([$node],$this->decl,$_), @{$this->errors ||[]} ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
200 group => $this,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
201 nodes => \@nodes
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
202 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
203 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
204 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
205
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
206 sub GetMetadataForModel {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
207 my ($self,$model,$args) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
208
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
209 $args ||= {};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
210
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
211 my $modelType = delete $args->{modelType};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
212
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
213 if($model) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
214 die ArgException->new(model => "A node is required")
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
215 unless is($model,DOMNode);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
216
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
217 $args->{decl} ||= $model->schemaNode;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
218 $args->{schema} ||= $model->schemaType;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
219 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
220
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
221 return $self->new(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
222 $model,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
223 $modelType,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
224 $args
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
225 );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
226 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
227
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
228 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
229
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
230 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
231
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
232 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
233
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
234 =head1 NAME
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
235
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
236 =head1 SYNOPSIS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
237
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
238 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
239
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
240 Расширенные метаданные модели для элементов формы, помимо стандартных свойств
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
241 сожержит в себе информацию о схеме.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
242
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
243 =head1 MEMBERS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
244
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
245 =head2 C<[get]errors>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
246
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
247 Ссылка на массив с ошибками при проверке схемы. Ошибки относятся ко всем
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
248 узлам в текущей модели, включая вложенные и т.п.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
249
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
250 =head2 C<[get]model>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
251
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
252 Ссылка на элемент документа, либо на массив с элементами для множественных
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
253 значений (C<isMultiple = true>). В том случае, когда документ был не
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
254 корректен и для не множественного элемента было передено несколько значений,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
255 данное свойство будет содержать только первое.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
256
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
257 =head2 C<[get]nodes>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
258
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
259 Ссылка на массив с узлами документа. В теории количество узлов может быть
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
260 произвольным, поскольку документ может быть некорректным, т.е. их может
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
261 быть более одного в то время, как C<isMultiple = false> или, напротив, ни
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
262 одного при C<isOptional = false>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
263
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
264 Как правило для построения формы данное свойство не требуется.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
265
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
266 =head2 C<[get]modelType>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
267
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
268 Название типа данных из схемы документа (C<< schema->name >>), если тип не имеет название, то это
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
269 C<ComplexNode> для сложных узлов и C<SimpleNode> для простых.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
270
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
271 Для моделей с множественными значениями это свойство не задано. Тип элементов
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
272 храниться в свойстве C<holdingType>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
273
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
274 =head2 C<[get]decl>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
275
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
276 Объявление элемента формы, объявление может совпадать со схемой в случае,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
277 когда это был C<SimpleNode> или C<ComplexNode>, иначе это C<Node> ссылающийся
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
278 на заранее обпределенный тип.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
279
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
280 =head2 C<[get]schema>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
281
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
282 Схема текущего элемента, C<СomlexType>, C<SimpleType>, C<ComplexNode> или
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
283 C<SimpleNode>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
284
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
285 =head2 C<[get]isOptional>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
286
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
287 Данный элемент может не иметь ни одного значения
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
288
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
289 =head2 C<[get]isMultiple>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
290
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
291 Данный элемент может иметь более одного значения. Модель с множественными
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
292 значениями является сложным элементом, в котором дочерними моделями являются
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
293 не свойства а сами элементы, в данном случае они их именами будут индексы.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
294
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
295 =begin code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
296
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
297 for(my $i=0; $i< 10; $i++) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
298 display_for($i,'template');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
299 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
300
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
301 sub display_for {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
302 my ($index,$tmpl) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
303
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
304 if ($index =~ /^\d+$/) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
305 return render($tmpl, metadata => { $meta->GetItem($index) });
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
306 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
307 return render($tmpl, metadata => { $meta->GetProperty($index) });
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
308 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
309 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
310
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
311 =end code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
312
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
313 =head2 C<GetOwnErrors()>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
314
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
315 Возвращает ошибки относящиеся к самому элементу C<model>, это принципиально
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
316 для контейнеров и в случаях, когда модель не корректна и в ней присутствуют
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
317 лишние значения.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
318
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
319 =cut