updating skeletons. run through perltidy. added note about Installable aspect. removed old install routines
This commit is contained in:
parent
af01175192
commit
815134dca1
2 changed files with 155 additions and 264 deletions
|
|
@ -18,6 +18,10 @@ use WebGUI::International;
|
|||
use WebGUI::Utility;
|
||||
use base 'WebGUI::Asset::Wobject';
|
||||
|
||||
# To get an installer for your wobject, add the Installable AssetAspect
|
||||
# See WebGUI::AssetAspect::Installable and sbin/installClass.pl for more
|
||||
# details
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 definition ( )
|
||||
|
|
@ -29,46 +33,44 @@ getEditForm method is unnecessary/redundant/useless.
|
|||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new($session, 'Asset_NewWobject');
|
||||
my %properties;
|
||||
tie %properties, 'Tie::IxHash';
|
||||
%properties = (
|
||||
templateId =>{
|
||||
|
||||
#See the list of field/control types in /lib/WebGUI/Form/
|
||||
fieldType=>"template",
|
||||
|
||||
defaultValue=>'NewWobjectTmpl00000001',
|
||||
tab=>"display",
|
||||
|
||||
#www_editSave will ignore anyone's attempts to update this field if this is set to 1
|
||||
noFormPost=>0,
|
||||
|
||||
#This is an option specific to the template fieldType.
|
||||
namespace=>"NewWobject",
|
||||
|
||||
#This is what will appear when the user hovers the mouse over the label
|
||||
# of your form field.
|
||||
hoverHelp=>$i18n->get('templateId label description'),
|
||||
|
||||
# This is the text that will appear to the left of your form field.
|
||||
label=>$i18n->get('templateId label'),
|
||||
}
|
||||
);
|
||||
push(@{$definition}, {
|
||||
assetName=>$i18n->get('assetName'),
|
||||
icon=>'newWobject.gif',
|
||||
autoGenerateForms=>1,
|
||||
tableName=>'NewWobject',
|
||||
className=>'WebGUI::Asset::Wobject::NewWobject',
|
||||
properties=>\%properties
|
||||
});
|
||||
return $class->SUPER::definition($session, $definition);
|
||||
}
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new( $session, 'Asset_NewWobject' );
|
||||
my %properties;
|
||||
tie my %properties, 'Tie::IxHash', (
|
||||
templateId => {
|
||||
|
||||
#See the list of field/control types in /lib/WebGUI/Form/
|
||||
fieldType => "template",
|
||||
|
||||
defaultValue => 'NewWobjectTmpl00000001',
|
||||
tab => "display",
|
||||
|
||||
#www_editSave will ignore anyone's attempts to update this field if this is set to 1
|
||||
noFormPost => 0,
|
||||
|
||||
#This is an option specific to the template fieldType.
|
||||
namespace => "NewWobject",
|
||||
|
||||
#This is what will appear when the user hovers the mouse over the label
|
||||
# of your form field.
|
||||
hoverHelp => $i18n->get('templateId label description'),
|
||||
|
||||
# This is the text that will appear to the left of your form field.
|
||||
label => $i18n->get('templateId label'),
|
||||
}
|
||||
);
|
||||
push @{$definition}, {
|
||||
assetName => $i18n->get('assetName'),
|
||||
icon => 'newWobject.gif',
|
||||
autoGenerateForms => 1,
|
||||
tableName => 'NewWobject',
|
||||
className => 'WebGUI::Asset::Wobject::NewWobject',
|
||||
properties => \%properties
|
||||
};
|
||||
return $class->SUPER::definition( $session, $definition );
|
||||
} ## end sub definition
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -81,9 +83,9 @@ wobject instances, you will need to duplicate them here.
|
|||
=cut
|
||||
|
||||
sub duplicate {
|
||||
my $self = shift;
|
||||
my $newAsset = $self->SUPER::duplicate(@_);
|
||||
return $newAsset;
|
||||
my $self = shift;
|
||||
my $newAsset = $self->SUPER::duplicate(@_);
|
||||
return $newAsset;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -96,16 +98,16 @@ This method is optional if you set autoGenerateForms=1 in the definition.
|
|||
=cut
|
||||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm();
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm();
|
||||
|
||||
$tabform->getTab("display")->template(
|
||||
-value=>$self->getValue("templateId"),
|
||||
-label=>WebGUI::International::get("template_label","Asset_NewWobject"),
|
||||
-namespace=>"NewWobject"
|
||||
);
|
||||
|
||||
return $tabform;
|
||||
$tabform->getTab("display")->template(
|
||||
value => $self->getValue("templateId"),
|
||||
label => WebGUI::International::get( "template_label", "Asset_NewWobject" ),
|
||||
namespace => "NewWobject"
|
||||
);
|
||||
|
||||
return $tabform;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -117,14 +119,13 @@ See WebGUI::Asset::prepareView() for details.
|
|||
=cut
|
||||
|
||||
sub prepareView {
|
||||
my $self = shift;
|
||||
$self->SUPER::prepareView();
|
||||
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
|
||||
$template->prepare;
|
||||
$self->{_viewTemplate} = $template;
|
||||
my $self = shift;
|
||||
$self->SUPER::prepareView();
|
||||
my $template = WebGUI::Asset::Template->new( $self->session, $self->get("templateId") );
|
||||
$template->prepare;
|
||||
$self->{_viewTemplate} = $template;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 purge ( )
|
||||
|
|
@ -137,10 +138,11 @@ wobject instances, you will need to purge them here.
|
|||
=cut
|
||||
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
#purge your wobject-specific data here. This does not include fields
|
||||
# you create for your NewWobject asset/wobject table.
|
||||
return $self->SUPER::purge;
|
||||
my $self = shift;
|
||||
|
||||
#purge your wobject-specific data here. This does not include fields
|
||||
# you create for your NewWobject asset/wobject table.
|
||||
return $self->SUPER::purge;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -153,16 +155,16 @@ to be displayed within the page style.
|
|||
=cut
|
||||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
#This automatically creates template variables for all of your wobject's properties.
|
||||
my $var = $self->get;
|
||||
|
||||
#This is an example of debugging code to help you diagnose problems.
|
||||
#WebGUI::ErrorHandler::warn($self->get("templateId"));
|
||||
|
||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||
#This automatically creates template variables for all of your wobject's properties.
|
||||
my $var = $self->get;
|
||||
|
||||
#This is an example of debugging code to help you diagnose problems.
|
||||
#$session->log->warn($self->get("templateId"));
|
||||
|
||||
return $self->processTemplate( $var, undef, $self->{_viewTemplate} );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -183,60 +185,6 @@ adminConsole views.
|
|||
# return $self->getAdminConsole->render($self->getEditForm->print, $i18n->get("edit title"));
|
||||
#}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Everything below here is to make it easier to install your custom
|
||||
# wobject, but has nothing to do with wobjects in general
|
||||
#-------------------------------------------------------------------
|
||||
# cd /data/WebGUI/lib
|
||||
# perl -MWebGUI::Asset::Wobject::NewWobject -e install www.example.com.conf [ /path/to/WebGUI ]
|
||||
# - or -
|
||||
# perl -MWebGUI::Asset::Wobject::NewWobject -e uninstall www.example.com.conf [ /path/to/WebGUI ]
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
||||
use base 'Exporter';
|
||||
our @EXPORT = qw(install uninstall);
|
||||
use WebGUI::Session;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub install {
|
||||
my $config = $ARGV[0];
|
||||
my $home = $ARGV[1] || "/data/WebGUI";
|
||||
die "usage: perl -MWebGUI::Asset::Wobject::NewWobject -e install www.example.com.conf\n" unless ($home && $config);
|
||||
print "Installing asset.\n";
|
||||
my $session = WebGUI::Session->open($home, $config);
|
||||
$session->config->addToArray("assets","WebGUI::Asset::Wobject::NewWobject");
|
||||
$session->db->write("create table NewWobject (
|
||||
assetId varchar(22) binary not null,
|
||||
revisionDate bigint not null,
|
||||
primary key (assetId, revisionDate)
|
||||
)");
|
||||
$session->var->end;
|
||||
$session->close;
|
||||
print "Done. Please restart Apache.\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub uninstall {
|
||||
my $config = $ARGV[0];
|
||||
my $home = $ARGV[1] || "/data/WebGUI";
|
||||
die "usage: perl -MWebGUI::Asset::Wobject::NewWobject -e uninstall www.example.com.conf\n" unless ($home && $config);
|
||||
print "Uninstalling asset.\n";
|
||||
my $session = WebGUI::Session->open($home, $config);
|
||||
$session->config->deleteFromArray("assets","WebGUI::Asset::Wobject::NewWobject");
|
||||
my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::Wobject::NewWobject'");
|
||||
while (my ($id) = $rs->array) {
|
||||
my $asset = WebGUI::Asset->new($session, $id, "WebGUI::Asset::Wobject::NewWobject");
|
||||
$asset->purge if defined $asset;
|
||||
}
|
||||
$session->db->write("drop table NewWobject");
|
||||
$session->var->end;
|
||||
$session->close;
|
||||
print "Done. Please restart Apache.\n";
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ use Tie::IxHash;
|
|||
use base 'WebGUI::Asset';
|
||||
use WebGUI::Utility;
|
||||
|
||||
|
||||
# To get an installer for your wobject, add the Installable AssetAspect
|
||||
# See WebGUI::AssetAspect::Installable and sbin/installClass.pl for more
|
||||
# details
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -40,21 +42,19 @@ These methods are available from this class:
|
|||
|
||||
=cut
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addRevision
|
||||
|
||||
This method exists for demonstration purposes only. The superclass
|
||||
handles revisions to NewAsset Assets.
|
||||
This method exists for demonstration purposes only. The superclass
|
||||
handles revisions to NewAsset Assets.
|
||||
|
||||
=cut
|
||||
|
||||
sub addRevision {
|
||||
my $self = shift;
|
||||
my $newSelf = $self->SUPER::addRevision(@_);
|
||||
return $newSelf;
|
||||
my $self = shift;
|
||||
my $newSelf = $self->SUPER::addRevision(@_);
|
||||
return $newSelf;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -73,66 +73,68 @@ A hash reference passed in from a subclass definition.
|
|||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my %properties;
|
||||
tie %properties, 'Tie::IxHash';
|
||||
my $i18n = WebGUI::International->new($session, "Asset_NewAsset");
|
||||
%properties = (
|
||||
templateId => {
|
||||
# Determines which tab this property appears in
|
||||
tab=>"display",
|
||||
#See the list of field/control types in /lib/WebGUI/Form/
|
||||
fieldType=>"template",
|
||||
defaultValue=>'NewAssetTmpl0000000001',
|
||||
#www_editSave will ignore anyone's attempts to update this field if this is set to 1
|
||||
noFormPost=>0,
|
||||
#This is an option specific to the template fieldType.
|
||||
namespace=>"NewAsset",
|
||||
#This is what will appear when the user hovers the mouse over the label
|
||||
# of your form field.
|
||||
hoverHelp=>$i18n->get('templateId label description'),
|
||||
# This is the text that will appear to the left of your form field.
|
||||
label=>$i18n->get('templateId label')
|
||||
},
|
||||
foo => {
|
||||
tab=>"properties",
|
||||
fieldType=>"text",
|
||||
defaultValue=>undef,
|
||||
label=>$i18n->get("foo label"),
|
||||
hoverHelp=>$i18n->get("foo label help")
|
||||
}
|
||||
);
|
||||
push(@{$definition}, {
|
||||
assetName=>$i18n->get('assetName'),
|
||||
icon=>'NewAsset.gif',
|
||||
autoGenerateForms=>1,
|
||||
tableName=>'NewAsset',
|
||||
className=>'WebGUI::Asset::NewAsset',
|
||||
properties=>\%properties
|
||||
});
|
||||
return $class->SUPER::definition($session, $definition);
|
||||
}
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new( $session, "Asset_NewAsset" );
|
||||
tie my %properties, 'Tie::IxHash', (
|
||||
templateId => {
|
||||
|
||||
# Determines which tab this property appears in
|
||||
tab => "display",
|
||||
|
||||
#See the list of field/control types in /lib/WebGUI/Form/
|
||||
fieldType => "template",
|
||||
defaultValue => 'NewAssetTmpl0000000001',
|
||||
|
||||
#www_editSave will ignore anyone's attempts to update this field if this is set to 1
|
||||
noFormPost => 0,
|
||||
|
||||
#This is an option specific to the template fieldType.
|
||||
namespace => "NewAsset",
|
||||
|
||||
#This is what will appear when the user hovers the mouse over the label
|
||||
# of your form field.
|
||||
hoverHelp => $i18n->get('templateId label description'),
|
||||
|
||||
# This is the text that will appear to the left of your form field.
|
||||
label => $i18n->get('templateId label')
|
||||
},
|
||||
foo => {
|
||||
tab => "properties",
|
||||
fieldType => "text",
|
||||
defaultValue => undef,
|
||||
label => $i18n->get("foo label"),
|
||||
hoverHelp => $i18n->get("foo label help")
|
||||
},
|
||||
);
|
||||
push @{$definition}, {
|
||||
assetName => $i18n->get('assetName'),
|
||||
icon => 'NewAsset.gif',
|
||||
autoGenerateForms => 1,
|
||||
tableName => 'NewAsset',
|
||||
className => 'WebGUI::Asset::NewAsset',
|
||||
properties => \%properties,
|
||||
};
|
||||
return $class->SUPER::definition( $session, $definition );
|
||||
} ## end sub definition
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 duplicate
|
||||
|
||||
This method exists for demonstration purposes only. The superclass
|
||||
handles duplicating NewAsset Assets. This method will be called
|
||||
whenever a copy action is executed
|
||||
This method exists for demonstration purposes only. The superclass
|
||||
handles duplicating NewAsset Assets. This method will be called
|
||||
whenever a copy action is executed
|
||||
|
||||
=cut
|
||||
|
||||
sub duplicate {
|
||||
my $self = shift;
|
||||
my $newAsset = $self->SUPER::duplicate(@_);
|
||||
return $newAsset;
|
||||
my $self = shift;
|
||||
my $newAsset = $self->SUPER::duplicate(@_);
|
||||
return $newAsset;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 indexContent ( )
|
||||
|
|
@ -142,12 +144,11 @@ Making private. See WebGUI::Asset::indexContent() for additonal details.
|
|||
=cut
|
||||
|
||||
sub indexContent {
|
||||
my $self = shift;
|
||||
my $indexer = $self->SUPER::indexContent;
|
||||
$indexer->setIsPublic(0);
|
||||
my $self = shift;
|
||||
my $indexer = $self->SUPER::indexContent;
|
||||
$indexer->setIsPublic(0);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 prepareView ( )
|
||||
|
|
@ -157,14 +158,13 @@ See WebGUI::Asset::prepareView() for details.
|
|||
=cut
|
||||
|
||||
sub prepareView {
|
||||
my $self = shift;
|
||||
$self->SUPER::prepareView();
|
||||
my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId"));
|
||||
$template->prepare;
|
||||
$self->{_viewTemplate} = $template;
|
||||
my $self = shift;
|
||||
$self->SUPER::prepareView();
|
||||
my $template = WebGUI::Asset::Template->new( $self->session, $self->get("templateId") );
|
||||
$template->prepare;
|
||||
$self->{_viewTemplate} = $template;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 processPropertiesFromFormPost ( )
|
||||
|
|
@ -176,11 +176,10 @@ when /yourAssetUrl?func=editSave is requested/posted.
|
|||
=cut
|
||||
|
||||
sub processPropertiesFromFormPost {
|
||||
my $self = shift;
|
||||
$self->SUPER::processPropertiesFromFormPost;
|
||||
my $self = shift;
|
||||
$self->SUPER::processPropertiesFromFormPost;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 purge ( )
|
||||
|
|
@ -194,8 +193,8 @@ asset instances, you will need to purge them here.
|
|||
=cut
|
||||
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
return $self->SUPER::purge;
|
||||
my $self = shift;
|
||||
return $self->SUPER::purge;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -207,8 +206,8 @@ This method is called when data is purged by the system.
|
|||
=cut
|
||||
|
||||
sub purgeRevision {
|
||||
my $self = shift;
|
||||
return $self->SUPER::purgeRevision;
|
||||
my $self = shift;
|
||||
return $self->SUPER::purgeRevision;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -220,13 +219,12 @@ method called by the container www_view method.
|
|||
=cut
|
||||
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my $var = $self->get; # $var is a hash reference.
|
||||
$var->{controls} = $self->getToolbar;
|
||||
return $self->processTemplate($var,undef, $self->{_viewTemplate});
|
||||
my $self = shift;
|
||||
my $var = $self->get; # $var is a hash reference.
|
||||
$var->{controls} = $self->getToolbar;
|
||||
return $self->processTemplate( $var, undef, $self->{_viewTemplate} );
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_edit ( )
|
||||
|
|
@ -238,69 +236,14 @@ the module.
|
|||
=cut
|
||||
|
||||
sub www_edit {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
return $session->privilege->insufficient() unless $self->canEdit;
|
||||
return $session->privilege->locked() unless $self->canEditIfLocked;
|
||||
my $i18n = WebGUI::International->new($session, 'Asset_NewAsset');
|
||||
return $self->getAdminConsole->render($self->getEditForm->print, $i18n->get('edit asset'));
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
return $session->privilege->insufficient() unless $self->canEdit;
|
||||
return $session->privilege->locked() unless $self->canEditIfLocked;
|
||||
my $i18n = WebGUI::International->new( $session, 'Asset_NewAsset' );
|
||||
return $self->getAdminConsole->render( $self->getEditForm->print, $i18n->get('edit asset') );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# Everything below here is to make it easier to install your custom
|
||||
# asset, but has nothing to do with assets in general
|
||||
#-------------------------------------------------------------------
|
||||
# cd /data/WebGUI/lib
|
||||
# perl -MWebGUI::Asset::NewAsset -e install www.example.com.conf [ /path/to/WebGUI ]
|
||||
# - or -
|
||||
# perl -MWebGUI::Asset::NewAsset -e uninstall www.example.com.conf [ /path/to/WebGUI ]
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
||||
use base 'Exporter';
|
||||
our @EXPORT = qw(install uninstall);
|
||||
use WebGUI::Session;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
sub install {
|
||||
my $config = $ARGV[0];
|
||||
my $home = $ARGV[1] || "/data/WebGUI";
|
||||
die "usage: perl -MWebGUI::Asset::NewAsset -e install www.example.com.conf\n" unless ($home && $config);
|
||||
print "Installing asset.\n";
|
||||
my $session = WebGUI::Session->open($home, $config);
|
||||
$session->config->addToArray("assets","WebGUI::Asset::NewAsset");
|
||||
$session->db->write("create table NewAsset (
|
||||
assetId varchar(22) binary not null,
|
||||
revisionDate bigint not null,
|
||||
primary key (assetId, revisionDate)
|
||||
)");
|
||||
$session->var->end;
|
||||
$session->close;
|
||||
print "Done. Please restart Apache.\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
sub uninstall {
|
||||
my $config = $ARGV[0];
|
||||
my $home = $ARGV[1] || "/data/WebGUI";
|
||||
die "usage: perl -MWebGUI::Asset::NewAsset -e uninstall www.example.com.conf\n" unless ($home && $config);
|
||||
print "Uninstalling asset.\n";
|
||||
my $session = WebGUI::Session->open($home, $config);
|
||||
$session->config->deleteFromArray("assets","WebGUI::Asset::NewAsset");
|
||||
my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::NewAsset'");
|
||||
while (my ($id) = $rs->array) {
|
||||
my $asset = WebGUI::Asset->new($session, $id, "WebGUI::Asset::NewAsset");
|
||||
$asset->purge if defined $asset;
|
||||
}
|
||||
$session->db->write("drop table NewAsset");
|
||||
$session->var->end;
|
||||
$session->close;
|
||||
print "Done. Please restart Apache.\n";
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue