Added radio/checkbox groups support
This commit is contained in:
parent
f55abb267b
commit
8a6554063b
1 changed files with 55 additions and 6 deletions
|
|
@ -12,6 +12,7 @@ package WebGUI::Wobject::MailForm;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Tie::CPHash;
|
use Tie::CPHash;
|
||||||
|
use Tie::IxHash;
|
||||||
use WebGUI::Form;
|
use WebGUI::Form;
|
||||||
use WebGUI::HTMLForm;
|
use WebGUI::HTMLForm;
|
||||||
use WebGUI::Icon;
|
use WebGUI::Icon;
|
||||||
|
|
@ -162,21 +163,27 @@ sub www_editSave {
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
sub www_editField {
|
sub www_editField {
|
||||||
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
return WebGUI::Privilege::insufficient() unless (WebGUI::Privilege::canEditPage());
|
||||||
my ($output, %field, $f);
|
my ($output, %field, $f, %fieldTypes, %fieldStatus);
|
||||||
tie %field, 'Tie::CPHash';
|
tie %field, 'Tie::CPHash';
|
||||||
my %fieldStatus = ( 1 => WebGUI::International::get(4, $namespace),
|
tie %fieldTypes, 'Tie::IxHash';
|
||||||
|
|
||||||
|
%fieldStatus = ( 1 => WebGUI::International::get(4, $namespace),
|
||||||
2 => WebGUI::International::get(5, $namespace),
|
2 => WebGUI::International::get(5, $namespace),
|
||||||
3 => WebGUI::International::get(6, $namespace) );
|
3 => WebGUI::International::get(6, $namespace) );
|
||||||
|
|
||||||
my %fieldTypes = ( text => "Textbox",
|
%fieldTypes = ( text => "Textbox",
|
||||||
checkbox => "Checkbox",
|
checkbox => "Checkbox",
|
||||||
|
checkList => "Checkbox List",
|
||||||
|
radioList => "Radio Buttons List",
|
||||||
textarea => "Textarea",
|
textarea => "Textarea",
|
||||||
date => "Date",
|
date => "Date",
|
||||||
email => "Email Address",
|
email => "Email Address",
|
||||||
url => "URL",
|
url => "URL",
|
||||||
yesNo => "Yes/No",
|
yesNo => "Yes/No",
|
||||||
select => "Drop-Down Box" );
|
select => "Drop-Down Box",
|
||||||
|
);
|
||||||
|
|
||||||
|
%fieldTypes;
|
||||||
%field = WebGUI::SQL->quickHash("select * from MailForm_field where MailForm_fieldId='$session{form}{fid}'");
|
%field = WebGUI::SQL->quickHash("select * from MailForm_field where MailForm_fieldId='$session{form}{fid}'");
|
||||||
$output = helpIcon(2,$_[0]->get("namespace"));
|
$output = helpIcon(2,$_[0]->get("namespace"));
|
||||||
$output .= '<h1>'.WebGUI::International::get(20,$namespace).'</h1>';
|
$output .= '<h1>'.WebGUI::International::get(20,$namespace).'</h1>';
|
||||||
|
|
@ -192,7 +199,7 @@ sub www_editField {
|
||||||
$f->select("type",\%fieldTypes,WebGUI::International::get(23,$namespace),$type);
|
$f->select("type",\%fieldTypes,WebGUI::International::get(23,$namespace),$type);
|
||||||
$f->integer("width",WebGUI::International::get(8, $namespace),$field{width} || $_[0]->get("width") || 45);
|
$f->integer("width",WebGUI::International::get(8, $namespace),$field{width} || $_[0]->get("width") || 45);
|
||||||
$f->textarea("possibleValues",WebGUI::International::get(24,$namespace),$field{possibleValues});
|
$f->textarea("possibleValues",WebGUI::International::get(24,$namespace),$field{possibleValues});
|
||||||
$f->text("defaultValue",WebGUI::International::get(25,$namespace),$field{defaultValue});
|
$f->textarea("defaultValue",WebGUI::International::get(25,$namespace),$field{defaultValue});
|
||||||
$f->yesNo("proceed",WebGUI::International::get(15,$namespace));
|
$f->yesNo("proceed",WebGUI::International::get(15,$namespace));
|
||||||
$f->submit;
|
$f->submit;
|
||||||
$output .= $f->print;
|
$output .= $f->print;
|
||||||
|
|
@ -382,11 +389,49 @@ sub _createField {
|
||||||
tie %selectOptions, 'Tie::IxHash';
|
tie %selectOptions, 'Tie::IxHash';
|
||||||
# add an empty option if no default value is provided
|
# add an empty option if no default value is provided
|
||||||
foreach (split(/\n/, $data->{possibleValues})) {
|
foreach (split(/\n/, $data->{possibleValues})) {
|
||||||
|
s/\s+$//; # remove trailing spaces
|
||||||
$selectOptions{$_} = $_[0]->processMacros($_);
|
$selectOptions{$_} = $_[0]->processMacros($_);
|
||||||
}
|
}
|
||||||
$f->select($name, \%selectOptions, $data->{name}, [$data->{defaultValue}], "", "", "", "");
|
$f->select($name, \%selectOptions, $data->{name}, [$data->{defaultValue}], "", "", "", "");
|
||||||
last SWITCH;
|
last SWITCH;
|
||||||
};
|
};
|
||||||
|
/^checkList$/ && do {
|
||||||
|
my (%selectOptions, @defaultValues);
|
||||||
|
my $vertical = 1; # TODO: Make this configurable
|
||||||
|
$name = "field_".$data->{sequenceNumber} if ($name eq ""); # Empty fieldname not allowed
|
||||||
|
tie %selectOptions, 'Tie::IxHash';
|
||||||
|
foreach (split(/\n/, $data->{possibleValues})) {
|
||||||
|
s/\s+$//; # remove trailing spaces
|
||||||
|
$selectOptions{$_} = $_[0]->processMacros($_);
|
||||||
|
}
|
||||||
|
# put default values in array
|
||||||
|
foreach (split(/\n/, $data->{defaultValue})) {
|
||||||
|
s/\s+$//; # remove trailing spaces
|
||||||
|
push(@defaultValues, $_);
|
||||||
|
}
|
||||||
|
$f->checkList($name, \%selectOptions, $data->{name}, \@defaultValues, $vertical);
|
||||||
|
last SWITCH;
|
||||||
|
};
|
||||||
|
/^radioList$/ && do {
|
||||||
|
my (%selectOptions, @defaultValues);
|
||||||
|
my $vertical = 1; # TODO: Make this configurable
|
||||||
|
$name = "field_".$data->{sequenceNumber} if ($name eq ""); # Empty fieldname not allowed
|
||||||
|
tie %selectOptions, 'Tie::IxHash';
|
||||||
|
foreach (split(/\n/, $data->{possibleValues})) {
|
||||||
|
s/\s+$//; # remove trailing spaces
|
||||||
|
$selectOptions{$_} = $_[0]->processMacros($_);
|
||||||
|
}
|
||||||
|
# put default values in array
|
||||||
|
foreach (split(/\n/, $data->{defaultValue})) {
|
||||||
|
s/\s+$//; # remove trailing spaces
|
||||||
|
push(@defaultValues, $_);
|
||||||
|
}
|
||||||
|
$f->radioList($name, \%selectOptions, $data->{name}, \@defaultValues, $vertical);
|
||||||
|
last SWITCH;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $row = '<tr><td class="formDescription" valign="top">'.$data->{name}.'</td><td class="tableData">'.$f->printRowsOnly();
|
my $row = '<tr><td class="formDescription" valign="top">'.$data->{name}.'</td><td class="tableData">'.$f->printRowsOnly();
|
||||||
|
|
@ -456,6 +501,10 @@ sub www_send {
|
||||||
$value = ($value == 1) ? "yes" : "no";
|
$value = ($value == 1) ? "yes" : "no";
|
||||||
} elsif ($data{type} eq "checkbox") {
|
} elsif ($data{type} eq "checkbox") {
|
||||||
$value = ($value) ? "checked" : "not checked";
|
$value = ($value) ? "checked" : "not checked";
|
||||||
|
} elsif ($data{type} eq "checkList" || $data{type} eq "radioList") {
|
||||||
|
$data{name} = $urlizedName = "field_".$data{sequenceNumber} if ($urlizedName eq "");
|
||||||
|
my @values = $session{cgi}->param($urlizedName);
|
||||||
|
$value = join(", ",@values);
|
||||||
}
|
}
|
||||||
|
|
||||||
# store results
|
# store results
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue