From 72619fb9c0a9fd312bd5f58e2b54514abf5d9712 Mon Sep 17 00:00:00 2001 From: Matthew Wilson Date: Tue, 29 Nov 2005 18:48:26 +0000 Subject: [PATCH] Committing Dashboard. Many more fixes, updates to come. --- docs/changelog/6.x.x.txt | 11 + docs/upgrades/upgrade_6.7.8-6.8.0.pl | 780 ++++++++++++++++++++++++++- lib/WebGUI/Asset.pm | 1 - lib/WebGUI/Asset/Shortcut.pm | 574 +++++++++++++------- lib/WebGUI/Asset/Wobject/Layout.pm | 1 - 5 files changed, 1133 insertions(+), 234 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index b59ecffcc..a0df20f9d 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -22,6 +22,17 @@ - Added a simple Style Wizard. - Updated preload.perl to automatically preload all WebGUI related modules, which increased shared memory usage by 30%. + - Added StockData asset. + - Added WeatherData asset. + - Added MultiSearch asset. Will eventually be re-merged with the + existing search wobject for the release of 6.9.0. + - Extended the Shortcut asset to allow fully extensible admin overrides, + which can be pulled from user preferences also attached to a Shortcut. + - Added Dashboard asset, which uses personalized Shortcuts to allow + personalization of any asset on your site to create a "portal" or + "dashboard". You can create more than one dashboard per site. + Assets that come with templates for the Dashboard: + StockData, WeatherData, SearchBox, SyndicatedContent 6.7.7 diff --git a/docs/upgrades/upgrade_6.7.8-6.8.0.pl b/docs/upgrades/upgrade_6.7.8-6.8.0.pl index bf8e29e7c..27371588e 100644 --- a/docs/upgrades/upgrade_6.7.8-6.8.0.pl +++ b/docs/upgrades/upgrade_6.7.8-6.8.0.pl @@ -27,9 +27,7 @@ my $quiet; start(); addTimeZonesToUserPreferences(); -# MUST DO: any dates in WebGUI greater than epoch 2^32 must be reduced, because -# the new DateTime system uses Params::Validate, which will only validate integers -# up to 2^32 as SCALARs. :( +fixVeryLateDates(); removeUnneededFiles(); updateCollaboration(); addPhotoField(); @@ -40,6 +38,7 @@ addEnableAvatarColumn(); addMatrix(); updateConfigFile(); addInOutBoard(); +addDashboardStuff(); addZipArchive(); updateUserProfileDayLabels(); finish(); @@ -99,23 +98,758 @@ STOP $newAsset->commit; } +#------------------------------------------------- +sub addDashboardStuff { + print "\tAdding Dashboard tables and templates.\n" unless ($quiet); + WebGUI::SQL->write("CREATE TABLE `Dashboard` ( + `assetId` VARCHAR(22) BINARY NOT NULL DEFAULT '', + `revisionDate` VARCHAR(22) BINARY NOT NULL DEFAULT '', + `adminsGroupId` VARCHAR(22) BINARY NOT NULL DEFAULT '4', + `usersGroupId` VARCHAR(22) BINARY NOT NULL DEFAULT '2', + `templateId` VARCHAR(22) BINARY NOT NULL DEFAULT 'DashboardViewTmpl00001', + `mapFieldId` VARCHAR(22) DEFAULT '', + PRIMARY KEY(`assetId`, `revisionDate`) + )"); +# WebGUI::SQL->write("CREATE TABLE `Dashlet` ( +# `assetId` VARCHAR(22) BINARY NOT NULL DEFAULT '', +# `revisionDate` VARCHAR(22) BINARY NOT NULL DEFAULT '', +# `proxiedAssetId` VARCHAR(22) BINARY NOT NULL DEFAULT '', +# PRIMARY KEY(`assetId`) +# )"); +# Convert Shortcuts to Dashlortcuts. + WebGUI::SQL->write("CREATE TABLE `WeatherData` ( + `assetId` VARCHAR(22) BINARY NOT NULL DEFAULT '', + `revisionDate` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, + `templateId` VARCHAR(22) BINARY NOT NULL DEFAULT 'WeatherDataTmpl0000001', + `locations` TEXT DEFAULT '', + PRIMARY KEY(`assetId`, `revisionDate`) + )"); + WebGUI::SQL->write("CREATE TABLE `MultiSearch` ( + `assetId` VARCHAR(22) BINARY NOT NULL DEFAULT '', + `revisionDate` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, + `templateId` VARCHAR(22) BINARY NOT NULL DEFAULT 'MultiSearchTmpl0000001', + `predefinedSearches` TEXT DEFAULT '', + PRIMARY KEY(`assetId`, `revisionDate`) + )"); + WebGUI::SQL->write("CREATE TABLE `wgField` ( + `assetId` VARCHAR(22) BINARY NOT NULL DEFAULT '', + `revisionDate` VARCHAR(22) NOT NULL DEFAULT '', + `formTemplateId` VARCHAR(22) BINARY DEFAULT '', + `valueTemplateId` VARCHAR(22) BINARY DEFAULT '', + `isUserPref` TINYINT UNSIGNED NOT NULL DEFAULT 0, + `fieldName` VARCHAR(255) DEFAULT '', + `fieldLabel` VARCHAR(255) DEFAULT '', + `fieldDescription` TEXT DEFAULT '', + `fieldType` VARCHAR(50) DEFAULT '', + `overrideForm` TINYINT UNSIGNED NOT NULL DEFAULT 0, + `overrideValue` TINYINT UNSIGNED NOT NULL DEFAULT 0, + `possibleValues` TEXT DEFAULT '', + `defaultValue` TEXT NOT NULL DEFAULT '', + PRIMARY KEY(`assetId`, `revisionDate`) + )"); + WebGUI::SQL->write("CREATE TABLE `wgFieldUserData` ( + `assetId` VARCHAR(22) BINARY NOT NULL DEFAULT '', + `userId` VARCHAR(22) BINARY NOT NULL DEFAULT '', + `userValue` TEXT DEFAULT '', + PRIMARY KEY(`assetId`, `userId`) + )"); + + WebGUI::SQL->write("create table StockData ( + assetId varchar(22) binary not null, + templateId varchar(22) binary not null default 'StockListTMPL000000001', + displayTemplateId varchar(22) binary not null default 'StockListTMPL000000002', + defaultStocks text, + source varchar(50) default 'usa', + failover integer default 1, + revisionDate integer not null, + primary key(assetId,revisionDate) +)"); + + my $template = < + + + ^Page(title); - <tmpl_var session.setting.companyName> + + + + + + +^AdminBar("PBtmpl0000000000000090"); + + + +STOP +my $folder = WebGUI::Asset->newByUrl('templates') || WebGUI::Asset->getImportNode; +my $newAsset = $folder->addChild({ + className=>"WebGUI::Asset::Template", + template=>$template, + namespace=>"style", + title=>'WebGUI 6 Blank Style', + menuTitle=>'WebGUI 6 Blank Style', + ownerUserId=>'3', + groupIdView=>'4', + groupIdEdit=>'4', + isHidden=>1 +}, 'PBtmplBlankStyle000001'); +$newAsset->commit; +$template = < + +table.dashboardColumn { +width: 100%; +background: none; +background-color:transparent; +} +.availableDashlet { +} +div#dashboardContainer { +font: 11px Lucida Grande, Verdana, Arial, Helvetica, sans serif; +background: url(^Extras;wobject/Dashboard/background.gif) repeat-x #fff; +} +table#dashboardChooserContainer { +margin:0px; +padding:0px; +border:0px; + +} + +tbody.availableDashlet * div.content { display: none; } +div#availableDashlets * td {width:100px;} +div#availableDashlets * div.content {width:100px; overflow-x:hidden;} +div#columnsContainerDiv { +margin:6px; +} +td {vertical-align: top;} +h1 { +font: 15px Lucida Grande, Verdana, Arial, Helvetica, sans serif; +} + +
+ + + + + + + +
+ + + + +
Add New Content
+ +

