From d33b0587cb20954d0fe4b629e89ec0a0da134d72 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Mon, 28 Dec 2020 13:44:17 +0100 Subject: [PATCH] Advanced search tags are now multiselects (#1240) --- cps/static/js/edit_books.js | 18 +++++++++++++----- cps/templates/search_form.html | 20 ++++++++++---------- cps/web.py | 6 ++++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/cps/static/js/edit_books.js b/cps/static/js/edit_books.js index 35515aa1..5f9154fc 100644 --- a/cps/static/js/edit_books.js +++ b/cps/static/js/edit_books.js @@ -249,18 +249,26 @@ promisePublishers.done(function() { ); }); -$("#search").on("change input.typeahead:selected", function() { +$("#search").on("change input.typeahead:selected", function(event) { + if (event.target.type == "search" && event.target.tagName == "INPUT") { + return; + } var form = $("form").serialize(); $.getJSON( getPath() + "/get_matching_tags", form, function( data ) { $(".tags_click").each(function() { - if ($.inArray(parseInt($(this).children("input").first().val(), 10), data.tags) === -1 ) { - if (!($(this).hasClass("active"))) { - $(this).addClass("disabled"); + if ($.inArray(parseInt($(this).val(), 10), data.tags) === -1) { + if(!$(this).prop("selected")) { + $(this).prop("disabled", true); } } else { - $(this).removeClass("disabled"); + $(this).prop("disabled", false); } }); + $("#include_tag option:selected").each(function () { + $("#exclude_tag").find("[value="+$(this).val()+"]").prop("disabled", true); + }); + $('#include_tag').selectpicker("refresh"); + $('#exclude_tag').selectpicker("refresh"); }); }); diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index e39cf661..e61fe067 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -42,17 +42,17 @@
- {% for tag in tags %} - + {% endfor %}
- {% for tag in tags %} - + {% endfor %}
@@ -60,7 +60,7 @@
- {% for serie in series %} {% endfor %} @@ -68,7 +68,7 @@
- {% for serie in series %} {% endfor %} @@ -79,7 +79,7 @@
- {% for language in languages %} {% endfor %} @@ -87,7 +87,7 @@
- {% for language in languages %} {% endfor %} @@ -98,7 +98,7 @@
- {% for extension in extensions %} {% endfor %} @@ -106,7 +106,7 @@
- {% for extension in extensions %} {% endfor %} diff --git a/cps/web.py b/cps/web.py index 21bc41a0..6d993e29 100644 --- a/cps/web.py +++ b/cps/web.py @@ -335,8 +335,6 @@ def get_matching_tags(): title_input = request.args.get('book_title') or '' include_tag_inputs = request.args.getlist('include_tag') or '' exclude_tag_inputs = request.args.getlist('exclude_tag') or '' - # include_extension_inputs = request.args.getlist('include_extension') or '' - # exclude_extension_inputs = request.args.getlist('exclude_extension') or '' q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_input + "%")), func.lower(db.Books.title).ilike("%" + title_input + "%")) if len(include_tag_inputs) > 0: @@ -1067,8 +1065,12 @@ def render_adv_search_results(term, offset=None, order=None, limit=None): pub_start = u"" tag_names = calibre_db.session.query(db.Tags).filter(db.Tags.id.in_(include_tag_inputs)).all() searchterm.extend(tag.name for tag in tag_names) + tag_names = calibre_db.session.query(db.Tags).filter(db.Tags.id.in_(exclude_tag_inputs)).all() + searchterm.extend(tag.name for tag in tag_names) serie_names = calibre_db.session.query(db.Series).filter(db.Series.id.in_(include_series_inputs)).all() searchterm.extend(serie.name for serie in serie_names) + serie_names = calibre_db.session.query(db.Series).filter(db.Series.id.in_(exclude_series_inputs)).all() + searchterm.extend(serie.name for serie in serie_names) language_names = calibre_db.session.query(db.Languages).\ filter(db.Languages.id.in_(include_languages_inputs)).all() if language_names: