From: Stéphane Jacob Date: Fri, 10 Jun 2011 09:08:03 +0000 (+0200) Subject: Improves search on address components. X-Git-Tag: xorg/1.1.2~29 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=4aab50612c8e62a391df9a274e37b1e51bd240e9;p=platal.git Improves search on address components. Removes confusing search on administrative_area_level_3, fatorizes code, allows to easily delete search criteria. --- diff --git a/htdocs/javascript/search.js b/htdocs/javascript/search.js index 4347c33..feca64b 100644 --- a/htdocs/javascript/search.js +++ b/htdocs/javascript/search.js @@ -21,7 +21,8 @@ // {{{ Page initialization var baseurl = $.plURL('search/'); -var address_types = new Array('country', 'administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'locality', 'sublocality'); +var address_types = new Array('country', 'administrative_area_level_1', 'administrative_area_level_2', 'locality', 'sublocality'); +var address_types_count = address_types.length; function load_advanced_search(request) { @@ -46,13 +47,12 @@ function load_advanced_search(request) setAddress(0, 1, new Array(request['country'], request['administrative_area_level_1'], request['administrative_area_level_2'], - request['administrative_area_level_3'], request['locality'], request['sublocality']) ); } else { - for (var i = 1; i < 6; ++i) { - $('tr#' + address_types[i] + '_list').hide(); + for (var i = 1; i < address_types_count; ++i) { + $('tr#' + address_types[i]).hide(); } } @@ -86,6 +86,22 @@ function load_advanced_search(request) }); $('#only_referent').change(function() { changeOnlyReferent(); }); + + $('.delete_address_component').click(function() { + var field_name = $(this).attr('href'); + var hide = false; + + for (var i = 1; i < address_types_count; ++i) { + if (field_name == address_types[i]) { + hide = true; + } + if (hide) { + delete_address_component(address_types[i]); + } + } + + return false; + }); } function display_list(field_name) @@ -216,17 +232,17 @@ function setAddress(i, j, values) $("select[name='locality_text']").attr('value', ''); } - $("[name='" + next_type + "']").parent().load(baseurl + 'list/' + next_type, { previous:prev_type, value:values[i] }, function() { + $('#' + next_list).load(baseurl + 'list/' + next_type, { previous:prev_type, value:values[i] }, function() { if ($("select[name='" + next_type + "']").children("option").size() > 1) { - $("tr#" + next_list).show(); + $("tr#" + next_type).show(); $("select[name='" + next_type + "']").attr('value', values[j]); - if (j < 6) { + if (j < address_types_count) { setAddress(j, j + 1, values); } } else { - $("tr#" + next_list).hide(); + $("tr#" + next_type).hide(); $("select[name='" + next_type + "']").attr('value', ''); - if (j < 6) { + if (j < address_types_count) { setAddress(i, j + 1, values); } } @@ -239,18 +255,18 @@ function displayNextAddressComponent(i, j, value) var next_type = address_types[j]; var next_list = next_type + '_list'; - if (j == 3) { + if (next_type == 'locality') { $('tr#locality_text').hide(); $("select[name='locality_text']").attr('value', ''); } - $("[name='" + next_type + "']").parent().load(baseurl + 'list/' + next_type, { previous:prev_type, value:value }, function() { + $('#' + next_list).load(baseurl + 'list/' + next_type, { previous:prev_type, value:value }, function() { $("select[name='" + next_type + "']").attr('value', ''); if ($("select[name='" + next_type + "']").children('option').size() > 1) { - $('tr#' + next_list).show(); + $('tr#' + next_type).show(); } else { - $('tr#' + next_list).hide(); - if (j < 6) { + $('tr#' + next_type).hide(); + if (j < address_types_count) { displayNextAddressComponent(i, j + 1, value); } } @@ -259,25 +275,34 @@ function displayNextAddressComponent(i, j, value) function changeAddressComponents(type, value) { - var i = 0, j = 0; + var i = 0; - while (address_types[i] != type && i < 6) { + while (address_types[i] != type && i < address_types_count) { ++i; } - j = i + 1; - while (j < 6) { - $("select[name='" + address_types[j] + "']").attr('value', ''); - $('tr#' + address_types[j] + '_list').hide(); - ++j; + for (var j = i + 1; j < address_types_count; ++j) { + delete_address_component(address_types[j]); } - if (value != '' && i < 5) { + if (value != '' && i < address_types_count) { $("select[name='" + type + "']").attr('value', value); displayNextAddressComponent(i, i + 1, value); } } +function delete_address_component(field_name) +{ + $('tr#' + field_name).hide(); + $('#' + field_name + '_list').html(''); + $("input[name='" + field_name + "']").val(''); + + if (field_name == 'locality') { + $("select[name='locality_text']").attr('value', ''); + $('tr#locality_text').show(); + } +} + // when changing school, open diploma choice function changeSchool(schoolId, diploma) { diff --git a/modules/search.php b/modules/search.php index b10b098..ff3d8b8 100644 --- a/modules/search.php +++ b/modules/search.php @@ -312,7 +312,6 @@ class SearchModule extends PLModule break; case 'administrative_area_level_1': case 'administrative_area_level_2': - case 'administrative_area_level_3': case 'locality': $page->assign('onchange', 'changeAddressComponents(\'' . $type . '\', this.value)'); case 'sublocality': diff --git a/templates/search/adv.form.address_component.tpl b/templates/search/adv.form.address_component.tpl new file mode 100644 index 0000000..f64ebf3 --- /dev/null +++ b/templates/search/adv.form.address_component.tpl @@ -0,0 +1,34 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 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 *} +{* *} +{**************************************************************************} + + + {$description} + + + + + {icon name="cross" title="Supprimer ce critère"} + + + + +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/search/adv.form.autocomplete_select.tpl b/templates/search/adv.form.autocomplete_select.tpl index 8af2905..d634f8d 100644 --- a/templates/search/adv.form.autocomplete_select.tpl +++ b/templates/search/adv.form.autocomplete_select.tpl @@ -20,14 +20,16 @@ {* *} {**************************************************************************} -{$description} - - - - - - {icon name="table" title=$title} - - + + {$description} + + + + + + {icon name="table" title=$title} + + + {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/search/adv.form.tpl b/templates/search/adv.form.tpl index 0c79d76..4df0e1d 100644 --- a/templates/search/adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -145,44 +145,18 @@ Seuls les lieux où résident des camarades sont proposés ci-dessous. - - {include file="search/adv.form.autocomplete_select.tpl" description="Pays" name="country" - value_text=$smarty.request.country_text value=$smarty.request.country title="Tous les pays"} - - - Région, province, état… - - - - - - Département, comté… - - - - - - Canton… - - - - + {include file="search/adv.form.autocomplete_select.tpl" description="Pays" name="country" + value_text=$smarty.request.country_text value=$smarty.request.country title="Tous les pays"} + {include file="search/adv.form.address_component.tpl" description="Région, province, état…" name="administrative_area_level_1" + value=$smarty.request.administrative_area_level_1} + {include file="search/adv.form.address_component.tpl" description="Département, comté…" name="administrative_area_level_2" + value=$smarty.request.administrative_area_level_2} Ville - - Ville - - - - - - Arrondissement, quartier… - - - - + {include file="search/adv.form.address_component.tpl" description="Ville" name="locality" value=$smarty.request.locality} + {include file="search/adv.form.address_component.tpl" description="Arrondissement, quartier…" name="sublocality" value=$smarty.request.sublocality}