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