annotate Lib/IMPL/Web/View/Metadata/FormMeta.pm @ 371:d5c8b955bf8d

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