package HTML::Mason::Commands;
use strict;
use vars qw($m $r);
my $_escape = \&HTML::Mason::Parser::_escape_perl_expression;
my $mk_time_field = sub {
my ($p) = @_;
$m->out('
') unless $p->{compact};
};
HTML::Mason::Component::FileBased->new
(
'code'=>sub {
my %ARGS;
if (@_ % 2 == 0) { %ARGS = @_ } else { die "Odd number of parameters passed to component expecting name/value pairs" }
my $widget = (!exists $ARGS{'widget'} ? die "no value sent for required parameter 'widget'" : $ARGS{'widget'});
my $base_name = (!exists $ARGS{'base_name'} ? die "no value sent for required parameter 'base_name'" : $ARGS{'base_name'});
my $default_current = (!exists $ARGS{'default_current'} ? die "no value sent for required parameter 'default_current'" : $ARGS{'default_current'});
my $year = (!exists $ARGS{'year'} ? '' : $ARGS{'year'});
my $mon = (!exists $ARGS{'mon'} ? '' : $ARGS{'mon'});
my $day = (!exists $ARGS{'day'} ? '' : $ARGS{'day'});
my $hour = (!exists $ARGS{'hour'} ? '' : $ARGS{'hour'});
my $min = (!exists $ARGS{'min'} ? '' : $ARGS{'min'});
my $formName = (!exists $ARGS{'formName'} ? "forms[0]" : $ARGS{'formName'});
my $indent = (!exists $ARGS{'indent'} ? undef : $ARGS{'indent'});
my $useTable = (!exists $ARGS{'useTable'} ? 0 : $ARGS{'useTable'});
my $compact = (!exists $ARGS{'compact'} ? undef : $ARGS{'compact'});
my $disp = (!exists $ARGS{'disp'} ? '' : $ARGS{'disp'});
my $_out = $m->current_sink;
$m->debug_hook($m->current_comp->path) if (%DB::);
# Keep this time widget with this base name distict from others on the page.
my $sub_widget = "$widget.$base_name";
my $s = get_state_data($sub_widget);
my $js;
my $agent = $m->comp("/widgets/util/detectAgent.mc");
my $cw = 80;
my $cellWidth = "width=$cw";
my $cellsDisplayed = 0;
if ($compact) { $useTable = 0 };
$indent = $useTable ? FIELD_INDENT + 3 : 0 unless defined $indent;
$indent -= 7 if ($agent->{browser} eq "Netscape");
# Set some default values for the time if necessary.
if ($default_current) {
my @t = localtime;
$s->{'year'} ||= $t[5] + 1900;
$s->{'mon'} ||= $t[4] + 1;
$s->{'day'} ||= $t[3];
$s->{'hour'} ||= $t[2];
$s->{'min'} ||= $t[1];
}
my @mon_names = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my @month = map { [$_,$mon_names[$_-1]] } ('01'..'12');
if ($year && $mon && $day ) {
$js = ' onChange="';
$js .= "setDays('".$base_name."_year', '".$base_name."_mon', '".$base_name."_day', this)\"";
}
$_out->('
');
$m->out(q{
}) if ($useTable);
# Print out a display label if necessary
if ($disp && !$compact) {
$m->out(qq{
}) if ($useTable);
$m->out(qq{$disp: });
$m->out(qq{
}) if ($useTable);
} else {
$m->out(qq{
}) if ($useTable);
}
if (!$useTable) {$compact = 1};
#-- Month Select
if ($mon) {
$mk_time_field->({'base' => $base_name.'_mon',
'default' => sprintf('%02d', $s->{'mon'} || 0),
'label' => 'Month',
'vals' => \@month,
'width' => $cellWidth,
'compact' => $compact});
$cellsDisplayed++;
}
#-- Day Select
if ($day) {
$mk_time_field->({'base' => $base_name.'_day',
'default' => $s->{'day'},
'label' => 'Day',
'vals' => $day,
'width' => $cellWidth,
'compact' => $compact});
$cellsDisplayed++;
}
#-- Year Select
if ($year) {
$mk_time_field->({'base' => $base_name.'_year',
'default' => $s->{'year'},
'label' => 'Year',
'vals' => $year,
'width' => $cellWidth,
'compact' => $compact});
$cellsDisplayed++;
}
#-- Hour Select
if ($hour) {
$mk_time_field->({'base' => $base_name.'_hour',
'default' => $s->{'hour'},
'label' => 'Hour',
'vals' => $hour,
'width' => $cellWidth,
'compact' => $compact});
$cellsDisplayed++;
}
#-- Minute Select
if ($min) {
$mk_time_field->({'base' => $base_name.'_min',
'default' => $s->{'min'},
'label' => 'Minute',
'vals' => $min,
'width' => $cellWidth,
'compact' => $compact});
$cellsDisplayed++;
}
# End the table unless this is a compact listing.
unless ($compact) {
# make a cell to use the remaining space, so Netscape can do the right thing
$m->out("