+ +

+
+ + +

+ +

+
+ + + + +

+ +

+
+
+ + +
+ + + + + + + + +
+ + + + + + + + +
+
+
+
+
+ +
+
+
+
+ + + + + + + + + +
+
+
+ +
+
+ +
+
+
+
+ + + + + + + + +
+
+
+ +
+
+
+
+
+
+
+ + + + +
+ +
+
+STOP +$newAsset = $folder->addChild({ + title=>"Dashboard Default View", + menuTitle=>"Dashboard Default View", + namespace=>"Dashboard", + url=>"dashboard-default-view-template", + className=>"WebGUI::Asset::Template", + template=>$template + }, "DashboardViewTmpl00001"); +$newAsset->commit; +$template = < + + +

+
+ + +

+
+ + +

+ + + + + + + + + + + + + + +
+
+
+
 
+ +
+ +
+
+
+
°F
+
+ +
+STOP +WebGUI::Asset->getImportNode; +my $newAsset = $folder->addChild({ + className=>"WebGUI::Asset::Template", + template=>$template, + namespace=>"WeatherData", + title=>'WeatherData Default View', + menuTitle=>'WeatherData Default View', + ownerUserId=>'3', + groupIdView=>'4', + groupIdEdit=>'4', + isHidden=>1 + }, 'WeatherDataTmpl0000001'); +$newAsset->commit; +$template = < + + + + + + + + + + + + + + +
+
+ + + + + +
() + +
1:23 PM EDT
+ +
+
+
+
+ + + + + + +
+ + + + + + + + + + + +
Today5d1m3m1y5y20y
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Last Price
Market Cap
Change + +
Open
Day High
Bid
52 Wk High
E.P.S.
Ex-Div Date
Yield
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Last Trade
Volume m
% Change %
Prev Close
Day Low
Ask
52 Wk Low
P/E Ratio
Dividend
Exchange
+
+
+ +

