.div{id: "order_#{order.id}_modal"} = render :partial => 'group_order_invoices/links', locals: { order: order } - content_for :javascript do :javascript $(document).ready(function() { $("#order_#{order.id}_modal").on('click', "#collective-direct-debit-link-#{order.id}", function(e) { e.preventDefault(); console.log("hi"); // Extract selected group_order_ids var selectedGroupOrderIds = $('input[name^="group_order_ids_for_order_#{order.id}"]:checked').map(function() { return $(this).val(); }).get(); // Log the selected IDs (for testing purposes) console.log('Selected Group Order IDs:', selectedGroupOrderIds); var url = $(this).closest('a').attr('href'); //suppress generic error warning $.ajaxSetup({ global: false, }); $.ajax({ url: url, method: 'GET', // You may adjust the HTTP method as needed data: { group_order_ids: selectedGroupOrderIds }, dataType: 'xml', success: function(response) { // Handle success response console.log('AJAX request successful:', response); // Convert XML response to a Blob var blob = new Blob([new XMLSerializer().serializeToString(response)], { type: 'text/xml' }); // Create a temporary link element var link = document.createElement('a'); link.href = URL.createObjectURL(blob); if(selectedGroupOrderIds.length > 1){ link.download = "#{order.supplier.name}-#{order.id}-Sammellastschrift.xml"; } else { link.download = "#{order.supplier.name}-#{order.id}-Lastschrift.xml"; } // Append the link to the document and trigger the click event document.body.appendChild(link); link.click(); // Clean up document.body.removeChild(link); $("group-order-invoices-for-order-#{order.id}" + " .expand-trigger a").click(); }, error: function(error) { // Handle error if (error.responseJSON) { alert('AJAX request error:' + "\n" + error.responseJSON.message); } else{ var errorText = JSON.parse(error.responseText).error; var alertDiv = '