364
|
1 package IMPL::Web::View::Metadata::FormProvider;
|
|
2 use strict;
|
|
3
|
366
|
4 ues IMPL::lang ;
|
364
|
5 use IMPL::declare {
|
365
|
6 require => {
|
366
|
7 Meta => 'IMPL::Web::View::Metadata::FormMeta',
|
|
8
|
|
9 Exception => 'IMPL::Exception',
|
|
10 ArgException => '-IMPL::InvalidArgumentException'
|
365
|
11 },
|
364
|
12 base => [
|
|
13 'IMPL::Object' => undef
|
|
14 ]
|
|
15 };
|
|
16
|
366
|
17 sub PopulateProperties {
|
364
|
18 my ($this,$meta) = @_;
|
|
19
|
366
|
20 die ArgException->new(meta => 'A FormMeta is required')
|
|
21 unless is($meta,Meta);
|
|
22
|
|
23 my @props;
|
|
24
|
|
25 # return empty list of properties in case of multiple values
|
|
26 return \@props if $meta->isMultiple;
|
|
27
|
|
28 my $navi = SchemaNavigator->new($meta->schema);
|
|
29
|
|
30 foreach my $decl (@{$meta->schema->content->childNodes}) {
|
|
31
|
|
32 my $schema = $navi->NavigateName($decl->name);
|
|
33
|
|
34 my @nodes = $meta->model && $meta->model->selectNodes( sub { $_->schemaSource == $decl } );
|
|
35
|
|
36 my %args = (
|
|
37 name => $decl->name,
|
|
38 decl => $decl,
|
|
39 schema => $schema,
|
|
40 nodes => \@nodes,
|
|
41 errors => [grep _IsErrorRelates(\@nodes,$decl,$_), @{$meta->errors || []}]
|
|
42 );
|
|
43
|
|
44 my ($model,$type);
|
|
45
|
|
46 if ($decl->isMultiple) {
|
|
47 $model = \@nodes;
|
|
48 $type = 'ARRAY';
|
|
49 $args{holdingType} = $decl->type;
|
|
50 } else {
|
|
51 $model = shift @nodes;
|
|
52 $type = $decl->type;
|
|
53 }
|
|
54
|
|
55 push @props, Meta->new(
|
|
56 $this,
|
|
57 \@nodes,
|
|
58 $decl->type,
|
|
59 {
|
|
60 name => $decl->name,
|
|
61 schema => $schema,
|
|
62 }
|
|
63 )
|
|
64 }
|
364
|
65 }
|
|
66
|
365
|
67
|
|
68 sub _IsErrorRelates {
|
366
|
69 my ($nodes,$source,$err) = @_;
|
365
|
70
|
|
71 # this is an own error
|
366
|
72 return 1 if ($err->node && grep($err->node == $_, @$nodes)) || (not(@$nodes) && $err->schema == $source );
|
365
|
73
|
|
74 # this error relates to the child control
|
|
75
|
366
|
76 return 0 unless @$nodes;
|
365
|
77
|
|
78 for (my $n = $err->parent; $n ; $n = $n->parentNode) {
|
366
|
79 return 1 if grep($n == $_, @$nodes);
|
365
|
80 }
|
|
81
|
|
82 return 0;
|
364
|
83 }
|
|
84
|
|
85 1; |