[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Mon, 08 Jul 2002 20:35:36 -0000
matthew Mon Jul 8 16:35:36 2002 EDT
Modified files:
/loncom/interface lonsearchcat.pm
Log:
Changed the logic around selecting a view to fix a bug which caused the
view selection field to not save its values for the 'Revise Search Request'.
This change should make it easier to add new views.
Added global hash %Views, which correlates view descriptions with view
generating functions.
&handler now sets a default view.
&basic_search_form and &advanced_search_form now use &selectbox to generate
their view selection forms.
&selectbox now accepts a $title of undef, which results in *only* the
<select> tag being returned, without any "$TITLE: " nonsense around it.
Also cleanly handles $anyvalue = undef.
&output_results uses %Views to determine $viewfunction.
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.138 loncom/interface/lonsearchcat.pm:1.139
--- loncom/interface/lonsearchcat.pm:1.138 Mon Jul 8 10:52:19 2002
+++ loncom/interface/lonsearchcat.pm Mon Jul 8 16:35:36 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.138 2002/07/08 14:52:19 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.139 2002/07/08 20:35:36 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -118,6 +118,13 @@
The full path to the (temporary) search database file. This is set and
used in &handler() and is also used in &output_results().
+=item %Views
+
+Hash which associates an output view description with the function
+that produces it. Adding a new view type should be as easy as
+adding a line to the definition of this hash and making sure the function
+takes the proper parameters.
+
=back
=cut
@@ -133,6 +140,12 @@
my %hash; # database hash
my $diropendb = ""; # db file
+# View Description Function Pointer
+my %Views = ("Detailed Citation View" => \&detailed_citation_view,
+ "Summary View" => \&summary_view,
+ "Fielded Format" => \&fielded_format_view,
+ "XML/SGML" => \&xml_sgml_view );
+
######################################################################
######################################################################
@@ -223,6 +236,7 @@
$searchtype = 'Basic' if ($ENV{'form.basicsubmit'} eq 'SEARCH');
$searchtype = 'Advanced' if ($ENV{'form.advancedsubmit'} eq 'SEARCH');
if ($searchtype) {
+ # We are running a search
my ($query,$customquery,$customshow,$libraries) =
(undef,undef,undef,undef);
if ($searchtype eq 'Basic') {
@@ -239,12 +253,21 @@
my $reply=&Apache::lonnet::metadata_query($query,$customquery,
$customshow,$libraries);
&output_results($searchtype,$r,$reply,$hidden);
- } elsif ($ENV{'form.reqinterface'} eq 'advanced') {
+ } else {
+ #
+ # We need to get information to search on
+ #
+ # Set the default view if it is not already set.
+ if (!defined($ENV{'form.viewselect'})) {
+ $ENV{'form.viewselect'} ="Detailed Citation View";
+ }
# Output the advanced interface
- $r->print(&advanced_search_form($closebutton,$hidden));
- } else {
- # Output normal search interface
- $r->print(&basic_search_form($closebutton,$hidden));
+ if ($ENV{'form.reqinterface'} eq 'advanced') {
+ $r->print(&advanced_search_form($closebutton,$hidden));
+ } else {
+ # Output normal search interface
+ $r->print(&basic_search_form($closebutton,$hidden));
+ }
}
return OK;
}
@@ -295,20 +318,18 @@
' ';
# $scrout.=&simplecheckbox('allversions',$ENV{'form.allversions'});
# $scrout.='<font color="#800000">Search historic archives</font>';
- $scrout.=<<ENDDOCUMENT;
+ $scrout.=<<END;
</td><td><a href="/adm/searchcat?reqinterface=advanced">Advanced Search</a></td></tr></table>
</p>
<p>
<input type="submit" name="basicsubmit" value='SEARCH' />
$closebutton
-<!-- view selection -->
-<select name="viewselect">
-<option value="Detailed Citation View" selected="true" >Detailed Citation View</option>
-<option value="Summary View" >Summary View</option>
-<option value="Fielded Format">Fielded Format</option>
-<option value="XML/SGML" >XML/SGML</option>
-</select>
-<!-- end of view selection -->
+END
+ $scrout.=&selectbox(undef,'viewselect',
+ $ENV{'form.viewselect'},
+ undef,undef,undef,
+ sort(keys(%Views)));
+ $scrout.=<<ENDDOCUMENT;
<input type="button" value="HELP" onClick="openhelp()" />
</p>
</form>
@@ -341,6 +362,9 @@
<input type="button" value="HELP" onClick="openhelp()" />
</p>
END
+ if (!defined($ENV{'form.viewselect'})) {
+ $ENV{'form.viewselect'} ="Detailed Citation View";
+ }
my $scrout=<<"ENDHEADER";
<html>
<head>
@@ -365,16 +389,12 @@
<table>
<tr><td><font color="#800000" face="helvetica"><b>VIEW:</b></font></td>
<td>
-<!-- view selection -->
-<select name="viewselect" size ="1">
- <option value="Detailed Citation View" selected="true">Detailed Citation View</option>
- <option value="Summary View">Summary View</option>
- <option value="Fielded Format">Fielded Format</option>
- <option value="XML/SGML">XML/SGML</option>
-</select>
-<!-- end of view selection -->
-</td></tr>
ENDHEADER
+ $scrout.=&selectbox(undef,'viewselect',
+ $ENV{'form.viewselect'},
+ undef,undef,undef,
+ sort(keys(%Views)));
+ $scrout.="</td></tr>\n";
$scrout.=&searchphrasefield('title', 'title' ,$ENV{'form.title'});
$scrout.=&searchphrasefield('author', 'author' ,$ENV{'form.author'});
$scrout.=&searchphrasefield('subject', 'subject' ,$ENV{'form.subject'});
@@ -593,7 +613,8 @@
=item $title
-Printed above the select box, in uppercase.
+Printed above the select box, in uppercase. If undefined, only a select
+box will be returned, with no additional html.
=item $name
@@ -601,12 +622,12 @@
=item $default
-The default value of the form. Can be $anyvalue or in @idlist.
+The default value of the form. Can be $anyvalue, or in @idlist.
=item $anyvalue
The <option value="..."> used to indicate a default of
-none of the values.
+none of the values. Can be undef.
=item $anytag
@@ -702,10 +723,15 @@
sub selectbox {
my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;
if (! defined($functionref)) { $functionref = sub { $_[0]}; }
- my $uctitle=uc($title);
- my $selout="\n".'<p><font color="#800000" face="helvetica">'.
- '<b>'.$uctitle.': </b></font><select name="'.$name.'">';
- foreach ($anyvalue,@idlist) {
+ my $selout='';
+ if (defined($title)) {
+ my $uctitle=uc($title);
+ $selout="\n".'<p><font color="#800000" face="helvetica">'.
+ '<b>'.$uctitle.': </b></font>';
+ }
+ $selout .= '<select name="'.$name.'">';
+ unshift @idlist,$anyvalue if (defined($anyvalue));
+ foreach (@idlist) {
$selout.='<option value="'.$_.'"';
if ($_ eq $default and !/^any$/) {
$selout.=' selected >'.&{$functionref}($_).'</option>';
@@ -715,7 +741,7 @@
}
else {$selout.='>'.&{$functionref}($_).'</option>';}
}
- return $selout.'</select></p>';
+ return $selout.'</select>'.(defined($title)?'</p>':' ');
}
######################################################################
@@ -1110,16 +1136,7 @@
##
## Set viewing function
##
- my $viewfunction = undef;
- if ($ENV{'form.viewselect'} eq 'Detailed Citation View') {
- $viewfunction = \&detailed_citation_view;
- } elsif ($ENV{'form.viewselect'} eq 'Summary View') {
- $viewfunction = \&summary_view;
- } elsif ($ENV{'form.viewselect'} eq 'Fielded Format') {
- $viewfunction = \&fielded_format_view;
- } elsif ($ENV{'form.viewselect'} eq 'XML/SGML') {
- $viewfunction = \&xml_sgml_view;
- }
+ my $viewfunction = $Views{$ENV{'form.viewselect'}};
if (!defined($viewfunction)) {
$r->print("Internal Error - Bad view selected.\n");
$r->rflush();