From 4cee904a19977f0a64337bfd5b4bf722d4c55b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Thu, 13 May 2021 17:38:59 +0200 Subject: [PATCH 1/3] Adapter for Add sample form confirmation --- bika/lims/browser/analysisrequest/add2.py | 22 +++++++++++++++++++ .../analysisrequest/templates/ar_add2.pt | 15 +++++++++++++ .../js/bika.lims.analysisrequest.add.js | 16 ++++++++++++-- .../bika.lims.analysisrequest.add.coffee | 16 ++++++++++++++ bika/lims/interfaces/__init__.py | 11 ++++++++++ 5 files changed, 78 insertions(+), 2 deletions(-) diff --git a/bika/lims/browser/analysisrequest/add2.py b/bika/lims/browser/analysisrequest/add2.py index 119b8dbca9..c229dc7c5f 100644 --- a/bika/lims/browser/analysisrequest/add2.py +++ b/bika/lims/browser/analysisrequest/add2.py @@ -45,6 +45,7 @@ from bika.lims import logger from bika.lims.api.analysisservice import get_calculation_dependencies_for from bika.lims.api.analysisservice import get_service_dependencies_for +from bika.lims.interfaces import IAddSampleConfirmation from bika.lims.interfaces import IAddSampleFieldsFlush from bika.lims.interfaces import IAddSampleObjectInfo from bika.lims.interfaces import IGetDefaultFieldValueARAddHook @@ -1564,9 +1565,30 @@ def ajax_recalculate_prices(self): return prices + def check_confirmation(self): + """Returns a dict when user confirmation is required for the creation of + samples. Returns None otherwise + """ + import pdb;pdb.set_trace() + if self.request.form.get("confirmed") == "1": + # User pressed the "yes" button in the confirmation pane already + return None + + # Find out if there is a confirmation adapter available + adapter = queryAdapter(self.request, IAddSampleConfirmation) + if not adapter: + return None + + # Extract records from the request and call the adapter + records = self.get_records() + return adapter.check_confirmation(records) + def ajax_submit(self): """Submit & create the ARs """ + confirmation = self.check_confirmation() + if confirmation: + return {"confirmation": confirmation} # Get AR required fields (including extended fields) fields = self.get_ar_fields() diff --git a/bika/lims/browser/analysisrequest/templates/ar_add2.pt b/bika/lims/browser/analysisrequest/templates/ar_add2.pt index a79b9fc18d..cebe46a6fc 100644 --- a/bika/lims/browser/analysisrequest/templates/ar_add2.pt +++ b/bika/lims/browser/analysisrequest/templates/ar_add2.pt @@ -214,6 +214,18 @@ + + + @@ -603,6 +615,9 @@ name="save_button" i18n:attributes="value" value="Save"/> + + + diff --git a/bika/lims/browser/js/bika.lims.analysisrequest.add.js b/bika/lims/browser/js/bika.lims.analysisrequest.add.js index c07acb4845..e45e3b8a3d 100644 --- a/bika/lims/browser/js/bika.lims.analysisrequest.add.js +++ b/bika/lims/browser/js/bika.lims.analysisrequest.add.js @@ -1315,11 +1315,12 @@ * Eventhandler for the form submit button. * Extracts and submits all form data asynchronous. */ - var base_url, me; + var base_url, me, portal_url; console.debug("°°° on_form_submit °°°"); event.preventDefault(); me = this; base_url = me.get_base_url(); + portal_url = me.get_portal_url(); $("div.error").removeClass("error"); $("div.fieldErrorBox").text(""); return this.ajax_post_form("submit").done(function(data) { @@ -1332,7 +1333,7 @@ * This includes GET params for printing labels, so that we do not * have to care about this here. */ - var ars, destination, errorbox, field, fieldname, message, msg, parent, q, stickertemplate; + var ars, destination, dialog, errorbox, field, fieldname, message, msg, parent, q, stickertemplate; if (data['errors']) { msg = data.errors.message; if (msg !== "") { @@ -1357,6 +1358,17 @@ stickertemplate = data['stickertemplate']; q = '/sticker?autoprint=1&template=' + stickertemplate + '&items=' + ars.join(','); return window.location.replace(destination + q); + } else if (data['confirmation']) { + dialog = me.template_dialog("confirm-template", data.confirmation); + return dialog.on("yes", function() { + destination = data.confirmation["destination"]; + if (destination) { + return window.location.replace(portal_url + '/' + destination); + } else { + $("input[name=confirmed]").val("1"); + return $("input[name=save_button]").trigger("click"); + } + }); } else { return window.location.replace(base_url); } diff --git a/bika/lims/browser/js/coffee/bika.lims.analysisrequest.add.coffee b/bika/lims/browser/js/coffee/bika.lims.analysisrequest.add.coffee index e2aaa37dd0..43bf240c39 100644 --- a/bika/lims/browser/js/coffee/bika.lims.analysisrequest.add.coffee +++ b/bika/lims/browser/js/coffee/bika.lims.analysisrequest.add.coffee @@ -1343,6 +1343,9 @@ class window.AnalysisRequestAdd # get the right base url base_url = me.get_base_url() + # the poral url + portal_url = me.get_portal_url() + # remove all errors $("div.error").removeClass("error") $("div.fieldErrorBox").text("") @@ -1382,6 +1385,19 @@ class window.AnalysisRequestAdd stickertemplate = data['stickertemplate'] q = '/sticker?autoprint=1&template=' + stickertemplate + '&items=' + ars.join(',') window.location.replace destination + q + + else if data['confirmation'] + dialog = me.template_dialog "confirm-template", data.confirmation + dialog.on "yes", -> + destination = data.confirmation["destination"] + if destination + # Redirect user + window.location.replace portal_url + '/' + destination + else + # Re-submit + $("input[name=confirmed]").val "1" + $("input[name=save_button]").trigger "click" + else window.location.replace base_url diff --git a/bika/lims/interfaces/__init__.py b/bika/lims/interfaces/__init__.py index 834f9c59a1..d5f5571860 100644 --- a/bika/lims/interfaces/__init__.py +++ b/bika/lims/interfaces/__init__.py @@ -981,6 +981,17 @@ def get_object_info(self): """ +class IAddSampleConfirmation(Interface): + """Marker interface for confirmation Add Sample form confirmation + """ + + def check_confirmation(self, records): + """Returns a dict when user confirmation is required for the creation + of samples when the Save button from Add Sample form is pressed. Returns + None otherwise + """ + + class IClientAwareMixin(Interface): """Marker interface for objects that can be bound to a Client, either because they can be added inside a Client folder or because it can be From fd1b66bc13a47dd9972f4881a45a9f59f259bab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Thu, 13 May 2021 17:40:34 +0200 Subject: [PATCH 2/3] Changelog --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 61eee726ee..50adc75b5a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changelog 1.3.5 (unreleased) ------------------ +- #1802 Adapter for Add sample form confirmation - #1781 Exclude invalid samples from dashboard's not-printed indicator - #1774 Fix Lab clerk can edit items from setup folder - #1763 Remove final states from dashboard From 290365529fd9545b62206199f80b5ed97bba75f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Thu, 13 May 2021 17:44:36 +0200 Subject: [PATCH 3/3] Remove pdb --- bika/lims/browser/analysisrequest/add2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bika/lims/browser/analysisrequest/add2.py b/bika/lims/browser/analysisrequest/add2.py index c229dc7c5f..9d509d86d8 100644 --- a/bika/lims/browser/analysisrequest/add2.py +++ b/bika/lims/browser/analysisrequest/add2.py @@ -1569,7 +1569,6 @@ def check_confirmation(self): """Returns a dict when user confirmation is required for the creation of samples. Returns None otherwise """ - import pdb;pdb.set_trace() if self.request.form.get("confirmed") == "1": # User pressed the "yes" button in the confirmation pane already return None