adding the new form system
This commit is contained in:
parent
fe0d968d87
commit
7d95169b38
26 changed files with 2160 additions and 1073 deletions
|
|
@ -39,6 +39,8 @@
|
|||
- fix [ 1240316 ] Doc erro in Folder template thumbnail => thumbnail.url
|
||||
- The Navigation template variable "unfolded_page_loop" was removed a long
|
||||
time ago, but the documentation was never updated until now.
|
||||
- Created a new pluggable form control backend. See migration.txt for
|
||||
details.
|
||||
|
||||
|
||||
6.6.5
|
||||
|
|
|
|||
|
|
@ -397,3 +397,33 @@ a slight impact on the WebGUI::ErrorHandler API. Although there are many
|
|||
changes, the only thing anyone should notice is that fatalError() was renamed
|
||||
to fatal().
|
||||
|
||||
|
||||
5.18 Form API Changed
|
||||
|
||||
In 6.7 we made the form controls pluggable so that new ones can be added
|
||||
without changing the core code at all. This change is mostly transparent
|
||||
unless you're still using the ancient deprecated WebGUI::HTMLForm syntax that
|
||||
allows you to pass in form control properties as arrays like this:
|
||||
|
||||
my $f = WebGUI::HTMLForm->new;
|
||||
$f->text("nameGoesHere","value goes here","label goes here");
|
||||
|
||||
Instead you should be using something like this:
|
||||
|
||||
$f->text(
|
||||
name=>"nameGoesHere",
|
||||
value=>"Value Goes Here",
|
||||
label=>"Label goes here"
|
||||
);
|
||||
|
||||
Note you can pass in the parameters as either a hash reference or a hash and
|
||||
the param names can be tagged or not. Here are examples:
|
||||
|
||||
$f->text(-name=>"nameGoesHere");
|
||||
$f->text({-name=>"nameGoesHere"});
|
||||
$f->text(name=>"nameGoesHere");
|
||||
$f->text({name=>"nameGoesHere"});
|
||||
|
||||
See WebGUI::HTMLForm and WebGUI::Form::Control for additional information.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -387,7 +387,11 @@ sub editUserSettingsForm {
|
|||
-value=>$session{setting}{webguiPasswordRecovery},
|
||||
-label=>WebGUI::International::get(6,'AuthWebGUI')
|
||||
);
|
||||
$f->textarea("webguiRecoverPasswordEmail",WebGUI::International::get(134),$session{setting}{webguiRecoverPasswordEmail});
|
||||
$f->textarea(
|
||||
-name=>"webguiRecoverPasswordEmail",
|
||||
-label=>WebGUI::International::get(134),
|
||||
-value=>$session{setting}{webguiRecoverPasswordEmail}
|
||||
);
|
||||
$f->yesNo(
|
||||
-name=>"webguiValidateEmail",
|
||||
-value=>$session{setting}{webguiValidateEmail},
|
||||
|
|
|
|||
|
|
@ -39,47 +39,26 @@ Base forms package. Eliminates some of the normal code work that goes along with
|
|||
|
||||
use WebGUI::Form;
|
||||
|
||||
$html = WebGUI::Form::asset({value=>$assetId});
|
||||
$html = WebGUI::Form::button({value=>"Click me!", extras=>qq|onclick="alert('Aaaaggggghhh!!!')"|});
|
||||
$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();
|
||||
$html = WebGUI::Form::date({name=>"endDate", value=>$endDate});
|
||||
$html = WebGUI::Form::dateTime({name=>"begin", value=>$begin});
|
||||
$html = WebGUI::Form::email({name=>"emailAddress"});
|
||||
$html = WebGUI::Form::fieldType({name=>"fieldType");
|
||||
$html = WebGUI::Form::file({name=>"image"});
|
||||
$html = WebGUI::Form::formFooter();
|
||||
$html = WebGUI::Form::formHeader();
|
||||
$html = WebGUI::Form::filterContent({value=>"javascript"});
|
||||
$html = WebGUI::Form::float({name=>"distance"});
|
||||
$html = WebGUI::Form::group({name=>"groupToPost"});
|
||||
$html = WebGUI::Form::hidden({name=>"wid",value=>"55"});
|
||||
$html = WebGUI::Form::hiddenList({name=>"wid",value=>"55",options=>\%options});
|
||||
$html = WebGUI::Form::HTMLArea({name=>"description"});
|
||||
$html = WebGUI::Form::integer({name=>"size"});
|
||||
$html = WebGUI::Form::interval({name=>"timeToLive", interval=>12, units=>"hours"});
|
||||
$html = WebGUI::Form::password({name=>"identifier"});
|
||||
$html = WebGUI::Form::phone({name=>"cellPhone"});
|
||||
$html = WebGUI::Form::radio({name=>"whichOne", value=>"red"});
|
||||
$html = WebGUI::Form::radioList({name="dayOfWeek", options=>\%days});
|
||||
$html = WebGUI::Form::selectList({name=>"dayOfWeek", options=>\%days, value=>\@array"});
|
||||
$html = WebGUI::Form::submit();
|
||||
$html = WebGUI::Form::template({name=>"templateId"});
|
||||
$html = WebGUI::Form::text({name=>"firstName"});
|
||||
$html = WebGUI::Form::textarea({name=>"emailMessage"});
|
||||
$html = WebGUI::Form::timeField({name=>"begin", value=>$begin});
|
||||
$html = WebGUI::Form::url({name=>"homepage"});
|
||||
$html = WebGUI::Form::yesNo({name=>"happy"});
|
||||
$html = WebGUI::Form::zipcode({name=>"workZip"});
|
||||
|
||||
$html = WebGUI::Form::anyFieldType(%properties);
|
||||
|
||||
Example:
|
||||
|
||||
$html = WebGUI::Form::text(%properties);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
All of the functions in this package accept the input of a hash reference containing the parameters to populate the form element. These functions are available from this package:
|
||||
These functions are available from this package:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 AUTOLOAD ()
|
||||
|
||||
Dynamically creates functions on the fly for all the different form control types.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -90,7 +69,7 @@ sub AUTOLOAD {
|
|||
my $cmd = "use WebGUI::Form::".$name;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::error("Couldn't compile form field: ".$name.". Root cause: ".$@);
|
||||
WebGUI::ErrorHandler::error("Couldn't compile form control: ".$name.". Root cause: ".$@);
|
||||
return undef;
|
||||
}
|
||||
my $class = "WebGUI::Form::".$name;
|
||||
|
|
@ -127,480 +106,6 @@ sub _fixTags {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 asset ( hashref )
|
||||
|
||||
Returns an asset picker control.
|
||||
|
||||
=head3 value
|
||||
|
||||
The asset ID assigned to this control.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of this field. Defaults to "asset".
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
If no value is specified, use this value.
|
||||
|
||||
=head3 class
|
||||
|
||||
Limit options to a specific class type such as "WebGUI::Asset::Wobject::Article"
|
||||
|
||||
=head3 extras
|
||||
|
||||
Assign extra things like javascript events to this form element.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
sub asset {
|
||||
my $params = shift;
|
||||
my $value = defined($params->{value}) ? $params->{value} : $params->{defaultValue};
|
||||
my $name = $params->{name} || "asset";
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($value) || WebGUI::Asset->getRoot;
|
||||
return hidden({
|
||||
name=>$name,
|
||||
extras=>'id="'.$name.'" '.$params->{extras},
|
||||
value=>$asset->getId
|
||||
})
|
||||
.text({
|
||||
name=>$name."_display",
|
||||
extras=>'id="'.$name."_display".'" readonly="1"',
|
||||
value=>$asset->get("title")
|
||||
})
|
||||
.button({
|
||||
value=>"...",
|
||||
extras=>'onclick="window.open(\''.$asset->getUrl("op=formAssetTree&classLimiter=".$params->{class}."&formId=".$name).'\',\'assetPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"'
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 button ( hashRef )
|
||||
|
||||
Returns a button. Use it in combination with scripting code to make the button perform an action.
|
||||
|
||||
=head3 value
|
||||
|
||||
The button text for this submit button. Defaults to "save".
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onClick="alert(\'You've just pushed me !\')"'
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified.
|
||||
|
||||
=cut
|
||||
|
||||
sub button {
|
||||
my $params = shift;
|
||||
my $value = $params->{value} || $params->{defaultValue} || WebGUI::International::get(62);
|
||||
$value = _fixQuotes($value);
|
||||
return '<input type="button" value="'.$value.'" '.$params->{extras}.' />';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 checkbox ( hashRef )
|
||||
|
||||
Returns a checkbox form element.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 checked
|
||||
|
||||
If you'd like this box to be defaultly checked, set this to "1".
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value for this form element.
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified. Defaults to 1.
|
||||
|
||||
=cut
|
||||
|
||||
sub checkbox {
|
||||
my $params = shift;
|
||||
my $checkedText = ' checked="1"' if ($params->{checked});
|
||||
my $value = $params->{value} || $params->{defaultValue} || 1;
|
||||
return '<input type="checkbox" name="'.$params->{name}.'" value="'.$value.'"'.$checkedText.' '.$params->{extras}.' />';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 checkList ( hashRef )
|
||||
|
||||
Returns checkbox list.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 options
|
||||
|
||||
The list of options for this list. Should be passed as a hash reference.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value(s) for this form element. This should be passed as an array reference.
|
||||
|
||||
=head3 vertical
|
||||
|
||||
If set to "1" the radio button elements will be laid out horizontally. Defaults to "0".
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified. Should be passed as an array reference.
|
||||
|
||||
=cut
|
||||
|
||||
sub checkList {
|
||||
my $params = shift;
|
||||
my ($output, $checked, $key, $item);
|
||||
my $values = $params->{value} || $params->{defaultValue};
|
||||
foreach $key (keys %{$params->{options}}) {
|
||||
$checked = 0;
|
||||
foreach $item (@{$values}) {
|
||||
if ($item eq $key) {
|
||||
$checked = 1;
|
||||
}
|
||||
}
|
||||
$output .= checkbox({
|
||||
name=>$params->{name},
|
||||
value=>$key,
|
||||
extras=>$params->{extras},
|
||||
checked=>$checked
|
||||
});
|
||||
$output .= ${$params->{options}}{$key};
|
||||
if ($params->{vertical}) {
|
||||
$output .= "<br />\n";
|
||||
} else {
|
||||
$output .= " \n";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
sub codearea {
|
||||
my $params = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/TabFix.js',{type=>"text/javascript"});
|
||||
$params->{extras} = 'style="width: 99%; min-width: 440px; height: 400px" onkeypress="return TabFix_keyPress(event)" onkeydown="return TabFix_keyDown(event)"';
|
||||
my $output = textarea($params);
|
||||
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 )
|
||||
|
||||
Returns a select list and a text field. If the text box is filled out it will have a value stored in "name"_new.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 options
|
||||
|
||||
The list of options for the select list. Should be passed as a hash reference.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value(s) for this form element. This should be passed as an array reference.
|
||||
|
||||
=head3 size
|
||||
|
||||
The number of characters tall this form element should be. Defaults to "1".
|
||||
|
||||
=head3 multiple
|
||||
|
||||
A boolean value for whether this select list should allow multiple selections. Defaults to "0".
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified. Should be passed as an array reference.
|
||||
|
||||
=cut
|
||||
|
||||
sub combo {
|
||||
my $params = shift;
|
||||
$params->{options}->{''} = '['.WebGUI::International::get(582).']';
|
||||
$params->{options}->{_new_} = WebGUI::International::get(581).'->';
|
||||
my $output = selectList({
|
||||
name=>$params->{name},
|
||||
options=>$params->{options},
|
||||
value=>$params->{value} || $params->{defaultValue},
|
||||
multiple=>$params->{multiple},
|
||||
extras=>$params->{extras}
|
||||
});
|
||||
my $size = $session{setting}{textBoxSize}-5;
|
||||
$output .= text({name=>$params->{name}."_new",size=>$size});
|
||||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 contentType ( hashRef )
|
||||
|
||||
Returns a content type select list field. This is usually used to help tell WebGUI how to treat posted content.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 types
|
||||
|
||||
An array reference of field types to be displayed. The types are "mixed", "html", "code", and "text". Defaults to all.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value for this form element.
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified. Defaults to "mixed".
|
||||
|
||||
=cut
|
||||
|
||||
sub contentType {
|
||||
my $params = shift;
|
||||
my (%hash, $output, $type);
|
||||
tie %hash, 'Tie::IxHash';
|
||||
# NOTE: What you are about to see is bad code. Do not attempt this
|
||||
# without adult supervision. =) It was done this way because a huge
|
||||
# if/elsif construct executes much more quickly than a bunch of
|
||||
# unnecessary database hits.
|
||||
my @types = qw(mixed html code text);
|
||||
$params->{types} = \@types unless ($params->{types});
|
||||
foreach $type (@{$params->{types}}) {
|
||||
if ($type eq "text") {
|
||||
$hash{text} = WebGUI::International::get(1010);
|
||||
} elsif ($type eq "mixed") {
|
||||
$hash{mixed} = WebGUI::International::get(1008);
|
||||
} elsif ($type eq "code") {
|
||||
$hash{code} = WebGUI::International::get(1011);
|
||||
} elsif ($type eq "html") {
|
||||
$hash{html} = WebGUI::International::get(1009);
|
||||
}
|
||||
}
|
||||
return selectList({
|
||||
options=>\%hash,
|
||||
name=>$params->{name},
|
||||
value=>[$params->{value}],
|
||||
extras=>$params->{extras},
|
||||
defaultValue=>[$params->{defaultValue}]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 databaseLink ( hashRef )
|
||||
|
||||
Returns a select list of database links.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element. Defaults to "databaseLinkId".
|
||||
|
||||
=head3 value
|
||||
|
||||
The unique identifier for the selected template.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified. Defaults to 0 (the WebGUI database).
|
||||
|
||||
=cut
|
||||
|
||||
sub databaseLink {
|
||||
my $params = shift;
|
||||
my $value = $params->{value} || $params->{defaultValue} || 0;
|
||||
my $name = $params->{name} || "databaseLinkId";
|
||||
return selectList({
|
||||
name=>$name,
|
||||
options=>WebGUI::DatabaseLink::getList(),
|
||||
value=>[$value]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 date ( hashRef )
|
||||
|
||||
Returns a date field.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default date. Pass as an epoch value. Defaults to today.
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 size
|
||||
|
||||
The number of characters wide this form element should be. There should be no reason for anyone to specify this.
|
||||
|
||||
=head3 noDate
|
||||
|
||||
By default a date is placed in the "value" field. Set this to "1" to turn off the default date.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified. Defaults to today.
|
||||
|
||||
=cut
|
||||
|
||||
sub date {
|
||||
my $params = shift;
|
||||
my $value = epochToSet($params->{value}||$params->{defaultValue}) unless ($params->{noDate} && $params->{value} eq '');
|
||||
my $size = $params->{size} || 10;
|
||||
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},
|
||||
value=>$value,
|
||||
size=>$size,
|
||||
extras=>'id="'.$params->{name}.'Id" '.$params->{extras},
|
||||
maxlength=>10
|
||||
}) . '<script type="text/javascript">
|
||||
Calendar.setup({
|
||||
inputField : "'.$params->{name}.'Id",
|
||||
ifFormat : "%Y-%m-%d",
|
||||
showsTime : false,
|
||||
timeFormat : "12",
|
||||
mondayFirst : false
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 dateTime ( hashRef )
|
||||
|
||||
Returns a date/time field.
|
||||
|
||||
=head3 name
|
||||
|
||||
The the base name for this form element. This form element actually returns two values under different names. They are name_date and name_time.
|
||||
|
||||
=head3 value
|
||||
|
||||
The date and time. Pass as an epoch value. Defaults to today and now.
|
||||
|
||||
=head3 extras
|
||||
|
||||
Extra parameters to add to the date/time form element such as javascript or stylesheet information.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified. Defaults to today and now.
|
||||
|
||||
=cut
|
||||
|
||||
sub dateTime {
|
||||
my $params = shift;
|
||||
my $value = epochToSet($params->{value}||$params->{defaultValue},1);
|
||||
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},
|
||||
value=>$value,
|
||||
size=>19,
|
||||
extras=>'id="'.$params->{name}.'Id" '.$params->{extras},
|
||||
maxlength=>19
|
||||
}) . '<script type="text/javascript">
|
||||
Calendar.setup({
|
||||
inputField : "'.$params->{name}.'Id",
|
||||
ifFormat : "%Y-%m-%d %H:%M:%S",
|
||||
showsTime : true,
|
||||
timeFormat : "12",
|
||||
mondayFirst : false
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -652,53 +157,6 @@ sub dynamicField {
|
|||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 email ( hashRef )
|
||||
|
||||
Returns an email address field.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value for this form element.
|
||||
|
||||
=head3 maxlength
|
||||
|
||||
The maximum number of characters to allow in this form element.
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 size
|
||||
|
||||
The number of characters wide this form element should be. There should be no reason for anyone to specify this.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified.
|
||||
|
||||
=cut
|
||||
|
||||
sub email {
|
||||
my $params = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/emailCheck.js',{ type=>'text/javascript' });
|
||||
my $output .= text({
|
||||
name=>$params->{name},
|
||||
value=>$params->{value},
|
||||
size=>$params->{size},
|
||||
extras=>' onChange="emailCheck(this.value)" '.$params->{extras},
|
||||
defaultValue=>$params->{defaultValue}
|
||||
});
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -1072,35 +530,6 @@ sub group {
|
|||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 hidden ( hashRef )
|
||||
|
||||
Returns a hidden field.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value for this form element.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified.
|
||||
|
||||
=head3 extras
|
||||
|
||||
Add extra things like ids and javascript event handlers.
|
||||
|
||||
=cut
|
||||
|
||||
sub hidden {
|
||||
my $params = shift;
|
||||
return '<input type="hidden" name="'.$params->{name}.'" value="'._fixQuotes(_fixMacros(_fixSpecialCharacters($params->{value}))).'" '.$params->{extras}.' />'."\n";
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -1546,78 +975,6 @@ sub radioList {
|
|||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 selectList ( hashRef )
|
||||
|
||||
Returns a select list field.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 options
|
||||
|
||||
The list of options for this select list. Should be passed as a hash reference.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value(s) for this form element. This should be passed as an array reference.
|
||||
|
||||
=head3 size
|
||||
|
||||
The number of characters tall this form element should be. Defaults to "1".
|
||||
|
||||
=head3 multiple
|
||||
|
||||
A boolean value for whether this select list should allow multiple selections. Defaults to "0".
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 sortByValue
|
||||
|
||||
A boolean value for whether or not the values in the options hash should be sorted.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified. Should be passed as an array reference.
|
||||
|
||||
=cut
|
||||
|
||||
sub selectList {
|
||||
my $params = shift;
|
||||
my ($output, $key, $item, $size, $multiple);
|
||||
$size = $params->{size} || 1;
|
||||
$multiple = ' multiple="1"' if ($params->{multiple});
|
||||
$output = '<select name="'.$params->{name}.'" size="'.$size.'" '.$params->{extras}.$multiple.'>';
|
||||
my $values = $params->{value} || $params->{defaultValue};
|
||||
my %options;
|
||||
tie %options, 'Tie::IxHash';
|
||||
if ($params->{sortByValue}) {
|
||||
foreach my $optionKey (sort {"\L${$params->{options}}{$a}" cmp "\L${$params->{options}}{$b}" } keys %{$params->{options}}) {
|
||||
$options{$optionKey} = ${$params->{options}}{$optionKey};
|
||||
}
|
||||
} else {
|
||||
%options = %{$params->{options}};
|
||||
}
|
||||
foreach $key (keys %options) {
|
||||
$output .= '<option value="'.$key.'"';
|
||||
foreach $item (@{$values}) {
|
||||
if ($item eq $key) {
|
||||
$output .= ' selected="1"';
|
||||
}
|
||||
}
|
||||
$output .= '>'.${$params->{options}}{$key}.'</option>';
|
||||
}
|
||||
$output .= '</select>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 submit ( hashRef )
|
||||
|
|
@ -1703,100 +1060,6 @@ sub template {
|
|||
});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 text ( hashRef )
|
||||
|
||||
Returns a text input field.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value for this form element.
|
||||
|
||||
=head3 maxlength
|
||||
|
||||
The maximum number of characters to allow in this form element.
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 size
|
||||
|
||||
The number of characters wide this form element should be. There should be no reason for anyone to specify this.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified.
|
||||
|
||||
=cut
|
||||
|
||||
sub text {
|
||||
my $params = shift;
|
||||
my $value = _fixSpecialCharacters($params->{value}||$params->{defaultValue});
|
||||
$value = _fixQuotes($value);
|
||||
$value = _fixMacros($value);
|
||||
my $maxLength = $params->{maxlength} || 255;
|
||||
my $size = $params->{size} || $session{setting}{textBoxSize} || 30;
|
||||
return '<input type="text" name="'.$params->{name}.'" value="'.$value.'" size="'.
|
||||
$size.'" maxlength="'.$maxLength.'" '.$params->{extras}.' />';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 textarea ( hashRef )
|
||||
|
||||
Returns a text area field.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value for this form element.
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 wrap
|
||||
|
||||
The method for wrapping text in the text area. Defaults to "virtual". There should be almost no reason to specify this.
|
||||
|
||||
=head3 rows
|
||||
|
||||
The number of characters tall this form element should be. There should be no reason for anyone to specify this.
|
||||
|
||||
=head3 columns
|
||||
|
||||
The number of characters wide this form element should be. There should be no reason for anyone to specify this.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified.
|
||||
|
||||
=cut
|
||||
|
||||
sub textarea {
|
||||
my $params = shift;
|
||||
my $wrap = $params->{wrap} || "virtual";
|
||||
my $rows = $params->{rows} || $session{setting}{textAreaRows} || 5;
|
||||
my $columns = $params->{columns} || $session{setting}{textAreaCols} || 50;
|
||||
my $value = _fixSpecialCharacters($params->{value} || $params->{defaultValue});
|
||||
$value = _fixTags($value);
|
||||
$value = _fixMacros($value);
|
||||
return '<textarea name="'.$params->{name}.'" cols="'.$columns.'" rows="'.$rows.'" wrap="'.
|
||||
$wrap.'" '.$params->{extras}.'>'.$value.'</textarea>';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -1994,55 +1257,6 @@ sub yesNo {
|
|||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 zipcode ( hashRef )
|
||||
|
||||
Returns a zip code field.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name field for this form element.
|
||||
|
||||
=head3 value
|
||||
|
||||
The default value for this form element.
|
||||
|
||||
=head3 maxlength
|
||||
|
||||
The maximum number of characters to allow in this form element.
|
||||
|
||||
=head3 extras
|
||||
|
||||
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
|
||||
|
||||
'onChange="this.form.submit()"'
|
||||
|
||||
=head3 size
|
||||
|
||||
The number of characters wide this form element should be. There should be no reason for anyone to specify this.
|
||||
|
||||
=head3 defaultValue
|
||||
|
||||
This will be used if no value is specified.
|
||||
|
||||
=cut
|
||||
|
||||
sub zipcode {
|
||||
my $params = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
|
||||
my $maxLength = $params->{maxlength} || 10;
|
||||
return text({
|
||||
name=>$params->{name},
|
||||
maxlength=>$maxLength,
|
||||
extras=>'onKeyUp="doInputCheck(this.form.'.$params->{name}.',\'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- \')" '.$params->{extras},
|
||||
value=>$params->{value},
|
||||
size=>$params->{size},
|
||||
defaultValue=>$params->{defaultValue}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
|||
372
lib/WebGUI/Form/Control.pm
Normal file
372
lib/WebGUI/Form/Control.pm
Normal file
|
|
@ -0,0 +1,372 @@
|
|||
package WebGUI::Form::Control;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::Control
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Base class for all form field objects. Never use this class directly.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use base 'WebGUI::Form::Control';
|
||||
|
||||
...your methods here...
|
||||
|
||||
Subclasses will look like this:
|
||||
|
||||
use WebGUI::Form::subclass;
|
||||
my $obj = WebGUI::Form::subclass->new(%params);
|
||||
|
||||
my $html = $obj->toHtml;
|
||||
my $html = $obj->toHtmlAsHidden;
|
||||
my $tableRows = $obj->toHtmlWithWrapper;
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are available via this package.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
Defines the schema or parameters for a form field.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
An array reference containing a hash of hashes of parameter names and their definitions.
|
||||
|
||||
Example:
|
||||
|
||||
[{
|
||||
myParam=>{
|
||||
defaultValue=>undef
|
||||
}
|
||||
}]
|
||||
|
||||
By default all form fields have the following parameters:
|
||||
|
||||
=head4 name
|
||||
|
||||
The field name.
|
||||
|
||||
=head4 value
|
||||
|
||||
The starting value for the field.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
If no starting value is specified, this will be used instead.
|
||||
|
||||
=head4 extras
|
||||
|
||||
Add extra attributes to the form tag like
|
||||
|
||||
onmouseover='doSomething()'
|
||||
|
||||
=head4 label
|
||||
|
||||
A text label that will be displayed if toHtmlWithWrapper() is called.
|
||||
|
||||
=head4 uiLevel
|
||||
|
||||
The UI Level that the user must meet or exceed if this field should be displayed with toHtmlWithWrapper() is called.
|
||||
|
||||
=head4 uiLevelOverride
|
||||
|
||||
An identifier that will be grabbed from the config file to determine the uiLevel. If the uiLevelOverride is "Article" and the name is "title" then the entry in the config file would look like:
|
||||
|
||||
Article_uiLevel = title => 5
|
||||
|
||||
=head4 subtext
|
||||
|
||||
A text string that will be appended after the field when toHtmlWithWrapper() is called.
|
||||
|
||||
=head4 labelClass
|
||||
|
||||
A stylesheet class assigned to the label with toHtmlWithWrapper() is called. Defaults to "formDescription".
|
||||
|
||||
=head4 fieldClass
|
||||
|
||||
A stylesheet class assigned to wrapper the field when toHtmlWithWrapper() is called. Defaults to "tableData".
|
||||
|
||||
=head4 rowClass
|
||||
|
||||
A stylesheet class assigned to each label/field pair.
|
||||
|
||||
=head4 hoverHelp
|
||||
|
||||
A text string that will pop up when the user hovers over the label when toHtmlWithWrapper() is called. This string should indicate how to use the field and is usually tied into the help system.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
name=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
value=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
extras=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
defaultValue=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
label=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
uiLevel=>{
|
||||
defaultValue=>1
|
||||
},
|
||||
uiLevelOverride=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
labelClass=>{
|
||||
defaultValue=>"formDescription"
|
||||
},
|
||||
fieldClass=>{
|
||||
defaultValue=>"tableData"
|
||||
},
|
||||
rowClass=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
hoverHelp=>{
|
||||
defaultValue=>undef
|
||||
},
|
||||
subtext=>{
|
||||
defaultValue=>undef
|
||||
}
|
||||
});
|
||||
return $definition;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 fixMacros ( string )
|
||||
|
||||
Returns the string having converted all macros in the string to HTML entities so that they won't be processed my the macro engine, but instead will be displayed.
|
||||
|
||||
=head3 string
|
||||
|
||||
The string to search for macros in.
|
||||
|
||||
=cut
|
||||
|
||||
sub fixMacros {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
$value =~ s/\^/\&\#94\;/g;
|
||||
return $value;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 fixQuotes ( string )
|
||||
|
||||
Returns the string having replaced quotes with HTML entities. This is important so not to screw up HTML attributes which use quotes as delimiters.
|
||||
|
||||
=head3 string
|
||||
|
||||
The string to search for quotes in.
|
||||
|
||||
=cut
|
||||
|
||||
sub fixQuotes {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
$value =~ s/\"/\"\;/g;
|
||||
return $value;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 fixSpecialCharacters ( string )
|
||||
|
||||
Returns a string having converted any characters that have special meaning in HTML to HTML entities. Currently the only character is ampersand.
|
||||
|
||||
=head3 string
|
||||
|
||||
The string to search for special characters in.
|
||||
|
||||
=cut
|
||||
|
||||
sub fixSpecialCharacters {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
$value =~ s/\&/\&\;/g;
|
||||
return $value;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 fixTags ( string )
|
||||
|
||||
Returns a string having converted HTML tags into HTML entities. This is useful when you have HTML that you need to render inside of a <textarea> for instance.
|
||||
|
||||
=head3 string
|
||||
|
||||
The string to search for HTML tags in.
|
||||
|
||||
=cut
|
||||
|
||||
sub fixTags {
|
||||
my $self = shift;
|
||||
my $value = shift;
|
||||
$value =~ s/\</\<\;/g;
|
||||
$value =~ s/\>/\>\;/g;
|
||||
return $value;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Retrieves a value from a form GET or POST and returns it. If the value comes back as undef, this method will return the defaultValue instead.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $formValue = $session{cgi}->param($self->{name});
|
||||
if (defined $formValue) {
|
||||
return $formValue;
|
||||
} else {
|
||||
return $self->{defaultValue};
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( parameters )
|
||||
|
||||
Constructor. Creates a new form field object.
|
||||
|
||||
=head3 parameters
|
||||
|
||||
Accepts any parameters specified by the definition() method. This parameter set can be specified by either a hash or hash reference, and can be tagged or not. Here are examples:
|
||||
|
||||
my $obj = $class->new({ name=>"this", value=>"that"});
|
||||
my $obj = $class->new({ -name=>"this", -value=>"that"});
|
||||
my $obj = $class->new(name=>"this", value=>"that");
|
||||
my $obj = $class->new(-name=>"this", -value=>"that");
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my %raw;
|
||||
# deal with a hash reference full of properties
|
||||
if (ref $_[0] eq "HASH") {
|
||||
%raw = %{$_[0]};
|
||||
} else {
|
||||
%raw = @_;
|
||||
}
|
||||
my %params;
|
||||
# Ensure that overrides overwrite the previously defined definition of a field
|
||||
my @reversedDefinitions = reverse @{$class->definition};
|
||||
foreach my $definition (@reversedDefinitions) {
|
||||
foreach my $fieldName (keys %{$definition}) {
|
||||
$params{$fieldName} = $raw{$fieldName} || $raw{"-".$fieldName} || $definition->{$fieldName}{defaultValue};
|
||||
}
|
||||
}
|
||||
unless (exists $params{value}) {
|
||||
$params{value} = $params{defaultValue};
|
||||
}
|
||||
WebGUI::ErrorHandler::debug($class);
|
||||
bless \%params, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders the form field to HTML. This method should be overridden by all subclasses.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
return $self->{value};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtmlAsHidden ( )
|
||||
|
||||
Renders the form field to HTML as a hidden field rather than whatever field type it was supposed to be.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
return '<input type="hidden" name="'.$self->{name}.'" value="'.$self->fixQuotes($self->fixMacros($self->fixSpecialCharacters($self->{value}))).'" />'."\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtmlWithWrapper ( )
|
||||
|
||||
Renders the form field to HTML as a table row complete with labels, subtext, hoverhelp, etc.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtmlWithWrapper {
|
||||
my $self = shift;
|
||||
if ($self->{uiLevel} <= $session{user}{uiLevel}
|
||||
|| ( $session{config}{$self->{uiLevelOverride}}{$self->{name}}
|
||||
&& $session{config}{$self->{uiLevelOverride}}{$self->{name}} <= $session{user}{uiLevel}))
|
||||
{
|
||||
my $rowClass = $self->{rowClass};
|
||||
$rowClass = qq| class="$rowClass" | if($self->{rowClass});
|
||||
my $labelClass = $self->{labelClass};
|
||||
$labelClass = qq| class="$labelClass" | if($self->{labelClass});
|
||||
my $fieldClass = $self->{fieldClass};
|
||||
$fieldClass = qq| class="$fieldClass" | if($self->{fieldClass});
|
||||
my $hoverHelp = $self->{hoverHelp};
|
||||
$hoverHelp =~ s/\r/ /g;
|
||||
$hoverHelp =~ s/\n/ /g;
|
||||
$hoverHelp =~ s/&/& amp;/g;
|
||||
$hoverHelp =~ s/>/& gt;/g;
|
||||
$hoverHelp =~ s/</& lt;/g;
|
||||
$hoverHelp =~ s/&/&/g;
|
||||
$hoverHelp =~ s/>/>/g;
|
||||
$hoverHelp =~ s/</</g;
|
||||
$hoverHelp =~ s/"/"/g;
|
||||
$hoverHelp =~ s/'/\\'/g;
|
||||
$hoverHelp =~ s/^\s+//;
|
||||
$hoverHelp = qq| onmouseover="return escape('$hoverHelp')"| if ($hoverHelp);
|
||||
my $subtext = $self->{subtext};
|
||||
$subtext = qq| <span class="formSubtext">$subtext</span>| if ($subtext);
|
||||
return '<tr'.$rowClass.'><td'.$labelClass.$hoverHelp.' valign="top" style="width: 25%;">'.$self->{label}.'</td><td valign="top"'.$fieldClass.' style="width: 75%;">'.$self->toHtml.$subtext."</td></tr>\n";
|
||||
} else {
|
||||
return $self->toHtmlAsHidden;
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
106
lib/WebGUI/Form/asset.pm
Normal file
106
lib/WebGUI/Form/asset.pm
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
package WebGUI::Form::asset;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::Form::button;
|
||||
use WebGUI::Form::hidden;
|
||||
use WebGUI::Form::text;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::asset
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates an asset selector field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 name
|
||||
|
||||
The name of the field. Defaults to "asset".
|
||||
|
||||
=head4 class
|
||||
|
||||
Limits the list of selectable assets to a specific class, such as "WebGUI::Asset::Wobject::Article", specified by this parameter.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
name=>{
|
||||
defaultValue=> "asset"
|
||||
},
|
||||
class=>{
|
||||
defaultValue=> undef
|
||||
},
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders an asset selector.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($self->{value}) || WebGUI::Asset->getRoot;
|
||||
return WebGUI::Form::hidden->new(
|
||||
name=>$self->{name},
|
||||
extras=>'id="'.$self->{name}.'" '.$self->{extras},
|
||||
value=>$asset->getId
|
||||
)->toHtml
|
||||
.WebGUI::Form::text->new(
|
||||
name=>$self->{name}."_display",
|
||||
extras=>'id="'.$self->{name}."_display".'" readonly="1"',
|
||||
value=>$asset->get("title")
|
||||
)->toHtml
|
||||
.WebGUI::Form::button->new(
|
||||
value=>"...",
|
||||
extras=>'onclick="window.open(\''.$asset->getUrl("op=formAssetTree&classLimiter=".$self->{class}."&formId=".$self->{name}).'\',\'assetPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"'
|
||||
)->toHtml;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
83
lib/WebGUI/Form/button.pm
Normal file
83
lib/WebGUI/Form/button.pm
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package WebGUI::Form::button;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::button
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a form button.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
The default text to appear on the button. Defaults to an internationalized version of the word "save".
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
defaultValue=>{
|
||||
defaultValue=>WebGUI::International::get(62)
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a button.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixQuotes($self->{value});
|
||||
return '<input type="button" name="'.$self->{name}.'" value="'.$value.'" '.$self->{extras}.' />';
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
133
lib/WebGUI/Form/checkList.pm
Normal file
133
lib/WebGUI/Form/checkList.pm
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
package WebGUI::Form::checkList;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Form::checkbox;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::checkList
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a series of check box form fields.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control. Also take a look ath WebGUI::Form::checkbox as this class creates a list of checkboxes.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 options
|
||||
|
||||
A hash reference containing key values that will be returned with the form post and displayable text pairs. Defaults to an empty hash reference.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
An array reference of the items to be checked if no value is specified. Defaults to an empty array reference.
|
||||
|
||||
=head4 vertical
|
||||
|
||||
Boolean representing whether the checklist should be represented vertically or horizontally. If set to "1" will be displayed vertically. Defaults to "0".
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
options=>{
|
||||
defaultValue=>{}
|
||||
},
|
||||
defaultValue=>{
|
||||
defaultValue=>[],
|
||||
},
|
||||
vertical=>{
|
||||
defaultValue=>0
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my @data = $session{cgi}->param($self->{name});
|
||||
return wantarray ? @data : join("\n",@data);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a series of checkboxes.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $output;
|
||||
foreach my $key (keys %{$self->{options}}) {
|
||||
my $checked = 0;
|
||||
foreach my $item (@{$self->{value}}) {
|
||||
if ($item eq $key) {
|
||||
$checked = 1;
|
||||
}
|
||||
}
|
||||
$output .= WebGUI::Form::checkbox->new({
|
||||
name=>$self->{name},
|
||||
value=>$key,
|
||||
extras=>$self->{extras},
|
||||
checked=>$checked
|
||||
})->toHtml;
|
||||
$output .= ${$self->{options}}{$key};
|
||||
if ($self->{vertical}) {
|
||||
$output .= "<br />\n";
|
||||
} else {
|
||||
$output .= " \n";
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
91
lib/WebGUI/Form/checkbox.pm
Normal file
91
lib/WebGUI/Form/checkbox.pm
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
package WebGUI::Form::checkbox;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::checkbox
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a check box form field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 checked
|
||||
|
||||
Defaults to "0". Set to "1" if this field should be checked.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
The value returned by this field if it is checked and no value is specified. Defaults to "1".
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
checked=>{
|
||||
defaultValue=> 0
|
||||
},
|
||||
defaultValue=>{
|
||||
defaultValue=>1
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders and input tag of type checkbox.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixQuotes($self->{value});
|
||||
my $checkedText = ' checked="checked"' if ($self->{checked});
|
||||
return '<input type="checkbox" name="'.$self->{name}.'" value="'.$value.'"'.$checkedText.' '.$self->{extras}.' />';
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
58
lib/WebGUI/Form/codearea.pm
Normal file
58
lib/WebGUI/Form/codearea.pm
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package WebGUI::Form::codearea;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::text';
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::codearea
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a code area form field, which is just like a text area except stretches to fit it's space and allows tabs in it's content.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::textarea.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a code area field.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/TabFix.js',{type=>"text/javascript"});
|
||||
$self->{extras} .= ' style="width: 99%; min-width: 440px; height: 400px" onkeypress="return TabFix_keyPress(event)" onkeydown="return TabFix_keyDown(event)"';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
70
lib/WebGUI/Form/color.pm
Normal file
70
lib/WebGUI/Form/color.pm
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package WebGUI::Form::color;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::color
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a color picker which returns hex colors like #000000.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns a hex color like "#000000". Returns undef if the return value is not a valid color.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $color = $session{cgi}->param($self->{name});
|
||||
return undef unless $color =~ /\#\w{6}/;
|
||||
return $color;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a color picker control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/colorPicker.js',{ type=>'text/javascript' });
|
||||
return '<script type="text/javascript">initColorPicker("'.$self->{name}.'","'.($self->{value}).'");</script>';
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
80
lib/WebGUI/Form/combo.pm
Normal file
80
lib/WebGUI/Form/combo.pm
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package WebGUI::Form::combo;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::selectList';
|
||||
use WebGUI::Form::text;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::combo
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a select list merged with a text box form control.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::selectList.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
if ($session{cgi}->param($self->{name}."_new")) {
|
||||
return $session{cgi}->param($self->{name}."_new");
|
||||
}
|
||||
return $self->SUPER::getValueFromPost;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a combo box form control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
$self->{options}->{''} = '['.WebGUI::International::get(582).']';
|
||||
$self->{options}->{_new_} = WebGUI::International::get(581).'->';
|
||||
return $self->SUPER::toHtml
|
||||
.WebGUI::Form::text->new(
|
||||
size=>$session{setting}{textBoxSize}-5,
|
||||
name=>$self->{name}."_new"
|
||||
)->toHtml;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
124
lib/WebGUI/Form/contentType.pm
Normal file
124
lib/WebGUI/Form/contentType.pm
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
package WebGUI::Form::contentType;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Form::selectList;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::contentType
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a content type selector which can be used in conjunction with WebGUI::HTML::filter().
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 types
|
||||
|
||||
An array reference of field types to be displayed. The types are "mixed", "html", "code", and "text". Defaults to all.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
An array reference of the items to be checked if no value is specified. Defaults to "mixed". Possible values are "mixed", "code", "html", and "text".
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
options=>{
|
||||
defaultValue=>[qw(mixed html code text)]
|
||||
},
|
||||
defaultValue=>{
|
||||
defaultValue=>"mixed",
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns either what's posted or if nothing comes back it returns "mixed".
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return $session{cgi}->param($self->{name}) || "mixed";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a select list form control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my %types;
|
||||
foreach my $type (@{$self->{types}}) {
|
||||
if ($type eq "text") {
|
||||
$types{text} = WebGUI::International::get(1010);
|
||||
} elsif ($type eq "mixed") {
|
||||
$types{mixed} = WebGUI::International::get(1008);
|
||||
} elsif ($type eq "code") {
|
||||
$types{code} = WebGUI::International::get(1011);
|
||||
} elsif ($type eq "html") {
|
||||
$types{html} = WebGUI::International::get(1009);
|
||||
}
|
||||
}
|
||||
return WebGUI::Form::selectList->new(
|
||||
options=>\%types,
|
||||
name=>$self->{name},
|
||||
value=>[$self->{value}],
|
||||
extras=>$self->{extras},
|
||||
defaultValue=>[$self->{defaultValue}]
|
||||
)->toHtml;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
96
lib/WebGUI/Form/databaseLink.pm
Normal file
96
lib/WebGUI/Form/databaseLink.pm
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
package WebGUI::Form::databaseLink;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::DatabaseLink;
|
||||
use WebGUI::Form::selectList;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::databaseLink
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a database connection chooser control.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 name
|
||||
|
||||
The identifier for this field. Defaults to "databaseLinkId".
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
A database link id. Defaults to "0", which is the WebGUI database.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
name=>{
|
||||
defaultValue=>"databaseLinkId"
|
||||
},
|
||||
defaultValue=>{
|
||||
defaultValue=>0
|
||||
},
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a database connection picker control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
return WebGUI::Form::selectList->new(
|
||||
name=>$self->{name},
|
||||
options=>WebGUI::DatabaseLink::getList(),
|
||||
value=>[$self->{value}]
|
||||
)->toHtml;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
136
lib/WebGUI/Form/date.pm
Normal file
136
lib/WebGUI/Form/date.pm
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
package WebGUI::Form::date;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::text';
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::date
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Accepts and returns and epoch date and creates a date picker control.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::text.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the superclass for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 maxlength
|
||||
|
||||
Defaults to 10. Determines the maximum number of characters allowed in this field.
|
||||
|
||||
=head4 size
|
||||
|
||||
Defaults to 10. The displayed size of the box for the date to be typed in.
|
||||
|
||||
=head4 noDate
|
||||
|
||||
By default a date is placed in the value field. Set this to "1" to leave it empty.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
If no value is specified, this will be used. Defaults to today and now.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
defaultValue=>{
|
||||
defaultValue=>time()
|
||||
},
|
||||
maxlength=>{
|
||||
defaultValue=> 10
|
||||
},
|
||||
size=>{
|
||||
defaultValue=> 10
|
||||
},
|
||||
noDate=>{
|
||||
defaultValue=>0
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns a validated form post result. If the result does not pass validation, it returns undef instead.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return WebGUI::DateTime::setToEpoch($session{cgi}->param($self->{name}));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a date picker control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = WebGUI::DateTime::epochToSet($self->{value}) unless ($self->{noDate} && $self->{value} eq '');
|
||||
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" });
|
||||
my $mondayFirst = $session{user}{firstDayOfWeek} ? "true" : "false";
|
||||
return WebGUI::Form::text->new(
|
||||
name=>$self->{name},
|
||||
value=>$value,
|
||||
size=>$self->{size},
|
||||
extras=>'id="'.$self->{name}.'Id" '.$self->{extras},
|
||||
maxlength=>$self->{maxlength}
|
||||
)->toHtml . '<script type="text/javascript">
|
||||
Calendar.setup({
|
||||
inputField : "'.$self->{name}.'Id",
|
||||
ifFormat : "%Y-%m-%d",
|
||||
showsTime : false,
|
||||
timeFormat : "12",
|
||||
mondayFirst : '.$mondayFirst.'
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
129
lib/WebGUI/Form/dateTime.pm
Normal file
129
lib/WebGUI/Form/dateTime.pm
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
package WebGUI::Form::dateTime;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::text';
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::dateTime
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Accepts and returns and epoch date and creates a date picker control.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::text.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the superclass for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 maxlength
|
||||
|
||||
Defaults to 19. Determines the maximum number of characters allowed in this field.
|
||||
|
||||
=head4 size
|
||||
|
||||
Defaults to 19. The displayed size of the box for the date to be typed in.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
If no value is specified, this will be used. Defaults to today and now.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
defaultValue=>{
|
||||
defaultValue=>time()
|
||||
},
|
||||
maxlength=>{
|
||||
defaultValue=> 19
|
||||
},
|
||||
size=>{
|
||||
defaultValue=> 19
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns a validated form post result. If the result does not pass validation, it returns undef instead.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return WebGUI::DateTime::setToEpoch($session{cgi}->param($self->{name}));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a date picker control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = WebGUI::DateTime::epochToSet($self->{value},1);
|
||||
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" });
|
||||
my $mondayFirst = $session{user}{firstDayOfWeek} ? "true" : "false";
|
||||
return WebGUI::Form::text->new(
|
||||
name=>$self->{name},
|
||||
value=>$value,
|
||||
size=>$self->{size},
|
||||
extras=>'id="'.$self->{name}.'Id" '.$self->{extras},
|
||||
maxlength=>$self->{maxlength}
|
||||
)->toHtml . '<script type="text/javascript">
|
||||
Calendar.setup({
|
||||
inputField : "'.$self->{name}.'Id",
|
||||
ifFormat : "%Y-%m-%d %H:%M:%S",
|
||||
showsTime : true,
|
||||
timeFormat : "12",
|
||||
mondayFirst : '.$mondayFirst.'
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
73
lib/WebGUI/Form/email.pm
Normal file
73
lib/WebGUI/Form/email.pm
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package WebGUI::Form::email;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::text';
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::email
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates an email field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::text.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns a validated email address. If the result does not pass validation, it returns undef instead.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{cgi}->param($self->{name});
|
||||
if ($value =~ /^([A-Z0-9]+[._+-]?){1,}([A-Z0-9]+[_+-]?)+\@(([A-Z0-9]+[._-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i) {
|
||||
return $value;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders an email address field.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/emailCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onChange="emailCheck(this.value)" ';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
81
lib/WebGUI/Form/hidden.pm
Normal file
81
lib/WebGUI/Form/hidden.pm
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
package WebGUI::Form::hidden;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::hidden
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a hidden field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
A synonym for toHtmlAsHidden.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
$self->toHtmlAsHidden;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtmlAsHidden ( )
|
||||
|
||||
Renders an input tag of type hidden.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value})));
|
||||
return '<input type="hidden" name="'.$self->{name}.'" value="'.$value.'" '.$self->{extras}.' />'."\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtmlWithWrapper ( )
|
||||
|
||||
A synonym for toHtmlAsHidden.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtmlWithWrapper {
|
||||
my $self = shift;
|
||||
return $self->toHtmlAsHidden;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
146
lib/WebGUI/Form/selectList.pm
Normal file
146
lib/WebGUI/Form/selectList.pm
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
package WebGUI::Form::selectList;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::selectList
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a select list, aka dropdown list form control.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 options
|
||||
|
||||
A hash reference containing key values that will be returned with the form post and displayable text pairs. Defaults to an empty hash reference.
|
||||
|
||||
=head4 defaultValue
|
||||
|
||||
An array reference of the items to be checked if no value is specified. Defaults to an empty array reference.
|
||||
|
||||
=head4 size
|
||||
|
||||
The number of characters tall this list should be. Defaults to '1'.
|
||||
|
||||
=head4 multiple
|
||||
|
||||
Boolean indicating whether the user can select multiple items from this list like a checkList. Defaults to "0".
|
||||
|
||||
=head4 sortByValue
|
||||
|
||||
A boolean value for whether or not the values in the options hash should be sorted. Defaults to "0".
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
options=>{
|
||||
defaultValue=>{}
|
||||
},
|
||||
defaultValue=>{
|
||||
defaultValue=>[],
|
||||
},
|
||||
multiple=>{
|
||||
defaultValue=>0
|
||||
},
|
||||
sortByValue=>{
|
||||
defaultValue=>0
|
||||
},
|
||||
size=>{
|
||||
defaultValue=>1
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my @data = $session{cgi}->param($self->{name});
|
||||
return wantarray ? @data : join("\n",@data);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders a select list form control.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $multiple = ' multiple="1"' if ($self->{multiple});
|
||||
my $output = '<select name="'.$self->{name}.'" size="'.$self->{size}.'" '.$self->{extras}.$multiple.'>';
|
||||
my %options;
|
||||
tie %options, 'Tie::IxHash';
|
||||
if ($self->{sortByValue}) {
|
||||
foreach my $optionKey (sort {"\L${$self->{options}}{$a}" cmp "\L${$self->{options}}{$b}" } keys %{$self->{options}}) {
|
||||
$options{$optionKey} = $self->{options}{$optionKey};
|
||||
}
|
||||
} else {
|
||||
%options = %{$self->{options}};
|
||||
}
|
||||
foreach my $key (keys %options) {
|
||||
$output .= '<option value="'.$key.'"';
|
||||
foreach my $item (@{$self->{value}}) {
|
||||
if ($item eq $key) {
|
||||
$output .= ' selected="selected"';
|
||||
}
|
||||
}
|
||||
$output .= '>'.${$self->{options}}{$key}.'</option>';
|
||||
}
|
||||
$output .= '</select>'."\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
89
lib/WebGUI/Form/text.pm
Normal file
89
lib/WebGUI/Form/text.pm
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
package WebGUI::Form::text;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::text
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a text input box form field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 maxlength
|
||||
|
||||
Defaults to 255. Determines the maximum number of characters allowed in this field.
|
||||
|
||||
=head4 size
|
||||
|
||||
Defaults to the setting textBoxSize or 30 if that's not set. Specifies how big of a text box to display.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
maxlength=>{
|
||||
defaultValue=> 255
|
||||
},
|
||||
size=>{
|
||||
defaultValue=>$session{setting}{textBoxSize} || 30
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders an input tag of type text.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value})));
|
||||
return '<input type="text" name="'.$self->{name}.'" value="'.$value.'" size="'.$self->{size}.'" maxlength="'.$self->{maxlength}.'" '.$self->{extras}.' />';
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
100
lib/WebGUI/Form/textarea.pm
Normal file
100
lib/WebGUI/Form/textarea.pm
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package WebGUI::Form::textarea;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::Control';
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::textarea
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a text area form field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::Control.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the super class for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 rows
|
||||
|
||||
The number of rows (in characters) tall the box should be. Defaults to the setting textAreaRows or 5 if that's not specified.
|
||||
|
||||
=head4 columns
|
||||
|
||||
The number of columns (in characters) wide the box should be. Defaults to the setting textAreaCols or 50 if that's not specified.
|
||||
|
||||
=head4 wrap
|
||||
|
||||
The style of wrapping this form should use. Defaults to "virtual". Other possible values are "off" and "physical".
|
||||
|
||||
=head
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
rows=>{
|
||||
defaultValue=> $session{setting}{textAreaRows} || 5
|
||||
},
|
||||
columns=>{
|
||||
defaultValue=> $session{setting}{textAreaCols} || 50
|
||||
},
|
||||
wrap=>{
|
||||
defaultValue=>"virtual"
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders an input tag of type text.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixMacros($self->fixTags($self->fixSpecialCharacters($self->{value})));
|
||||
return '<textarea name="'.$self->{name}.'" cols="'.$self->{columns}.'" rows="'.$self->{rows}.'" wrap="'.
|
||||
$self->{wrap}.'" '.$self->{extras}.'>'.$value.'</textarea>';
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
100
lib/WebGUI/Form/zipcode.pm
Normal file
100
lib/WebGUI/Form/zipcode.pm
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
package WebGUI::Form::zipcode;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use base 'WebGUI::Form::text';
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Form::zipcode
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Creates a zip code form field.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
This is a subclass of WebGUI::Form::text.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
The following methods are specifically available from this class. Check the superclass for additional methods.
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( [ additionalTerms ] )
|
||||
|
||||
See the superclass for additional details.
|
||||
|
||||
=head3 additionalTerms
|
||||
|
||||
The following additional parameters have been added via this sub class.
|
||||
|
||||
=head4 maxlength
|
||||
|
||||
Defaults to 10. Determines the maximum number of characters allowed in this field.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift || [];
|
||||
push(@{$definition}, {
|
||||
maxlength=>{
|
||||
defaultValue=> 10
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getValueFromPost ( )
|
||||
|
||||
Returns a validated form post result. If the result does not pass validation, it returns undef instead.
|
||||
|
||||
=cut
|
||||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{cgi}->param($self->{name});
|
||||
if ($value =~ /^[A-Z\d\s\-]+$/) {
|
||||
return $value;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
||||
Renders an input tag of type text.
|
||||
|
||||
=cut
|
||||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- \')"';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -76,195 +76,26 @@ sub _checkEmailAddy {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 asset ( name )
|
||||
=head2 AUTOLOAD ()
|
||||
|
||||
Returns an asset id.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
Dynamically creates functions on the fly for all the different form control types.
|
||||
|
||||
=cut
|
||||
|
||||
sub asset {
|
||||
return $session{form}{$_[0]};
|
||||
sub AUTOLOAD {
|
||||
our $AUTOLOAD;
|
||||
my $name = (split /::/, $AUTOLOAD)[-1];
|
||||
my $fieldName = shift;
|
||||
my $cmd = "use WebGUI::Form::".$name;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::error("Couldn't compile form control: ".$name.". Root cause: ".$@);
|
||||
return undef;
|
||||
}
|
||||
my $class = "WebGUI::Form::".$name;
|
||||
return $class->new({name=>$fieldName})->getValueFromPost;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 checkbox ( name )
|
||||
|
||||
Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub checkbox {
|
||||
return selectList($_[0]);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 checkList ( name )
|
||||
|
||||
Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub checkList {
|
||||
return selectList($_[0]);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 codearea ( name )
|
||||
|
||||
Returns a string.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub codearea {
|
||||
return $session{form}{$_[0]};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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 )
|
||||
|
||||
Returns either an array of values or a scalar value depending upon what you request.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub combo {
|
||||
if ($session{form}{$_[0]."_new"}) {
|
||||
return $session{form}{$_[0]."_new"};
|
||||
}
|
||||
return selectList($_[0]);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 contentType ( name )
|
||||
|
||||
Returns a content type. Defaults to "mixed".
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub contentType {
|
||||
return ($session{form}{$_[0]} || "mixed");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 databaseLink ( name )
|
||||
|
||||
Returns the ID of a database link.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub databaseLink {
|
||||
return selectList($_[0]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 date ( name )
|
||||
|
||||
Returns an epoch datestamp.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub date {
|
||||
return WebGUI::DateTime::setToEpoch($session{form}{$_[0]});
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 dateTime ( name )
|
||||
|
||||
Returns an epoch datestamp.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub dateTime {
|
||||
return WebGUI::DateTime::setToEpoch($session{form}{$_[0]});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 email ( name )
|
||||
|
||||
Returns an email address.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub email {
|
||||
if (_checkEmailAddy($session{form}{$_[0]})) {
|
||||
return $session{form}{$_[0]};
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 fieldType ( name )
|
||||
|
|
@ -339,22 +170,6 @@ sub group {
|
|||
return 2;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 hidden ( name )
|
||||
|
||||
Returns a string.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub hidden {
|
||||
return $session{form}{$_[0]};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -537,23 +352,6 @@ sub radioList {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 selectList ( name )
|
||||
|
||||
Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub selectList {
|
||||
my @data = $session{cgi}->param($_[0]);
|
||||
return wantarray ? @data : join("\n",@data);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -575,39 +373,6 @@ sub template {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 text ( name )
|
||||
|
||||
Returns a string of text.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub text {
|
||||
return $session{form}{$_[0]};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 textarea ( name )
|
||||
|
||||
Returns a string of text.
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub textarea {
|
||||
return $session{form}{$_[0]};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -675,26 +440,6 @@ sub yesNo {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 zipcode ( name )
|
||||
|
||||
Returns a string which allows uppercase alpha characters, digits, spaces, and hypens (dashes).
|
||||
|
||||
=head3 name
|
||||
|
||||
The name of the form variable to retrieve.
|
||||
|
||||
=cut
|
||||
|
||||
sub zipcode {
|
||||
if ($session{form}{$_[0]} =~ /^[A-Z\d\s\-]+$/) {
|
||||
return $session{form}{$_[0]};
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -252,6 +252,30 @@ sub _uiLevelChecksOut {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 AUTOLOAD ()
|
||||
|
||||
Dynamically creates functions on the fly for all the different form control types.
|
||||
|
||||
=cut
|
||||
|
||||
sub AUTOLOAD {
|
||||
our $AUTOLOAD;
|
||||
my $name = (split /::/, $AUTOLOAD)[-1];
|
||||
my @params = @_;
|
||||
my $cmd = "use WebGUI::Form::".$name;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::error("Couldn't compile form control: ".$name.". Root cause: ".$@);
|
||||
return undef;
|
||||
}
|
||||
my $class = "WebGUI::Form::".$name;
|
||||
return $class->new(@params)->toHtmlWithWrapper;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 asset ( name, label, value, class, extras, subtext, defaultValue, uiLevel )
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
PACKAge WebGUI::Operation::Settings;
|
||||
package WebGUI::Operation::Settings;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
cursor: default;
|
||||
background: #d4d0c8;
|
||||
font-family: tahoma,verdana,sans-serif;
|
||||
z-index: 500;
|
||||
}
|
||||
|
||||
.calendar table {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue