migrated forms system to use WebGUI::Pluggable
This commit is contained in:
parent
1b4022205a
commit
3f62be51ec
4 changed files with 29 additions and 47 deletions
|
|
@ -22,6 +22,7 @@ use WebGUI::Asset;
|
|||
use WebGUI::Asset::RichEdit;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Pluggable;
|
||||
use WebGUI::Utility;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -64,14 +65,12 @@ sub AUTOLOAD {
|
|||
my $name = ucfirst((split /::/, $AUTOLOAD)[-1]);
|
||||
my $session = shift;
|
||||
my @params = @_;
|
||||
my $cmd = "use WebGUI::Form::".$name;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
$session->errorHandler->error("Couldn't compile form control: ".$name.". Root cause: ".$@);
|
||||
return;
|
||||
}
|
||||
my $class = "WebGUI::Form::".$name;
|
||||
return $class->new($session,@params)->toHtml;
|
||||
my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$name, "new", [ $session, @params ]) };
|
||||
if ($@) {
|
||||
$session->errorHandler->error($@);
|
||||
return;
|
||||
}
|
||||
return $control->toHtml;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ package WebGUI::FormValidator;
|
|||
|
||||
use strict qw(vars subs);
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::Pluggable;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -70,14 +71,12 @@ sub AUTOLOAD {
|
|||
|
||||
my $name = ucfirst((split /::/, $AUTOLOAD)[-1]);
|
||||
$params = {name=>$params} if ref ($params) ne "HASH";
|
||||
my $cmd = "use WebGUI::Form::".$name;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error("Couldn't compile form control: ".$name.". Root cause: ".$@);
|
||||
return;
|
||||
}
|
||||
my $class = "WebGUI::Form::".$name;
|
||||
return $class->new($self->session, $params)->getValueFromPost(@args);
|
||||
my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$name, "new", [ $self->session, $params ]) };
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error($@);
|
||||
return;
|
||||
}
|
||||
return $control->getValueFromPost(@args);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use CGI::Util qw(rearrange);
|
|||
use strict qw(vars refs);
|
||||
use WebGUI::Form;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Pluggable;
|
||||
use WebGUI::Utility;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -63,7 +64,8 @@ sub _uiLevelChecksOut {
|
|||
my $self = shift;
|
||||
if ($_[0] <= $self->session->user->profileField("uiLevel")) {
|
||||
return 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -77,20 +79,18 @@ Dynamically creates functions on the fly for all the different form control type
|
|||
=cut
|
||||
|
||||
sub AUTOLOAD {
|
||||
our $AUTOLOAD;
|
||||
our $AUTOLOAD;
|
||||
my $self = shift;
|
||||
my $name = ucfirst((split /::/, $AUTOLOAD)[-1]);
|
||||
my %params = @_;
|
||||
my $name = ucfirst((split /::/, $AUTOLOAD)[-1]);
|
||||
my %params = @_;
|
||||
$params{uiLevelOverride} ||= $self->{_uiLevelOverride};
|
||||
$params{rowClass} ||= $self->{_class};
|
||||
my $cmd = "use WebGUI::Form::".$name;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error("Couldn't compile form control: ".$name.". Root cause: ".$@);
|
||||
return;
|
||||
}
|
||||
my $class = "WebGUI::Form::".$name;
|
||||
$self->{_data} .= $class->new($self->session,%params)->toHtmlWithWrapper;
|
||||
my $control = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$name, "new", [ $self->session, %params ]) };
|
||||
if ($@) {
|
||||
$self->session->errorHandler->error($@);
|
||||
return;
|
||||
}
|
||||
$self->{_data} .= $control->toHtmlWithWrapper;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use WebGUI::Asset;
|
|||
use WebGUI::Asset::Wobject::Folder;
|
||||
use WebGUI::Form::Group;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Pluggable;
|
||||
use WebGUI::Storage::Image;
|
||||
use WebGUI::Utility;
|
||||
|
||||
|
|
@ -47,26 +48,9 @@ sub www_formHelper {
|
|||
my $class = "WebGUI::Form::".$form->get("class");
|
||||
my $sub = $form->get("sub");
|
||||
return "ERROR" unless (defined $sub && defined $class);
|
||||
|
||||
# Load the form helper class
|
||||
my $load = "use ".$class;
|
||||
eval($load);
|
||||
my $output = eval { WebGUI::Pluggable::instanciate($class, "www_".$sub, [$session]) };
|
||||
if ($@) {
|
||||
$session->errorHandler->error("Couldn't load form helper class $class because $@");
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
# Make sure the subroutine exists
|
||||
my $command = $class->can('www_'.$sub);
|
||||
if (!$command) {
|
||||
$session->errorHandler->error("Could not execute form helper: Couldn't find subroutine www_$sub via class $class");
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
# Run the subroutine
|
||||
my $output = eval { $command->($session) };
|
||||
if ($@) {
|
||||
$session->errorHandler->error("Couldn't execute form helper ${class}::www_${sub} because $@");
|
||||
$session->errorHandler->error($@);
|
||||
return "ERROR";
|
||||
}
|
||||
return $output;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue