[OGDev] Category Dropdown Selection
Christopher Schmidt
crschmidt at crschmidt.net
Fri Apr 7 17:01:08 BST 2006
Boston uses a dropdown to allow you to select from existing
categories/locales. I do this via a CGI::Wiki::Plugin module (attached:
summariser.pm) and some changes to wiki.cgi (also attached, although
that patch has some cruft.) The categories are then iterated in the
edit_form.tt template to create a dropdown box with some javascript.
I'm not sure what the best way to do this is, but I'd like to see it
pulled into the core, because more than one person has asked for it, and
it'll be one less thing for me to maintain on my own.
What's a better way to do this? Anyone have any suggestions?
--
Christopher Schmidt
Web Developer
-------------- next part --------------
package CGI::Wiki::Plugin::Summariser;
use strict;
use CGI::Wiki::Plugin;
use vars qw( $VERSION @ISA );
$VERSION = '0.01';
@ISA = qw( CGI::Wiki::Plugin );
=head1 NAME
CGI::Wiki::Plugin::Summariser - Category management for CGI::Wiki.
=head1 DESCRIPTION
=head1 SYNOPSIS
use CGI::Wiki;
use CGI::Wiki::Plugin::Summariser;
my $summariser = CGI::Wiki::Plugin::Summariser->new;
$wiki->register_plugin( plugin => $summariser );
=head1 METHODS
=over 4
=item B<new>
my $summariser = CGI::Wiki::Plugin::Summariser->new;
$wiki->register_plugin( plugin => $summariser );
=cut
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
return $self;
}
=item B<metadata_list>
my @list = $summariser->metadata_list( type => "Category" );
=cut
sub metadata_list {
my ($self, %args) = @_;
my $dbh = $self->datastore->dbh;
my $sth;
if ( $args{type} ) {
$sth = $dbh->prepare( "
SELECT DISTINCT metadata.metadata_value FROM metadata WHERE metadata.metadata_type = ? ORDER BY metadata.metadata_value
" );
$sth->execute( $args{type} );
} else {
$sth = $dbh->prepare( "
SELECT DISTINCT metadata.metadata_value FROM metadata ORDER BY metadata.metadata_value
" );
$sth->execute( );
}
my @categories;
while ( my ($cat) = $sth->fetchrow_array ) {
push @categories, $cat;
}
return @categories;
}
=head1 SEE ALSO
=over 4
=item *
L<CGI::Wiki>
=item *
L<CGI::Wiki::Plugin>
=back
=head1 AUTHOR
Christopher Schmidt
=head1 COPYRIGHT
Copyright (C) 2005 Christopher Schmidt. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1;
-------------- next part --------------
Index: wiki.cgi
===================================================================
--- wiki.cgi (revision 756)
+++ wiki.cgi (working copy)
@@ -1,14 +1,15 @@
-#!/usr/local/bin/perl
+#!/usr/bin/perl
use strict;
use warnings;
use vars qw( $VERSION );
-$VERSION = '0.53';
+$VERSION = '0.51-local';
use CGI qw/:standard/;
use CGI::Carp qw(croak);
use CGI::Wiki;
+use CGI::Wiki::Plugin::Summariser;
use Geography::NationalGrid;
use Geography::NationalGrid::GB;
use OpenGuides;
@@ -260,16 +258,20 @@
config => $config,
metadata => $node_data{metadata} );
- $metadata_vars{website} ||= 'http://';
-
+ my $summariser = CGI::Wiki::Plugin::Summariser->new;
+ $wiki->register_plugin( plugin => $summariser );
+ my @categories = $summariser->metadata_list( type => 'Category' );
+ my @locales = $summariser->metadata_list( type => 'Locale' );
my %tt_vars = ( content => $q->escapeHTML($content),
checksum => $q->escapeHTML($checksum),
%metadata_vars,
username => $username,
+ global_categories => \@categories,
+ global_locales => \@locales,
edit_type => $edit_type,
deter_robots => 1,
);
-
+
process_template("edit_form.tt", $node, \%tt_vars);
}
More information about the OpenGuides-Dev
mailing list