annotate Lib/IMPL/Web/View/Metadata/FormMeta.pm @ 366:935629bf80df

model metadata, in progress
author cin
date Mon, 02 Dec 2013 17:44:38 +0400
parents 7c621bb95e53
children 608e74bc309f
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
363
d67e45705be5 sync, model metadata
cin
parents: 362
diff changeset
4 use IMPL::Const qw(:prop);
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
5 use IMPL::declare {
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
6 require => {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
7 Exception => 'IMPL::Exception',
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
8 ArgException => '-IMPL::InvalidArgumentException'
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
9 },
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
10 base => [
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
11 'IMPL::Web::View::Metadata::BaseMeta' => '@_'
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
12 ],
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
13 props => [
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
14 nodes => PROP_RO,
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
15 decl => PROP_RO,
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
16 schema => PROP_RO,
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
17 errors => PROP_RO
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
18 ]
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
19 };
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
20
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
21 sub CTOR {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
22 my ($this,$provider,$model,$type,$args) = @_;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
23
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
24 if ($args) {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
25 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(decl schema nodes errors);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
26 }
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
27
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
28 $this->$_() || die ArgException->new($_ => "The $_ is required")
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
29 foreach qw(decl schema);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
30 }
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
31
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
32 sub isMultiple {
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
33 shift->decl->isMultiple;
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
34 }
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
35
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
36 sub isOptional {
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
37 shift->decl->isOptional;
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
38 }
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
39
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
40 sub GetOwnErrors {
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
41 my ($this) = @_;
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
42
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
43 my $node = undef;
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
44
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
45 $node = not($this->isMultiple) && $this->nodes ? $this->nodes->[0] : undef;
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
46
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
47 return [
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
48 grep {
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
49 ($node && $_->node && $_->node == $node) || (not($node) && $_->schema == $this->decl )
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
50 } @{$this->errors || []}
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
51 ];
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
52 }
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
53
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
54 1;
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
55
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
56 __END__
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
57
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
58 =pod
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
59
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
60 =head1 NAME
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
61
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
62 =head1 SYNOPSIS
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
63
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
64 =head1 DESCRIPTION
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
65
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
66 Расширенные метаданные модели для элементов формы, помимо стандартных свойств
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
67 сожержит в себе информацию о схеме.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
68
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
69 =head1 MEMBERS
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
70
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
71 =head2 C<[get]errors>
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
72
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
73 Ссылка на массив с ошибками при проверке схемы. Ошибки относятся ко всем
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
74 узлам в текущей модели, включая вложенные и т.п.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
75
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
76 =head2 C<[get]model>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
77
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
78 Ссылка на элемент документа, либо на массив с элементами для множественных
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
79 значений (C<isMultiple = true>). В том случае, когда документ был не
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
80 корректен и для не множественного элемента было передено несколько значений,
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
81 данное свойство будет содержать только первое.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
82
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
83 =head2 C<[get]nodes>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
84
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
85 Ссылка на массив с узлами документа. В теории количество узлов может быть
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
86 произвольным, поскольку документ может быть некорректным, т.е. их может
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
87 быть более одного в то время, как C<isMultiple = false> или, напротив, ни
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
88 одного при C<isOptional = false>.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
89
366
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
90 Как правило для построения формы данное свойство не требуется.
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
91
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
92 =head2 C<[get]modelType>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
93
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
94 Название типа данных из схемы документа (C<< schema->name >>), если тип не имеет название, то это
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
95 C<ComplexNode> для сложных узлов и C<SimpleNode> для простых.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
96
366
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
97 Для моделей с множественными значениями это свойство не задано. Тип элементов
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
98 храниться в свойстве C<holdingType>
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
99
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
100 =head2 C<[get]decl>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
101
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
102 Объявление элемента формы, объявление может совпадать со схемой в случае,
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
103 когда это был C<SimpleNode> или C<ComplexNode>, иначе это C<Node> ссылающийся
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
104 на заранее обпределенный тип.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
105
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
106 =head2 C<[get]schema>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
107
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
108 Схема текущего элемента, C<СomlexType>, C<SimpleType>, C<ComplexNode> или
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
109 C<SimpleNode>.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
110
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
111 =head2 C<[get]isOptional>
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
112
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
113 Данный элемент может не иметь ни одного значения
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
114
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
115 =head2 C<[get]isMultiple>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
116
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
117 Данный элемент может иметь более одного значения. Модель с множественными
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
118 значениями является сложным элементом, в котором дочерними моделями являются
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
119 не свойства а сами элементы, в данном случае они их именами будут индексы.
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
120
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
121 =begin code
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
122
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
123 for(my $i=0; $i< 10; $i++) {
366
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
124 display_for($i,'template');
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
125 }
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
126
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
127 sub display_for {
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
128 my ($index,$tmpl) = @_;
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
129
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
130 if ($index =~ /^\d+$/) {
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
131 return render($tmpl, meta => { $meta->GetItem($index) });
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
132 } else {
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
133 return render($tmpl, meta => { $meta->GetProperty($index) });
935629bf80df model metadata, in progress
cin
parents: 365
diff changeset
134 }
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
135 }
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
136
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
137 =end code
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
138
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
139 =head2 C<GetOwnErrors()>
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
140
365
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
141 Возвращает ошибки относящиеся к самому элементу C<model>, это принципиально
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
142 для контейнеров и в случаях, когда модель не корректна и в ней присутствуют
7c621bb95e53 working on the metadata model
sergey
parents: 364
diff changeset
143 лишние значения.
362
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
144
715b9959b207 WebView: initial work on metadata providers
cin
parents:
diff changeset
145 =cut