@@ -46,31 +46,33 @@ def generate_filter_form
4646
4747 < div class ="bulk-actions-bar ">
4848 < button type ="button " class ="action-button execute-button " id ="execute-selected-top " disabled > Execute Selected</ button >
49+ < button type ="button " class ="action-button discard-button " id ="reject-selected-top " disabled > Reject Selected</ button >
4950 </ div >
5051 HTML
5152 end
5253
5354 def generate_table_with_actions
5455 <<-HTML
55- < form id ="scheduled-jobs-form " action =" #{ execute_jobs_path } " method="POST">
56+ < form id ="scheduled-jobs-form " method ="POST ">
5657 #{ generate_table }
5758 </ form>
5859 < script >
5960 document.addEventListener('DOMContentLoaded', function() {
6061 const selectAllCheckbox = document.querySelector('th input[type="checkbox"]');
6162 const jobCheckboxes = document.getElementsByName('job_ids[]');
6263 const executeButton = document.getElementById('execute-selected-top');
64+ const rejectButton = document.getElementById('reject-selected-top');
6365 const form = document.getElementById('scheduled-jobs-form');
6466 #{ ' ' }
6567 selectAllCheckbox.addEventListener('change', function() {
6668 jobCheckboxes.forEach(checkbox => checkbox.checked = this.checked);
67- updateExecuteButton ();
69+ updateButtonStates ();
6870 });
6971
7072 jobCheckboxes.forEach(checkbox => {
7173 checkbox.addEventListener('change', function() {
7274 selectAllCheckbox.checked = Array.from(jobCheckboxes).every(cb => cb.checked);
73- updateExecuteButton ();
75+ updateButtonStates ();
7476 });
7577 });
7678 #{ ' ' }
@@ -79,6 +81,31 @@ def generate_table_with_actions
7981 const selectedIds = Array.from(document.querySelectorAll('input[name="job_ids[]"]:checked')).map(cb => cb.value);
8082 if (selectedIds.length === 0) return;
8183 #{ ' ' }
84+ submitForm('#{ execute_jobs_path } ', selectedIds);
85+ });
86+ #{ ' ' }
87+ // Add event listener for the reject button
88+ rejectButton.addEventListener('click', function() {
89+ const selectedIds = Array.from(document.querySelectorAll('input[name="job_ids[]"]:checked')).map(cb => cb.value);
90+ if (selectedIds.length === 0) return;
91+ #{ ' ' }
92+ if (confirm('Are you sure you want to reject the selected jobs? This action cannot be undone.')) {
93+ submitForm('#{ reject_jobs_path } ', selectedIds);
94+ }
95+ });
96+ #{ ' ' }
97+ function submitForm(actionUrl, selectedIds) {
98+ // Uncheck all checkboxes to prevent duplicate submission
99+ document.querySelectorAll('input[name="job_ids[]"]').forEach(checkbox => {
100+ checkbox.checked = false;
101+ });
102+
103+ // Clear any existing hidden inputs
104+ document.querySelectorAll('input[type="hidden"][name="job_ids[]"]').forEach(input => input.remove());
105+
106+ // Set form action
107+ form.action = actionUrl;
108+
82109 // Add selected IDs as hidden inputs
83110 selectedIds.forEach(id => {
84111 const input = document.createElement('input');
@@ -87,18 +114,20 @@ def generate_table_with_actions
87114 input.value = id;
88115 form.appendChild(input);
89116 });
90- #{ ' ' }
117+
118+ // Submit the form
91119 form.submit();
92- });
120+ }
93121 #{ ' ' }
94- function updateExecuteButton () {
122+ function updateButtonStates () {
95123 const checkboxes = document.getElementsByName('job_ids[]');
96124 const checked = Array.from(checkboxes).some(cb => cb.checked);
97125 executeButton.disabled = !checked;
126+ rejectButton.disabled = !checked;
98127 }
99128 #{ ' ' }
100- // Initialize button state
101- updateExecuteButton ();
129+ // Initialize button states
130+ updateButtonStates ();
102131 });
103132 </ script>
104133 HTML
@@ -130,7 +159,7 @@ def generate_row(execution)
130159 <<-HTML
131160 < tr >
132161 < td >
133- < input type ="checkbox " name ="job_ids[] " value ="#{ execution . id } " onchange="updateExecuteButton()" >
162+ < input type ="checkbox " name ="job_ids[] " value ="#{ execution . id } ">
134163 </ td>
135164 < td > #{ execution . job . class_name } </ td>
136165 < td > #{ execution . queue_name } </ td>
0 commit comments