From 029b12c0048285bfc5a8bb9a9ece1cc29bca3549 Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Fri, 21 Jan 2022 13:07:44 +0100 Subject: [PATCH 1/5] Force combobox close when search query changed --- .../js/coffee/bika.lims.analysisrequest.add.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/senaite/core/browser/static/js/coffee/bika.lims.analysisrequest.add.coffee b/src/senaite/core/browser/static/js/coffee/bika.lims.analysisrequest.add.coffee index fe2b0ce2e0..ad1236acac 100644 --- a/src/senaite/core/browser/static/js/coffee/bika.lims.analysisrequest.add.coffee +++ b/src/senaite/core/browser/static/js/coffee/bika.lims.analysisrequest.add.coffee @@ -491,9 +491,11 @@ class window.AnalysisRequestAdd # get the combogrid options options = JSON.parse field.attr "combogrid_options" + # we have absolute URLs now + # https://github.com/senaite/senaite.core/pull/1917 + url = options.url + # prepare the new query url - url = @get_base_url() - url += "/#{options.url}" url += "?_authenticator=#{@get_authenticator()}" url += "&catalog_name=#{catalog_name}" url += "&colModel=#{JSON.stringify options.colModel}" @@ -519,10 +521,12 @@ class window.AnalysisRequestAdd options.url = url options.force_all = "false" - field.combogrid options field.attr "search_query", "{}" + # close on any open searchbox to force reload on the next focus + field.trigger("blur") + set_reference_field: (field, uid, title) => ### From ffd0edfe23fa7a9a35c5fed0046094535d057c62 Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Fri, 21 Jan 2022 13:08:18 +0100 Subject: [PATCH 2/5] Remove portal_factory check in combobox JS --- .../skins/senaite_templates/senaite_widgets/referencewidget.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/senaite/core/skins/senaite_templates/senaite_widgets/referencewidget.js b/src/senaite/core/skins/senaite_templates/senaite_widgets/referencewidget.js index 1a1c9459f7..0ae4e343f1 100644 --- a/src/senaite/core/skins/senaite_templates/senaite_widgets/referencewidget.js +++ b/src/senaite/core/skins/senaite_templates/senaite_widgets/referencewidget.js @@ -133,9 +133,6 @@ function referencewidget_lookups(elements) { } }; - if (window.location.href.search("portal_factory") > -1) { - options.url = window.location.href.split("/portal_factory")[0] + "/" + options.url; - } options.url = options.url + "?_authenticator=" + $("input[name='_authenticator']").val(); options.url = options.url + "&catalog_name=" + $(element).attr("catalog_name"); options.url = options.url + "&base_query=" + $(element).attr("base_query"); From a01f40947641a02f09d4780e0fba4f2fb4bc7263 Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Fri, 21 Jan 2022 13:08:47 +0100 Subject: [PATCH 3/5] Handle portal_factory urls --- .../core/browser/widgets/referencewidget.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/senaite/core/browser/widgets/referencewidget.py b/src/senaite/core/browser/widgets/referencewidget.py index 85c4d49ce7..7c9c1d3adc 100644 --- a/src/senaite/core/browser/widgets/referencewidget.py +++ b/src/senaite/core/browser/widgets/referencewidget.py @@ -96,18 +96,25 @@ def process_form(self, instance, field, form, empty_marker=None, uid = None return uid, {} + def get_search_url(self, context): + """Prepare an absolute search url for the combobox + """ + # ensure we have an absolute url for the current context + url = api.get_url(context) + # normalize portal factory urls + url = url.split("portal_factory")[0] + # ensure the search path does not contain already the url + search_path = self.url.split(url)[-1] + # return the absolute search url + return "/".join([url, search_path]) + def get_combogrid_options(self, context, fieldName): colModel = self.colModel if "UID" not in [x["columnName"] for x in colModel]: colModel.append({"columnName": "UID", "hidden": True}) - # ensure we have an absolute url for the current context - url = api.get_url(context) - search_path = self.url.split(url)[-1] - search_url = "/".join([url, search_path]) - options = { - "url": search_url, + "url": self.get_search_url(context), "colModel": colModel, "showOn": self.showOn, "width": self.popup_width, From f830e71f0d3d220910a4c176ab361c76a91e4a10 Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Fri, 21 Jan 2022 13:09:42 +0100 Subject: [PATCH 4/5] Generated coffee script --- .../core/browser/static/js/bika.lims.analysisrequest.add.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/senaite/core/browser/static/js/bika.lims.analysisrequest.add.js b/src/senaite/core/browser/static/js/bika.lims.analysisrequest.add.js index 400c69b65f..4b8158daf7 100644 --- a/src/senaite/core/browser/static/js/bika.lims.analysisrequest.add.js +++ b/src/senaite/core/browser/static/js/bika.lims.analysisrequest.add.js @@ -510,8 +510,7 @@ return; } options = JSON.parse(field.attr("combogrid_options")); - url = this.get_base_url(); - url += "/" + options.url; + url = options.url; url += "?_authenticator=" + (this.get_authenticator()); url += "&catalog_name=" + catalog_name; url += "&colModel=" + (JSON.stringify(options.colModel)); @@ -532,7 +531,8 @@ options.url = url; options.force_all = "false"; field.combogrid(options); - return field.attr("search_query", "{}"); + field.attr("search_query", "{}"); + return field.trigger("blur"); }; AnalysisRequestAdd.prototype.set_reference_field = function(field, uid, title) { From 0071ac55bceb7feb0b65397a9bc9458b23b51e84 Mon Sep 17 00:00:00 2001 From: Ramon Bartl Date: Fri, 21 Jan 2022 13:18:20 +0100 Subject: [PATCH 5/5] Changelog updated --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 12ccb737fd..19e5b9e681 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changelog 2.2.0 (unreleased) ------------------ +- #1918 Fix stale combobox items displayed when search query changed - #1917 Fix wrong context in reference widget lookups - #1916 Provide the request record to object info adapters in the sample add form - #1913 Ported PR #1865 for dexterity contents