Replace auto-submits in advance search with AJAX
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 13 Nov 2006 21:20:27 +0000 (21:20 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 13 Nov 2006 21:20:27 +0000 (21:20 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1075 839d8a87-29fc-0310-9880-83ba4fa771e5

modules/search.php
templates/search/adv.form.tpl
templates/search/adv.grade.form.tpl [new file with mode: 0644]
templates/search/adv.region.form.tpl [new file with mode: 0644]

index d06b5e3..68760b2 100644 (file)
@@ -26,6 +26,8 @@ class SearchModule extends PLModule
         return array(
             'search'     => $this->make_hook('quick', AUTH_PUBLIC),
             'search/adv' => $this->make_hook('advanced', AUTH_COOKIE),
+            'search/ajax/region'  => $this->make_hook('region', AUTH_COOKIE, '', NO_AUTH),
+            'search/ajax/grade'   => $this->make_hook('grade',  AUTH_COOKIE, '', NO_AUTH),
             'advanced_search.php' => $this->make_hook('redir_advanced', AUTH_PUBLIC),
         );
     }
@@ -103,21 +105,30 @@ class SearchModule extends PLModule
                       XDB::iterator('SELECT id,text FROM applis_def ORDER BY text'));
         $page->assign('choix_secteurs',
                       XDB::iterator('SELECT id,label FROM emploi_secteur ORDER BY label'));
+        $this->get_diplomas();
+    }
+
+    function get_diplomas($school = null)
+    {
+        if (is_null($school) && Env::has('school')) {
+            $school = Env::i('school');
+        }
 
-        if (Env::has('school')) {
-            $sql = 'SELECT type FROM applis_def WHERE id='.Env::i('school');
+        if (!is_null($school)) {
+            $sql = 'SELECT type FROM applis_def WHERE id=' . $school;
         } else {
             $sql = 'DESCRIBE applis_def type';
         }
 
         $res = XDB::query($sql);
         $row = $res->fetchOneRow();
-        if (Env::has('school')) {
+        if (!is_null($school)) {
             $types = $row[0];
         } else {
             $types = explode('(',$row[1]);
             $types = str_replace("'","",substr($types[1],0,-1));
         }
+        global $page;
         $page->assign('choix_diplomas', explode(',',$types));
     }
 
@@ -235,8 +246,24 @@ class SearchModule extends PLModule
 
         }
 
+        $page->addJsLink('ajax.js');
         $page->register_modifier('display_lines', 'display_lines');
     }
+
+    function handler_region(&$page, $country = null)
+    {
+        require_once("geoloc.inc.php");
+        $page->ChangeTpl('search/adv.region.form.tpl', NO_SKIN);
+        $page->assign('region', "");
+        $page->assign('country', $country);
+    }
+
+    function handler_grade(&$page, $school = null)
+    {
+        $page->ChangeTpl('search/adv.grade.form.tpl', NO_SKIN);
+        $page->assign('grade', '');
+        $this->get_diplomas($school);
+    }
 }
 
 ?>
index f35bf4e..881ebd2 100644 (file)
     <tr>
       <td>Pays</td>
       <td>
-        <select name="country" onchange="javascript:document.forms.recherche.submit();">
+        <select name="country" onchange="return Ajax.update_html('region', '{$platal->ns}search/ajax/region/' + this.value);">
         {if $smarty.request.country}
           {assign var="country" value=$smarty.request.country}
         {else}
     <tr>
       <td>Région ou département</td>
       <td>
-        <select name="region">
+        <select name="region" id="region">
         {if $smarty.request.region}
           {assign var="region" value=$smarty.request.region}
         {else}
           {assign var="region" value=""}
         {/if}
-        {if $smarty.request.country neq ""}
-        {geoloc_region country=$smarty.request.country region=$region}
-        {else}
-        <option value=""></option>
-        {/if}
+        {include file="search/adv.region.form.tpl" country=$smarty.request.country}
         </select>
       </td>
     </tr>
     <tr>
       <td>Formation</td>
       <td>
-        <select name="school" onchange="javascript:document.forms.recherche.submit();">
+        <select name="school" onchange="return Ajax.update_html('grade', '{$platal->ns}search/ajax/grade/' + this.value);">
           <option value="0"></option>
           {iterate item=cs from=$choix_schools}
           <option value="{$cs.id}" {if $smarty.request.school eq $cs.id}selected="selected"{/if}>
     <tr>
       <td></td>
       <td>
-        <select name="diploma">
-          <option value="0"></option>
-          {section name=diploma loop=$choix_diplomas}
-          <option value="{$choix_diplomas[diploma]}" {if $smarty.request.diploma eq
-          $choix_diplomas[diploma]}selected="selected"{/if}>
-            {$choix_diplomas[diploma]}
-          </option>
-          {/section}
+        <select name="diploma" id="grade">
+          {include file="search/adv.grade.form.tpl" grade=$smarty.request.diploma}
         </select>
       </td>
     </tr>
diff --git a/templates/search/adv.grade.form.tpl b/templates/search/adv.grade.form.tpl
new file mode 100644 (file)
index 0000000..cfa4429
--- /dev/null
@@ -0,0 +1,30 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2006 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<option value="0"></option>
+{section name=diploma loop=$choix_diplomas}
+<option value="{$choix_diplomas[diploma]}" {if $grade eq $choix_diplomas[diploma]}selected="selected"{/if}>
+  {$choix_diplomas[diploma]}
+</option>
+{/section}
+
+{* vim:set et sw=2 sts=2 sws=2: *}
diff --git a/templates/search/adv.region.form.tpl b/templates/search/adv.region.form.tpl
new file mode 100644 (file)
index 0000000..61a40ae
--- /dev/null
@@ -0,0 +1,29 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2006 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+{if $country neq ""}
+  {geoloc_region country=$country region=$region}
+{else}
+  <option value=""></option>
+{/if}
+
+{* vim:set et sw=2 sts=2 sws=2: *}