comparison Lib/IMPL/Web/TT/Form.pm @ 138:c5bc900eefd3

IMPL::Web::Application: Fixed file uploading Minor improvements in the IMPL::Web::TT::Form
author wizard
date Thu, 01 Jul 2010 04:25:07 +0400
parents 0dce0470a3d8
children b56ebc31bf18
comparison
equal deleted inserted replaced
137:6975cd4973d1 138:c5bc900eefd3
3 3
4 use base qw(IMPL::Web::TT::Control); 4 use base qw(IMPL::Web::TT::Control);
5 5
6 use IMPL::Class::Property; 6 use IMPL::Class::Property;
7 use IMPL::DOM::Navigator::SchemaNavigator; 7 use IMPL::DOM::Navigator::SchemaNavigator;
8 use IMPL::DOM::Property qw(_dom);
9
10 __PACKAGE__->PassThroughArgs; 8 __PACKAGE__->PassThroughArgs;
11 9
12 BEGIN { 10 BEGIN {
13 public property base => prop_all; 11 public property base => prop_all;
14 public property schema => prop_all; 12 public property schema => prop_all;
15 public property errors => prop_all; 13 public property errors => prop_all;
16 public property data => prop_all; 14 public property data => prop_all;
15 public property state => prop_all;
16 public property formResult => prop_all;
17 } 17 }
18 18
19 sub CTOR { 19 sub CTOR {
20 my ($this) = @_; 20 my ($this) = @_;
21 21
22 $this->base($this->nodeName) unless $this->base; 22 if (my $form = $this->formResult) {
23 $this->base($form->{formName});
24 $this->errors($form->{formErrors});
25 $this->data($form->{formData});
26 $this->schema($form->{formSchema});
27 $this->state($form->{state});
28 } else {
23 29
24 die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName) 30 $this->base($this->nodeName) unless $this->base;
25 unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) };
26
27 die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base)
28 unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base });
29 31
32 die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName)
33 unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) };
34
35 die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base)
36 unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base });
37 }
38
30 $this->errors([]) unless $this->errors; 39 $this->errors([]) unless $this->errors;
31 } 40 }
32 41
33 sub makeControlArgs{ 42 sub makeControlArgs{
34 my ($this,$path) = @_; 43 my ($this,$path) = @_;
45 54
46 my $schema = $navi->Current; 55 my $schema = $navi->Current;
47 my $sourceSchema = $navi->SourceSchemaNode; 56 my $sourceSchema = $navi->SourceSchemaNode;
48 my $queryParameter = join '/', @path; 57 my $queryParameter = join '/', @path;
49 shift @path; 58 shift @path;
50 my $node = $this->data->selectSingleNode(@path); 59 my $node = $this->data ? $this->data->selectSingleNode(@path) : undef;
51 60
52 my @errors; 61 my @errors;
53 62
54 if ($node) { 63 if ($node) {
55 @errors = grep { ( $_->Node || $_->Parent) == $node } @{$this->errors}; 64 @errors = grep { ( $_->Node || $_->Parent) == $node } @{$this->errors};