diff --git a/bika/lims/browser/fields/interimfieldsfield.py b/bika/lims/browser/fields/interimfieldsfield.py
index 408597e125..68f9b75826 100644
--- a/bika/lims/browser/fields/interimfieldsfield.py
+++ b/bika/lims/browser/fields/interimfieldsfield.py
@@ -6,13 +6,10 @@
from AccessControl import ClassSecurityInfo
from Products.ATExtensions.ateapi import RecordsField
from Products.Archetypes.Registry import registerField
-from Products.Archetypes.public import *
from bika.lims import bikaMessageFactory as _
-from bika.lims.utils import t
class InterimFieldsField(RecordsField):
-
"""a list of InterimFields for calculations """
_properties = RecordsField._properties.copy()
_properties.update({
@@ -22,25 +19,37 @@ class InterimFieldsField(RecordsField):
'type': 'InterimFields',
'subfields': ('keyword', 'title', 'value', 'unit', 'hidden', 'wide'),
'required_subfields': ('keyword', 'title'),
- 'subfield_labels': {'keyword': _('Keyword'),
- 'title': _('Field Title'),
- 'value': _('Default value'),
- 'unit': _('Unit'),
- 'hidden': _('Hidden Field'),
- 'wide': _('Apply wide')},
- 'subfield_types': {'hidden': 'boolean', 'value': 'float', 'wide': 'boolean'},
- 'subfield_sizes': {'keyword': 20,
- 'title': 20,
- 'value': 10,
- 'unit': 10},
- 'subfield_validators': {'keyword': 'interimfieldsvalidator',
- 'title': 'interimfieldsvalidator',
- 'value': 'interimfieldsvalidator',
- 'unit': 'interimfieldsvalidator'},
- })
+ 'subfield_labels': {
+ 'keyword': _('Keyword'),
+ 'title': _('Field Title'),
+ 'value': _('Default value'),
+ 'unit': _('Unit'),
+ 'hidden': _('Hidden Field'),
+ 'wide': _('Apply wide'),
+ },
+ 'subfield_types': {
+ 'hidden': 'boolean',
+ 'value': 'float',
+ 'wide': 'boolean',
+ },
+ 'subfield_sizes': {
+ 'keyword': 20,
+ 'title': 20,
+ 'value': 10,
+ 'unit': 10,
+ },
+ 'subfield_validators': {
+ 'keyword': 'interimfieldsvalidator',
+ 'title': 'interimfieldsvalidator',
+ 'value': 'interimfieldsvalidator',
+ 'unit': 'interimfieldsvalidator',
+ },
+ })
security = ClassSecurityInfo()
-registerField(InterimFieldsField,
- title="Interim Fields",
- description="Used for storing Interim Fields or Interim Results.",
- )
+
+registerField(
+ InterimFieldsField,
+ title="Interim Fields",
+ description="Used for storing Interim Fields or Interim Results."
+)
diff --git a/bika/lims/browser/js/bika.lims.analysisservice.js b/bika/lims/browser/js/bika.lims.analysisservice.js
index 923b8ad36b..3fd4927ff8 100644
--- a/bika/lims/browser/js/bika.lims.analysisservice.js
+++ b/bika/lims/browser/js/bika.lims.analysisservice.js
@@ -1,867 +1,677 @@
-/**
+
+/*
* Controller class for Analysis Service Edit view
*/
-function AnalysisServiceEditView() {
-
- var that = this;
-
- var manual_fd = $('#archetypes-fieldname-ManualEntryOfResults');
- var manual_chk = $('#archetypes-fieldname-ManualEntryOfResults #ManualEntryOfResults');
- var instre_fd = $('#archetypes-fieldname-InstrumentEntryOfResults');
- var instr_chk = $('#archetypes-fieldname-InstrumentEntryOfResults #InstrumentEntryOfResults');
- var methods_fd = $('#archetypes-fieldname-Methods');
- var methods_ms = $('#archetypes-fieldname-Methods #Methods');
- var method_fd = $('#archetypes-fieldname-Method');
- var method_sel = $('#archetypes-fieldname-Method #Method');
- var instrs_fd = $('#archetypes-fieldname-Instruments');
- var instrs_ms = $('#archetypes-fieldname-Instruments #Instruments');
- var instr_fd = $('#archetypes-fieldname-Instrument');
- var instr_sel = $('#archetypes-fieldname-Instrument #Instrument');
-
- var default_calculation_chk = $('#archetypes-fieldname-UseDefaultCalculation #UseDefaultCalculation');
- var calculation_field = $('#archetypes-fieldname-Calculation');
- var calculation_label = $(calculation_field).find('label');
- var calculation_select_element = $('#archetypes-fieldname-Calculation #Calculation');
- var interim_fd = $("#archetypes-fieldname-InterimFields");
- var interim_rw = $("#archetypes-fieldname-InterimFields tr.records_row_InterimFields");
- var ldsel_chk = $('#archetypes-fieldname-DetectionLimitSelector #DetectionLimitSelector');
- var ldman_fd = $('#archetypes-fieldname-AllowManualDetectionLimit');
- var ldman_chk = $('#archetypes-fieldname-AllowManualDetectionLimit #AllowManualDetectionLimit');
-
- /**
+(function() {
+ window.AnalysisServiceEditView = function() {
+ var applyStyles, calculation_field, calculation_label, calculation_select_element, catchOriginalValues, default_calculation_chk, insert_manual_methods, instr_chk, instr_fd, instr_sel, instre_fd, instrs_fd, instrs_ms, interim_fd, interim_rw, ldman_chk, ldman_fd, ldsel_chk, loadInterims, manual_chk, manual_fd, method_fd, method_sel, methods_fd, methods_ms, that, updateContainers, validateInstruments;
+ that = this;
+ manual_fd = $('#archetypes-fieldname-ManualEntryOfResults');
+ manual_chk = $('#archetypes-fieldname-ManualEntryOfResults #ManualEntryOfResults');
+ instre_fd = $('#archetypes-fieldname-InstrumentEntryOfResults');
+ instr_chk = $('#archetypes-fieldname-InstrumentEntryOfResults #InstrumentEntryOfResults');
+ methods_fd = $('#archetypes-fieldname-Methods');
+ methods_ms = $('#archetypes-fieldname-Methods #Methods');
+ method_fd = $('#archetypes-fieldname-Method');
+ method_sel = $('#archetypes-fieldname-Method #Method');
+ instrs_fd = $('#archetypes-fieldname-Instruments');
+ instrs_ms = $('#archetypes-fieldname-Instruments #Instruments');
+ instr_fd = $('#archetypes-fieldname-Instrument');
+ instr_sel = $('#archetypes-fieldname-Instrument #Instrument');
+ default_calculation_chk = $('#archetypes-fieldname-UseDefaultCalculation #UseDefaultCalculation');
+ calculation_field = $('#archetypes-fieldname-Calculation');
+ calculation_label = $(calculation_field).find('label');
+ calculation_select_element = $('#archetypes-fieldname-Calculation #Calculation');
+ interim_fd = $('#archetypes-fieldname-InterimFields');
+ interim_rw = $('#archetypes-fieldname-InterimFields tr.records_row_InterimFields');
+ ldsel_chk = $('#archetypes-fieldname-DetectionLimitSelector #DetectionLimitSelector');
+ ldman_fd = $('#archetypes-fieldname-AllowManualDetectionLimit');
+ ldman_chk = $('#archetypes-fieldname-AllowManualDetectionLimit #AllowManualDetectionLimit');
+
+ /*
* Entry-point method for AnalysisServiceEditView
*/
- that.load = function() {
-
- // LIMS-1775 Allow to select LDL or UDL defaults in results with readonly mode
- // https://jira.bikalabs.com/browse/LIMS-1775
- $(ldsel_chk).change(function() {
- if ($(this).is(':checked')) {
- $(ldman_fd).show();
- } else {
- $(ldman_fd).hide();
- $(ldman_chk).prop('checked', false);
- }
- });
- $(ldsel_chk).change();
-
- // service defaults
- // update defalt Containers
- $(".portaltype-analysisservice #RequiredVolume, .portaltype-analysisservice #Separate").change(function(){
- var separate = $("#Separate").prop("checked");
- if(!separate){
- $("[name='Preservation\\:list']").prop("disabled", false);
- }
- var requestdata = {
- "allow_blank":true,
- "show_container_types":!separate,
- "show_containers":separate,
- "_authenticator": $("input[name='_authenticator']").val()
- };
- updateContainers("#Container\\:list", requestdata);
- });
-
- // partition table -> separate checkboxes
- // partition table -> minvol field
- // update row's containers
- $(".portaltype-analysisservice [name^='PartitionSetup.separate'],.portaltype-analysisservice [name^='PartitionSetup.vol']").change(function(){
- var separate = $(this).parents("tr").find("[name^='PartitionSetup.separate']").prop("checked");
- if (!separate){
- $(this).parents("tr").find("[name^='PartitionSetup.preservation']").prop("disabled", false);
- }
- var minvol = $(this).parents("tr").find("[name^='PartitionSetup.vol']").val();
- var target = $(this).parents("tr").find("[name^='PartitionSetup.container']");
- var requestdata = {
- "allow_blank":true,
- "minvol":minvol,
- "show_container_types":!separate,
- "show_containers":separate,
- "_authenticator": $("input[name='_authenticator']").val()
- };
- updateContainers(target, requestdata);
- });
-
- // copy sampletype MinimumVolume to minvol when selecting sampletype
- $(".portaltype-analysisservice [name^='PartitionSetup.sampletype']").change(function(){
- var st_element = this;
- var request_data = {
- catalog_name: "uid_catalog",
- UID: $(this).val()
- };
- window.bika.lims.jsonapi_read(request_data, function(data) {
- var minvol = data.objects[0].MinimumVolume;
- var target = $(st_element).parents("tr").find("[name^='PartitionSetup.vol']");
- $(target).val(minvol);
- // trigger change on containers, in case SampleType volume rendered
- // the selected container too small and removed it from the list
- $(st_element).parents("tr").find("[name^='PartitionSetup.container']").change();
- });
- });
-
-
- // handling of pre-preserved containers in the Default Container field
- // select the preservation and disable the input.
- $(".portaltype-analysisservice #Container").bind("selected", function(){
- var container_uid = $(this).attr("uid");
- if (container_uid === undefined || container_uid === null){
- container_uid='';
- }
- var request_data = {
- catalog_name: "uid_catalog",
- UID: container_uid
- };
- window.bika.lims.jsonapi_read(request_data, function(data) {
- if (data.objects.length < 1 ||
- (!data.objects[0].PrePreserved) || (!data.objects[0].Preservation)) {
- $("#Preservation").val("");
- $("#Preservation").prop("disabled", false);
- } else {
- $("#Preservation").val(data.objects[0].Preservation);
- $("#Preservation").prop("disabled", true);
- }
- });
- });
+ insert_manual_methods = function() {
+ $.ajax({
+ url: window.portal_url + '/get_instrument_methods',
+ type: 'POST',
+ data: {
+ '_authenticator': $('input[name="_authenticator"]').val(),
+ 'uid': $(instr_sel).val()
+ },
+ dataType: 'json',
+ async: false
+ }).done(function(data) {
+ $(method_sel).find('option').remove();
+ if (data !== null && data.methods.length > 0) {
+ $.each(data.methods, function(index, value) {
+ var option, title, uid;
+ uid = value.uid;
+ title = value.title;
+ console.debug('Adding Method ' + title + ' to the Selection');
+ option = '';
+ $(method_sel).append(option);
+ $(method_sel).val(uid);
+ });
+ } else {
+ $(method_sel).append('');
+ $(method_sel).val('');
+ }
+ $(default_calculation_chk).change();
+ });
+ };
- // handling of pre-preserved containers in the per Sample-Type rows
- // select the preservation and disable the input.
- $(".portaltype-analysisservice [name^='PartitionSetup.container']").change(function(){
- var target = $(this).parents("tr").find("[name^='PartitionSetup.preservation']");
- var container_uid = $(this).val();
- if(!container_uid || (container_uid.length == 1 && !container_uid[0])){
- $(target).prop("disabled", false);
- return;
- }
- container_uid = container_uid[0];
- if (container_uid === undefined || container_uid === null){
- container_uid='';
- }
- var request_data = {
- catalog_name: "uid_catalog",
- UID: container_uid
- };
- window.bika.lims.jsonapi_read(request_data, function(data) {
- if (data.objects.length < 1 ||
- (!data.objects[0].PrePreserved) || (!data.objects[0].Preservation)) {
- $(target).prop("disabled", false);
- } else {
- $(this).val(container_uid); // makes no sense to leave multiple items selected
- $(target).val(data.objects[0].Preservation);
- $(target).prop("disabled", true);
- }
- });
+ /*
+ * Controls the visibility and values of fields generated by Plone automatically.
+ */
+ catchOriginalValues = function() {
+ var calcuid, hidd, i, keyword, originals, request_data, rows, title, toremove, unit, value, wide;
+ $(manual_chk).attr('data-default', $(manual_chk).is(':checked'));
+ $(instr_chk).attr('data-default', $(instr_chk).is(':checked'));
+ $(methods_ms).attr('data-default', $(methods_ms).val());
+ $(method_sel).attr('data-default', $(method_sel).val());
+ $(instrs_ms).attr('data-default', $(instrs_ms).val());
+ $(instr_sel).attr('data-default', $(instr_sel).val());
+ $(default_calculation_chk).attr('data-default', $(default_calculation_chk).is(':checked'));
+ $(calculation_select_element).attr('data-default', $(calculation_select_element).val());
+ if (!$(manual_chk).is(':checked')) {
+ $(methods_fd).hide();
+ $(methods_ms).find('option[selected]').prop('selected', false);
+ $(methods_ms).val('');
+ }
+ if (!$(instr_chk).is(':checked')) {
+ $('#invalid-instruments-alert').remove();
+ $(instrs_fd).hide();
+ if ($(instrs_ms).find('option[value=""]').length === 0) {
+ $(instrs_ms).prepend('');
+ }
+ $(instrs_ms).val('');
+ $(instrs_ms).find('option[value=""]').prop('selected', true);
+ $(instr_fd).hide();
+ if ($(instr_sel).find('option[value=""]').length === 0) {
+ $(instr_sel).prepend('');
+ }
+ $(instr_sel).val('');
+ $(instr_sel).find('option[value=""]').prop('selected', true);
+ $(manual_chk).click(function(e) {
+ e.preventDefault();
});
-
- // update on first load
- // $(".portaltype-analysisservice [name^='PartitionSetup.separate']").change();
- // $(".portaltype-analysisservice [name^='Container']").change();
- // $(".portaltype-analysisservice [name^='PartitionSetup.container']").trigger("selected");
-
- // initial setup - hide Interim widget if no Calc is selected
-// This is commented because javascript halts execution in this block.
-// I think it's because this code fucks around with non-visible elements.
-// So the same question as always: How did this ever work, and how do
-// we replace it now.
-// if($(".portaltype-analysisservice #Calculation").val() === ""){
-// $("#InterimFields_more").click(); // blank last row
-// var rows = $("tr.records_row_InterimFields"); // Clear the rest
-// if($(rows).length > 1){
-// for (var i = $(rows).length - 2; i >= 0; i--) {
-// $($(rows)[i]).remove();
-// }
-// }
-// $("#archetypes-fieldname-InterimFields").hide();
-// return;
-// }
-
- // Check if there is, at least, one instrument available
- if ($(instrs_ms).find('option').length == 0) {
- // Ooops, there isn't any instrument!
- $(manual_chk).prop('checked', true);
- $(manual_chk).prop('readonly', true);
- $(instr_chk).prop('checked', false);
- $(instr_chk).prop('readonly', true);
- var errmsg = _("No instruments available");
- var title = _("Instrument entry of results option not allowed");
- var html = "
"+
- "
" + errmsg + ""+
- " " + title + ""+
- "";
- $('#analysisservice-base-edit').before(html);
+ }
+ if (!$(calculation_select_element).find(':selected').val()) {
+ $(interim_fd).hide();
+ }
+ $(methods_ms).find('option[value=""]').remove();
+ if (!$(default_calculation_chk).is(':checked')) {
+ $(calculation_label).show();
+ } else {
+ $(calculation_label).hide();
+ }
+ $('body').append('');
+ rows = $('tr.records_row_InterimFields');
+ originals = [];
+ if ($(rows).length > 1) {
+ i = $(rows).length - 2;
+ while (i >= 0) {
+ keyword = $($($(rows)[i]).find('td input')[0]).val();
+ if (keyword !== '') {
+ title = $($($(rows)[i]).find('td input')[1]).val();
+ value = $($($(rows)[i]).find('td input')[2]).val();
+ unit = $($($(rows)[i]).find('td input')[3]).val();
+ hidd = $($($(rows)[i]).find('td input')[4]).is(':checked');
+ wide = $($($(rows)[i]).find('td input')[5]).is(':checked');
+ originals.push([keyword, title, value, unit, hidd, wide]);
+ }
+ i--;
}
-
- // The 'Manual entry of results' value changes
- $(manual_chk).change(function() {
- if ($(this).is(':checked')) {
-
- // Insert all methods without instruments into the
- // methods InOut options widget.
- insert_manual_methods();
- $(methods_fd).fadeIn('slow');
- // Delegate remaining actions to Methods change event
- $(methods_ms).change();
-
- } else {
-
- // The method selection must be done by enabling the
- // 'Allow instrument entry of results'
-
- // Hide and clear the methods multiselector
- $(methods_fd).hide();
- $(methods_ms).find('option[selected]').prop('selected', false);
- $(methods_ms).val('');
-
- // Delegate remaining actions to Methods change event
- $(methods_ms).change();
-
- // Select instrument entry and fire event
- $(instr_chk).prop('checked', true);
+ }
+ toremove = [];
+ calcuid = '';
+ if ($(default_calculation_chk).is(':checked')) {
+ $(calculation_select_element).find('option').remove();
+ calcuid = $(calculation_select_element).attr('data-default');
+ }
+ if (calcuid !== null && calcuid !== '') {
+ request_data = {
+ catalog_name: 'bika_setup_catalog',
+ UID: calcuid
+ };
+ window.bika.lims.jsonapi_read(request_data, function(data) {
+ var manualinterims, row;
+ if (data.objects.length > 0) {
+ $(calculation_select_element).append('');
+ $(calculation_select_element).val(data.objects[0].UID);
+ $(calculation_select_element).find('option').attr('selected', 'selected');
+ i = 0;
+ while (i < data.objects[0].InterimFields.length) {
+ row = data.objects[0].InterimFields[i];
+ toremove.push(row.keyword);
+ i++;
}
- $(instr_chk).change();
+ } else {
+ $(calculation_select_element).append('');
+ $(calculation_select_element).val('');
+ }
+ manualinterims = originals.filter(function(el) {
+ return toremove.indexOf(el[0]) < 0;
+ });
+ $('#temp_manual_interims').val($.toJSON(manualinterims));
});
+ }
+ };
- // The 'Allow instrument entry of results' value changes
- $(instr_chk).change(function() {
- if ($(this).is(':checked')) {
-
- // The user must select the instruments supported by
- // this Analysis Service. The default method will be
- // retrieved from the default instrument selected.
-
- // The user must be able to allow manual entry
- $(manual_chk).unbind("click");
-
- // Show the instruments multiselector
- $(instrs_fd).fadeIn('slow');
-
- // Remove the 'none' option from instruments multiselector
- $(instrs_ms).find('option[value=""]').remove();
-
- // Remove the 'none' option from def instrument selector
- $(instr_sel).find('option[value=""]').remove();
-
- // Show the default instrument selector
- $(instr_fd).fadeIn('slow');
-
- // Disable the default method selector
- $(method_sel).focus(function(e) {
- $(this).blur();
- });
-
- // Disable the default calculation selector
- $(calculation_select_element).focus(function(e) {
- $(this).blur();
- });
-
- // Delegate remaining actions to Instruments change event
- $(instrs_ms).change();
-
- } else {
-
- // The method selection must be done manually, by
- // selecting the methods for which this Analysis Service
- // has support.
-
- // Remove the invalid instrument alert (if exists)
- $('#invalid-instruments-alert').remove();
-
- // Hide the instruments multiselector and unselect all
- $(instrs_fd).hide();
- if ($(instrs_ms).find('option[value=""]').length == 0) {
- $(instrs_ms).prepend('');
- }
- $(instrs_ms).val('');
- $(instrs_ms).find('option[value=""]').prop("selected", true);
-
- // Hide the default instrument selector
- $(instr_fd).hide();
-
- // Unselect the default instrument
- if ($(instr_sel).find('option[value=""]').length == 0) {
- $(instr_sel).prepend('');
- }
- $(instr_sel).val('');
- $(instr_sel).find('option[value=""]').prop("selected", true);
-
- // The user mustn't be allowed to unset manual entry
- $(manual_chk).click(function(e) {
- e.preventDefault();
- });
-
- // The user must be able to select the default method manualy
- $(methods_ms).change();
- $(method_sel).unbind("focus");
-
- // If manual entry is not selected, select it and
- // fire event cascade
- if (!$(manual_chk).is(':checked')) {
- $(manual_chk).prop('checked', true);
- $(manual_chk).change();
- }
+ /*
+ * Loads the Interim fields Widget for the specificied calculation
+ */
+ loadInterims = function(calcuid) {
+ var i, request_data, rows;
+ $(interim_fd).hide();
+ if (calcuid === null || calcuid === '') {
+ $('#InterimFields_more').click();
+ rows = $('tr.records_row_InterimFields');
+ if ($(rows).length > 1) {
+ i = $(rows).length - 2;
+ while (i >= 0) {
+ $($(rows)[i]).remove();
+ i--;
+ }
+ }
+ $(interim_fd).hide();
+ return;
+ }
+ request_data = {
+ catalog_name: 'bika_setup_catalog',
+ UID: calcuid
+ };
+ window.bika.lims.jsonapi_read(request_data, function(data) {
+ var _rows, hidd, j, k, keyword, manualinterims, original, originals, row, unit, value, wide;
+ $('#InterimFields_more').click();
+ _rows = $('tr.records_row_InterimFields');
+ originals = [];
+ if ($(_rows).length > 1) {
+ i = $(_rows).length - 2;
+ while (i >= 0) {
+ keyword = $($($(_rows)[i]).find('td input')[0]).val();
+ if (keyword !== '') {
+ value = $($($(_rows)[i]).find('td input')[2]).val();
+ unit = $($($(_rows)[i]).find('td input')[3]).val();
+ hidd = $($($(_rows)[i]).find('td input')[4]).is(':checked');
+ wide = $($($(_rows)[i]).find('td input')[5]).is(':checked');
+ originals.push([keyword, value, unit, hidd, wide]);
}
- });
-
- // The methods multiselect changes
- $(methods_ms).change(function(e) {
- var prevmethod = $(method_sel).val();
- var prevmethodtxt = $(method_sel).find('option[value="'+prevmethod+'"]').html();
- /*if ($(this).val() == null) {
- // At least one method must be selected
- $(this).val($(this).find('option').first().val());
- }*/
-
- // If it has default Instrument, Default method can be only one of that Default Instrument's methods. Do
- // not do anything.
- if ($(instr_chk).is(':checked')) {
- $(method_sel).change(function(e) {
- // Delegate actions to Default Calculation change event
- $(default_calculation_chk).change();
- });
- return;
+ $($(_rows)[i]).remove();
+ i--;
+ }
+ }
+ if (data.objects.length > 0) {
+ $(interim_fd).fadeIn('slow');
+ $('[id^=\'InterimFields-keyword-\']').attr('id', 'InterimFields-keyword-0');
+ $('[id^=\'InterimFields-title-\']').attr('id', 'InterimFields-title-0');
+ $('[id^=\'InterimFields-value-\']').attr('id', 'InterimFields-value-0');
+ $('[id^=\'InterimFields-unit-\']').attr('id', 'InterimFields-unit-0');
+ i = 0;
+ while (i < data.objects[0].InterimFields.length) {
+ row = data.objects[0].InterimFields[i];
+ original = null;
+ j = 0;
+ while (j < originals.length) {
+ if (originals[j][0] === row.keyword) {
+ original = originals[j];
+ break;
+ }
+ j++;
}
-
- $(method_sel).find('option').remove();
-
- // Populate with the methods from the multi-select
- var methods = $(methods_ms).val();
- if (methods != null) {
- $.each(methods, function(index, value) {
- var option = $(methods_ms).find('option[value="'+value+'"]').clone();
- $(method_sel).append(option);
- });
+ $('#InterimFields-keyword-' + i).val(row.keyword);
+ $('#InterimFields-title-' + i).val(row.title);
+ if (original === null) {
+ $('#InterimFields-value-' + i).val(row.value);
+ $('#InterimFields-unit-' + i).val(row.unit);
} else {
- $(method_sel).prepend('');
- }
-
- // Select the previously selected method or the first one
- defoption = $(method_sel).find('option[value="'+$(method_sel).attr('data-default')+'"]');
- if (defoption == null || defoption == '') {
- defoption = $(method_sel).find('option[value="'+prevmethod+'"]');
- if (defoption == null || defoption == '') {
- defoption = $(method_sel).find('option').first();
- }
- }
-
- // Delegate remaining actions to Method change event
- $(method_sel).change();
- });
-
- $(method_sel).change(function(e) {
- // Delegate actions to Default Calculation change event
- $(default_calculation_chk).change();
- });
-
-
- // The instruments multiselect changes
- $(instrs_ms).change(function(e) {
- var previnstr = $(instr_sel).val();
- if ($(this).val() == null) {
- // At least one instrument must be selected
- $(this).val($(this).find('option').first().val());
+ $('#InterimFields-value-' + i).val(original[1]);
+ $('#InterimFields-unit-' + i).val(original[2]);
}
+ $('#InterimFields_more').click();
+ i++;
+ }
+ }
+ manualinterims = $.parseJSON($('#temp_manual_interims').val());
+ if (manualinterims.length > 0) {
+ $(interim_fd).fadeIn('slow');
+ i = $('tr.records_row_InterimFields').length - 1;
+ k = 0;
+ while (k < manualinterims.length) {
+ $('#InterimFields-keyword-' + i).val(manualinterims[k][0]);
+ $('#InterimFields-title-' + i).val(manualinterims[k][1]);
+ $('#InterimFields-value-' + i).val(manualinterims[k][2]);
+ $('#InterimFields-unit-' + i).val(manualinterims[k][3]);
+ $('#InterimFields_more').click();
+ i++;
+ k++;
+ }
+ }
+ });
+ };
- // Populate the default instrument list with the selected instruments
- $(instr_sel).find('option').remove();
- var insts = $(instrs_ms).val();
- $.each(insts, function(index, value) {
- var option = $(instrs_ms).find('option[value="'+value+'"]').clone();
- $(instr_sel).append(option);
- });
-
- // Select the previously selected instrument or the first one
- defoption = $(instr_sel).find('option[value="'+previnstr+'"]');
- if (defoption == null || defoption == '') {
- defoption = $(instr_sel).find('option[value="'+$(instr_sel).attr('data-default')+'"]');
- if (defoption == null || defoption == '') {
- defoption = $(instr_sel).find('option').first();
- }
+ /*
+ * Checks if the selected instruments aren't out-of-date and their
+ * latest Internal Calibration Tests are valid. If an invalid
+ * instrument gets selected, shows an alert to the user
+ */
+ validateInstruments = function() {
+ var _, insts;
+ $('#invalid-instruments-alert').remove();
+ if ($('#InstrumentEntryOfResults').is(':checked')) {
+ window.jarn.i18n.loadCatalog('bika');
+ _ = window.jarn.i18n.MessageFactory('bika');
+ insts = $('#Instruments').val() ? $('#Instruments').val() : [];
+ $.each(insts, function(index, value) {
+ var request_data;
+ request_data = {
+ catalog_name: 'uid_catalog',
+ UID: value
+ };
+ window.bika.lims.jsonapi_read(request_data, function(data) {
+ var errmsg, html, instrument_path, title;
+ if (data.objects[0].Valid !== '1') {
+ title = data.objects[0].Title;
+ instrument_path = window.location.protocol + '//' + window.location.host + data.objects[0].path;
+ if ($('#invalid-instruments-alert').length > 0) {
+ $('#invalid-instruments-alert dd').first().append(', ' + title);
+ } else {
+ errmsg = _('Some of the selected instruments are out-of-date or with failed calibration tests');
+ html = '';
+ $('#analysisservice-base-edit').before(html);
+ }
}
- $(instr_sel).val($(defoption).val());
-
- // Check if out-of-date or QC-fail instruments have been
- // selected.
- $('#invalid-instruments-alert').remove();
- $.each(insts, function(index, value) {
- // Is valid?
- if (value != '' && $(instr_chk).is(':checked')) {
- var request_data = {
- catalog_name: "uid_catalog",
- UID: value
- };
- window.bika.lims.jsonapi_read(request_data, function(data) {
- if (!$(instr_chk).is(':checked')) {
- $('#invalid-instruments-alert').remove();
- } else if (data.objects[0].Valid != '1') {
- var title = data.objects[0].Title;
- var instrument_path = window.location.protocol + "//" + window.location.host + data.objects[0].path;
- if ($('#invalid-instruments-alert').length > 0) {
- $('#invalid-instruments-alert dd').first().append(", " + title);
- } else {
- var errmsg = _("Some of the selected instruments are out-of-date or with failed calibration tests");
- var html = "";
- $('#analysisservice-base-edit').before(html);
- }
- }
- });
- }
- });
-
- // Delegate remaining actions to Instrument change event
- $(instr_sel).change();
- });
-
-
- // The instrument selector changes
- $(instr_sel).change(function() {
- // Clear and disable the method list and populate with the
- // method assigned to the selected instrument
- $(method_sel).find('option').remove();
- $(method_sel).append("");
- $(method_sel).val('');
- $.ajax({
- url: window.portal_url + "/get_instrument_methods",
- type: 'POST',
- data: {'_authenticator': $('input[name="_authenticator"]').val(),
- 'uid': $(instr_sel).val() },
- dataType: 'json',
- async: false
- }).done(function(data) {
- $(method_sel).find('option').remove();
- // Handle multiple methods
- if (data != null && data.methods.length > 0) {
- // Set the instrument's methods
- $.each(data.methods, function(index, value) {
- var uid = value.uid;
- var title = value.title;
- console.debug("Adding Method " + title + " to the Selection");
- var option = '';
- $(method_sel).append(option);
- $(method_sel).val(uid);
- });
- } else {
- // Oooopps. The instrument has no method assigned
- $(method_sel).append("");
- $(method_sel).val('');
- }
- // Delegate the action to Default Calc change event
- $(default_calculation_chk).change();
- });
+ });
});
-
-
- // The 'Default Calculation' checkbox changes
- $(default_calculation_chk).change(function() {
-
- if ($(this).is(':checked')) {
-
- // Using default calculation.
- // So, we deny access to the "Calculation" selection field.
- $(calculation_label).hide();
-
- // Load the calculation for the selected method
- var muid = $(method_sel).val();
- if (muid != null && muid != '') {
- // A valid method was selected
- $.ajax({
- url: window.portal_url + "/get_method_calculation",
- type: 'POST',
- data: {'_authenticator': $('input[name="_authenticator"]').val(),
- 'uid': muid },
- dataType: 'json'
- }).done(function(data) {
- $(calculation_select_element).find('option').remove();
- if (data != null && data['uid']) {
- $(calculation_select_element).prepend('');
- } else {
- $(calculation_select_element).append('');
- }
- $(calculation_select_element).val($(calculation_select_element).find('option').first().val());
-
- // Delegate the action to Default Calculation change event
- $(calculation_select_element).change();
- });
- } else {
- $(calculation_select_element).find('option').remove();
- $(calculation_select_element).append('');
- $(calculation_select_element).change();
- }
+ } else {
+ loadEmptyInstrument();
+ }
+ };
+ updateContainers = function(target, requestdata) {
+ $.ajax({
+ type: 'POST',
+ url: window.location.href + '/getUpdatedContainers',
+ data: requestdata,
+ success: function(data) {
+ var option;
+ option = $(target).val();
+ if (option === null || option === void 0) {
+ option = [];
+ }
+ $(target).empty();
+ $.each(data, function(i, v) {
+ if ($.inArray(v[0], option) > -1) {
+ $(target).append('');
} else {
- $(calculation_select_element).find('option').remove();
- $(calculation_select_element).append('');
- $(calculation_select_element).val('');
-
- // Unselected "Use Default Calculation"
- // So, we allow selection of calculation manually and fill the list with the all available Calculations
- // in the system.
- $(calculation_label).show();
- //$(calculation_select_element).prop('disabled', false);
-
- // Get available Calculations from Bika
- $.ajax({
- url: window.portal_url + "/get_available_calculations",
- type: 'POST',
- data: {'_authenticator': $('input[name="_authenticator"]').val()},
- dataType: 'json'
- }).done(function(data) {
- $(calculation_select_element).find('option').remove();
- if (data != null) {
- for(i=0; i'+data[i]['title']+'');
- }
- } else {
- $(calculation_select_element).append('');
- }
- $(calculation_select_element).val($(calculation_select_element).find('option').first().val());
-
- // Delegate the action to Default Calculation change event
- $(calculation_select_element).change();
- });
+ $(target).append('');
}
+ });
+ },
+ dataType: 'json'
+ });
+ };
+ applyStyles = function() {
+ $($(manual_fd)).after($(methods_fd));
+ $(methods_fd).css('border', '1px solid #cfcfcf').css('background-color', '#efefef').css('padding', '10px').css('margin-bottom', '20px');
+ $(instrs_fd).css('border', '1px solid #cfcfcf').css('border-bottom', 'none').css('background-color', '#efefef').css('padding', '10px').css('margin-bottom', '0px');
+ $(instr_fd).css('border', '1px solid #cfcfcf').css('border-top', 'none').css('background-color', '#efefef').css('padding', '10px').css('margin-bottom', '20px');
+ };
+ that.load = function() {
+ var errmsg, html, title;
+ $(ldsel_chk).change(function() {
+ if ($(this).is(':checked')) {
+ $(ldman_fd).show();
+ } else {
+ $(ldman_fd).hide();
+ $(ldman_chk).prop('checked', false);
+ }
+ });
+ $(ldsel_chk).change();
+ $('.portaltype-analysisservice #RequiredVolume, .portaltype-analysisservice #Separate').change(function() {
+ var requestdata, separate;
+ separate = $('#Separate').prop('checked');
+ if (!separate) {
+ $('[name=\'Preservation\\:list\']').prop('disabled', false);
+ }
+ requestdata = {
+ 'allow_blank': true,
+ 'show_container_types': !separate,
+ 'show_containers': separate,
+ '_authenticator': $('input[name=\'_authenticator\']').val()
+ };
+ updateContainers('#Container\\:list', requestdata);
+ });
+ $('.portaltype-analysisservice [name^=\'PartitionSetup.separate\'],.portaltype-analysisservice [name^=\'PartitionSetup.vol\']').change(function() {
+ var minvol, requestdata, separate, target;
+ separate = $(this).parents('tr').find('[name^=\'PartitionSetup.separate\']').prop('checked');
+ if (!separate) {
+ $(this).parents('tr').find('[name^=\'PartitionSetup.preservation\']').prop('disabled', false);
+ }
+ minvol = $(this).parents('tr').find('[name^=\'PartitionSetup.vol\']').val();
+ target = $(this).parents('tr').find('[name^=\'PartitionSetup.container\']');
+ requestdata = {
+ 'allow_blank': true,
+ 'minvol': minvol,
+ 'show_container_types': !separate,
+ 'show_containers': separate,
+ '_authenticator': $('input[name=\'_authenticator\']').val()
+ };
+ updateContainers(target, requestdata);
+ });
+ $('.portaltype-analysisservice [name^=\'PartitionSetup.sampletype\']').change(function() {
+ var request_data, st_element;
+ st_element = this;
+ request_data = {
+ catalog_name: 'uid_catalog',
+ UID: $(this).val()
+ };
+ window.bika.lims.jsonapi_read(request_data, function(data) {
+ var minvol, target;
+ minvol = data.objects[0].MinimumVolume;
+ target = $(st_element).parents('tr').find('[name^=\'PartitionSetup.vol\']');
+ $(target).val(minvol);
+ $(st_element).parents('tr').find('[name^=\'PartitionSetup.container\']').change();
});
-
- // The 'Default calculation' changes
- $(calculation_select_element).change(function() {
- loadInterims($(this).val());
+ });
+ $('.portaltype-analysisservice #Container').bind('selected', function() {
+ var container_uid, request_data;
+ container_uid = $(this).attr('uid');
+ if (container_uid === void 0 || container_uid === null) {
+ container_uid = '';
+ }
+ request_data = {
+ catalog_name: 'uid_catalog',
+ UID: container_uid
+ };
+ window.bika.lims.jsonapi_read(request_data, function(data) {
+ if (data.objects.length < 1 || !data.objects[0].PrePreserved || !data.objects[0].Preservation) {
+ $('#Preservation').val('');
+ $('#Preservation').prop('disabled', false);
+ } else {
+ $('#Preservation').val(data.objects[0].Preservation);
+ $('#Preservation').prop('disabled', true);
+ }
});
-
- // Apply default styling
- applyStyles();
-
- // Grab original values
- catchOriginalValues();
- }
-
- function insert_manual_methods(){
- $.ajax({
- url: window.portal_url + "/get_instrument_methods",
- type: 'POST',
- data: {'_authenticator': $('input[name="_authenticator"]').val(),
- 'uid': $(instr_sel).val() },
- dataType: 'json',
- async: false
- }).done(function(data) {
- $(method_sel).find('option').remove();
- // Handle multiple methods
-
- if (data != null && data.methods.length > 0) {
- // Set the instrument's methods
- $.each(data.methods, function(index, value) {
- var uid = value.uid;
- var title = value.title;
- console.debug("Adding Method " + title + " to the Selection");
- var option = '';
- $(method_sel).append(option);
- $(method_sel).val(uid);
- });
- } else {
- // Oooopps. The instrument has no method assigned
- $(method_sel).append("");
- $(method_sel).val('');
- }
- // Delegate the action to Default Calc change event
- $(default_calculation_chk).change();
+ });
+ $('.portaltype-analysisservice [name^=\'PartitionSetup.container\']').change(function() {
+ var container_uid, request_data, target;
+ target = $(this).parents('tr').find('[name^=\'PartitionSetup.preservation\']');
+ container_uid = $(this).val();
+ if (!container_uid || container_uid.length === 1 && !container_uid[0]) {
+ $(target).prop('disabled', false);
+ return;
+ }
+ container_uid = container_uid[0];
+ if (container_uid === void 0 || container_uid === null) {
+ container_uid = '';
+ }
+ request_data = {
+ catalog_name: 'uid_catalog',
+ UID: container_uid
+ };
+ window.bika.lims.jsonapi_read(request_data, function(data) {
+ if (data.objects.length < 1 || !data.objects[0].PrePreserved || !data.objects[0].Preservation) {
+ $(target).prop('disabled', false);
+ } else {
+ $(this).val(container_uid);
+ $(target).val(data.objects[0].Preservation);
+ $(target).prop('disabled', true);
+ }
});
- }
-
- /**
- * Controls the visibility and values of fields generated by Plone automatically.
- */
- function catchOriginalValues() {
- $(manual_chk).attr('data-default', $(manual_chk).is(':checked'));
- $(instr_chk).attr('data-default', $(instr_chk).is(':checked'));
- $(methods_ms).attr('data-default', $(methods_ms).val());
- $(method_sel).attr('data-default', $(method_sel).val());
- $(instrs_ms).attr('data-default', $(instrs_ms).val());
- $(instr_sel).attr('data-default', $(instr_sel).val());
- $(default_calculation_chk).attr('data-default', $(default_calculation_chk).is(':checked'));
- $(calculation_select_element).attr('data-default', $(calculation_select_element).val());
-
- // If manual entry is disabled, hide and clear the methods multiselector
- if (!$(manual_chk).is(':checked')) {
- $(methods_fd).hide();
- $(methods_ms).find('option[selected]').prop('selected', false);
- $(methods_ms).val('');
+ });
+ if ($(instrs_ms).find('option').length === 0) {
+ $(manual_chk).prop('checked', true);
+ $(manual_chk).prop('readonly', true);
+ $(instr_chk).prop('checked', false);
+ $(instr_chk).prop('readonly', true);
+ errmsg = _('No instruments available');
+ title = _('Instrument entry of results option not allowed');
+ html = '' + '
' + errmsg + '' + '' + title + '' + '';
+ $('#analysisservice-base-edit').before(html);
+ }
+ $(manual_chk).change(function() {
+ if ($(this).is(':checked')) {
+ insert_manual_methods();
+ $(methods_fd).fadeIn('slow');
+ $(methods_ms).change();
+ } else {
+ $(methods_fd).hide();
+ $(methods_ms).find('option[selected]').prop('selected', false);
+ $(methods_ms).val('');
+ $(methods_ms).change();
+ $(instr_chk).prop('checked', true);
}
-
- // If Instrument assignment is disabled, hide and clear everything related with instruments.
- if (!$(instr_chk).is(':checked')) {
- $('#invalid-instruments-alert').remove();
-
- // Hide the instruments multiselector and unselect all
- $(instrs_fd).hide();
- if ($(instrs_ms).find('option[value=""]').length == 0) {
- $(instrs_ms).prepend('');
- }
- $(instrs_ms).val('');
- $(instrs_ms).find('option[value=""]').prop("selected", true);
-
- // Hide the default instrument selector
- $(instr_fd).hide();
-
- // Unselect the default instrument
- if ($(instr_sel).find('option[value=""]').length == 0) {
- $(instr_sel).prepend('');
- }
- $(instr_sel).val('');
- $(instr_sel).find('option[value=""]').prop("selected", true);
-
- // The user mustn't be allowed to unset manual entry
- $(manual_chk).click(function(e) {
- e.preventDefault();
- });
+ $(instr_chk).change();
+ });
+ $(instr_chk).change(function() {
+ if ($(this).is(':checked')) {
+ $(manual_chk).unbind('click');
+ $(instrs_fd).fadeIn('slow');
+ $(instrs_ms).find('option[value=""]').remove();
+ $(instr_sel).find('option[value=""]').remove();
+ $(instr_fd).fadeIn('slow');
+ $(method_sel).focus(function(e) {
+ $(this).blur();
+ });
+ $(calculation_select_element).focus(function(e) {
+ $(this).blur();
+ });
+ $(instrs_ms).change();
+ } else {
+ $('#invalid-instruments-alert').remove();
+ $(instrs_fd).hide();
+ if ($(instrs_ms).find('option[value=""]').length === 0) {
+ $(instrs_ms).prepend('');
+ }
+ $(instrs_ms).val('');
+ $(instrs_ms).find('option[value=""]').prop('selected', true);
+ $(instr_fd).hide();
+ if ($(instr_sel).find('option[value=""]').length === 0) {
+ $(instr_sel).prepend('');
+ }
+ $(instr_sel).val('');
+ $(instr_sel).find('option[value=""]').prop('selected', true);
+ $(manual_chk).click(function(e) {
+ e.preventDefault();
+ });
+ $(methods_ms).change();
+ $(method_sel).unbind('focus');
+ if (!$(manual_chk).is(':checked')) {
+ $(manual_chk).prop('checked', true);
+ $(manual_chk).change();
+ }
}
+ });
+ $(methods_ms).change(function(e) {
+ var defoption, methods, prevmethod, prevmethodtxt;
+ prevmethod = $(method_sel).val();
+ prevmethodtxt = $(method_sel).find('option[value="' + prevmethod + '"]').html();
- // If there is no calculation assigned, hide interim fields section.
- if(!$(calculation_select_element).find(":selected").val()){
- $(interim_fd).hide();
+ /*if ($(this).val() == null) {
+ // At least one method must be selected
+ $(this).val($(this).find('option').first().val());
}
- // Remove 'None' option from 'Methods' multi-select
- $(methods_ms).find('option[value=""]').remove();
-
-
- // Toggle default/alternative calculation
- if (!$(default_calculation_chk).is(':checked')) {
- $(calculation_label).show();
+ */
+ if ($(instr_chk).is(':checked')) {
+ $(method_sel).change(function(e) {
+ $(default_calculation_chk).change();
+ });
+ return;
+ }
+ $(method_sel).find('option').remove();
+ methods = $(methods_ms).val();
+ if (methods !== null) {
+ $.each(methods, function(index, value) {
+ var option;
+ option = $(methods_ms).find('option[value="' + value + '"]').clone();
+ $(method_sel).append(option);
+ });
} else {
- $(calculation_label).hide();
+ $(method_sel).prepend('');
}
-
- // Save the manually entered interims to keep them if another
- // calculation is set. We need to know which interim fields
- // are from the current selected calculation and which of them
- // have been set manually.
- $('body').append("");
- rows = $("tr.records_row_InterimFields");
- var originals = [];
- if($(rows).length > 1){
- for (i = $(rows).length - 2; i >= 0; i--) {
- // Get the original values
- var keyword = $($($(rows)[i]).find('td input')[0]).val();
- if (keyword != '') {
- var title = $($($(rows)[i]).find('td input')[1]).val();
- var value = $($($(rows)[i]).find('td input')[2]).val();
- var unit = $($($(rows)[i]).find('td input')[3]).val();
- var hidd = $($($(rows)[i]).find('td input')[4]).is(':checked');
- var wide = $($($(rows)[i]).find('td input')[5]).is(':checked');
- originals.push([keyword, title, value, unit, hidd, wide]);
- }
- }
+ defoption = $(method_sel).find('option[value="' + $(method_sel).attr('data-default') + '"]');
+ if (defoption === null || defoption === '') {
+ defoption = $(method_sel).find('option[value="' + prevmethod + '"]');
+ if (defoption === null || defoption === '') {
+ defoption = $(method_sel).find('option').first();
+ }
}
- var toremove = []
- var calcuid = "";
- if ($(default_calculation_chk).is(':checked')) {
- $(calculation_select_element).find('option').remove();
- calcuid = $(calculation_select_element).attr('data-default');
+ $(method_sel).change();
+ });
+ $(method_sel).change(function(e) {
+ $(default_calculation_chk).change();
+ });
+ $(instrs_ms).change(function(e) {
+ var defoption, insts, previnstr;
+ previnstr = $(instr_sel).val();
+ if ($(this).val() === null) {
+ $(this).val($(this).find('option').first().val());
+ }
+ $(instr_sel).find('option').remove();
+ insts = $(instrs_ms).val();
+ $.each(insts, function(index, value) {
+ var option;
+ option = $(instrs_ms).find('option[value="' + value + '"]').clone();
+ $(instr_sel).append(option);
+ });
+ defoption = $(instr_sel).find('option[value="' + previnstr + '"]');
+ if (defoption === null || defoption === '') {
+ defoption = $(instr_sel).find('option[value="' + $(instr_sel).attr('data-default') + '"]');
+ if (defoption === null || defoption === '') {
+ defoption = $(instr_sel).find('option').first();
+ }
}
- if (calcuid != null && calcuid != '') {
- var request_data = {
- catalog_name: "bika_setup_catalog",
- UID: calcuid
+ $(instr_sel).val($(defoption).val());
+ $('#invalid-instruments-alert').remove();
+ $.each(insts, function(index, value) {
+ var request_data;
+ if (value !== '' && $(instr_chk).is(':checked')) {
+ request_data = {
+ catalog_name: 'uid_catalog',
+ UID: value
};
window.bika.lims.jsonapi_read(request_data, function(data) {
- if (data.objects.length > 0) {
- $(calculation_select_element).append('');
- $(calculation_select_element).val(data.objects[0].UID);
- $(calculation_select_element).find('option').attr('selected','selected');
- for (i = 0; i < data.objects[0].InterimFields.length; i++) {
- var row = data.objects[0].InterimFields[i];
- toremove.push(row.keyword);
- }
- // When a field is disabled, its setter is not called at all. Thus,
- //we must avoid use of disabling fields.
- //$(calculation_select_element).attr('disabled',true);
+ var title;
+ var errmsg;
+ var html;
+ var instrument_path;
+ if (!$(instr_chk).is(':checked')) {
+ $('#invalid-instruments-alert').remove();
+ } else if (data.objects[0].Valid !== '1') {
+ title = data.objects[0].Title;
+ instrument_path = window.location.protocol + '//' + window.location.host + data.objects[0].path;
+ if ($('#invalid-instruments-alert').length > 0) {
+ $('#invalid-instruments-alert dd').first().append(', ' + title);
} else {
- $(calculation_select_element).append('');
- $(calculation_select_element).val('');
+ errmsg = _('Some of the selected instruments are out-of-date or with failed calibration tests');
+ html = '';
+ $('#analysisservice-base-edit').before(html);
}
- var manualinterims = originals.filter(function(el) {
- return toremove.indexOf(el[0]) < 0;
- });
- // Save the manualinterims in some hidden place
- $('#temp_manual_interims').val($.toJSON(manualinterims));
+ }
});
- }
- }
-
- /**
- * Loads the Interim fields Widget for the specificied calculation
- */
- function loadInterims(calcuid) {
- $(interim_fd).hide();
- var rows, i;
- if (calcuid == null || calcuid == ""){
- $("#InterimFields_more").click(); // blank last row
- rows = $("tr.records_row_InterimFields"); // Clear the rest
- if($(rows).length > 1){
- for (i = $(rows).length - 2; i >= 0; i--) {
- $($(rows)[i]).remove();
- }
- }
- $(interim_fd).hide();
- return;
- }
- var request_data = {
- catalog_name: "bika_setup_catalog",
- UID: calcuid
- };
- window.bika.lims.jsonapi_read(request_data, function(data) {
- // Clear rows
- var rows, i;
- $("#InterimFields_more").click(); // blank last row
- rows = $("tr.records_row_InterimFields");
- var originals = [];
- if($(rows).length > 1){
- for (i = $(rows).length - 2; i >= 0; i--) {
- // Save the original values
- var keyword = $($($(rows)[i]).find('td input')[0]).val();
- if (keyword != '') {
- var value = $($($(rows)[i]).find('td input')[2]).val();
- var unit = $($($(rows)[i]).find('td input')[3]).val();
- var hidd = $($($(rows)[i]).find('td input')[4]).is(':checked');
- var wide = $($($(rows)[i]).find('td input')[5]).is(':checked');
- originals.push([keyword, value, unit, hidd, wide]);
- }
- $($(rows)[i]).remove();
- }
- }
-
- if (data.objects.length > 0) {
- $(interim_fd).fadeIn('slow');
- $("[id^='InterimFields-keyword-']").attr("id", "InterimFields-keyword-0");
- $("[id^='InterimFields-title-']").attr("id", "InterimFields-title-0");
- $("[id^='InterimFields-value-']").attr("id", "InterimFields-value-0");
- $("[id^='InterimFields-unit-']").attr("id", "InterimFields-unit-0");
-
- for (i = 0; i < data.objects[0].InterimFields.length; i++) {
- var row = data.objects[0].InterimFields[i];
- var original = null;
- for (j = 0; j < originals.length; j++) {
- if (originals[j][0] == row.keyword) {
- original = originals[j]; break;
- }
- }
- $("#InterimFields-keyword-"+i).val(row.keyword);
- $("#InterimFields-title-"+i).val(row.title);
- if (original == null) {
- $("#InterimFields-value-"+i).val(row.value);
- $("#InterimFields-unit-"+i).val(row.unit);
- } else {
- $("#InterimFields-value-"+i).val(original[1]);
- $("#InterimFields-unit-"+i).val(original[2]);
- }
- $("#InterimFields_more").click();
- }
- }
-
- // Manually entered results?
- var manualinterims = $.parseJSON($('#temp_manual_interims').val());
- if (manualinterims.length > 0) {
- $(interim_fd).fadeIn('slow');
- var i = $("tr.records_row_InterimFields").length-1;
- for (k = 0; k < manualinterims.length; k++) {
- $("#InterimFields-keyword-"+i).val(manualinterims[k][0]);
- $("#InterimFields-title-"+i).val(manualinterims[k][1]);
- $("#InterimFields-value-"+i).val(manualinterims[k][2]);
- $("#InterimFields-unit-"+i).val(manualinterims[k][3]);
- $("#InterimFields_more").click();
- i++;
- }
- }
+ }
});
- }
-
-
- /**
- * Checks if the selected instruments aren't out-of-date and their
- * latest Internal Calibration Tests are valid. If an invalid
- * instrument gets selected, shows an alert to the user
- */
- function validateInstruments() {
- $('#invalid-instruments-alert').remove();
- if ($('#InstrumentEntryOfResults').is(':checked')) {
- window.jarn.i18n.loadCatalog("bika");
- var _ = window.jarn.i18n.MessageFactory("bika");
- var insts = $('#Instruments').val() ? $('#Instruments').val() : [];
- $.each(insts, function(index, value) {
- // Is valid?
- var request_data = {
- catalog_name: "uid_catalog",
- UID: value
- };
- window.bika.lims.jsonapi_read(request_data, function(data) {
- if (data.objects[0].Valid != '1') {
- var title = data.objects[0].Title;
- var instrument_path = window.location.protocol + "//" + window.location.host + data.objects[0].path;
- if ($('#invalid-instruments-alert').length > 0) {
- $('#invalid-instruments-alert dd').first().append(", " + title);
- } else {
- var errmsg = _("Some of the selected instruments are out-of-date or with failed calibration tests");
- var html = "";
- $('#analysisservice-base-edit').before(html);
- }
- }
- });
+ $(instr_sel).change();
+ });
+ $(instr_sel).change(function() {
+ $(method_sel).find('option').remove();
+ $(method_sel).append('');
+ $(method_sel).val('');
+ $.ajax({
+ url: window.portal_url + '/get_instrument_methods',
+ type: 'POST',
+ data: {
+ '_authenticator': $('input[name="_authenticator"]').val(),
+ 'uid': $(instr_sel).val()
+ },
+ dataType: 'json',
+ async: false
+ }).done(function(data) {
+ $(method_sel).find('option').remove();
+ if (data !== null && data.methods.length > 0) {
+ $.each(data.methods, function(index, value) {
+ var title;
+ var option, uid;
+ uid = value.uid;
+ title = value.title;
+ console.debug('Adding Method ' + title + ' to the Selection');
+ option = '';
+ $(method_sel).append(option);
+ $(method_sel).val(uid);
});
+ } else {
+ $(method_sel).append('');
+ $(method_sel).val('');
+ }
+ $(default_calculation_chk).change();
+ });
+ });
+ $(default_calculation_chk).change(function() {
+ var muid;
+ if ($(this).is(':checked')) {
+ $(calculation_label).hide();
+ muid = $(method_sel).val();
+ if (muid !== null && muid !== '') {
+ $.ajax({
+ url: window.portal_url + '/get_method_calculation',
+ type: 'POST',
+ data: {
+ '_authenticator': $('input[name="_authenticator"]').val(),
+ 'uid': muid
+ },
+ dataType: 'json'
+ }).done(function(data) {
+ $(calculation_select_element).find('option').remove();
+ if (data !== null && data['uid']) {
+ $(calculation_select_element).prepend('');
+ } else {
+ $(calculation_select_element).append('');
+ }
+ $(calculation_select_element).val($(calculation_select_element).find('option').first().val());
+ $(calculation_select_element).change();
+ });
+ } else {
+ $(calculation_select_element).find('option').remove();
+ $(calculation_select_element).append('');
+ $(calculation_select_element).change();
+ }
} else {
- loadEmptyInstrument();
- }
- }
-
-
- function updateContainers(target,requestdata){
- $.ajax({
- type: "POST",
- url: window.location.href + "/getUpdatedContainers",
- data: requestdata,
- success: function(data){
- // keep the current selection if possible
- var option = $(target).val();
- if (option === null || option === undefined){
- option = [];
- }
- $(target).empty();
- $.each(data, function(i,v){
- if($.inArray(v[0], option) > -1) {
- $(target).append("");
- } else {
- $(target).append("");
- }
- });
+ $(calculation_select_element).find('option').remove();
+ $(calculation_select_element).append('');
+ $(calculation_select_element).val('');
+ $(calculation_label).show();
+ $.ajax({
+ url: window.portal_url + '/get_available_calculations',
+ type: 'POST',
+ data: {
+ '_authenticator': $('input[name="_authenticator"]').val()
},
- dataType: "json"
- });
- }
-
-
- function applyStyles() {
-
- $($(manual_fd)).after($(methods_fd));
-
- $(methods_fd)
- .css('border', '1px solid #cfcfcf')
- .css('background-color', '#efefef')
- .css('padding', '10px')
- .css('margin-bottom', '20px');
-
- $(instrs_fd)
- .css('border', '1px solid #cfcfcf')
- .css('border-bottom', 'none')
- .css('background-color', '#efefef')
- .css('padding', '10px')
- .css('margin-bottom', '0px');
- $(instr_fd)
- .css('border', '1px solid #cfcfcf')
- .css('border-top', 'none')
- .css('background-color', '#efefef')
- .css('padding', '10px')
- .css('margin-bottom', '20px');
-
-// $(calculation_field).find('label').hide();
- }
-}
+ dataType: 'json'
+ }).done(function(data) {
+ var i;
+ $(calculation_select_element).find('option').remove();
+ if (data !== null) {
+ i = 0;
+ while (i < data.length) {
+ $(calculation_select_element).append('');
+ i++;
+ }
+ } else {
+ $(calculation_select_element).append('');
+ }
+ $(calculation_select_element).val($(calculation_select_element).find('option').first().val());
+ $(calculation_select_element).change();
+ });
+ }
+ });
+ $(calculation_select_element).change(function() {
+ loadInterims($(this).val());
+ });
+ applyStyles();
+ catchOriginalValues();
+ };
+ };
+
+}).call(this);
diff --git a/bika/lims/browser/js/coffee/bika.lims.analysisservice.coffee b/bika/lims/browser/js/coffee/bika.lims.analysisservice.coffee
new file mode 100644
index 0000000000..f0e76d5455
--- /dev/null
+++ b/bika/lims/browser/js/coffee/bika.lims.analysisservice.coffee
@@ -0,0 +1,726 @@
+###
+# Controller class for Analysis Service Edit view
+###
+
+window.AnalysisServiceEditView = ->
+ that = this
+ manual_fd = $('#archetypes-fieldname-ManualEntryOfResults')
+ manual_chk = $('#archetypes-fieldname-ManualEntryOfResults #ManualEntryOfResults')
+ instre_fd = $('#archetypes-fieldname-InstrumentEntryOfResults')
+ instr_chk = $('#archetypes-fieldname-InstrumentEntryOfResults #InstrumentEntryOfResults')
+ methods_fd = $('#archetypes-fieldname-Methods')
+ methods_ms = $('#archetypes-fieldname-Methods #Methods')
+ method_fd = $('#archetypes-fieldname-Method')
+ method_sel = $('#archetypes-fieldname-Method #Method')
+ instrs_fd = $('#archetypes-fieldname-Instruments')
+ instrs_ms = $('#archetypes-fieldname-Instruments #Instruments')
+ instr_fd = $('#archetypes-fieldname-Instrument')
+ instr_sel = $('#archetypes-fieldname-Instrument #Instrument')
+ default_calculation_chk = $('#archetypes-fieldname-UseDefaultCalculation #UseDefaultCalculation')
+ calculation_field = $('#archetypes-fieldname-Calculation')
+ calculation_label = $(calculation_field).find('label')
+ calculation_select_element = $('#archetypes-fieldname-Calculation #Calculation')
+ interim_fd = $('#archetypes-fieldname-InterimFields')
+ interim_rw = $('#archetypes-fieldname-InterimFields tr.records_row_InterimFields')
+ ldsel_chk = $('#archetypes-fieldname-DetectionLimitSelector #DetectionLimitSelector')
+ ldman_fd = $('#archetypes-fieldname-AllowManualDetectionLimit')
+ ldman_chk = $('#archetypes-fieldname-AllowManualDetectionLimit #AllowManualDetectionLimit')
+
+ ###
+ # Entry-point method for AnalysisServiceEditView
+ ###
+
+ insert_manual_methods = ->
+ $.ajax(
+ url: window.portal_url + '/get_instrument_methods'
+ type: 'POST'
+ data:
+ '_authenticator': $('input[name="_authenticator"]').val()
+ 'uid': $(instr_sel).val()
+ dataType: 'json'
+ async: false).done (data) ->
+ $(method_sel).find('option').remove()
+ # Handle multiple methods
+ if data != null and data.methods.length > 0
+ # Set the instrument's methods
+ $.each data.methods, (index, value) ->
+ uid = value.uid
+ title = value.title
+ console.debug 'Adding Method ' + title + ' to the Selection'
+ option = ''
+ $(method_sel).append option
+ $(method_sel).val uid
+ return
+ else
+ # Oooopps. The instrument has no method assigned
+ $(method_sel).append ''
+ $(method_sel).val ''
+ # Delegate the action to Default Calc change event
+ $(default_calculation_chk).change()
+ return
+ return
+
+ ###
+ # Controls the visibility and values of fields generated by Plone automatically.
+ ###
+
+ catchOriginalValues = ->
+ $(manual_chk).attr 'data-default', $(manual_chk).is(':checked')
+ $(instr_chk).attr 'data-default', $(instr_chk).is(':checked')
+ $(methods_ms).attr 'data-default', $(methods_ms).val()
+ $(method_sel).attr 'data-default', $(method_sel).val()
+ $(instrs_ms).attr 'data-default', $(instrs_ms).val()
+ $(instr_sel).attr 'data-default', $(instr_sel).val()
+ $(default_calculation_chk).attr 'data-default', $(default_calculation_chk).is(':checked')
+ $(calculation_select_element).attr 'data-default', $(calculation_select_element).val()
+ # If manual entry is disabled, hide and clear the methods multiselector
+ if !$(manual_chk).is(':checked')
+ $(methods_fd).hide()
+ $(methods_ms).find('option[selected]').prop 'selected', false
+ $(methods_ms).val ''
+ # If Instrument assignment is disabled, hide and clear everything related with instruments.
+ if !$(instr_chk).is(':checked')
+ $('#invalid-instruments-alert').remove()
+ # Hide the instruments multiselector and unselect all
+ $(instrs_fd).hide()
+ if $(instrs_ms).find('option[value=""]').length == 0
+ $(instrs_ms).prepend ''
+ $(instrs_ms).val ''
+ $(instrs_ms).find('option[value=""]').prop 'selected', true
+ # Hide the default instrument selector
+ $(instr_fd).hide()
+ # Unselect the default instrument
+ if $(instr_sel).find('option[value=""]').length == 0
+ $(instr_sel).prepend ''
+ $(instr_sel).val ''
+ $(instr_sel).find('option[value=""]').prop 'selected', true
+ # The user mustn't be allowed to unset manual entry
+ $(manual_chk).click (e) ->
+ e.preventDefault()
+ return
+ # If there is no calculation assigned, hide interim fields section.
+ if !$(calculation_select_element).find(':selected').val()
+ $(interim_fd).hide()
+ # Remove 'None' option from 'Methods' multi-select
+ $(methods_ms).find('option[value=""]').remove()
+ # Toggle default/alternative calculation
+ if !$(default_calculation_chk).is(':checked')
+ $(calculation_label).show()
+ else
+ $(calculation_label).hide()
+ # Save the manually entered interims to keep them if another
+ # calculation is set. We need to know which interim fields
+ # are from the current selected calculation and which of them
+ # have been set manually.
+ $('body').append ''
+ rows = $('tr.records_row_InterimFields')
+ originals = []
+ if $(rows).length > 1
+ i = $(rows).length - 2
+ while i >= 0
+ # Get the original values
+ keyword = $($($(rows)[i]).find('td input')[0]).val()
+ if keyword != ''
+ title = $($($(rows)[i]).find('td input')[1]).val()
+ value = $($($(rows)[i]).find('td input')[2]).val()
+ unit = $($($(rows)[i]).find('td input')[3]).val()
+ hidd = $($($(rows)[i]).find('td input')[4]).is(':checked')
+ wide = $($($(rows)[i]).find('td input')[5]).is(':checked')
+ originals.push [
+ keyword
+ title
+ value
+ unit
+ hidd
+ wide
+ ]
+ i--
+ toremove = []
+ calcuid = ''
+ if $(default_calculation_chk).is(':checked')
+ $(calculation_select_element).find('option').remove()
+ calcuid = $(calculation_select_element).attr('data-default')
+ if calcuid != null and calcuid != ''
+ request_data =
+ catalog_name: 'bika_setup_catalog'
+ UID: calcuid
+ window.bika.lims.jsonapi_read request_data, (data) ->
+ if data.objects.length > 0
+ $(calculation_select_element).append ''
+ $(calculation_select_element).val data.objects[0].UID
+ $(calculation_select_element).find('option').attr 'selected', 'selected'
+ i = 0
+ while i < data.objects[0].InterimFields.length
+ row = data.objects[0].InterimFields[i]
+ toremove.push row.keyword
+ i++
+ #We must avoid use of disabling fields.
+ #When a field is disabled, its setter is not called at all.
+ #$(calculation_select_element).attr('disabled',true);
+ else
+ $(calculation_select_element).append ''
+ $(calculation_select_element).val ''
+ manualinterims = originals.filter((el) ->
+ toremove.indexOf(el[0]) < 0
+ )
+ # Save the manualinterims in some hidden place
+ $('#temp_manual_interims').val $.toJSON(manualinterims)
+ return
+ return
+
+ ###
+ # Loads the Interim fields Widget for the specificied calculation
+ ###
+
+ loadInterims = (calcuid) ->
+ $(interim_fd).hide()
+ if calcuid == null or calcuid == ''
+ $('#InterimFields_more').click()
+ # blank last row
+ rows = $('tr.records_row_InterimFields')
+ # Clear the rest
+ if $(rows).length > 1
+ i = $(rows).length - 2
+ while i >= 0
+ $($(rows)[i]).remove()
+ i--
+ $(interim_fd).hide()
+ return
+ request_data =
+ catalog_name: 'bika_setup_catalog'
+ UID: calcuid
+ window.bika.lims.jsonapi_read request_data, (data) ->
+ # Clear rows
+ $('#InterimFields_more').click()
+ # blank last row
+ _rows = $('tr.records_row_InterimFields')
+ originals = []
+ if $(_rows).length > 1
+ i = $(_rows).length - 2
+ while i >= 0
+ # Save the original values
+ keyword = $($($(_rows)[i]).find('td input')[0]).val()
+ if keyword != ''
+ value = $($($(_rows)[i]).find('td input')[2]).val()
+ unit = $($($(_rows)[i]).find('td input')[3]).val()
+ hidd = $($($(_rows)[i]).find('td input')[4]).is(':checked')
+ wide = $($($(_rows)[i]).find('td input')[5]).is(':checked')
+ originals.push [
+ keyword
+ value
+ unit
+ hidd
+ wide
+ ]
+ $($(_rows)[i]).remove()
+ i--
+ if data.objects.length > 0
+ $(interim_fd).fadeIn 'slow'
+ $('[id^=\'InterimFields-keyword-\']').attr 'id', 'InterimFields-keyword-0'
+ $('[id^=\'InterimFields-title-\']').attr 'id', 'InterimFields-title-0'
+ $('[id^=\'InterimFields-value-\']').attr 'id', 'InterimFields-value-0'
+ $('[id^=\'InterimFields-unit-\']').attr 'id', 'InterimFields-unit-0'
+ i = 0
+ while i < data.objects[0].InterimFields.length
+ row = data.objects[0].InterimFields[i]
+ original = null
+ j = 0
+ while j < originals.length
+ if originals[j][0] == row.keyword
+ original = originals[j]
+ break
+ j++
+ $('#InterimFields-keyword-' + i).val row.keyword
+ $('#InterimFields-title-' + i).val row.title
+ if original == null
+ $('#InterimFields-value-' + i).val row.value
+ $('#InterimFields-unit-' + i).val row.unit
+ else
+ $('#InterimFields-value-' + i).val original[1]
+ $('#InterimFields-unit-' + i).val original[2]
+ $('#InterimFields_more').click()
+ i++
+ # Manually entered results?
+ manualinterims = $.parseJSON($('#temp_manual_interims').val())
+ if manualinterims.length > 0
+ $(interim_fd).fadeIn 'slow'
+ i = $('tr.records_row_InterimFields').length - 1
+ k = 0
+ while k < manualinterims.length
+ $('#InterimFields-keyword-' + i).val manualinterims[k][0]
+ $('#InterimFields-title-' + i).val manualinterims[k][1]
+ $('#InterimFields-value-' + i).val manualinterims[k][2]
+ $('#InterimFields-unit-' + i).val manualinterims[k][3]
+ $('#InterimFields_more').click()
+ i++
+ k++
+ return
+ return
+
+ ###
+ # Checks if the selected instruments aren't out-of-date and their
+ # latest Internal Calibration Tests are valid. If an invalid
+ # instrument gets selected, shows an alert to the user
+ ###
+
+ validateInstruments = ->
+ $('#invalid-instruments-alert').remove()
+ if $('#InstrumentEntryOfResults').is(':checked')
+ window.jarn.i18n.loadCatalog 'bika'
+ _ = window.jarn.i18n.MessageFactory('bika')
+ insts = if $('#Instruments').val() then $('#Instruments').val() else []
+ $.each insts, (index, value) ->
+ # Is valid?
+ request_data =
+ catalog_name: 'uid_catalog'
+ UID: value
+ window.bika.lims.jsonapi_read request_data, (data) ->
+ if data.objects[0].Valid != '1'
+ title = data.objects[0].Title
+ instrument_path = window.location.protocol + '//' + window.location.host + data.objects[0].path
+ if $('#invalid-instruments-alert').length > 0
+ $('#invalid-instruments-alert dd').first().append ', ' + title
+ else
+ errmsg = _('Some of the selected instruments are out-of-date or with failed calibration tests')
+ html = ''
+ $('#analysisservice-base-edit').before html
+ return
+ return
+ else
+ loadEmptyInstrument()
+ return
+
+ updateContainers = (target, requestdata) ->
+ $.ajax
+ type: 'POST'
+ url: window.location.href + '/getUpdatedContainers'
+ data: requestdata
+ success: (data) ->
+ # keep the current selection if possible
+ option = $(target).val()
+ if option == null or option == undefined
+ option = []
+ $(target).empty()
+ $.each data, (i, v) ->
+ if $.inArray(v[0], option) > -1
+ $(target).append ''
+ else
+ $(target).append ''
+ return
+ return
+ dataType: 'json'
+ return
+
+ applyStyles = ->
+ $($(manual_fd)).after $(methods_fd)
+ $(methods_fd).css('border', '1px solid #cfcfcf').css('background-color', '#efefef').css('padding', '10px').css 'margin-bottom', '20px'
+ $(instrs_fd).css('border', '1px solid #cfcfcf').css('border-bottom', 'none').css('background-color', '#efefef').css('padding', '10px').css 'margin-bottom', '0px'
+ $(instr_fd).css('border', '1px solid #cfcfcf').css('border-top', 'none').css('background-color', '#efefef').css('padding', '10px').css 'margin-bottom', '20px'
+ # $(calculation_field).find('label').hide();
+ return
+
+ that.load = ->
+ # LIMS-1775 Allow to select LDL or UDL defaults in results with readonly mode
+ # https://jira.bikalabs.com/browse/LIMS-1775
+ $(ldsel_chk).change ->
+ if $(this).is(':checked')
+ $(ldman_fd).show()
+ else
+ $(ldman_fd).hide()
+ $(ldman_chk).prop 'checked', false
+ return
+ $(ldsel_chk).change()
+ # service defaults
+ # update defalt Containers
+ $('.portaltype-analysisservice #RequiredVolume, .portaltype-analysisservice #Separate').change ->
+ separate = $('#Separate').prop('checked')
+ if !separate
+ $('[name=\'Preservation\\:list\']').prop 'disabled', false
+ requestdata =
+ 'allow_blank': true
+ 'show_container_types': !separate
+ 'show_containers': separate
+ '_authenticator': $('input[name=\'_authenticator\']').val()
+ updateContainers '#Container\\:list', requestdata
+ return
+ # partition table -> separate checkboxes
+ # partition table -> minvol field
+ # update row's containers
+ $('.portaltype-analysisservice [name^=\'PartitionSetup.separate\'],.portaltype-analysisservice [name^=\'PartitionSetup.vol\']').change ->
+ separate = $(this).parents('tr').find('[name^=\'PartitionSetup.separate\']').prop('checked')
+ if !separate
+ $(this).parents('tr').find('[name^=\'PartitionSetup.preservation\']').prop 'disabled', false
+ minvol = $(this).parents('tr').find('[name^=\'PartitionSetup.vol\']').val()
+ target = $(this).parents('tr').find('[name^=\'PartitionSetup.container\']')
+ requestdata =
+ 'allow_blank': true
+ 'minvol': minvol
+ 'show_container_types': !separate
+ 'show_containers': separate
+ '_authenticator': $('input[name=\'_authenticator\']').val()
+ updateContainers target, requestdata
+ return
+ # copy sampletype MinimumVolume to minvol when selecting sampletype
+ $('.portaltype-analysisservice [name^=\'PartitionSetup.sampletype\']').change ->
+ st_element = this
+ request_data =
+ catalog_name: 'uid_catalog'
+ UID: $(this).val()
+ window.bika.lims.jsonapi_read request_data, (data) ->
+ minvol = data.objects[0].MinimumVolume
+ target = $(st_element).parents('tr').find('[name^=\'PartitionSetup.vol\']')
+ $(target).val minvol
+ # trigger change on containers, in case SampleType volume rendered
+ # the selected container too small and removed it from the list
+ $(st_element).parents('tr').find('[name^=\'PartitionSetup.container\']').change()
+ return
+ return
+ # handling of pre-preserved containers in the Default Container field
+ # select the preservation and disable the input.
+ $('.portaltype-analysisservice #Container').bind 'selected', ->
+ container_uid = $(this).attr('uid')
+ if container_uid == undefined or container_uid == null
+ container_uid = ''
+ request_data =
+ catalog_name: 'uid_catalog'
+ UID: container_uid
+ window.bika.lims.jsonapi_read request_data, (data) ->
+ if data.objects.length < 1 or !data.objects[0].PrePreserved or !data.objects[0].Preservation
+ $('#Preservation').val ''
+ $('#Preservation').prop 'disabled', false
+ else
+ $('#Preservation').val data.objects[0].Preservation
+ $('#Preservation').prop 'disabled', true
+ return
+ return
+ # handling of pre-preserved containers in the per Sample-Type rows
+ # select the preservation and disable the input.
+ $('.portaltype-analysisservice [name^=\'PartitionSetup.container\']').change ->
+ target = $(this).parents('tr').find('[name^=\'PartitionSetup.preservation\']')
+ container_uid = $(this).val()
+ if !container_uid or container_uid.length == 1 and !container_uid[0]
+ $(target).prop 'disabled', false
+ return
+ container_uid = container_uid[0]
+ if container_uid == undefined or container_uid == null
+ container_uid = ''
+ request_data =
+ catalog_name: 'uid_catalog'
+ UID: container_uid
+ window.bika.lims.jsonapi_read request_data, (data) ->
+ if data.objects.length < 1 or !data.objects[0].PrePreserved or !data.objects[0].Preservation
+ $(target).prop 'disabled', false
+ else
+ $(this).val container_uid
+ # makes no sense to leave multiple items selected
+ $(target).val data.objects[0].Preservation
+ $(target).prop 'disabled', true
+ return
+ return
+ # update on first load
+ # $(".portaltype-analysisservice [name^='PartitionSetup.separate']").change();
+ # $(".portaltype-analysisservice [name^='Container']").change();
+ # $(".portaltype-analysisservice [name^='PartitionSetup.container']").trigger("selected");
+ # initial setup - hide Interim widget if no Calc is selected
+ # This is commented because javascript halts execution in this block.
+ # I think it's because this code fucks around with non-visible elements.
+ # So the same question as always: How did this ever work, and how do
+ # we replace it now.
+ # if($(".portaltype-analysisservice #Calculation").val() === ""){
+ # $("#InterimFields_more").click(); // blank last row
+ # var rows = $("tr.records_row_InterimFields"); // Clear the rest
+ # if($(rows).length > 1){
+ # for (var i = $(rows).length - 2; i >= 0; i--) {
+ # $($(rows)[i]).remove();
+ # }
+ # }
+ # $("#archetypes-fieldname-InterimFields").hide();
+ # return;
+ # }
+ # Check if there is, at least, one instrument available
+ if $(instrs_ms).find('option').length == 0
+ # Ooops, there isn't any instrument!
+ $(manual_chk).prop 'checked', true
+ $(manual_chk).prop 'readonly', true
+ $(instr_chk).prop 'checked', false
+ $(instr_chk).prop 'readonly', true
+ errmsg = _('No instruments available')
+ title = _('Instrument entry of results option not allowed')
+ html = '' + '
' + errmsg + '' + '' + title + '' + ''
+ $('#analysisservice-base-edit').before html
+ # The 'Manual entry of results' value changes
+ $(manual_chk).change ->
+ if $(this).is(':checked')
+ # Insert all methods without instruments into the
+ # methods InOut options widget.
+ insert_manual_methods()
+ $(methods_fd).fadeIn 'slow'
+ # Delegate remaining actions to Methods change event
+ $(methods_ms).change()
+ else
+ # The method selection must be done by enabling the
+ # 'Allow instrument entry of results'
+ # Hide and clear the methods multiselector
+ $(methods_fd).hide()
+ $(methods_ms).find('option[selected]').prop 'selected', false
+ $(methods_ms).val ''
+ # Delegate remaining actions to Methods change event
+ $(methods_ms).change()
+ # Select instrument entry and fire event
+ $(instr_chk).prop 'checked', true
+ $(instr_chk).change()
+ return
+ # The 'Allow instrument entry of results' value changes
+ $(instr_chk).change ->
+ if $(this).is(':checked')
+ # The user must select the instruments supported by
+ # this Analysis Service. The default method will be
+ # retrieved from the default instrument selected.
+ # The user must be able to allow manual entry
+ $(manual_chk).unbind 'click'
+ # Show the instruments multiselector
+ $(instrs_fd).fadeIn 'slow'
+ # Remove the 'none' option from instruments multiselector
+ $(instrs_ms).find('option[value=""]').remove()
+ # Remove the 'none' option from def instrument selector
+ $(instr_sel).find('option[value=""]').remove()
+ # Show the default instrument selector
+ $(instr_fd).fadeIn 'slow'
+ # Disable the default method selector
+ $(method_sel).focus (e) ->
+ $(this).blur()
+ return
+ # Disable the default calculation selector
+ $(calculation_select_element).focus (e) ->
+ $(this).blur()
+ return
+ # Delegate remaining actions to Instruments change event
+ $(instrs_ms).change()
+ else
+ # The method selection must be done manually, by
+ # selecting the methods for which this Analysis Service
+ # has support.
+ # Remove the invalid instrument alert (if exists)
+ $('#invalid-instruments-alert').remove()
+ # Hide the instruments multiselector and unselect all
+ $(instrs_fd).hide()
+ if $(instrs_ms).find('option[value=""]').length == 0
+ $(instrs_ms).prepend ''
+ $(instrs_ms).val ''
+ $(instrs_ms).find('option[value=""]').prop 'selected', true
+ # Hide the default instrument selector
+ $(instr_fd).hide()
+ # Unselect the default instrument
+ if $(instr_sel).find('option[value=""]').length == 0
+ $(instr_sel).prepend ''
+ $(instr_sel).val ''
+ $(instr_sel).find('option[value=""]').prop 'selected', true
+ # The user mustn't be allowed to unset manual entry
+ $(manual_chk).click (e) ->
+ e.preventDefault()
+ return
+ # The user must be able to select the default method manualy
+ $(methods_ms).change()
+ $(method_sel).unbind 'focus'
+ # If manual entry is not selected, select it and
+ # fire event cascade
+ if !$(manual_chk).is(':checked')
+ $(manual_chk).prop 'checked', true
+ $(manual_chk).change()
+ return
+ # The methods multiselect changes
+ $(methods_ms).change (e) ->
+ prevmethod = $(method_sel).val()
+ prevmethodtxt = $(method_sel).find('option[value="' + prevmethod + '"]').html()
+
+ ###if ($(this).val() == null) {
+ // At least one method must be selected
+ $(this).val($(this).find('option').first().val());
+ }
+ ###
+
+ # If it has default Instrument, Default method can be only one of that Default Instrument's methods. Do
+ # not do anything.
+ if $(instr_chk).is(':checked')
+ $(method_sel).change (e) ->
+ # Delegate actions to Default Calculation change event
+ $(default_calculation_chk).change()
+ return
+ return
+ $(method_sel).find('option').remove()
+ # Populate with the methods from the multi-select
+ methods = $(methods_ms).val()
+ if methods != null
+ $.each methods, (index, value) ->
+ option = $(methods_ms).find('option[value="' + value + '"]').clone()
+ $(method_sel).append option
+ return
+ else
+ $(method_sel).prepend ''
+ # Select the previously selected method or the first one
+ defoption = $(method_sel).find('option[value="' + $(method_sel).attr('data-default') + '"]')
+ if defoption == null or defoption == ''
+ defoption = $(method_sel).find('option[value="' + prevmethod + '"]')
+ if defoption == null or defoption == ''
+ defoption = $(method_sel).find('option').first()
+ # Delegate remaining actions to Method change event
+ $(method_sel).change()
+ return
+ $(method_sel).change (e) ->
+ # Delegate actions to Default Calculation change event
+ $(default_calculation_chk).change()
+ return
+ # The instruments multiselect changes
+ $(instrs_ms).change (e) ->
+ previnstr = $(instr_sel).val()
+ if $(this).val() == null
+ # At least one instrument must be selected
+ $(this).val $(this).find('option').first().val()
+ # Populate the default instrument list with the selected instruments
+ $(instr_sel).find('option').remove()
+ insts = $(instrs_ms).val()
+ $.each insts, (index, value) ->
+ option = $(instrs_ms).find('option[value="' + value + '"]').clone()
+ $(instr_sel).append option
+ return
+ # Select the previously selected instrument or the first one
+ defoption = $(instr_sel).find('option[value="' + previnstr + '"]')
+ if defoption == null or defoption == ''
+ defoption = $(instr_sel).find('option[value="' + $(instr_sel).attr('data-default') + '"]')
+ if defoption == null or defoption == ''
+ defoption = $(instr_sel).find('option').first()
+ $(instr_sel).val $(defoption).val()
+ # Check if out-of-date or QC-fail instruments have been
+ # selected.
+ $('#invalid-instruments-alert').remove()
+ $.each insts, (index, value) ->
+ # Is valid?
+ if value != '' and $(instr_chk).is(':checked')
+ request_data =
+ catalog_name: 'uid_catalog'
+ UID: value
+ window.bika.lims.jsonapi_read request_data, (data) ->
+ `var title`
+ `var errmsg`
+ `var html`
+ if !$(instr_chk).is(':checked')
+ $('#invalid-instruments-alert').remove()
+ else if data.objects[0].Valid != '1'
+ title = data.objects[0].Title
+ instrument_path = window.location.protocol + '//' + window.location.host + data.objects[0].path
+ if $('#invalid-instruments-alert').length > 0
+ $('#invalid-instruments-alert dd').first().append ', ' + title
+ else
+ errmsg = _('Some of the selected instruments are out-of-date or with failed calibration tests')
+ html = ''
+ $('#analysisservice-base-edit').before html
+ return
+ return
+ # Delegate remaining actions to Instrument change event
+ $(instr_sel).change()
+ return
+ # The instrument selector changes
+ $(instr_sel).change ->
+ # Clear and disable the method list and populate with the
+ # method assigned to the selected instrument
+ $(method_sel).find('option').remove()
+ $(method_sel).append ''
+ $(method_sel).val ''
+ $.ajax(
+ url: window.portal_url + '/get_instrument_methods'
+ type: 'POST'
+ data:
+ '_authenticator': $('input[name="_authenticator"]').val()
+ 'uid': $(instr_sel).val()
+ dataType: 'json'
+ async: false).done (data) ->
+ $(method_sel).find('option').remove()
+ # Handle multiple methods
+ if data != null and data.methods.length > 0
+ # Set the instrument's methods
+ $.each data.methods, (index, value) ->
+ `var title`
+ uid = value.uid
+ title = value.title
+ console.debug 'Adding Method ' + title + ' to the Selection'
+ option = ''
+ $(method_sel).append option
+ $(method_sel).val uid
+ return
+ else
+ # Oooopps. The instrument has no method assigned
+ $(method_sel).append ''
+ $(method_sel).val ''
+ # Delegate the action to Default Calc change event
+ $(default_calculation_chk).change()
+ return
+ return
+ # The 'Default Calculation' checkbox changes
+ $(default_calculation_chk).change ->
+ if $(this).is(':checked')
+ # Using default calculation.
+ # So, we deny access to the "Calculation" selection field.
+ $(calculation_label).hide()
+ # Load the calculation for the selected method
+ muid = $(method_sel).val()
+ if muid != null and muid != ''
+ # A valid method was selected
+ $.ajax(
+ url: window.portal_url + '/get_method_calculation'
+ type: 'POST'
+ data:
+ '_authenticator': $('input[name="_authenticator"]').val()
+ 'uid': muid
+ dataType: 'json').done (data) ->
+ $(calculation_select_element).find('option').remove()
+ if data != null and data['uid']
+ $(calculation_select_element).prepend ''
+ else
+ $(calculation_select_element).append ''
+ $(calculation_select_element).val $(calculation_select_element).find('option').first().val()
+ # Delegate the action to Default Calculation change event
+ $(calculation_select_element).change()
+ return
+ else
+ $(calculation_select_element).find('option').remove()
+ $(calculation_select_element).append ''
+ $(calculation_select_element).change()
+ else
+ $(calculation_select_element).find('option').remove()
+ $(calculation_select_element).append ''
+ $(calculation_select_element).val ''
+ # Unselected "Use Default Calculation"
+ # So, we allow selection of calculation manually and fill the list with the all available Calculations
+ # in the system.
+ $(calculation_label).show()
+ #$(calculation_select_element).prop('disabled', false);
+ # Get available Calculations from Bika
+ $.ajax(
+ url: window.portal_url + '/get_available_calculations'
+ type: 'POST'
+ data: '_authenticator': $('input[name="_authenticator"]').val()
+ dataType: 'json').done (data) ->
+ $(calculation_select_element).find('option').remove()
+ if data != null
+ i = 0
+ while i < data.length
+ $(calculation_select_element).append ''
+ i++
+ else
+ $(calculation_select_element).append ''
+ $(calculation_select_element).val $(calculation_select_element).find('option').first().val()
+ # Delegate the action to Default Calculation change event
+ $(calculation_select_element).change()
+ return
+ return
+ # The 'Default calculation' changes
+ $(calculation_select_element).change ->
+ loadInterims $(this).val()
+ return
+ # Apply default styling
+ applyStyles()
+ # Grab original values
+ catchOriginalValues()
+ return
+
+ return
diff --git a/bika/lims/content/analysisservice.py b/bika/lims/content/analysisservice.py
index 51b392ec46..e382680518 100644
--- a/bika/lims/content/analysisservice.py
+++ b/bika/lims/content/analysisservice.py
@@ -8,7 +8,7 @@
import transaction
from AccessControl import ClassSecurityInfo
-from Products.ATExtensions.ateapi import RecordsField, RecordsWidget
+from Products.ATExtensions.ateapi import RecordsField
from Products.Archetypes.Registry import registerField
from Products.Archetypes.public import BooleanField, BooleanWidget, \
DisplayList, MultiSelectionWidget, Schema, registerType
@@ -17,6 +17,7 @@
from bika.lims import PMF, bikaMessageFactory as _
from bika.lims.browser.fields import InterimFieldsField, UIDReferenceField
from bika.lims.browser.widgets.partitionsetupwidget import PartitionSetupWidget
+from bika.lims.browser.widgets.recordswidget import RecordsWidget
from bika.lims.browser.widgets.referencewidget import ReferenceWidget
from bika.lims.browser.widgets.uidselectionwidget import UIDSelectionWidget
from bika.lims.config import PROJECTNAME
@@ -52,7 +53,7 @@ def getContainers(instance,
bsc = getToolByName(instance, 'bika_setup_catalog')
- items = allow_blank and [['', _('Any')]] or []
+ items = [['', _('Any')]] if allow_blank else []
containers = []
for container in bsc(portal_type='Container', sort_on='sortable_title'):
@@ -77,7 +78,7 @@ def getContainers(instance,
# containers with no containertype first
for container in containers:
if not container.getContainerType():
- items.append((container.UID(), container.Title()))
+ items.append([container.UID(), container.Title()])
ts = getToolByName(instance, 'translation_service').translate
cat_str = _c(ts(_('Container Type')))
@@ -87,12 +88,12 @@ def getContainers(instance,
for ctype_uid, ctype_title in containertypes.items():
ctype_title = _c(ctype_title)
if show_container_types:
- items.append((ctype_uid, "%s: %s" % (cat_str, ctype_title)))
+ items.append([ctype_uid, "%s: %s" % (cat_str, ctype_title)])
if show_containers:
for container in containers:
ctype = container.getContainerType()
if ctype and ctype.UID() == ctype_uid:
- items.append((container.UID(), container.Title()))
+ items.append([container.UID(), container.Title()])
items = tuple(items)
return items
@@ -158,7 +159,7 @@ def SampleTypes(self, instance=None):
def Preservations(self, instance=None):
instance = instance or self
bsc = getToolByName(instance, 'bika_setup_catalog')
- items = [(c.UID, c.title) for c in
+ items = [[c.UID, c.title] for c in
bsc(portal_type='Preservation',
inactive_state='active',
sort_on='sortable_title')]