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

Avoid unnecessary Price recalculations in Sample Add Form #1539

Merged
merged 3 commits into from
Feb 13, 2020
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 @@ -30,6 +30,7 @@ Changelog

**Changed**

- #1539 Avoid unnecessary Price recalculations in Sample Add Form
- #1532 Updated jQuery Barcode to version 2.2.0
- #1513 Better Ajax Loader for Sample Add Form
- #1508 Do not try to render InstrumentQCFailuresViewlet to non-lab personnel
Expand Down
24 changes: 16 additions & 8 deletions bika/lims/browser/js/bika.lims.analysisrequest.add.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
$("body").on("click", "img.copybutton", this.on_copy_button_click);

/* internal events */
$(this).on("form:changed", this.debounce(this.recalculate_records, 500));
$(this).on("data:updated", this.debounce(this.recalculate_prices, 3000));
$(this).on("data:updated", this.debounce(this.update_form, 300));
$(this).on("data:updated", this.debounce(this.hide_all_service_info, 300));
$(this).on("form:changed", this.debounce(this.recalculate_records, 1500));
$(this).on("services:changed", this.debounce(this.recalculate_prices, 3000));
$(this).on("data:updated", this.debounce(this.update_form));
$(this).on("data:updated", this.debounce(this.hide_all_service_info));
$(this).on("ajax:start", this.on_ajax_start);
return $(this).on("ajax:end", this.on_ajax_end);
};
Expand Down Expand Up @@ -135,7 +135,7 @@
} else if (execAsap) {
func.apply(obj, args);
}
return timeout = setTimeout(delayed, threshold || 100);
return timeout = setTimeout(delayed, threshold || 300);
};
};

Expand Down Expand Up @@ -645,11 +645,15 @@
var el, poc;
console.debug("*** set_service::AR=" + arnum + " UID=" + uid + " checked=" + checked);
el = $("td[fieldname='Analyses-" + arnum + "'] #cb_" + arnum + "_" + uid);
if (el.is(":checked") === checked) {
return;
}
el.prop("checked", checked);
poc = el.closest("tr[poc]").attr("poc");
if (this.is_poc_expanded(poc)) {
return el.closest("tr").addClass("visible");
el.closest("tr").addClass("visible");
}
return $(this).trigger("services:changed");
};

AnalysisRequestAdd.prototype.set_service_spec = function(arnum, uid, spec) {
Expand Down Expand Up @@ -1006,7 +1010,8 @@
$el = $(el);
uid = $el.val();
console.debug("°°° on_analysis_click::UID=" + uid + " checked=" + checked + "°°°");
return $(me).trigger("form:changed");
$(me).trigger("form:changed");
return $(me).trigger("services:changed");
};

AnalysisRequestAdd.prototype.on_service_listing_header_click = function(event) {
Expand Down Expand Up @@ -1114,7 +1119,7 @@
console.debug("-> Copy checkbox field");
$el = $(el);
checked = $el.prop("checked");
return $.each((function() {
$.each((function() {
results1 = [];
for (var j = 1; 1 <= ar_count ? j <= ar_count : j >= ar_count; 1 <= ar_count ? j++ : j--){ results1.push(j); }
return results1;
Expand All @@ -1127,6 +1132,9 @@
_el = $(_td).find("input[type=checkbox]")[index];
return $(_el).prop("checked", checked);
});
if ($el.hasClass("analysisservice-cb")) {
return $(me).trigger("services:changed");
}
});
$td1.find("select").each(function(index, el) {
var j, results1;
Expand Down
24 changes: 17 additions & 7 deletions bika/lims/browser/js/coffee/bika.lims.analysisrequest.add.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ class window.AnalysisRequestAdd
### internal events ###

# handle value changes in the form
$(this).on "form:changed", @debounce @recalculate_records, 500
# recalculate prices after data changed
$(this).on "data:updated", @debounce @recalculate_prices, 3000
$(this).on "form:changed", @debounce @recalculate_records, 1500
# recalculate prices after services changed
$(this).on "services:changed", @debounce @recalculate_prices, 3000
# update form from records after the data changed
$(this).on "data:updated", @debounce @update_form, 300
$(this).on "data:updated", @debounce @update_form
# hide open service info after data changed
$(this).on "data:updated", @debounce @hide_all_service_info, 300
$(this).on "data:updated", @debounce @hide_all_service_info
# handle Ajax events
$(this).on "ajax:start", @on_ajax_start
$(this).on "ajax:end", @on_ajax_end
Expand All @@ -116,7 +116,7 @@ class window.AnalysisRequestAdd
###
timeout = null

(args...) ->
return (args...) ->
obj = this
delayed = ->
func.apply(obj, args) unless execAsap
Expand All @@ -125,7 +125,7 @@ class window.AnalysisRequestAdd
clearTimeout(timeout)
else if (execAsap)
func.apply(obj, args)
timeout = setTimeout delayed, threshold || 100
timeout = setTimeout(delayed, threshold || 300)


template_dialog: (template_id, context, buttons) =>
Expand Down Expand Up @@ -650,13 +650,18 @@ class window.AnalysisRequestAdd
console.debug "*** set_service::AR=#{arnum} UID=#{uid} checked=#{checked}"
# get the service checkbox element
el = $("td[fieldname='Analyses-#{arnum}'] #cb_#{arnum}_#{uid}")
# avoid unneccessary event triggers if the checkbox status is unchanged
if el.is(":checked") == checked
return
# select the checkbox
el.prop "checked", checked
# get the point of capture of this element
poc = el.closest("tr[poc]").attr "poc"
# make the element visible if the categories are visible
if @is_poc_expanded poc
el.closest("tr").addClass "visible"
# trigger event for price recalculation
$(@).trigger "services:changed"


set_service_spec: (arnum, uid, spec) =>
Expand Down Expand Up @@ -1048,6 +1053,8 @@ class window.AnalysisRequestAdd

# trigger form:changed event
$(me).trigger "form:changed"
# trigger event for price recalculation
$(me).trigger "services:changed"


on_service_listing_header_click: (event) =>
Expand Down Expand Up @@ -1169,6 +1176,9 @@ class window.AnalysisRequestAdd
_td = $tr.find("td[arnum=#{arnum}]")
_el = $(_td).find("input[type=checkbox]")[index]
$(_el).prop "checked", checked
# trigger event for price recalculation
if $el.hasClass "analysisservice-cb"
$(me).trigger "services:changed"

# Copy <select> fields
$td1.find("select").each (index, el) ->
Expand Down