From 2796764ffd92bded6203032ad4aee88f55d2ba69 Mon Sep 17 00:00:00 2001 From: ryan-preble Date: Fri, 25 Oct 2024 11:51:03 -0400 Subject: [PATCH] Change select all checkbox to a button. Button remains disabled when no seedlots are available to be selected from list. --- mason/tools/available_seedlots.mas | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/mason/tools/available_seedlots.mas b/mason/tools/available_seedlots.mas index 8e3b5a05b1..511b9f01a2 100644 --- a/mason/tools/available_seedlots.mas +++ b/mason/tools/available_seedlots.mas @@ -6,7 +6,7 @@ AccessionsSeedlots - Select All + Breeding Program Seedlot Name Contents @@ -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', @@ -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'); },