diff --git a/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js b/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js index 31d52ae20..ddde1dbde 100644 --- a/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js +++ b/tdrs-backend/tdpservice/data_files/static/admin/js/admin/admin_datafile_model.js @@ -2,29 +2,44 @@ $(window).on('load', function() { console.log('loaded'); var submitBtn=document.querySelector('button[type=submit]'); // add the first listener var theForm = submitBtn.parentNode.parentNode; + var action = ""; + var number_of_files_line = ""; - for (var i = 0; i < theForm.childNodes.length; i++) { - if (theForm.childNodes[i].className == "actions") { - form_header = theForm.childNodes[i]; + submitBtn.addEventListener('click', function(e) { + e.preventDefault(); + // number of files + action_counter = document.querySelector('span.action-counter') + is_action_counter_hidden = action_counter.className === "action-counter hidden" - for (var i = 0; i < form_header.childNodes.length; i++) { - if (form_header.childNodes[i].className == "action-counter") { - number_of_files = form_header.childNodes[i]; - break; - } - } + action_counter_all = document.querySelector('span.all') - break; + if (is_action_counter_hidden) { + number_of_files_line = action_counter_all.innerText; + } else { + number_of_files_line = action_counter.innerText; } - } - submitBtn.addEventListener('click', function(e) { - e.preventDefault(); - if (confirm("You are about to re-parse " + number_of_files.innerHTML.split(/(\s+)/)[0] + " files. Are you sure you want to continue?")) { - console.log('submitting'); - theForm.submit(); + + // what action is selected + action = document.querySelector('select[name=action]').value; + + if (action === "reparse") { + console.log('reparse'); + var splitted_number_of_files = number_of_files_line.split(/(\s+)/); + if (Number(splitted_number_of_files[0]) > 0 ) { + number_of_files = splitted_number_of_files[0]; + } else { + number_of_files = splitted_number_of_files[2]; + } + if (confirm("You are about to re-parse " + number_of_files + " files. Are you sure you want to continue?")) { + console.log('submitting'); + theForm.submit(); + } else { + console.log('not submitting'); + }; } else { - console.log('not submitting'); - }; + console.log('not reparse'); + alert('Please select the "Reparse" action to continue.'); + } }); });