From 82f0626061729084cd2a2b2a479c01a599bcf941 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Thu, 9 Jun 2011 14:49:24 +0200 Subject: [PATCH] Allows toggle between list and text in advanced search. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- htdocs/javascript/search.js | 85 ++++++++++++----------- include/ufbuilder.inc.php | 18 ++--- modules/search.php | 22 +++--- templates/include/field.select.tpl | 7 -- templates/search/adv.form.autocomplete_select.tpl | 33 +++++++++ templates/search/adv.form.tpl | 65 ++++------------- 6 files changed, 114 insertions(+), 116 deletions(-) create mode 100644 templates/search/adv.form.autocomplete_select.tpl diff --git a/htdocs/javascript/search.js b/htdocs/javascript/search.js index 8078a93..68e7852 100644 --- a/htdocs/javascript/search.js +++ b/htdocs/javascript/search.js @@ -25,27 +25,16 @@ var address_types = new Array('country', 'administrative_area_level_1', 'adminis function load_advanced_search(request) { - $('.autocompleteTarget').hide(); + $('.autocomplete_target').hide(); $('.autocomplete').show().each(function() { - targeted = $('../.autocompleteTarget', this)[0]; - - if (targeted && targeted.value) { - me = $(this); - - $.get(baseurl + 'list/' + targeted.name + '/' + targeted.value, {}, function(textValue) { - me.attr('value', textValue); - me.addClass('hidden_valid'); - }); - } - $(this).autocomplete(baseurl + 'autocomplete/' + this.name, { selectOnly: 1, formatItem: make_format_autocomplete(this), field: this.name, onItemSelect: select_autocomplete(this.name), matchSubset: 0, - width: $(this).width()} - ); + width: $(this).width() + }); }); $('.autocomplete').change(function() { $(this).removeClass('hidden_valid'); }); @@ -67,32 +56,50 @@ function load_advanced_search(request) } } - $(".autocomplete[name='schoolTxt']").change(function() { changeSchool('', ''); }); + $(".autocomplete[name='school_text']").change(function() { changeSchool('', ''); }); changeSchool(request['school'], request['diploma']); - $(".autocompleteToSelect").each(function() { - var fieldName = $(this).attr('href'); + $(".autocomplete_to_select").each(function() { + var field_name = $(this).attr('href'); - $(this).attr('href', baseurl + 'list/' + fieldName).click(function() { - var oldval = $("input.autocompleteTarget[name='" + fieldName + "']")[0].value; + if ($(".autocomplete_target[name='" + field_name + "']").val()) { + display_list(field_name); + } - $(".autocompleteTarget[name='" + fieldName + "']").parent().load(baseurl + 'list/' + fieldName, {}, function(selectBox) { - $(".autocompleteTarget[name='" + fieldName + "']").remove(); - $(".autocomplete[name='" + fieldName + "Txt']").remove(); - $("select[name='" + fieldName + "']").attr('value', oldval); - }); + $(this).attr('href', baseurl + 'list/' + field_name).click(function() { + if ($(this).attr('title') == 'display') { + display_list(field_name); + } else { + var value = $("select[name='" + field_name + "']").val(); + var text_value = $("select[name='" + field_name + "'] option:selected").text(); + $('#' + field_name + '_list').html(''); + $(".autocomplete[name='" + field_name + "_text']").show(); + $('#' + field_name + '_table').attr('title', 'display'); + if (value) { + $(".autocomplete_target[name='" + field_name + "']").val(value); + $(".autocomplete[name='" + field_name + "_text']").val(text_value).addClass('hidden_valid'); + } + } return false; }); - }).parent().find('.autocomplete').change(function() { - // If we change the value in the type="text" field, then the value in the 'integer id' field must not be used, - // to ensure that, we unset it - $(this).parent().find('.autocompleteTarget').val(''); }); $('#only_referent').change(function() { changeOnlyReferent(); }); } +function display_list(field_name) +{ + var value = $("input.autocomplete_target[name='" + field_name + "']").val(); + + $('#' + field_name + '_list').load(baseurl + 'list/' + field_name, {}, function(selectBox) { + $(".autocomplete_target[name='" + field_name + "']").val(''); + $(".autocomplete[name='" + field_name + "_text']").hide().val('').removeClass('hidden_valid'); + $("select[name='" + field_name + "']").val(value); + $('#' + field_name + '_table').attr('title', 'hide'); + }); +} + // }}} // {{{ Regexps to wipe out from search queries @@ -147,7 +154,7 @@ function cancel_autocomplete(field, realfield) { $(".autocomplete[name='" + field + "']").removeClass('hidden_valid').val('').focus(); if (typeof(realfield) != 'undefined') { - $(".autocompleteTarget[name='" + realfield + "']").val(''); + $(".autocomplete_target[name='" + realfield + "']").val(''); } return; } @@ -155,7 +162,7 @@ function cancel_autocomplete(field, realfield) // when choosing autocomplete from list, must validate function select_autocomplete(name) { - nameRealField = name.replace(/Txt$/, ''); + nameRealField = name.replace(/_text$/, ''); // nothing to do if field is not a text field for a list if (nameRealField == name) { @@ -165,7 +172,7 @@ function select_autocomplete(name) // When changing country or locality, open next address component. if (nameRealField == 'country' || nameRealField == 'locality') { return function(i) { - nameRealField = name.replace(/Txt$/, ''); + nameRealField = name.replace(/_text$/, ''); if (i.extra[0] < 0) { cancel_autocomplete(name, nameRealField); i.extra[1] = ''; @@ -180,7 +187,7 @@ function select_autocomplete(name) if (nameRealField == 'school') return function(i) { if (i.extra[0] < 0) { - cancel_autocomplete('schoolTxt', 'school'); + cancel_autocomplete('school_text', 'school'); i.extra[1] = ''; } changeSchool(i.extra[1], ''); @@ -188,13 +195,13 @@ function select_autocomplete(name) // change field in list and display text field as valid return function(i) { - nameRealField = this.field.replace(/Txt$/, ''); + nameRealField = this.field.replace(/_text$/, ''); if (i.extra[0] < 0) { cancel_autocomplete(this.field, nameRealField); return; } - $(".autocompleteTarget[name='"+nameRealField+"']").attr('value',i.extra[1]); + $(".autocomplete_target[name='" + nameRealField + "']").attr('value', i.extra[1]); $(".autocomplete[name='"+this.field+"']").addClass('hidden_valid'); } } @@ -210,7 +217,7 @@ function setAddress(i, j, values) if (j == 3) { $('tr#locality_text').hide() - $("select[name='localityTxt']").attr('value', ''); + $("select[name='locality_text']").attr('value', ''); } $("[name='" + next_type + "']").parent().load(baseurl + 'list/' + next_type, { previous:prev_type, value:values[i] }, function() { @@ -238,7 +245,7 @@ function displayNextAddressComponent(i, j, value) if (j == 3) { $('tr#locality_text').hide(); - $("select[name='localityTxt']").attr('value', ''); + $("select[name='locality_text']").attr('value', ''); } $("[name='" + next_type + "']").parent().load(baseurl + 'list/' + next_type, { previous:prev_type, value:value }, function() { @@ -281,9 +288,9 @@ function changeSchool(schoolId, diploma) $(".autocompleteTarget[name='school']").attr('value', schoolId); if (schoolId) { - $(".autocomplete[name='schoolTxt']").addClass('hidden_valid'); + $(".autocomplete[name='school_text']").addClass('hidden_valid'); } else { - $(".autocomplete[name='schoolTxt']").removeClass('hidden_valid'); + $(".autocomplete[name='school_text']").removeClass('hidden_valid'); } $("[name='diploma']").parent().load(baseurl + 'list/diploma/', { school:schoolId }, function() { @@ -305,7 +312,7 @@ function changeOnlyReferent() function searchForJobTerm(treeid, jtid, full_name) { $(".term_tree").remove(); - $("input[name='jobtermTxt']").val(full_name).addClass("hidden_valid").show(); + $("input[name='jobterm_text']").val(full_name).addClass("hidden_valid").show(); $("input[name='jobterm']").val(jtid); } diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index 84f354a..8c12a66 100644 --- a/include/ufbuilder.inc.php +++ b/include/ufbuilder.inc.php @@ -351,8 +351,8 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_AddressIndex('administrative_area_level_3', 'Canton', 'ADMNISTRATIVEAREAS3'), new UFBF_AddressIndex('administrative_area_level_2', 'Département', 'ADMNISTRATIVEAREAS2'), new UFBF_AddressIndex('administrative_area_level_1', 'Région', 'ADMNISTRATIVEAREAS1'), - new UFBF_AddressMixed('localityTxt', 'locality', 'Ville', 'LOCALITIES'), - new UFBF_AddressMixed('countryTxt', 'country', 'Pays', 'COUNTRIES'), + new UFBF_AddressMixed('locality_text', 'locality', 'Ville', 'LOCALITIES'), + new UFBF_AddressMixed('country_text', 'country', 'Pays', 'COUNTRIES'), new UFBF_JobCompany('entreprise', 'Entreprise'), new UFBF_JobDescription('jobdescription', 'Fonction'), @@ -363,14 +363,14 @@ class UFB_AdvancedSearch extends UserFilterBuilder new UFBF_CurrentCorps('current_corps', 'Corps actuel'), new UFBF_CorpsRank('corps_rank', 'Grade'), - new UFBF_Nationality('nationaliteTxt', 'nationalite', 'Nationalité'), - new UFBF_Binet('binetTxt', 'binet', 'Binet'), - new UFBF_Group('groupexTxt', 'groupex', 'Groupe X'), - new UFBF_Section('sectionTxt', 'section', 'Section'), + new UFBF_Nationality('nationalite_text', 'nationalite', 'Nationalité'), + new UFBF_Binet('binet_text', 'binet', 'Binet'), + new UFBF_Group('groupex_text', 'groupex', 'Groupe X'), + new UFBF_Section('section_text', 'section', 'Section'), - new UFBF_EducationSchool('schoolTxt', 'school', "École d'application"), - new UFBF_EducationDegree('diplomaTxt', 'diploma', 'Diplôme'), - new UFBF_EducationField('fieldTxt', 'field', "Domaine d'études"), + new UFBF_EducationSchool('school_text', 'school', "École d'application"), + new UFBF_EducationDegree('diploma_text', 'diploma', 'Diplôme'), + new UFBF_EducationField('field_text', 'field', "Domaine d'études"), new UFBF_Comment('free', 'Commentaire'), new UFBF_Phone('phone_number', 'Téléphone'), diff --git a/modules/search.php b/modules/search.php index 362e582..b10b098 100644 --- a/modules/search.php +++ b/modules/search.php @@ -243,17 +243,17 @@ class SearchModule extends PLModule } $enums = array( - 'binetTxt' => DirEnum::BINETS, - 'groupexTxt' => DirEnum::GROUPESX, - 'sectionTxt' => DirEnum::SECTIONS, - 'networking_typeTxt' => DirEnum::NETWORKS, - 'localityTxt' => DirEnum::LOCALITIES, - 'countryTxt' => DirEnum::COUNTRIES, - 'entreprise' => DirEnum::COMPANIES, - 'jobtermTxt' => DirEnum::JOBTERMS, - 'description' => DirEnum::JOBDESCRIPTION, - 'nationaliteTxt' => DirEnum::NATIONALITIES, - 'schoolTxt' => DirEnum::EDUSCHOOLS, + 'binet_text' => DirEnum::BINETS, + 'groupex_text' => DirEnum::GROUPESX, + 'section_text' => DirEnum::SECTIONS, + 'networking_type_text' => DirEnum::NETWORKS, + 'locality_text' => DirEnum::LOCALITIES, + 'country_text' => DirEnum::COUNTRIES, + 'entreprise' => DirEnum::COMPANIES, + 'jobterm_text' => DirEnum::JOBTERMS, + 'description' => DirEnum::JOBDESCRIPTION, + 'nationalite_text' => DirEnum::NATIONALITIES, + 'school_text' => DirEnum::EDUSCHOOLS, ); if (!array_key_exists($type, $enums)) { exit(); diff --git a/templates/include/field.select.tpl b/templates/include/field.select.tpl index 4103328..cb28ae1 100644 --- a/templates/include/field.select.tpl +++ b/templates/include/field.select.tpl @@ -20,9 +20,6 @@ {* *} {**************************************************************************} -{if t($with_text_value)} -
-{/if} -{if t($with_text_value)} - -
-{/if} {* vim:set et sws=2 sts=2 sw=2 enc=utf-8: *} diff --git a/templates/search/adv.form.autocomplete_select.tpl b/templates/search/adv.form.autocomplete_select.tpl new file mode 100644 index 0000000..8af2905 --- /dev/null +++ b/templates/search/adv.form.autocomplete_select.tpl @@ -0,0 +1,33 @@ +{**************************************************************************} +{* *} +{* 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="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 fda5ad4..0c79d76 100644 --- a/templates/search/adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -146,13 +146,8 @@ Seuls les lieux où résident des camarades sont proposés ci-dessous. - Pays - - - - {icon name="table" title="Tous les pays"} - + {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… @@ -174,7 +169,7 @@ Ville - + Ville @@ -208,13 +203,8 @@ - Mots-clefs - - - - {icon name="table" title="Tous les mots-clefs"} - + {include file="search/adv.form.autocomplete_select.tpl" description="Mots-clefs" name="jobterm" + value_text=$smarty.request.jobterm_text value=$smarty.request.jobterm title="Tous les mots-clefs"} {if hasPerm('directory_private')} @@ -232,53 +222,28 @@ Divers - Nationalité - - - - {icon name="table" title="Toutes les nationalités"} - + {include file="search/adv.form.autocomplete_select.tpl" description="Nationalité" name="nationalite" + value_text=$smarty.request.nationalite_text value=$smarty.request.nationalite title="Toutes les nationalités"} {if hasPerm('directory_private')} - Binet - - - - {icon name="table" title="Tous les binets"} - + {include file="search/adv.form.autocomplete_select.tpl" description="Binet" name="binet" + value_text=$smarty.request.binet_text value=$smarty.request.binet title="Tous les binets"} {/if} - Groupe X - - - - {icon name="table" title="Tous les groupes X"} - + {include file="search/adv.form.autocomplete_select.tpl" description="Groupe X" name="groupex" + value_text=$smarty.request.groupex_text value=$smarty.request.groupex title="Tous les groupes X"} {if hasPerm('directory_private')} - Section - - - - {icon name="table" title="Toutes les sections"} - + {include file="search/adv.form.autocomplete_select.tpl" description="Section" name="section" + value_text=$smarty.request.section_text value=$smarty.request.section title="Toutes les sections"} {/if} - Formation - - - - {icon name="table" title="Toutes les formations"} - + {include file="search/adv.form.autocomplete_select.tpl" description="Formation" name="school" + value_text=$smarty.request.school_text value=$smarty.request.school title="Toutes les formations"} Diplôme -- 2.1.4