Clean url in advanced search. Closes #1177
authorPascal Corpet <pascal.corpet@m4x.org>
Wed, 1 Sep 2010 21:52:35 +0000 (23:52 +0200)
committerPascal Corpet <pascal.corpet@m4x.org>
Wed, 1 Sep 2010 21:52:35 +0000 (23:52 +0200)
ChangeLog
Makefile
templates/search/adv.form.tpl

index 436763c..e4754b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,10 @@ New:
     * Profile:
         - Sectors replaced by job terms (thesaurus)                        -Car
 
+Bug/Wish:
+    * Search:
+        - #1177: clean url in advanced search                              -Car
+
 From 1.0.0 branch:
     * AXLetter:
         - Fix unsubscription                                               -XEL
index 55603ee..ef7997d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -170,7 +170,7 @@ $(MEDAL_THUMBNAILS): $(subst /medals/thumb/,/medals/,$(@F))
 ## jquery
 ##
 JQUERY_VERSION=1.4.2
-JQUERY_PLUGINS=color
+JQUERY_PLUGINS=color form
 JQUERY_PLUGINS_PATHES=$(addprefix htdocs/javascript/jquery.,$(addsuffix .js,$(JQUERY_PLUGINS)))
 
 JQUERY_UI_VERSION=1.6
@@ -190,7 +190,7 @@ htdocs/javascript/jquery-$(JQUERY_VERSION).min.js:
 htdocs/javascript/jquery.js: htdocs/javascript/jquery-$(JQUERY_VERSION).min.js
        ln -snf $(<F) $@
 
-$(JQUERY_PLUGINS_PATHES): DOWNLOAD_SRC = http://plugins.jquery.com/files/$(@F).txt
+$(JQUERY_PLUGINS_PATHES): DOWNLOAD_SRC = http://plugins.jquery.com/files/$(@F)_0.txt
 $(JQUERY_PLUGINS_PATHES):
        @-rm htdocs/javascript/jquery.ui*.$*.js
        @$(download)
index 5521a00..5025531 100644 (file)
@@ -22,6 +22,8 @@
 
 <h1>Recherche dans l'annuaire</h1>
 
+{javascript name=jquery.form}
+
 <script type="text/javascript">// <!--
   var baseurl = platal_baseurl + "search/";
   {literal}
           $(this).parent().find('.autocompleteTarget').val('');
         });
     });
+/** Regexps to wipe out from search queries */
+var default_form_values = [ /&woman=0(&|$)/, /&subscriber=0(&|$)/, /&alive=0(&|$)/, /&egal[12]=[^&]*&promo[12]=(&|$)/g, /&[^&=]+=(&|$)/g ];
+/** Uses javascript to clean form from all empty fields */
+function cleanForm(f) {
+  var query = $(f).formSerialize();
+  var old_query;
+  for each (var reg in default_form_values) if (typeof(reg) != "undefined") {
+    do {
+      old_query = query;
+      query = query.replace(reg, '$1');
+    } while (old_query != query);
+  }
+  query = query.replace(/^&*(.*)&*$/, '$1');
+  if (query == "") {
+    alert("Aucun critère n'a été spécifié");
+    return false;
+  }
+  document.location = f.action + '?' + query;
+  return false;
+}
 -->
 {/literal}</script>
 <p class="center">[<a href="search">Revenir à la recherche simple</a>]</p>
-<form id="recherche" action="search/adv" method="get">
+<form id="recherche" action="search/adv" method="get" onsubmit="return cleanForm(this)">
   <table class="bicol" cellpadding="3" summary="Recherche">
     <tr>
       <th colspan="2">