From 3733b39fa5b8417ab5c722732d3a469cdac912f1 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 28 Jul 2005 19:26:07 +0000 Subject: [PATCH] sub bug fixes, and the new file form control --- lib/WebGUI/Asset/File.pm | 1 - lib/WebGUI/Form.pm | 63 ---------------------- lib/WebGUI/Form/Control.pm | 15 +++++- lib/WebGUI/Form/HTMLArea.pm | 2 +- lib/WebGUI/Form/button.pm | 2 +- lib/WebGUI/Form/file.pm | 87 ++++++++++++++++++------------- lib/WebGUI/HTMLForm.pm | 56 -------------------- lib/WebGUI/i18n/English/WebGUI.pm | 6 +++ 8 files changed, 74 insertions(+), 158 deletions(-) diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index a5c9f252e..33df19120 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -128,7 +128,6 @@ sub getEditForm { } $tabform->getTab("properties")->file( - -name=>"file", -label=>WebGUI::International::get('new file', 'Asset_File'), -hoverHelp=>WebGUI::International::get('new file description', 'Asset_File'), ); diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index 09d11e5ed..67561400c 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -158,69 +158,6 @@ sub dynamicField { } -#------------------------------------------------------------------- - -=head2 file ( hashRef ) - -Returns a file upload field. - -=head3 name - -The name field for this form element. - -=head3 extras - -If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows: - - 'onChange="this.form.submit()"' - -=head3 size - -The number of characters wide this form element should be. There should be no reason for anyone to specify this. - -=cut - -sub file { - my $params = shift; - my $size = $params->{size} || $session{setting}{textBoxSize} || 30; - return '{extras}.' />'; -} - - -#------------------------------------------------------------------- - -=head2 files ( hashRef ) - -Returns a multiple file upload control. - -=head3 name - -The name field for this form element. - -=cut - -sub files { - WebGUI::Style::setScript($session{config}{extrasURL}.'/FileUploadControl.js',{type=>"text/javascript"}); - my $uploadControl = '
- '; - return $uploadControl; -} - #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm index fd23bf93c..5ee3a6c22 100644 --- a/lib/WebGUI/Form/Control.pm +++ b/lib/WebGUI/Form/Control.pm @@ -306,9 +306,22 @@ sub new { my @reversedDefinitions = reverse @{$class->definition}; foreach my $definition (@reversedDefinitions) { foreach my $fieldName (keys %{$definition}) { - $params{$fieldName} = $raw{$fieldName} || $raw{"-".$fieldName} || $definition->{$fieldName}{defaultValue}; + my $value = $raw{$fieldName}; + # if we have no value, try the tagged name + unless (defined $value) { + $value = $raw{"-".$fieldName}; + } + # if we still have no value try the default value for the field + unless (defined $value) { + $value = $definition->{$fieldName}{defaultValue}; + } + # and finally, if we have a value, let's set it + if (defined $value) { + $params{$fieldName} = $value; + } } } + # if the value field is undefined, lets use the defaultValue field instead unless (exists $params{value}) { $params{value} = $params{defaultValue}; } diff --git a/lib/WebGUI/Form/HTMLArea.pm b/lib/WebGUI/Form/HTMLArea.pm index c3705ecc9..f7c3deafc 100644 --- a/lib/WebGUI/Form/HTMLArea.pm +++ b/lib/WebGUI/Form/HTMLArea.pm @@ -123,7 +123,7 @@ sub toHtml { my $self = shift; WebGUI::Style::setScript($session{config}{extrasURL}.'/textFix.js',{ type=>'text/javascript' }); $self->{extras} .= ' id="'.$self->{name}.'" onBlur="fixChars(this.form.'.$self->{name}.')" mce_editable="true" '; - return $self->SUPER::toHtml.WebGUI::Asset::RichEdit->new($self->{richEditId})->getRichEditor(); + return $self->SUPER::toHtml.WebGUI::Asset::RichEdit->new($self->{richEditId})->getRichEditor($self->{name}); } diff --git a/lib/WebGUI/Form/button.pm b/lib/WebGUI/Form/button.pm index e9a12a7ff..69fee4df9 100644 --- a/lib/WebGUI/Form/button.pm +++ b/lib/WebGUI/Form/button.pm @@ -58,7 +58,7 @@ sub definition { my $definition = shift || []; push(@{$definition}, { defaultValue=>{ - defaultValue=>WebGUI::International::get(62) + defaultValue=>WebGUI::International::get(62,"WebGUI") } }); return $class->SUPER::definition($definition); diff --git a/lib/WebGUI/Form/file.pm b/lib/WebGUI/Form/file.pm index 19c9e34ff..cb192787a 100644 --- a/lib/WebGUI/Form/file.pm +++ b/lib/WebGUI/Form/file.pm @@ -1,4 +1,4 @@ -package WebGUI::Form::text; +package WebGUI::Form::file; =head1 LEGAL @@ -18,10 +18,12 @@ use strict; use base 'WebGUI::Form::Control'; use WebGUI::International; use WebGUI::Session; +use WebGUI::Storage; +use WebGUI::Style; =head1 NAME -Package WebGUI::Form::text +Package WebGUI::Form::file =head1 DESCRIPTION @@ -47,13 +49,13 @@ See the super class for additional details. The following additional parameters have been added via this sub class. -=head4 maxlength +=head4 name -Defaults to 255. Determines the maximum number of characters allowed in this field. +If no name is specified a default name of "file" will be used. -=head4 size +=head4 maxAttachments -Defaults to the setting textBoxSize or 30 if that's not set. Specifies how big of a text box to display. +Defaults to 1. Determines how many files the user can upload with this form control. =cut @@ -61,11 +63,11 @@ sub definition { my $class = shift; my $definition = shift || []; push(@{$definition}, { - maxlength=>{ - defaultValue=> 255 - }, - size=>{ - defaultValue=>$session{setting}{textBoxSize} || 30 + name=>{ + defaultValue=>"file" + } + maxAttachments=>{ + defaultValue=>1 } }); return $class->SUPER::definition($definition); @@ -81,43 +83,45 @@ Returns the human readable name or type of this form control. =cut sub getName { - return WebGUI::International::get("475","WebGUI"); + return WebGUI::International::get("file","WebGUI"); } +#------------------------------------------------------------------- + +=head2 getValueFromPost ( ) + +Returns the storageId for the storage location that the file(s) got uploaded to. Returns undef if no files were uploaded. + +=cut + +sub getValueFromPost { + my $self = shift; + my $storage = WebGUI::Storage->create; + $storage->addFileFromFormPost($self->{name}); + @files = $storage->getFiles; + if (scalar(@files) < 1) { + $storage->delete; + return undef; + } else { + return $storage->getId; + } +} + #------------------------------------------------------------------- =head2 toHtml ( ) -Renders an input tag of type text. +Renders a file upload control. =cut sub toHtml { my $self = shift; - my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value}))); - return '{extras}.' />'; -} - - -#------------------------------------------------------------------- - -=head2 files ( hashRef ) - -Returns a multiple file upload control. - -=head3 name - -The name field for this form element. - -=cut - -sub files { WebGUI::Style::setScript($session{config}{extrasURL}.'/FileUploadControl.js',{type=>"text/javascript"}); - my $uploadControl = '
- '; return $uploadControl; } +#------------------------------------------------------------------- + +=head4 toHtmlAsHidden ( ) + +Returns undef. + +=cut + +sub toHtmlAsHidden { + return undef; +} + + 1; diff --git a/lib/WebGUI/HTMLForm.pm b/lib/WebGUI/HTMLForm.pm index 7f6c8bb6d..af2915b4c 100644 --- a/lib/WebGUI/HTMLForm.pm +++ b/lib/WebGUI/HTMLForm.pm @@ -189,62 +189,6 @@ sub dynamicField { } -#------------------------------------------------------------------- - -=head2 file ( name [, label, subtext, extras, size, uiLevel ] ) - -Adds a file browse row to this form. - -=head3 name - -The name field for this form element. - -=head3 label - -The left column label for this form row. - -=head3 subtext - -Extra text to describe this form element or to provide special instructions. - -=head3 extras - -If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows: - - 'onChange="this.form.submit()"' - -=head3 size - -The number of characters wide this form element should be. There should be no reason for anyone to specify this. - -=head3 uiLevel - -The UI level for this field. See the WebGUI developer's site for details. Defaults to "0". - -=head3 hoverHelp - -A string of text or HTML to be displayed when a user's mouse hover's over a field label. It is meant to describe to the user what to use the field for. - -=cut - -sub file { - my ($output); - my ($self, @p) = @_; - my ($name, $label, $subtext, $extras, $size, $uiLevel,$hoverHelp) = - rearrange([qw(name label subtext extras size uiLevel hoverHelp)], @p); - if (_uiLevelChecksOut($uiLevel)) { - $output = WebGUI::Form::file({ - "name"=>$name, - "size"=>$size, - "extras"=>$extras - }); - $output .= _subtext($subtext); - $output = $self->_tableFormRow($label,$output,$hoverHelp); - } - $self->{_data} .= $output; -} - - #------------------------------------------------------------------- =head2 new ( [ noTable, action, method, extras, enctype, tableExtras ] ) diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index 052cfa933..c0b66fea7 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -3332,6 +3332,12 @@ Privileges and styles assigned to pages in the package will not be copied when t context => q|Field type name| }, + 'file' => { + message => q|File|, + lastUpdated =>0, + context => q|Field type name| + }, + 'codearea' => { message => q|Code Area|, lastUpdated =>0,