sub bug fixes, and the new file form control

This commit is contained in:
JT Smith 2005-07-28 19:26:07 +00:00
parent e184f2c185
commit 3733b39fa5
8 changed files with 74 additions and 158 deletions

View file

@ -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'),
);

View file

@ -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 '<input type="file" name="'.$params->{name}.'" size="'.$size.'" '.$params->{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 = '<div id="fileUploadControl"> </div>
<script>
var images = new Array();
';
opendir(DIR,$session{config}{extrasPath}.'/fileIcons');
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
unless ($file eq "." || $file eq "..") {
my $ext = $file;
$ext =~ s/(.*?)\.gif/$1/;
$uploadControl .= 'images["'.$ext.'"] = "'.$session{config}{extrasURL}.'/fileIcons/'.$file.'";'."\n";
}
}
$uploadControl .= 'var uploader = new FileUploadControl("fileUploadControl", images, "'.WebGUI::International::get('removeLabel','WebGUI').'");
uploader.addRow();
</script>';
return $uploadControl;
}
#-------------------------------------------------------------------

View file

@ -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};
}

View file

@ -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});
}

View file

@ -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);

View file

@ -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 '<input type="text" name="'.$self->{name}.'" value="'.$value.'" size="'.$self->{size}.'" maxlength="'.$self->{maxlength}.'" '.$self->{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 = '<div id="fileUploadControl"> </div>
<script>
var images = new Array();
my $uploadControl = '<script type="text/javascript">
var fileIcons = new Array();
';
opendir(DIR,$session{config}{extrasPath}.'/fileIcons');
my @files = readdir(DIR);
@ -129,11 +133,24 @@ sub files {
$uploadControl .= 'images["'.$ext.'"] = "'.$session{config}{extrasURL}.'/fileIcons/'.$file.'";'."\n";
}
}
$uploadControl .= 'var uploader = new FileUploadControl("fileUploadControl", images, "'.WebGUI::International::get('removeLabel','WebGUI').'");
$uploadControl .= 'var uploader = new FileUploadControl("'.$self->{name}.'", fileIcons, "'.WebGUI::International::get('removeLabel','WebGUI').'","'.$self->{maxAttachments}.'");
uploader.addRow();
</script>';
return $uploadControl;
}
#-------------------------------------------------------------------
=head4 toHtmlAsHidden ( )
Returns undef.
=cut
sub toHtmlAsHidden {
return undef;
}
1;

View file

@ -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 ] )

View file

@ -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,