Skip to content

Commit

Permalink
Change select all checkbox to a button. Button remains disabled when …
Browse files Browse the repository at this point in the history
…no seedlots are available to be selected from list.
  • Loading branch information
ryan-preble committed Oct 25, 2024
1 parent cf392e6 commit 2796764
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions mason/tools/available_seedlots.mas
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<th rowspan="2" style="text-align: center;">Accessions</th><th colspan="7" style="text-align: center;">Seedlots</th>
</tr>
<tr>
<th style="text-align: center;"><input id="selectallaccessions" type="checkbox" disabled>Select All</input></th>
<th style="text-align: center;"><button id="selectallaccessions" type="button" disabled>Select/Deselect All</button></th>
<th style="text-align: center;">Breeding Program</th>
<th style="text-align: center;">Seedlot Name</th>
<th style="text-align: center;">Contents</th>
Expand All @@ -23,26 +23,25 @@
var d3 = global.d3v4;
var ex = {};

const selectall_checkbox = document.getElementById('selectallaccessions');
const selectall_button = document.getElementById('selectallaccessions');
const seedlot_form = document.getElementById('available-seedlots');
function selectAllAccessions(event){
var seedlot_checkboxes = seedlot_form.querySelectorAll('input[type="checkbox"]:not(#selectallaccessions):not(:disabled)');
if (event.target.checked){
seedlot_checkboxes.forEach(function(checkbox){
checkbox.checked = true;
});
} else {
seedlot_checkboxes.forEach(function(checkbox){
checkbox.checked = false;
});
}
var any_checked = false;
seedlot_checkboxes.forEach(function(checkbox){
if (checkbox.checked == true){
any_checked = true;
}
});
seedlot_checkboxes.forEach(function(checkbox){
checkbox.checked = !any_checked;
});
}
selectall_checkbox.addEventListener('change', selectAllAccessions);
selectall_button.addEventListener('click', selectAllAccessions);

ex.build_table = function(accession_names, list_type){
jQuery('#working_modal').modal('show');
selectall_checkbox.setAttribute('disabled', 'true'); //Reset the checkbox if looking at a different list
selectall_checkbox.checked = false;
selectall_button.setAttribute('disabled', 'true'); //Reset the checkbox if looking at a different list
jQuery.ajax({
type: 'POST',
url: '/ajax/accessions/possible_seedlots',
Expand All @@ -52,7 +51,7 @@
_build_table(accession_names,response.seedlots,response.synonyms);
var seedlot_checkboxes = seedlot_form.querySelectorAll('input[type="checkbox"]:not(#selectallaccessions):not(:disabled)');
if (seedlot_checkboxes.length > 0){
selectall_checkbox.removeAttribute('disabled');
selectall_button.removeAttribute('disabled');
}
jQuery('#working_modal').modal('hide');
},
Expand Down

0 comments on commit 2796764

Please sign in to comment.