Fix some issues with autocompletion in advanced search
[platal.git] / templates / search / adv.form.tpl
CommitLineData
0337d704 1{**************************************************************************}
2{* *}
5ddeb07c 3{* Copyright (C) 2003-2007 Polytechnique.org *}
0337d704 4{* http://opensource.polytechnique.org/ *}
5{* *}
6{* This program is free software; you can redistribute it and/or modify *}
7{* it under the terms of the GNU General Public License as published by *}
8{* the Free Software Foundation; either version 2 of the License, or *}
9{* (at your option) any later version. *}
10{* *}
11{* This program is distributed in the hope that it will be useful, *}
12{* but WITHOUT ANY WARRANTY; without even the implied warranty of *}
13{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *}
14{* GNU General Public License for more details. *}
15{* *}
16{* You should have received a copy of the GNU General Public License *}
17{* along with this program; if not, write to the Free Software *}
18{* Foundation, Inc., *}
19{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *}
20{* *}
21{**************************************************************************}
22
1f17ab93 23<h1>Recherche dans l'annuaire</h1>
0337d704 24
a94040d2 25{javascript name="jquery"}
26{javascript name="jquery.autocomplete"}
66f2b6b3 27<script type="text/javascript">// <!--
7f304b19 28 var baseurl = platal_baseurl + "search/";
66f2b6b3 29 {literal}
66f2b6b3 30 // display an autocomplete row : blabla (nb of found matches)
bac1e60a 31 function make_format_autocomplete(block) {
32 return function(row) {
af2ff9ef 33 regexp = new RegExp('(' + RegExp.escape(block.value) + ')', 'i');
bac1e60a 34 name = row[0].replace(regexp, '<strong>$1</strong>');
35 if (row[1] == 1) {
36 return name;
37 }
38 return name + '<em>&nbsp;&nbsp;-&nbsp;&nbsp;'+ row[1] + ' camarades</em>';
39 };
66f2b6b3 40 }
41
42 // when changing country, open up region choice
43 function changeCountry(a2) {
44 $(".autocompleteTarget[@name='country']").attr('value',a2);
45 if (a2) {
46 $(".autocomplete[@name='countryTxt']").addClass('hidden_valid');
47 $("[@name='region']").parent().load(baseurl + 'list/region/', { country:a2 }, function() {
48 if ($("select[@name='region']").children("option").size() > 1) {
bac1e60a 49 $("select[@name='region']").attr('value', '{/literal}{$smarty.request.region}{literal}');
50 $("tr#region_ln").show();
66f2b6b3 51 } else {
bac1e60a 52 $("select[@name='region']").attr('value', '');
53 $("tr#region_ln").hide();
66f2b6b3 54 }
55 });
56 } else {
57 $(".autocomplete[@name='countryTxt']").removeClass('hidden_valid');
bac1e60a 58 $("select[@name='region']").attr('value', '');
59 $("tr#region_ln").hide();
66f2b6b3 60 }
61 }
62
63 // when changing school, open diploma choice
64 function changeSchool(schoolId) {
65 $(".autocompleteTarget[@name='school']").attr('value',schoolId);
66 if (schoolId) {
67 $(".autocomplete[@name='schoolTxt']").addClass('hidden_valid');
206e75c3 68 $("[@name='diploma']").parent().load(baseurl + 'list/diploma/', { school:schoolId }, function() {
66f2b6b3 69 if ($("select[@name='diploma']").children("option").size() > 1) {
70 $("select[@name='diploma']").attr('value', '{/literal}{$smarty.request.diploma}{literal}');
bac1e60a 71 $("tr#diploma_ln").show();
66f2b6b3 72 } else {
bac1e60a 73 $("select[@name='diploma']").attr('value', '');
74 $("tr#diploma_ln").hide();
66f2b6b3 75 }
76 });
77 } else {
78 $(".autocomplete[@name='schoolTxt']").removeClass('hidden_valid');
bac1e60a 79 $("select[@name='diploma']").attr('value', '');
80 $("tr#diploma_ln").hide();
66f2b6b3 81 }
82 }
83
84 // when choosing autocomplete from list, must validate
85 function select_autocomplete(name) {
86 nameRealField = name.replace(/Txt$/, '');
87 // nothing to do if field is not a text field for a list
88 if (nameRealField == name)
89 return null;
90 // if changing country, might want to open region choice
91 if (nameRealField == 'country')
92 return function(i) {
93 changeCountry(i.extra[1]);
94 }
95 if (nameRealField == 'school')
96 return function(i) {
97 changeSchool(i.extra[1]);
98 }
99 // change field in list and display text field as valid
100 return function(i) {
101 nameRealField = this.field.replace(/Txt$/, '');
102 $(".autocompleteTarget[@name='"+nameRealField+"']").attr('value',i.extra[1]);
103 $(".autocomplete[@name='"+this.field+"']").addClass('hidden_valid');
104 }
105 }
106 $(document).ready(function() {
107 $(".autocompleteTarget").hide();
108 $(".autocomplete").show().each(function() {
109 targeted = $("../.autocompleteTarget",this)[0];
110 if (targeted && targeted.value) {
111 me = $(this);
112 $.get(baseurl + 'list/'+ targeted.name +'/'+targeted.value, {},function(textValue) {
113 me.attr('value', textValue);
114 me.addClass('hidden_valid');
115 });
116 }
117 $(this).autocomplete(baseurl + "autocomplete/"+this.name,{
118 selectOnly:1,
bac1e60a 119 formatItem:make_format_autocomplete(this),
66f2b6b3 120 field:this.name,
121 onItemSelect:select_autocomplete(this.name),
122 matchSubset:0,
123 width:$(this).width()});
124 });
125 $(".autocomplete").change(function() { $(this).removeClass('hidden_valid'); });
126 $(".autocomplete[@name='countryTxt']").change(function() { changeCountry(''); });
127 changeCountry({/literal}'{$smarty.request.country}'{literal});
128 $(".autocomplete[@name='schoolTxt']").change(function() { changeSchool(''); });
129 changeSchool({/literal}'{$smarty.request.school}'{literal});
130 $(".autocompleteToSelect").each(function() {
131 var fieldName = $(this).attr('href');
132 $(this).attr('href', baseurl + 'list/'+fieldName).click(function() {
133 var oldval = $("input.autocompleteTarget[@name='"+fieldName+"']")[0].value;
134 $(".autocompleteTarget[@name='"+fieldName+"']").parent().load(baseurl + 'list/'+fieldName,{},function(selectBox) {
135 $(".autocompleteTarget[@name='"+fieldName+"']").remove();
136 $(".autocomplete[@name='"+fieldName+"Txt']").remove();
137 $("select[@name='"+fieldName+"']").attr('value', oldval);
138 });
139 return false;
140 });
141 });
142 });
143 -->
a94040d2 144{/literal}</script>
7b2413f6 145<form id="recherche" action="search/adv" method="get">
0337d704 146 <table class="bicol" cellpadding="3" summary="Recherche">
147 <tr>
1f17ab93 148 <th colspan="2">
a7de4ef7 149 Recherche avancée [<a href="search">&lt;&lt;&lt;&nbsp;Recherche simple</a>]
1f17ab93 150 </th>
151 </tr>
152 <tr>
0337d704 153 <td>Nom</td>
154 <td>
66f2b6b3 155 <input type="hidden" name="rechercher" value="Chercher"/>
156 <input type="submit" style="display:none"/>
838cc16a 157 <input type="text" class="autocomplete" name="name" size="32" value="{$smarty.request.name}" />
0337d704 158 </td>
159 </tr>
160 <tr>
a7de4ef7 161 <td>Prénom</td>
0337d704 162 <td>
838cc16a 163 <input class="autocomplete" type="text" name="firstname" size="32" value="{$smarty.request.firstname}" />
0337d704 164 </td>
165 </tr>
166 <tr>
167 <td>Surnom</td>
168 <td>
838cc16a 169 <input class="autocomplete" type="text" name="nickname" size="32" value="{$smarty.request.nickname}" />
0337d704 170 </td>
171 </tr>
172 <tr>
173 <td>Promotion</td>
174 <td>
175 <select name="egal1">
176 <option value="=" {if $smarty.request.egal1 eq "="}selected="selected"{/if}>&nbsp;=&nbsp;</option>
177 <option value="&gt;=" {if $smarty.request.egal1 eq "&gt;="}selected="selected"{/if}>&nbsp;&gt;=&nbsp;</option>
178 <option value="&lt;=" {if $smarty.request.egal1 eq "&lt;="}selected="selected"{/if}>&nbsp;&lt;=&nbsp;</option>
179 </select>
180 <input type="text" name="promo1" size="4" maxlength="4" value="{$smarty.request.promo1}" />
181 &nbsp;ET&nbsp;
182 <select name="egal2">
183 <option value="=" {if $smarty.request.egal2 eq "="}selected="selected"{/if}>&nbsp;=&nbsp;</option>
184 <option value="&gt;=" {if $smarty.request.egal2 eq "&gt;="}selected="selected"{/if}>&nbsp;&gt;=&nbsp;</option>
f6818108 185 <option value="&lt;=" {if $smarty.request.egal2 neq "&gt;=" && $smarty.request.egal2 neq "="}selected="selected"{/if}>&nbsp;&lt;=&nbsp;</option>
0337d704 186 </select>
187 <input type="text" name="promo2" size="4" maxlength="4" value="{$smarty.request.promo2}" />
188 </td>
189 </tr>
190 <tr>
191 <td>Sexe</td>
192 <td>
193 <table>
194 <tr>
195 <td style="width:100px">
f6818108 196 <input type="radio" name="woman" value="0" {if !$smarty.request.woman}checked="checked"{/if} id="woman0"/><label for="woman0">Indifférent</label>
0337d704 197 </td>
198 <td style="width:100px">
f6818108 199 <input type="radio" name="woman" value="1" {if $smarty.request.woman eq 1}checked="checked"{/if} id="woman1"/><label for="woman1">Homme</label>
0337d704 200 </td>
201 <td style="width:100px">
f6818108 202 <input type="radio" name="woman" value="2" {if $smarty.request.woman eq 2}checked="checked"{/if} id="woman2"/><label for="woman2">Femme</label>
0337d704 203 </td>
204 </tr>
205 </table>
206 </td>
207 </tr>
208 <tr>
209 <td>Sur polytechnique.org</td>
210 <td>
211 <table>
212 <tr>
213 <td style="width:100px">
f6818108 214 <input type="radio" name="subscriber" value="0" {if !$smarty.request.subscriber}checked="checked"{/if} id="subscriber0"/><label for="subscriber0">Indifférent</label>
0337d704 215 </td>
216 <td style="width:100px">
f6818108 217 <input type="radio" name="subscriber" value="1" {if $smarty.request.subscriber eq 1}checked="checked"{/if} id="subscriber1"/><label for="subscriber1">Inscrit</label>
0337d704 218 </td>
219 <td style="width:100px">
f6818108 220 <input type="radio" name="subscriber" value="2" {if $smarty.request.subscriber eq 2}checked="checked"{/if} id="subscriber2"/><label for="subscriber2">Non inscrit</label>
0337d704 221 </td>
222 </tr>
223 </table>
224 </td>
225 </tr>
226 <tr>
227 <td>En vie</td>
228 <td>
229 <table>
230 <tr>
231 <td style="width:100px">
f6818108 232 <input type="radio" name="alive" value="0" {if !$smarty.request.alive}checked="checked"{/if} id="alive0"/><label for="alive0">Indifférent</label>
0337d704 233 </td>
234 <td style="width:100px">
f6818108 235 <input type="radio" name="alive" value="1" {if $smarty.request.alive eq 1}checked="checked"{/if} id="alive1"/><label for="alive1">Vivant</label>
0337d704 236 </td>
237 <td style="width:100px">
f6818108 238 <input type="radio" name="alive" value="2" {if $smarty.request.alive eq 2}checked="checked"{/if} id="alive2"/><label for="alive2">Décédé</label>
0337d704 239 </td>
240 </tr>
241 </table>
242 </td>
243 </tr>
244 <tr>
56670b6a 245 <td colspan="2">
b16476f7 246 <input type="checkbox" name="with_soundex" value="1" {if $smarty.request.with_soundex}checked="checked"{/if} id="sdxn" />
247 <label for="sdxn">étendre par proximité sonore (uniquement sur nom et prénom)</label>
248 </td>
20ac3913 249 </tr>
b16476f7 250 <tr>
251 <th colspan="2">Géographie</th>
56670b6a 252 </tr>
253 <tr>
0337d704 254 <td>Ville</td>
df87518a 255 <td><input type="text" class="autocomplete" name="city" size="32" value="{$smarty.request.city}" /></td>
0337d704 256 </tr>
257 <tr>
258 <td>Pays</td>
259 <td>
b0691e10
FB
260 <input name="countryTxt" type="text" class="autocomplete" style="display:none" size="32"
261 value="{$smarty.request.countryTxt}"/>
66f2b6b3 262 <input name="country" class="autocompleteTarget" type="hidden" value="{$smarty.request.country}"/>
263 <a href="country" class="autocompleteToSelect">{icon name="table" title="Tous les pays"}</a>
0337d704 264 </td>
265 </tr>
bac1e60a 266 <tr id="region_ln">
a7de4ef7 267 <td>Région ou département</td>
f6818108 268 <td>
269 <input name="region" type="hidden" size="32" value="{$smarty.request.region}"/>
0337d704 270 </td>
271 </tr>
272 <tr>
b16476f7 273 <td colspan="2">
274 <label for="only_current"><input name="only_current" id="only_current" type="checkbox"{if $smarty.request.only_current}
275checked="checked"{/if}/>chercher uniquement les adresses où les camarades sont actuellement.</label></td>
276 </tr>
277 <tr>
a7de4ef7 278 <th colspan="2">Activité</th>
0337d704 279 </tr>
280 <tr>
281 <td>Entreprise</td>
838cc16a 282 <td><input type="text" class="autocomplete" name="entreprise" size="32" value="{$smarty.request.entreprise}" /></td>
0337d704 283 </tr>
284 <tr>
285 <td>Fonction</td>
286 <td>
b0691e10
FB
287 <input name="fonctionTxt" type="text" class="autocomplete" style="display:none" size="32"
288 value="{$smarty.request.fonctionTxt}"/>
66f2b6b3 289 <input name="fonction" class="autocompleteTarget" type="hidden" value="{$smarty.request.fonction}"/>
290 <a href="fonction" class="autocompleteToSelect">{icon name="table" title="Toutes les fonctions"}</a>
0337d704 291 </td>
292 </tr>
293 <tr>
294 <td>Poste</td>
df87518a 295 <td><input type="text" class="autocomplete" name="poste" size="32" value="{$smarty.request.poste}" /></td>
0337d704 296 </tr>
297 <tr>
298 <td>Secteur</td>
299 <td>
b0691e10
FB
300 <input name="secteurTxt" type="text" class="autocomplete" style="display:none" size="32"
301 value="{$smarty.request.secteurTxt}"/>
66f2b6b3 302 <input name="secteur" class="autocompleteTarget" type="hidden" value="{$smarty.request.secteur}"/>
303 <a href="secteur" class="autocompleteToSelect">{icon name="table" title="Tous les secteurs"}</a>
0337d704 304 </td>
305 </tr>
306 <tr>
307 <td>CV contient</td>
308 <td><input type="text" name="cv" size="32" value="{$smarty.request.cv}" /></td>
309 </tr>
310 <tr>
311 <td colspan="2">
f6818108 312 <input type='checkbox' name='only_referent' {if $smarty.request.only_referent}checked='checked'{/if} id="only_referent"/>
313 <label for="only_referent">chercher uniquement parmi les camarades se proposant comme référents</label>
0337d704 314 </td>
315 </tr>
316 <tr>
317 <th colspan="2">Divers</th>
318 </tr>
319 <tr>
a7de4ef7 320 <td>Nationalité</td>
0337d704 321 <td>
b0691e10
FB
322 <input name="nationaliteTxt" type="text" class="autocomplete" style="display:none" size="32"
323 value="{$smarty.request.nationaliteTxt}"/>
66f2b6b3 324 <input name="nationalite" class="autocompleteTarget" type="hidden" value="{$smarty.request.nationalite}"/>
325 <a href="nationalite" class="autocompleteToSelect">{icon name="table" title="Toutes les nationalités"}</a>
0337d704 326 </td>
327 </tr>
328 <tr>
329 <td>Binet</td>
330 <td>
b0691e10
FB
331 <input name="binetTxt" type="text" class="autocomplete" style="display:none" size="32"
332 value="{$smarty.request.binetTxt}"/>
66f2b6b3 333 <input name="binet" class="autocompleteTarget" type="hidden" value="{$smarty.request.binet}"/>
334 <a href="binet" class="autocompleteToSelect">{icon name="table" title="Tous les binets"}</a>
0337d704 335 </td>
336 </tr>
337 <tr>
338 <td>Groupe X</td>
339 <td>
b0691e10
FB
340 <input name="groupexTxt" type="text" class="autocomplete" style="display:none" size="32"
341 value="{$smarty.request.groupexTxt}"/>
66f2b6b3 342 <input name="groupex" class="autocompleteTarget" type="hidden" value="{$smarty.request.groupex}"/>
343 <a href="groupex" class="autocompleteToSelect">{icon name="table" title="Tous les groupes X"}</a>
0337d704 344 </td>
345 </tr>
346 <tr>
347 <td>Section</td>
348 <td>
b0691e10
FB
349 <input name="sectionTxt" type="text" class="autocomplete" style="display:none" size="32"
350 value="{$smarty.request.sectionTxt}"/>
66f2b6b3 351 <input name="section" class="autocompleteTarget" type="hidden" value="{$smarty.request.section}"/>
352 <a href="section" class="autocompleteToSelect">{icon name="table" title="Toutes les sections"}</a>
0337d704 353 </td>
354 </tr>
355 <tr>
356 <td>Formation</td>
357 <td>
b0691e10
FB
358 <input name="schoolTxt" type="text" class="autocomplete" style="display:none" size="32"
359 value="{$smarty.request.schoolTxt}"/>
66f2b6b3 360 <input name="school" class="autocompleteTarget" type="hidden" value="{$smarty.request.school}"/>
361 <a href="school" class="autocompleteToSelect">{icon name="table" title="Toutes les formations"}</a>
0337d704 362 </td>
363 </tr>
bac1e60a 364 <tr id="diploma_ln">
f6818108 365 <td>Diplôme</td>
366 <td>
367 <input name="diploma" type="hidden" size="32" value="{$smarty.request.diploma}"/>
0337d704 368 </td>
369 </tr>
370 <tr>
371 <td>Commentaire contient</td>
372 <td><input type="text" name="free" size="32" value="{$smarty.request.free}" /></td>
373 </tr>
1f17ab93 374 <tr>
375 <td colspan="2" style="padding-top: 1.5em">
376 <div style="float: right">
fbc210fa 377 <input type="submit" value="Chercher" />
1f17ab93 378 </div>
379 {if $smarty.session.auth ge AUTH_COOKIE}
f6818108 380 <input type='checkbox' name='order' value='date_mod' {if $smarty.request.order eq "date_mod"}checked='checked'{/if} id="order"/>
381 <label for="order">mettre les fiches modifiées récemment en premier</label>
1f17ab93 382 {/if}
383 </td>
384 </tr>
0337d704 385 </table>
cb4a0b71 386</form>
0337d704 387<p>
a7de4ef7 388 <strong>N.B.</strong> Le caractère joker * peut remplacer une ou plusieurs lettres dans les recherches.
0337d704 389</p>
390
a7de4ef7 391{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}