+ + + + +
+ +
+
+ +STOP +WebGUI::Asset->getImportNode; +my $newAsset = $folder->addChild({ + className=>"WebGUI::Asset::Template", + template=>$template, + namespace=>"StockData/Display", + title=>'StockData Default Display', + menuTitle=>'StockData Default Display', + ownerUserId=>'3', + groupIdView=>'4', + groupIdEdit=>'4', + isHidden=>1 + }, 'StockDataTMPL000000002'); +$newAsset->commit; +$template = < + + +

+
+ + +

+
+ + +

+ + + + + + + + + + + +
+
+ + + + + +
Stock Watch +
+ Last Update: EDT
+ +
+
+
+ + + + + + + + + + + + + + + + + + +
Name SymbolLastTickChg
+ + + +
+
+STOP +WebGUI::Asset->getImportNode; +my $newAsset = $folder->addChild({ + className=>"WebGUI::Asset::Template", + template=>$template, + namespace=>"StockData", + title=>'StockData Default View', + menuTitle=>'StockData Default View', + ownerUserId=>'3', + groupIdView=>'4', + groupIdEdit=>'4', + isHidden=>1 + }, 'StockDataTMPL000000001'); +$newAsset->commit; +$template = < + + +

+
+ + +

+
+ + +

+ + +

