Skip to content

Commit

Permalink
solved issue BU-ISCIII#315 allowed to submit even not Select the Samp…
Browse files Browse the repository at this point in the history
…les to add Molecule information
  • Loading branch information
luissian committed Sep 27, 2024
1 parent b5661ba commit 76bd975
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/utils/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 22 additions & 6 deletions wetlab/templates/wetlab/handling_molecules.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ <h3>Select the molecules to add Extraction information</h3>
</div>
</form>
{% else %}
<h4>There is no samples to add Molecule Extraction information</h4>
<h4>There is no samples to add Extraction information</h4>
{% endif %}
</div>
</div>
Expand All @@ -286,7 +286,7 @@ <h4>There is no samples to add Molecule Extraction information</h4>
<div class="col">
<div class="card">
<div class="card-header text-center">
<h3>Select the Samples to add Molecule information</h3>
<h3>Select the Samples to add Pending extraction information</h3>
</div>
<div class="card-body">
{% if molecules_availables %}
Expand All @@ -298,7 +298,7 @@ <h3>Select the Samples to add Molecule information</h3>
{% csrf_token %}
<input type="hidden" name="action" value="selectedOwnerMolecules" />
<div class="col-md my-3">
<div id="pending_molecules"></div>
<div id="pending_extraction"></div>
</div>
<input type="button"
class="btn btn-outline-secondary my-3"
Expand Down Expand Up @@ -414,11 +414,11 @@ <h4>Not molecule uses have been defined yet</h4>
});
{% 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 %}
Expand All @@ -439,13 +439,29 @@ <h4>Not molecule uses have been defined yet</h4>
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)
$("<input />").attr("type", "hidden")
.attr("name", "pending_molecules")
.attr("name", "pending_extraction")
.attr("value", data_json)
.appendTo("#selectedOwnerMolecules");
$("#btnSubmit").attr("disabled", true);
Expand Down
4 changes: 2 additions & 2 deletions wetlab/templates/wetlab/modify_sample_project_fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ <h3>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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion wetlab/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 76bd975

Please sign in to comment.