diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 80fdd08a0..b0fdfaba5 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -7,6 +7,140 @@ Commerce merge amounts of money using the new commerce system. - Merged all the old shipping plugins into one "Flat Rate" shipping plugin. See gotchas. + +7.5.11 + - fix: template variable isUncommitted is not documented in the help + - Cleaned the pollution from the forms system. + - fix: Event is no longer editable by anyone who can add events + - fixed: Package search is slow for large websites + - fixed: rich editor image picker displays incorrectly in IE + +7.5.10 + - fix: Syntax error in GetCsMail + - fix: Trapped an exception for corrupt config files. + - fixed: Thingy: field types not in alphabetical order + - fixed: Thingy: Text, File and Hidden field types listed twice (Yung Han Khoe) + - fixed: Thingy: subtext is not displayed + - fixed: Thingy: edit/add field popup doesn't fit all options + - fixed: selecting some field types will crash Thingy + - fixed: Thingy: "add" and "edit" permission problem + - fixed: EMail field rejects some valid email addresses + - fixed: Calendar date localization can be broken + - fixed: Thingy: field sequence not imported correctly for existing Thingies + - fixed: anonymous registration leaves user at blank page + - fixed: Thingy: field type 'other thing' does not stay selected + - fixed: Thingy: delete a thing dysfunctions linked things + - fixed: i18n discrepencies in Gallery / GalleryAlbum / Photo + - fixed: After saving Photo, Add an Image points to wrong link + - fixed: "Back to Album" link doesn't work + - fixed: email validation links can be broken by mail servers + - fixed: Clipboard select all doesn't work with one item in IE + - fixed: able to view visitor profile, send private messages, add as friend + - fixed: international characters corrupted in titles + - fixed: Users without karma can transfer karma by rating posts + - fixed: gateway macro not usable in links in rich editor + - fixed: iCal feeds don't update properly when events are changed + - fixed: getLineage with joinClass only joins first table in definition + +7.5.9 + - fixed: Collaboration System attachments follow site's max size instead of CS's + - fixed: Rich editor image uploader doesn't follow size limits + - fixed: Poll question/answers with international text corrupted + - fixed: Thingy: on demo sites the edit and delete icons in search results have wrong url's + - fixed: Form::FieldType->getTypes should exclude Form::Slider base class (Yung Han Khoe) + - upgraded to TinyMCE 3 + - fixed: subscription group in CS edit not internationalized + - fixed: profile photos don't obey max image size + - fixed: Unable to communicate with Spectre under alternate locales + - fixed: Project Manager can't track non-integer durations + - fixed: Unable to edit CS posts that were denied as a normal user + - added: Better error messages when SQL Report lacks a query (William McKee, Knowmad Technologies) + - fixed: edit branch sends thread notifications + - fixed: changing style template with edit branch creates new revisions of assets that have no style template + - fixed: Wiki attachments uploaded by non-Content Managers deleted by maintenance workflow + - fixed: Non-Content managers unable to paste assets even with edit privaledges + - use UTF8 JSON encoding and decoding universally + - fixed: Import/Export of packages with international text is broken + - fixed: CS rating links are exposed to site spiders + - improved behavior of CS mail message filtering + - fixed: Thingy: "cancel" -- cannot cancel when adding a thing + - fixed: unable to respond to survey multiple times in same session + - fixed: packages try to restore owner + +7.5.8 + - moved Gallery utility methods to WebGUI::Utility::Gallery + - Added tests for GalleryAlbum RSS + - More tests for comments + - Test International Macro sprintf as third+ arguments + - Add Gallery search limiting by user ID + - Remaining i18n for Gallery templates + - Fix: Search form now visible in Photo assets + - Added hover help in Thingy's yui popups + - Thingy now shows all field types when editing a field + - Added an optionsSettable flag to form types that have an options property (Yung Han Khoe) + - fixed: Editting matrix listings shows fields from other matrix assets + - fixed: Matrix assets show pending listings from all matrix assets on a site + - fixed: Changing name of Matrix listing leaves discussion forum with old name + - fixed: Importing a package can break when updating a pending asset + - fixed: errors on package importing are always reported as corrupted packages + - fixed: Optional pubDate RSS field generates warnings when missing + - fixed: Collaboration System threads can return other object types when asked for replies + - fixed: Able to cut or trash system assets + - fixed: Can't purge uncommitted assets if not using its version tag + - fixed: DataForm will create fields with duplicate names but doesn't use them separately + - fixed: Bad message if database link for SQL Report doesn't exist + - fixed: Thingy shows things from other Thingies + - fixed: Collaboration System errors when missing RSS From Parent + - fixed: Syndicated Content picks wrong entries for interleaving + - fixed: Syndicated Content URLs using macros not updated by caching workflow + - fixed: Syndicated Content asset tries too hard to get URLs returning errors + - fixed: Thingy: field type includes things without fields + - fixed: Thingy: problems editing/viewing records + - fix: Users now have permission to add comments + - fix: Username for comment poster is now shown correctly + - fix: Slideshow now works + - added: Database index on userSession.expires field to speed up workflows + +7.5.7 + - fixed: HttpProxy mixes original site's content encoding with WebGUI's + - fixed: Thingy i18n has an empty message + - fixed: Thingy has no icon + - fixed: Wiki page history shows username instead of alias + - added: Uploads locations and files are set to the same uid/gid that owns the uploads root + - fixed: SQL Form fields with a regex are required even if not set to required + - fixed: Matrix caches pages, and may not update for new listings + +7.5.6 + - fixed: events get start/end time even when none specified (also can offset start/end day) + - fixed: event related links may not work with some group names + - Use UTF8 for database connection when connecting to MySQL + - Convert all database tables to UTF8, repairing erroneous data + - Internationalized Calendar templates + - fixed: exporting as HTML leaks sessions for inaccessible assets, + - new YUI based date picker + - fixed: changing image thumbnail size doesn't resize image + - fixed: loadAddConfigs loads hidden files + - ensure proper XML encoding for ITransact messages + - fixed: fatal error duplicate keywords added to a wiki page + - rfe: added the ability to choose whether assets should be added to the front or end of the first content position of the page (Dept of State) + - Added Thingy asset + +7.5.5 + - fixed: Several typos in the new Calendar help documentation. + - fix: List View now starts at the beginning of the day passed in. + - Removed some spurious warnings from the calendar. + - Added ability to edit comments. Entirely changed how comments work in prep + for turning it into a mixin. + - fixed: Child assets not indicated by plus sign in uncommited tags + - Added WebGUI::Asset::File::GalleryFile as a subclass for all files to be + used inside the Gallery. + - Changed WebGUI::Asset::File::Image::Photo to subclass GalleryFile + +7.5.4 + - fixed: unable to remove calendar feeds in IE6 + - Moved the Wiki Help link into i18n so it can be pointed to other sites for + other lanugages. +>>>>>>> .merge-right.r6153 - The YUI library used in WebGUI has been upgraded to 2.5.0. - The resizable text area implementation used in WebGUI has been migrated to the code provided by YUI 2.5.0. diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index c27450791..13a0c9ef2 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -270,7 +270,7 @@ Get the storage location created by the form post. sub getStorageFromPost { my $self = shift; my $storageId = shift; - my $fileStorageId = WebGUI::Form::File->new($self->session, {name => 'newFile', value=>$storageId })->getValueFromPost; + my $fileStorageId = WebGUI::Form::File->new($self->session, {name => 'newFile', value=>$storageId })->getValue; $self->session->errorHandler->info( "File Storage Id: $fileStorageId" ); return $self->getStorageClass->get($self->session, $fileStorageId); } diff --git a/lib/WebGUI/Asset/FilePile.pm b/lib/WebGUI/Asset/FilePile.pm index d7fe31438..9d38b5f7e 100644 --- a/lib/WebGUI/Asset/FilePile.pm +++ b/lib/WebGUI/Asset/FilePile.pm @@ -143,7 +143,7 @@ sub editSave { my $self = shift; ##This is a hack. File uploads should go through the WebGUI::Form::File API - my $tempFileStorageId = WebGUI::Form::File->new($self->session,{name => 'file'})->getValueFromPost; + my $tempFileStorageId = WebGUI::Form::File->new($self->session,{name => 'file'})->getValue; my $tempStorage = WebGUI::Storage::Image->get($self->session, $tempFileStorageId); foreach my $filename (@{$tempStorage->getFiles}) { diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 0ab34a047..681dcd368 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -701,7 +701,7 @@ sub www_editListingSave { versionNumber=>$self->session->form->process("versionNumber") ); - my $storageId = WebGUI::Form::Image->new($self->session,{name => 'screenshot', value => $listing->{storageId}})->getValueFromPost; + my $storageId = WebGUI::Form::Image->new($self->session,{name => 'screenshot', value => $listing->{storageId}})->getValue; if ($storageId) { $data{storageId} = $storageId; $data{filename} = WebGUI::Storage->get($self->session, $storageId)->getFiles->[0]; diff --git a/lib/WebGUI/Form/Asset.pm b/lib/WebGUI/Form/Asset.pm index f78598c1d..6e1ec7822 100644 --- a/lib/WebGUI/Form/Asset.pm +++ b/lib/WebGUI/Form/Asset.pm @@ -69,9 +69,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session, "Asset"); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("asset"), - }, label=>{ defaultValue=>$i18n->get("asset"), }, @@ -81,15 +78,67 @@ sub definition { class=>{ defaultValue=> undef }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "VARCHAR(22) BINARY". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(22) BINARY"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'Asset')->get('asset'); +} + +#------------------------------------------------------------------- + +=head2 getValueAsHtml ( ) + +Formats as a link. + +=cut + +sub getValueAsHtml { + my $self = shift; + my $asset = WebGUI::Asset->newByDynamicClass($self->session,$self->getValue); + if (defined $asset) { + return ''.$asset->getTitle.''; + } + return undef; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders an asset selector. @@ -98,7 +147,7 @@ Renders an asset selector. sub toHtml { my $self = shift; - my $asset = WebGUI::Asset->newByDynamicClass($self->session, $self->get("value")) || WebGUI::Asset->getRoot($self->session); + my $asset = WebGUI::Asset->newByDynamicClass($self->session, $self->getDefaultValue) || WebGUI::Asset->getRoot($self->session); my $url = $asset->getUrl("op=formHelper;sub=assetTree;class=Asset;formId=".$self->get('id')); $url .= ";classLimiter=".$self->get("class") if ($self->get("class")); return WebGUI::Form::Hidden->new($self->session, diff --git a/lib/WebGUI/Form/Attachments.pm b/lib/WebGUI/Form/Attachments.pm index 96d3f0b6b..ce555d53a 100644 --- a/lib/WebGUI/Form/Attachments.pm +++ b/lib/WebGUI/Form/Attachments.pm @@ -34,7 +34,7 @@ conjunction with one or more Rich Editors (see WebGUI::Form::HTMLArea) and shoul list for ease of use. B This form control is not capable of handling all aspects of the files uploaded to it. So you as the -developer need to complete the process after the form has been submitted. See the getValueFromPost() method for +developer need to complete the process after the form has been submitted. See the getValue() method for details. =head1 SEE ALSO @@ -85,11 +85,7 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("file") - }, name=>{ defaultValue=>"attachments" }, @@ -98,26 +94,45 @@ sub definition { }, maxImageSize=>{}, thumbnailSize=>{}, - profileEnabled=>{ - defaultValue=>0 - }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getDatabaseFieldType ( ) + +Returns "VARCHAR(22) BINARY". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(22) BINARY"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('Attachments formName'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) Returns an array reference of asset ids that have been uploaded. New assets are uploaded to a temporary location, and you must move them to the place in the asset tree you want them, or they will be automatically deleted. =cut -sub getValueFromPost { +sub getValue { my $self = shift; my @values = $self->session->form->param($self->get("name")); return \@values; @@ -133,7 +148,7 @@ Renders an attachments control. sub toHtml { my $self = shift; - my @assetIds = @{$self->get("value")}; + my @assetIds = @{$self->getDefaultValue}; my $thumbnail = $self->get("thumbnailSize") || $self->session->setting->get("thumbnailSize"); my $image = $self->get("maxImageSize") || $self->session->setting->get("maxImageSize"); my $attachmentsList = "attachments=".join(";attachments=", @assetIds) if (scalar(@assetIds)); diff --git a/lib/WebGUI/Form/Button.pm b/lib/WebGUI/Form/Button.pm index b6d663408..6642db7c9 100644 --- a/lib/WebGUI/Form/Button.pm +++ b/lib/WebGUI/Form/Button.pm @@ -58,21 +58,28 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session,"WebGUI"); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get('button') - }, defaultValue=>{ defaultValue=>$i18n->get(62) }, - dbDataType => { - defaultValue => "VARCHAR(255)", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('button'); +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a button. @@ -81,7 +88,7 @@ Renders a button. sub toHtml { my $self = shift; - my $value = $self->fixQuotes($self->get("value")); + my $value = $self->fixQuotes($self->getDefaultValue); my $html = 'get("name").'" ' if ($self->get("name")); $html .= 'id="'.$self->get('id').'" ' unless ($self->get('id') eq "_formId"); diff --git a/lib/WebGUI/Form/Captcha.pm b/lib/WebGUI/Form/Captcha.pm index 92c17f691..e428c2512 100644 --- a/lib/WebGUI/Form/Captcha.pm +++ b/lib/WebGUI/Form/Captcha.pm @@ -51,10 +51,6 @@ The following additional parameters have been added via this sub class. Defaults to "Verify Your Humanity" -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { @@ -63,33 +59,49 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session,"Form_Captcha"); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("topicName") - }, label => { defaultValue=>$i18n->get("verify your humanity") }, - profileEnabled=>{ - defaultValue=>0 - }, - dbDataType => { - defaultValue => "VARCHAR(6)", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getDatabaseFieldType ( ) + +Returns "BOOLEAN". + +=cut + +sub getDatabaseFieldType { + return "BOOLEAN"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'Form_Captcha')->get('topicName'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) Returns a boolean indicating whether the string typed matched the image. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = $self->session->form->param($self->get("name")); + my $value = $self->SUPER::getValue(@_); my $challenge = $self->session->scratch->get("captcha_".$self->get("name")); $self->session->scratch->delete("captcha_".$self->get("name")); return (lc($value) eq lc($challenge)); @@ -97,6 +109,18 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a captcha field. diff --git a/lib/WebGUI/Form/CheckList.pm b/lib/WebGUI/Form/CheckList.pm index c3a4c621b..183838410 100644 --- a/lib/WebGUI/Form/CheckList.pm +++ b/lib/WebGUI/Form/CheckList.pm @@ -52,10 +52,6 @@ The following additional parameters have been added via this sub class. Boolean representing whether the checklist should be represented vertically or horizontally. If set to "1" will be displayed vertically. Defaults to "0". -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =head4 showSelectAllButton Flag that toggles a "Select All" toggle button on or off. @@ -66,17 +62,10 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push @{$definition}, { - formName => { - defaultValue => $i18n->get("941"), - }, vertical => { defaultValue => 0, }, - profileEnabled => { - defaultValue => 1, - }, showSelectAll => { defaultValue => 0, }, @@ -86,6 +75,19 @@ sub definition { #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('941'); +} + +#------------------------------------------------------------------- + =head2 getSelectAllButton ( ) Returns the HTML / Script for the Select All button @@ -115,6 +117,18 @@ sub getSelectAllButton { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a series of checkboxes. @@ -131,23 +145,21 @@ sub toHtml { $output .= $self->getSelectAllButton; } my $i=0; - tie my %options, 'Tie::IxHash', $self->orderedHash(); - foreach my $key (keys %options) { - $i++; + my $options = $self->getOptions; + foreach my $key (keys %{$options}) { + $i++; my $checked = (grep { $_ eq $key } @{ $self->correctValues($self->get('value')) }) ? 1 : 0 ; - - $output - .= WebGUI::Form::Checkbox->new($self->session, { + $output .= WebGUI::Form::Checkbox->new($self->session, { name => $self->get('name'), value => $key, extras => $self->get('extras'), checked => $checked, id => $self->get('name').$i, })->toHtml - . '" + . '" . $alignment ; } diff --git a/lib/WebGUI/Form/Checkbox.pm b/lib/WebGUI/Form/Checkbox.pm index 47fcf44eb..3e56dc8d9 100644 --- a/lib/WebGUI/Form/Checkbox.pm +++ b/lib/WebGUI/Form/Checkbox.pm @@ -53,30 +53,19 @@ Defaults to "0". Set to "1" if this field should be checked. The value returned by this field if it is checked and no value is specified. Defaults to "1". -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("943"), - }, checked=>{ defaultValue=> 0 }, defaultValue=>{ defaultValue=>1 }, - profileEnabled=>{ - defaultValue=>0 - } }); return $class->SUPER::definition($session, $definition); } @@ -96,24 +85,27 @@ sub generateIdParameter { #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) -Retrieves a value from a form GET or POST and returns it. If the value comes back as undef, this method will return undef. - -=head3 value - -An optional value to process, instead of POST input. +Returns the human readable name of this control. =cut -sub getValueFromPost { - my $self = shift; - my $formValue = @_ ? shift : $self->session->form->param($self->get("name")); - if (defined $formValue) { - return $formValue; - } else { - return undef; - } +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('943'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; } #------------------------------------------------------------------- @@ -126,7 +118,7 @@ Renders and input tag of type checkbox. sub toHtml { my $self = shift; - my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value")))) || ''; + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))) || ''; my $checkedText = $self->get("checked") ? ' checked="checked"' : ''; my $idText = $self->get('id') ? ' id="'.$self->get('id').'" ' : ''; return 'get("extras")||'').' />'; diff --git a/lib/WebGUI/Form/ClassName.pm b/lib/WebGUI/Form/ClassName.pm index d93053810..6867cb5e1 100644 --- a/lib/WebGUI/Form/ClassName.pm +++ b/lib/WebGUI/Form/ClassName.pm @@ -36,47 +36,49 @@ The following methods are specifically available from this class. Check the supe =cut + #------------------------------------------------------------------- -=head2 definition ( [ additionalTerms ] ) +=head2 getName ( session ) -See the super class for additional details. +Returns the human readable name of this control. =cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>"Class Name" - }, - profileEnabled=>{ - defaultValue=>1 - }, - }); - return $class->SUPER::definition($session, $definition); +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('class name'); } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getValue ( ) Returns a class name which has been taint checked. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = @_ ? shift : $self->session->form->param($self->get("name")); + my $value = $self->SUPER::getValue(@_); $value =~ s/[^\w:]//g; return $value; } #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a class name field. diff --git a/lib/WebGUI/Form/Codearea.pm b/lib/WebGUI/Form/Codearea.pm index 07c4e14e1..bf4c7dc50 100644 --- a/lib/WebGUI/Form/Codearea.pm +++ b/lib/WebGUI/Form/Codearea.pm @@ -59,21 +59,13 @@ Style attributes besides width and height which should be specified using the ab The following additional parameters have been added via this sub class. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("codearea") - }, height=>{ defaultValue=> 450 }, @@ -83,18 +75,49 @@ sub definition { style=>{ defaultValue => undef, }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "TEXT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "MEDIUMTEXT". + +=cut + +sub getDatabaseFieldType { + return "MEDIUMTEXT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('codearea'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a code area field. diff --git a/lib/WebGUI/Form/Color.pm b/lib/WebGUI/Form/Color.pm index b0e950cea..70f84c577 100644 --- a/lib/WebGUI/Form/Color.pm +++ b/lib/WebGUI/Form/Color.pm @@ -38,31 +38,32 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- -=head2 definition ( ) +=head2 getDatabaseFieldType ( ) -See the super class for additional details. +Returns "VARCHAR(7)". -=cut +=cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("color") - }, - dbDataType => { - defaultValue => "VARCHAR(7)", - }, - }); - return $class->SUPER::definition($session, $definition); +sub getDatabaseFieldType { + return "VARCHAR(7)"; } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('color'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) Returns a hex color like "#000000". Returns undef if the return value is not a valid color. @@ -72,15 +73,27 @@ An optional value to use instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $color = @_ ? shift : $self->session->form->param($self->get("name")); + my $color = $self->SUPER::getValue(@_); return undef unless $color =~ /\#\w{6}/; return $color; } #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a color picker control. @@ -102,7 +115,7 @@ sub toHtml { $style->setScript($url->extras('/yui/build/slider/slider-min.js'),{ type=>'text/javascript' }); $style->setScript($url->extras('/colorpicker/colorpicker.js'),{ type=>'text/javascript' }); my $id = $self->get("id"); - my $value = $self->get("value"); + my $value = $self->getDefaultValue; return q| new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("combobox") - }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "TEXT", - }, - }); - return $class->SUPER::definition($session, $definition); +sub getDatabaseFieldType { + return "TEXT"; } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('combobox'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar. If @@ -91,18 +82,30 @@ Optional values to process, instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; if (@_) { - return $self->SUPER::getValueFromPost(@_); + return $self->SUPER::getValue(@_); } elsif ($self->session->form->param($self->get("name")."_new")) { my $formValue = $self->session->form->param($self->get("name")."_new"); $formValue =~ tr/\r\n//d; return $formValue; } - return $self->SUPER::getValueFromPost; + return $self->SUPER::getValue(@_); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; } #------------------------------------------------------------------- @@ -116,8 +119,9 @@ Renders a combo box form control. sub toHtml { my $self = shift; my $i18n = WebGUI::International->new($self->session); - $self->get("options")->{''} = '['.$i18n->get(582).']'; - $self->get("options")->{_new_} = $i18n->get(581).'->'; + my $options = $self->getOptions; + $options->{''} = '['.$i18n->get(582).']'; + $options->{_new_} = $i18n->get(581).'->'; return $self->SUPER::toHtml .WebGUI::Form::Text->new($self->session, size=>$self->session->setting->get("textBoxSize")-5, diff --git a/lib/WebGUI/Form/ContentType.pm b/lib/WebGUI/Form/ContentType.pm index 6253a656c..7b9fd84b4 100644 --- a/lib/WebGUI/Form/ContentType.pm +++ b/lib/WebGUI/Form/ContentType.pm @@ -38,6 +38,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -66,9 +78,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("1007") - }, label=>{ defaultValue=>$i18n->get("1007") }, @@ -77,13 +86,38 @@ sub definition { }, defaultValue=>{ defaultValue=>"mixed", - } - }); + }, + }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('1007'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a select list form control. diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm index bb8130c97..bad71ec33 100644 --- a/lib/WebGUI/Form/Control.pm +++ b/lib/WebGUI/Form/Control.pm @@ -15,7 +15,6 @@ package WebGUI::Form::Control; =cut use strict; -use WebGUI::Operation::Shared; use WebGUI::International; =head1 NAME @@ -41,6 +40,11 @@ Subclasses will look like this: my $html = $obj->toHtmlAsHidden; my $tableRows = $obj->toHtmlWithWrapper; + my $value = $obj->getValue; + my $value = $obj->getDefaultValue; + my $html = $obj->getValueAsHtml; + + =head1 METHODS The following methods are available via this package. @@ -50,23 +54,21 @@ The following methods are available via this package. #------------------------------------------------------------------- -=head2 privateName ( ) +=head2 areOptionsSettable ( ) -Creates a safe, private name for additional use in multi-part forms -like File and Image. +Returns a boolean indicating whether the options of the list are settable. Some have a predefined set of options. This is useful in generating dynamic forms. Really only used by form controls with an "options" field, which are mostly subclasses if WebGUI::Form::List. Returns 0. =cut -sub privateName { - my ($self, $action) = @_; - return join '_', '_', $self->get('name'), $action; +sub areOptionsSettable { + return 1; } #------------------------------------------------------------------- =head2 definition ( session, [ additionalTerms ] ) -Defines the schema or parameters for a form field. +Defines passible parameters for a form field. =head3 session @@ -109,10 +111,6 @@ Add extra attributes to the form tag like onmouseover='doSomething()' -=head4 formName - -The key to look up for the form name. - =head4 label A text label that will be displayed if toHtmlWithWrapper() is called. @@ -155,16 +153,6 @@ A stylesheet class assigned to each label/field pair. 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. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - -=head4 dbDataType - -The SQL data type for this form element. Fields created using this form control -will create a column with this data type. If undef, will not create a database -column. Defaults to "VARCHAR(255)". - =cut sub definition { @@ -172,9 +160,6 @@ sub definition { my $session = shift; my $definition = shift || []; push(@{$definition}, { - formName=>{ - defaultValue=>'A name for this form was not supplied' - }, name=>{ defaultValue=>undef }, @@ -220,12 +205,6 @@ sub definition { idPrefix=>{ defaultValue=>undef }, - profileEnabled=>{ - defaultValue=>0 - }, - dbDataType => { - defaultValue => "VARCHAR(255)", - }, }); return $definition; } @@ -234,51 +213,39 @@ sub definition { =head2 displayForm ( ) -This utility method is used to format values for the Profile system but can -be used in other areas as well. Most form elements will just return toHtml. +Depricated, see toHtml(). =cut sub displayForm { - my ($self) = @_; - $self->toHtml; + my $self = shift; + return $self->toHtml(@_); } #------------------------------------------------------------------- =head2 displayFormWithWrapper ( ) -This utility method is used to format values for the Profile system but can -be used in other areas as well. Most form elements will just return displayForm. +Depricated, see toHtmlWithWrapper(). =cut sub displayFormWithWrapper { my $self = shift; - if ($self->passUiLevelCheck) { - my ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext) = $self->prepareWrapper; - $hoverHelp &&= '
' . $hoverHelp . '
'; - return ' - '.$self->get("label") . $hoverHelp . ' - '.$self->displayForm().$subtext." - \n"; - } else { - return $self->toHtmlAsHidden; - } + return $self->toHtmlWithWrapper(@_); } #------------------------------------------------------------------- =head2 displayValue ( ) -This utility method is used to format values for the Profile system. Most -form elements will just return their value. +Depricated, see getValueAsHtml(). =cut sub displayValue { my ($self) = @_; - return $self->get("value"); + return $self->getValueAsHtml; } #------------------------------------------------------------------- @@ -300,39 +267,6 @@ sub generateIdParameter { } -#------------------------------------------------------------------- - -=head2 get ( var ) - -Returns a property of this form object. - -=head3 var - -The variable name of the value to return. - -=cut - -sub get { - my $self = shift; - my $var = shift; - return $self->{_params}{$var}; -} - -#------------------------------------------------------------------- - -=head2 getName ( ) - -Returns a human readable name for this form control type. You MUST override this method with your own when creating new form controls. - -=cut - -sub getName { - my $self = shift; - my $session = shift; - my $definition = $self->definition($session); - return $definition->[0]->{formName}->{defaultValue}; -} - #------------------------------------------------------------------- @@ -348,9 +282,9 @@ The string to search for macros in. sub fixMacros { my $self = shift; - my $value = shift; - $value =~ s/\^/\&\#94\;/g; - return $value; + my $value = shift; + $value =~ s/\^/\&\#94\;/g; + return $value; } #------------------------------------------------------------------- @@ -413,9 +347,52 @@ sub fixTags { #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 get ( var ) -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. +Returns a property of this form object. + +=head3 var + +The variable name of the value to return. + +=cut + +sub get { + my $self = shift; + my $var = shift; + return $self->{_params}{$var}; +} + +#------------------------------------------------------------------- + +=head2 getDatabaseFieldType ( ) + +A class method that tells you what database field type this form field should be stored in. Defaults to "VARCHAR(255)". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(255)"; +} + + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns a human readable name for this form control type. You MUST override this method with your own when creating new form controls. + +=cut + +sub getName { + return "Override Me"; +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) + +Gets the value of this form field from the following sources in order: passed in value, form post/get value, definition value, definition default value. =head3 value @@ -423,30 +400,75 @@ An optional value to process, instead of POST input. =cut +sub getValue { + my ($self, $value) = @_; + return $value if (defined $value); + if ($self->session->request) { + $value = $self->session->form->param($self->get("name")); + return $value if (defined $value); + } + return $self->getDefaultValue; +} + +#------------------------------------------------------------------- + +=head2 getDefaultValue ( ) + +Returns the either the "value" ore "defaultValue" passed in to the object in that order, and doesn't take into account form processing. + +=cut + +sub getDefaultValue { + my $self = shift; + my $value = $self->get("value"); + return $value if (defined $value); + return $self->get("defaultValue"); +} + + +#------------------------------------------------------------------- + +=head2 getValueAsHtml ( ) + +Returns the value rendered suitably in HTML. This is useful for forms that are rendered dynamically like user profiling and Thingy. + +=cut + +sub getValueAsHtml { + my $self = shift; + return $self->getValue(@_); +} + +#------------------------------------------------------------------- + +=head2 getValueFromPost + +Depricated. See getValue(). + +=cut + sub getValueFromPost { - my $self = shift; - my $formValue; + my $self = shift; + return $self->getValue(@_); +} - if (@_) { - $formValue = shift; - } - elsif ($self->session->request) { - $formValue = $self->session->form->param($self->get("name")); - } +#------------------------------------------------------------------- - if (defined $formValue) { - return $formValue; - } else { - return $self->get("defaultValue"); - } +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; } #------------------------------------------------------------------- =head2 isProfileEnabled ( session ) -A class method. Returns a 1 if this control can be used by the profiling system. In general that means that the -field is safe for dynamic generation. +Depricated. See isDynamicCompatible(). =cut @@ -454,7 +476,7 @@ field is safe for dynamic generation. sub isProfileEnabled { my $class = shift; my $session = shift; - return $class->definition($session)->[0]{profileEnabled}; + return $class->isDynamicCompatible(); } @@ -526,6 +548,29 @@ sub new { } +#------------------------------------------------------------------- + +=head2 passUiLevelCheck ( ) + +Renders the form field to HTML as a table row complete with labels, subtext, hoverhelp, etc. + +=cut + +sub passUiLevelCheck { + my $self = shift; + my $passUiLevelCheck = 0; + my $override = $self->session->config->get($self->get("uiLevelOverride")."_uiLevel"); + if (defined $override && $override->{$self->get("name")}) { # use override if it exists + $passUiLevelCheck = ($override->{$self->get("name")} <= $self->session->user->profileField("uiLevel")); + } else { # use programmed default + $passUiLevelCheck = ($self->get("uiLevel") <= $self->session->user->profileField("uiLevel")); + } + $passUiLevelCheck = $self->session->user->isInGroup(3) unless ($passUiLevelCheck); # override if in admins group + return $passUiLevelCheck; +} + + + #------------------------------------------------------------------- =head2 prepareWrapper ( ) @@ -550,6 +595,19 @@ sub prepareWrapper { } +#------------------------------------------------------------------- + +=head2 privateName ( ) + +Creates a safe, private name for additional use in multi-part forms like File and Image. + +=cut + +sub privateName { + my ($self, $action) = @_; + return join '_', '_', $self->get('name'), $action; +} + #------------------------------------------------------------------- =head2 session ( ) @@ -636,27 +694,6 @@ sub toHtmlWithWrapper { } } -#------------------------------------------------------------------- - -=head2 passUiLevelCheck ( ) - -Renders the form field to HTML as a table row complete with labels, subtext, hoverhelp, etc. - -=cut - -sub passUiLevelCheck { - my $self = shift; - my $passUiLevelCheck = 0; - my $override = $self->session->config->get($self->get("uiLevelOverride")."_uiLevel"); - if (defined $override && $override->{$self->get("name")}) { # use override if it exists - $passUiLevelCheck = ($override->{$self->get("name")} <= $self->session->user->profileField("uiLevel")); - } else { # use programmed default - $passUiLevelCheck = ($self->get("uiLevel") <= $self->session->user->profileField("uiLevel")); - } - $passUiLevelCheck = $self->session->user->isInGroup(3) unless ($passUiLevelCheck); # override if in admins group - return $passUiLevelCheck; -} - 1; diff --git a/lib/WebGUI/Form/Country.pm b/lib/WebGUI/Form/Country.pm index cb60ec5b7..e6e5de631 100644 --- a/lib/WebGUI/Form/Country.pm +++ b/lib/WebGUI/Form/Country.pm @@ -39,6 +39,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -59,9 +71,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get('country') - }, label=>{ defaultValue=>$i18n->get('country') }, @@ -71,18 +80,45 @@ sub definition { defaultValue=>{ defaultValue=>"United States" }, - }); + }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('country'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a country picker control. =cut +sub toHtml { + my $self = shift; my %countries; tie %countries, 'Tie::IxHash'; %countries = ( @@ -329,8 +365,6 @@ tie %countries, 'Tie::IxHash'; 'Zimbabwe' => 'Zimbabwe' ); -sub toHtml { - my $self = shift; $self->set("options", \%countries); return $self->SUPER::toHtml(); } diff --git a/lib/WebGUI/Form/DatabaseLink.pm b/lib/WebGUI/Form/DatabaseLink.pm index b5ae0563b..6651d1bb2 100644 --- a/lib/WebGUI/Form/DatabaseLink.pm +++ b/lib/WebGUI/Form/DatabaseLink.pm @@ -39,6 +39,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -75,9 +87,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("1075") - }, label=>{ defaultValue=>$i18n->get("1075") }, @@ -93,15 +102,49 @@ sub definition { hoverHelp=>{ defaultValue=>$i18n->get('1075 description') }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, - }); + }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "VARCHAR(22) BINARY". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(22) BINARY"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('1075'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a database connection picker control. @@ -127,11 +170,10 @@ sub toHtmlWithWrapper { if ($self->session->user->isInGroup(3)) { my $subtext; if ($self->get("afterEdit")) { - $subtext = $self->session->icon->edit("op=editDatabaseLink;lid=".$self->get("value").";afterEdit=".$self->session->url->escape($self->get("afterEdit"))); + $subtext = $self->session->icon->edit("op=editDatabaseLink;lid=".$self->getDefaultValue.";afterEdit=".$self->session->url->escape($self->get("afterEdit"))); } $subtext .= $self->session->icon->manage("op=listDatabaseLinks"); $self->set("subtext", $subtext . $self->get("subtext")); -# $self->get("subtext") = $subtext . $self->get("subtext"); } return $self->SUPER::toHtmlWithWrapper; } diff --git a/lib/WebGUI/Form/Date.pm b/lib/WebGUI/Form/Date.pm index 63a77f5df..0afc30853 100644 --- a/lib/WebGUI/Form/Date.pm +++ b/lib/WebGUI/Form/Date.pm @@ -71,21 +71,13 @@ If no value is specified, this will be used. Defaults to today and now. If the defaultValue is a MySQL date string, this form control will return MySQL date strings instead of epoch times. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("352") - }, defaultValue=>{ defaultValue=>$session->datetime->time() }, @@ -98,42 +90,38 @@ sub definition { noDate=>{ defaultValue=>0 }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "BIGINT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 displayValue ( ) +=head2 getDatabaseFieldType ( ) -Return the date in a human readable format for the Profile system. +Returns "BIGINT". -=cut +=cut -sub displayValue { - my ($self) = @_; - # This should probably be rewritten as a cascading ternary - if (!$self->get("defaultValue") - || $self->get("defaultValue") =~ m/^\d+$/ - || !$self->get("value") - || $self->get("value") =~ m/^\d+$/) { - return $self->session->datetime->epochToHuman($self->get("value"),"%z"); - } else { - # MySQL format - my $value = $self->get("value"); - return $value; - } +sub getDatabaseFieldType { + return "BIGINT"; } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('352'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) Returns a validated form post result. If the result does not pass validation, it returns undef instead. @@ -144,18 +132,16 @@ An optional value to process, instead of POST input. This should be in the 'YY(Y =cut -sub getValueFromPost { +sub getValue { my $self = shift; # This should probably be rewritten as a cascading ternary - if (!$self->get("defaultValue") - || $self->get("defaultValue") =~ m/^\d+$/ - || !$self->get("value") - || $self->get("value") =~ m/^\d+$/) { - return $self->session->datetime->setToEpoch(@_ ? shift : $self->session->form->param($self->get("name"))); - } else { + my $value = $self->SUPER::getValue(@_); + if (!$self->getDefaultValue || $self->getDefaultValue =~ m/^\d+$/) { + return $self->session->datetime->setToEpoch($value); + } + else { # MySQL format # YY(YY)?-MM-DD - my $value = @_ ? shift : $self->session->form->param($self->get("name")); # NOTE: Cannot fix time zone since we don't have a complete date/time @@ -166,6 +152,42 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 getValueAsHtml ( ) + +Return the date in a human readable format. + +=cut + +sub getValueAsHtml { + my ($self) = @_; + # This should probably be rewritten as a cascading ternary + if (!$self->get("defaultValue") + || $self->get("defaultValue") =~ m/^\d+$/ + || !$self->get("value") + || $self->get("value") =~ m/^\d+$/) { + return $self->session->datetime->epochToHuman($self->getValue,"%z"); + } + else { + # MySQL format + my $value = $self->getValue; + return $value; + } +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a date picker control. @@ -185,11 +207,11 @@ sub toHtml { || !$self->get("value") || $self->get("value") =~ m/^\d+$/) { # Epoch format - $value = $self->set("value",$self->session->datetime->epochToSet($self->get("value"))); + $value = $self->set("value",$self->session->datetime->epochToSet($self->getDefaultValue)); } else { # MySQL format - $value = $self->get("value"); + $value = $self->getDefaultValue; # NOTE: Cannot fix time zone since we don't have a complete date/time } @@ -238,10 +260,10 @@ sub toHtmlAsHidden { || $self->get("defaultValue") =~ m/^\d+$/ || !$self->get("value") || $self->get("value") =~ m/^\d+$/) { - $value = $self->session->datetime->epochToSet($self->get("value"),"%z"); + $value = $self->session->datetime->epochToSet($self->getDefaultValue,"%z"); } else { # MySQL format - $value = $self->get("value"); + $value = $self->getDefaultValue; # NOTE: Cannot fix time zone since we don't have a complete date/time } diff --git a/lib/WebGUI/Form/DateTime.pm b/lib/WebGUI/Form/DateTime.pm index 16ffcf95a..89820af2f 100644 --- a/lib/WebGUI/Form/DateTime.pm +++ b/lib/WebGUI/Form/DateTime.pm @@ -62,10 +62,6 @@ Defaults to 19. Determines the maximum number of characters allowed in this fiel Defaults to 19. The displayed size of the box for the date to be typed in. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =head4 defaultValue If no value is specified, this will be used. Defaults to today and now. @@ -79,11 +75,7 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("972") - }, defaultValue=>{ defaultValue=>$session->datetime->time() }, @@ -93,19 +85,38 @@ sub definition { size=>{ defaultValue=> 19 }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "BIGINT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getDatabaseFieldType ( ) + +Returns "BIGINT". + +=cut + +sub getDatabaseFieldType { + return "BIGINT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('972'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) Returns a validated form post result. If the result does not pass validation, it returns undef instead. @@ -115,23 +126,20 @@ An optional value to process, instead of POST input. This should be in the 'YY(Y =cut -sub getValueFromPost { +sub getValue { my $self = shift; # This should probably be rewritten as a cascading ternary - if (!$self->get("defaultValue") - || $self->get("defaultValue") =~ m/^\d+$/ - || !$self->get("value") - || $self->get("value") =~ m/^\d+$/) { + my $value = $self->SUPER::getValue(@_); + if (!$self->get("defaultValue") || $self->get("defaultValue") =~ m/^\d+$/ || !$self->get("value") || $self->get("value") =~ m/^\d+$/) { # Epoch format - return $self->session->datetime->setToEpoch(@_ ? shift : $self->session->form->param($self->get("name"))); - } else { + return $self->session->datetime->setToEpoch($value); + } + else { # MySQL format # YY(YY)?-MM-DD HH:MM:SS - my $value = @_ ? shift : $self->session->form->param($self->get("name")); - $self->session->errorHandler->warn("Date value: $value"); # Verify format - return + return undef unless ($value =~ m/(?:\d{2}|\d{4})\D\d{2}\D\d{2}\D\d{2}\D\d{2}\D\d{2}/); # Fix time zone @@ -144,6 +152,42 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 getValueAsHtml ( ) + +Return the date in a human readable format. + +=cut + +sub getValueAsHtml { + my ($self) = @_; + # This should probably be rewritten as a cascading ternary + if (!$self->get("defaultValue") + || $self->get("defaultValue") =~ m/^\d+$/ + || !$self->get("value") + || $self->get("value") =~ m/^\d+$/) { + return $self->session->datetime->epochToHuman($self->getDefaultValue,"%z %Z"); + } + else { + # MySQL format + my $value = $self->getDefaultValue; + return $value; + } +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a date picker control. @@ -159,10 +203,10 @@ sub toHtml { || !$self->get("value") || $self->get("value") =~ m/^\d+$/) { # Epoch format - $value = $self->session->datetime->epochToSet($self->get("value"),1); + $value = $self->session->datetime->epochToSet($self->getDefaultValue,1); } else { # MySQL format - $value = $self->get("value"); + $value = $self->getDefaultValue; # Fix time zone $value = WebGUI::DateTime->new($value) ->set_time_zone($self->session->user->profileField("timeZone")) @@ -214,10 +258,10 @@ sub toHtmlAsHidden { || $self->get("defaultValue") =~ m/^\d+$/ || !$self->get("value") || $self->get("value") =~ m/^\d+$/) { - $value = $self->session->datetime->epochToSet($self->get("value"),1); + $value = $self->session->datetime->epochToSet($self->getDefaultValue,1); } else { # MySQL format - $value = $self->get("value"); + $value = $self->getDefaultValue; # Fix Time zone $value = WebGUI::DateTime->new($value) ->set_time_zone($self->session->user->profileField("timeZone")) diff --git a/lib/WebGUI/Form/DynamicField.pm b/lib/WebGUI/Form/DynamicField.pm index d30e39f3e..00810c30c 100644 --- a/lib/WebGUI/Form/DynamicField.pm +++ b/lib/WebGUI/Form/DynamicField.pm @@ -17,6 +17,7 @@ package WebGUI::Form::DynamicField; use strict; use base 'WebGUI::Form::Control'; use WebGUI::International; +use WebGUI::Pluggable; use WebGUI::Utility; =head1 NAME @@ -57,11 +58,7 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("475"), - }, fieldType=>{ defaultValue=> "Text" }, @@ -71,6 +68,19 @@ sub definition { #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('475'); +} + +#------------------------------------------------------------------- + =head2 new ( params) Creates the object for the appropriate field type. @@ -99,12 +109,11 @@ sub new { my $class = shift; my $session = shift; my %raw = @_; - my $param = \%raw; - my $fieldType = ucfirst($param->{fieldType}); - delete $param->{fieldType}; + my $fieldType = ucfirst($raw{fieldType}); + delete $raw{fieldType}; # Return the appropriate field object. if ($fieldType eq "") { - $session->errorHandler->warn("Something is trying to create a dynamic field called ".$param->{name}.", but didn't pass in a field type."); + $session->errorHandler->warn("Something is trying to create a dynamic field called ".$raw{name}.", but didn't pass in a field type."); $fieldType = "Text"; } ##No infinite loops, please @@ -112,23 +121,7 @@ sub new { $session->errorHandler->warn("Something is trying to create a DynamicField via DynamicField."); $fieldType = "Text"; } - no strict 'refs'; - my $cmd = "WebGUI::Form::".$fieldType; - my $load = "use ".$cmd; - eval ($load); - if ($@) { - $session->errorHandler->error("Couldn't compile form control: ".$fieldType.". Root cause: ".$@); - return undef; - } - my $formObj = $cmd->new($session, $param); - if ($formObj->isa('WebGUI::Form::List')) { - $formObj->correctValues($param->{value}); - $formObj->correctOptions($param->{possibleValues}); - } - if ($param->{size}) { - $formObj->set('size',$param->{size}); - } - return $formObj; + return WebGUI::Pluggable::instanciate("WebGUI::Form::".$fieldType, "new", [$session, \%raw]); } diff --git a/lib/WebGUI/Form/Email.pm b/lib/WebGUI/Form/Email.pm index 4f99e84f8..e6a4ef05d 100644 --- a/lib/WebGUI/Form/Email.pm +++ b/lib/WebGUI/Form/Email.pm @@ -36,41 +36,23 @@ The following methods are specifically available from this class. Check the supe =cut + #------------------------------------------------------------------- -=head2 definition ( [ additionalTerms ] ) +=head2 getName ( session ) -See the super class for additional details. - -=head3 additionalTerms - -The following additional parameters have been added via this sub class. - -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile +Returns the human readable name of this control. =cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("480") - }, - profileEnabled=>{ - defaultValue=>1 - } - }); - return $class->SUPER::definition($session, $definition); +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('480'); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getValue ( [ value ] ) Returns a validated email address. If the result does not pass validation, it returns undef instead. @@ -80,7 +62,7 @@ An optional value to process instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; my $value = @_ ? shift : $self->session->form->param($self->get("name")); if ($value =~ /^([0-9a-zA-Z]([-.+\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/i) { @@ -91,6 +73,33 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 getValueAsHtml ( ) + +Formats as an email link. + +=cut + +sub getValueAsHtml { + my $self = shift; + my $email = $self->getValue; + return ''.$email.''; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders an email address field. diff --git a/lib/WebGUI/Form/FieldType.pm b/lib/WebGUI/Form/FieldType.pm index 4c48460c9..5b8f05a2d 100644 --- a/lib/WebGUI/Form/FieldType.pm +++ b/lib/WebGUI/Form/FieldType.pm @@ -16,9 +16,10 @@ package WebGUI::Form::FieldType; use strict; use base 'WebGUI::Form::SelectBox'; -use WebGUI::International; -use WebGUI::Utility; use Tie::IxHash; +use WebGUI::International; +use WebGUI::Pluggable; +use WebGUI::Utility; =head1 NAME @@ -26,7 +27,7 @@ Package WebGUI::Form::FieldType =head1 DESCRIPTION -Creates a form control that will allow you to select a form control type. +Creates a form control that will allow you to select a form control type. It's meant to be used in conjunction with the DynamicField form control. =head1 SEE ALSO @@ -40,6 +41,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -50,7 +63,7 @@ The following additional parameters have been added via this sub class. =head4 types -An array reference containing the form control types to be selectable. Defaults to all available types. +An array reference containing the form control types to be selectable. Defaults to all available dynamic types. =head4 label @@ -64,63 +77,87 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("fieldtype","WebGUI") - }, label=>{ defaultValue=>$i18n->get("fieldtype","WebGUI") }, types=>{ - defaultValue=>$class->getTypes($session) - } - }); + defaultValue=>[], + }, + }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getTypes ( ) +=head2 getName ( session ) -A class method that returns an array reference of all the valid form -control types present in the system. Invalid form types include -Control.pm, the form master class and List, the list form master class -and DynamicField, the form class dispatcher. +Returns the human readable name of this control. =cut -sub getTypes { - my $class = shift; - my $session = shift; - opendir(DIR,$session->config->getWebguiRoot."/lib/WebGUI/Form/"); - my @rawTypes = readdir(DIR); - closedir(DIR); - my @types; - foreach my $type (@rawTypes) { - if ($type =~ /^(.*)\.pm$/) { - next if (isIn($1, qw/Control List DynamicField/)); - push(@types,$1); - } - } - return \@types; +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('fieldType'); } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getTypes ( ) + +Returns a hash reference of field types and human readable names. Defaultly returns all that have isDynamicCompatible() set to 1, but if types is specified in the constructor, will return the ones from that list. + +=cut + +sub getTypes { + my $self = shift; + my @types = @{$self->get('types')}; + unless (scalar(@types)) { + opendir(DIR,$self->session->config->getWebguiRoot."/lib/WebGUI/Form/"); + foreach my $type (readdir(DIR)) { + if ($type =~ s/^(.*)\.pm$/$1/) { + if (WebGUI::Pluggable::instanciate('WebGUI::Form::'.ucfirst($type),'isDynamicCompatible')) { + push @types, $type; + } + } + } + closedir(DIR); + } + my %fields = (); + foreach my $type (@types) { + $fields{$type} = WebGUI::Pluggable::instanciate('WebGUI::Form::'.ucfirst($type), 'getName', [$self->session]); + } + return \%fields; +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) Returns either what's posted or if nothing comes back it returns "text". =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $fieldType = $self->session->form->param($self->get("name")); + my $fieldType = $self->SUPER::getValue(@_); $fieldType =~ s/[^\w]//g; return $fieldType || "text"; } #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a fieldType selector. @@ -131,19 +168,7 @@ sub toHtml { my $self = shift; my %options; tie %options, "Tie::IxHash"; - foreach my $type (@{ $self->get('types') }) { - my $class = "WebGUI::Form::".ucfirst($type); - my $cmd = "use ".$class; - eval ($cmd); - if ($@) { - $self->session->errorHandler->error("Couldn't compile form control: ".$type.". Root cause: ".$@); - next; - } - next unless $class->isProfileEnabled($self->session); - $options{$type} = $class->getName($self->session); - } - $self->set('options',\%options); - + $self->set('options', $self->getTypes); return $self->SUPER::toHtml(); } diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm index a8c1a0e17..f623ae882 100644 --- a/lib/WebGUI/Form/File.pm +++ b/lib/WebGUI/Form/File.pm @@ -57,10 +57,6 @@ If no name is specified a default name of "file" will be used. How many attachments will be allowed to be uploaded. However, the file form only supports displaying/deleting 1 attachment. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =head4 deleteFileUrl A url that will get a filename appended to it and then links to delete the files will be generated automatically. @@ -75,76 +71,46 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("file") - }, name=>{ defaultValue=>"file" }, maxAttachments=>{ defaultValue=>1 }, - profileEnabled=>{ - defaultValue=>1 - }, deleteFileUrl=>{ defaultValue=>undef }, size=>{ defaultValue=>40 }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 displayForm ( ) +=head2 getDatabaseFieldType ( ) -If an file is uploaded, then return an icon for that file's type and a control to -delete it. Otherwise, display a form element to upload a file. +Returns "VARCHAR(22) BINARY". -=cut +=cut -sub displayForm { - my ($self) = @_; - return $self->toHtml unless $self->get("value"); - ##There are files inside here, for each one, display the file icon - ##and another form control for deleting it. - my $location = WebGUI::Storage->get($self->session,$self->get("value")); - my $fileForm = ''; - my $i18n = WebGUI::International->new($self->session); - my $file = shift @{ $location->getFiles }; - $fileForm .= sprintf qq!
!, $location->getFileIconUrl($file); - $fileForm .= $i18n->get(392) - . " "x4 - . WebGUI::Form::YesNo->new($self->session,{-name=>$self->privateName('delete'), -value=>0})->toHtml; - $fileForm .= $self->toHtmlAsHidden(); - $fileForm .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'keep'})->toHtml(); - return $fileForm; +sub getDatabaseFieldType { + return "VARCHAR(22) BINARY"; } #------------------------------------------------------------------- -=head2 displayValue ( ) +=head2 getName ( session ) -This utility method is used to format values for the Profile system. Most -form elements will just return their value. +Returns the human readable name of this control. =cut -sub displayValue { - my ($self) = @_; - return '' unless $self->get("value"); - my $location = WebGUI::Storage->get($self->session,$self->get("value")); - my $file = shift @{ $location->getFiles }; - my $fileValue = sprintf qq| %s|, $location->getFileIconUrl($file), $location->getUrl($file), $file; - return $fileValue; +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('file'); } #------------------------------------------------------------------- @@ -162,6 +128,7 @@ A WebGUI::Storage object. sub getFilePreview { my $self = shift; my $storage = shift; + my $i18n = WebGUI::International->new($self->session); my $preview = ""; foreach my $file (@{$storage->getFiles}) { if ($self->get("deleteFileUrl")) { @@ -171,10 +138,12 @@ sub getFilePreview { $preview .= '

' .''
 			.$file.' '.$file.'


'; + $preview .= $i18n->get(392) . (" "x4) . WebGUI::Form::YesNo->new($self->session,{name=>$self->privateName('delete'), value=>0})->toHtml; } return $preview; } + #------------------------------------------------------------------- =head2 getStorageLocation ( ) @@ -185,14 +154,15 @@ Returns the WebGUI::Storage object for this control. sub getStorageLocation { my $self = shift; - my $storage = WebGUI::Storage->get($self->session, $self->get("value")) if ($self->get("value")); + my $value = $self->getDefaultValue; + my $storage = WebGUI::Storage->get($self->session, $value) if ( defined $value ); return $storage; } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getValue ( ) Returns the storageId for the storage location that the file(s) got uploaded to. Returns undef if no files were uploaded. Also handles @@ -200,7 +170,7 @@ deleting the file if it was specified. =cut -sub getValueFromPost { +sub getValue { my $self = shift; my $value = $self->get("value"); if ($self->session->form->param($self->privateName('delete'))) { @@ -232,6 +202,36 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 getValueAsHtml ( ) + +Displays the file as a link. + +=cut + +sub getValueAsHtml { + my ($self) = @_; + my $value = $self->getValue; + return '' unless $value; + my $location = WebGUI::Storage->get($self->session,$value); + my $file = shift @{ $location->getFiles }; + my $fileValue = sprintf qq| %s|, $location->getFileIconUrl($file), $location->getUrl($file), $file; + return $fileValue; +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a file upload control. @@ -274,7 +274,7 @@ sub toHtml { else { $uploadControl .= WebGUI::Form::Hidden->new($self->session, { name => $self->get("name"), - value => $self->get("value"), + value => $self->getDefaultValue, id => $self->get("id") })->toHtml()."
"; $uploadControl .= WebGUI::Form::Hidden->new($self->session, { @@ -284,6 +284,9 @@ sub toHtml { })->toHtml()."
"; } if (scalar(@files)) { + if ($self->get('maxAttachments') == 1) { + $self->set(""); + } $uploadControl .= $self->getFilePreview($storage); } return $uploadControl; diff --git a/lib/WebGUI/Form/FilterContent.pm b/lib/WebGUI/Form/FilterContent.pm index baa90d6b1..9996c3d53 100644 --- a/lib/WebGUI/Form/FilterContent.pm +++ b/lib/WebGUI/Form/FilterContent.pm @@ -39,6 +39,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -67,9 +79,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("418") - }, name=>{ defaultValue=>"filterContent" }, @@ -79,24 +88,58 @@ sub definition { defaultValue=>{ defaultValue=>"most", }, - dbDataType => { - defaultValue => "VARCHAR(16)", - }, - }); + }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getDatabaseFieldType ( ) + +Returns "VARCHAR(16)". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(16)"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('418'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) Returns either what's posted or if nothing comes back it returns "most". =cut -sub getValueFromPost { +sub getValue { my $self = shift; - return $self->session->form->param($self->get("name")) || "most"; + return $self->SUPER::getValue(@_) || "most"; +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/Float.pm b/lib/WebGUI/Form/Float.pm index 318c88a1e..721098427 100644 --- a/lib/WebGUI/Form/Float.pm +++ b/lib/WebGUI/Form/Float.pm @@ -58,21 +58,13 @@ Defaults to 0. Used if no value is specified. Defaults to 11. The number of characters that will be displayed at once in this field. Usually no need to override the default. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("float") - }, maxlength=>{ defaultValue=> 14 }, @@ -82,19 +74,38 @@ sub definition { size=>{ defaultValue=>11 }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "DOUBLE", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getDatabaseFieldType ( ) + +Returns "DOUBLE". + +=cut + +sub getDatabaseFieldType { + return "DOUBLE"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('float'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) Returns the integer from the form post, or returns 0.0 if the post result is invalid. @@ -104,9 +115,9 @@ An optional value to process, instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = @_ ? shift : $self->session->form->param($self->get("name")); + my $value = $self->SUPER::getValue(@_); if ($value =~ /^-?[\d\.]+$/ and $value =~ /\d/) { return $value; } @@ -115,6 +126,18 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a floating point field. diff --git a/lib/WebGUI/Form/Group.pm b/lib/WebGUI/Form/Group.pm index d4bbb0331..8e1c7fc8f 100644 --- a/lib/WebGUI/Form/Group.pm +++ b/lib/WebGUI/Form/Group.pm @@ -39,6 +39,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -63,21 +75,13 @@ An array reference containing a list of groups to exclude from the list. Default This will be used if no value is specified. Should be passed as an array reference. Defaults to 7 (Everyone). -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("group") - }, size=>{ defaultValue=>1 }, @@ -90,18 +94,67 @@ sub definition { excludeGroups=>{ defaultValue=>[] }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, - }); + }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "VARCHAR(22) BINARY". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(22) BINARY"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('group'); +} + +#------------------------------------------------------------------- + +=head2 getValueAsHtml ( ) + +Formats as a name. + +=cut + +sub getValueAsHtml { + my $self = shift; + my $group = WebGUI::Group->new($self->session, $self->getValue); + if (defined $group) { + return $group->name; + } + return undef; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) 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. diff --git a/lib/WebGUI/Form/HTMLArea.pm b/lib/WebGUI/Form/HTMLArea.pm index 851bb247e..4e20a625b 100644 --- a/lib/WebGUI/Form/HTMLArea.pm +++ b/lib/WebGUI/Form/HTMLArea.pm @@ -67,21 +67,13 @@ Style attributes besides width and height which should be specified using the ab The ID of the WebGUI::Asset::RichEdit object to load. Defaults to the richEditor setting or "PBrichedit000000000001" if that's not set. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("477") - }, height=>{ defaultValue=> 400 }, @@ -94,19 +86,38 @@ sub definition { richEditId=>{ defaultValue=>$session->setting->get("richEditor") || "PBrichedit000000000001" }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "LONGTEXT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getDatabaseFieldType ( ) + +Returns "LONGTEXT". + +=cut + +sub getDatabaseFieldType { + return "LONGTEXT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('477'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) Returns the value of this form field after stipping unwanted tags like . @@ -116,12 +127,24 @@ An optional value to process, instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - return WebGUI::HTML::cleanSegment($self->SUPER::getValueFromPost(@_)); + return WebGUI::HTML::cleanSegment($self->SUPER::getValue(@_)); } +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + #------------------------------------------------------------------- =head2 toHtml ( ) @@ -521,7 +544,7 @@ sub www_addImageSave { return $session->privilege->insufficient('bare') unless $base->canEdit; #my $imageId = WebGUI::Form::Image->create($session); - my $imageId = WebGUI::Form::Image->new($session,{name => 'filename'})->getValueFromPost; + my $imageId = WebGUI::Form::Image->new($session,{name => 'filename'})->getDefaultValue; my $imageObj = WebGUI::Storage::Image->get($session, $imageId); ##This is a hack. It should use the WebGUI::Form::File API to insulate ##us from future form name changes. diff --git a/lib/WebGUI/Form/HexSlider.pm b/lib/WebGUI/Form/HexSlider.pm index 13cf29a67..91c45a0cf 100644 --- a/lib/WebGUI/Form/HexSlider.pm +++ b/lib/WebGUI/Form/HexSlider.pm @@ -62,21 +62,13 @@ The length of the input box. Pad the value to padLength characters by adding zeros in front if necesarry. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=> $i18n->get("hex slider") - }, maximum=>{ defaultValue=> "ff", }, @@ -89,9 +81,6 @@ sub definition { padLength=>{ defaultValue=>"2", }, - profileEnabled=>{ - defaultValue=>1 - }, }); return $class->SUPER::definition($session, $definition); } @@ -160,17 +149,16 @@ sub getOnChangeSlider { #------------------------------------------------------------------- -#=head2 getSliderMaximum ( ) -# -#Returns the maximum value the slider can be set to in slider units. -# -#=cut -# -#sub getSliderMaximum { -# my $self = shift; -# -# return scalar(keys %{$self->get('options')}) - 1; -#} +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('hex slider'); +} #------------------------------------------------------------------- @@ -216,13 +204,13 @@ sub getSliderValue { #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getValue ( ) 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. Strip newlines/carriage returns from the value. =cut -sub getValueFromPost { +sub getValue { my $self = shift; my $properties = { @@ -232,7 +220,19 @@ sub getValueFromPost { id => 'view-'.$self->get('id'), }; - return WebGUI::Form::Hexadecimal->new($self->session, $properties)->getValueFromPost; + return WebGUI::Form::Hexadecimal->new($self->session, $properties)->getValue; +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; } 1; diff --git a/lib/WebGUI/Form/Hexadecimal.pm b/lib/WebGUI/Form/Hexadecimal.pm index faf01cfbf..5462b742f 100644 --- a/lib/WebGUI/Form/Hexadecimal.pm +++ b/lib/WebGUI/Form/Hexadecimal.pm @@ -58,21 +58,13 @@ Defaults to 0. Used if no value is specified. Defaults to 11. The number of characters that will be displayed at once in this field. Usually no need to override the default. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("hexadecimal") - }, maxlength=>{ defaultValue=> 11 }, @@ -82,24 +74,34 @@ sub definition { size=>{ defaultValue=>11 }, - profileEnabled=>{ - defaultValue=>1 - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('hexadecimal'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) Returns the integer from the form post, or returns 0 if the post result is invalid. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = $self->session->form->param($self->get("name")); + my $value = $self->SUPER::getValue(@_); if ($value =~ /^[0-9a-f]+$/i) { return $value; } @@ -108,6 +110,18 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders an integer field. diff --git a/lib/WebGUI/Form/Hidden.pm b/lib/WebGUI/Form/Hidden.pm index 3f7b5e1ef..469cadada 100644 --- a/lib/WebGUI/Form/Hidden.pm +++ b/lib/WebGUI/Form/Hidden.pm @@ -36,37 +36,6 @@ The following methods are specifically available from this class. Check the supe =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 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - -=cut - -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("hidden") - }, - profileEnabled=>{ - defaultValue=>1 - }, - }); - return $class->SUPER::definition($session, $definition); -} #------------------------------------------------------------------- @@ -82,6 +51,31 @@ sub generateIdParameter { #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('hidden'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) A synonym for toHtmlAsHidden. @@ -103,7 +97,7 @@ Renders an input tag of type hidden. sub toHtmlAsHidden { my $self = shift; - my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value")))) || ''; + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))) || ''; my $idText = $self->get('id') ? ' id="'.$self->get('id').'" ' : ''; return 'get("extras")||'').$idText.' />'."\n"; } diff --git a/lib/WebGUI/Form/HiddenList.pm b/lib/WebGUI/Form/HiddenList.pm index 4012f936d..2d5d64b22 100644 --- a/lib/WebGUI/Form/HiddenList.pm +++ b/lib/WebGUI/Form/HiddenList.pm @@ -36,47 +36,42 @@ The following methods are specifically available from this class. Check the supe =cut + #------------------------------------------------------------------- -=head2 definition ( [ additionalTerms ] ) +=head2 getDatabaseFieldType ( ) -See the super class for additional details. +Returns "TEXT". -=head3 additionalTerms +=cut -The following additional parameters have been added via this sub class. +sub getDatabaseFieldType { + return "TEXT"; +} -=head4 options +#------------------------------------------------------------------- -A hash reference containing name value pairs. The name of each pair will be used to fill the value attribute of the hidden field. Defaults to an empty hash reference. +=head2 getName ( session ) -=head4 defaultValue - -value and defaultValue are array referneces containing the names from the options list that should be stored. - -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile +Returns the human readable name of this control. =cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("hidden list"), - }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "TEXT", - }, - }); - return $class->SUPER::definition($session, $definition); +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('hidden list'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/Image.pm b/lib/WebGUI/Form/Image.pm index 3f06e5859..6133d9e43 100644 --- a/lib/WebGUI/Form/Image.pm +++ b/lib/WebGUI/Form/Image.pm @@ -53,10 +53,6 @@ The following additional parameters have been added via this sub class. If no name is specified a default name of "file" will be used. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =head4 forceImageOnly When set, form control will not allow file uploads unless the file has recognized image file extension @@ -67,74 +63,18 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("image") - }, name=>{ defaultValue=>"image" }, - profileEnabled=>{ - defaultValue=>1 - }, forceImageOnly=>{ defaultValue=>0 }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, }); return $class->SUPER::definition($session, $definition); } -#------------------------------------------------------------------- - -=head2 displayForm ( ) - -If an image is uploaded, then return the image and a control to -delete it. Otherwise, display a form element to upload a file. - -=cut - -sub displayForm { - my ($self) = @_; - return $self->toHtml unless $self->get('value'); - ##There are files inside here, for each one, display the image - ##and another form control for deleting it. - my $location = WebGUI::Storage::Image->get($self->session, $self->get('value')); - my $i18n = WebGUI::International->new($self->session); - my $fileForm = ''; - my $file = shift @{ $location->getFiles }; - $fileForm .= sprintf qq!
!, $location->getUrl($file); - $fileForm .= $i18n->get(392) - . " "x4 - . WebGUI::Form::YesNo->new($self->session, {-name=>$self->privateName('delete'), -value=>0})->toHtml; - $fileForm .= $self->toHtmlAsHidden(); - $fileForm .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'keep'})->toHtml(); - return $fileForm; -} - -#------------------------------------------------------------------- - -=head2 displayValue ( ) - -This utility method is used to format values for the Profile system. It -displays each image in the storage location that is the value of the -profile field. - -=cut - -sub displayValue { - my ($self) = @_; - return '' unless $self->get("value"); - my $location = WebGUI::Storage::Image->get($self->session,$self->get("value")); - my $file = shift @{ $location->getFiles }; - my $fileValue = sprintf qq| %s|, $location->getUrl($file), $file; - return $fileValue; -} - #------------------------------------------------------------------- =head2 getFilePreview ( storage ) @@ -151,6 +91,7 @@ sub getFilePreview { my $self = shift; my $storage = shift; my $preview = ""; + my $i18n = WebGUI::International->new($self->session); foreach my $file (@{$storage->getFiles}) { if ($self->get("deleteFileUrl")) { $preview .= '

