starting adding file asset
This commit is contained in:
parent
29611731c4
commit
5421f8e9d7
6 changed files with 299 additions and 49 deletions
163
lib/WebGUI/Asset/File.pm
Normal file
163
lib/WebGUI/Asset/File.pm
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
package WebGUI::Asset::File;
|
||||
|
||||
=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::Session;
|
||||
use WebGUI::Storage;
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( definition )
|
||||
|
||||
Defines the properties of this asset.
|
||||
|
||||
=head3 definition
|
||||
|
||||
A hash reference passed in from a subclass definition.
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
push(@{$definition}, {
|
||||
tableName=>'FileAsset',
|
||||
className=>'WebGUI::Asset::File',
|
||||
properties=>{
|
||||
filename=>{
|
||||
fieldType=>'hidden',
|
||||
defaultValue=>undef
|
||||
},
|
||||
storageId=>{
|
||||
fieldType=>'hidden',
|
||||
defaultValue=>undef
|
||||
},
|
||||
fileSize=>{
|
||||
fieldType=>'hidden',
|
||||
defaultValue=>undef
|
||||
}
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getEditForm ()
|
||||
|
||||
Returns the TabForm object that will be used in generating the edit page for this asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm();
|
||||
if ($self->get("filename") ne "") {
|
||||
my $storage = WebGUI::Storage->new($self->get("storageId"));
|
||||
|
||||
}
|
||||
$tabform->getTab("properties")->url(
|
||||
-name=>"file",
|
||||
-label=>"File To Upload"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName
|
||||
|
||||
Returns the displayable name of this asset.
|
||||
|
||||
=cut
|
||||
|
||||
sub getName {
|
||||
return "File";
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_editSave
|
||||
|
||||
Gathers data from www_edit and persists it.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editSave {
|
||||
my $self = shift;
|
||||
$self->SUPER::www_editSave();
|
||||
my $storage = WebGUI::Storage->create;
|
||||
my $filename = $storage->addFileFromFormPost("file");
|
||||
if (defined $filename) {
|
||||
$self->update({
|
||||
filename=>$filename,
|
||||
storageId=>$storage->getId,
|
||||
fileSize=>$storage->getFileSize
|
||||
});
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_view
|
||||
|
||||
A web executable method that redirects the user to the specified page, or displays the edit interface when admin mode is enabled.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
if ($session{var}{adminOn}) {
|
||||
return $self->www_edit;
|
||||
}
|
||||
my $storage = WebGUI::Storage->new($self->get("storageId"));
|
||||
WebGUI::HTTP::setRedirect($storage->getUrl($self->get("filename")));
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ sub getUiLevel {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 name
|
||||
=head2 getName
|
||||
|
||||
Returns the displayable name of this asset.
|
||||
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ sub www_createShortcut {
|
|||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless ($self->canEdit);
|
||||
my $w = WebGUI::Wobject::WobjectProxy->new({wobjectId=>"new",namespace=>"WobjectProxy"});
|
||||
$w->set({
|
||||
$w->update({
|
||||
pageId=>'2',
|
||||
templatePosition=>1,
|
||||
title=>$self->getValue("title"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue