Mercurial > pub > Impl
comparison Lib/IMPL/Web/View/Metadata/FormProvider.pm @ 366:935629bf80df
model metadata, in progress
author | cin |
---|---|
date | Mon, 02 Dec 2013 17:44:38 +0400 |
parents | 7c621bb95e53 |
children | 608e74bc309f |
comparison
equal
deleted
inserted
replaced
365:7c621bb95e53 | 366:935629bf80df |
---|---|
1 package IMPL::Web::View::Metadata::FormProvider; | 1 package IMPL::Web::View::Metadata::FormProvider; |
2 use strict; | 2 use strict; |
3 | 3 |
4 ues IMPL::lang ; | |
4 use IMPL::declare { | 5 use IMPL::declare { |
5 require => { | 6 require => { |
6 Meta => 'IMPL::Web::View::Metadata::FormMeta' | 7 Meta => 'IMPL::Web::View::Metadata::FormMeta', |
8 | |
9 Exception => 'IMPL::Exception', | |
10 ArgException => '-IMPL::InvalidArgumentException' | |
7 }, | 11 }, |
8 base => [ | 12 base => [ |
9 'IMPL::Object' => undef | 13 'IMPL::Object' => undef |
10 ] | 14 ] |
11 }; | 15 }; |
12 | 16 |
13 sub GetFormMetadata { | 17 sub PopulateProperties { |
14 my ($this,$model, $form) = @_; | 18 my ($this,$meta) = @_; |
19 | |
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 } | |
15 } | 65 } |
16 | 66 |
17 sub PopulateChildren { | |
18 my ($this,$meta) = @_; | |
19 | |
20 map Meta->new($this,), $meta->schema->content->childNodes; | |
21 } | |
22 | |
23 sub GetChild { | |
24 | |
25 } | |
26 | 67 |
27 sub _IsErrorRelates { | 68 sub _IsErrorRelates { |
28 my ($node,$source,$err) = @_; | 69 my ($nodes,$source,$err) = @_; |
29 | 70 |
30 # this is an own error | 71 # this is an own error |
31 return 1 if ($node && $err->node && $err->node == $node) || (not($node) && $err->schema == $source ); | 72 return 1 if ($err->node && grep($err->node == $_, @$nodes)) || (not(@$nodes) && $err->schema == $source ); |
32 | 73 |
33 # this error relates to the child control | 74 # this error relates to the child control |
34 | 75 |
35 return 0 unless $node; | 76 return 0 unless @$nodes; |
36 | 77 |
37 for (my $n = $err->parent; $n ; $n = $n->parentNode) { | 78 for (my $n = $err->parent; $n ; $n = $n->parentNode) { |
38 return 1 if $n == $node; | 79 return 1 if grep($n == $_, @$nodes); |
39 } | 80 } |
40 | 81 |
41 return 0; | 82 return 0; |
42 } | 83 } |
43 | 84 |