diff --git a/docs/upgrades/upgrade_6.2.11-6.3.0.pl b/docs/upgrades/upgrade_6.2.11-6.3.0.pl index 199eca486..9e3d65553 100644 --- a/docs/upgrades/upgrade_6.2.11-6.3.0.pl +++ b/docs/upgrades/upgrade_6.2.11-6.3.0.pl @@ -477,7 +477,7 @@ WebGUI::SQL->write("drop table collateral"); print "\tConverting template system to asset tree\n" unless ($quiet); WebGUI::SQL->write("update template set namespace='Layout' where namespace='page'"); WebGUI::SQL->write("alter table template add column assetId varchar(22) not null"); -my $tempRootLineage = sprintf("%018d",($collateralRootLineage+1)); +my $tempRootLineage = getNextLineage('PBasset000000000000002'); my $tempRootId = WebGUI::SQL->setRow("asset","assetId",{ assetId=>"new", isHidden=>1, @@ -689,6 +689,7 @@ $conf->set("assets"=>[ 'WebGUI::Asset::Wobject::HttpProxy', 'WebGUI::Asset::Wobject::SQLReport', 'WebGUI::Asset::Wobject::Survey', + 'WebGUI::Asset::Wobject::Product', 'WebGUI::Asset::Redirect', 'WebGUI::Asset::Template', 'WebGUI::Asset::FilePile', diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index f139bdd7e..aaa15525b 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -3,6 +3,7 @@ assets = WebGUI::Asset::File::Image, \ WebGUI::Asset::Snippet, \ WebGUI::Asset::Redirect, \ WebGUI::Asset::Wobject::USS, \ + WebGUI::Asset::Wobject::Product, \ WebGUI::Asset::Wobject::Poll, \ WebGUI::Asset::Wobject::SyndicatedContent, \ WebGUI::Asset::Wobject::HttpProxy, \ diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 33a62bc8a..4ff4ced97 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1425,9 +1425,7 @@ sub getToolbar { .copyIcon('func=copy',$self->get("url")); # .moveTopIcon('func=moveTop&wid='.${$wobject}{wobjectId}) # .moveBottomIcon('func=moveBottom&wid='.${$wobject}{wobjectId}) - # if (${$wobject}{namespace} ne "WobjectProxy" && isIn("WobjectProxy",@{$session{config}{wobjects}})) { - # $wobjectToolbar .= shortcutIcon('func=createShortcut'); - #} + $toolbar .= shortcutIcon('func=createShortcut') unless ($self->get("className") =~ /Shortcut/); return $toolbar; } @@ -2163,6 +2161,19 @@ sub www_copyList { #------------------------------------------------------------------- +=head2 www_createShortcut () + +=cut + +sub www_createShortcut () { + my $self = shift; + $self->addChild({ + className=>$self->get("className"), + }); +} + +#------------------------------------------------------------------- + =head2 www_cut ( ) Cuts (removes to clipboard) self, returns the www_view of the Parent if canEdit. Otherwise returns AdminConsole rendered insufficient privilege. diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 87a86481b..cde282c1f 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -11,17 +11,11 @@ package WebGUI::Asset::Shortcut; #------------------------------------------------------------------- use strict; -use Tie::CPHash; -use WebGUI::DateTime; -use WebGUI::Icon; +use WebGUI::Asset; use WebGUI::International; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; -use WebGUI::Page; -use WebGUI::TabForm; -use WebGUI::Template; -use WebGUI::MetaData; our @ISA = qw(WebGUI::Asset); @@ -35,7 +29,7 @@ sub definition { className=>'WebGUI::Asset::File', properties=>{ shortcutToAssetId=>{ - fieldType=>"hidden" + fieldType=>"hidden", defaultValue=>undef }, overrideTitle=>{ @@ -76,15 +70,17 @@ sub definition { } + #------------------------------------------------------------------- sub getEditForm { my $self = shift; my $tabform = $self->SUPER::getEditForm(); -# $tabform->getTab("display")->template( -# -name=>"overrideTemplateId", -# -value=>$self->getValue("overrideTemplateId"), -# -namespace=>$self->getShortcut-> -# ); + my $originalTemplate = WebGUI::Asset::Template->new(self->getShortcut->get("templateId")); + $tabform->getTab("display")->template( + -name=>"overrideTemplateId", + -value=>$self->getValue("overrideTemplateId") || $originalTemplate->getId, + -namespace=>$originalTemplate->get("namespace") + ); $tabform->getTab("properties")->yesNo( -name=>"overrideTitle", -value=>$self->getValue("overrideTitle"), @@ -105,19 +101,17 @@ sub getEditForm { -value=>$self->getValue("overrideTemplate"), -label=>WebGUI::International::get(10,"Shortcut") ); - my @data = WebGUI::SQL->quickArray("select page.urlizedTitle,wobject.title from wobject left join page on wobject.pageId=page.pageId - where wobject.wobjectId=".quote($self->get("proxiedWobjectId"))); $tabform->getTab("properties")->readOnly( -label=>WebGUI::International::get(1,"Shortcut"), - -value=>''.$data[1].' ('.$self->get("proxiedWobjectId").')' + -value=>''.$self->getShortcut->get('title').' ('.$self->getShortcut->getId.')' ); if($session{setting}{metaDataEnabled}) { $tabform->getTab("properties")->yesNo( - -name=>"proxyByCriteria", - -value=>$self->getValue("proxyByCriteria"), - -label=>WebGUI::International::get("Proxy by alternate criteria?","Shortcut"), + -name=>"shortcutByCriteria", + -value=>$self->getValue("shortcutByCriteria"), + -label=>WebGUI::International::get("Shortcut by alternate criteria?","Shortcut"), -extras=>q|Onchange=" - if (this.form.proxyByCriteria[0].checked) { + if (this.form.shortcutByCriteria[0].checked) { this.form.resolveMultiples.disabled=false; this.form.proxyCriteria.disabled=false; } else { @@ -125,7 +119,7 @@ sub getEditForm { this.form.proxyCriteria.disabled=true; }"| ); - if ($self->getValue("proxyByCriteria") == 0) { + if ($self->getValue("shortcutByCriteria") == 0) { $self->{_disabled} = 'disabled=true'; } $tabform->getTab("properties")->selectList( @@ -160,8 +154,149 @@ sub getName { return WebGUI::International::get(3,"Shortcut"); } + + #------------------------------------------------------------------- sub getShortcut { + my $self = shift; + unless ($self->{_shortcut}) { + if ($self->get("shortcutByCriteria")) { + $self->{_shortcut} = $self->getShortcutByCriteria; + } else { + $self->{_shortcut} = $self->getShortcutDefault; + } + } + $self->{_shortcut}{_properties}{templateId} = $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")); + return $self->{_shortcut}; +} + +#------------------------------------------------------------------- + +=head2 getShortcutByCriteria ( hashRef ) + +This function will search for a asset that match a metadata criteria set. +If no asset is found, undef will be returned. + +=head3 hashRef + +A typical hashRef for this function will look like: + +{ + proxiedNamespace => "Article", + resolveMultiples => "random", + proxyCriteria => "State = Wisconsin AND Country != Sauk" +} + +Most of the time this will be a: + +WebGUI::SQL->quickHashRef("select * from AssetProxy where assetId=".quote($proxiedId)); + +=cut + +sub getShortcutByCriteria { + my $self = shift; + my $assetProxy = shift; + my $criteria = $self->get("shortcutCriteria"); + my $order = $self->get("resolveMultiples"); + my $assetId = $self->getId; + + # Parse macro's in criteria + $criteria = WebGUI::Macro::process($criteria); + + # Once a asset is found, we will stick to that asset, + # to prevent the proxying of multiple- depth assets like Surveys and USS. + my $scratchId; + if ($assetId) { + $scratchId = "Shortcut_" . $assetId; + if($session{scratch}{$scratchId}) { + return $session{scratch}{$scratchId} unless ($session{var}{adminOn}); + } + } + + # $criteria = "State = Wisconsin AND Country != Sauk"; + # + # State = Wisconsin AND Country != Sauk + # | | | + # |- $field |_ $operator |- $value + # |_ $attribute |_ $attribute + my $operator = qr/<>|!=|=|>=|<=|>|<|like/i; + my $attribute = qr/['"][^()|=>getShortcutDefault->get("className")); + + + # Add constraint only if it has been modified. + $sql .= " and ".$constraint if (($constraint ne $criteria) && $constraint ne ""); + $sql .= " order by w.lastUpdated desc"; + + # Execute the query with an unconditional read + my @ids; + my $sth = WebGUI::SQL->unconditionalRead($sql); + while (my ($data) = $sth->array) { + push (@ids, $data); + } + $sth->finish; + + # No matching assets found. + if (scalar(@ids) == 0) { + return $self->getShortcutDefault; # fall back to the originally mirrored asset. + } + my $id; + # Grab a wid from the results + if ($order eq 'random') { + $id = $ids[ rand @ids ]; + } else { + #default order is mostRecent + $id = $ids[0]; # 1st element in list is most recent. + } + + # Store the matching assetId in user scratch. + WebGUI::Session::setScratch($scratchId,$id) if ($scratchId); + + return WebGUI::Asset->newByDynamicClass($id); +} + +#------------------------------------------------------------------- +sub getShortcutDefault { my $self = shift; return WebGUI::Asset->newByDynamicClass($self->get("shortcutToAssetId")); } @@ -218,9 +353,9 @@ sub _drawQueryBuilder { } # Static form fields - my $proxyCriteriaField = WebGUI::Form::textarea({ - name=>"proxyCriteria", - value=>$_[0]->getValue("proxyCriteria"), + my $shortcutCriteriaField = WebGUI::Form::textarea({ + name=>"shortcutCriteria", + value=>$_[0]->getValue("shortcutCriteria"), extras=>'style="width: 100%" '.$_[0]->{_disabled} }); my $conjunctionField = WebGUI::Form::selectList({ @@ -235,13 +370,13 @@ sub _drawQueryBuilder { # html my $output; $output .= ''; + $session{config}{extrasURL}.'/wobject/Shortcut/querybuilder.js">'; $output .= ''; + '/wobject/Shortcut/querybuilder.css" type="text/css" rel="stylesheet">'; $output .= qq| - + @@ -326,126 +461,4 @@ sub www_view { 1; -#------------------------------------------------------------------- - -=head2 getAssetByCriteria ( hashRef ) - -This function will search for a asset that match a metadata criteria set. -If no asset is found, undef will be returned. - -=head3 hashRef - -A typical hashRef for this function will look like: - -{ - proxiedNamespace => "Article", - resolveMultiples => "random", - proxyCriteria => "State = Wisconsin AND Country != Sauk" -} - -Most of the time this will be a: - -WebGUI::SQL->quickHashRef("select * from AssetProxy where assetId=".quote($proxiedId)); - -=cut - -sub getAssetByCriteria { - my $assetProxy = shift; - my $criteria = $assetProxy->{proxyCriteria}; - my $order = $assetProxy->{resolveMultiples}; - my $namespace = $assetProxy->{proxiedNamespace}; - my $assetId = $assetProxy->{assetId}; - - # Parse macro's in criteria - $criteria = WebGUI::Macro::process($criteria); - - # Once a asset is found, we will stick to that asset, - # to prevent the proxying of multiple- depth assets like Surveys and USS. - my $scratchId; - if ($assetId) { - $scratchId = "AssetProxy_" . $assetId; - if($session{scratch}{$scratchId}) { - return $session{scratch}{$scratchId} unless ($session{var}{adminOn}); - } - } - - # $criteria = "State = Wisconsin AND Country != Sauk"; - # - # State = Wisconsin AND Country != Sauk - # | | | - # |- $field |_ $operator |- $value - # |_ $attribute |_ $attribute - my $operator = qr/<>|!=|=|>=|<=|>|<|like/i; - my $attribute = qr/['"][^()|=>unconditionalRead($sql); - while (my ($data) = $sth->array) { - push (@wids, $data); - } - $sth->finish; - - # No matching assets found. - if (scalar(@wids) == 0) { - return undef; # fall back to the originally mirrored asset. - } - my $wid; - # Grab a wid from the results - if ($order eq 'random') { - $wid = $wids[ rand @wids ]; - } else { - #default order is mostRecent - $wid = $wids[0]; # 1st element in list is most recent. - } - - # Store the matching assetId in user scratch. - WebGUI::Session::setScratch($scratchId,$wid) if ($scratchId); - - return $wid; -} - diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 40d9c99a3..a8e71bae9 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -16,6 +16,7 @@ package WebGUI::Asset::Snippet; use strict; use WebGUI::Asset; +use WebGUI::Asset::Template; use WebGUI::Macro; use WebGUI::Session; @@ -134,7 +135,7 @@ sub view { my $output = WebGUI::Macro::process($self->get("snippet")); # if it's a javascript file this would break it # $output = '

'.$self->getToolbar.'

'.$output if ($session{var}{adminOn}); - return $output; + return WebGUI::Asset::Template->processRaw($output); } #------------------------------------------------------------------- diff --git a/www/extras/wobject/WobjectProxy/hline.gif b/www/extras/wobject/Shortcut/hline.gif similarity index 100% rename from www/extras/wobject/WobjectProxy/hline.gif rename to www/extras/wobject/Shortcut/hline.gif diff --git a/www/extras/wobject/WobjectProxy/querybuilder.css b/www/extras/wobject/Shortcut/querybuilder.css similarity index 100% rename from www/extras/wobject/WobjectProxy/querybuilder.css rename to www/extras/wobject/Shortcut/querybuilder.css diff --git a/www/extras/wobject/WobjectProxy/querybuilder.js b/www/extras/wobject/Shortcut/querybuilder.js similarity index 100% rename from www/extras/wobject/WobjectProxy/querybuilder.js rename to www/extras/wobject/Shortcut/querybuilder.js diff --git a/www/extras/wobject/WobjectProxy/vline.gif b/www/extras/wobject/Shortcut/vline.gif similarity index 100% rename from www/extras/wobject/WobjectProxy/vline.gif rename to www/extras/wobject/Shortcut/vline.gif
$proxyCriteriaField$shortcutCriteriaField