OpenGuides
view release on metacpan or search on metacpan
lib/OpenGuides/CGI.pm view on Meta::CPAN
my @dropdowns;
my ( $got_cat, $got_loc );
foreach my $criterion ( @selected ) {
my $type = $criterion->{type} || "";
my $value = $criterion->{value} || "";
my $html;
if ( $type eq "category" ) {
$html = $class->_make_dropdown_html(
%$criterion, guide => $guide );
$got_cat = 1;
} elsif ( $type eq "locale" ) {
$html = $class->_make_dropdown_html(
%$criterion, guide => $guide );
$got_loc = 1;
} else {
warn "Unknown or missing criterion type: $type";
}
if ( $html ) {
push @dropdowns, { type => $type, html => $html };
}
}
if ( !$got_cat ) {
push @dropdowns, { type => "category", html =>
$class->_make_dropdown_html( type => "category", guide => $guide )
};
}
if ( !$got_loc ) {
push @dropdowns, { type => "locale", html =>
$class->_make_dropdown_html( type => "locale", guide => $guide )
};
}
# List the category dropdowns before the locale dropdowns, for consistency.
@dropdowns = sort { $a->{type} cmp $b->{type} } @dropdowns;
return @dropdowns;
}
sub _make_dropdown_html {
my ( $class, %args ) = @_;
my ( $field_name, $any_label );
if ( $args{type} eq "locale" ) {
$args{type} = "locales"; # hysterical raisins
$any_label = " -- anywhere -- ";
$field_name = "loc";
} else {
$any_label = " -- anything -- ";
$field_name = "cat";
}
my @options = $args{guide}->wiki->list_nodes_by_metadata(
metadata_type => "category",
metadata_value => $args{type},
ignore_case => 1,
);
@options = map { s/^Category //; s/^Locale //; $_ } @options;
my %labels = map { lc( $_ ) => $_ } @options;
my @values = sort keys %labels;
my $default = lc( $args{value} || "");
my $q = CGI->new( "" );
return $q->popup_menu( -name => $field_name,
-class => "$args{type}_index",
-values => [ "", @values ],
-labels => { "" => $any_label, %labels },
-default => $default );
}
=back
=head1 AUTHOR
The OpenGuides Project (openguides-dev@lists.openguides.org)
=head1 COPYRIGHT
Copyright (C) 2003-2013 The OpenGuides Project. 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;
( run in 1.129 second using v1.01-cache-2.11-cpan-364913b4093 )