updates to the file pile

This commit is contained in:
JT Smith 2004-12-29 19:36:51 +00:00
parent 990cd43035
commit 330d3afb23
6 changed files with 257 additions and 44 deletions

View file

@ -144,7 +144,7 @@ my %migration;
print "\tConverting navigation system to asset tree\n" unless ($quiet);
my ($navRootLineage) = WebGUI::SQL->quickArray("select assetId,title,lineage from asset where length(lineage)=12 order by lineage desc limit 1");
$navRootLineage = sprintf("%012d",("000001000005"+1));
$navRootLineage = sprintf("%012d",($navRootLineage+1));
my $navRootId = WebGUI::SQL->setRow("asset","assetId",{
assetId=>"new",
isHidden=>1,
@ -265,6 +265,113 @@ $sth->finish;
WebGUI::SQL->write("update Navigation set startPoint='root' where startPoint='nameless_root'");
WebGUI::SQL->write("drop table tempoldnav");
print "\tConverting collateral manager items into assets\n" unless ($quiet);
my ($collateralRootLineage) = WebGUI::SQL->quickArray("select assetId,title,lineage from asset where length(lineage)=12 order by lineage desc limit 1");
$collateralRootLineage = sprintf("%012d",($collateralRootLineage+1));
my $collateralRootId = WebGUI::SQL->setRow("asset","assetId",{
assetId=>"new",
isHidden=>1,
title=>"Navigation Configurations",
menuTitle=>"Navigation Configurations",
url=>fixUrl('doesntexistyet',"Navigation Configurations"),
ownerUserId=>"3",
groupIdView=>"4",
groupIdEdit=>"4",
parentId=>"PBasset000000000000001",
lineage=>$collateralRootLineage,
lastUpdated=>time(),
className=>"WebGUI::Asset::Wobject::Navigation",
state=>"published"
});
WebGUI::SQL->setRow("wobject","assetId",{
assetId=>$collateralRootId,
templateId=>"1",
styleTemplateId=>"1",
printableStyleTemplateId=>"3"
},undef,$collateralRootId);
WebGUI::SQL->setRow("Navigation","assetId",{
assetId=>$collateralRootId,
startType=>"relativeToCurrentUrl",
startPoint=>"0",
endPoint=>"55",
assetsToInclude=>"descendants",
showHiddenPages=>1
},undef,$collateralRootId);
my %folderCache = ('0'=>$collateralRootId);
my $collateralRankCounter = 1;
my $sth = WebGUI::SQL->read("select * from collateralFolder");
while (my $data = $sth->hashRef) {
my $folderId = WebGUI::SQL->setRow("asset","assetId",{
assetId=>"new",
className=>'WebGUI::Asset::Layout',
lineage=>$collateralRootLineage.sprintf("%06d",$collateralRankCounter),
parentId=>$collateralRootId,
ownerUserId=>'3',
groupIdView=>'4',
groupIdEdit=>'4',
lastUpdate=>time(),
title=>quote($data->{name}),
menuTitle=>quote($data->{name}),
url=>quote(fixUrl('doesntexist',$data->{name})),
state=>'published'
});
WebGUI::SQL->setRow("wobject","assetId",{
assetId=>quote($folderId),
templateId=>'15',
styleTemplateId=>"1",
printableStyleTemplateId=>"3",
namespace=>'Layout',
description=>quote($data->{description})
},undef,$folderId);
WebGUI::SQL->setRow("layout","assetId",{
assetId=>quote($folderId)
},undef,$folderId);
$folderCache{$data->{collateralFolderId}} = $folderId;
$collateralRankCounter++;
}
$sth->finish;
my %collateralCache;
my $lastCollateralFolderId = 'nolastid';
my ($parentId, $baseLineage, $rank);
my $sth = WebGUI::SQL->read("select * from collateral order by collateralFolderId");
while (my $data = $sth->hashRef) {
unless ($lastCollateralFolderId eq $data->{collateralFolderId}) {
$rank = 1;
$baseLineage = "";
$parentId = "";
}
my $class;
my $collateralId = WebGUI::Id::generate();
if ($data->{filename} ne "") {
my $storageId = copyFile($data->{filename},'images/'.$data->{collateralId});
if (isIn(getFileExtension($data->{filename}), qw(jpg jpeg gif png))) {
copyFile('thumb-'.$data->{filename},'images/'.$data->{collateralId},$storageId);
WebGUI::SQL->write("insert into ImageAsset (assetId, thumbnailSize) values (".quote($newId).",
".quote($session{setting}{thumbnailSize}).")");
$class = 'WebGUI::Asset::File::Image';
} else {
$class = 'WebGUI::Asset::File';
}
WebGUI::SQL->write("insert into FileAsset (assetId, filename, storageId, fileSize) values (
".quote($newId).", ".quote($data->{$field}).", ".quote($storageId).",
".quote(getFileSize($storageId,$data->{$field})).")");
} else {
}
WebGUI::SQL->write("insert into asset (assetId, parentId, lineage, className, state, title, menuTitle,
url, startDate, endDate, isHidden, ownerUserId, groupIdView, groupIdEdit, synopsis) values (".
quote($collateralId).", ".quote($parentId).", ".quote($baseLineage.sprintf("%06d",$rank)).",
'".$class."','published',".quote($data->{fileTitle}).", ".
quote($data->{fileTitle}).", ".quote(fixUrl($newId,$wobjectUrl.'/'.$data->{$field})).",
".quote($wobject->{startDate}).", ".quote($wobject->{endDate}).", 1, ".quote($ownerId).",
".quote($data->{groupToView}).", ".quote($groupIdEdit).", ".quote($data->{briefSynopsis}).")");
$collateralCache{$data->{collateralId}) = $collateralId;
$rank++;
}
WebGUI::SQL->write("drop table collateralFolder");
WebGUI::SQL->write("drop table collateral");
print "\tConverting navigation templates\n" unless ($quiet);
my $sth = WebGUI::SQL->read("select templateId, template from template where namespace='Navigation'");

View file

@ -198,7 +198,7 @@ sub view {
my $self = shift;
my $storage = WebGUI::Storage->get($self->get("storageId"));
my %var = %{$self->get};
$var{controls} = $toolbar;
$var{controls} = $self->getToolbar;
$var{fileUrl} = $storage->getUrl($self->get("filename"));
$var{fileIcon} = $storage->getFileIconUrl($self->get("filename"));
$var{thumbnail} = $storage->getUrl("thumb-".$self->get("filename"));

View file

@ -21,6 +21,7 @@ use WebGUI::Icon;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Storage;
use WebGUI::TabForm;
use WebGUI::Template;
use WebGUI::Utility;
@ -80,7 +81,7 @@ sub edit {
-label=>WebGUI::International::get(940),
-uiLevel=>6
);
$tabform->addTab("privileges",WebGUI::International::get(107),6);
$tabform->addTab("security",WebGUI::International::get(107),6);
$tabform->getTab("security")->dateTime(
-name=>"startDate",
-label=>WebGUI::International::get(497),
@ -129,45 +130,27 @@ sub edit {
-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"
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);
uploader.addRow();
</script>';
$tabform->getTab("properties")->readOnly(
-label=>"Upload Files",
-value=>$uploadControl
);
return $self->getAdminConsole->render($tabform->print,"Add a Pile of Files");
}

View file

@ -104,8 +104,8 @@ foreach my $link (@{$session{asset}->getAssetAdderLinks}) {
# $hash{$acParams->{url}} = $acParams->{title} if ($acParams->{canUse});
# $acParams = WebGUI::AdminConsole->getAdminFunction("groups");
# $hash{$acParams->{url}} = $acParams->{title} if ($acParams->{canUse});
# $acParams = WebGUI::AdminConsole->getAdminFunction("assets");
# $hash{$acParams->{url}} = $acParams->{title} if ($acParams->{canView});
$acParams = WebGUI::AdminConsole->getAdminFunction("assets");
$hash{$acParams->{url}} = $acParams->{title} if ($acParams->{canUse});
%hash = sortHash(%hash);
%hash = (

123
www/extras/FileUploadControl.js Executable file
View file

@ -0,0 +1,123 @@
//constructor for a new file upload control object. The object generates file upload boxes based on user
//input. Each file upload input is named "file" the control must be rendered in a form. The
//Worspace id is the id of the div in the html page to rener the control in.
function FileUploadControl(workspaceId, imageArray) {
this.images = images;
this.dom=document.getElementById&&!document.all;
this.topLevelElement=this.dom? "HTML" : "BODY"
var workspace = document.getElementById(workspaceId);
var str = '<table border="0"><tbody id="' + workspaceId + '.fileUpload.body">';
str += '</tbody></table><table>';
str +='<table style="display: none;">'
str += '<tr id="' + workspaceId + '.template" class="fileUploadRow"><td><img src="' + images["unknown"] + '" style="visibility: hidden"></td>';
str +='<td><input type="file" name="files" size="40" onchange="FileUploadControl_valueChange(event)"></td><td><input type="button" value="Remove" onclick="FileUploadControl_removeButtonClick(event)"></td></tr>';
str += '</table>';
workspace.innerHTML = str;
this.tbody = document.getElementById(workspaceId + '.fileUpload.body');
this.tbody.fileUploadControl = this;
this.rowTemplate = document.getElementById(workspaceId + ".template");
this.removeRow = FileUploadControl_removeRow;
this.addRow = FileUploadControl_addRow;
this.swapImage = FileUploadControl_swapImage;
this.getRow = FileUploadControl_getRow;
}
//Searches up the object tree to find the control that owns this object
function FileUploadControl_getControl(firedobj){
var dom=document.getElementById&&!document.all;
var topLevelElement=dom? "HTML" : "BODY"
//traverse up the dom tree until you find the asset
while (firedobj.tagName!=topLevelElement && !firedobj.fileUploadControl) {
firedobj=dom? firedobj.parentNode : firedobj.parentElement
}
if (firedobj.fileUploadControl) {
return firedobj.fileUploadControl;
}else {
return null;
}
}
//traverses up the object tree to find the row associated with firedobj
function FileUploadControl_getRow(firedobj) {
while (firedobj.tagName!=this.topLevelElement && firedobj.className!="fileUploadRow") {
firedobj=this.dom? firedobj.parentNode : firedobj.parentElement
}
return firedobj;
}
//uses the image array passed into the constructor to set the src on the image for the row.
function FileUploadControl_swapImage(firedobj) {
var parts = firedobj.value.split('.');
var imgPath = this.images["unknown"];
if (parts.length !=1) {
var extension = parts[parts.length -1];
if (this.images[extension]) {
imgPath = this.images[extension];
}
}
var row = this.getRow(firedobj);
var img = row.childNodes[0].childNodes[0];
img.src = imgPath;
img.style.visibility="visible";
}
//removes a row from the control
function FileUploadControl_removeRow(firedobj) {
if (this.tbody.childNodes[this.tbody.childNodes.length -1] == this.getRow(firedobj)) {
window.status="cant remove last; return true";
return;
}
var row = this.getRow(firedobj);
this.tbody.removeChild(row);
}
//adds a row to the control
function FileUploadControl_addRow() {
var row = this.rowTemplate.cloneNode(true);
row.id = new Date().getTime();
this.tbody.appendChild(row);
}
//event handlers
//called on click of the remove button
function FileUploadControl_removeButtonClick(e) {
var dom = document.getElementById&&!document.all;
e=dom? e : event;
var firedobj =dom? e.target : e.srcElement
var control = FileUploadControl_getControl(firedobj);
control.removeRow(firedobj);
}
//called on change of the upload inputs
function FileUploadControl_valueChange(e) {
var dom = document.getElementById&&!document.all;
e=dom? e : event;
var firedobj =dom? e.target : e.srcElement
var control = FileUploadControl_getControl(firedobj);
if (control.tbody.childNodes[control.tbody.childNodes.length -1].childNodes[1].childNodes[0].value != "") {
control.addRow();
}
control.swapImage(firedobj);
}

BIN
www/extras/fileIcons/js.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 977 B