From 7bc98eed07641ed1243a44fa129a947b47989f96 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 5 Oct 2002 04:38:57 +0000 Subject: [PATCH] Adding the new forms package needed for the new UI Levels system. --- docs/gotcha.txt | 9 +- lib/WebGUI/Form.pm | 1196 ++++++++++++++++++++++++++++++++++ lib/WebGUI/HTMLForm.pm | 1130 ++++++++++++++++++-------------- lib/WebGUI/Macro/AdminBar.pm | 28 +- 4 files changed, 1852 insertions(+), 511 deletions(-) create mode 100644 lib/WebGUI/Form.pm diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 707712bc8..58fdbe16d 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -7,6 +7,14 @@ upgrading from one version to the next, or even between multiple versions. Be sure to heed the warnings contained herein as they will save you many hours of grief. +4.7.0 +-------------------------------------------------------------------- + * WebGUI::HTMLForm->radioList has been changed to correct an API + error. However, if your applications use this method, this + change will break your application. If you do not use any + third-party or custom plug-ins, you can disregard this + warning. + 4.6.3 -------------------------------------------------------------------- * It has been reported that some people had a duplicate key error @@ -17,7 +25,6 @@ save you many hours of grief. patches, or just moving forward. Either way will produce the same result. - 4.6.0 -------------------------------------------------------------------- * The runHourly scheduler has been updated to allow for more diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm new file mode 100644 index 000000000..01844fee5 --- /dev/null +++ b/lib/WebGUI/Form.pm @@ -0,0 +1,1196 @@ +package WebGUI::Form; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2002 Plain Black LLC. + ------------------------------------------------------------------- + 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::DateTime; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::SQL; +use WebGUI::URL; + +=head1 NAME + + Package WebGUI::Form + +=head1 SYNOPSIS + + use WebGUI::Form; + + WebGUI::Form::checkbox({name=>"whichOne", value=>"red"}); + WebGUI::Form::checkList({name=>"dayOfWeek", options=>\%days}); + WebGUI::Form::combo({name=>"fruit",options=>\%fruit}); + WebGUI::Form::date({name=>"endDate", value=>$endDate}); + WebGUI::Form::email({name=>"emailAddress"}); + WebGUI::Form::file({name=>"image"}); + WebGUI::Form::group({name=>"groupToPost"}); + WebGUI::Form::hidden({name=>"wid",value=>"55"}); + WebGUI::Form::HTMLArea({name=>"description"}); + WebGUI::Form::integer({name=>"size"}); + WebGUI::Form::interval({name=>"timeToLive", interval=>12, units=>"hours"}); + WebGUI::Form::password({name=>"identifier"}); + WebGUI::Form::phone({name=>"cellPhone"}); + WebGUI::Form::radio({name=>"whichOne", value=>"red"}); + WebGUI::Form::radioList({name="dayOfWeek", options=>\%days}); + WebGUI::Form::selectList({name=>"dayOfWeek", options=>\%days, value=>\@array"}); + WebGUI::Form::submit; + WebGUI::Form::text({name=>"firstName"}); + WebGUI::Form::textarea({name=>"emailMessage"}); + WebGUI::Form::url({name=>"homepage"}); + WebGUI::Form::yesNo({name=>"happy"}); + WebGUI::Form::zipcode({name=>"workZip"}); + +=head1 DESCRIPTION + + Base forms package. Eliminates some of the normal code work that goes + along with creating forms. Used by the PowerForm package. + +=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: + +=cut + +#------------------------------------------------------------------- +sub _fixQuotes { + my $value = shift; + $value =~ s/\"/\"\;/g; + return $value; +} + +#------------------------------------------------------------------- + +=head2 checkbox ( hashRef ) + + Returns a checkbox form element. + +=item name + + The name field for this form element. + +=item checked + + If you'd like this box to be defaultly checked, set this to "1". + +=item value + + The default value for this form element. Defaults to "1". + +=item 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()"' + +=cut + +sub checkbox { + my ($checkedText, $value); + $checkedText = ' checked="1"' if ($_[0]->{checked}); + $value = $_[0]->{value} || 1; + return '{extras}.'>'; +} + +#------------------------------------------------------------------- + +=head2 checkList ( hashRef ) + + Returns checkbox list. + +=item name + + The name field for this form element. + +=item options + The list of options for this list. Should be passed as a + hash reference. + +=item value + + The default value(s) for this form element. This should be passed + as an array reference. + +=item vertical + + If set to "1" the radio button elements will be laid out + horizontally. Defaults to "0". + +=item 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()"' + +=cut + +sub checkList { + my ($output, $checked, $key, $item); + foreach $key (keys %{$_[0]->{options}}) { + $checked = 0; + foreach $item (@{$_[0]->{value}}) { + if ($item eq $key) { + $checked = 1; + } + } + $output .= checkbox({ + name=>$_[0]->{name}, + value=>$key, + extras=>$_[0]->{extras}, + checked=>$checked + }); + $output .= ${$_[0]->{options}}{$key}.'    '; + $output .= '
' if ($_[0]->{vertical}); + } + return $output; +} + +#------------------------------------------------------------------- + +=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. + +=item name + + The name field for this form element. + +=item options + The list of options for the select list. Should be passed as a + hash reference. + +=item value + + The default value(s) for this form element. This should be passed + as an array reference. + +=item size + + The number of characters tall this form element should be. Defaults + to "1". + +=item multiple + + A boolean value for whether this select list should allow multiple + selections. Defaults to "0". + +=item 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()"' + +=cut + +sub combo { + my ($output, $size); + $_[0]->{options}->{''} = '['.WebGUI::International::get(582).']'; + $_[0]->{options}->{_new_} = WebGUI::International::get(581).'->'; + $output = selectList({ + name=>$_[0]->{name}, + value=>$_[0]->{value}, + multiple=>$_[0]->{multiple}, + extras=>$_[0]->{extras} + }); + $size = $session{setting}{textBoxSize}-5; + $output .= text({name=>$_[0]->{name}."_new",size=>$size}); + return $output; +} + +#------------------------------------------------------------------- + +=head2 date ( hashRef ) + + Returns a date field. + +=item name + + The name field for this form element. + +=item value + + The default date. Pass as an epoch value. Defaults to today. + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=item noDate + + By default a date is placed in the "value" field. Set this to "1" + to turn off the default date. + +=cut + +sub date { + my ($subtext, $noDate, $class, $output, $name, $label, $extras, $size, $value); + $value = epochToSet($_[0]->{value}); + $size = $_[0]->{size} || 10; + $value = "" if ($_[0]->{noDate}); + $output = text({ + name=>$_[0]->{name}, + value=>$value, + size=>$size, + maxlength=>10, + extras=>$_[0]->{extras} + }); + $output .= ''; + return $output; +} + + + +#------------------------------------------------------------------- + +=head2 email ( hashRef ) + + Adds an email address row to this form. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item maxlength + + The maximum number of characters to allow in this form element. + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub email { + my ($output); + $output = ''; + $output .= text({ + name=>$_[0]->{name}, + value=>$_[0]->{value}, + extras=>' onChange="emailCheck(this.value)" '.$_[0]->{extras} + }); + return $output; +} + + +#------------------------------------------------------------------- + +=head2 file ( hashRef ) + + Returns a file upload field. + +=item name + + The name field for this form element. + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub file { + my ($size); + $size = $_[0]->{size} || $session{setting}{textBoxSize} || 30; + return '{extras}.'>'; +} + +#------------------------------------------------------------------- + +=head2 formHeader ( hashRef ) + + Returns a form header. + +=item action + + The form action. Defaults to the current page. + +=item method + + The form method. Defaults to "POST". + +=item enctype + + The form enctype. Defaults to "multipart/form-data". + +=item extras + + If you want to add anything special to the form header like + javascript actions or stylesheet info, then use this. + +=cut + +sub formHeader { + my ($action, $method, $enctype); + $action = $_[0]->{action} || WebGUI::URL::page(); + $method = $_[0]->{method} || "POST"; + $enctype = $_[0]->{enctype} || "multipart/form-data"; + return '
{extras}.'>'; + +} + +#------------------------------------------------------------------- + +=head2 group ( hashRef ] ) + + Returns a group pull-down field. A group pull down + provides a select list that provides name value pairs for all the + groups in the WebGUI system. + +=item name + + The name field for this form element. + +=item value + + The default value(s) for this form element. This should be passed + as an array reference. Defaults to "7" (Everyone). + +=item size + + How many rows should be displayed at once? + +=item multiple + + Set to "1" if multiple groups should be selectable. + +=item 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()"' + +=cut + +sub group { + my (%hash, $value); + $value = $_[0]->{value}; + if ($$value[0] eq "") { #doing long form otherwise arrayRef didn't work + $value = [7]; + } + tie %hash, 'Tie::IxHash'; + %hash = WebGUI::SQL->buildHash("select groupId,groupName from groups where groupName<>'Reserved' order by groupName"); + return selectList({ + options=>\%hash, + name=>$_[0]->{name}, + value=>$value, + extras=>$_[0]->{extras}, + size=>$_[0]->{size}, + multiple=>$_[0]->{multiple} + }); + +} + +#------------------------------------------------------------------- + +=head2 hidden ( hashRef ) + + Returns a hidden field. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=cut + +sub hidden { + return ''; +} + + +#------------------------------------------------------------------- + +=head2 hiddenList ( hashRef ) + + Returns a list of hidden fields. This is primarily to be used by + the HTMLForm package, but we decided to make it a public method + in case anybody else had a use for it. + +=item options + + A hash reference where the key is the "name" of the hidden field. + +=item value + + An array reference where each value in the array should be a name + from the hash (if you want it to show up in the hidden list). + +=cut + +sub hiddenList { + my ($output, $key, $item); + foreach $key (keys %{$_[0]->{options}}) { + foreach $item (@$_[0]->{value}) { + if ($item eq $key) { + $output .= hidden({ + name=>$key, + value=>$item + }); + } + } + } + return $output; +} + + + +#------------------------------------------------------------------- + +=head2 HTMLArea ( hashRef ) + + Returns an HTML area. An HTML area is different than + a standard text area in that it provides rich edit functionality + and some special error trapping for HTML and other special + characters. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item 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()"' + +=item wrap + + The method for wrapping text in the text area. Defaults to + "virtual". There should be almost no reason to specify this. + +=item rows + + The number of characters tall this form element should be. There + should be no reason for anyone to specify this. + +=item columns + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub HTMLArea { + my ($output, $value); + $output = ''; + $value =~ s/\/\>\;/g; + if ($session{setting}{richEditor} eq "edit-on-pro") { + $output .= ''; + } else { + $output .= ''; + } + $output .= '
'; + $output .= textarea({ + name=>$_[0]->{name}, + value=>$_[0]->{value}, + wrap=>$_[0]->{wrap}, + columns=>$_[0]->{columns}, + rows=>$_[0]->{rows}, + extras=>$_[0]->{extras}.' onBlur="fixChars(this.form.'.$_[0]->{name}.')"' + }); + return $output; +} + +#------------------------------------------------------------------- + +=head2 integer ( hashRef ) + + Returns an integer field. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item maxlength + + The maximum number of characters to allow in this form element. + Defaults to 11. + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub integer { + my ($output, $size, $value); + $value = $_[0]->{value} || 0; + $size = $_[0]->{size} || 11; + $output = ''; + $output .= text({ + name=>$_[0]->{name}, + value=>$value, + size=>$size, + extras=>'onKeyUp="doNumCheck(this.form.'.$_[0]->{name}.')"'.$_[0]->{extras}, + maxlength=>$_[0]->{maxlength} + }); + return $output; +} + +#------------------------------------------------------------------- + +=head2 interval ( hashRef ) + + Adds a time interval row to this form. + +=item name + + The the base name for this form element. This form element actually + returns two values under different names. They are name_interval and + name_units. + +=item intervalValue + + The default value for interval portion of this form element. Defaults + to '1'. + +=item unitsValue + + The default value for units portion of this form element. Defaults + to 'seconds'. Possible values are 'seconds', 'minutes', 'hours', + 'days', 'weeks', 'months', and 'years'. + +=item 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()"' + +=cut + +sub interval { + my (%units, $output, $intervalValue, $unitsValue); + $intervalValue = $_[0]->{intervalValue} || 1; + $unitsValue = $_[0]->{unitsValue} || "seconds"; + tie %units, 'Tie::IxHash'; + %units = ('seconds'=>WebGUI::International::get(704), + 'minutes'=>WebGUI::International::get(705), + 'hours'=>WebGUI::International::get(706), + 'days'=>WebGUI::International::get(700), + 'weeks'=>WebGUI::International::get(701), + 'months'=>WebGUI::International::get(702), + 'years'=>WebGUI::International::get(703)); + $output = integer({ + name=>$_[0]->{name}.'_interval', + value=>$intervalValue, + extras=>$_[0]->{extras} + }); + $output .= selectList({ + name=>$_[0]->{name}.'_units', + value=>[$unitsValue], + options=>\%units + }); + return $output; +} + + +#------------------------------------------------------------------- + +=head2 password ( hashRef ) + + Returns a password field. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item maxlength + + The maximum number of characters to allow in this form element. + Defaults to "35". + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. Defaults to "30" + unless overridden in the settings. + +=cut + +sub password { + my ($size, $maxLength, $value); + $value = _fixQuotes($_[0]->{value}); + $maxLength = $_[0]->{maxlength} || 35; + $size = $_[0]->{size} || $session{setting}{textBoxSize} || 30; + return '{extras}.'>'; +} + +#------------------------------------------------------------------- + +=head2 phone ( hashRef ) + + Returns a phone field. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item maxlength + + The maximum number of characters to allow in this form element. + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub phone { + my ($maxLength); + $maxLength = shift || 30; + return text({ + name=>$_[0]->{name}, + maxlength=>$maxLength, + extras=>$_[0]->{extras}, + value=>$_[0]->{value}, + size=>$_[0]->{size} + }); +} + +#------------------------------------------------------------------- + +=head2 radio ( hashRef ) + + Returns a radio button. + +=item name + + The name field for this form element. + +=item checked + + If you'd like this radio button to be defaultly checked, set this to "1". + +=item value + + The default value for this form element. + +=item 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()"' + +=cut + +sub radio { + my ($checkedText); + $checkedText = ' checked="1"' if ($_[0]->{checked}); + return '{extras}.'>'; +} + +#------------------------------------------------------------------- + +=head2 radioList ( hashRef ) + + Adds a radio button list row to this form. + +=item name + + The name field for this form element. + +=item options + + The list of options for this list. Should be passed as a + hash reference. + +=item value + + The default value for this form element. + +=item vertical + + If set to "1" the radio button elements will be laid out + horizontally. Defaults to "0". + +=item 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()"' + +=cut + +sub radioList { + my ($output, $key, $checked); + foreach $key (keys %{$_[0]->{options}}) { + $output .= '{value} eq $key) { + $checked = 1; + } else { + $checked = 0; + } + $output .= radio({ + name=>$_[0]->{name}, + value=>$key, + checked=>$checked, + extras=>$_[0]->{extras} + }); + $output .= ' '.$_[0]->{options}->{$key}; + $output .= '    '; + $output .= '
' if ($_[0]->{vertical}); + } + return $output; +} + +#------------------------------------------------------------------- + +=head2 selectList ( hashRef ) + + Adds a select list field. + +=item name + + The name field for this form element. + +=item options + + The list of options for this select list. Should be passed as a + hash reference. + +=item value + + The default value(s) for this form element. This should be passed + as an array reference. + +=item size + + The number of characters tall this form element should be. Defaults + to "1". + +=item multiple + + A boolean value for whether this select list should allow multiple + selections. Defaults to "0". + +=item 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()"' + +=cut + +sub selectList { + my ($output, $key, $item, $size, $multiple); + $size = $_[0]->{size} || 1; + $multiple = ' multiple="1"' if ($_[0]->{multiple}); + $output = ''; + return $output; +} + +#------------------------------------------------------------------- + +=head2 submit ( hashRef ) + + Returns a submit button. + +=item value + + The button text for this submit button. Defaults to "save". + +=item 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()"' + +=cut + +sub submit { + my ($label, $extras, $subtext, $class, $output, $name, $value, $wait); + $value = $_[0]->{value} || WebGUI::International::get(62); + $value = _fixQuotes($value); + $wait = WebGUI::International::get(452); + return '{extras}.'>'; +} + +#------------------------------------------------------------------- + +=head2 text ( hashRef ) + + Returns a text input field. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item maxlength + + The maximum number of characters to allow in this form element. + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub text { + my ($size, $maxLength, $value); + $value = _fixQuotes($_[0]->{value}); + $maxLength = $_[0]->{maxlength} || 255; + $size = $_[0]->{size} || $session{setting}{textBoxSize} || 30; + return '{extras}.' />'; +} + +#------------------------------------------------------------------- + +=head2 textarea ( hashRef ) + + Returns a text area field. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item 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()"' + +=item wrap + + The method for wrapping text in the text area. Defaults to + "virtual". There should be almost no reason to specify this. + +=item rows + + The number of characters tall this form element should be. There + should be no reason for anyone to specify this. + +=item columns + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub textarea { + my ($columns, $rows, $wrap); + $wrap = $_[0]->{virtual} || "virtual"; + $rows = $_[0]->{rows} || $session{setting}{textAreaRows} || 5; + $columns = $_[0]->{columns} || $session{setting}{textAreaCols} || 50; + return ''; +} + +#------------------------------------------------------------------- + +=head2 url ( hashRef ) + + Returns a URL field. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item maxlength + + The maximum number of characters to allow in this form element. + Defaults to 2048. + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub url { + my ($output, $maxLength); + $maxLength = $_[0]->{maxlength} || 2048; + $output = ''; + $output .= text({ + name=>$_[0]->{name}, + value=>$_[0]->{value}, + extras=>$_[0]->{extras}.' onBlur="addHTTP(this.form.'.$_[0]->{name}.')"', + size=>$_[0]->{size}, + maxlength=>$maxLength + }); + return $output; +} + +#------------------------------------------------------------------- + +=head2 yesNo ( hashRef ) + + Returns a yes/no radio field. + +=item name + + The name field for this form element. + +=item value + + The default value(s) for this form element. Valid values are "1" + and "0". Defaults to "1". + +=item 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()"' + +=cut + +sub yesNo { + my ($subtext, $checkYes, $checkNo, $class, $output, $name, $label, $extras, $value); + if ($_[0]->{value}) { + $checkYes = 1; + } else { + $checkNo = 1; + } + $output = radio({ + checked=>$checkYes, + name=>$_[0]->{name}, + value=>1, + extras=>$_[0]->{extras} + }); + $output .= WebGUI::International::get(138); + $output .= '   '; + $output .= radio({ + checked=>$checkNo, + name=>$_[0]->{name}, + value=>0, + extras=>$_[0]->{extras} + }); + $output .= WebGUI::International::get(139); + return $output; +} + +#------------------------------------------------------------------- + +=head2 zipcode ( hashRef ) + + Returns a zip code field. + +=item name + + The name field for this form element. + +=item value + + The default value for this form element. + +=item maxlength + + The maximum number of characters to allow in this form element. + +=item 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()"' + +=item size + + The number of characters wide this form element should be. There + should be no reason for anyone to specify this. + +=cut + +sub zipcode { + #this is here for future expansion + return text($_[0]); +} + + + + +1; + + diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 0333f1e9c..08aa216f5 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -14,12 +14,12 @@ package WebGUI::HTMLForm; =cut -use strict; -use WebGUI::DateTime; +use CGI::Util qw(rearrange); +use strict qw(vars refs); +use WebGUI::Form; use WebGUI::International; use WebGUI::Session; use WebGUI::SQL; -use WebGUI::URL; =head1 NAME @@ -55,6 +55,16 @@ use WebGUI::URL; $f->yesNo("happy","Are you happy?"); $f->zipcode("workZip","Office Zip Code"); + Alternatively each of these methods can also be called with the + tag element syntax like this: + + $f->checkbox( + -name=>"whichOne", + -value=>"red", + -label=>"Is red your favorite?" + ); + + $f->print; $f->printRowsOnly; @@ -87,12 +97,25 @@ sub _subtext { #------------------------------------------------------------------- sub _tableFormRow { - return ''.$_[0].''.$_[1].''; + unless ($_[0]->{_noTable}) { + return ''.$_[1].''.$_[2].''; + } else { + return $_[2]; + } +} + +#------------------------------------------------------------------- +sub _uiLevelChecksOut { + if ($_[0] <= $session{user}{uiLevel}) { + return 1; + } else { + return 0; + } } #------------------------------------------------------------------- -=head2 checkbox ( name [ label, checked, subtext, value, extras ] ) +=head2 checkbox ( name [ label, checked, subtext, value, extras, uiLevel ] ) Adds a checkbox row to this form. @@ -125,28 +148,41 @@ sub _tableFormRow { 'onChange="this.form.submit()"' +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub checkbox { - my ($subtext, $checkedText, $class, $output, $name, $label, $extras, $checked, $value); - $class = shift; - $name = shift; - $label = shift; - $checked = shift; - $checkedText = ' checked="1"' if ($checked); - $subtext = shift; - $value = shift; - $value = 1 if ($value eq ""); - $extras = shift; - $output = ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $checked, $subtext, $value, $extras, $uiLevel) = + rearrange([name, label, checked, subtext, value, extras, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::checkbox({ + name=>$name, + value=>$value, + checked=>$checked, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + if ($checked) { + $output = WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); + } + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 checkList ( name, options [ label, value, vertical, extras, subtext ] ) +=head2 checkList ( name, options [ label, value, vertical, extras, subtext, uiLevel ] ) Adds a checkbox list row to this form. @@ -185,36 +221,40 @@ sub checkbox { Extra text to describe this form element or to provide special instructions. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub checkList { - my ($label, $subtext, $class, $output, $vertical, $value, $key, $item, $name, $options, $extras); - $class = shift; - $name = shift; - $options = shift; - $label = shift; - $value = shift; - $vertical = shift; - $extras = shift; - $subtext = shift; - foreach $key (keys %{$options}) { - $output .= ''.${$options}{$key}.'    '; - $output .= '
' if ($vertical); - } - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $options, $label, $value, $vertical, $extras, $subtext, $uiLevel) = + rearrange([name, options, label, value, vertical, extras, subtext, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::checkList({ + name=>$name, + options=>$options, + value=>$value, + vertical=>$vertical, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + hiddenList({ + options=>$options, + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 combo ( name, options [ label, value, size, multiple, extras, subtext ] ) +=head2 combo ( name, options [ label, value, size, multiple, extras, subtext, uiLevel ] ) Adds a combination select list / text box row to this form. If the text box is filled out it will have a value stored in "name"_new @@ -260,43 +300,41 @@ sub checkList { Extra text to describe this form element or to provide special instructions. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub combo { - my ($label, $subtext, $class, $output, $value, $key, $item, $name, $options, $size, $multiple, $extras); - $class = shift; - $name = shift; - $options = shift; - ${$options}{''} = '['.WebGUI::International::get(582).']'; - $label = shift; - $value = shift; - $size = shift || 1; - $multiple = shift; - $multiple = ' multiple="1"' if ($multiple); - $extras = shift; - $subtext = shift; - $output = ''; - $size = $session{setting}{textBoxSize}-5; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 date ( name [ label, value, extras, subtext, size, noDate ] ) +=head2 date ( name [ label, value, extras, subtext, size, noDate, uiLevel ] ) Adds a date row to this form. @@ -335,36 +373,42 @@ sub combo { By default a date is placed in the "value" field. Set this to "1" to turn off the default date. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub date { - my ($subtext, $noDate, $class, $output, $name, $label, $extras, $size, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $value = epochToSet($value); - $extras = shift; - $subtext = shift; - $size = shift || 10; - $noDate = shift; - $value = "" if ($noDate); - $output = ''; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $extras, $subtext, $size, $noDate, $uiLevel) = + rearrange([name, label, value, extras, subtext, size, noDate, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::date({ + name=>$name, + value=>$value, + noDate=>$noDate, + size=>$size, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 email ( name [ label, value, maxlength, extras, subtext, size ] ) +=head2 email ( name [ label, value, maxlength, extras, subtext, size, uiLevel ] ) Adds an email address row to this form. @@ -402,31 +446,41 @@ sub date { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub email { - my ($subtext, $class, $output, $name, $label, $extras, $size, $maxLength, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $value = _fixQuotes($value); - $maxLength = shift || 255; - $extras = shift; - $subtext = shift; - $size = shift || $session{setting}{textBoxSize} || 30; - $output = ''; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $maxlength, $extras, $subtext, $size, $uiLevel) = + rearrange([name, label, value, maxlength, extras, subtext, size, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::email({ + name=>$name, + value=>$value, + maxlength=>$maxlength, + size=>$size, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 file ( name [ label, subtext, extras, size ] ) +=head2 file ( name [ label, subtext, extras, size, uiLevel ] ) Adds a file browse row to this form. @@ -456,25 +510,33 @@ sub email { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub file { - my ($subtext, $class, $output, $name, $label, $extras, $size, $value); - $class = shift; - $name = shift; - $label = shift; - $subtext = shift; - $extras = shift; - $size = shift || $session{setting}{textBoxSize} || 30; - $output = ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $subtext, $extras, $size, $uiLevel) = + rearrange([name, label, subtext, extras, size, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::file({ + name=>$name, + size=>$size, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 group ( name [ label, value, size, multiple, extras, subtext ] ) +=head2 group ( name [ label, value, size, multiple, extras, subtext, uiLevel ] ) Adds a group pull-down to this form. A group pull down provides a select list that provides name value pairs for all the @@ -514,38 +576,36 @@ sub file { Extra text to describe this form element or to provide special instructions. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub group { - my ($size, $multiple, %hash, $subtext, $class, $key, $item, $output, $name, $label, $extras, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - if ($$value[0] eq "") { #doing long form otherwise arrayRef didn't work - $value = [7]; - } - $size = shift || 1; - $multiple = shift; - $multiple = ' multiple="1" ' if ($multiple); - $extras = shift; - $subtext = shift; - tie %hash, 'Tie::IxHash'; - %hash = WebGUI::SQL->buildHash("select groupId,groupName from groups where groupName<>'Reserved' order by groupName"); - $output = ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + $self->{_data} .= $output; } #------------------------------------------------------------------- @@ -565,18 +625,17 @@ sub group { =cut sub hidden { - my ($class, $output, $name, $value); - $class = shift; - $name = shift; - $value = shift; - $value = _fixQuotes($value); - $output = ''; - $class->{_data} .= $output; + my ($self, @p) = @_; + my ($name, $value) = rearrange([name, value], @p); + $self->{_data} .= WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); } #------------------------------------------------------------------- -=head2 HTMLArea ( name [ label, value, subtext, extras, wrap, rows, columns ] ) +=head2 HTMLArea ( name [ label, value, subtext, extras, wrap, rows, columns, uiLevel ] ) Adds an HTML area row to this form. An HTML area is different than a standard text area in that it provides rich edit functionality @@ -623,57 +682,41 @@ sub hidden { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub HTMLArea { - my ($subtext, $class, $output, $name, $value, $columns, $rows, $wrap, $extras, $label); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $subtext = shift; - $extras = shift; - $wrap = shift || "virtual"; - $rows = shift || $session{setting}{textAreaRows} || 5; - $columns = shift || $session{setting}{textAreaCols} || 50; - $output = ''; - $value =~ s/\/\>\;/g; - if ($session{setting}{richEditor} eq "edit-on-pro") { - $output .= ''; - } else { - $output .= ''; - } - $output .= '
'; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $subtext, $extras, $wrap, $rows, $columns, $uiLevel) = + rearrange([name, label, value, subtext, extras, wrap, rows, columns, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::HTMLArea({ + name=>$name, + value=>$value, + wrap=>$wrap, + columns=>$columns, + rows=>$rows, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 integer ( name [ label, value, maxlength, extras, subtext, size ] ) +=head2 integer ( name [ label, value, maxlength, extras, subtext, size, uiLevel ] ) Adds an integer row to this form. @@ -712,41 +755,40 @@ sub HTMLArea { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub integer { - my ($subtext, $class, $output, $name, $label, $extras, $size, $maxLength, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift || 0; - $value = _fixQuotes($value); - $maxLength = shift || 11; - $extras = shift; - $subtext = shift; - $size = shift || 11; - $output = ''; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $maxlength, $extras, $subtext, $size, $uiLevel) = + rearrange([name, label, value, maxlength, extras, subtext, size, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::integer({ + name=>$name, + value=>$value, + maxlength=>$maxlength, + size=>$size, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 interval ( name [ label, intervalValue, unitsValue, extras, subtext ] ) +=head2 interval ( name [ label, intervalValue, unitsValue, extras, subtext, uiLevel ] ) Adds a time interval row to this form. @@ -784,51 +826,38 @@ sub integer { Extra text to describe this form element or to provide special instructions. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub interval { - my ($subtext, %units, $item, $key, $class, $output, $name, $label, $extras, $intervalValue, $unitsValue); - $class = shift; - $name = shift; - $label = shift; - $intervalValue = shift || 1; - $unitsValue = shift || "seconds"; - $extras = shift; - $subtext = shift; - tie %units, 'Tie::IxHash'; - %units = ('seconds'=>WebGUI::International::get(704), - 'minutes'=>WebGUI::International::get(705), - 'hours'=>WebGUI::International::get(706), - 'days'=>WebGUI::International::get(700), - 'weeks'=>WebGUI::International::get(701), - 'months'=>WebGUI::International::get(702), - 'years'=>WebGUI::International::get(703)); - $output = ''; - $output .= ''; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + $self->{_data} .= $output; } @@ -878,24 +907,26 @@ sub interval { =cut sub new { - my ($tableExtras, $header, $footer, $noTable, $enctype, $class, $method, $action, $extras); - $class = shift; - $noTable = shift || 0; - $action = shift || WebGUI::URL::page(); - $method = shift || "POST"; - $extras = shift; - $enctype = shift || "multipart/form-data"; - $tableExtras = shift; - $header = ''; + my ($noTable, $header, $footer); + my ($self, @p) = @_; + my ($noTable, $action, $method, $extras, $enctype, $tableExtras) = + rearrange([noTable, action, method, extras, enctype, tableExtras], @p); + $noTable = $noTable || 0; + $header = WebGUI::Form::formHeader({ + action=>$action, + extras=>$extras, + method=>$method, + enctype=>$enctype + }); $header .= '' unless ($noTable); $footer = '
' unless ($noTable); $footer .= '
'; - bless {_noTable => $noTable, _header => $header, _footer => $footer, _data => ''}, $class; + bless {_noTable => $noTable, _header => $header, _footer => $footer, _data => ''}, $self; } #------------------------------------------------------------------- -=head2 password ( name [ label, value, subtext, maxlength, extras, size ] ) +=head2 password ( name [ label, value, subtext, maxlength, extras, size, uiLevel ] ) Adds a password row to this form. @@ -935,29 +966,40 @@ sub new { should be no reason for anyone to specify this. Defaults to "30" unless overridden in the settings. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub password { - my ($subtext, $class, $output, $name, $label, $extras, $size, $maxLength, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $value = _fixQuotes($value); - $subtext = shift; - $maxLength = shift || 35; - $extras = shift; - $size = shift || $session{setting}{textBoxSize} || 30; - $output = ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $subtext, $maxlength, $extras, $size, $uiLevel) = + rearrange([name, label, value, subtext, maxlength, extras, size, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::password({ + name=>$name, + value=>$value, + size=>$size, + maxlength=>$maxlength, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name.'_interval', + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 phone ( name [ label, value, maxlength, extras, subtext, size ] ) +=head2 phone ( name [ label, value, maxlength, extras, subtext, size, uiLevel ] ) Adds a text row to this form. @@ -995,24 +1037,35 @@ sub password { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub phone { - my ($subtext, $class, $output, $name, $label, $extras, $size, $maxLength, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $value = _fixQuotes($value); - $maxLength = shift || 30; - $extras = shift; - $subtext = shift; - $size = shift || $session{setting}{textBoxSize} || 30; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $maxlength, $extras, $subtext, $size, $uiLevel) = + rearrange([name, label, value, maxlength, extras, subtext, size, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::phone({ + name=>$name, + value=>$value, + size=>$size, + maxlength=>$maxlength, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name.'_interval', + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- @@ -1024,9 +1077,7 @@ sub phone { =cut sub print { - my ($class); - $class = shift; - return $class->{_header}.$class->{_data}.$class->{_footer}; + return $_[0]->{_header}.$_[0]->{_data}.$_[0]->{_footer}; } #------------------------------------------------------------------- @@ -1039,14 +1090,12 @@ sub print { =cut sub printRowsOnly { - my ($class); - $class = shift; - return $class->{_data}; + return $_[0]->{_data}; } #------------------------------------------------------------------- -=head2 radio ( name [ label, checked, value, subtext, extras ] ) +=head2 radio ( name [ label, checked, value, subtext, extras, uiLevel ] ) Adds a radio button row to this form. @@ -1079,27 +1128,41 @@ sub printRowsOnly { 'onChange="this.form.submit()"' +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub radio { - my ($subtext, $checkedText, $class, $output, $name, $label, $extras, $checked, $value); - $class = shift; - $name = shift; - $label = shift; - $checked = shift; - $checkedText = ' checked="1"' if ($checked); - $value = shift; - $subtext = shift; - $extras = shift; - $output = ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $checked, $value, $subtext, $extras, $uiLevel) = + rearrange([name, label, checked, value, subtext, extras, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::checkbox({ + name=>$name, + value=>$value, + checked=>$checked, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + if ($checked) { + $output = WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); + } + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 radioList ( name, options [ label, value, vertical, extras, subtext ] ) +=head2 radioList ( name, options [ label, value, vertical, extras, subtext, uiLevel ] ) Adds a radio button list row to this form. @@ -1108,6 +1171,7 @@ sub radio { The name field for this form element. =item options + The list of options for this list. Should be passed as a hash reference. @@ -1117,8 +1181,7 @@ sub radio { =item value - The default value(s) for this form element. This should be passed - as an array reference. + The default value for this form element. =item vertical @@ -1138,52 +1201,64 @@ sub radio { Extra text to describe this form element or to provide special instructions. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub radioList { - my ($label, $subtext, $class, $output, $vertical, $value, $key, $item, $name, $options, $extras); - $class = shift; - $name = shift; - $options = shift; - $label = shift; - $value = shift; - $vertical = shift; - $extras = shift; - $subtext = shift; - foreach $key (keys %{$options}) { - $output .= ''.${$options}{$key}.'    '; - $output .= '
' if ($vertical); + my ($output); + my ($self, @p) = @_; + my ($name, $options, $label, $value, $vertical, $extras, $subtext, $uiLevel) = + rearrange([name, options, label, value, vertical, extras, subtext, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::checkList({ + name=>$name, + options=>$options, + value=>$value, + vertical=>$vertical, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + hiddenList({ + options=>$options, + value=>[$value] + }); } - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 raw ( value ) +=head2 raw ( value, uiLevel ) Adds raw data to the form. This is primarily useful with the printRowsOnly method and if you generate your own form elements. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub raw { - my ($class, $output, $value); - $class = shift; - $value = shift; - $class->{_data} .= $value; + my ($output); + my ($self, @p) = @_; + my ($value, $uiLevel) = rearrange([value, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $self->{_data} .= $value; + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 readOnly ( value [ label, subtext ] ) +=head2 readOnly ( value [ label, subtext, uiLevel ] ) Adds a read only row to this form. This is mainly used for displaying not editable properties, but it can also be used to @@ -1202,23 +1277,29 @@ sub raw { Extra text to describe this form element or to provide special instructions. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub readOnly { - my ($output, $subtext, $class, $label, $value); - $class = shift; - $value = shift; - $label = shift; - $subtext = shift; - $output = $value; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($value, $label, $subtext, $uiLevel) = + rearrange([value, label, subtext, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = $value; + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 select ( name, options [ label, value, size, multiple, extras, subtext ] ) +=head2 select ( name, options [ label, value, size, multiple, extras, subtext, uiLevel ] ) Adds a select list row to this form. @@ -1262,34 +1343,36 @@ sub readOnly { Extra text to describe this form element or to provide special instructions. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub select { - my ($label, $subtext, $class, $output, $value, $key, $item, $name, $options, $size, $multiple, $extras); - $class = shift; - $name = shift; - $options = shift; - $label = shift; - $value = shift; - $size = shift || 1; - $multiple = shift; - $multiple = ' multiple="1"' if ($multiple); - $extras = shift; - $subtext = shift; - $output = ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($value, $label, $extras, $subtext) = rearrange([value, label, extras, subtext], @p); + $output = WebGUI::Form::submit({ + value=>$value, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 text ( name [ label, value, maxlength, extras, subtext, size ] ) +=head2 text ( name [ label, value, maxlength, extras, subtext, size, uiLevel ] ) Adds a text row to this form. @@ -1376,29 +1457,40 @@ sub submit { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub text { - my ($subtext, $class, $output, $name, $label, $extras, $size, $maxLength, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $value = _fixQuotes($value); - $maxLength = shift || 255; - $extras = shift; - $subtext = shift; - $size = shift || $session{setting}{textBoxSize} || 30; - $output = ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $maxlength, $extras, $subtext, $size, $uiLevel) = + rearrange([name, label, value, maxlength, extras, subtext, size, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::text({ + name=>$name, + value=>$value, + size=>$size, + maxlength=>$maxlength, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name.'_interval', + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 textarea ( name [ label, value, subtext, extras, wrap, rows, columns ] ) +=head2 textarea ( name [ label, value, subtext, extras, wrap, rows, columns, uiLevel ] ) Adds a text area row to this form. @@ -1442,29 +1534,41 @@ sub text { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub textarea { - my ($subtext, $class, $output, $name, $value, $columns, $rows, $wrap, $extras, $label); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $subtext = shift; - $extras = shift; - $wrap = shift || "virtual"; - $rows = shift || $session{setting}{textAreaRows} || 5; - $columns = shift || $session{setting}{textAreaCols} || 50; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $subtext, $extras, $wrap, $rows, $columns, $uiLevel) = + rearrange([name, label, value, subtext, extras, wrap, rows, columns, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::textarea({ + name=>$name, + value=>$value, + wrap=>$wrap, + columns=>$columns, + rows=>$rows, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 url ( name [ label, value, maxlength, extras, subtext, size ] ) +=head2 url ( name [ label, value, maxlength, extras, subtext, size, uiLevel ] ) Adds a URL row to this form. @@ -1503,32 +1607,40 @@ sub textarea { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub url { - my ($subtext, $class, $output, $name, $label, $extras, $size, $maxLength, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $value = _fixQuotes($value); - $maxLength = shift || 2048; - $extras = shift; - $subtext = shift; - $size = shift || $session{setting}{textBoxSize} || 30; - $output = ''; - $output .= ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $maxlength, $extras, $subtext, $size, $uiLevel) = + rearrange([name, label, value, maxlength, extras, subtext, size, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::url({ + name=>$name, + value=>$value, + size=>$size, + maxlength=>$maxlength, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name.'_interval', + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 yesNo ( name [ label, value, extras, subtext ] ) +=head2 yesNo ( name [ label, value, extras, subtext, uiLevel ] ) Adds a yes/no radio menu to this form. @@ -1558,31 +1670,39 @@ sub url { Extra text to describe this form element or to provide special instructions. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub yesNo { - my ($subtext, $class, $output, $name, $label, $extras, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift || 0; - $extras = shift; - $subtext = shift; - $output = ''.WebGUI::International::get(138); - $output .= '   '; - $output .= ''.WebGUI::International::get(139); - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $extras, $subtext, $uiLevel) = + rearrange([name, label, value, extras, subtext, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::yesNo({ + name=>$name, + value=>$value, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $value = 0 unless ($value); + $output = WebGUI::Form::hidden({ + name=>$name, + value=>$value + }); + } + $self->{_data} .= $output; } #------------------------------------------------------------------- -=head2 zipcode ( name [ label, value, maxlength, extras, subtext, size ] ) +=head2 zipcode ( name [ label, value, maxlength, extras, subtext, size, uiLevel ] ) Adds a zip code row to this form. @@ -1620,27 +1740,39 @@ sub yesNo { The number of characters wide this form element should be. There should be no reason for anyone to specify this. +=item uiLevel + + The UI level for this field. See the WebGUI developer's site for + details. Defaults to "0". + =cut sub zipcode { - my ($subtext, $class, $output, $name, $label, $extras, $size, $maxLength, $value); - $class = shift; - $name = shift; - $label = shift; - $value = shift; - $value = _fixQuotes($value); - $maxLength = shift || 255; - $extras = shift; - $subtext = shift; - $size = shift || $session{setting}{textBoxSize} || 30; - $output = ''; - $output .= _subtext($subtext); - $output = _tableFormRow($label,$output) unless ($class->{_noTable}); - $class->{_data} .= $output; + my ($output); + my ($self, @p) = @_; + my ($name, $label, $value, $maxlength, $extras, $subtext, $size, $uiLevel) = + rearrange([name, label, value, maxlength, extras, subtext, size, uiLevel], @p); + if (_uiLevelChecksOut($uiLevel)) { + $output = WebGUI::Form::zipcode({ + name=>$name, + value=>$value, + size=>$size, + maxlength=>$maxlength, + extras=>$extras + }); + $output .= _subtext($subtext); + $output = $self->_tableFormRow($label,$output); + } else { + $output = WebGUI::Form::hidden({ + name=>$name.'_interval', + value=>$value + }); + } + $self->{_data} .= $output; } 1; + diff --git a/lib/WebGUI/Macro/AdminBar.pm b/lib/WebGUI/Macro/AdminBar.pm index 767f167ee..9f5886319 100644 --- a/lib/WebGUI/Macro/AdminBar.pm +++ b/lib/WebGUI/Macro/AdminBar.pm @@ -12,7 +12,7 @@ package WebGUI::Macro::AdminBar; use strict; use Tie::IxHash; -use WebGUI::HTMLForm; +use WebGUI::Form; use WebGUI::International; use WebGUI::Privilege; use WebGUI::Session; @@ -22,7 +22,7 @@ use WebGUI::Utility; #------------------------------------------------------------------- sub _replacement { - my (%hash2, $f, $miscSelect, $adminSelect, $clipboardSelect, %hash, $output, $contentSelect, $key); + my (%hash2, $miscSelect, $adminSelect, $clipboardSelect, %hash, $output, $contentSelect, $key); tie %hash, "Tie::IxHash"; tie %hash2, "Tie::IxHash"; #--content adder @@ -34,9 +34,11 @@ sub _replacement { } %hash2 = sortHash(%hash2); %hash = (%hash, %hash2); - $f = WebGUI::HTMLForm->new(1); - $f->select("contentSelect",\%hash,'',[],'','','onChange="goContent()"'); - $contentSelect = $f->printRowsOnly; + $contentSelect = WebGUI::Form::selectList({ + name=>"contentSelect", + options=>\%hash, + extras=>'onChange="goContent()"' + }); #--clipboard paster %hash2 = (); $hash2{WebGUI::URL::page()} = WebGUI::International::get(3); @@ -48,9 +50,11 @@ sub _replacement { foreach $key (keys %hash) { $hash2{WebGUI::URL::page('func=paste&wid='.$key)} = $hash{$key}; } - $f = WebGUI::HTMLForm->new(1); - $f->select("clipboardSelect",\%hash2,'',[],'','','onChange="goClipboard()"'); - $clipboardSelect = $f->printRowsOnly; + $clipboardSelect = WebGUI::Form::selectList({ + name=>"clipboardSelect", + options=>\%hash2, + extras=>'onChange="goClipboard()"' + }); #--admin functions %hash = (); if (WebGUI::Privilege::isInGroup(3,$session{user}{userId})) { @@ -106,9 +110,11 @@ sub _replacement { WebGUI::URL::page('op=switchOffAdmin')=>WebGUI::International::get(12), %hash ); - $f = WebGUI::HTMLForm->new(1); - $f->select("adminSelect",\%hash,'',[],'','','onChange="goAdmin()"'); - $adminSelect = $f->printRowsOnly; + $adminSelect = WebGUI::Form::selectList({ + name=>"adminSelect", + options=>\%hash, + extras=>'onChange="goAdmin()"' + }); #--output admin bar $output = '