diff --git a/core/utils/samples.py b/core/utils/samples.py index 2afa376a..e1e231b9 100644 --- a/core/utils/samples.py +++ b/core/utils/samples.py @@ -1514,7 +1514,7 @@ def get_selection_from_excel_data(data, heading, check_field, field_id): excel_json_data = core.utils.common.jspreadsheet_to_dict(heading, excel_data) for row in excel_json_data: if check_field is not None: - if row[check_field] is True or row[check_field] != "": + if row[check_field] is True: selected.append(row[field_id]) selected_row.append(row) else: diff --git a/wetlab/templates/wetlab/handling_molecules.html b/wetlab/templates/wetlab/handling_molecules.html index 97667b4d..84a9f4e7 100644 --- a/wetlab/templates/wetlab/handling_molecules.html +++ b/wetlab/templates/wetlab/handling_molecules.html @@ -268,7 +268,7 @@

Select the molecules to add Extraction information

{% else %} -

There is no samples to add Molecule Extraction information

+

There is no samples to add Extraction information

{% endif %} @@ -286,7 +286,7 @@

There is no samples to add Molecule Extraction information

-

Select the Samples to add Molecule information

+

Select the Samples to add Pending extraction information

{% if molecules_availables %} @@ -298,7 +298,7 @@

Select the Samples to add Molecule information

{% csrf_token %}
-
+
Not molecule uses have been defined yet }); {% endif %} {% if molecules_availables.molecule_heading %} - // excel for pending molecules + // excel for pending Extraction data var data2 = [{% for values in molecules_availables.data %} [{% for value in values %}'{{value}}',{% endfor %}],{% endfor %} ]; - var table2 = jexcel(document.getElementById('pending_molecules'), { + var table2 = jexcel(document.getElementById('pending_extraction'), { data:data2, columns: [{% for values in molecules_availables.molecule_heading %} {% if forloop.last %} @@ -439,13 +439,29 @@

Not molecule uses have been defined yet

pagination:20, csvFileName:'molecule_use', }); + // Function to check if at least one checkbox in the "select sample" column is set to true + function isAnySelectedColumnChecked() { + var table_data2 = table2.getData(); + // Assuming the "Select sample" column is the third column (index 5) + for (var i = 0; i < table_data2.length; i++) { + if (table_data2[i][5] === true) { // Check if "Select sample" column (index 5) is true + return true; + } + } + return false; + } // send form for molecule in use $(document).ready(function () { $("#selectedOwnerMolecules").submit(function (e) { + if (!isAnySelectedColumnChecked()) { + e.preventDefault(); // Prevent form submission + alert('You must select at least one sample before submitting.'); + return false; + } var table_data2 = table2.getData() var data_json = JSON.stringify(table_data2) $("").attr("type", "hidden") - .attr("name", "pending_molecules") + .attr("name", "pending_extraction") .attr("value", data_json) .appendTo("#selectedOwnerMolecules"); $("#btnSubmit").attr("disabled", true); diff --git a/wetlab/templates/wetlab/modify_sample_project_fields.html b/wetlab/templates/wetlab/modify_sample_project_fields.html index 97cbfc73..82a68113 100644 --- a/wetlab/templates/wetlab/modify_sample_project_fields.html +++ b/wetlab/templates/wetlab/modify_sample_project_fields.html @@ -134,9 +134,9 @@

Modify sample project fields for {{ sample_project_field.sample_project_name // Function to check if at least one checkbox in the "Used" column is set to true function isAnyUsedColumnChecked() { var table_data1 = table1.getData(); - // Assuming the "Used" column is the third column (index 2) + // Assuming the "Used" column is the third column (index 3) for (var i = 0; i < table_data1.length; i++) { - if (table_data1[i][2] === true) { // Check if "Used" column (index 2) is true + if (table_data1[i][3] === true) { // Check if "Used" column (index 3) is true return true; } } diff --git a/wetlab/views.py b/wetlab/views.py index 53622e3c..d34b7f39 100644 --- a/wetlab/views.py +++ b/wetlab/views.py @@ -3284,7 +3284,7 @@ def handling_molecules(request): heading = core.core_config.HEADING_FOR_PENDING_MOLECULES.copy() heading.insert(-1, "s_id") molecules, _ = core.utils.samples.get_selection_from_excel_data( - request.POST["pending_molecules"], heading, "Select Molecule", "s_id" + request.POST["pending_extraction"], heading, "Select Molecule", "s_id" ) if len(molecules) == 0: return redirect("handling_molecules")