changeset 124:e30bdd040fe3

IMPL::Web::TT::Form concept
author wizard
date Thu, 10 Jun 2010 02:45:59 +0400
parents 1d7e370a91fa
children a4b0a819bbda
files Lib/IMPL/DOM/Node.pm Lib/IMPL/DOM/Schema/ComplexType.pm Lib/IMPL/DOM/Schema/SimpleNode.pm Lib/IMPL/DOM/Schema/SimpleType.pm Lib/IMPL/Web/TT/Form.pm _test/Test/DOM/Node.pm
diffstat 6 files changed, 92 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Node.pm	Wed Jun 09 17:53:12 2010 +0400
+++ b/Lib/IMPL/DOM/Node.pm	Thu Jun 10 02:45:59 2010 +0400
@@ -40,7 +40,9 @@
         weaken($this->{$document});
     }
     
-    $this->{$_propertyMap} = \%args;
+    while ( my ($key,$value) = each %args ) {
+    	$this->nodeProperty($key,$value);
+    }
 }
 
 sub insertNode {
--- a/Lib/IMPL/DOM/Schema/ComplexType.pm	Wed Jun 09 17:53:12 2010 +0400
+++ b/Lib/IMPL/DOM/Schema/ComplexType.pm	Thu Jun 10 02:45:59 2010 +0400
@@ -18,6 +18,7 @@
         $args{minOccur} = 0;
         $args{maxOccur} = 'unbounded';
         $args{name} ||= 'ComplexType';
+        delete @args{qw(nativeType messageWrongType)};
         %args
     }
 );
--- a/Lib/IMPL/DOM/Schema/SimpleNode.pm	Wed Jun 09 17:53:12 2010 +0400
+++ b/Lib/IMPL/DOM/Schema/SimpleNode.pm	Thu Jun 10 02:45:59 2010 +0400
@@ -12,7 +12,12 @@
 }
 
 our %CTOR = (
-    'IMPL::DOM::Schema::Node' => sub {my %args = @_; $args{nodeName} ||= 'SimpleNode'; %args}
+    'IMPL::DOM::Schema::Node' => sub {
+    	my %args = @_;
+    	$args{nodeName} ||= 'SimpleNode';
+    	delete @args{qw(inflator messageInflateError)};
+    	%args
+    }
 );
 
 sub CTOR {
--- a/Lib/IMPL/DOM/Schema/SimpleType.pm	Wed Jun 09 17:53:12 2010 +0400
+++ b/Lib/IMPL/DOM/Schema/SimpleType.pm	Thu Jun 10 02:45:59 2010 +0400
@@ -18,6 +18,7 @@
         $args{minOccur} = 0;
         $args{maxOccur} = 'unbounded';
         $args{name} ||= 'SimpleType';
+        delete @args{qw(nativeType messageWrongType)};
         %args
     }
 );
--- a/Lib/IMPL/Web/TT/Form.pm	Wed Jun 09 17:53:12 2010 +0400
+++ b/Lib/IMPL/Web/TT/Form.pm	Thu Jun 10 02:45:59 2010 +0400
@@ -3,6 +3,47 @@
 
 use base qw(IMPL::Web::TT::Control);
 
+use IMPL::Class::Property;
+use IMPL::DOM::Navigator::SchemaNavigator;
+use IMPL::DOM::Property qw(_dom);
+
+__PACKAGE__->PasssThroughArgs;
+
+BEGIN {
+	public property base => prop_all;
+	public property schema => prop_all;
+	public property errors => prop_all;
+	public property data => prop_all;
+}
+
+sub CTOR {
+	my ($this) = @_;
+	
+	$this->base($this->nodeName) unless $this->base;
+	
+	die new IMPL::InvalidArgumentException('A schema is required for a form',$this->nodeName)
+		unless eval { $this->schema->isa( typeof IMPL::DOM::Schema ) };
+	
+	die new IMPL::InvalidOperationException('Can\'t find a form definition in a schema',$this->nodeName,$this->base)
+		unless $this->schema->selectNodes(sub { $_->nodeName eq 'ComplexNode' and $_->name eq $this->base });
+}
+
+sub createControl {
+	my ($this, $path, $class, $hashArgs) = @_;
+	
+	my $navi = new IMPL::DOM::Navigator::SchemaNavigator($this->schema);
+	
+	$navi->NavigateName($_) or die new IMPL::InvalidAgrumentException(
+		"Can't find a definition for an element",
+		$_,
+		$path,
+		$this->element
+	) foreach $this->base, split /\./,$path;
+	
+	my $schema = $navi->Current;
+	my @errors = grep $_->Source == $navi->SourceSchemaNode
+}
+
 
 1;
 
--- a/_test/Test/DOM/Node.pm	Wed Jun 09 17:53:12 2010 +0400
+++ b/_test/Test/DOM/Node.pm	Thu Jun 10 02:45:59 2010 +0400
@@ -153,6 +153,46 @@
 	} and failed "Setting a private property successfull";
 };
 
+test createNodeWithProps => sub {
+	my $uuid = 'entity_76fd98b9e7a';
+	my $name = 'Vergon 6';
+	my $systemName = 'entity_vergon_6';
+	
+	my $node = Test::DOM::TypedNode->new(
+		nodeName => 'TestNode',
+		uuid => $uuid,
+		name => $name,
+		systemName => $systemName 
+	);
+	
+	failed "Failed to get dynamic property 'uuid'" unless $node->nodeProperty('uuid') eq $uuid;
+	failed "Failed to get property 'name' through nodeProperty method" unless $node->nodeProperty('name') eq $name;
+	failed "Failed to get property name directly" unless $node->name eq $name;
+};
+
+test listNodePredefinedProps => sub {
+	my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
+	
+	my @props = $node->listProperties;
+	my @expected = qw(name _private);
+	
+	failed "Got wrong list of props", @props unless cmparray(\@props,\@expected);
+};
+
+test listNodeAllProps => sub {
+	my $node = Test::DOM::TypedNode->new(
+		nodeName => 'TestNode',
+		uuid => 'ade58f98b', # dynamic
+		name => 'noname', # predefined
+		systemName => 'no sys' # not visible to DOM
+	);
+	
+	my @props = $node->listProperties;
+	my @expected = qw(name _private uuid); # systemName is not a DOM prop
+	
+	failed "Got wrong list of props", @props unless cmparray(\@props,\@expected);
+};
+
 package Test::DOM::TypedNode;
 use base qw(IMPL::DOM::Node);
 use IMPL::Class::Property;