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