added snippet and added getToolbar method to asset superclass

This commit is contained in:
JT Smith 2004-12-29 15:53:52 +00:00
parent 1c409def1f
commit a215ed8c7c
8 changed files with 204 additions and 29 deletions

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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);

View file

@ -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"));

161
lib/WebGUI/Asset/Snippet.pm Normal file
View file

@ -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 = '<p>'.$self->getToolbar.'</p>'.$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;

View file

@ -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}

View file

@ -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 )