Added feature to allow users to determine whether new / unplaced assets are added to the top or bottom of the first content position of Layouts.

This commit is contained in:
Frank Dillon 2008-03-08 17:07:29 +00:00
parent d49b7a7077
commit eb8b2f3f31
4 changed files with 287 additions and 222 deletions

View file

@ -7,6 +7,7 @@
- fixed: loadAddConfigs loads hidden files - fixed: loadAddConfigs loads hidden files
- ensure proper XML encoding for ITransact messages - ensure proper XML encoding for ITransact messages
- fixed: fatal error duplicate keywords added to a wiki page - fixed: fatal error duplicate keywords added to a wiki page
- rfe: added the ability to choose whether assets should be added to the front or end of the first content position of the page (Dept of State)
7.5.5 7.5.5
- fixed: Several typos in the new Calendar help documentation. - fixed: Several typos in the new Calendar help documentation.

View file

@ -23,6 +23,7 @@ my $quiet; # this line required
my $session = start(); # this line required my $session = start(); # this line required
convertCacheToBinary($session); convertCacheToBinary($session);
addLayoutOrderSetting( $session );
finish($session); # this line required finish($session); # this line required
@ -41,6 +42,22 @@ sub convertCacheToBinary {
# # and here's our code # # and here's our code
#} #}
#----------------------------------------------------------------------------
# Add a column to the Gallery
sub addLayoutOrderSetting {
my $session = shift;
print "\tAdding Layout Order Setting... " unless $quiet;
$session->db->write( q{
ALTER TABLE Layout ADD COLUMN assetOrder varchar(20) default 'asc';
} );
$session->db->write( q{
UPDATE Layout SET assetOrder='asc';
});
print "DONE!\n" unless $quiet;
}
# --------------- DO NOT EDIT BELOW THIS LINE -------------------------------- # --------------- DO NOT EDIT BELOW THIS LINE --------------------------------

View file

@ -56,33 +56,38 @@ A hash reference passed in from a subclass definition.
=cut =cut
sub definition { sub definition {
my $class = shift; my $class = shift;
my $session = shift; my $session = shift;
my $definition = shift; my $definition = shift;
my $i18n = WebGUI::International->new($session,"Asset_Layout"); my $i18n = WebGUI::International->new($session,"Asset_Layout");
push(@{$definition}, {
assetName=>$i18n->get("assetName"), push(@{$definition}, {
icon=>'layout.gif', assetName=>$i18n->get("assetName"),
tableName=>'Layout', icon=>'layout.gif',
className=>'WebGUI::Asset::Wobject::Layout', tableName=>'Layout',
properties=>{ className=>'WebGUI::Asset::Wobject::Layout',
templateId =>{ properties=>{
fieldType=>"template", templateId =>{
namespace => "Layout", fieldType =>"template",
defaultValue=>'PBtmpl0000000000000054', namespace => "Layout",
}, defaultValue =>'PBtmpl0000000000000054',
contentPositions => { },
noFormPost=>1, contentPositions => {
defaultValue=>undef, noFormPost =>1,
fieldType=>"hidden" defaultValue =>undef,
}, fieldType =>"hidden"
assetsToHide => { },
defaultValue=>undef, assetsToHide => {
fieldType=>"checkList" defaultValue =>undef,
} fieldType =>"checkList"
} },
}); assetOrder => {
return $class->SUPER::definition($session, $definition); defaultValue =>'asc',
fieldType =>'selectBox',
}
}
});
return $class->SUPER::definition($session, $definition);
} }
@ -95,48 +100,61 @@ Returns the TabForm object that will be used in generating the edit page for thi
=cut =cut
sub getEditForm { sub getEditForm {
my $self = shift; my $self = shift;
my $tabform = $self->SUPER::getEditForm(); my $tabform = $self->SUPER::getEditForm();
my $i18n = WebGUI::International->new($self->session,"Asset_Layout"); my $i18n = WebGUI::International->new($self->session,"Asset_Layout");
my ($templateId); my ($templateId);
if (($self->get("assetId") eq "new") && ($self->getParent->get('className') eq 'WebGUI::Asset::Wobject::Layout')) { if (($self->get("assetId") eq "new") && ($self->getParent->get('className') eq 'WebGUI::Asset::Wobject::Layout')) {
$templateId = $self->getParent->getValue('templateId'); $templateId = $self->getParent->getValue('templateId');
} else { } else {
$templateId = $self->getValue('templateId'); $templateId = $self->getValue('templateId');
} }
$tabform->getTab("display")->template( $tabform->getTab("display")->template(
-value=>$templateId, -value=>$templateId,
-label=>$i18n->get('layout template title'), -label=>$i18n->get('layout template title'),
-hoverHelp=>$i18n->get('template description'), -hoverHelp=>$i18n->get('template description'),
-namespace=>"Layout" -namespace=>"Layout"
); );
if ($self->get("assetId") eq "new") {
$tabform->getTab("properties")->whatNext( tie my %assetOrder, "Tie::IxHash";
-options=>{ %assetOrder = (
view=>$i18n->get(823), "asc" =>$i18n->get("asset order asc"),
viewParent=>$i18n->get(847) "desc" =>$i18n->get("asset order desc"),
}, );
-value=>"view" $tabform->getTab("display")->selectBox(
); -name => 'assetOrder',
} else { -label => $i18n->get('asset order label'),
my @assetsToHide = split("\n",$self->getValue("assetsToHide")); -hoverHelp => $i18n->get('asset order hoverHelp'),
my $children = $self->getLineage(["children"],{"returnObjects"=>1, excludeClasses=>["WebGUI::Asset::Wobject::Layout"]}); -value => $self->getValue('assetOrder'),
my %childIds; -options => \%assetOrder
foreach my $child (@{$children}) { );
$childIds{$child->getId} = $child->getTitle; if ($self->get("assetId") eq "new") {
} $tabform->getTab("properties")->whatNext(
$tabform->getTab("display")->checkList( -options=>{
-name=>"assetsToHide", view=>$i18n->get(823),
-value=>\@assetsToHide, viewParent=>$i18n->get(847)
-options=>\%childIds, },
-label=>$i18n->get('assets to hide'), -value=>"view"
-hoverHelp=>$i18n->get('assets to hide description'), );
-vertical=>1, } else {
-uiLevel=>9 my @assetsToHide = split("\n",$self->getValue("assetsToHide"));
); my $children = $self->getLineage(["children"],{"returnObjects"=>1, excludeClasses=>["WebGUI::Asset::Wobject::Layout"]});
} my %childIds;
return $tabform; foreach my $child (@{$children}) {
$childIds{$child->getId} = $child->getTitle;
}
$tabform->getTab("display")->checkList(
-name=>"assetsToHide",
-value=>\@assetsToHide,
-options=>\%childIds,
-label=>$i18n->get('assets to hide'),
-hoverHelp=>$i18n->get('assets to hide description'),
-vertical=>1,
-uiLevel=>9
);
}
return $tabform;
} }
@ -147,182 +165,191 @@ sub getEditForm {
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub prepareView { sub prepareView {
my $self = shift; my $self = shift;
$self->SUPER::prepareView; $self->SUPER::prepareView;
my $children = $self->getLineage( ["children"], { returnObjects=>1, excludeClasses=>["WebGUI::Asset::Wobject::Layout"] }); my $children = $self->getLineage( ["children"], { returnObjects=>1, excludeClasses=>["WebGUI::Asset::Wobject::Layout"] });
my %vars; my %vars;
# I'm sure there's a more efficient way to do this. We'll figure it out someday. # I'm sure there's a more efficient way to do this. We'll figure it out someday.
my @positions = split(/\./,$self->get("contentPositions")); my @positions = split(/\./,$self->get("contentPositions"));
my @hidden = split("\n",$self->get("assetsToHide")); my @hidden = split("\n",$self->get("assetsToHide"));
my %placeHolder; my %placeHolder;
my $i = 1; my $i = 1;
my $template = WebGUI::Asset->new($self->session,$self->get("templateId"),"WebGUI::Asset::Template"); my $template = WebGUI::Asset->new($self->session,$self->get("templateId"),"WebGUI::Asset::Template");
my $templateContent = $template->get("template"); my $templateContent = $template->get("template");
$self->{_viewTemplate} = $template; $self->{_viewTemplate} = $template;
my $numPositions = 1; my $numPositions = 1;
foreach my $j (2..15) { foreach my $j (2..15) {
$numPositions = $j if $templateContent =~ m/position${j}\_loop/; $numPositions = $j if $templateContent =~ m/position${j}\_loop/;
} }
my @found; my @found;
foreach my $position (@positions) { foreach my $position (@positions) {
my @assets = split(",",$position); my @assets = split(",",$position);
ASSET: foreach my $asset (@assets) { ASSET: foreach my $asset (@assets) {
my $childCount = 0; my $childCount = 0;
CHILD: foreach my $child (@{$children}) { CHILD: foreach my $child (@{$children}) {
if ($asset eq $child->getId) { if ($asset eq $child->getId) {
unless (isIn($asset,@hidden) || !($child->canView)) { unless (isIn($asset,@hidden) || !($child->canView)) {
$child->prepareView; $child->prepareView;
if ($i > $numPositions || $i==1) { if ($i > $numPositions || $i==1) {
$placeHolder{$child->getId} = $child; $placeHolder{$child->getId} = $child;
push(@{$vars{"position1_loop"}},{ push(@{$vars{"position1_loop"}},{
id=>$child->getId, id=>$child->getId,
isUncommitted=> $child->get('status') eq 'pending', isUncommitted=> $child->get('status') eq 'pending',
content=>"~~~".$child->getId."~~~~~" content=>"~~~".$child->getId."~~~~~"
}); });
} else { } else {
$placeHolder{$child->getId} = $child; $placeHolder{$child->getId} = $child;
push(@{$vars{"position".$i."_loop"}},{ push(@{$vars{"position".$i."_loop"}},{
id=>$child->getId, id=>$child->getId,
isUncommitted=>$child->get('status') eq 'pending', isUncommitted=>$child->get('status') eq 'pending',
content=>"~~~".$child->getId."~~~~~" content=>"~~~".$child->getId."~~~~~"
}); });
} }
} }
splice(@{$children},$childCount,1); splice(@{$children},$childCount,1);
next ASSET; next ASSET;
}else{ }else{
$childCount++; $childCount++;
}
}
}
$i++;
}
# deal with unplaced children
foreach my $child (@{$children}) {
unless (isIn($child->getId,@hidden)) {
if ($child->canView) {
$child->prepareView;
$placeHolder{$child->getId} = $child;
#Add children to the top or bottom of the first content position based on assetOrder setting
if($self->getValue("assetOrder") eq "asc"){
push(@{$vars{"position1_loop"}},{
id=>$child->getId,
content=>"~~~".$child->getId."~~~~~"
});
} }
} else {
} unshift(@{$vars{"position1_loop"}},{
$i++; id=>$child->getId,
} content=>"~~~".$child->getId."~~~~~"
# deal with unplaced children });
foreach my $child (@{$children}) { }
unless (isIn($child->getId,@hidden)) { }
if ($child->canView) { }
$child->prepareView; }
$placeHolder{$child->getId} = $child; $self->{_viewPlaceholder} = \%placeHolder;
push(@{$vars{"position1_loop"}},{ $vars{showAdmin} = ($self->session->var->isAdminOn && $self->canEdit);
id=>$child->getId, $self->{_viewVars} = \%vars;
content=>"~~~".$child->getId."~~~~~" if ($vars{showAdmin}) {
}); # under normal circumstances we don't put HTML stuff in our code, but this will make it much easier
} # for end users to work with our templates
} $self->session->style->setScript($self->session->url->extras("draggable.js"),{ type=>"text/javascript" });
} $self->session->style->setLink($self->session->url->extras("draggable.css"),{ type=>"text/css", rel=>"stylesheet", media=>"all" });
$self->{_viewPlaceholder} = \%placeHolder; $self->session->style->setRawHeadTags('
$vars{showAdmin} = ($self->session->var->isAdminOn && $self->canEdit); <style type="text/css">
$self->{_viewVars} = \%vars; .dragging, .empty {
if ($vars{showAdmin}) { background-image: url("'.$self->session->url->extras('opaque.gif').'");
# under normal circumstances we don't put HTML stuff in our code, but this will make it much easier }
# for end users to work with our templates </style>
$self->session->style->setScript($self->session->url->extras("draggable.js"),{ type=>"text/javascript" }); ');
$self->session->style->setLink($self->session->url->extras("draggable.css"),{ type=>"text/css", rel=>"stylesheet", media=>"all" }); }
$self->session->style->setRawHeadTags('
<style type="text/css">
.dragging, .empty {
background-image: url("'.$self->session->url->extras('opaque.gif').'");
}
</style>
');
}
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub view { sub view {
my $self = shift; my $self = shift;
if ($self->{_viewVars}{showAdmin} && $self->canEditIfLocked) { if ($self->{_viewVars}{showAdmin} && $self->canEditIfLocked) {
# under normal circumstances we don't put HTML stuff in our code, but this will make it much easier # under normal circumstances we don't put HTML stuff in our code, but this will make it much easier
# for end users to work with our templates # for end users to work with our templates
$self->{_viewVars}{"dragger.icon"} = '<div class="dragTrigger dragTriggerWrap">'.$self->session->icon->drag('class="dragTrigger"').'</div>'; $self->{_viewVars}{"dragger.icon"} = '<div class="dragTrigger dragTriggerWrap">'.$self->session->icon->drag('class="dragTrigger"').'</div>';
$self->{_viewVars}{"dragger.init"} = ' $self->{_viewVars}{"dragger.init"} = '
<iframe id="dragSubmitter" style="display: none;" src="'.$self->session->url->extras('spacer.gif').'"></iframe> <iframe id="dragSubmitter" style="display: none;" src="'.$self->session->url->extras('spacer.gif').'"></iframe>
<script type="text/javascript"> <script type="text/javascript">
dragable_init("'.$self->getUrl("func=setContentPositions;map=").'"); dragable_init("'.$self->getUrl("func=setContentPositions;map=").'");
</script> </script>
'; ';
} }
my $showPerformance = $self->session->errorHandler->canShowPerformanceIndicators(); my $showPerformance = $self->session->errorHandler->canShowPerformanceIndicators();
my $out = $self->processTemplate($self->{_viewVars},undef,$self->{_viewTemplate}); my $out = $self->processTemplate($self->{_viewVars},undef,$self->{_viewTemplate});
my @parts = split("~~~~~",$self->processTemplate($self->{_viewVars},undef,$self->{_viewTemplate})); my @parts = split("~~~~~",$self->processTemplate($self->{_viewVars},undef,$self->{_viewTemplate}));
my $output = ""; my $output = "";
foreach my $part (@parts) { foreach my $part (@parts) {
my ($outputPart, $assetId) = split("~~~",$part,2); my ($outputPart, $assetId) = split("~~~",$part,2);
if ($self->{_viewPrintOverride}) { if ($self->{_viewPrintOverride}) {
$self->session->output->print($outputPart); $self->session->output->print($outputPart);
} else { } else {
$output .= $outputPart; $output .= $outputPart;
} }
my $asset = $self->{_viewPlaceholder}{$assetId}; my $asset = $self->{_viewPlaceholder}{$assetId};
if (defined $asset) { if (defined $asset) {
my $t = [Time::HiRes::gettimeofday()] if ($showPerformance); my $t = [Time::HiRes::gettimeofday()] if ($showPerformance);
my $assetOutput = $asset->view; my $assetOutput = $asset->view;
$assetOutput .= "Asset:".Time::HiRes::tv_interval($t) if ($showPerformance); $assetOutput .= "Asset:".Time::HiRes::tv_interval($t) if ($showPerformance);
if ($self->{_viewPrintOverride}) { if ($self->{_viewPrintOverride}) {
$self->session->output->print($assetOutput); $self->session->output->print($assetOutput);
} else { } else {
$output .= $assetOutput; $output .= $assetOutput;
} }
} }
} }
return $output; return $output;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub www_setContentPositions { sub www_setContentPositions {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
$self->addRevision({ $self->addRevision({
contentPositions=>$self->session->form->process("map") contentPositions=>$self->session->form->process("map")
}); });
if ($self->session->setting->get("autoRequestCommit")) { if ($self->session->setting->get("autoRequestCommit")) {
WebGUI::VersionTag->getWorking($self->session)->requestCommit; WebGUI::VersionTag->getWorking($self->session)->requestCommit;
} }
return "Map set: ".$self->session->form->process("map"); return "Map set: ".$self->session->form->process("map");
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub getContentLastModified { sub getContentLastModified {
# Buggo: this is a little too conservative. Children that are hidden maybe shouldn't count. Hm. # Buggo: this is a little too conservative. Children that are hidden maybe shouldn't count. Hm.
my $self = shift; my $self = shift;
my $mtime = $self->get("revisionDate"); my $mtime = $self->get("revisionDate");
foreach my $child (@{$self->getLineage(["children"],{returnObjects=>1, excludeClasses=>['WebGUI::Asset::Wobject::Layout']})}) { foreach my $child (@{$self->getLineage(["children"],{returnObjects=>1, excludeClasses=>['WebGUI::Asset::Wobject::Layout']})}) {
my $child_mtime = $child->getContentLastModified; my $child_mtime = $child->getContentLastModified;
$mtime = $child_mtime if ($child_mtime > $mtime); $mtime = $child_mtime if ($child_mtime > $mtime);
} }
return $mtime; return $mtime;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub www_view { sub www_view {
my $self = shift; my $self = shift;
# slashdot / burst protection hack # slashdot / burst protection hack
if ($self->session->var->get("userId") eq "1" && $self->session->form->param() == 0) { if ($self->session->var->get("userId") eq "1" && $self->session->form->param() == 0) {
my $check = $self->checkView; my $check = $self->checkView;
return $check if (defined $check); return $check if (defined $check);
my $cache = WebGUI::Cache->new($self->session, "view_".$self->getId); my $cache = WebGUI::Cache->new($self->session, "view_".$self->getId);
my $out = $cache->get if defined $cache; my $out = $cache->get if defined $cache;
unless ($out) { unless ($out) {
$self->prepareView; $self->prepareView;
$self->session->stow->set("cacheFixOverride", 1); $self->session->stow->set("cacheFixOverride", 1);
$out = $self->processStyle($self->view); $out = $self->processStyle($self->view);
$cache->set($out, 60); $cache->set($out, 60);
$self->session->stow->delete("cacheFixOverride"); $self->session->stow->delete("cacheFixOverride");
} }
# keep those ads rotating # keep those ads rotating
while ($out =~ /(\[AD\:([^\]]+)\])/gs) { while ($out =~ /(\[AD\:([^\]]+)\])/gs) {
my $code = $1; my $code = $1;
my $adSpace = WebGUI::AdSpace->newByName($self->session, $2); my $adSpace = WebGUI::AdSpace->newByName($self->session, $2);
my $ad = $adSpace->displayImpression if (defined $adSpace); my $ad = $adSpace->displayImpression if (defined $adSpace);
$out =~ s/\Q$code/$ad/ges; $out =~ s/\Q$code/$ad/ges;
} }
$self->session->http->setLastModified($self->getContentLastModified); $self->session->http->setLastModified($self->getContentLastModified);
$self->session->http->sendHeader; $self->session->http->sendHeader;
$self->session->output->print($out, 1); $self->session->output->print($out, 1);
return "chunked"; return "chunked";
} }
$self->{_viewPrintOverride} = 1; # we do this to make it output each asset as it goes, rather than waiting until the end $self->{_viewPrintOverride} = 1; # we do this to make it output each asset as it goes, rather than waiting until the end
return $self->SUPER::www_view; return $self->SUPER::www_view;
} }
1; 1;

View file

@ -113,6 +113,26 @@ be useful, others may not.|,
lastUpdated => 1164841027 lastUpdated => 1164841027
}, },
'asset order asc' => {
message => q|To the Bottom|,
lastUpdated => 1164841027
},
'asset order desc' => {
message => q|To the Top|,
lastUpdated => 1164841027
},
'asset order label' => {
message => q|Add New Assets|,
lastUpdated => 1164841027
},
'asset order hoverhelp' => {
message => q|Choose whether you'd like new or unpositioned assets added to the top or bottom of the first content position on the page.|,
lastUpdated => 1164841027
},
}; };
1; 1;