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

Исправления, изменена концепция веб-форм
author sourcer
date Mon, 06 Jun 2011 03:30:36 +0400
parents b88b7fe60aa3
children 068acfe903c3
comparison
equal deleted inserted replaced
170:b88b7fe60aa3 171:59e5fcb59d86
70 $self->class_data(CONTROLLER_METHODS)->{$method} = { 70 $self->class_data(CONTROLLER_METHODS)->{$method} = {
71 wrapper => 'FormWrapper', 71 wrapper => 'FormWrapper',
72 schema => $info 72 schema => $info
73 }; 73 };
74 } elsif (ref $info eq 'HASH') { 74 } elsif (ref $info eq 'HASH') {
75 die new IMPL::Exception("A schema must be specified",$self,$method) unless $info->{schema};
76
77 $info->{wrapper} = 'FormWrapper'; 75 $info->{wrapper} = 'FormWrapper';
78 76
79 $self->class_data(CONTROLLER_METHODS)->{$method} = $info; 77 $self->class_data(CONTROLLER_METHODS)->{$method} = $info;
80 } else { 78 } else {
81 die new IMPL::Exception("Unsupported method information",$self,$method); 79 die new IMPL::Exception("Unsupported method information",$self,$method);
135 } 133 }
136 134
137 sub FormWrapper { 135 sub FormWrapper {
138 my ($self,$method,$action,$methodInfo) = @_; 136 my ($self,$method,$action,$methodInfo) = @_;
139 137
140 my $schema = $self->loadSchema($methodInfo->{schema}); 138 my $schema = $methodInfo->{schema} ? $self->loadSchema($methodInfo->{schema}) : $self->unitSchema;
141 139
142 my $process = $action->query->param('process') || 0; 140 my $process = $action->query->param('process') || 0;
143 my $form = $methodInfo->{form} 141 my $form = $methodInfo->{form}
144 || $action->query->param('form') 142 || $action->query->param('form')
145 || $schema->selectSingleNode('ComplexNode')->name 143 || $method;
146 or die new IMPL::Exception('No situable form name could be determined',$self,$method);
147 144
148 my %result; 145 my %result;
149 146
150 my $transform = IMPL::DOM::Transform::PostToDOM->new( 147 my $transform = IMPL::DOM::Transform::PostToDOM->new(
151 undef, 148 undef,
153 $form 150 $form
154 ); 151 );
155 152
156 $result{formName} = $form; 153 $result{formName} = $form;
157 $result{formSchema} = $schema; 154 $result{formSchema} = $schema;
158 $result{formData} = $transform->Transform($action->query);
159
160 155
161 if ($process) { 156 if ($process) {
157 $result{formData} = $transform->Transform($action->query);
162 $result{formErrors} = $transform->Errors->as_list; 158 $result{formErrors} = $transform->Errors->as_list;
163 if ($transform->Errors->Count) { 159 if ($transform->Errors->Count) {
164 $result{state} = STATE_INVALID; 160 $result{state} = STATE_INVALID;
165 } else { 161 } else {
166 $result{state} = STATE_CORRECT; 162 $result{state} = STATE_CORRECT;
177 die $err; 173 die $err;
178 } 174 }
179 } 175 }
180 } 176 }
181 } else { 177 } else {
178 if (my $initMethod = $methodInfo->{init}) {
179 my $unit = $self->new($action,\%result);
180 $result{formData} = $transform->Transform( $unit->$initMethod($unit->MakeParams($methodInfo)) );
181 } else {
182 $result{formData} = $transform->Transform($action->query);
183 }
184
185 $result{formErrors} = $transform->Errors->as_list;
182 $result{state} = STATE_NEW; 186 $result{state} = STATE_NEW;
183 } 187 }
184 188
185 return \%result; 189 return \%result;
186 } 190 }