diff Lib/IMPL/Web/Application/ControllerUnit.pm @ 171:59e5fcb59d86

Исправления, изменена концепция веб-форм
author sourcer
date Mon, 06 Jun 2011 03:30:36 +0400
parents b88b7fe60aa3
children 068acfe903c3
line wrap: on
line diff
--- a/Lib/IMPL/Web/Application/ControllerUnit.pm	Tue May 24 01:11:16 2011 +0400
+++ b/Lib/IMPL/Web/Application/ControllerUnit.pm	Mon Jun 06 03:30:36 2011 +0400
@@ -72,8 +72,6 @@
 				schema => $info
 			};
 		} elsif (ref $info eq 'HASH') {
-			die new IMPL::Exception("A schema must be specified",$self,$method) unless $info->{schema};
-			
 			$info->{wrapper} = 'FormWrapper';
 			
 			$self->class_data(CONTROLLER_METHODS)->{$method} = $info;
@@ -137,13 +135,12 @@
 sub FormWrapper {
 	my ($self,$method,$action,$methodInfo) = @_;
 	
-	my $schema = $self->loadSchema($methodInfo->{schema});
+	my $schema = $methodInfo->{schema} ? $self->loadSchema($methodInfo->{schema}) : $self->unitSchema;
 	
 	my $process = $action->query->param('process') || 0;
 	my $form = $methodInfo->{form}
 		|| $action->query->param('form')
-		|| $schema->selectSingleNode('ComplexNode')->name
-			or die new IMPL::Exception('No situable form name could be determined',$self,$method);
+		|| $method;
 	
 	my %result;
 	
@@ -155,10 +152,9 @@
 	
 	$result{formName} = $form;
 	$result{formSchema} = $schema;
-	$result{formData} = $transform->Transform($action->query);
-	
 	
 	if ($process) {
+		$result{formData} = $transform->Transform($action->query);
 		$result{formErrors} = $transform->Errors->as_list;
 		if ($transform->Errors->Count) {
 			$result{state} = STATE_INVALID;
@@ -179,6 +175,14 @@
 			} 
 		}
 	} else {
+		if (my $initMethod = $methodInfo->{init}) {
+			my $unit = $self->new($action,\%result);
+			$result{formData} = $transform->Transform( $unit->$initMethod($unit->MakeParams($methodInfo)) );
+		} else {
+			$result{formData} = $transform->Transform($action->query);
+		}
+		
+		$result{formErrors} = $transform->Errors->as_list;
 		$result{state} = STATE_NEW;
 	}