From 330d3afb2353851b1393efda40a50bb9238e2f8f Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 29 Dec 2004 19:36:51 +0000 Subject: [PATCH] updates to the file pile --- docs/upgrades/upgrade_6.2.9-6.3.0.pl | 109 +++++++++++++++++++++++- lib/WebGUI/Asset/File/Image.pm | 2 +- lib/WebGUI/Asset/FilePile.pm | 63 +++++--------- lib/WebGUI/Macro/AdminBar.pm | 4 +- www/extras/FileUploadControl.js | 123 +++++++++++++++++++++++++++ www/extras/fileIcons/js.gif | Bin 0 -> 977 bytes 6 files changed, 257 insertions(+), 44 deletions(-) create mode 100755 www/extras/FileUploadControl.js create mode 100644 www/extras/fileIcons/js.gif diff --git a/docs/upgrades/upgrade_6.2.9-6.3.0.pl b/docs/upgrades/upgrade_6.2.9-6.3.0.pl index 267ac7e82..74f148a56 100644 --- a/docs/upgrades/upgrade_6.2.9-6.3.0.pl +++ b/docs/upgrades/upgrade_6.2.9-6.3.0.pl @@ -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'"); diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index f560d9dd9..1bc6eb9d5 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -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")); diff --git a/lib/WebGUI/Asset/FilePile.pm b/lib/WebGUI/Asset/FilePile.pm index 5a0f72ae1..5cad921af 100644 --- a/lib/WebGUI/Asset/FilePile.pm +++ b/lib/WebGUI/Asset/FilePile.pm @@ -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 = '
+ '; + $tabform->getTab("properties")->readOnly( + -label=>"Upload Files", + -value=>$uploadControl ); return $self->getAdminConsole->render($tabform->print,"Add a Pile of Files"); } diff --git a/lib/WebGUI/Macro/AdminBar.pm b/lib/WebGUI/Macro/AdminBar.pm index c9acd0ce0..99ca2c751 100644 --- a/lib/WebGUI/Macro/AdminBar.pm +++ b/lib/WebGUI/Macro/AdminBar.pm @@ -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 = ( diff --git a/www/extras/FileUploadControl.js b/www/extras/FileUploadControl.js new file mode 100755 index 000000000..8759c06f2 --- /dev/null +++ b/www/extras/FileUploadControl.js @@ -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 = ''; + str += '
'; + + str +='
' + + str += ''; + str +=''; + + str += '
'; + + 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); +} \ No newline at end of file diff --git a/www/extras/fileIcons/js.gif b/www/extras/fileIcons/js.gif new file mode 100644 index 0000000000000000000000000000000000000000..7b544200044aabf75dbf23d56b585d80f1dc10ed GIT binary patch literal 977 zcmeH`KWh|00LACd1ea*y2}w-kL}v?e;6j|MG6VvdfPc2ISOg)6oNkcd*_{SqE$)sD zr!ZKJV6jCsY!g{cGv&rhgGFli`H4;z_`e0<-;q-B z0#G})<4*wV6DV2LTa|VNE{{#0wbvT7yKKv?{qAPJ2kbw;;5O||RBKCXR{z`U(uh4d z93Fh=L+~ivZ4VE+*2L-_o89h!&YAl9%