Update Dashboard for Moose.
This commit is contained in:
parent
e5d471567e
commit
b6048b7f24
1 changed files with 77 additions and 92 deletions
|
|
@ -11,14 +11,71 @@ package WebGUI::Asset::Wobject::Dashboard;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::ProfileField;
|
||||
use Time::HiRes;
|
||||
use WebGUI::Asset::Wobject;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
use WebGUI::Definition::Asset;
|
||||
extends 'WebGUI::Asset::Wobject';
|
||||
aspect assetName => [ 'assetName', 'Asset_Dashboard' ];
|
||||
aspect icon => 'dashboard.gif';
|
||||
aspect tableName => 'Dashboard';
|
||||
property templateId => (
|
||||
fieldType => "template",
|
||||
default => 'DashboardViewTmpl00001',
|
||||
namespace => "Dashboard",
|
||||
tab => 'display',
|
||||
label => [ 'dashboard template field label', 'Asset_Dashboard' ],
|
||||
hoverHelp => [ 'dashboard template description', 'Asset_Dashboard' ],
|
||||
);
|
||||
|
||||
property adminsGroupId => (
|
||||
fieldType => "group",
|
||||
default => '4',
|
||||
tab => 'security',
|
||||
label => [ 'dashboard adminsGroupId field label', 'Asset_Dashboard' ],
|
||||
hoverHelp => [ 'dashboard adminsGroupId description', 'Asset_Dashboard' ],
|
||||
);
|
||||
|
||||
property usersGroupId => (
|
||||
fieldType => "group",
|
||||
default => '2',
|
||||
label => [ 'dashboard usersGroupId field label', 'Asset_Dashboard' ],
|
||||
hoverHelp => [ 'dashboard usersGroupId description', 'Asset_Dashboard' ],
|
||||
);
|
||||
|
||||
property isInitialized => (
|
||||
fieldType => "yesNo",
|
||||
default => 0,
|
||||
noFormPost => 1,
|
||||
);
|
||||
|
||||
property assetsToHide => (
|
||||
default => undef,
|
||||
fieldType => "checkList",
|
||||
noFormPost => \&_assetsToHide_noFormPost,
|
||||
label => [ 'assets to hide', 'Asset_Dashboard' ],
|
||||
hoverHelp => [ 'assets to hide description', 'Asset_Dashboard' ],
|
||||
vertical => 1,
|
||||
uiLevel => 9,
|
||||
options => \&_assetsToHide_options,
|
||||
);
|
||||
sub _assetsToHide_noFormPost {
|
||||
my $self = shift;
|
||||
return $self->session->form->process("func") eq "add" ? 1 : 0;
|
||||
}
|
||||
sub _assetsToHide_options {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $children = $self->getLineage(["children"],{"returnObjects"=>1, excludeClasses=>["WebGUI::Asset::Wobject::Layout"]});
|
||||
my %childIds;
|
||||
foreach my $child (@{$children}) {
|
||||
$childIds{$child->getId} = $child->getTitle.' ['.ref($child).']';
|
||||
}
|
||||
return \%childIds;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -34,7 +91,7 @@ in the dashboard's adminsGroup.
|
|||
sub canManage {
|
||||
my $self = shift;
|
||||
return 0 if $self->session->user->isVisitor;
|
||||
return $self->session->user->isInGroup($self->get("adminsGroupId"));
|
||||
return $self->session->user->isInGroup($self->adminsGroupId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -50,7 +107,7 @@ in this dashboard's userGroup.
|
|||
sub canPersonalize {
|
||||
my $self = shift;
|
||||
return 0 if $self->session->user->isVisitor;
|
||||
return $self->session->user->isInGroup($self->get("usersGroupId"));
|
||||
return $self->session->user->isInGroup($self->usersGroupId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -61,50 +118,10 @@ sub definition {
|
|||
my $i18n = WebGUI::International->new($session,"Asset_Dashboard");
|
||||
|
||||
my %properties;
|
||||
tie %properties, 'Tie::IxHash';
|
||||
%properties = (
|
||||
templateId => {
|
||||
fieldType => "template",
|
||||
defaultValue => 'DashboardViewTmpl00001',
|
||||
namespace => "Dashboard",
|
||||
tab => 'display',
|
||||
label => $i18n->get('dashboard template field label'),
|
||||
hoverHelp => $i18n->get('dashboard template description'),
|
||||
},
|
||||
|
||||
adminsGroupId => {
|
||||
fieldType => "group",
|
||||
defaultValue => '4',
|
||||
tab => 'security',
|
||||
label => $i18n->get('dashboard adminsGroupId field label'),
|
||||
hoverHelp=>$i18n->get('dashboard adminsGroupId description'),
|
||||
},
|
||||
|
||||
usersGroupId => {
|
||||
fieldType => "group",
|
||||
defaultValue => '2',
|
||||
label => $i18n->get('dashboard usersGroupId field label'),
|
||||
hoverHelp => $i18n->get('dashboard usersGroupId description'),
|
||||
},
|
||||
|
||||
isInitialized => {
|
||||
fieldType => "yesNo",
|
||||
defaultValue => 0,
|
||||
noFormPost => 1,
|
||||
autoGenerate => 0,
|
||||
},
|
||||
|
||||
assetsToHide => {
|
||||
defaultValue => undef,
|
||||
fieldType => "checkList",
|
||||
autoGenerate => 0,
|
||||
},
|
||||
);
|
||||
|
||||
push(@{$definition}, {
|
||||
assetName => $i18n->get('assetName'),
|
||||
icon => 'dashboard.gif',
|
||||
tableName => 'Dashboard',
|
||||
className => 'WebGUI::Asset::Wobject::Dashboard',
|
||||
properties => \%properties,
|
||||
autoGenerateForms => 1,
|
||||
|
|
@ -138,7 +155,7 @@ then return default locations.
|
|||
|
||||
sub getContentPositions {
|
||||
my $self = shift;
|
||||
my $dummy = $self->initialize unless $self->get("isInitialized");
|
||||
my $dummy = $self->initialize unless $self->isInitialized;
|
||||
my $u = WebGUI::User->new($self->session, $self->discernUserId);
|
||||
return $u->profileField($self->getContentPositionsId)
|
||||
|| $self->getContentPositionsDefault;
|
||||
|
|
@ -169,7 +186,7 @@ Returns the default content positions for this Dashboard.
|
|||
|
||||
sub getContentPositionsDefault {
|
||||
my $self = shift;
|
||||
my $dummy = $self->initialize unless $self->get("isInitialized");
|
||||
my $dummy = $self->initialize unless $self->isInitialized;
|
||||
# The default positions are saved under the "Visitor" user
|
||||
my $u = WebGUI::User->new($self->session, 1);
|
||||
return $u->profileField($self->getContentPositionsId);
|
||||
|
|
@ -177,38 +194,6 @@ sub getContentPositionsDefault {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getEditForm
|
||||
|
||||
Extend the base method to display lists of assets to hide or show.
|
||||
|
||||
=cut
|
||||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm;
|
||||
my $i18n = WebGUI::International->new($self->session, "Asset_Dashboard");
|
||||
if ($self->session->form->process("func") ne "add") {
|
||||
my @assetsToHide = split("\n",$self->getValue("assetsToHide"));
|
||||
my $children = $self->getLineage(["children"],{"returnObjects"=>1, excludeClasses=>["WebGUI::Asset::Wobject::Layout"]});
|
||||
my %childIds;
|
||||
foreach my $child (@{$children}) {
|
||||
$childIds{$child->getId} = $child->getTitle.' ['.ref($child).']';
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 initialize
|
||||
|
||||
Add the unique profile field that holds content positions for this dashboard.
|
||||
|
|
@ -256,7 +241,7 @@ sub prepareView {
|
|||
my $self = shift;
|
||||
$self->SUPER::prepareView;
|
||||
my $children = $self->getLineage( ["children"], { returnObjects=>1, excludeClasses=>["WebGUI::Asset::Wobject::Layout","WebGUI::Asset::Wobject::Dashboard"] });
|
||||
my @hidden = split("\n",$self->get("assetsToHide"));
|
||||
my @hidden = split("\n",$self->assetsToHide);
|
||||
foreach my $child (@{$children}) {
|
||||
unless (isIn($child->getId, @hidden) || !($child->canView)) {
|
||||
$self->session->style->setRawHeadTags($child->getExtraHeadTags);
|
||||
|
|
@ -280,7 +265,7 @@ sub processPropertiesFromFormPost {
|
|||
if ($self->session->form->process("assetId") eq "new" && $self->session->form->process("class") eq 'WebGUI::Asset::Wobject::Dashboard') {
|
||||
$self->initialize;
|
||||
if (ref $self->getParent eq 'WebGUI::Asset::Wobject::Layout') {
|
||||
$self->getParent->update({assetsToHide=>$self->getParent->get("assetsToHide")."\n".$self->getId});
|
||||
$self->getParent->update({assetsToHide=>$self->getParent->assetsToHide."\n".$self->getId});
|
||||
}
|
||||
$self->update({styleTemplateId=>'PBtmplBlankStyle000001'});
|
||||
}
|
||||
|
|
@ -322,24 +307,24 @@ sub view {
|
|||
{ type=>'text/javascript' }
|
||||
);
|
||||
|
||||
my $templateId = $self->get("templateId");
|
||||
my $templateId = $self->templateId;
|
||||
my $children = $self->getLineage( ["children"], { returnObjects=>1, excludeClasses=>["WebGUI::Asset::Wobject::Layout","WebGUI::Asset::Wobject::Dashboard"] });
|
||||
# I'm sure there's a more efficient way to do this. We'll figure it out someday.
|
||||
my @positions = split(/\./,$self->getContentPositions);
|
||||
my @hidden = split("\n",$self->get("assetsToHide"));
|
||||
my @hidden = split("\n",$self->assetsToHide);
|
||||
foreach my $child (@{$children}) {
|
||||
push(@hidden,$child->get('shortcutToAssetId')) if ref $child eq 'WebGUI::Asset::Shortcut';
|
||||
push(@hidden,$child->shortcutToAssetId) if ref $child eq 'WebGUI::Asset::Shortcut';
|
||||
#the following loop will initially place just-dashletted assets.
|
||||
for (my $i = 0; $i < scalar(@positions); $i++) {
|
||||
next unless isIn($child->get('shortcutToAssetId'),@hidden);
|
||||
next unless isIn($child->shortcutToAssetId,@hidden);
|
||||
my $newChildId = $child->getId;
|
||||
my $oldChildId = $child->get('shortcutToAssetId');
|
||||
my $oldChildId = $child->shortcutToAssetId;
|
||||
$positions[$i] =~ s/${oldChildId}/${newChildId}/g;
|
||||
}
|
||||
}
|
||||
my $i = 1;
|
||||
my $templateAsset = WebGUI::Asset->newById($self->session, $templateId) || WebGUI::Asset->getImportNode($self->session);
|
||||
my $template = $templateAsset->get("template");
|
||||
my $template = $templateAsset->template;
|
||||
my $numPositions = 1;
|
||||
foreach my $j (2..15) {
|
||||
$numPositions = $j if $template =~ m/position${j}\_loop/;
|
||||
|
|
@ -393,7 +378,7 @@ sub view {
|
|||
foreach my $child (@{$children}) {
|
||||
unless (isIn($child->getId, @found)||isIn($child->getId,@hidden)) {
|
||||
if ($child->canView) {
|
||||
$child->{_properties}{title} = $child->getShortcut->get("title") if (ref $child eq 'WebGUI::Asset::Shortcut');
|
||||
$child->{_properties}{title} = $child->getShortcut->title if (ref $child eq 'WebGUI::Asset::Shortcut');
|
||||
push(@{$vars{"position1_loop"}},{
|
||||
id=>$child->getId,
|
||||
content=>'',
|
||||
|
|
@ -430,8 +415,8 @@ sub www_setContentPositions {
|
|||
my $self = shift;
|
||||
return 'Visitors cannot save settings' if($self->session->user->isVisitor);
|
||||
return $self->session->privilege->insufficient() unless ($self->canPersonalize);
|
||||
return 'empty' unless $self->get("isInitialized");
|
||||
my $dummy = $self->initialize unless $self->get("isInitialized");
|
||||
return 'empty' unless $self->isInitialized;
|
||||
my $dummy = $self->initialize unless $self->isInitialized;
|
||||
my $u = WebGUI::User->new($self->session, $self->discernUserId);
|
||||
my $success = $u->profileField($self->getContentPositionsId,$self->session->form->process("map")) eq $self->session->form->process("map");
|
||||
return "Map set: ".$self->session->form->process("map") if $success;
|
||||
|
|
@ -449,12 +434,12 @@ Renders self->view based upon current style, subject to timeouts. Returns Privil
|
|||
sub www_view {
|
||||
my $self = shift;
|
||||
unless ($self->canView) {
|
||||
if ($self->get("state") eq "published") { # no privileges, make em log in
|
||||
if ($self->state eq "published") { # no privileges, make em log in
|
||||
return $self->session->privilege->noAccess();
|
||||
} elsif ($self->session->var->isAdminOn && $self->get("state") =~ /^trash/) { # show em trash
|
||||
} elsif ($self->session->var->isAdminOn && $self->state =~ /^trash/) { # show em trash
|
||||
$self->session->http->setRedirect($self->getUrl("func=manageTrash"));
|
||||
return undef;
|
||||
} elsif ($self->session->var->isAdminOn && $self->get("state") =~ /^clipboard/) { # show em clipboard
|
||||
} elsif ($self->session->var->isAdminOn && $self->state =~ /^clipboard/) { # show em clipboard
|
||||
$self->session->http->setRedirect($self->getUrl("func=manageClipboard"));
|
||||
return undef;
|
||||
} else { # tell em it doesn't exist anymore
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue