Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter hook for confirmation when creating a Sample #1802

Merged
merged 3 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions bika/lims/browser/analysisrequest/add2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1564,9 +1565,29 @@ 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
"""
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()
Expand Down
15 changes: 15 additions & 0 deletions bika/lims/browser/analysisrequest/templates/ar_add2.pt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@
</table>
</script>

<!-- Confirmation Template -->
<script id="confirm-template" type="text/x-handlebars-template">
<div title="Confirm" i18n:attributes="title">
<p i18n:translate="">
{{message}}
</p>
<p i18n:translate="">
Do you want to continue?
</p>
</div>
</script>

</metal:block>
</head>

Expand Down Expand Up @@ -603,6 +615,9 @@
name="save_button"
i18n:attributes="value"
value="Save"/>

<input type="hidden" id="confirmed" name="confirmed" value="0"/>

</form>
<!-- /ADD Form -->

Expand Down
16 changes: 14 additions & 2 deletions bika/lims/browser/js/bika.lims.analysisrequest.add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 !== "") {
Expand All @@ -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);
}
Expand Down
16 changes: 16 additions & 0 deletions bika/lims/browser/js/coffee/bika.lims.analysisrequest.add.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions bika/lims/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down