From 81c1f3449d055ed43e760fb93028ca4b6e009749 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 3 Jul 2018 18:26:38 +0200 Subject: Change criteria search UI to put criteria in the search text (refs #4180) --- archaeological_operations/models.py | 25 +++++++++++++------ ishtar_common/forms.py | 2 +- ishtar_common/static/js/ishtar.js | 29 +++++++++++----------- .../templates/blocks/bs_field_snippet.html | 3 ++- .../templates/blocks/bs_form_snippet.html | 25 ++++++------------- ishtar_common/templates/widgets/search_input.html | 8 +++++- 6 files changed, 51 insertions(+), 41 deletions(-) diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 688c12bea..912351f9b 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -364,14 +364,25 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter, # alternative names of fields for searches ALT_NAMES = { - 'periods__pk': pgettext_lazy( - "key for text search (no accent, no spaces)", u"period"), - 'operation_type__pk': pgettext_lazy( - "key for text search (no accent, no spaces)", u"operation-type"), - 'remains__pk': pgettext_lazy( - "key for text search (no accent, no spaces)", u"remain"), + 'periods': ( + pgettext_lazy( + "key for text search (no accent, no spaces)", u"period"), + 'periods__pk' + ), + 'operation_type': ( + pgettext_lazy( + "key for text search (no accent, no spaces)", u"operation-type" + ), + 'operation_type__pk' + ), + 'remains': ( + pgettext_lazy( + "key for text search (no accent, no spaces)", u"remain"), + 'remains__pk' + ), } - EXTRA_REQUEST_KEYS.update(dict([(v, k) for k, v in ALT_NAMES.items()])) + for v in ALT_NAMES.values(): + EXTRA_REQUEST_KEYS[v[0]] = v[1] # fields definition creation_date = models.DateField(_(u"Creation date"), diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index bb468eff1..c1e699ab5 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -471,7 +471,7 @@ class TableSelect(IshtarForm): cls += " search-vector" self.fields[k].widget.attrs['class'] = cls if k in ALT_NAMES: - self.fields[k].alt_name = ALT_NAMES[k] + self.fields[k].alt_name = ALT_NAMES[k][0] else: self.fields[k].alt_name = k key = self.fields.keys()[0] diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index b5d701528..2f04775c5 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -529,12 +529,12 @@ function get_label_from_input(input){ if (input.parent().filter('.input-group').length){ input = input.parent(); } - return "" + input.prev().html() + ""; + return input.parent().attr('data-alt-name'); } -function update_search_resume(){ - var summary = ""; +function update_search_field(){ + var query = ""; var inputs = $('#wizard-form input').map( function(){ var v = ""; @@ -555,8 +555,8 @@ function update_search_resume(){ v = $(this).val(); } if (v == "") return; - if (summary) summary += " ; "; - summary += get_label_from_input(item_for_label) + " " + v; + if (query) query += " "; + query += get_label_from_input(item_for_label) + '="' + v + '"'; } ).get(); var selects = $('#wizard-form select').each( @@ -567,18 +567,20 @@ function update_search_resume(){ if(item_for_label.filter('optgroup').length){ item_for_label = item_for_label.parent(); } - if (summary) summary += " ; "; - summary += get_label_from_input(item_for_label) + " " + $(this).text(); + if (query) query += " "; + query += get_label_from_input(item_for_label) + '="' + + $(this).text() + '"'; }); } ); - if (summary != ""){ - $('#advanced-search-resume-content').html(summary); - $('#advanced-search-resume').show(); - } else { - $('#advanced-search-resume').hide(); + var value = $("#id_search_vector").val(); + if (value){ + value += " "; } + value += query; + document.getElementById('wizard-form').reset(); + value = $("#id_search_vector").val(value); } var sheet_list = new Array(); @@ -610,10 +612,9 @@ function register_advanced_search(){ $(".advanced-search-reset").click( function(){ document.getElementById('wizard-form').reset(); - $('#advanced-search-resume').hide(); } ); - $(".advanced-search-valid").click(update_search_resume); + $(".advanced-search-valid").click(update_search_field); } diff --git a/ishtar_common/templates/blocks/bs_field_snippet.html b/ishtar_common/templates/blocks/bs_field_snippet.html index 4c4e17bf1..a164c81d8 100644 --- a/ishtar_common/templates/blocks/bs_field_snippet.html +++ b/ishtar_common/templates/blocks/bs_field_snippet.html @@ -1,5 +1,6 @@ {% load i18n %} -
+