Replace field for 'networking type' in advanced search (Closes #1251)
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 10 Oct 2010 18:52:19 +0000 (20:52 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 10 Oct 2010 18:54:21 +0000 (20:54 +0200)
Use a list of options instead.
Special valued: -1 => Any, 0 => empty

Fix UserFilterBuilderFields as well.

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
include/ufbuilder.inc.php
modules/search.php
templates/search/adv.form.tpl

index 40c5a74..a28a10a 100644 (file)
@@ -268,7 +268,7 @@ abstract class UFB_Field
             return false;
         }
 
-        if (!$this->empty) {
+        if (!$this->isEmpty()) {
             $ufc = $this->buildUFC($ufb);
             if ($ufc != null) {
                 $ufb->addCond($ufc);
@@ -1010,6 +1010,11 @@ class UFBF_Networking extends UFBF_Text
         }
     }
 
+    public function isEmpty()
+    {
+        return parent::isEmpty() || $this->nwtype == 0;
+    }
+
     public function buildUFC(UserFilterBuilder &$ufb)
     {
         return new UFC_Networking($this->nwtype, $this->val);
index 505e5ee..06c729a 100644 (file)
@@ -155,6 +155,12 @@ class SearchModule extends PLModule
         $page->assign('advanced',1);
         $page->addJsLink('jquery.autocomplete.js');
 
+        $networks = DirEnum::getOptions(DirEnum::NETWORKS);
+        $networks[-1] = 'Tous types';
+        $networks[0] = '-';
+        ksort($networks);
+        $page->assign('networking_types', $networks);
+
         if (!Env::has('rechercher') && $model != 'geoloc') {
             $this->form_prepare();
         } else {
index a9e56a5..ee730a4 100644 (file)
         });
     });
 /** Regexps to wipe out from search queries */
-var default_form_values = [ /&woman=0(&|$)/, /&subscriber=0(&|$)/, /&alive=0(&|$)/, /&egal[12]=[^&]*&promo[12]=(&|$)/g, /&[^&=]+=(&|$)/g ];
+var default_form_values = [ /&woman=0(&|$)/, /&subscriber=0(&|$)/, /&alive=0(&|$)/, /&egal[12]=[^&]*&promo[12]=(&|$)/g, /&networking_type=0(&|$)/, /&[^&=]+=(&|$)/g ];
 /** Uses javascript to clean form from all empty fields */
 function cleanForm(f) {
   var query = $(f).formSerialize();
@@ -462,9 +462,11 @@ function cleanForm(f) {
               <input type="text" name="networking_address" size="32" value="{$smarty.request.networking_address}" />
             </td>
             <td>
-              <input type="text" name="networking_typeTxt" class="autocomplete" size="10" value="{$smarty.request.networking_typeTxt}" />
-              <input name="networking_type" class="autocompleteTarget" type="hidden" value="{$smarty.request.networking_type}"/>
-              <a href="networking_type" class="autocompleteToSelect">{icon name="table" title="Tous les types d'adresse"}</a>
+              <select name="networking_type">
+              {foreach from=$networking_types key=id item=network}
+                <option value="{$id}" {if $smarty.request.networking_type eq $id}selected="selected"{/if}>{$network}</option>
+              {/foreach}
+              </select>
             </td>
           </tr>
         </table>