' @@ -160,12 +101,26 @@ sub getFilePreview { $preview .= '

' .''
 			.$file.' '.$file.'


'; + $preview .= $i18n->get(392) . " "x4 . WebGUI::Form::YesNo->new($self->session, {-name=>$self->privateName('delete'), -value=>0})->toHtml; } return $preview; } #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('image'); +} + +#------------------------------------------------------------------- + =head2 getStorageLocation ( ) Returns the WebGUI::Storage object for this control. @@ -174,22 +129,23 @@ Returns the WebGUI::Storage object for this control. sub getStorageLocation { my $self = shift; - my $storage = WebGUI::Storage::Image->get($self->session, $self->get("value")) if ($self->get("value")); + my $value = $self->getDefaultValue; + my $storage = WebGUI::Storage::Image->get($self->session, $value) if ($value); return $storage; } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getValue ( ) -See WebGUI::Form::File::getValueFromPost() for details. Generates a thumbnail. +See WebGUI::Form::File::getValue() for details. Generates a thumbnail. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $id = $self->SUPER::getValueFromPost(@_); + my $id = $self->SUPER::getValue(@_); if (defined $id) { my $storage = WebGUI::Storage::Image->get($self->session, $id); if (defined $storage) { @@ -207,5 +163,35 @@ sub getValueFromPost { return $id; } +#------------------------------------------------------------------- + +=head2 getValueAsHtml ( ) + +Displays the image using an img tag. + +=cut + +sub getValueAsHtml { + my ($self) = @_; + my $value = $self->getValue; + return '' unless $value; + my $location = WebGUI::Storage::Image->get($self->session, $value); + my $file = shift @{ $location->getFiles }; + my $fileValue = sprintf qq| %s|, $location->getUrl($file), $file; + return $fileValue; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} 1; diff --git a/lib/WebGUI/Form/IntSlider.pm b/lib/WebGUI/Form/IntSlider.pm index c1da8ca37..47d1d8a95 100644 --- a/lib/WebGUI/Form/IntSlider.pm +++ b/lib/WebGUI/Form/IntSlider.pm @@ -50,36 +50,34 @@ The following additional parameters have been added via this sub class. The length of the input box. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=> $i18n->get("int slider") - }, size=>{ defaultValue=> "3", }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "BIGINT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "BIGINT". + +=cut + +sub getDatabaseFieldType { + return "BIGINT"; +} + +#------------------------------------------------------------------- + =head2 getInputElement ( ) Returns the form element used for manual input. @@ -99,6 +97,19 @@ sub getInputElement { #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('int slider'); +} + +#------------------------------------------------------------------- + =head2 getOnChangeInputElement ( ) Returns the javascript code to update the slider and other form elements on a @@ -130,7 +141,7 @@ sub getOnChangeSlider { #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getValue ( [ value ] ) 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. Strip newlines/carriage returns from the value. @@ -140,7 +151,7 @@ A value to process instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; my @args = @_; @@ -151,7 +162,19 @@ sub getValueFromPost { id => 'view-'.$self->get('id'), }; - return WebGUI::Form::Integer->new($self->session, $properties)->getValueFromPost(@args); + return WebGUI::Form::Integer->new($self->session, $properties)->getValue(@args); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; } 1; diff --git a/lib/WebGUI/Form/Integer.pm b/lib/WebGUI/Form/Integer.pm index b5b01ba22..6cca40746 100644 --- a/lib/WebGUI/Form/Integer.pm +++ b/lib/WebGUI/Form/Integer.pm @@ -58,21 +58,13 @@ Defaults to 0. Used if no value is specified. Defaults to 11. The number of characters that will be displayed at once in this field. Usually no need to override the default. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("482") - }, maxlength=>{ defaultValue=> 11 }, @@ -82,19 +74,38 @@ sub definition { size=>{ defaultValue=>11 }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "BIGINT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getDatabaseFieldType ( ) + +Returns "BIGINT". + +=cut + +sub getDatabaseFieldType { + return "BIGINT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('482'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) Returns the integer from the form post, or returns 0 if the post result is invalid. @@ -104,9 +115,9 @@ An optional value to process, instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = @_ ? shift : $self->session->form->param($self->get("name")); + my $value = $self->SUPER::getValue(@_); if ($value =~ /^-?\d+$/) { return $value; } @@ -115,6 +126,18 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders an integer field. diff --git a/lib/WebGUI/Form/Interval.pm b/lib/WebGUI/Form/Interval.pm index e453863fd..f7f693a61 100644 --- a/lib/WebGUI/Form/Interval.pm +++ b/lib/WebGUI/Form/Interval.pm @@ -55,37 +55,48 @@ The following additional parameters have been added via this sub class. A time interval in seconds that is used if value is not specified. Defaults to 1. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("interval"), - }, defaultValue=>{ defaultValue=>1, }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "BIGINT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ num_and_units ] ) +=head2 getDatabaseFieldType ( ) + +Returns "BIGINT". + +=cut + +sub getDatabaseFieldType { + return "BIGINT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('interval'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ num_and_units ] ) Returns either the interval that was posted (in seconds) or if nothing comes back it returns 0. @@ -95,7 +106,7 @@ The number and units for this interval, to use instead of POST input, which is t =cut -sub getValueFromPost { +sub getValue { my $self = shift; if (@_) { @@ -108,6 +119,18 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders an interval control. @@ -126,7 +149,7 @@ sub toHtml { 'weeks'=>$i18n->get(701), 'months'=>$i18n->get(702), 'years'=>$i18n->get(703)); - my ($interval, $units) = $self->session->datetime->secondsToInterval($self->get("value")); + my ($interval, $units) = $self->session->datetime->secondsToInterval($self->getDefaultValue); # not sure why, but these things need to be defined like this or # they fail under some circumstnaces my $cmd = "WebGUI::Form::Integer"; @@ -141,7 +164,7 @@ sub toHtml { options=>\%units, name=>$self->get("name")."_units", id=>$self->get('id')."_units", - value=>[$units] + value=>$units )->toHtml; return $out; } @@ -157,7 +180,7 @@ Returns the field as hidden controls rather than displayable controls. sub toHtmlAsHidden { my $self = shift; - my ($interval, $units) = $self->session->datetime->secondsToInterval($self->get("value")); + my ($interval, $units) = $self->session->datetime->secondsToInterval($self->getDefaultValue); return WebGUI::Form::Hidden->new($self->session, name=>$self->get("name").'_interval', value=>$interval diff --git a/lib/WebGUI/Form/LdapLink.pm b/lib/WebGUI/Form/LdapLink.pm index f444a13cb..87ae2e913 100644 --- a/lib/WebGUI/Form/LdapLink.pm +++ b/lib/WebGUI/Form/LdapLink.pm @@ -39,6 +39,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -79,9 +91,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("LDAPLink_1075","AuthLDAP") - }, label=>{ defaultValue=>$i18n->get("LDAPLink_1075","AuthLDAP") }, @@ -100,15 +109,49 @@ sub definition { afterEdit=>{ defaultValue=>undef }, - dbDataType => { - defaultValue => "TEXT", - }, - }); + }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "TEXT". + +=cut + +sub getDatabaseFieldType { + return "TEXT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'AuthLDAP')->get('LDAPLink_1075'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a database connection picker control. @@ -148,7 +191,7 @@ sub toHtmlWithWrapper { if ($self->session->user->isInGroup(3)) { my $subtext; if ($self->get("afterEdit")) { - $subtext = $self->session->icon->edit("op=editLDAPLink;llid=".$self->get("value").";afterEdit=".$self->session->url->escape($self->get("afterEdit"))); + $subtext = $self->session->icon->edit("op=editLDAPLink;llid=".$self->getDefaultValue.";afterEdit=".$self->session->url->escape($self->get("afterEdit"))); } $subtext .= $self->session->icon->manage("op=listLDAPLinks"); $self->set("subtext", $subtext . $self->get("subtext")); diff --git a/lib/WebGUI/Form/List.pm b/lib/WebGUI/Form/List.pm index 923506057..9199f202b 100644 --- a/lib/WebGUI/Form/List.pm +++ b/lib/WebGUI/Form/List.pm @@ -58,56 +58,16 @@ sub alignmentSeparator { #------------------------------------------------------------------- -=head2 correctOptions ( ) +=head2 areOptionsSettable ( ) -Parse a string for a list of options to present to the user. This method -will mainly be called from WebGUI::Form::DynamicField. +Returns a boolean indicating whether the options of the list are settable. Some have a predefined set of options. This is useful in generating dynamic forms. Returns 1. =cut -sub correctOptions { - my ($self, $possibleValues) = @_; - my %options; - tie %options, 'Tie::IxHash'; - foreach (split(/\n/, $possibleValues)) { - s/\s+$//; # remove trailing spaces - $options{$_} = $_; - } - if ($self->get('options') && ref($self->get('options')) eq "HASH") { - %options = (%{$self->get('options')} , %options); - } - $self->set('options', \%options); +sub areOptionsSettable { + return 1; } - -##------------------------------------------------------------------- - -=head2 correctValues ( ) - -Parse a string for a list of values that should be selected. This method -will mainly be called from WebGUI::Form::DynamicField. Form types that -don't have multiple select, like RadioLists, need to override this -method. - -=cut - -sub correctValues { - my ($self, $value) = @_; - return undef unless defined $value; - my @defaultValues; - if (ref $value eq "ARRAY") { - @defaultValues = @{ $value }; - } - else { - foreach (split(/\n/, $value)) { - s/\s+$//; # remove trailing spaces - push(@defaultValues, $_); - } - } - $self->set("value", \@defaultValues); -} - - #------------------------------------------------------------------- =head2 definition ( [ additionalTerms ] ) @@ -138,25 +98,17 @@ A boolean indicating whether the user can select multiple items from this list l A boolean value for whether or not the values in the options hash should be sorted. Defaults to "0". -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("486"), - }, options=>{ defaultValue=>{} }, - defaultValue=>{ + defaultValue=>{ defaultValue=>[], }, multiple=>{ @@ -168,12 +120,6 @@ sub definition { size=>{ defaultValue=>1 }, - profileEnabled=>{ - defaultValue=>0 - }, - dbDataType => { - defaultValue => "TEXT", - }, }); return $class->SUPER::definition($session, $definition); } @@ -181,22 +127,72 @@ sub definition { #------------------------------------------------------------------- -=head2 displayValue ( ) +=head2 getDatabaseFieldType ( ) -Return all the options +Returns "LONGTEXT". -=cut +=cut -sub displayValue { - my ($self) = @_; - return join ", ", $self->getValues(); +sub getDatabaseFieldType { + return "LONGTEXT"; } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) -Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar. +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('486'); +} + +#------------------------------------------------------------------- + +=head2 getOptions ( ) + +Options are passed in for many list types. Those options can come in as a hash ref, or a \n separated string, or a key|value\n separated string. This method returns a hash ref regardless of what's passed in. + +=cut + +sub getOptions { + my ($self) = @_; + my $possibleValues = $self->get('options'); + my %options = (); + tie %options, 'Tie::IxHash'; + if (ref $possibleValues eq "HASH") { + %options = %{$possibleValues}; + } + else { + foreach my $line (split "\n", $possibleValues) { + if ($line =~ m/(.*)|(.*)/) { + $options{$1} = $2; + } + else { + $options{$line} = $line; + } + } + } + if ($self->get('sortByValue')) { + my %ordered = (); + tie %ordered, 'Tie::IxHash'; + foreach my $optionKey (sort {"\L$options{$a}" cmp "\L$options{$b}" } keys %options) { + $ordered{$optionKey} = $options{$optionKey}; + } + return \%ordered; + } + return \%options; +} + + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) + +Returns an array or a carriage return ("\n") separated scalar depending upon whether you're returning the values into an array or a scalar. Also parses the input values (wherever they come from) to see if it's a scalar then it splits on \n. =head3 value @@ -204,56 +200,78 @@ Optional values to process, instead of POST input. =cut -sub getValueFromPost { - my $self = shift; - my @data = @_ ? @_ : $self->session->form->param($self->get("name")); - return wantarray ? @data : join("\n",@data); +sub getValue { + my ($self, $value) = @_; + my @values = (); + if (defined $value) { + if (ref $value eq "ARRAY") { + @values = @{$value}; + } + else { + @values = split "\n", $value; + } + } + if (scalar @values < 1 && $self->session->request) { + my $value = $self->session->form->param($self->get("name")); + if (defined $value) { + @values = $self->session->form->param($self->get("name")); + } + } + if (scalar @values < 1) { + @values = $self->getDefaultValue; + } + return wantarray ? @values : join("\n",@values); +} + +#------------------------------------------------------------------- + +=head2 getDefaultValue ( ) + +Returns the either the "value" ore "defaultValue" passed in to the object in that order, and doesn't take into account form processing. + +=cut + +sub getDefaultValue { + my $self = shift; + my @values = (); + foreach my $value ($self->get("value"), $self->get("defaultValue")) { + if (scalar @values < 1 && defined $value) { + if (ref $value eq "ARRAY") { + @values = @{$value}; + } + else { + @values = split "\n", $value; + } + } + } + return wantarray ? @values : join("\n",@values); +} + +#------------------------------------------------------------------- + +=head2 getValueAsHtml ( ) + +Return all the options + +=cut + +sub getValueAsHtml { + my ($self) = @_; + my $options = $self->getOptions; + return join ", ", map { $options->{$_} } $self->getValue(); } #------------------------------------------------------------------- =head2 getValues ( ) -Safely handle returning values whether the stored data is scalar or an array -ref. +Depricated. See getValue(). =cut sub getValues { my $self = shift; - my @values = (); - if (ref $self->get("value") eq 'ARRAY') { - @values = @{ $self->get("value") }; - } - else { - push @values, $self->get("value"); - } - return @values; -} - -#------------------------------------------------------------------- - -=head2 orderedHash ( ) - -Based on whether the sortByValue flag is set, return the options hash -for List type Forms sorted by values. The sort is done without regard -to the case of the values. - -=cut - -sub orderedHash { - my ($self) = @_; - my %options; - tie %options, 'Tie::IxHash'; - my $original = $self->get("options"); - if ($self->get('sortByValue')) { - foreach my $optionKey (sort {"\L$original->{$a}" cmp "\L$original->{$b}" } keys %{$original}) { - $options{$optionKey} = $original->{$optionKey}; - } - } else { - %options = %{$original}; - } - return %options; + return $self->getValue(@_); } @@ -267,21 +285,19 @@ Creates a series of hidden fields representing the data in the list. sub toHtmlAsHidden { my $self = shift; - my %options; - tie %options, 'Tie::IxHash'; - %options = $self->orderedHash(); + my $options = $self->getOptions(); my $output; - my @values = $self->getValues(); - foreach my $key (keys %options) { - foreach my $item (@values) { - if ($item eq $key) { - $output .= WebGUI::Form::Hidden->new($self->session, - name=>$self->get("name"), - value=>$key - )->toHtmlAsHidden; - } - } - } + my @values = $self->getDefaultValue(); + foreach my $key (keys %{$options}) { + foreach my $item (@values) { + if ($item eq $key) { + $output .= WebGUI::Form::Hidden->new($self->session, + name=>$self->get("name"), + value=>$key + )->toHtmlAsHidden; + } + } + } return $output; } diff --git a/lib/WebGUI/Form/MimeType.pm b/lib/WebGUI/Form/MimeType.pm index 000a832be..0c972197c 100644 --- a/lib/WebGUI/Form/MimeType.pm +++ b/lib/WebGUI/Form/MimeType.pm @@ -58,21 +58,40 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session, 'Form_MimeType'); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get('mimeType'), - }, label=>{ defaultValue=>$i18n->get('mimeType'), }, - profileEnabled=>{ - defaultValue=>0 - } }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'Form_MimeType')->get('mimeType'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a database connection picker control. diff --git a/lib/WebGUI/Form/Password.pm b/lib/WebGUI/Form/Password.pm index 6a1179690..b291e1f07 100644 --- a/lib/WebGUI/Form/Password.pm +++ b/lib/WebGUI/Form/Password.pm @@ -54,36 +54,63 @@ Defaults to 35. Determines the maximum number of characters allowed in this fiel Defaults to 30. Specifies how big of a text box to display. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("51") - }, maxlength=>{ defaultValue=>35 }, size=>{ defaultValue=>30 }, - profileEnabled=>{ - defaultValue=>1 - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('51'); +} + +#------------------------------------------------------------------- + +=head2 getValueAsHtml ( ) + +Formats as ******. + +=cut + +sub getValueAsHtml { + return '******'; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders an input tag of type password. @@ -92,7 +119,7 @@ Renders an input tag of type password. sub toHtml { my $self = shift; - my $html = 'get("name").'" value="'.$self->fixQuotes($self->getDefaultValue).'" size="'.$self->get("size").'" id="'.$self->get('id').'" '; $html .= 'maxlength="'.$self->get("maxlength").'" ' if ($self->get("maxlength")); $html .= $self->get("extras").' />'; return $html; diff --git a/lib/WebGUI/Form/Phone.pm b/lib/WebGUI/Form/Phone.pm index 09657fa51..e96c3943f 100644 --- a/lib/WebGUI/Form/Phone.pm +++ b/lib/WebGUI/Form/Phone.pm @@ -38,39 +38,20 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- -=head2 definition ( [ additionalTerms ] ) +=head2 getName ( session ) -See the super class for additional details. - -=head3 additionalTerms - -The following additional parameters have been added via this sub class. - -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile +Returns the human readable name of this control. =cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("481") - }, - profileEnabled=>{ - defaultValue=>1 - }, - }); - return $class->SUPER::definition($session, $definition); +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('481'); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getValue ( [ value ] ) Returns a string filtered to allow only digits, spaces, and these special characters: + - ( ) or it will return undef it the number doesn't validate to those. @@ -80,9 +61,9 @@ An input value to use instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = @_ ? shift : $self->session->form->param($self->get("name")); + my $value = $self->SUPER::getValue(@_); if ($value =~ /^[x\d \.\-\+\(\)]+$/ and $value =~ /\d/) { return $value; } @@ -91,6 +72,18 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a phone number field. diff --git a/lib/WebGUI/Form/Radio.pm b/lib/WebGUI/Form/Radio.pm index fbc52093c..4064c79e2 100644 --- a/lib/WebGUI/Form/Radio.pm +++ b/lib/WebGUI/Form/Radio.pm @@ -50,27 +50,16 @@ The following additional parameters have been added via this sub class. Defaults to "0". Set to "1" if this field should be checked. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("radio") - }, checked=>{ defaultValue=> 0 }, - profileEnabled=>{ - defaultValue=>1 - }, }); return $class->SUPER::definition($session, $definition); } @@ -90,6 +79,19 @@ sub generateIdParameter { #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('radio'); +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders and input tag of type radio. diff --git a/lib/WebGUI/Form/RadioList.pm b/lib/WebGUI/Form/RadioList.pm index 14c17dc6c..5789a5bad 100644 --- a/lib/WebGUI/Form/RadioList.pm +++ b/lib/WebGUI/Form/RadioList.pm @@ -37,17 +37,6 @@ The following methods are specifically available from this class. Check the supe =cut -##------------------------------------------------------------------- - -=head2 correctValues ( ) - -Override method from master class since RadioList only supports a single value - -=cut - -sub correctValues { } - - #------------------------------------------------------------------- =head2 definition ( [ additionalTerms ] ) @@ -62,27 +51,16 @@ The following additional parameters have been added via this sub class. Boolean representing whether the checklist should be represented vertically or horizontally. If set to "1" will be displayed vertically. Defaults to "0". -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("942") - }, vertical=>{ defaultValue=>0 }, - profileEnabled=>{ - defaultValue=>1 - }, defaultValue=>{ defaultValue=>'' } @@ -91,6 +69,57 @@ sub definition { } +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('942'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) + +See WebGUI::Form::Control::getValue() + +=cut + +sub getValue { + my $self = shift; + return $self->WebGUI::Form::Control::getValue(@_); +} + +#------------------------------------------------------------------- + +=head2 getDefaultValue ( [ value ] ) + +See WebGUI::Form::Control::getDefaultValue() + +=cut + +sub getDefaultValue { + my $self = shift; + return $self->WebGUI::Form::Control::getDefaultValue(@_); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + #------------------------------------------------------------------- =head2 toHtml ( ) @@ -103,26 +132,24 @@ sub toHtml { my $self = shift; my $output; my $alignment = $self->alignmentSeparator; - my %options; - tie %options, 'Tie::IxHash'; - %options = $self->orderedHash; my $i=0; - foreach my $key (keys %options) { + my $options = $self->getOptions; + foreach my $key (keys %{$options}) { $i++; - my $checked = 0; - if ($self->get('value') eq $key) { - $checked = 1; - } - $output .= WebGUI::Form::Radio->new($self->session, { - name=>$self->get('name'), - value=>$key, - extras=>$self->get('extras'), - checked=>$checked, - id=>$self->get('name').$i - })->toHtml; - $output .= '" . $alignment; + my $checked = 0; + if ($self->get('value') eq $key) { + $checked = 1; } - return $output; + $output .= WebGUI::Form::Radio->new($self->session, { + name=>$self->get('name'), + value=>$key, + extras=>$self->get('extras'), + checked=>$checked, + id=>$self->get('name').$i + })->toHtml; + $output .= '" . $alignment; + } + return $output; } 1; diff --git a/lib/WebGUI/Form/ReadOnly.pm b/lib/WebGUI/Form/ReadOnly.pm index bedc5b94e..3367b5e64 100644 --- a/lib/WebGUI/Form/ReadOnly.pm +++ b/lib/WebGUI/Form/ReadOnly.pm @@ -39,50 +39,43 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- -=head2 definition ( [ additionalTerms ] ) +=head2 getName ( session ) -See the super class for additional details. - -=head3 additionalTerms - -The following additional parameters have been added via this sub class. - -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile +Returns the human readable name of this control. =cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("read only") - }, - profileEnabled=>{ - defaultValue=>1 - }, - }); - return $class->SUPER::definition($session, $definition); +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('read only'); } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getValue ( ) Returns undef. =cut -sub getValueFromPost { +sub getValue { return undef; } #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders the value. @@ -91,7 +84,7 @@ Renders the value. sub toHtml { my $self = shift; - return $self->get("value"); + return $self->getDefaultValue; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/SelectBox.pm b/lib/WebGUI/Form/SelectBox.pm index ca8ac5ec8..6f039a5e9 100644 --- a/lib/WebGUI/Form/SelectBox.pm +++ b/lib/WebGUI/Form/SelectBox.pm @@ -36,16 +36,6 @@ The following methods are specifically available from this class. Check the supe =cut -##------------------------------------------------------------------- - -=head2 correctValues ( ) - -Override method from master class since SelectBox only support a single value - -=cut - -sub correctValues { } - #------------------------------------------------------------------- =head2 definition ( [ additionalTerms ] ) @@ -60,58 +50,92 @@ The following additional parameters have been added via this sub class. The number of characters tall this list should be. Defaults to '1'. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("487"), - }, defaultValue=>{ defaultValue=>'', # gotta be a scalar, not an arrayref. }, size=>{ defaultValue=>1, }, - profileEnabled=>{ - defaultValue=>1, - }, - dbDataType => { - defaultValue => "VARCHAR(255)", - } }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getDatabaseFieldType ( ) -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. Note, this is exactly the same method as used by Control since SelectBoxes only support a single value. +Returns "VARCHAR(255)". -=head3 value +=cut -Optional values to process (read "return"), instead of POST input. +sub getDatabaseFieldType { + return "VARCHAR(255)"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. =cut -sub getValueFromPost { - my $self = shift; +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('487'); +} - my $formValue = @_ ? shift : $self->session->form->param($self->get("name")); - if (defined $formValue) { - return $formValue; - } else { - return $self->get("defaultValue"); +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) + +See WebGUI::Form::Control::getValue() + +=cut + +sub getValue { + my $self = shift; + return $self->WebGUI::Form::Control::getValue(@_); +} + +#------------------------------------------------------------------- + +=head2 getDefaultValue ( ) + +Returns the either the "value" ore "defaultValue" passed in to the object in that order, and doesn't take into account form processing. + +=cut + +sub getDefaultValue { + my $self = shift; + my $value = $self->get("value"); + unless (defined $value) { + $value = $self->get("defaultValue"); } + if (ref $value eq 'ARRAY') { + $value = $value->[0]; + } + return $value; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; } #------------------------------------------------------------------- @@ -125,17 +149,15 @@ Renders a select list form control. sub toHtml { my $self = shift; my $output = ''."\n"; return $output; } diff --git a/lib/WebGUI/Form/SelectList.pm b/lib/WebGUI/Form/SelectList.pm index af09464f0..1b23422b5 100644 --- a/lib/WebGUI/Form/SelectList.pm +++ b/lib/WebGUI/Form/SelectList.pm @@ -54,32 +54,18 @@ The number of characters tall this list should be. Defaults to '5'. A boolean indicating whether the user can select multiple items from this list like a checkList. Defaults to "1". -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("484"), - }, multiple=>{ defaultValue=>1 }, size=>{ defaultValue=>5 - }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "LONGTEXT", }, }); return $class->SUPER::definition($session, $definition); @@ -87,6 +73,31 @@ sub definition { #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('484'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a select list form control. @@ -97,18 +108,16 @@ sub toHtml { my $self = shift; my $multiple = $self->get("multiple") ? ' multiple="multiple"' : ''; my $output = ''."\n"; return $output; diff --git a/lib/WebGUI/Form/SelectRichEditor.pm b/lib/WebGUI/Form/SelectRichEditor.pm index aa57f221f..bfd10c77f 100644 --- a/lib/WebGUI/Form/SelectRichEditor.pm +++ b/lib/WebGUI/Form/SelectRichEditor.pm @@ -36,6 +36,18 @@ The following methods are specifically available from this class. Check the supe =cut +#------------------------------------------------------------------- + +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + #---------------------------------------------------------------------------- =head2 definition ( [ additionalTerms ] ) @@ -57,11 +69,7 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push @{$definition}, { - formName => { - defaultValue => $i18n->get("475"), - }, defaultValue => { defaultValue => '', }, @@ -69,6 +77,19 @@ sub definition { return $class->SUPER::definition($session, $definition); } +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('SelectRichEditor formName'); +} + #---------------------------------------------------------------------------- =head2 new diff --git a/lib/WebGUI/Form/SelectSlider.pm b/lib/WebGUI/Form/SelectSlider.pm index 40c13bbb2..d2dd142b1 100644 --- a/lib/WebGUI/Form/SelectSlider.pm +++ b/lib/WebGUI/Form/SelectSlider.pm @@ -41,29 +41,44 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=> $i18n->get("select slider") - }, options =>{ defaultValue=>{}, }, value =>{ defaultValue=>[], }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "TEXT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "TEXT". + +=cut + +sub getDatabaseFieldType { + return "TEXT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('select slider'); +} + +#------------------------------------------------------------------- + =head2 getDisplayValue ( ) Returns the value that should be displayed initially. @@ -73,7 +88,7 @@ Returns the value that should be displayed initially. sub getDisplayValue { my $self = shift; - return $self->get('options')->{$self->get('value')->[0]}; + return $self->getOptions->{$self->get('value')->[0]}; } #------------------------------------------------------------------- @@ -90,7 +105,7 @@ sub getInputElement { return WebGUI::Form::selectList($self->session, { -name => $self->get('name'), -value => $self->get('value'), - -options=> $self->get('options'), + -options=> $self->getOptions, -id => 'view-'.$self->get('id'), -size => 1, }); @@ -131,6 +146,35 @@ sub getOnChangeSlider { #------------------------------------------------------------------- +=head2 getOptions ( ) + +Options are passed in for many list types. Those options can come in as a hash ref, or a \n separated string, or a key|value\n separated string. This method returns a hash ref regardless of what's passed in. + +=cut + +sub getOptions { + my ($self) = @_; + my $possibleValues = $self->get('options'); + my %options = (); + tie %options, 'Tie::IxHash'; + if (ref $possibleValues eq "HASH") { + %options = %{$possibleValues}; + } + else { + foreach my $line (split "\n", $possibleValues) { + if ($line =~ m/(.*)|(.*)/) { + $options{$1} = $2; + } + else { + $options{$line} = $line; + } + } + } + return \%options; +} + +#------------------------------------------------------------------- + =head2 getSliderMaximum ( ) Returns the maximum value the slider can be set to in slider units. @@ -140,7 +184,7 @@ Returns the maximum value the slider can be set to in slider units. sub getSliderMaximum { my $self = shift; - return scalar(keys %{$self->get('options')}) - 1; + return scalar(keys %{$self->getOptions}) - 1; } #------------------------------------------------------------------- @@ -168,7 +212,7 @@ Returns the initial position of the slider in slider units. sub getSliderValue { my $self = shift; - my @keys = keys %{$self->get('options')}; + my @keys = keys %{$self->getOptions}; for (my $i = 0; $i < @keys; $i++) { return $i if $keys[$i] eq $self->get('value')->[0]; } @@ -178,7 +222,7 @@ sub getSliderValue { #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getValue ( [ value ] ) 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. Strip @@ -190,21 +234,33 @@ A value to process instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; my @args = @_; my $properties = { -name => $self->get('name'), -value => $self->get('value'), - -options=> $self->get('options'), + -options=> $self->getOptions, -id => 'view-'.$self->get('id'), -size => 1, }; - return WebGUI::Form::SelectList->new($self->session, $properties)->getValueFromPost(@args); + return WebGUI::Form::SelectList->new($self->session, $properties)->getValue(@args); } +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + 1; diff --git a/lib/WebGUI/Form/Slider.pm b/lib/WebGUI/Form/Slider.pm index 5ac98b962..7c41cc955 100644 --- a/lib/WebGUI/Form/Slider.pm +++ b/lib/WebGUI/Form/Slider.pm @@ -60,21 +60,13 @@ Defaults to "0". The minimum value that the slider can go to. Defaults to 1. Setting this option to 0 will hide the input element tied to the slider. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=> "No name", - }, maximum=>{ defaultValue=> "100", }, @@ -84,9 +76,6 @@ sub definition { editable=>{ defaultValue=> "1", }, - profileEnabled=>{ - defaultValue=>0, - }, }); return $class->SUPER::definition($session, $definition); } @@ -156,6 +145,19 @@ sub getInputVariable { #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('slider'); +} + +#------------------------------------------------------------------- + =head2 getOnChangeInputElement ( ) This method should return the javascript code that should be executed on an diff --git a/lib/WebGUI/Form/Submit.pm b/lib/WebGUI/Form/Submit.pm index 3298f79aa..85c8f301f 100644 --- a/lib/WebGUI/Form/Submit.pm +++ b/lib/WebGUI/Form/Submit.pm @@ -38,23 +38,15 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- -=head2 definition ( ) +=head2 getName ( session ) -See the super class for additional details. +Returns the human readable name of this control. =cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("submit") - }, - }); - return $class->SUPER::definition($session, $definition); +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('submit'); } #------------------------------------------------------------------- @@ -67,7 +59,7 @@ Renders a button. sub toHtml { my $self = shift; - my $value = $self->fixQuotes($self->get("value")); + my $value = $self->fixQuotes($self->getDefaultValue); my $extras = $self->get("extras") || q|class="forwardButton"|; my $i18n = WebGUI::International->new($self->session); $self->{_params}{extras} ||= 'onclick="this.value=\''.$i18n->get(452).'\'"'; diff --git a/lib/WebGUI/Form/SubscriptionGroup.pm b/lib/WebGUI/Form/SubscriptionGroup.pm index f1e2ef0da..cc0ab8223 100644 --- a/lib/WebGUI/Form/SubscriptionGroup.pm +++ b/lib/WebGUI/Form/SubscriptionGroup.pm @@ -36,36 +36,18 @@ The following methods are specifically available from this class. Check the supe =cut + #------------------------------------------------------------------- -=head2 definition ( [ additionalTerms ] ) +=head2 getName ( session ) -See the super class for additional details. - -=head3 additionalTerms - -The following additional parameters have been added via this sub class. - -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile +Returns the human readable name of this control. =cut -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift || []; - my $i18n = WebGUI::International->new($session); - push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("hidden") - }, - profileEnabled=>{ - defaultValue=>0 - }, - }); - return $class->SUPER::definition($session, $definition); +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('SubscriptionGroup formName'); } #------------------------------------------------------------------- @@ -78,7 +60,7 @@ Renders the form field to HTML as a table row. The row is not displayed because sub toHtmlWithWrapper { my $self = shift; - my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value")))) || ''; + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))) || ''; my $manageButton = " "; if($value) { diff --git a/lib/WebGUI/Form/Template.pm b/lib/WebGUI/Form/Template.pm index 02db443d9..bb853d55e 100644 --- a/lib/WebGUI/Form/Template.pm +++ b/lib/WebGUI/Form/Template.pm @@ -39,6 +39,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -71,9 +83,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session, 'Asset_Template'); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("assetName") - }, label=>{ defaultValue=>$i18n->get("assetName") }, @@ -86,15 +95,49 @@ sub definition { onlyCommitted=>{ defaultValue=>'' }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, - }); + }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "VARCHAR(22) BINARY". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(22) BINARY"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'Asset_Template')->get('assetName'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a template picker control. diff --git a/lib/WebGUI/Form/Text.pm b/lib/WebGUI/Form/Text.pm index 929721246..fd3d89292 100644 --- a/lib/WebGUI/Form/Text.pm +++ b/lib/WebGUI/Form/Text.pm @@ -54,37 +54,39 @@ Defaults to 255. Determines the maximum number of characters allowed in this fie Defaults to the setting textBoxSize or 30 if that's not set. Specifies how big of a text box to display. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=> $i18n->get("475") - }, maxlength=>{ defaultValue=> 255 }, size=>{ defaultValue=>$session->setting->get("textBoxSize") || 30 }, - profileEnabled=>{ - defaultValue=>1 - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('475'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) 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. Strip newlines/carriage returns from the value. @@ -94,22 +96,23 @@ An optional value to process, instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $formValue; + my $value = $self->SUPER::getValue(@_); + $value =~ tr/\n\n//d; + return $value; +} - if (@_) { - $formValue = shift; - } - elsif ($self->session->request) { - $formValue = $self->session->form->param($self->get("name")); - } - if (defined $formValue) { - $formValue =~ tr/\r\n//d; - return $formValue; - } else { - return $self->{defaultValue}; - } +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; } #------------------------------------------------------------------- @@ -122,7 +125,7 @@ Renders an input tag of type text. sub toHtml { my $self = shift; - my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value")))); + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))); return 'get("extras").' />'; } diff --git a/lib/WebGUI/Form/Textarea.pm b/lib/WebGUI/Form/Textarea.pm index 7729a5e77..e7a5ec369 100644 --- a/lib/WebGUI/Form/Textarea.pm +++ b/lib/WebGUI/Form/Textarea.pm @@ -58,10 +58,6 @@ The height of this control in pixels. Defaults to 150 pixels. Style attributes besides width and height which should be specified using the above parameters. Be sure to escape quotes if you use any. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =head4 resizable A boolean indicating whether the text area can be reized by users. Defaults to 1. @@ -72,11 +68,7 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("476") - }, height=>{ defaultValue=> 150 }, @@ -89,18 +81,49 @@ sub definition { resizable => { defaultValue => 1, }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "LONGTEXT", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "LONGTEXT". + +=cut + +sub getDatabaseFieldType { + return "LONGTEXT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('476'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders an input tag of type text. @@ -109,7 +132,7 @@ Renders an input tag of type text. sub toHtml { my $self = shift; - my $value = $self->fixMacros($self->fixTags($self->fixSpecialCharacters($self->get("value")))); + my $value = $self->fixMacros($self->fixTags($self->fixSpecialCharacters($self->getDefaultValue))); my $width = $self->get('width') || 400; my $height = $self->get('height') || 150; my ($style, $url) = $self->session->quick(qw(style url)); diff --git a/lib/WebGUI/Form/TimeField.pm b/lib/WebGUI/Form/TimeField.pm index f34715e11..fdcbab845 100644 --- a/lib/WebGUI/Form/TimeField.pm +++ b/lib/WebGUI/Form/TimeField.pm @@ -66,21 +66,13 @@ Defaults to 8. Determines the maximum number of characters allowed in this field Default to 8. Determines how many characters wide the field wlll be. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("971") - }, maxlength=>{ defaultValue=>8 }, @@ -89,12 +81,6 @@ sub definition { }, format => { defaultValue => undef, - }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "BIGINT", }, }); return $class->SUPER::definition($session, $definition); @@ -102,7 +88,32 @@ sub definition { #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getDatabaseFieldType ( ) + +Returns "BIGINT". + +=cut + +sub getDatabaseFieldType { + return "BIGINT"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('971'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) If the defaultValue is a MySQL time, the value returned by this form element will be a MySQL time. Note: Will not be adjusted for the user's time zone. @@ -116,11 +127,10 @@ An optional value to process, instead of POST input. This should be in the form =cut -sub getValueFromPost { +sub getValue { my $self = shift; - + my $value = $self->SUPER::getValue(@_); if (@_) { - my $value = shift; if ($self->get('format') ne 'mysql' && ( !$self->get("defaultValue") || $self->get("defaultValue") =~ m/^\d+$/ @@ -143,10 +153,10 @@ sub getValueFromPost { || !$self->get("value") || $self->get("value") =~ m/^\d+$/)) { # epoch format - return $self->session->datetime->timeToSeconds($self->session->form->param($self->get("name")))-($self->session->user->profileField("timeOffset")*3600); - } else { + return $self->session->datetime->timeToSeconds($value)-($self->session->user->profileField("timeOffset")*3600); + } + else { # Mysql format - my $value = $self->session->form->param($self->get("name")); return undef unless $value =~ /^\d{2}\D\d{2}(\D\d{2})?$/; return $value; } @@ -154,6 +164,18 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a time field. @@ -162,18 +184,7 @@ Renders a time field. sub toHtml { my $self = shift; - my $value; - # This should probably be rewritten as a cascading ternary - if (!$self->get("defaultValue") - || $self->get("defaultValue") =~ m/^\d+$/ - || !$self->get("value") - || $self->get("value") =~ m/^\d+$/) { - # Epoch format - $value = $self->session->datetime->secondsToTime($self->get("value")); - } else { - # MySQL format - $value = $self->get("value"); - } + my $value = $self->getDefaultValue; my $i18n = WebGUI::International->new($self->session); $self->session->style->setScript($self->session->url->extras('inputCheck.js'),{ type=>'text/javascript' }); $self->set("extras", $self->get('extras') . ' onkeyup="doInputCheck(document.getElementById(\''.$self->get("id").'\'),\'0123456789:\')"'); @@ -195,18 +206,7 @@ Renders the field as a hidden field. sub toHtmlAsHidden { my $self = shift; - my $value; - # This should probably be rewritten as a cascading ternary - if (!$self->get("defaultValue") - || $self->get("defaultValue") =~ m/^\d+$/ - || !$self->get("value") - || $self->get("value") =~ m/^\d+$/) { - # Epoch format - $value = $self->session->datetime->secondsToTime($self->get("value")); - } else { - # MySQL format - $value = $self->get("value"); - } + my $value = $self->getDefaultValue; return WebGUI::Form::Hidden->new($self->session, name=>$self->get("name"), value=>$value diff --git a/lib/WebGUI/Form/TimeZone.pm b/lib/WebGUI/Form/TimeZone.pm index 2e9a160ef..7bfaa3ffb 100644 --- a/lib/WebGUI/Form/TimeZone.pm +++ b/lib/WebGUI/Form/TimeZone.pm @@ -38,6 +38,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( ) See the super class for additional details. @@ -48,16 +60,37 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("timezone", 'DateTime') - }, value=>{ defaultValue=>undef }, - }); - return $class->SUPER::definition($session, $definition); + }); + return $class->SUPER::definition($session, $definition); +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'DateTime')->get('timezone'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/Url.pm b/lib/WebGUI/Form/Url.pm index 4347d5b7e..a60081038 100644 --- a/lib/WebGUI/Form/Url.pm +++ b/lib/WebGUI/Form/Url.pm @@ -50,10 +50,6 @@ The following additional parameters have been added via this sub class. Defaults to 2048. Determines the maximum number of characters allowed in this field. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { @@ -62,36 +58,45 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("478") - }, maxlength=>{ defaultValue=> 2048 }, - profileEnabled=>{ - defaultValue=>1 - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( ) +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('478'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) Parses the posted value and tries to make corrections if necessary. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = @_ ? shift : $self->session->form->param($self->get("name")); + my $value = $self->SUPER::getValue(@_); $value =~ tr/\r\n//d; if ($value =~ /mailto:/) { return $value; - } elsif ($value =~ /^([A-Z0-9]+[._+-]?){1,}([A-Z0-9]+[_+-]?)+\@(([A-Z0-9]+[._-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i) { + } + elsif ($value =~ /^([A-Z0-9]+[._+-]?){1,}([A-Z0-9]+[_+-]?)+\@(([A-Z0-9]+[._-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i) { return "mailto:".$value; - } elsif ($value =~ /^\// || $value =~ /:\/\// || $value =~ /^\^/) { + } + elsif ($value =~ /^\// || $value =~ /:\/\// || $value =~ /^\^/) { return $value; } return "http://".$value; @@ -99,6 +104,33 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 getValueAsHtml ( ) + +Formats as a link. + +=cut + +sub getValueAsHtml { + my $self = shift; + my $url = $self->getValue; + return ''.$url.''; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a URL field. @@ -106,7 +138,7 @@ Renders a URL field. =cut sub toHtml { - my $self = shift; + my $self = shift; $self->session->style->setScript($self->session->url->extras('addHTTP.js'),{ type=>'text/javascript' }); $self->set("extras", $self->get('extras') . ' onblur="addHTTP(this.form.'.$self->get("name").')"'); return $self->SUPER::toHtml; diff --git a/lib/WebGUI/Form/User.pm b/lib/WebGUI/Form/User.pm index a9f312cca..97d9f3bb3 100644 --- a/lib/WebGUI/Form/User.pm +++ b/lib/WebGUI/Form/User.pm @@ -69,9 +69,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session, "WebGUI"); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("user"), - }, label=>{ defaultValue=>$i18n->get("user"), }, @@ -81,15 +78,67 @@ sub definition { readOnly=>{ defaultValue=>0, }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- +=head2 getDatabaseFieldType ( ) + +Returns "VARCHAR(22) BINARY". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(22) BINARY"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('user'); +} + +#------------------------------------------------------------------- + +=head2 getValueAsHtml ( ) + +Formats as a name. + +=cut + +sub getValueAsHtml { + my $self = shift; + my $user = WebGUI::User->new($self->session, $self->getValue); + if (defined $user) { + return $user->username; + } + return undef; +} + + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a user selector. @@ -98,7 +147,7 @@ Renders a user selector. sub toHtml { my $self = shift; - my $user = WebGUI::User->new($self->session, $self->get("value")); + my $user = WebGUI::User->new($self->session, $self->getDefaultValue); my $manage = undef; if ($self->session->user->isInGroup(3)) { $manage = " ".$self->session->icon->manage('op=listUsers'); diff --git a/lib/WebGUI/Form/WhatNext.pm b/lib/WebGUI/Form/WhatNext.pm index 92191e03d..e119c7326 100644 --- a/lib/WebGUI/Form/WhatNext.pm +++ b/lib/WebGUI/Form/WhatNext.pm @@ -62,9 +62,6 @@ sub definition { my $definition = shift || []; my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("744") - }, label=>{ defaultValue=>$i18n->get("744") }, @@ -77,6 +74,31 @@ sub definition { #------------------------------------------------------------------- +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('744'); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a question selector asking the user where they want to go. diff --git a/lib/WebGUI/Form/Workflow.pm b/lib/WebGUI/Form/Workflow.pm index 7aec8649b..2ae9b46fc 100644 --- a/lib/WebGUI/Form/Workflow.pm +++ b/lib/WebGUI/Form/Workflow.pm @@ -39,6 +39,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -74,11 +86,8 @@ sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session, 'Workflow'); + my $i18n = WebGUI::International->new($session, 'Workflow'); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("topicName") - }, label=>{ defaultValue=>$i18n->get("topicName") }, @@ -94,11 +103,33 @@ sub definition { includeRealtime => { defaultValue => 0 }, - dbDataType => { - defaultValue => "VARCHAR(22) BINARY", - }, - }); - return $class->SUPER::definition($session, $definition); + }); + return $class->SUPER::definition($session, $definition); +} + +#------------------------------------------------------------------- + +=head2 getDatabaseFieldType ( ) + +Returns "VARCHAR(22) BINARY". + +=cut + +sub getDatabaseFieldType { + return "VARCHAR(22) BINARY"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'Workflow')->get('topicName'); } #------------------------------------------------------------------- @@ -130,7 +161,6 @@ sub toHtmlWithWrapper { my $returnUrl = ";proceed=goBackToPage;returnUrl=".$self->session->url->escape($self->session->asset->getUrl) if $self->session->asset; my $buttons; # This edit button will not work with multiple workflows. - #$buttons .= $self->session->icon->edit("op=editWorkflow;workflowId=".$self->get("value")->[0].$returnUrl) if ($self->get("value")); $buttons .= $self->session->icon->manage("op=manageWorkflows".$returnUrl); $self->set("subtext",$buttons . $self->get("subtext")); return $self->SUPER::toHtmlWithWrapper; diff --git a/lib/WebGUI/Form/YesNo.pm b/lib/WebGUI/Form/YesNo.pm index 577613bb4..364c13a7c 100644 --- a/lib/WebGUI/Form/YesNo.pm +++ b/lib/WebGUI/Form/YesNo.pm @@ -51,53 +51,48 @@ The following additional parameters have been added via this sub class. Can be a 1 or 0. Defaults to 0 if no value is specified. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=>$i18n->get("483") - }, defaultValue=>{ defaultValue=>0 }, - profileEnabled=>{ - defaultValue=>1 - }, - dbDataType => { - defaultValue => "bool", - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 yesNo ( ) +=head2 getDatabaseFieldType ( ) -Returns either a 1 or 0 representing yes, no. +Returns "BOOLEAN". -=cut +=cut -sub yesNo { - my $self = shift; - if ($self->session->form->param($self->get("name")) > 0) { - return 1; - } - return 0; +sub getDatabaseFieldType { + return "BOOLEAN"; } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('483'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) If value is present, we will process it, otherwise the superclass will handle the request. @@ -107,15 +102,43 @@ An optional value to process, instead of POST input. This should be in the form =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = shift; - $value = $self->SUPER::getValueFromPost unless (defined $value); + my $value = $self->SUPER::getValue(@_); return ($value =~ /^y/i || $value eq '1') ? 1 : 0; } #------------------------------------------------------------------- +=head2 getValueAsHtml () + +Shows either Yes or No. + +=cut + +sub getValueAsHtml { + my $self = shift; + my $i18n = WebGUI::International->new($self->session); + if ($self->getValue) { + return $i18n->get(138); + } + return $i18n->get(139); +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a yes/no question field. @@ -126,7 +149,7 @@ sub toHtml { my $self = shift; my $i18n = WebGUI::International->new($self->session); my ($checkYes, $checkNo); - if ($self->get("value")) { + if ($self->getDefaultValue) { $checkYes = 1; } else { $checkNo = 1; diff --git a/lib/WebGUI/Form/Zipcode.pm b/lib/WebGUI/Form/Zipcode.pm index 7ea115555..65e65dfdf 100644 --- a/lib/WebGUI/Form/Zipcode.pm +++ b/lib/WebGUI/Form/Zipcode.pm @@ -50,34 +50,36 @@ The following additional parameters have been added via this sub class. Defaults to 10. Determines the maximum number of characters allowed in this field. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=> $i18n->get("944") - }, maxlength=>{ defaultValue=> 10 }, - profileEnabled=>{ - defaultValue=>1 - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('944'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) Returns a validated form post result. If the result does not pass validation, it returns undef instead. @@ -87,9 +89,9 @@ An optional value to use instead of POST input. =cut -sub getValueFromPost { +sub getValue { my $self = shift; - my $value = @_ ? shift : $self->session->form->param($self->get("name")); + my $value = $self->SUPER::getValue(@_); $value =~ tr/\r\n//d; if ($value =~ /^[A-Z\d\s\-]+$/) { return $value; @@ -99,6 +101,18 @@ sub getValueFromPost { #------------------------------------------------------------------- +=head2 isDynamicCompatible ( ) + +A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. + +=cut + +sub isDynamicCompatible { + return 1; +} + +#------------------------------------------------------------------- + =head2 toHtml ( ) Renders a zip code field. diff --git a/lib/WebGUI/Form/_control.skeleton b/lib/WebGUI/Form/_control.skeleton index f2baf4e7a..d8a94ff63 100644 --- a/lib/WebGUI/Form/_control.skeleton +++ b/lib/WebGUI/Form/_control.skeleton @@ -50,58 +50,49 @@ The following additional parameters have been added via this sub class. Defaults to the setting textBoxSize or 30 if that's not set. Specifies how big of a text box to display. -=head4 profileEnabled - -Flag that tells the User Profile system that this is a valid form element in a User Profile - =cut sub definition { my $class = shift; my $session = shift; my $definition = shift || []; - my $i18n = WebGUI::International->new($session); push(@{$definition}, { - formName=>{ - defaultValue=> $i18n->get("475") - }, size=>{ defaultValue=>$session->setting->get("textBoxSize") || 30 }, - profileEnabled=>{ - defaultValue=>1 - }, }); return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- -=head2 getValueFromPost ( [ value ] ) +=head2 getName ( session ) -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. - -=head3 value - -An optional value to process, instead of POST input. +Returns the name of the form control. =cut -sub getValueFromPost { - my $self = shift; - my $formValue; +sub getName { + my ($class, $session) = @_; + return WebGUI::International->new($session, "Form_MyControl")>get("topicName"); +} - if (@_) { - $formValue = shift; - } - elsif ($self->session->request) { - $formValue = $self->session->form->param($self->get("name")); - } - if (defined $formValue) { - return $formValue; - } else { - return $self->{defaultValue}; - } + +#------------------------------------------------------------------- + +=head2 getValue ( [ value ] ) + +Does some special processing. + +=cut + +sub getValue { + my $self = shift; + my $value = $self->SUPER::getValue(@_); + + # ... do your work here + + return $value; } #------------------------------------------------------------------- @@ -114,7 +105,7 @@ Renders an input tag of type text. sub toHtml { my $self = shift; - my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value")))); + my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))); return 'get("extras").' />'; } diff --git a/lib/WebGUI/FormValidator.pm b/lib/WebGUI/FormValidator.pm index b97322a97..0c03cbe60 100644 --- a/lib/WebGUI/FormValidator.pm +++ b/lib/WebGUI/FormValidator.pm @@ -76,7 +76,7 @@ sub AUTOLOAD { $self->session->errorHandler->error($@); return undef; } - return $control->getValueFromPost(@args); + return $control->getValue(@args); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Operation/Graphics.pm b/lib/WebGUI/Operation/Graphics.pm index fb6a1dacf..243e2d958 100644 --- a/lib/WebGUI/Operation/Graphics.pm +++ b/lib/WebGUI/Operation/Graphics.pm @@ -272,7 +272,7 @@ sub www_editFontSave { if ($session->form->process('fid') eq 'new') { - my $fileStorageId = WebGUI::Form::File->new($session,{name => 'fontFile'})->getValueFromPost; + my $fileStorageId = WebGUI::Form::File->new($session,{name => 'fontFile'})->getValue; my $storage = WebGUI::Storage->get($session, $fileStorageId); my $filename = $storage->getFiles()->[0]; diff --git a/lib/WebGUI/ProfileField.pm b/lib/WebGUI/ProfileField.pm index fc848e000..e6a6f4511 100644 --- a/lib/WebGUI/ProfileField.pm +++ b/lib/WebGUI/ProfileField.pm @@ -122,7 +122,7 @@ sub create { $properties->{fieldType} ||= "ReadOnly"; my $formClass = 'WebGUI::Form::' . ucfirst $properties->{fieldType}; eval "use $formClass;"; - my $dbDataType = $formClass->new($session, $self->formProperties($properties))->get("dbDataType"); + my $dbDataType = $formClass->getDatabaseFieldType; # Add the column to the userProfileData table $db->write( @@ -245,11 +245,11 @@ sub formField { } } if ($withWrapper == 1) { - return WebGUI::Form::DynamicField->new($self->session,%{$properties})->displayFormWithWrapper; + return WebGUI::Form::DynamicField->new($self->session,%{$properties})->toHtmlWithWrapper; } elsif ($withWrapper == 2) { - return WebGUI::Form::DynamicField->new($self->session,%{$properties})->displayValue; + return WebGUI::Form::DynamicField->new($self->session,%{$properties})->getValueAsHtml; } else { - return WebGUI::Form::DynamicField->new($self->session,%{$properties})->displayForm; + return WebGUI::Form::DynamicField->new($self->session,%{$properties})->toHtml; } } @@ -592,7 +592,7 @@ sub rename { # Rename the userProfileData column my $fieldClass = $self->getFormControlClass; eval "use $fieldClass;"; - my $dbDataType = $fieldClass->new($session, $self->formProperties)->get("dbDataType"); + my $dbDataType = $fieldClass->getDatabaseFieldType; $self->session->db->write( "ALTER TABLE userProfileData " @@ -698,7 +698,7 @@ sub set { my $fieldClass = "WebGUI::Form::".ucfirst($properties->{fieldType}); eval "use $fieldClass;"; my $dbDataType - = $fieldClass->new($session, $self->formProperties($properties))->get("dbDataType"); + = $fieldClass->new($session, $self->formProperties($properties))->getDatabaseFieldType; my $sql = "ALTER TABLE userProfileData MODIFY COLUMN " diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index f93626a9d..cbbacd703 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -2639,6 +2639,24 @@ div.tabs { lastUpdated => 1044705103 }, + 'class name' => { + message => q|Class Name|, + lastUpdated => 0, + context=> 'Form Type Name, as in "Object Class Name"', + }, + + 'fieldType' => { + message => q|Field Type|, + lastUpdated => 0, + context=> 'form field type', + }, + + 'slider' => { + message => q|Slider|, + lastUpdated => 0, + context=> 'form field type that has a slide selector', + }, + '980' => { message => q|Empty this folder.|, lastUpdated => 1055908341 diff --git a/t/Form/Checkbox.t b/t/Form/Checkbox.t index 3010b0eac..54af4a8f5 100644 --- a/t/Form/Checkbox.t +++ b/t/Form/Checkbox.t @@ -108,5 +108,5 @@ WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); # # test WebGUI::FormValidator::Checkbox(undef,@values) # -is(WebGUI::Form::Checkbox->new($session)->getValueFromPost('test'), 'test', '$cbox->getValueFromPost(arg)'); +is(WebGUI::Form::Checkbox->new($session)->getValue('test'), 'test', '$cbox->getValue(arg)'); is($session->form->checkbox(undef,'test'), 'test', 'WebGUI::FormValidator::checkbox'); diff --git a/t/Form/ClassName.t b/t/Form/ClassName.t index 7642fecdd..dac7b087b 100644 --- a/t/Form/ClassName.t +++ b/t/Form/ClassName.t @@ -130,5 +130,5 @@ WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); # # test WebGUI::FormValidator::ClassName(undef,@values) # -is(WebGUI::Form::ClassName->new($session)->getValueFromPost('t*est'), 'test', '$cname->getValueFromPost(arg)'); +is(WebGUI::Form::ClassName->new($session)->getValue('t*est'), 'test', '$cname->getValue(arg)'); is($session->form->className(undef,'t*est'), 'test', 'WebGUI::FormValidator::className'); diff --git a/t/Form/Email.t b/t/Form/Email.t index 24b3e9d87..ab8bd9989 100644 --- a/t/Form/Email.t +++ b/t/Form/Email.t @@ -107,11 +107,11 @@ is($input->{maxlength}, 200, 'Checking maxlength param, set'); WebGUI::Form_Checking::auto_check($session, 'email', $testBlock); -# just testing that getValueFromPost works with an argument +# just testing that getValue works with an argument my $email = WebGUI::Form::Email->new($session); -is($email->getValueFromPost('james@plainblack.com'), 'james@plainblack.com', 'getValueFromPost(valid) returned a valid email'); -is($email->getValueFromPost('this*isn"t and@emailaddres,s'), undef, 'getValueFromPost(invalid) returned undef instead of an invalid email'); +is($email->getValue('james@plainblack.com'), 'james@plainblack.com', 'getValue(valid) returned a valid email'); +is($email->getValue('this*isn"t and@emailaddres,s'), undef, 'getValue(invalid) returned undef instead of an invalid email'); is($session->form->email(undef,'james@plainblack.com'), 'james@plainblack.com', '$form->email(valid) returned a valid email'); is($session->form->email(undef,'this*isn"t and@emailaddres,s'), undef, '$form->email(invalid) returned undef instead of an invalid email'); diff --git a/t/Form/Float.t b/t/Form/Float.t index f078db745..6219a831d 100644 --- a/t/Form/Float.t +++ b/t/Form/Float.t @@ -143,11 +143,11 @@ is($input->{maxlength}, 20, 'set maxlength'); WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); -# just testing that getValueFromPost works with an argument +# just testing that getValue works with an argument my $float = WebGUI::Form::Float->new($session); -is($float->getValueFromPost('112.233'), 112.233, 'Got a valid float'); -is($float->getValueFromPost('fred'), 0, 'Returned 0 instead of an invalid float'); +is($float->getValue('112.233'), 112.233, 'Got a valid float'); +is($float->getValue('fred'), 0, 'Returned 0 instead of an invalid float'); __END__ diff --git a/t/Form/Integer.t b/t/Form/Integer.t index c6e45ce44..338ac910b 100644 --- a/t/Form/Integer.t +++ b/t/Form/Integer.t @@ -120,14 +120,14 @@ is($input->{maxlength}, 20, 'set maxlength'); WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); -# just testing that getValueFromPost works with an argument +# just testing that getValue works with an argument my $int = WebGUI::Form::Integer->new($session); -is($int->getValueFromPost(-123456), -123456, 'getValueFromPost(-123456)'); -is($int->getValueFromPost('002300'), '002300', 'getValueFromPost(002300)'); -is($int->getValueFromPost('+123456'), 0, 'getValueFromPost(+123456)'); -is($int->getValueFromPost('123-456.'), 0, 'getValueFromPost(123-456.)'); -is($int->getValueFromPost(123.456), 0, 'getValueFromPost(123.456)'); +is($int->getValue(-123456), -123456, 'getValue(-123456)'); +is($int->getValue('002300'), '002300', 'getValue(002300)'); +is($int->getValue('+123456'), 0, 'getValue(+123456)'); +is($int->getValue('123-456.'), 0, 'getValue(123-456.)'); +is($int->getValue(123.456), 0, 'getValue(123.456)'); is($session->form->integer(undef,-123456), -123456, 'session->form->integer(undef,-123456)'); is($session->form->integer(undef,'002300'), '002300', 'session->form->integer(undef,002300)'); diff --git a/t/Form/Phone.t b/t/Form/Phone.t index 8d897300c..f69913332 100644 --- a/t/Form/Phone.t +++ b/t/Form/Phone.t @@ -146,10 +146,10 @@ WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); # test that we can process non-POST values correctly my $cntl = WebGUI::Form::Phone->new($session,{ defaultValue => 4242 }); -is($cntl->getValueFromPost('123-123-1234'), '123-123-1234', 'getValueFromPost(valid)'); -is($cntl->getValueFromPost('123/123-1234'), undef, 'getValueFromPost(invalid)'); -is($cntl->getValueFromPost(0), 0, 'zero'); -is($cntl->getValueFromPost(''), undef, '""'); +is($cntl->getValue('123-123-1234'), '123-123-1234', 'getValue(valid)'); +is($cntl->getValue('123/123-1234'), undef, 'getValue(invalid)'); +is($cntl->getValue(0), 0, 'zero'); +is($cntl->getValue(''), undef, '""'); is($session->form->phone(undef,'123-123-1234'), '123-123-1234', 'valid'); is($session->form->phone(undef,'123/123-1234'), undef, 'invalid'); is($session->form->phone(undef,0), 0, 'zero'); diff --git a/t/Form/SelectBox.t b/t/Form/SelectBox.t index eb4bd66f3..d5fe5d859 100644 --- a/t/Form/SelectBox.t +++ b/t/Form/SelectBox.t @@ -110,11 +110,11 @@ WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); # test that we can process non-POST values correctly my $cntl = WebGUI::Form::SelectBox->new($session,{ defaultValue => 4242 }); -is($cntl->getValueFromPost('text'), 'text', 'getValueFromPost(text)'); -is($cntl->getValueFromPost(42), 42, 'getValueFromPost(int)'); -is($cntl->getValueFromPost(0), 0, 'zero'); -is($cntl->getValueFromPost(''), '', '""'); -is($cntl->getValueFromPost(1,2,3), 1, 'list returns first item'); +is($cntl->getValue('text'), 'text', 'getValue(text)'); +is($cntl->getValue(42), 42, 'getValue(int)'); +is($cntl->getValue(0), 0, 'zero'); +is($cntl->getValue(''), '', '""'); +is($cntl->getValue(1,2,3), 1, 'list returns first item'); is($session->form->selectBox(undef,'text'), 'text', 'text'); is($session->form->selectBox(undef,42), 42, 'int'); is($session->form->selectBox(undef,0), 0, 'zero'); diff --git a/t/Form/Text.t b/t/Form/Text.t index e8a20b534..c82552b18 100644 --- a/t/Form/Text.t +++ b/t/Form/Text.t @@ -116,10 +116,10 @@ WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); # test that we can process non-POST values correctly my $cntl = WebGUI::Form::Text->new($session,{ defaultValue => 4242 }); -is($cntl->getValueFromPost('123-123-1234'), '123-123-1234', 'getValueFromPost(valid)'); -is($cntl->getValueFromPost(0), 0, 'zero'); -is($cntl->getValueFromPost(''), '', '""'); -is($cntl->getValueFromPost(undef), undef, 'undef returns undef'); +is($cntl->getValue('123-123-1234'), '123-123-1234', 'getValue(valid)'); +is($cntl->getValue(0), 0, 'zero'); +is($cntl->getValue(''), '', '""'); +is($cntl->getValue(undef), undef, 'undef returns undef'); is($session->form->text(undef,'123-123-1234'), '123-123-1234', 'valid'); is($session->form->text(undef,0), 0, 'zero'); is($session->form->text(undef,undef), undef, 'undef returns undef'); diff --git a/t/Form/Textarea.t b/t/Form/Textarea.t index 5b035bc11..5b68f066d 100644 --- a/t/Form/Textarea.t +++ b/t/Form/Textarea.t @@ -95,11 +95,11 @@ is($input->value, 'Some & text in " here', 'Checking default value'); WebGUI::Form_Checking::auto_check($session, $formType, $testBlock); -# just testing that getValueFromPost works with an argument +# just testing that getValue works with an argument my $txt = WebGUI::Form::Textarea->new($session); -is($txt->getValueFromPost("some test here"), "some test here", 'getValueFromPost(text)'); -is($txt->getValueFromPost("some \ntest \r\nhere"), "some \ntest \r\nhere", 'getValueFromPost(newlines)'); +is($txt->getValue("some test here"), "some test here", 'getValue(text)'); +is($txt->getValue("some \ntest \r\nhere"), "some \ntest \r\nhere", 'getValue(newlines)'); is($session->form->textarea(undef,"some test here"), "some test here", 'session->form->textarea(undef,text)'); is($session->form->textarea(undef,"some \ntest \r\nhere"), "some \ntest \r\nhere", 'session->form->textarea(undef,newlines)'); diff --git a/t/Form/Url.t b/t/Form/Url.t index c184852d4..926a402d5 100644 --- a/t/Form/Url.t +++ b/t/Form/Url.t @@ -134,13 +134,13 @@ WebGUI::Form_Checking::auto_check($session, 'Url', $testBlock); # test that we can process non-POST values correctly my $cntl = WebGUI::Form::Url->new($session,{ defaultValue => 4242 }); -is($cntl->getValueFromPost('mailto:whatever'), 'mailto:whatever', 'mailto processing'); -is($cntl->getValueFromPost('me@nowhere.com'), 'mailto:me@nowhere.com', 'email address processing'); -is($cntl->getValueFromPost('/'), '/', '/'); -is($cntl->getValueFromPost('://'), '://', '://'); -is($cntl->getValueFromPost('^'), '^', '^'); -is($cntl->getValueFromPost('mySite'), 'http://mySite', 'http://mySite'); -is($cntl->getValueFromPost('??**()!!'), 'http://??**()!!', 'random crap is passed through'); +is($cntl->getValue('mailto:whatever'), 'mailto:whatever', 'mailto processing'); +is($cntl->getValue('me@nowhere.com'), 'mailto:me@nowhere.com', 'email address processing'); +is($cntl->getValue('/'), '/', '/'); +is($cntl->getValue('://'), '://', '://'); +is($cntl->getValue('^'), '^', '^'); +is($cntl->getValue('mySite'), 'http://mySite', 'http://mySite'); +is($cntl->getValue('??**()!!'), 'http://??**()!!', 'random crap is passed through'); is($session->form->url(undef,'mailto:whatever'), 'mailto:whatever', 'mailto processing'); is($session->form->url(undef,'me@nowhere.com'), 'mailto:me@nowhere.com', 'email address processing'); diff --git a/t/Form/Zipcode.t b/t/Form/Zipcode.t index 4f7aa3ee1..1a36aa592 100644 --- a/t/Form/Zipcode.t +++ b/t/Form/Zipcode.t @@ -120,11 +120,11 @@ WebGUI::Form_Checking::auto_check($session, 'Zipcode', $testBlock); # test that we can process non-POST values correctly my $cntl = WebGUI::Form::Zipcode->new($session,{ defaultValue => 4242 }); -is($cntl->getValueFromPost('ABCDE'), 'ABCDE', 'alpha'); -is($cntl->getValueFromPost('02468'), '02468', 'numeric'); -is($cntl->getValueFromPost('NO WHERE'), 'NO WHERE', 'alpha space'); -is($cntl->getValueFromPost('-'), '-', 'bare dash'); -is($cntl->getValueFromPost('abcde'), undef, 'lower case'); +is($cntl->getValue('ABCDE'), 'ABCDE', 'alpha'); +is($cntl->getValue('02468'), '02468', 'numeric'); +is($cntl->getValue('NO WHERE'), 'NO WHERE', 'alpha space'); +is($cntl->getValue('-'), '-', 'bare dash'); +is($cntl->getValue('abcde'), undef, 'lower case'); is($session->form->zipcode(undef,'ABCDE'), 'ABCDE', 'alpha'); is($session->form->zipcode(undef,'02468'), '02468', 'numeric');