added file pile
This commit is contained in:
parent
2e9602e248
commit
27356b09f6
4 changed files with 249 additions and 8 deletions
|
|
@ -48,6 +48,8 @@
|
|||
- bugfix [1073753]. bug in WebGUI::Search (Leendert Bottelberghs).
|
||||
- Added an e-commerce system. Thanks to Atomic Learning for funding this
|
||||
feature.
|
||||
- Added new asset type: File Pile. This allows you to do a mass upload of
|
||||
files and images.
|
||||
|
||||
6.2.9
|
||||
- bugfix [ 1058105 ] input tag has to be closed with /
|
||||
|
|
|
|||
|
|
@ -620,8 +620,8 @@ sub processPropertiesFromFormPost {
|
|||
foreach my $property (keys %{$definition->{properties}}) {
|
||||
$data{$property} = WebGUI::FormProcessor::process(
|
||||
$property,
|
||||
$definition->{properties}{fieldType},
|
||||
$definition->{properties}{defaultValue}
|
||||
$definition->{properties}{$property}{fieldType},
|
||||
$definition->{properties}{$property}{defaultValue}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
241
lib/WebGUI/Asset/FilePile.pm
Normal file
241
lib/WebGUI/Asset/FilePile.pm
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
package WebGUI::Asset::FilePile;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2004 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::HTTP;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Storage;
|
||||
use WebGUI::Template;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset);
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Asset::File
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Provides a mechanism to upload files to WebGUI.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Asset::File;
|
||||
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
sub edit {
|
||||
my $self = shift;
|
||||
my $tabform = WebGUI::TabForm->new();
|
||||
$tabform->hidden({
|
||||
name=>"func",
|
||||
value=>"add"
|
||||
});
|
||||
$tabform->hidden({
|
||||
name=>"doit",
|
||||
value=>"1"
|
||||
});
|
||||
$tabform->hidden({
|
||||
name=>"class",
|
||||
value=>"WebGUI::Asset::FilePile"
|
||||
});
|
||||
if ($session{form}{afterEdit}) {
|
||||
$tabform->hidden({
|
||||
name=>"afterEdit",
|
||||
value=>$session{form}{afterEdit}
|
||||
});
|
||||
}
|
||||
$tabform->addTab("properties",WebGUI::International::get("properties","Asset"));
|
||||
$tabform->getTab("properties")->yesNo(
|
||||
-name=>"hideFromNavigation",
|
||||
-value=>1,
|
||||
-label=>WebGUI::International::get(886),
|
||||
-uiLevel=>6
|
||||
);
|
||||
$tabform->getTab("properties")->yesNo(
|
||||
-name=>"newWindow",
|
||||
-value=>0,
|
||||
-label=>WebGUI::International::get(940),
|
||||
-uiLevel=>6
|
||||
);
|
||||
$tabform->addTab("privileges",WebGUI::International::get(107),6);
|
||||
$tabform->getTab("privileges")->dateTime(
|
||||
-name=>"startDate",
|
||||
-label=>WebGUI::International::get(497),
|
||||
-value=>$self->get("startDate"),
|
||||
-uiLevel=>6
|
||||
);
|
||||
$tabform->getTab("privileges")->dateTime(
|
||||
-name=>"endDate",
|
||||
-label=>WebGUI::International::get(498),
|
||||
-value=>$self->get("endDate"),
|
||||
-uiLevel=>6
|
||||
);
|
||||
my $subtext;
|
||||
if (WebGUI::Grouping::isInGroup(3)) {
|
||||
$subtext = manageIcon('op=listUsers');
|
||||
} else {
|
||||
$subtext = "";
|
||||
}
|
||||
my $clause;
|
||||
if (WebGUI::Grouping::isInGroup(3)) {
|
||||
my $contentManagers = WebGUI::Grouping::getUsersInGroup(4,1);
|
||||
push (@$contentManagers, $session{user}{userId});
|
||||
$clause = "userId in (".quoteAndJoin($contentManagers).")";
|
||||
} else {
|
||||
$clause = "userId=".quote($self->get("ownerUserId"));
|
||||
}
|
||||
my $users = WebGUI::SQL->buildHashRef("select userId,username from users where $clause order by username");
|
||||
$tabform->getTab("privileges")->selectList(
|
||||
-name=>"ownerUserId",
|
||||
-options=>$users,
|
||||
-label=>WebGUI::International::get(108),
|
||||
-value=>[$self->get("ownerUserId")],
|
||||
-subtext=>$subtext,
|
||||
-uiLevel=>6
|
||||
);
|
||||
$tabform->getTab("privileges")->group(
|
||||
-name=>"groupIdView",
|
||||
-label=>WebGUI::International::get(872),
|
||||
-value=>[$self->get("groupIdView")],
|
||||
-uiLevel=>6
|
||||
);
|
||||
$tabform->getTab("privileges")->group(
|
||||
-name=>"groupIdEdit",
|
||||
-label=>WebGUI::International::get(871),
|
||||
-value=>[$self->get("groupIdEdit")],
|
||||
-excludeGroups=>[1,7],
|
||||
-uiLevel=>6
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>"file",
|
||||
-label=>"Upload File"
|
||||
);
|
||||
return $self->getAdminConsole->render($tabform->print);
|
||||
}
|
||||
|
||||
sub editSave {
|
||||
my $self = shift;
|
||||
my $parent = WebGUI::Asset->newByUrl;
|
||||
my $tempStorage = WebGUI::Storage->create;
|
||||
$tempStorage->addFileFromFormPost("file");
|
||||
foreach my $filename (@{$tempStorage->getFiles}) {
|
||||
my $storage = WebGUI::Storage->create;
|
||||
$storage->addFileFromFilesystem($tempStorage->getPath($filename));
|
||||
my %data;
|
||||
my $newAsset = $parent->addChild({className=>'WebGUI::Asset::File'});
|
||||
foreach my $definition (@{$self->definition}) {
|
||||
foreach my $property (keys %{$definition->{properties}}) {
|
||||
$data{$property} = WebGUI::FormProcessor::process(
|
||||
$property,
|
||||
$definition->{properties}{$property}{fieldType},
|
||||
$definition->{properties}{$property}{defaultValue}
|
||||
);
|
||||
}
|
||||
}
|
||||
$data{filename} = $filename;
|
||||
$data{storageId} = $storage->getId;
|
||||
$data{title} = $data{menuTitle} = $filename;
|
||||
$data{url} = $parent->getUrl.'/'.$filename;
|
||||
$newAsset->update(\%data);
|
||||
$newAsset->setSize($storage->getFileSize($filename));
|
||||
}
|
||||
$tempStorage->delete;
|
||||
return $parent->www_manageAssets if ($session{form}{afterEdit} eq "assetManager");
|
||||
return $parent->www_view;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getIcon {
|
||||
my $self = shift;
|
||||
my $small = shift;
|
||||
if ($small) {
|
||||
return $session{config}{extrasURL}.'/assets/small/folder.gif';
|
||||
}
|
||||
return $session{config}{extrasURL}.'/assets/folder.gif';
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName
|
||||
|
||||
Returns the displayable name of this asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
return "File Pile";
|
||||
}
|
||||
|
||||
sub www_edit {
|
||||
my $self = shift;
|
||||
unless ($session{form}{doit}) {
|
||||
return $self->edit;
|
||||
} else {
|
||||
return $self->editSave;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ Grabs an attachment from a form POST and saves it to this storage location.
|
|||
|
||||
=head3 formVariableName
|
||||
|
||||
Provide the form variable name to which the file being uploaded is assigned.
|
||||
Provide the form variable name to which the file being uploaded is assigned. Note that if multiple files are uploaded with the same formVariableName then they'll all be stored in the storage location, but only the last filename will be returned. Use the getFiles() method on the storage location to get all the filenames stored.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -166,9 +166,8 @@ sub addFileFromFormPost {
|
|||
my $self = shift;
|
||||
my $formVariableName = shift;
|
||||
return "" if (WebGUI::HTTP::getStatus() =~ /^413/);
|
||||
my $tempPath = $session{cgi}->upload($formVariableName);
|
||||
if (defined $tempPath) {
|
||||
my $filename;
|
||||
my $filename;
|
||||
foreach my $tempPath ($session{cgi}->upload($formVariableName)) {
|
||||
if ($tempPath =~ /([^\/\\]+)$/) {
|
||||
$filename = $1;
|
||||
} else {
|
||||
|
|
@ -193,9 +192,8 @@ sub addFileFromFormPost {
|
|||
$self->_addError("Couldn't open file ".$self->getPath($filename)." for writing due to error: ".$!);
|
||||
return undef;
|
||||
}
|
||||
return $filename;
|
||||
}
|
||||
return undef;
|
||||
return $filename;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue