package WebminUI::Section;
use WebminCore;
=head2 new WebminUI::Section(header, [columns], [title], [width])
Create a new form section, which has a header and contains some inputs
=cut
sub new
{
if (defined(&WebminUI::Theme::Section::new) &&
caller() !~ /WebminUI::Theme::Section/) {
return new WebminUI::Theme::Section(@_[1..$#_]);
}
my ($self, $header, $columns, $title, $width) = @_;
$self = { 'columns' => 4 };
bless($self);
$self->set_header($header);
$self->set_columns($columns) if (defined($columns));
$self->set_title($title) if (defined($title));
$self->set_width($width) if (defined($width));
return $self;
}
=head2 html()
Returns the HTML for this form section
=cut
sub html
{
my ($self) = @_;
my $rv;
$rv .= &ui_table_start($self->{'header'},
$self->{'width'} ? "width=$self->{'width'}" : undef,
$self->{'columns'});
foreach my $i (@{$self->{'inputs'}}) {
if (is_input($i->[1])) {
my $errs;
my @errs = $self->{'form'}->field_errors($i->[1]->get_name());
if (@errs) {
foreach my $e (@errs) {
$errs .= "
$e\n";
}
}
$rv .= &ui_table_row($i->[0], $i->[1]->html().$errs,
$i->[2]);
}
else {
$rv .= &ui_table_row($i->[0],
ref($i->[1]) ? $i->[1]->html() : $i->[1], $i->[2]);
}
}
$rv .= &ui_table_end();
return $rv;
}
=head2 add_input(label, input, [columns])
Adds some WebminUI::Input object to this form section
=cut
sub add_input
{
my ($self, $label, $input, $cols) = @_;
push(@{$self->{'inputs'}}, [ $label, $input, $cols ]);
$input->set_form($self->{'form'});
}
=head2 add_row(label, text, [columns])
Adds a non-editable row to this form section
=cut
sub add_row
{
my ($self, $label, $text, $cols) = @_;
push(@{$self->{'inputs'}}, [ $label, $text, $cols ]);
}
=head2 add_separator()
Adds some kind of separator at this point in the section
=cut
sub add_separator
{
my ($self) = @_;
push(@{$self->{'inputs'}}, [ undef, "