- api: You may now use a displayOnly attribute in your asset properties list

that will display a field, but is not settable via the update() method.
 - api: You may now use a customDrawMethod attribute in your asset properties
   list that will enable you to add custom display options for that fields when
   the edit form is automatically generated.
 - Added file attachments to the Wiki.
 - Added a new attachments form control.
 - Added a form control skeleton.
This commit is contained in:
JT Smith 2007-07-25 22:22:49 +00:00
parent 591fd954e3
commit 350d7f6e01
14 changed files with 599 additions and 85 deletions

View file

@ -14,8 +14,8 @@ use base 'WebGUI::Asset';
use strict;
use Tie::IxHash;
use WebGUI::International;
use WebGUI::Storage::Image;
use WebGUI::Utility;
use WebGUI::VersionTag;
#-------------------------------------------------------------------
@ -41,10 +41,6 @@ Override the default method in order to deal with attachments.
sub addRevision {
my $self = shift;
my $newSelf = $self->SUPER::addRevision(@_);
if ($self->get("storageId")) {
my $newStorage = WebGUI::Storage->get($self->session,$self->get("storageId"))->copy;
$newSelf->update({storageId=>$newStorage->getId});
}
my $now = time();
$newSelf->update({
isHidden => 1,
@ -80,8 +76,6 @@ sub definition {
tie %properties, 'Tie::IxHash';
%properties =
(
storageId => { fieldType => 'image',
defaultValue => undef },
content => { fieldType => "HTMLArea",
defaultValue => undef },
views => {
@ -150,16 +144,16 @@ sub getEditForm {
formHeader => WebGUI::Form::formHeader($session, { action => $url})
.WebGUI::Form::hidden($session, { name => 'func', value => 'editSave' })
.WebGUI::Form::hidden($session, { name=>"proceed", value=>"showConfirmation" }),
formTitle => WebGUI::Form::text($session, { name => 'title', maxlength => 255, size => 40, value => $self->get('title') }),
formContent => WebGUI::Form::HTMLArea($session, { name => 'content', richEditId => $wiki->get('richEditor'), value => $self->get('content') }),
formTitle => WebGUI::Form::text($session, { name => 'title', maxlength => 255, size => 40,
value => $self->get('title'), defaultValue=>$form->get("title","text") }),
formContent => WebGUI::Form::HTMLArea($session, { name => 'content', richEditId => $wiki->get('richEditor'), value => $self->get('content') }) ,
formSubmit => WebGUI::Form::submit($session, { value => 'Save' }),
formProtect => WebGUI::Form::yesNo($session, { name => "isProtected", value=>$self->getValue("isProtected")}),
formAttachment => '',
formKeywords => WebGUI::Form::text($session, {
name => "keywords",
value => WebGUI::Keyword->new($session)->getKeywordsForAsset({asset=>$self}),
}),
allowsAttachments => $wiki->get("maxAttachments"),
allowsAttachments => $wiki->get("allowAttachments"),
formFooter => WebGUI::Form::formFooter($session),
isNew => ($self->getId eq "new"),
canAdminister => $wiki->canAdminister,
@ -172,27 +166,20 @@ sub getEditForm {
protectQuestionLabel => $i18n->get("protectQuestionLabel"),
isProtected => $self->isProtected
};
my $children = [];
if ($self->getId eq "new") {
$var->{formHeader} .= WebGUI::Form::hidden($session, { name=>"assetId", value=>"new" })
.WebGUI::Form::hidden($session, { name=>"class", value=>$form->process("class","className") });
}
} else {
$children = $self->getLineage(["children"]);
}
$var->{formAttachment} = WebGUI::Form::Attachments($session, {
value => $children,
maxAttachments => $wiki->get("allowAttachments")
});
return $self->processTemplate($var, $wiki->getValue('pageEditTemplateId'));
}
#-------------------------------------------------------------------
sub getStorageLocation {
my $self = shift;
unless (exists $self->{_storageLocation}) {
if ($self->get("storageId") eq "") {
$self->{_storageLocation} = WebGUI::Storage::Image->create($self->session);
$self->update({storageId=>$self->{_storageLocation}->getId});
} else {
$self->{_storageLocation} = WebGUI::Storage::Image->get($self->session,$self->get("storageId"));
}
}
return $self->{_storageLocation};
}
#-------------------------------------------------------------------
sub getWiki {
my $self = shift;
@ -249,29 +236,26 @@ sub processPropertiesFromFormPost {
$self->update({isProtected => $self->session->form("isProtected")});
}
delete $self->{_storageLocation};
my $size = 0;
my $storage = $self->getStorageLocation;
foreach my $file (@{$storage->getFiles}) {
if ($storage->isImage($file)) {
my ($w, $h) = $storage->getSizeInPixels($file);
my $max_size = $self->getWiki->get("maxImageSize")
|| $self->session->setting->get("maxImageSize");
if($w > $max_size || $h > $max_size) {
if($w > $h) {
$storage->resize($file, $max_size);
}
else {
$storage->resize($file, 0, $max_size);
}
}
$storage->generateThumbnail($file, $self->getWiki->get("thumbnailSize"));
}
$size += $storage->getFileSize($file);
my @attachments = $self->session->form->param("attachments");
my @tags = ();
foreach my $assetId (@attachments) {
my $asset = WebGUI::Asset->newByDynamicClass($self->session, $assetId);
if (defined $asset) {
unless ($asset->get("parentId") eq $self->getId) {
$asset->setParent($self);
}
push(@tags, $asset->get("tagId"));
$asset->setVersionTag($self->get("tagId"));
}
$self->setSize($size);
}
foreach my $tag (@tags) {
my $version = WebGUI::VersionTag->new($self->session, $tag);
if (defined $version) {
if ($version->getAssetCount == 0) {
$version->rollback;
}
}
}
$self->requestAutoCommit;
}
@ -332,21 +316,22 @@ sub view {
});
}
my $var = {
keywordsLoop => \@keywordsLoop,
viewLabel => $i18n->get("viewLabel"),
editLabel => $i18n->get("editLabel"),
historyLabel => $i18n->get("historyLabel"),
wikiHomeLabel=>$i18n->get("wikiHomeLabel", "Asset_WikiMaster"),
searchLabel=>$i18n->get("searchLabel", "Asset_WikiMaster"),
searchUrl=>$self->getParent->getUrl("func=search"),
recentChangesUrl=>$self->getParent->getUrl("func=recentChanges"),
recentChangesLabel=>$i18n->get("recentChangesLabel", "Asset_WikiMaster"),
mostPopularUrl=>$self->getParent->getUrl("func=mostPopular"),
mostPopularLabel=>$i18n->get("mostPopularLabel", "Asset_WikiMaster"),
wikiHomeUrl=>$self->getParent->getUrl,
historyUrl=>$self->getUrl("func=getHistory"),
editContent=>$self->getEditForm,
content => $self->getWiki->autolinkHtml($self->scrubContent),
keywordsLoop => \@keywordsLoop,
viewLabel => $i18n->get("viewLabel"),
editLabel => $i18n->get("editLabel"),
historyLabel => $i18n->get("historyLabel"),
wikiHomeLabel => $i18n->get("wikiHomeLabel", "Asset_WikiMaster"),
searchLabel => $i18n->get("searchLabel", "Asset_WikiMaster"),
searchUrl => $self->getParent->getUrl("func=search"),
recentChangesUrl => $self->getParent->getUrl("func=recentChanges"),
recentChangesLabel => $i18n->get("recentChangesLabel", "Asset_WikiMaster"),
mostPopularUrl => $self->getParent->getUrl("func=mostPopular"),
mostPopularLabel => $i18n->get("mostPopularLabel", "Asset_WikiMaster"),
wikiHomeUrl => $self->getParent->getUrl,
historyUrl => $self->getUrl("func=getHistory"),
editContent => $self->getEditForm,
allowsAttachments => $self->getWiki->get("allowAttachments"),
content => $self->getWiki->autolinkHtml($self->scrubContent),
};
return $self->processTemplate($var, $self->getWiki->get("pageTemplateId"));
}

View file

@ -141,6 +141,7 @@ sub definition {
return $class->SUPER::definition($session, $definition);
}
#-------------------------------------------------------------------
sub duplicate {

View file

@ -40,11 +40,12 @@ sub appendRecentChanges {
my $self = shift;
my $var = shift;
my $limit = shift || $self->get("recentChangesCount") || 50;
my $rs = $self->session->db->read("select asset.assetId, revisionDate from assetData left join asset on assetData.assetId=asset.assetId where
lineage like ? and lineage<>? and status='approved' order by revisionDate desc limit ?",
[$self->get("lineage").'%', $self->get("lineage"), $limit]);
while (my ($id, $version) = $rs->array) {
my $asset = WebGUI::Asset->new($self->session, $id, "WebGUI::Asset::WikiPage", $version);
foreach my $asset (@{$self->getLineage(["children"], {
returnObjects => 1,
limit => $limit,
includeOnlyClasses =>["WebGUI::Asset::WikiPage"],
orderByClause => "assetData.revisionDate desc"
})}) {
my $user = WebGUI::User->new($self->session, $asset->get("actionTakenBy"));
my $specialAction = '';
my $isAvailable = 1;
@ -296,6 +297,13 @@ sub definition {
label => $i18n->get("max image size"),
hoverHelp => $i18n->get("max image size help")
},
allowAttachments => {
fieldType => "integer",
defaultValue => 0,
tab => "security",
label => $i18n->get("allow attachments"),
hoverHelp => $i18n->get("allow attachments help"),
},
useContentFilter =>{
fieldType=>"yesNo",
defaultValue=>1,
@ -390,7 +398,6 @@ sub www_byKeyword {
});
$p->setBaseUrl($self->getUrl("func=byKeyword"));
foreach my $assetData (@{$p->getPageData}) {
$self->session->errorHandler->warn($assetData->{assetId});
my $asset = WebGUI::Asset->newByDynamicClass($self->session, $assetData->{assetId});
next unless defined $asset;
push(@pages, {
@ -447,6 +454,7 @@ sub www_recentChanges {
sub www_search {
my $self = shift;
my $i18n = WebGUI::International->new($self->session, "Asset_WikiMaster");
my $queryString = $self->session->form->process('query', 'text');
my $var = {
resultsLabel=>$i18n->get("resultsLabel"),
notWhatYouWanted=>$i18n->get("notWhatYouWantedLabel"),
@ -459,9 +467,8 @@ sub www_search {
mostPopularUrl=>$self->getUrl("func=mostPopular"),
mostPopularLabel=>$i18n->get("mostPopularLabel"),
wikiHomeUrl=>$self->getUrl,
addPageUrl=>$self->getUrl("func=add;class=WebGUI::Asset::WikiPage"),
addPageUrl=>$self->getUrl("func=add;class=WebGUI::Asset::WikiPage;title=".$queryString),
};
my $queryString = $self->session->form->process('query', 'text');
if (defined $queryString) {
$self->session->scratch->set('wikiSearchQueryString', $queryString);
}