Added a color picker form field type.

This commit is contained in:
JT Smith 2005-04-20 21:17:44 +00:00
parent 0ab11cae6f
commit 83cbfc0d25
7 changed files with 333 additions and 361 deletions

View file

@ -43,6 +43,7 @@ Base forms package. Eliminates some of the normal code work that goes along with
$html = WebGUI::Form::checkbox({name=>"whichOne", value=>"red"});
$html = WebGUI::Form::checkList({name=>"dayOfWeek", options=>\%days});
$html = WebGUI::Form::codearea({name=>"stylesheet"});
$html = WebGUI::Form::color({name=>"highlightColor"});
$html = WebGUI::Form::combo({name=>"fruit",options=>\%fruit});
$html = WebGUI::Form::contentType({name=>"contentType");
$html = WebGUI::Form::databaseLink();
@ -300,6 +301,33 @@ sub codearea {
return $output;
}
#-------------------------------------------------------------------
=head2 color ( hashRef )
Returns a color picker field.
=head3 name
The name field for this form element.
=head3 value
The value for this form element. This should be a scalar containing a hex color like "#000000".
=head3 defaultValue
This will be used if no value is specified.
=cut
sub color {
my $params = shift;
WebGUI::Style::setScript($session{config}{extrasURL}.'/colorPicker.js',{ type=>'text/javascript' });
return '<script type="text/javascript">initColorPicker("'.$params->{name}.'","'.($params->{value}||$params->{defaultValue}).'");</script>';
}
#-------------------------------------------------------------------
=head2 combo ( hashRef )
@ -539,9 +567,9 @@ This will be used if no value is specified. Defaults to today and now.
sub dateTime {
my $params = shift;
my $value = epochToSet($params->{value}||$params->{defaultValue},1);
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/lang/calendar-en.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar-setup.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar.js',{ type=>'text/javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/lang/calendar-en.js',{ type=>'text/javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar-setup.js',{ type=>'text/javascript' });
WebGUI::Style::setLink($session{config}{extrasURL}.'/calendar/calendar-win2k-1.css', { rel=>"stylesheet", type=>"text/css", media=>"all" });
return text({
name=>$params->{name},
@ -646,7 +674,7 @@ This will be used if no value is specified.
sub email {
my $params = shift;
WebGUI::Style::setScript($session{config}{extrasURL}.'/emailCheck.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/emailCheck.js',{ type=>'text/javascript' });
my $output .= text({
name=>$params->{name},
value=>$params->{value},
@ -953,7 +981,7 @@ sub float {
my $params = shift;
my $value = $params->{value} || 0;
my $size = $params->{size} || 11;
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
return text({
name=>$params->{name},
value=>$value,
@ -1207,7 +1235,7 @@ This will be used if no value is specified.
sub integer {
my $params = shift;
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
return text({
name=>$params->{name},
value=>$params->{value},
@ -1354,7 +1382,7 @@ This will be used if no value is specified.
sub phone {
my $params = shift;
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
my $maxLength = $params->{maxlength} || 30;
return text({
name=>$params->{name},
@ -1738,7 +1766,7 @@ This will be used if no value is specified. Defaults to now.
sub timeField {
my $params = shift;
my $value = WebGUI::DateTime::secondsToTime($params->{value}||$params->{defaultValue});
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
my $output = text({
name=>$params->{name},
value=>$value,
@ -1790,7 +1818,7 @@ This will be used if no value is specified.
sub url {
my $params = shift;
my $maxLength = $params->{maxlength} || 2048;
WebGUI::Style::setScript($session{config}{extrasURL}.'/addHTTP.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/addHTTP.js',{ type=>'text/javascript' });
return text({
name=>$params->{name},
value=>$params->{value},
@ -1933,7 +1961,7 @@ This will be used if no value is specified.
sub zipcode {
my $params = shift;
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ language=>'javascript' });
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
my $maxLength = $params->{maxlength} || 10;
return text({
name=>$params->{name},

View file

@ -36,6 +36,7 @@ This package helps in the processing of the form variables that are returned fro
$value = WebGUI::FormProcessor::checkbox("whichOne");
$value = WebGUI::FormProcessor::checkList("dayOfWeek");
$value = WebGUI::FormProcessor::codearea("snippet");
$value = WebGUI::FormProcessor::color("highlightColor");
$value = WebGUI::FormProcessor::combo("fruit");
$value = WebGUI::FormProcessor::contentType("text");
$value = WebGUI::FormProcessor::date("endDate");
@ -140,6 +141,25 @@ sub codearea {
}
#-------------------------------------------------------------------
=head2 color ( name )
Returns a hex color string like: #000000
=head3 name
The name of the form variable to retrieve.
=cut
sub color {
my $color = $session{form}{$_[0]};
return undef unless $color =~ /\#\w{6}/;
return $color;
}
#-------------------------------------------------------------------
=head2 combo ( name )

View file

@ -60,6 +60,10 @@ Package that makes HTML forms typed data and significantly reduces the code need
-name=>"stylesheet",
-label=>"Stylesheet"
);
$f->color(
-name=>"highlightColor",
-label=>"Highlight Color"
);
$f->combo(
-name=>"fruit",
-options=>\%fruit,
@ -505,6 +509,61 @@ sub codearea {
$self->{_data} .= $output;
}
#-------------------------------------------------------------------
=head2 color ( name, [, label, value, subtext, uiLevel, defaultValue ] )
Adds a hex color picker field.
=head3 name
The name field for this form element.
=head3 label
The left column label for this form row.
=head3 value
The value for this form element. Should be passed as a scalar containing a hex color like this: #000000
=head3 subtext
Extra text to describe this form element or to provide special instructions.
=head3 uiLevel
The UI level for this field. See the WebGUI developer's site for details. Defaults to "0".
=head3 defaultValue
When no other value is present, will use this.
=cut
sub color {
my ($output);
my ($self, @p) = @_;
my ($name, $label, $value, $subtext, $uiLevel, $defaultValue) = rearrange([qw(name label value subtext uiLevel defaultValue)], @p);
if (_uiLevelChecksOut($uiLevel)) {
$output = WebGUI::Form::color({
"name"=>$name,
"value"=>$value,
"defaultValue"=>$defaultValue
});
$output .= _subtext($subtext);
$output = $self->_tableFormRow($label,$output);
} else {
$output = WebGUI::Form::hidden({
"name"=>$name,
"value"=>$value,
"defaultValue",$defaultValue
});
}
$self->{_data} .= $output;
}
#-------------------------------------------------------------------
=head2 combo ( name, options [, label, value, size, multiple, extras, subtext, uiLevel, defaultValue ] )