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

123 lines
No EOL
4.8 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() {
// Function For Downloading the xml
function doTheDownload(selectedGroupOrderIds, url, mode="all"){
if(mode == "all")
{
var data = { order_id: "#{order.id}" }
}
else
{
var data = { group_order_ids: selectedGroupOrderIds }
}
if(mode == "all" || selectedGroupOrderIds.length > 0)
{
//suppress generic error warning
$.ajaxSetup({
global: false,
});
$.ajax({
url: url,
method: 'GET', // You may adjust the HTTP method as needed
data: data,
dataType: 'xml',
success: function(response) {
// Handle success response
// Convert XML response to a Blob
var blob = new Blob([new XMLSerializer().serializeToString(response)], { type: 'text/xml' });
var order_id ="#{order.id}"
// 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();
$("#order_" + order_id + "_modal").load(window.location + " #order_" + order_id + "_modal");
},
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);
$('modal_')
}
}
});
}
else{
var errorText = "Nothing selected";
var alertDiv = '<div class="alert fade in alert-error"><button class="close" data-dismiss="alert">×</button>' + errorText + '</div>';
$('.page-header').before(alertDiv);
}
}
// register onClick listener for selected group_orders
$("#order_#{order.id}_modal").on('click', "#collective-direct-debit-link-selected-#{order.id}", function(e) {
e.preventDefault();
// Extract selected group_order_ids
var selectedGroupOrderIds = $('input[name^="group_order_ids_for_order_#{order.id}"]:checked').map(function() {
return $(this).val();
}).get();
var url = $(this).closest('a').attr('href');
doTheDownload(selectedGroupOrderIds, url, "selected");
});
// register onClick listener for all group_orders
$("#order_#{order.id}_modal").on('click', "#collective-direct-debit-link-all-#{order.id}", function(e) {
e.preventDefault();
var url = $(this).closest('a').attr('href');
doTheDownload([], url, "all");
});
});
- 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
}
});})