added image picker for rich edit

This commit is contained in:
JT Smith 2005-01-30 16:28:27 +00:00
parent 4704e4c55f
commit 7d6b93ff62
6 changed files with 143 additions and 298 deletions

View file

@ -1176,12 +1176,16 @@ sub getLineage {
$where .= " and ".join(" or ",@whereModifiers) if (scalar(@whereModifiers));
# based upon all available criteria, let's get some assets
my $columns = "assetId, className, parentId";
$columns = "*" if ($rules->{returnQuickReadObjects});
my $slavedb;
if ($rules->{returnQuickReadObjects}) {
$columns = "*";
$slavedb = WebGUI::SQL->getSlave;
}
my $sortOrder = ($rules->{invertTree}) ? "desc" : "asc";
my $sql = "select $columns from asset where $where order by lineage $sortOrder";
my @lineage;
my %relativeCache;
my $sth = WebGUI::SQL->read($sql);
my $sth = WebGUI::SQL->read($sql, $slavedb);
while (my $properties = $sth->hashRef) {
# create whatever type of object was requested
my $asset;
@ -1439,7 +1443,12 @@ Name value pairs to add to the URL in the form of:
sub getUrl {
my $self = shift;
my $params = shift;
return WebGUI::URL::gateway($self->get("url"),$params);
my $url = WebGUI::URL::gateway($self->get("url"),$params);
if ($self->get("encryptPage")) {
$url = WebGUI::URL::getSiteURL().$url;
$url =~ s/http:/https:/;
}
return $url;
}
#-------------------------------------------------------------------

View file

@ -46,6 +46,7 @@ These methods are available from this class:
=cut
#-------------------------------------------------------------------
sub edit {
my $self = shift;
my $tabform = WebGUI::TabForm->new();
@ -129,33 +130,16 @@ sub edit {
-excludeGroups=>[1,7],
-uiLevel=>6
);
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
-value=>$self->getUploadControl
);
return $self->getAdminConsole->render($tabform->print,"Add a Pile of Files");
}
#-------------------------------------------------------------------
sub editSave {
my $self = shift;
my $class = shift;
my $parent = WebGUI::Asset->newByUrl;
my $tempStorage = WebGUI::Storage->create;
$tempStorage->addFileFromFormPost("file");
@ -165,7 +149,7 @@ sub editSave {
my %data;
my $class = 'WebGUI::Asset::File';
$class = "WebGUI::Asset::File::Image" if (isIn($storage->getFileExtension($filename),qw(jpg jpeg gif png)));
foreach my $definition (@{$self->definition}) {
foreach my $definition (@{$class->definition}) {
foreach my $property (keys %{$definition->{properties}}) {
$data{$property} = WebGUI::FormProcessor::process(
$property,
@ -210,6 +194,32 @@ sub getName {
return "File Pile";
}
#-------------------------------------------------------------------
sub getUploadControl {
my $self = shift;
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>';
return $uploadControl;
}
#-------------------------------------------------------------------
sub www_edit {
my $self = shift;
unless ($session{form}{doit}) {

View file

@ -722,6 +722,41 @@ sub file {
}
#-------------------------------------------------------------------
=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);
uploader.addRow();
</script>';
return $uploadControl;
}
#-------------------------------------------------------------------
=head2 filterContent ( hashRef )

View file

@ -96,7 +96,8 @@ sub getOperations {
'editDatabaseLinkSave' => 'WebGUI::Operation::DatabaseLink',
'listDatabaseLinks' => 'WebGUI::Operation::DatabaseLink',
'richEditPageTree' => 'WebGUI::Operation::RichEdit',
'richEditImage' => 'WebGUI::Operation::RichEdit',
'richEditImageTree' => 'WebGUI::Operation::RichEdit',
'richEditViewThumbnail' => 'WebGUI::Operation::RichEdit',
'manageUsersInGroup' => 'WebGUI::Operation::Group',
'deleteGroup' => 'WebGUI::Operation::Group',
'deleteGroupConfirm' => 'WebGUI::Operation::Group',

View file

@ -59,6 +59,7 @@ window.opener.tinyMCE.insertLink("^" + "/" + ";" + document.getElementById("url"
$output .= '<p>'.join(" &gt; ", @crumb)."</p>\n";
my $children = $base->getLineage(["children"],{returnQuickReadObjects=>1});
foreach my $child (@{$children}) {
next unless $child->canView;
$output .= '<a href="#" onclick="document.getElementById(\'url\').value=\''.$child->get("url").'\'">(&bull;)</a> <a href="'.$child->getUrl("op=richEditPageTree").'">'.$child->get("menuTitle").'</a>'."<br />\n";
}
$session{page}{useEmptyStyle} = 1;
@ -66,178 +67,52 @@ window.opener.tinyMCE.insertLink("^" + "/" + ";" + document.getElementById("url"
}
#-------------------------------------------------------------------
sub _htmlAreaCreateTree {
my ($output);
my ($name, $description, $url, $image, $indent, $target, $delete) = @_;
if($delete) {
$delete = qq/<a href="javascript:deleteCollateral('$delete')" title="delete $name">/;
$delete .= deleteIcon()."</a>";
sub www_richEditImageTree {
my $base = WebGUI::Asset->newByUrl || WebGUI::Asset->getRoot;
my @crumb;
my $ancestors = $base->getLineage(["self","ancestors"],{returnQuickReadObjects=>1});
foreach my $ancestor (@{$ancestors}) {
push(@crumb,'<a href="'.$ancestor->getUrl("op=richEditImageTree").'">'.$ancestor->get("menuTitle").'</a>');
}
my $output = '<p>'.join(" &gt; ", @crumb)."</p>\n";
my $children = $base->getLineage(["children"],{returnQuickReadObjects=>1});
foreach my $child (@{$children}) {
next unless $child->canView;
if ($child->get("className") =~ /^WebGUI::Asset::File::Image/) {
$output .= '<a href="'.$child->getUrl("op=richEditViewThumbnail").'" target="viewer">(&bull;)</a> ';
} else {
$output .= "(&bull;) ";
}
$output .= '<a href="'.$child->getUrl("op=richEditImageTree").'">'.$child->get("menuTitle").'</a>'."<br />\n";
}
$target = ' target="'.$target.'" ' if ($target);
$output .= '<tr><td align="left" valign="bottom" width="100%">';
$output .= ('<img src="'.$session{config}{extrasURL}.'/tinymce/images/indent.gif" width="17" heigth="17">') x$indent;
$output .= '<img src="'.$session{config}{extrasURL}.'/tinymce/images/'.$image.'" align="bottom" alt="'.$name.'">';
$output .= '<a title="'.$description.'" href="'.$url.'" '.$target.'><b>'.$name.'</b></a></td>';
$output .= '<td class="delete" align="right" valign="bottom">'.$delete.'</td></tr>';
$session{page}{useEmptyStyle} = 1;
return $output;
}
#-------------------------------------------------------------------
sub www_htmlArealistCollateral {
my (@parents, $sth, $data, $indent);
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
return "<b>Only Content Managers are allowed to use WebGUI Collateral</b>" unless (WebGUI::Grouping::isInGroup(4));
my $output = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
my $folderId = $session{form}{fid} || 0;
my $parent = $folderId;
# push parent folders in array so it can be reversed
unshift(@parents, $parent);
until($parent eq '0') {
($parent) = WebGUI::SQL->quickArray("select parentId from collateralFolder where collateralFolderId=".quote($parent));
unshift(@parents, $parent);
}
# Build tree for opened parent folders
foreach $parent (@parents) {
my ($name, $description) = WebGUI::SQL->quickArray("select name, description from
collateralFolder where collateralFolderId=".quote($parent));
my ($itemsInFolder) = WebGUI::SQL->quickArray("select count(*) from collateral where collateralFolderId = ".quote($parent));
my ($foldersInFolder)=WebGUI::SQL->quickArray("select count(*) from collateralFolder where parentId=".quote($parent));
my $delete = "fid=$parent" unless ($itemsInFolder + $foldersInFolder);
$output .= _htmlAreaCreateTree($name, $description,
WebGUI::URL::page('op=htmlArealistCollateral&fid='.$parent), "opened.gif",
$indent++,"" ,$delete);
}
# Extend tree with closed folders in current folder
$sth = WebGUI::SQL->read("select collateralFolderId, name, description from collateralFolder
where parentId=".quote($folderId)." and collateralFolderId <> '0' order by name");
while ($data = $sth->hashRef) {
my ($itemsInFolder) = WebGUI::SQL->quickArray("select count(*) from collateral where
collateralFolderId = ".quote($data->{collateralFolderId}));
my $delete = 'fid='.$data->{collateralFolderId} unless $itemsInFolder;
$output .= _htmlAreaCreateTree($data->{name}, $data->{description},
WebGUI::URL::page('op=htmlArealistCollateral&fid='.$data->{collateralFolderId}),
"closed.gif", $indent, "", $delete);
}
# Extend tree with images in current folder
$sth = WebGUI::SQL->read("select collateralId, name, filename from collateral where collateralType = 'image' ".
"and collateralFolderId = ".quote($folderId));
while ($data = $sth->hashRef) {
$data->{filename} =~ /\.([^\.]+)$/; # Get extension
my $fileType = $1.'.gif';
$output .= _htmlAreaCreateTree($data->{filename}, $data->{name},
WebGUI::URL::page('op=htmlAreaviewCollateral&cid='.$data->{collateralId}),
$fileType, $indent, "viewer", 'cid='.$data->{collateralId}.'&fid='.$folderId);
}
$output .= '</table>';
$output .= '<script language="javascript">'."\n".'actionComplete("","'.$folderId.'","","");';
$output .= "\n</script>\n";
$sth->finish;
return $output;
}
#-------------------------------------------------------------------
sub www_htmlAreaviewCollateral {
my($output, $collateral, $file, $x, $y, $image, $error);
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
$output .= '<table align="center" border="0" cellspacing="0" cellpadding="2" width="100%" height="100%">';
if($session{form}{cid} eq "" || ! WebGUI::Grouping::isInGroup(4)) {
$output .= '<tr><td align="center" valign="middle" width="100%" height="100%">';
$output .= '<p align="center"><br><img src="'.$session{config}{extrasURL}.'/tinymce/images/icon.gif"
border="0"></p>';
$output .= '<P align=center><STRONG>WebGUI Image Manager<BR>for TinyMCE</STRONG></P>';
$output .= '</td></tr></table>';
} else {
my $c = WebGUI::Collateral->new($session{form}{cid});
$collateral = $c->get;
$file = WebGUI::Attachment->new($collateral->{filename},"images",$collateral->{collateralId});
$output .= '<tr><td class="label" align="center" valign="middle" width="100%">';
$output .= '<b>'.$file->getFilename.'</b><br>';
# if ($hasImageMagick) {
# $image = Image::Magick->new;
# $error = $image->Read($file->getPath);
# ($x, $y) = $image->Get('width','height');
# $output .= $error ? "Error reading image: $error" : "<i>($x &#215; $y)</i>";
# }
$output .= '</td></tr><tr><td align="center" valign="middle" width="100%" height="100%">';
$output .= '<img src="'.$file->getThumbnail.'" border="0">';
$output .= '</td></tr></table>';
$output .= '<script language="javascript">';
$output .= "\nvar src = '".$file->getURL."';\n";
sub www_richEditViewThumbnail {
my $image = WebGUI::Asset->newByUrl;
$session{page}{useEmptyStyle} = 1;
if ($image->get("className") =~ /WebGUI::Asset::File::Image/) {
my $output = '<div align="center">';
$output .= '<img src="'.$image->getThumbnailUrl.'" border="0" alt="Preview">';
$output .= '<br />';
$output .= $image->get("filename");
$output .= '</div>';
$output .= '<script type="text/javascript" language="javascript">';
$output .= "\nvar src = '".$image->getFileUrl."';\n";
$output .= "if(src.length > 0) {
var manager=window.parent;
var manager=window.parent;
if(manager)
manager.document.getElementById('txtFileName').value = src;
}
</script>\n";
}
</script>\n";
return $output;
}
return $output;
}
#-------------------------------------------------------------------
sub www_htmlAreaUpload {
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
return "<b>Only Content Managers are allowed to use WebGUI Collateral</b>" unless (WebGUI::Grouping::isInGroup(4));
return www_htmlArealistCollateral() if ($session{form}{image} eq "");
my($test, $file);
$session{form}{fid} = $session{form}{collateralFolderId} = $session{form}{path};
my $collateral = WebGUI::Collateral->new("new");
$session{form}{thumbnailSize} ||= $session{setting}{thumbnailSize};
$session{form}{cid} = $collateral->get("collateralId");
$collateral->save("image", $session{form}{thumbnailSize});
$session{form}{name} = "untitled" if ($session{form}{name} eq "");
while (($test) = WebGUI::SQL->quickArray("select name from collateral
where name=".quote($session{form}{name})." and collateralId<>".quote($collateral->get("collateralId")))) {
if ($session{form}{name} =~ /(.*)(\d+$)/) {
$session{form}{name} = $1.($2+1);
} elsif ($test ne "") {
$session{form}{name} .= "2";
}
}
$collateral->set($session{form});
$session{form}{collateralType} = "";
return www_htmlArealistCollateral();
}
#-------------------------------------------------------------------
sub www_htmlAreaDelete {
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
return "<b>Only Content Managers are allowed to use WebGUI Collateral</b>" unless (WebGUI::Grouping::isInGroup(4));
if($session{form}{cid}) { # Delete Image
my $collateral = WebGUI::Collateral->new($session{form}{cid});
$collateral->delete;
} elsif($session{form}{fid} and not($session{form}{cid})) {
return WebGUI::Privilege::vitalComponent() unless ($session{form}{fid} > 999);
my ($parent) = WebGUI::SQL->quickArray("select parentId from collateralFolder where collateralFolderId=".quote($session{form}{fid}));
WebGUI::SQL->write("delete from collateralFolder where collateralFolderId=".quote($session{form}{fid}));
$session{form}{fid}=$parent;
}
return www_htmlArealistCollateral();
}
#-------------------------------------------------------------------
sub www_htmlAreaCreateFolder {
$session{page}{makePrintable}=1; $session{page}{printableStyleId}=10;
return "<b>Only Content Managers are allowed to use WebGUI Collateral</b>" unless (WebGUI::Grouping::isInGroup(4));
$session{form}{fid} = WebGUI::Id::generate();
WebGUI::Session::setScratch("collateralFolderId",$session{form}{fid});
WebGUI::SQL->write("insert into collateralFolder (collateralFolderId) values (".quote($session{form}{fid}).")");
my $folderId = $session{scratch}{collateralFolderId} || 0;
$session{form}{name} = $session{form}{folder};
$session{form}{name} = "untitled" if ($session{form}{name} eq "");
while (my ($test) = WebGUI::SQL->quickArray("select name from collateralFolder
where name=".quote($session{form}{name})." and collateralFolderId<>".quote($folderId))) {
if ($session{form}{name} =~ /(.*)(\d+$)/) {
$session{form}{name} = $1.($2+1);
} elsif ($test ne "") {
$session{form}{name} .= "2";
}
}
WebGUI::SQL->write("update collateralFolder set parentId=".quote($session{form}{path}).", name=".quote($session{form}{name})
.", description=".quote($session{form}{description})." where collateralFolderId=".quote($folderId));
$session{form}{fid} = $session{form}{path};
return www_htmlArealistCollateral();
return '<div align="center"><img src="'.$session{config}{extrasURL}.'/tinymce/images/icon.gif" border="0" alt="Image Manager"></div>';
}

View file

@ -31,8 +31,8 @@ function Init() {
if(document.getElementById("dpicheck")) {
dpi = document.getElementById("dpicheck").width;
}
document.getElementById("lister").src = pageURL + '?op=htmlArealistCollateral&DPI=' + dpi;
document.getElementById("viewer").src = pageURL + '?op=htmlAreaviewCollateral&DPI=' + dpi;
document.getElementById("lister").src = pageURL + '?op=richEditImageTree&DPI=' + dpi;
document.getElementById("viewer").src = pageURL + '?op=richEditViewThumbnail&DPI=' + dpi;
var txtFileName = document.getElementById("txtFileName");
@ -119,7 +119,7 @@ function resetForm() {
document.getElementById("thumbnailSize").value = '';
document.getElementById("description").value = '';
document.getElementById("folder").value = '';
document.getElementById("viewer").src=window.opener.getWebguiProperty("pageURL") + "?op=htmlAreaviewCollateral";
document.getElementById("viewer").src=window.opener.getWebguiProperty("pageURL") + "?op=richEditImageTree";
}else {
initialLoad=false;
}
@ -135,7 +135,7 @@ function resetForm() {
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td>
<table name="manager" id="manager" border="0" cellpadding="0" cellspacing="0">
<table name="manager" id="manager" border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" align="center" valign="middle">
<fieldset>
@ -143,93 +143,7 @@ function resetForm() {
<table name="wrapper" id="wrapper" border="1" cellpadding="2" cellspacing="0" width="300">
<tr>
<td>
<iframe width="215" height="150" name="lister" id="lister">lister</iframe>
</td>
<td>
<iframe width="215" height="150" name="viewer" id="viewer">viewer</iframe>
</td>
</tr>
<tr>
<td colspan="3">
<script>
document.write('<form name="actions" id="actions" method="POST" action="'+ window.opener.getWebguiProperty("pageURL") +'" enctype="multipart/form-data" target="lister">');
</script>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<fieldset>
<legend align="left">Upload New Image</legend>
<table border="0" cellpadding="1" cellspacing="0">
<tr>
<td align="left" valign="middle">
<input type="submit" value="Upload" onclick="this.form.op.value='htmlAreaUpload'">&nbsp;
</td>
<td colspan="2">
<input type="file" name="image" id="image" size="54">
</td>
</tr>
<tr>
<td align="left" valign="middle">
Name as:
</td>
<td colspan="2">
<input type="input" name="name" id="name" size="54">
</td>
</tr>
<tr>
<td align="left" valign="middle">
Thumbnail:
</td>
<td align="left" valign="middle">
<input type="input" name="thumbnailSize" id="thumbnailSize" size="10">
<i>
&nbsp;(size in pixels)&nbsp;
</i>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
<!-- END 'UPLOAD' HTML -->
<!-- BEGIN 'CREATE' HTML (delete the '>' at the end of this comment to disable the 'CREATE' feature) -->
<tr>
<td colspan="2">
<fieldset>
<legend align="left">Create New Folder</legend>
<table border="0" cellpadding="1" cellspacing="0">
<tr>
<td align="left" valign="middle">
Name:
</td>
<td colspan="2">
<input type="input" name="folder" id="folder" size="54">
</td>
</tr>
<tr>
<td align="left" valign="middle">
Description:
</td>
<td>
<input type="input" name="description" id="description" size="54">
</td>
<td align="left" valign="top">
&nbsp;<input type="submit" value="Create" onclick="this.form.op.value='htmlAreaCreateFolder'">
</td>
</table>
</fieldset>
</td>
</tr>
<!-- END 'UPLOAD' HTML -->
</table>
<input type="hidden" name="DPI" value="96" id="DPI">
<input type="hidden" name="action" value="" id="action">
<input type="hidden" name="path" value="0" id="path">
<input type="hidden" name="op" value="" id="op">
</form>
<iframe width="435" height="250" name="lister" id="lister">lister</iframe>
</td>
</tr>
</table>
@ -240,24 +154,26 @@ function resetForm() {
<td colspan="3" valign="middle">
<fieldset>
<legend align="left">Selected Image</legend>
<table border="0" cellpadding="1" cellspacing="0">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
<td valign="middle">Image URL:&nbsp;&nbsp;</td>
<td valign="middle">
<input type="text" name="txtFileName" id="txtFileName" onfocus="select()" value="http://" size="54">
<input type="text" name="txtFileName" id="txtFileName" onfocus="select()" value="http://" size="40">
</td>
<td rowspan="3" valign="middle" align="center">
<iframe width="145" height="110" name="viewer" id="viewer">viewer</iframe>
</td>
</tr>
<tr>
<td valign="middle">Alt Text:</td>
<td valign="middle">
<input type="text" name="txtAltText" id="txtAltText" onfocus="select()" size="54">
<input type="text" name="txtAltText" id="txtAltText" onfocus="select()" size="40">
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr>
<tr>
<td colspan="2">
<table cellpadding="0" border="0" cellspacing="0">
<tr>
<td >
<fieldset name="fldLayout" id="fldLayout">
<legend align="left">Layout</legend>
@ -285,7 +201,7 @@ function resetForm() {
<input type="text" name="txtBorder" id="txtBorder" size="5" maxlength="3" onfocus="select()">
</td>
</tr>
</table
</table>
</fieldset>
</td>
<td >
@ -304,22 +220,21 @@ function resetForm() {
<input type="text" name="txtVertical" id="txtVertical" size="5" maxlength="3" onfocus="select()">
</td>
</tr>
</table
</table>
</fieldset>
</td>
<td valign="bottom">
<table align="right" border="0" cellpadding="2" cellspacing="0">
<tr>
<td valign="middle">
</tr>
</table>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr>
<td valign="bottom" align="right">
<input type="submit" value="OK" name="btnOK" id="btnOK" onClick="OKClick()">
</td>
</tr>
<tr>
<td valign="middle">
<input type="reset" value="Cancel" name="btnCancel" id="btnCancel" onClick="window.close();">
</td>
</tr>
</table
</td>
</tr>
</table>