From a215ed8c7cd0abfc24a541ed8791d016b53c5489 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 29 Dec 2004 15:53:52 +0000 Subject: [PATCH] added snippet and added getToolbar method to asset superclass --- docs/upgrades/upgrade_6.2.9-6.3.0.pl | 3 +- docs/upgrades/upgrade_6.2.9-6.3.0.sql | 5 + lib/WebGUI/Asset.pm | 16 +++ lib/WebGUI/Asset/File.pm | 9 +- lib/WebGUI/Asset/File/Image.pm | 7 -- lib/WebGUI/Asset/Snippet.pm | 161 ++++++++++++++++++++++++++ lib/WebGUI/Asset/Wobject.pm | 14 +-- lib/WebGUI/FormProcessor.pm | 18 +++ 8 files changed, 204 insertions(+), 29 deletions(-) create mode 100644 lib/WebGUI/Asset/Snippet.pm diff --git a/docs/upgrades/upgrade_6.2.9-6.3.0.pl b/docs/upgrades/upgrade_6.2.9-6.3.0.pl index a66edf21a..267ac7e82 100644 --- a/docs/upgrades/upgrade_6.2.9-6.3.0.pl +++ b/docs/upgrades/upgrade_6.2.9-6.3.0.pl @@ -343,7 +343,8 @@ $conf->set("assets"=>[ 'WebGUI::Asset::Redirect', 'WebGUI::Asset::FilePile', 'WebGUI::Asset::File', - 'WebGUI::Asset::File::Image' + 'WebGUI::Asset::File::Image', + 'WebGUI::Asset::Snippet' ]); $conf->write; diff --git a/docs/upgrades/upgrade_6.2.9-6.3.0.sql b/docs/upgrades/upgrade_6.2.9-6.3.0.sql index 56d522322..ff8ef09c6 100644 --- a/docs/upgrades/upgrade_6.2.9-6.3.0.sql +++ b/docs/upgrades/upgrade_6.2.9-6.3.0.sql @@ -83,6 +83,11 @@ create table redirect ( redirectUrl text ); +create table snippet ( + assetId varchar(22) not null primary key, + snippet mediumtext +); + create table layout ( assetId varchar(22) not null primary key, contentPositions text diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index ef568ea6b..821285a4c 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -546,6 +546,22 @@ sub getRank { return $rank; } +sub getToolbar { + my $self = shift; + my $toolbar = deleteIcon('func=delete',$self->get("url"),WebGUI::International::get(43)) + .editIcon('func=edit',$self->get("url")) + .moveUpIcon('func=promote',$self->get("url")) + .moveDownIcon('func=demote',$self->get("url")) + .cutIcon('func=cut',$self->get("url")) + .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'); + #} + return $toolbar; +} + sub getUiLevel { my $self = shift; return 0; diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index a2fdf0d48..6cc79e68b 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -17,7 +17,6 @@ package WebGUI::Asset::File; use strict; use WebGUI::Asset; use WebGUI::HTTP; -use WebGUI::Icon; use WebGUI::Session; use WebGUI::Storage; use WebGUI::Template; @@ -190,14 +189,8 @@ sub purge { sub view { my $self = shift; my $storage = WebGUI::Storage->get($self->get("storageId")); - my $toolbar = deleteIcon('func=delete',$self->get("url"),WebGUI::International::get(43)) - .editIcon('func=edit',$self->get("url")) - .moveUpIcon('func=promote',$self->get("url")) - .moveDownIcon('func=demote',$self->get("url")) - .cutIcon('func=cut',$self->get("url")) - .copyIcon('func=copy',$self->get("url")); my %var = %{$self->get}; - $var{controls} = $toolbar; + $var{controls} = $self->getToolbar; $var{fileUrl} = $storage->getUrl($self->get("filename")); $var{fileIcon} = $storage->getFileIconUrl($self->get("filename")); return WebGUI::Template::process("1","FileAsset",\%var); diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index d30e48b67..f560d9dd9 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -17,7 +17,6 @@ package WebGUI::Asset::File::Image; use strict; use WebGUI::Asset::File; use WebGUI::HTTP; -use WebGUI::Icon; use WebGUI::Session; use WebGUI::Storage; use WebGUI::Utility; @@ -198,12 +197,6 @@ sub processPropertiesFromFormPost { sub view { my $self = shift; my $storage = WebGUI::Storage->get($self->get("storageId")); - my $toolbar = deleteIcon('func=delete',$self->get("url"),WebGUI::International::get(43)) - .editIcon('func=edit',$self->get("url")) - .moveUpIcon('func=promote',$self->get("url")) - .moveDownIcon('func=demote',$self->get("url")) - .cutIcon('func=cut',$self->get("url")) - .copyIcon('func=copy',$self->get("url")); my %var = %{$self->get}; $var{controls} = $toolbar; $var{fileUrl} = $storage->getUrl($self->get("filename")); diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm new file mode 100644 index 000000000..b65aa1a9e --- /dev/null +++ b/lib/WebGUI/Asset/Snippet.pm @@ -0,0 +1,161 @@ +package WebGUI::Asset::Snippet; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2004 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use WebGUI::Asset; +use WebGUI::Macro; +use WebGUI::Session; + +our @ISA = qw(WebGUI::Asset); + + +=head1 NAME + +Package WebGUI::Asset::Snippet + +=head1 DESCRIPTION + +Provides a mechanism to publish arbitrary code snippets to WebGUI for reuse in other pages. Can be used for things like HTML segments, javascript, and cascading style sheets. + +=head1 SYNOPSIS + +use WebGUI::Asset::Snippet; + + +=head1 METHODS + +These methods are available from this class: + +=cut + + + +#------------------------------------------------------------------- + +=head2 definition ( definition ) + +Defines the properties of this asset. + +=head3 definition + +A hash reference passed in from a subclass definition. + +=cut + +sub definition { + my $class = shift; + my $definition = shift; + push(@{$definition}, { + tableName=>'snippet', + className=>'WebGUI::Asset::Snippet', + properties=>{ + snippet=>{ + fieldType=>'codearea', + defaultValue=>undef + } + } + }); + return $class->SUPER::definition($definition); +} + + + +#------------------------------------------------------------------- + +=head2 getEditForm () + +Returns the TabForm object that will be used in generating the edit page for this asset. + +=cut + +sub getEditForm { + my $self = shift; + my $tabform = $self->SUPER::getEditForm(); + $tabform->getTab("properties")->codearea( + -name=>"snippet", + -label=>"Snippet", + -value=>$self->getValue("snippet") + ); + return $tabform; +} + + +#------------------------------------------------------------------- +sub getIcon { + my $self = shift; + my $small = shift; + return $session{config}{extrasURL}.'/assets/small/snippet.gif' if ($small); + return $session{config}{extrasURL}.'/assets/snippet.gif'; +} + + +#------------------------------------------------------------------- + +=head2 getUiLevel () + +Returns the UI level of this asset. + +=cut + +sub getUiLevel { + return 5; +} + +#------------------------------------------------------------------- + +=head2 getName + +Returns the displayable name of this asset. + +=cut + +sub getName { + return "Snippet"; +} + + +#------------------------------------------------------------------- +sub view { + my $self = shift; + 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; +} + +#------------------------------------------------------------------- +sub www_edit { + my $self = shift; + return WebGUI::Privilege::insufficient() unless $self->canEdit; + return $self->getAdminConsole->render($self->getEditForm->print,"Edit Snippet"); +} + +#------------------------------------------------------------------- + +=head2 www_view + +A web accessible version of the view method. + +=cut + +sub www_view { + my $self = shift; + return $self->view; +} + + +1; + diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 1f52f2ec5..8fa2cb493 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -25,7 +25,6 @@ use WebGUI::FormProcessor; use WebGUI::Grouping; use WebGUI::HTML; use WebGUI::HTMLForm; -use WebGUI::Icon; use WebGUI::Id; use WebGUI::International; use WebGUI::Macro; @@ -296,18 +295,7 @@ sub processTemplate { foreach my $field (keys %$meta) { $var->{$meta->{$field}{fieldName}} = $meta->{$field}{value}; } - my $wobjectToolbar = deleteIcon('func=delete',$self->get("url"),WebGUI::International::get(43)) - .editIcon('func=edit',$self->get("url")) - .moveUpIcon('func=promote',$self->get("url")) - .moveDownIcon('func=demote',$self->get("url")) - .cutIcon('func=cut',$self->get("url")) - .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'); - #} - $var->{'controls'} = $wobjectToolbar; + $var->{'controls'} = $self->getToolbar; my %vars = ( %{$self->{_properties}}, %{$var} diff --git a/lib/WebGUI/FormProcessor.pm b/lib/WebGUI/FormProcessor.pm index c503c777b..67d7931a0 100644 --- a/lib/WebGUI/FormProcessor.pm +++ b/lib/WebGUI/FormProcessor.pm @@ -34,6 +34,7 @@ This package helps in the processing of the form variables that are returned fro $value = WebGUI::FormProcessor::checkbox("whichOne"); $value = WebGUI::FormProcessor::checkList("dayOfWeek"); + $value = WebGUI::FormProcessor::codearea("snippet"); $value = WebGUI::FormProcessor::combo("fruit"); $value = WebGUI::FormProcessor::contentType("text"); $value = WebGUI::FormProcessor::date("endDate"); @@ -105,6 +106,23 @@ sub checkList { } +#------------------------------------------------------------------- + +=head2 codearea ( name ) + +Returns a string. + +=head3 name + +The name of the form variable to retrieve. + +=cut + +sub codearea { + return $session{form}{$_[0]}; +} + + #------------------------------------------------------------------- =head2 combo ( name )