+
+ + + + +
+Search:  +
+  For:  + +
+
+
+
+STOP +WebGUI::Asset->getImportNode; +my $newAsset = $folder->addChild({ + className=>"WebGUI::Asset::Template", + template=>$template, + namespace=>"MultiSearch", + title=>'MultiSearch Default Display', + menuTitle=>'MultiSearch Default Display', + ownerUserId=>'3', + groupIdView=>'4', + groupIdEdit=>'4', + isHidden=>1 + }, 'MultiSearchTmpl0000001'); +$newAsset->commit; +} + +#------------------------------------------------- +sub fixVeryLateDates { + WebGUI::SQL->write("update assetdata set endDate='2082783600' where endDate>=4294967294"); +} + #------------------------------------------------- sub updateConfigFile { - print "\tUpdating config file.\n" unless ($quiet); - my $pathToConfig = '../../etc/'.$configFile; - my $conf = Parse::PlainConfig->new('DELIM' => '=', 'FILE' => $pathToConfig, 'PURGE'=>1); - my %newConfig; - foreach my $key ($conf->directives) { # delete unwanted stuff - unless (isIn($key,qw(enableDateCache scripturl))) { - $newConfig{$key} = $conf->get($key); - } - } - push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::Matrix"); - push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::InOutBoard"); - push(@{$newConfig{assets}}, "WebGUI::Asset::File::ZipArchive"); - $conf->purge; - $conf->set(%newConfig); - $conf->write; + print "\tUpdating config file.\n" unless ($quiet); + my $pathToConfig = '../../etc/'.$configFile; + my $conf = Parse::PlainConfig->new('DELIM' => '=', 'FILE' => $pathToConfig, 'PURGE'=>1); + my %newConfig; + foreach my $key ($conf->directives) { # delete unwanted stuff + unless (isIn($key,qw(enableDateCache scripturl))) { + $newConfig{$key} = $conf->get($key); + } + } + push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::Matrix") unless isIn("WebGUI::Asset::Wobject::Matrix",@{$newConfig{assets}}); + push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::InOutBoard") unless isIn("WebGUI::Asset::Wobject::InOutBoard",@{$newConfig{assets}}); + push(@{$newConfig{assets}}, "WebGUI::Asset::File::ZipArchive") unless isIn("WebGUI::Asset::File::ZipArchive",@{$newConfig{assets}}); + push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::StockData") unless isIn("WebGUI::Asset::Wobject::StockData",@{$newConfig{assets}}); + push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::WeatherData") unless isIn("WebGUI::Asset::Wobject::WeatherData",@{$newConfig{assets}}); + push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::MultiSearch") unless isIn("WebGUI::Asset::Wobject::MultiSearch",@{$newConfig{assets}}); + $conf->purge; + $conf->set(%newConfig); + $conf->write; } #------------------------------------------------- @@ -830,9 +1564,9 @@ my $template = < STOP # Get Template folder -my $templateFolder = WebGUI::Asset->newByUrl('templates'); +my $folder = WebGUI::Asset->newByUrl('templates') || WebGUI::Asset->getImportNode; # Add Collaboration/RSS folder beneath -my $rssFolder = $templateFolder->addChild({ +my $rssFolder = $folder->addChild({ title=>"Collaboration/RSS", menuTitle=>"Collaboration/RSS", url=>"templates/collaboration/rss", @@ -840,8 +1574,8 @@ my $rssFolder = $templateFolder->addChild({ }); $rssFolder->commit; # Place the Collaboration/RSS folder beneath the -# Collaboration/Thread folder -my $threadFolder = WebGUI::Asset->newByUrl('templates/collaboration/thread'); +# Collaboration/Thread folder if it exists. +my $threadFolder = WebGUI::Asset->newByUrl('templates/collaboration/thread') || WebGUI::Asset->getImportNode; my $threadRank = $threadFolder->getRank; $rssFolder->setRank($threadRank + 1); @@ -864,7 +1598,7 @@ $rssFolder->addChild({ sub addTimeZonesToUserPreferences { print "\tDropping time offsets in favor of time zones.\n" unless ($quiet); WebGUI::SQL->write("delete from userProfileData where fieldName='timeOffset'"); - WebGUI::SQL->write("update userProfileField set dataValues='', fieldName='timeZone', dataType='timeZone', dataDefault=".quote("['America/Chicago']")." where fieldName='timeOffset'"); + WebGUI::SQL->write("update userProfileField set dataValues='', fieldName='timeZone', dataType='timeZone', fieldLabel=".quote('WebGUI::International::get("timezone","DateTime");').",dataDefault=".quote("['America/Chicago']")." where fieldName='timeOffset'"); WebGUI::SQL->write("insert into userProfileData values ('1','timeZone','America/Chicago')"); } diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 77d3584c7..c83a27ffb 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1389,7 +1389,6 @@ sub www_add { $prototypeProperties{$property} = $prototype->get($property); } } - } my %properties = ( %prototypeProperties, diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 114b7400a..01a34ab89 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -12,6 +12,7 @@ package WebGUI::Asset::Shortcut; use strict; use WebGUI::Asset; +use WebGUI::Icon; use WebGUI::International; use WebGUI::Macro; use WebGUI::Privilege; @@ -20,6 +21,148 @@ use WebGUI::SQL; our @ISA = qw(WebGUI::Asset); +#------------------------------------------------------------------- +sub _drawQueryBuilder { + my $self = shift; + # Initialize operators + my @textFields = qw|text yesNo selectList radioList|; + my %operator; + foreach (@textFields) { + $operator{$_} = { + "=" => WebGUI::International::get("is","Asset_Shortcut"), + "!=" => WebGUI::International::get("isnt","Asset_Shortcut") + }; + } + $operator{integer} = { + "=" => WebGUI::International::get("equal to","Asset_Shortcut"), + "!=" => WebGUI::International::get("not equal to","Asset_Shortcut"), + "<" => WebGUI::International::get("less than","Asset_Shortcut"), + ">" => WebGUI::International::get("greater than","Asset_Shortcut") + }; + + # Get the fields and count them + my $fields = $self->getMetaDataFields(); + my $fieldCount = scalar(keys %$fields); + + unless ($fieldCount) { # No fields found.... + return 'No metadata defined yet. + Click here to define metadata attributes.'; + } + + # Static form fields + my $shortcutCriteriaField = WebGUI::Form::textarea({ + name=>"shortcutCriteria", + value=>$self->getValue("shortcutCriteria"), + extras=>'style="width: 100%" '.$self->{_disabled} + }); + my $conjunctionField = WebGUI::Form::selectList({ + name=>"conjunction", + options=>{ + "AND" => WebGUI::International::get("AND","Asset_Shortcut"), + "OR" => WebGUI::International::get("OR","Asset_Shortcut")}, + value=>["OR"], + extras=>'class="qbselect"', + } + ); + + # html + my $output; + $output .= ''; + $output .= ''; + $output .= qq||; + + # Here starts the field loop + my $i = 1; + foreach my $field (keys %$fields) { + my $fieldLabel = $fields->{$field}{fieldName}; + my $fieldType = $fields->{$field}{fieldType} || "text"; + + # The operator select field + my $opFieldName = "op_field".$i; + my $opField = WebGUI::Form::selectList({ + name=>$opFieldName, + uiLevel=>5, + options=>$operator{$fieldType}, + extras=>'class="qbselect"' + }); + # The value select field + my $valFieldName = "val_field".$i; + my $valueField = WebGUI::Form::dynamicField( + fieldType=>$fieldType, + name=>$valFieldName, + uiLevel=>5, + extras=>qq/title="$fields->{$field}{description}" class="qbselect"/, + possibleValues=>$fields->{$field}{possibleValues}, + ); + # An empty row + $output .= qq||; + + # Table row with field info + $output .= qq| + + + + + + + + |; + $i++; + } + # Close the table + $output .= "
$shortcutCriteriaField
$conjunctionField

$fieldLabel

+ $opField + + $valueField + +
"; + + return $output; +} + +#------------------------------------------------------------------- +sub _isUserPref { + my $self = shift; + my $thing = shift; + my $isUserPref = ($session{form}{isUserPref} eq '1'); + return $isUserPref unless $thing; + if ($thing eq 'url') { + return $isUserPref ? ';isUserPref=1' : ''; + } elsif ($thing eq 'titleHeader') { + return $isUserPref ? 'Manage User Preference Fields' : 'Manage Administrative Override Fields'; + } elsif ($thing eq 'name') { + return $isUserPref ? 'User Preference Field' : 'Administrative Override Field'; + } +} + +#------------------------------------------------------------------- +sub _submenu { + my $self = shift; + my $workarea = shift; + my $title = shift; + my $help = shift; + my $ac = WebGUI::AdminConsole->new("shortcutmanager"); + $ac->setHelp($help) if ($help); + $ac->setIcon($self->getIcon); + $ac->addSubmenuItem($self->getUrl('func=edit'), "Back to Edit Shortcut"); + return $ac->render($workarea, $title); +} + +#------------------------------------------------------------------- +sub canEdit { + my $self = shift; +return 1 if ($self->SUPER::canEdit || (ref $self->getParent eq 'WebGUI::Asset::Wobject::Dashboard' && $self->getParent->canManage)); + return 0; +} + +#------------------------------------------------------------------- +sub canManage { + my $self = shift; + return $self->canEdit; +} #------------------------------------------------------------------- sub definition { @@ -36,26 +179,26 @@ sub definition { fieldType=>"hidden", defaultValue=>undef }, - overrideTitle=>{ - fieldType=>"yesNo", - defaultValue=>0 - }, - overrideTemplate=>{ - fieldType=>"yesNo", - defaultValue=>0 - }, - overrideDisplayTitle=>{ - fieldType=>"yesNo", - defaultValue=>0 - }, - overrideDescription=>{ - fieldType=>"yesNo", - defaultValue=>0 - }, - overrideTemplateId=>{ - fieldType=>"template", - defaultValue=>undef - }, +# overrideTitle=>{ +# fieldType=>"yesNo", +# defaultValue=>0 +# }, +# overrideTemplate=>{ +# fieldType=>"yesNo", +# defaultValue=>0 +# }, +# overrideDisplayTitle=>{ +# fieldType=>"yesNo", +# defaultValue=>0 +# }, +# overrideDescription=>{ +# fieldType=>"yesNo", +# defaultValue=>0 +# }, +# overrideTemplateId=>{ +# fieldType=>"template", +# defaultValue=>undef +# }, shortcutByCriteria=>{ fieldType=>"yesNo", defaultValue=>0, @@ -92,55 +235,55 @@ sub getEditForm { my $self = shift; my $tabform = $self->SUPER::getEditForm(); my $originalTemplate; - $tabform->getTab("properties")->HTMLArea( - -value=>$self->getValue("description"), - -label=>WebGUI::International::get(85, 'Asset_Shortcut'), - -hoverHelp=>WebGUI::International::get('85 description', 'Asset_Shortcut'), - -name=>"description" - ); - $tabform->getTab("display")->template( - -value=>$self->getValue("templateId"), - -label=>WebGUI::International::get('shortcut template title', 'Asset_Shortcut'), - -hoverHelp=>WebGUI::International::get('shortcut template title description', 'Asset_Shortcut'), - -namespace=>"Shortcut" - ); - if ($self->getShortcut->get("templateId")) { - $originalTemplate = WebGUI::Asset::Template->new($self->getShortcut->get("templateId")); - $originalTemplate = WebGUI::Asset::Template->new($self->getShortcut->get("collaborationTemplateId")) if (ref $self->getShortcut eq "WebGUI::Asset::Wobject::Collaboration"); - #Shortcuts of Posts and Threads and other assets without a "templateId" - # are going to be ->view'ed by their original parent's settings anyway. - $tabform->getTab("display")->template( - -name=>"overrideTemplateId", - -value=>$self->getValue("overrideTemplateId") || $originalTemplate->getId, - -label=>WebGUI::International::get('override asset template', 'Asset_Shortcut'), - -hoverHelp=>WebGUI::International::get('override asset template description', 'Asset_Shortcut'), - -namespace=>$originalTemplate->get("namespace") - ); - $tabform->getTab("display")->yesNo( - -name=>"overrideTemplate", - -value=>$self->getValue("overrideTemplate"), - -label=>WebGUI::International::get(10,"Asset_Shortcut"), - -hoverHelp=>WebGUI::International::get('10 description',"Asset_Shortcut") - ); - } - $tabform->getTab("properties")->yesNo( - -name=>"overrideTitle", - -value=>$self->getValue("overrideTitle"), - -label=>WebGUI::International::get(7,"Asset_Shortcut"), - -hoverHelp=>WebGUI::International::get('7 description',"Asset_Shortcut") - ); - $tabform->getTab("display")->yesNo( - -name=>"overrideDisplayTitle", - -value=>$self->getValue("overrideDisplayTitle"), - -label=>WebGUI::International::get(8,"Asset_Shortcut"), - -hoverHelp=>WebGUI::International::get('8 description',"Asset_Shortcut") - ); - $tabform->getTab("properties")->yesNo( - -name=>"overrideDescription", - -value=>$self->getValue("overrideDescription"), - -label=>WebGUI::International::get(9,"Asset_Shortcut"), - -hoverHelp=>WebGUI::International::get('9 description',"Asset_Shortcut") - ); +# $tabform->getTab("properties")->HTMLArea( +# -value=>$self->getValue("description"), +# -label=>WebGUI::International::get(85, 'Asset_Shortcut'), +# -hoverHelp=>WebGUI::International::get('85 description', 'Asset_Shortcut'), +# -name=>"description" +# ); +# $tabform->getTab("display")->template( +# -value=>$self->getValue("templateId"), +# -label=>WebGUI::International::get('shortcut template title', 'Asset_Shortcut'), +# -hoverHelp=>WebGUI::International::get('shortcut template title description', 'Asset_Shortcut'), +# -namespace=>"Shortcut" +# ); +# if ($self->getShortcut->get("templateId")) { +# $originalTemplate = WebGUI::Asset::Template->new($self->getShortcut->get("templateId")); +# $originalTemplate = WebGUI::Asset::Template->new($self->getShortcut->get("collaborationTemplateId")) if (ref $self->getShortcut eq "WebGUI::Asset::Wobject::Collaboration"); +# #Shortcuts of Posts and Threads and other assets without a "templateId" +# # are going to be ->view'ed by their original parent's settings anyway. +# $tabform->getTab("display")->template( +# -name=>"overrideTemplateId", +# -value=>$self->getValue("overrideTemplateId") || $originalTemplate->getId, +# -label=>WebGUI::International::get('override asset template', 'Asset_Shortcut'), +# -hoverHelp=>WebGUI::International::get('override asset template description', 'Asset_Shortcut'), +# -namespace=>$originalTemplate->get("namespace") +# ); +# $tabform->getTab("display")->yesNo( +# -name=>"overrideTemplate", +# -value=>$self->getValue("overrideTemplate"), +# -label=>WebGUI::International::get(10,"Asset_Shortcut"), +# -hoverHelp=>WebGUI::International::get('10 description',"Asset_Shortcut") +# ); +# } +# $tabform->getTab("properties")->yesNo( +# -name=>"overrideTitle", +# -value=>$self->getValue("overrideTitle"), +# -label=>WebGUI::International::get(7,"Asset_Shortcut"), +# -hoverHelp=>WebGUI::International::get('7 description',"Asset_Shortcut") +# ); +# $tabform->getTab("display")->yesNo( +# -name=>"overrideDisplayTitle", +# -value=>$self->getValue("overrideDisplayTitle"), +# -label=>WebGUI::International::get(8,"Asset_Shortcut"), +# -hoverHelp=>WebGUI::International::get('8 description',"Asset_Shortcut") +# ); +# $tabform->getTab("properties")->yesNo( +# -name=>"overrideDescription", +# -value=>$self->getValue("overrideDescription"), +# -label=>WebGUI::International::get(9,"Asset_Shortcut"), +# -hoverHelp=>WebGUI::International::get('9 description',"Asset_Shortcut") +# ); $tabform->getTab("properties")->readOnly( -label=>WebGUI::International::get(1,"Asset_Shortcut"), -hoverHelp=>WebGUI::International::get('1 description',"Asset_Shortcut"), @@ -152,7 +295,7 @@ sub getEditForm { -value=>$self->getValue("shortcutByCriteria"), -label=>WebGUI::International::get("Shortcut by alternate criteria","Asset_Shortcut"), -hoverHelp=>WebGUI::International::get("Shortcut by alternate criteria description","Asset_Shortcut"), - -extras=>q|Onchange=" + -extras=>q|onchange=" if (this.form.shortcutByCriteria[0].checked) { this.form.resolveMultiples.disabled=false; this.form.shortcutCriteria.disabled=false; @@ -188,6 +331,8 @@ sub getEditForm { -hoverHelp=>WebGUI::International::get("Criteria description","Asset_Shortcut") ); } + $tabform->addTab('overrides','Custom Fields'); +# $tabform->getTab('overrides'); return $tabform; } @@ -205,6 +350,57 @@ sub getExtraHeadTags { return $self->get("extraHeadTags")."\n".$self->getShortcut->get("extraHeadTags"); } +#------------------------------------------------------------------- +sub getFields { + my $self = shift; + my $fielden = $self->getLineage(["children"],{includeOnlyClasses=>["WebGUI::Asset::Field"],returnObjects=>1}); + #WebGUI::ErrorHandler::warn("There are ".(scalar @$fielden)." fields."); + return $fielden; +} + +#------------------------------------------------------------------- +sub getFieldsList { + my $self = shift; + my $output = 'Add '.$self->_isUserPref('name').'

