Implemented persist_search hidden variable in forms which can specify
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 18 Jan 2005 17:07:14 +0000 (17:07 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 18 Jan 2005 17:07:14 +0000 (17:07 +0000)
(multiple) number of variables which should be persistent after user
specified them in form (useful for language for example). Values are
separated by comma (,). Some cleanup and warning removal.

git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@636 13eb9ef6-21d5-0310-b721-a9d68796d827

WebPac.pm
back2html.pm
template_html/search.html

index d6337b3..4375ea5 100644 (file)
--- a/WebPac.pm
+++ b/WebPac.pm
@@ -184,12 +184,13 @@ sub make_pager_vars {
        my $hidden_vars = '';
        foreach my $v (@persist_vars) {
                foreach my $val ($q->param($v)) {
+                       next if (! $val || $val eq '');
                        $hidden_vars .= '<input type="hidden" name="'.$v.'" value="'.$val.'"/>'."\n";
                }
        }
 
        $tmpl->param('PAGER_HIDDEN', $hidden_vars);
-       $tmpl->param('PAGER_JAVASCRIPT', qq{
+       $tmpl->param('PAGER_JAVASCRIPT', qq#
 <SCRIPT LANGUAGE="Javascript">
 <!-- Begin
        // dummy emulator for HTML::Pager templates
@@ -198,7 +199,7 @@ sub make_pager_vars {
        }
 // End -->
 </script>  
-       });
+       #);
 }
 
 #--------------------------------------------------------------------------
@@ -230,26 +231,47 @@ sub show_results_list {
        my @path_arr = $q->param('path');
        my $full = $q->param('full');
 
-       my @persist_vars = ( 'rm' );
+       my @persist_vars = ( 'rm', 'persist_search' );
        my @url_params = ( 'rm=results', 'show_full=1', 'last_PAGER_offset='.($q->param('PAGER_offset') || 0) );
 
+       my @persist_search_vars;
+       my @url_params_persist;
+       if ($q->param("persist_search")) {
+               @persist_search_vars = split(/\s*,\s*/, $q->param("persist_search"));
+               push @url_params_persist, "persist_search=".$q->url_param("persist_search");
+               push @url_params,"persist_search=".$q->url_param("persist_search");
+       }
+
        # support parametars "f" and "v" for start
-       for(my $i = ""; $i <=30; $i++) {
+       for(my $i = 0; $i <=30; $i++) {
+
+               $i = '' if ($i == 0);
 
                return show_index($self, $i) if ($q->param("f".$i."_index"));
 
-               next if (! $q->param("v$i"));
+               next if (! $q->param("v$i") || $q->param("v$i") eq '');
                next if (! $q->param("f$i"));
 
+               my $persist = grep(/^$i$/,@persist_search_vars);
+       
                push @persist_vars, "f$i";
                push @persist_vars, "v$i";
                push @persist_vars, "e$i" if ($q->param("e$i"));
 
+               # create url parametars (and persistent ones)
+
                push @url_params,"f$i=".$q->url_param("f$i");
+               push @url_params_persist,"f$i=".$q->url_param("f$i") if ($persist);
+
                foreach my $v ($q->url_param("v$i")) {
                        push @url_params,"v$i=$v";
+                       push @url_params_persist,"v$i=$v" if ($persist);
+               }
+
+               if ($q->param("e$i")) {
+                       push @url_params,"e$i=".$q->url_param("e$i");
+                       push @url_params_persist,"e$i=".$q->url_param("e$i");
                }
-               push @url_params,"e$i=".$q->url_param("e$i");
 
                my $wc="*";     # swish wildcard
                $wc="" if ($i eq "");   # don't apply wildcard on field 0
@@ -270,8 +292,9 @@ sub show_results_list {
 
                        # filed e[nr] is exact match bitmask
                        # 1 = beginning, 2=end, 3=both
-                       $pre = '"xxbxx ' if ($q->param("e$i") & 1);
-                       $post = ' xxexx"' if ($q->param("e$i") & 2);
+                       my $exact_flag = $q->param("e$i") || 0;
+                       $pre = '"xxbxx ' if ($exact_flag & 1);
+                       $post = ' xxexx"' if ($exact_flag & 2);
                        # add qotes on other side
                        if ($q->param("e$i")) {
                                $pre = '"' if (! $pre);
@@ -324,13 +347,12 @@ sub show_results_list {
 
        # construct swish query
        my $sw_q = join(" and ",@s_arr);
-       if (@path_arr) {
+       if (@path_arr && $q->param('show_full')) {
                $sw_q .= "and (swishdocpath=\"";
                $sw_q .= join("\" or swishdocpath=\"",@path_arr);
                $sw_q .= "\")";
-       }
-
-       if ($q->param('show_full')) {
+               $tmpl->param('full',1); # show full records
+       } elsif ($q->param('show_full')) {
                # just show full path, no path defined
                $tmpl->param('full',1);
        } else {
@@ -390,7 +412,7 @@ sub show_results_list {
                        rank => $result->Property('swishrank')
                };
 
-               $r->{html} = back2html($from_utf8->convert($result->Property('html'))) if ($q->param('show_full'));
+               $r->{html} = back2html($from_utf8->convert($result->Property('html')), join("&",@url_params_persist)) if ($q->param('show_full'));
 
                push @pager_data_list, $r;
        }
index 860a1d6..0fcf931 100644 (file)
@@ -6,6 +6,7 @@
 
 sub back2html {
        my $html = shift;
+       my $url_params = shift;
 
        $html =~ s/</&lt;/g;
        $html =~ s/>/&gt;/g;
@@ -16,7 +17,7 @@ sub back2html {
                # convert spaces in left field to non-breaking spaces
                $items[0] =~ s#\s+#&nbsp;#g;
                # try to make link on right field
-               sub mkurl {
+               sub mkurl($) {
                        my $url = shift || die "mkurl needs url as argument";
                        # chop URLS longer than 60 characters
                        my $txturl = substr($1,0,60);
@@ -30,7 +31,16 @@ sub back2html {
        # put <br> back into html
        $out =~ s,&lt;br/*&gt;,<br/>,gi;
        # put <a href=xxx>yyyy</a> back into html
-       $out =~ s,&lt;(a\s+href=)(.+?)&gt;(.+?)&lt;(/a)&gt;,<$1$2>$3<$4>,gsi;
+       sub mkurl_param($$$$) {
+               my ($a_href,$url,$text,$a_end) = @_;
+               if ($url =~ m#\?#) {
+                       $url .= "&".$url_params;
+               } else {
+                       $url .= "?".$url_params;
+               }
+               return '<'.$a_href.'"'.$url.'">'.$text.'<'.$a_end.'>';
+       }
+       $out =~ s#&lt;(a\s+href=)['"]*(.+?)['"]*&gt;(.+?)&lt;(/a)&gt;#mkurl_param($1,$2,$3,$4)#gsie;
        return $out;
 }
 
index a293fec..b2e83ce 100644 (file)
@@ -37,6 +37,7 @@
 <div>
 <form name="search" method="get" >
 <input type="hidden" name="rm" value="results">
+<input type="hidden" name="persist_search" value="10,11">
     <table border="0">
       <tr> 
         <td class="label1">Pretra¾i sve:&nbsp;</td>