foodsoft/app/views/group_order_invoices/_modal.html.haml

97 lines
No EOL
3.7 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

.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 = '<div class="alert fade in alert-error"><button class="close" data-dismiss="alert">×</button>' + errorText + '</div>';
$('.page-header').before(alertDiv);
}
}
});
});});
- content_for :javascript do
:javascript
$("#order_#{order.id}_modal").off('change', ".ajax-update-all-link-#{order.id} select").on('change', ".ajax-update-all-link-#{order.id} select", function() {
var selectedValue = $(this).val();
var url = $(this).closest('a').attr('href');
$.ajax({
url: url,
method: 'PATCH',
data: { sepa_sequence_type: selectedValue },
success: function(response) {
// Handle success response
},
error: function(error) {
console.log(error);
}
});})
- order.group_orders.each do |group_order|
- content_for :javascript do
:javascript
$(document).off('change', ".ajax-update-link-#{group_order.id} select").on('change', ".ajax-update-link-#{group_order.id} select", function() {
var selectedValue = $(this).val();
var url = $(this).closest('a').attr('href');
$.ajax({
url: url,
method: 'PATCH',
data: { sepa_sequence_type: selectedValue },
success: function(response) {
// Handle success response
},
error: function(error) {
// Handle error
}
});})