'; + my @fielden; + if ($self->_isUserPref) { + @fielden = $self->getUserPrefs; + } else { + @fielden = $self->getOverrides; + } + return $output unless scalar @fielden > 0; + $output .= ''; + $output .= ''; + foreach my $field (@fielden) { + $output .= ''; + $output .= ''; + $output .= ''; + $output .= ''; + } + $output .= '
fieldNameEdit/Delete
'.$field->get("fieldName").''; + $output .= WebGUI::Icon::editIcon($field->getUrl('func=edit')); + $output .= WebGUI::Icon::deleteIcon($field->getUrl('func=delete')); + $output .= '
'; + return $output; +} + + +#------------------------------------------------------------------- +sub getOverrides { + my $self = shift; + my $fielden = $self->getFields; + my @overrides; + my $i = 0; + #use Data::Dumper; + #WebGUI::ErrorHandler::warn(Dumper($fielden)); + foreach my $field (@{$fielden}) { + unless ($field->get("isUserPref")) { + @overrides[$i] = $field; + $i++; + } + } + return @overrides; +} #------------------------------------------------------------------- sub getShortcut { @@ -216,11 +412,12 @@ sub getShortcut { $self->{_shortcut} = $self->getShortcutDefault; } } - $self->{_shortcut}{_properties}{templateId} = $self->get("overrideTemplateId") if ($self->get("overrideTemplate")); - $self->{_shortcut}{_properties}{collaborationTemplateId} = $self->get("overrideTemplateId") if ($self->get("overrideTemplate")); - $self->{_shortcut}{_properties}{title} = $self->get("title") if ($self->get("overrideTitle")); - $self->{_shortcut}{_properties}{description} = $self->get("description") if ($self->get("overrideDescription")); - $self->{_shortcut}{_properties}{title} = $self->get("displayTitle") if ($self->get("overrideDisplayTitle")); + $self->{_shortcut}{_properties}{displayTitle} = undef; + # Hide title by default. If you want, you can create an override + # to display it. But it's being shown in the dragheader by default. + foreach my $override ($self->getOverrides) { + $self->{_shortcut}{_properties}{$override->getFieldName} = $override->getFieldValue; + } return $self->{_shortcut}; } @@ -339,6 +536,21 @@ sub getShortcutDefault { return WebGUI::Asset->newByDynamicClass($self->get("shortcutToAssetId")); } +#------------------------------------------------------------------- +sub getUserPrefs { + my $self = shift; + my $fielden = $self->getFields; + my @userPrefs; + my $i = 0; + foreach my $field (@{$fielden}) { + if ($field->get("isUserPref")) { + @userPrefs[$i] = $field; + $i++; + } + } + return @userPrefs; +} + #------------------------------------------------------------------- sub processPropertiesFromFormPost { my $self = shift; @@ -347,172 +559,116 @@ sub processPropertiesFromFormPost { WebGUI::Session::deleteAllScratch($scratchId); } +#------------------------------------------------------------------- + +sub purge { + my $self = shift; + # delete and purge all associated FieldIds and their preferences. + return $self->SUPER::purge; +} + +#------------------------------------------------------------------- + +sub purgeRevision { + my $self = shift; + return $self->SUPER::purgeRevision; +} + #------------------------------------------------------------------- sub view { my $self = shift; my $content; + my $shortcut = $self->getShortcut; if ($self->get("shortcutToAssetId") eq $self->get("parentId")) { $content = "Displaying this shortcut would cause a feedback loop."; } else { - $content = $self->getShortcut->view; + $content = $shortcut->view; } my %var = ( isShortcut => 1, 'shortcut.content' => $content, 'shortcut.label' => WebGUI::International::get('3',"Asset_Shortcut"), - originalURL => $self->getShortcut->getUrl + originalURL => $shortcut->getUrl ); return $self->processTemplate(\%var,$self->getValue("templateId")); } - #------------------------------------------------------------------- sub www_edit { - my $self = shift; - return WebGUI::Privilege::insufficient() unless $self->canEdit; + my $self = shift; + return WebGUI::Privilege::insufficient() unless $self->canEdit; $self->getAdminConsole->setHelp("shortcut add/edit","Asset_Shortcut"); - return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get(2,"Asset_Shortcut")); + $self->getAdminConsole->addSubmenuItem($self->getUrl("func=manageFields;isUserPref=0"),"Manage Shortcut Overrides"); + $self->getAdminConsole->addSubmenuItem($self->getUrl("func=manageFields;isUserPref=1"),"Manage User Preferences"); + return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get(2,"Asset_Shortcut")); } #------------------------------------------------------------------- -sub _drawQueryBuilder { +sub www_getUserPrefsForm { + #This is a form retrieved by "ajax". my $self = shift; - # Initialize operators - my @textFields = qw|text yesNo selectList radioList|; - my %operator; - foreach (@textFields) { - $operator{$_} = { - "=" => WebGUI::International::get("is","Asset_Shortcut"), - "!=" => WebGUI::International::get("isnt","Asset_Shortcut") - }; + return '' unless $self->getParent->canPersonalize; + my @fielden = $self->getUserPrefs; + my $f = WebGUI::HTMLForm->new(extras=>' onSubmit="submitForm(this,\''.'form_'.$self->getId.'\');return false;"'); + $f->hidden( + -name => 'func', + -value => 'saveUserPrefs' + ); + foreach my $field (@fielden) { + my $fieldType = $field->get("fieldType") || "text"; + my $options; + # Add a "Select..." option on top of a select list to prevent from + # saving the value on top of the list when no choice is made. + if($fieldType eq "selectList") { + $options = {"", WebGUI::International::get("Select","Asset")}; + } + $f->dynamicField( + name=>$field->getId, + label=>$field->get("fieldName"), + uiLevel=>5, + value=>$field->getUserPref($field->getId), + extras=>'', + possibleValues=>$field->get("possibleValues"), + options=>$options, + fieldType=>$fieldType + ); } - $operator{integer} = { - "=" => WebGUI::International::get("equal to","Asset_Shortcut"), - "!=" => WebGUI::International::get("not equal to","Asset_Shortcut"), - "<" => WebGUI::International::get("less than","Asset_Shortcut"), - ">" => WebGUI::International::get("greater than","Asset_Shortcut") - }; + $f->submit; + return $f->print; +} - # Get the fields and count them - my $fields = $self->getMetaDataFields(); - my $fieldCount = scalar(keys %$fields); - - unless ($fieldCount) { # No fields found.... - return 'No metadata defined yet. - Click here to define metadata attributes.'; +#------------------------------------------------------------------- +sub www_manageFields { + my $self = shift; + return WebGUI::Privilege::insufficient() unless $self->canEdit; + my $output = $self->getFieldsList; + return $self->_submenu($output,$self->_isUserPref('titleHeader')); +} + +#------------------------------------------------------------------- +sub www_saveUserPrefs { + my $self = shift; + return '' unless $self->getParent->canPersonalize; + my @fellowFields = $self->getUserPrefs; + foreach my $fieldId (keys %{$session{form}}) { + my $field = WebGUI::Asset->newByDynamicClass($fieldId); + next unless $field; + return 0 unless $field->setUserPref($fieldId,$session{form}{$fieldId}); } - - # Static form fields - my $shortcutCriteriaField = WebGUI::Form::textarea({ - name=>"shortcutCriteria", - value=>$self->getValue("shortcutCriteria"), - extras=>'style="width: 100%" '.$self->{_disabled} - }); - my $conjunctionField = WebGUI::Form::selectList({ - name=>"conjunction", - options=>{ - "AND" => WebGUI::International::get("AND","Asset_Shortcut"), - "OR" => WebGUI::International::get("OR","Asset_Shortcut")}, - value=>["OR"], - extras=>'class="qbselect"', - }); - - # html - my $output; - $output .= ''; - $output .= ''; - - $output .= qq| - - - - - - - - - - - - - - - - - - |; - - # Here starts the field loop - my $i = 1; - foreach my $field (keys %$fields) { - my $fieldLabel = $fields->{$field}{fieldName}; - my $fieldType = $fields->{$field}{fieldType} || "text"; - - # The operator select field - my $opFieldName = "op_field".$i; - my $opField = WebGUI::Form::selectList({ - name=>$opFieldName, - uiLevel=>5, - options=>$operator{$fieldType}, - extras=>'class="qbselect"' - }); - # The value select field - my $valFieldName = "val_field".$i; - my $valueField = WebGUI::Form::dynamicField( - fieldType=>$fieldType, - name=>$valFieldName, - uiLevel=>5, - extras=>qq/title="$fields->{$field}{description}" class="qbselect"/, - possibleValues=>$fields->{$field}{possibleValues}, - ); - # An empty row - $output .= qq| - - - - - - - - |; - - # Table row with field info - $output .= qq| - - - - - - - - |; - $i++; - } - # Close the table - $output .= "
$shortcutCriteriaField
-
- $conjunctionField -

$fieldLabel

- $opField - - $valueField - -
"; - - return $output; + return 1; } #------------------------------------------------------------------- sub www_view { my $self = shift; - return $self->getShortcut->www_view; + if (ref($self->getParent) eq 'WebGUI::Asset::Wobject::Dashboard') { + return WebGUI::Privilege::noAccess() unless $self->canView; + $session{asset} = $self->getParent; + return $session{asset}->www_view; + } else { + return $self->getShortcut->www_view; + } } - 1; - - diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index ac1681250..8ab39bd3f 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -84,7 +84,6 @@ sub definition { } - #------------------------------------------------------------------- =head2 getEditForm ()