annotate Lib/IMPL/Web/View/Metadata/FormMeta.pm @ 387:4cc6cc370fb2

DOM refactoring
author sergey
date Tue, 11 Feb 2014 01:13:47 +0400
parents 0d63f5273307
children 5aff94ba842f
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 {
383
2f16f13b000c DOM localization
cin
parents: 371
diff changeset
52 shift->GetSchemaProperty('label');
371
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
387
4cc6cc370fb2 DOM refactoring
sergey
parents: 385
diff changeset
99 #TODO: review filter
371
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
100 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
101
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
102 return 0;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
103 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
104
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
105 sub _IsErrorRelates {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
106 my ($nodes,$source,$err) = @_;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
107
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
108 # this is an own error
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
109 return 1 if _IsOwnError($nodes,$source,$err);
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
110
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
111 # this error relates to the child control
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
112
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
113 return 0 unless @$nodes;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
114
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
115 for (my $n = $err->parent; $n ; $n = $n->parentNode) {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
116 return 1 if grep($n == $_, @$nodes);
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
117 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
118
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
119 return 0;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
120 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
121
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
122 sub PopulateProperties {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
123 my ($this) = @_;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
124
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
125 my @props;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
126
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
127 # return empty list of properties in case of multiple values
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
128 return \@props if $this->isMultiple;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
129
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
130 my $navi = SchemaNavigator->new($this->schema);
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
131
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
132 foreach my $decl (@{$this->schema->content->childNodes}) {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
133
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
134 my $schema = $navi->NavigateName($decl->name);
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
135 $navi->SchemaBack();
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
136
387
4cc6cc370fb2 DOM refactoring
sergey
parents: 385
diff changeset
137 my @nodes = $this->model && $this->model->selectNodes( sub { $_->schemaNode == $decl } );
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
138
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
139 my %args = (
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
140 name => $decl->name,
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
141 decl => $decl,
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
142 schema => $schema,
371
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
143 nodes => [@nodes],
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
144 errors => [grep _IsErrorRelates(\@nodes,$decl,$_), @{$this->errors || []}]
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
145 );
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
146
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
147 my ($model,$type);
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
148
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
149 if ($decl->isMultiple) {
371
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
150 $model = [@nodes];
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
151 $type = 'ARRAY';
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
152 $args{holdingType} = $schema->type;
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
153 } else {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
154 $model = shift @nodes;
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
155 $type = $schema->type;
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
156 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
157
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
158 push @props, Meta->new($model,$type,\%args);
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
159 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
160
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
161 return \@props;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
162 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
163
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
164 sub GetItems {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
165 my ($this) = @_;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
166
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
167 die OpException->new("The operation must be performed on the container")
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
168 unless $this->isMultiple;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
169
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
170 my $i = 0;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
171
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
172 return [
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
173 map $this->_GetItemMeta($_,$i++), @{$this->nodes}
367
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
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
177 sub GetItem {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
178 my ($this,$index) = @_;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
179
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
180 die OpException->new("The operation must be performed on the container")
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
181 unless $this->isMultiple;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
182
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
183 my $node = $this->nodes->[$index];
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
184
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
185 return $this->_GetItemMeta($node,$index);
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
186 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
187
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
188 sub _GetItemMeta {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
189 my ($this,$node,$index) = @_;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
190
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
191 my @nodes;
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
192 push @nodes,$node if $node;
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
193
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
194 return Meta->new(
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
195 $node,
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
196 $this->schema->type,
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
197 {
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
198 name => $index,
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
199 schema => $this->schema,
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
200 errors => [grep _IsErrorRelates([$node],$this->decl,$_), @{$this->errors ||[]} ],
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
201 group => $this,
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
202 nodes => \@nodes
367
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 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
206
371
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
207 sub GetMetadataForModel {
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
208 my ($self,$model,$args) = @_;
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
209
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
210 $args ||= {};
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
211
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
212 my $modelType = delete $args->{modelType};
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
213
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
214 if($model) {
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
215 die ArgException->new(model => "A node is required")
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
216 unless is($model,DOMNode);
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
217
385
sergey
parents: 383
diff changeset
218 $args->{decl} ||= $model->schemaNode;
sergey
parents: 383
diff changeset
219 $args->{schema} ||= $model->schemaType;
371
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
220 }
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
221
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
222 return $self->new(
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
223 $model,
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
224 $modelType,
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
225 $args
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
226 );
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
227 }
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
228
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
229 1;
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
230
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
231 __END__
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
232
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
233 =pod
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
234
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
235 =head1 NAME
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
236
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
237 =head1 SYNOPSIS
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
238
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
239 =head1 DESCRIPTION
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
240
365
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
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
244 =head1 MEMBERS
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
245
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
246 =head2 C<[get]errors>
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
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
251 =head2 C<[get]model>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
252
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
253 Ссылка на элемент документа, либо на массив с элементами для множественных
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
254 значений (C<isMultiple = true>). В том случае, когда документ был не
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
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
258 =head2 C<[get]nodes>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
259
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
260 Ссылка на массив с узлами документа. В теории количество узлов может быть
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
261 произвольным, поскольку документ может быть некорректным, т.е. их может
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
262 быть более одного в то время, как C<isMultiple = false> или, напротив, ни
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
263 одного при C<isOptional = false>.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
264
366
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
265 Как правило для построения формы данное свойство не требуется.
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
266
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
267 =head2 C<[get]modelType>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
268
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
269 Название типа данных из схемы документа (C<< schema->name >>), если тип не имеет название, то это
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
270 C<ComplexNode> для сложных узлов и C<SimpleNode> для простых.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
271
366
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
272 Для моделей с множественными значениями это свойство не задано. Тип элементов
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
273 храниться в свойстве C<holdingType>
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
274
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
275 =head2 C<[get]decl>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
276
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
277 Объявление элемента формы, объявление может совпадать со схемой в случае,
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
278 когда это был C<SimpleNode> или C<ComplexNode>, иначе это C<Node> ссылающийся
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
279 на заранее обпределенный тип.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
280
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
281 =head2 C<[get]schema>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
282
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
283 Схема текущего элемента, C<СomlexType>, C<SimpleType>, C<ComplexNode> или
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
284 C<SimpleNode>.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
285
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
286 =head2 C<[get]isOptional>
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
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
290 =head2 C<[get]isMultiple>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
291
365
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
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
296 =begin code
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
297
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
298 for(my $i=0; $i< 10; $i++) {
366
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
299 display_for($i,'template');
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
300 }
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
301
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
302 sub display_for {
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
303 my ($index,$tmpl) = @_;
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
304
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
305 if ($index =~ /^\d+$/) {
371
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
306 return render($tmpl, metadata => { $meta->GetItem($index) });
366
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
307 } else {
371
d5c8b955bf8d refactoring
cin
parents: 368
diff changeset
308 return render($tmpl, metadata => { $meta->GetProperty($index) });
366
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
309 }
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
310 }
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
311
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
312 =end code
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
313
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
314 =head2 C<GetOwnErrors()>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
315
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
316 Возвращает ошибки относящиеся к самому элементу C<model>, это принципиально
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
317 для контейнеров и в случаях, когда модель не корректна и в ней присутствуют
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
318 лишние значения.
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
319
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
320 =cut