first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
$(document).ready(function() {
$(document).on('click', '.js-createDispatchOrder', function (e) {
e.preventDefault();
const link = $(this);
const form = $('#inpost-dispatch-order-form');
form.find('input[name="id_shipment"]').val(link.data('id-shipment'));
openDispatchOrderModal(link.attr('href'));
});
$(document).on('click', '.js-printLabel', function (e) {
e.preventDefault();
openPrintLabelModal($(this).attr('href'));
});
$(document).on('click', '.js-printReturnLabel', function (e) {
e.preventDefault();
openPrintLabelModal($(this).attr('href'), false);
});
});

View File

@@ -0,0 +1,38 @@
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
$(document).ready(function () {
$(document).on('click', '.js-print', function(e) {
e.preventDefault();
inPostShippingXhr({
type: 'GET',
url: $(this).attr('href'),
callbackBlob: blobFileDownload,
callbackJson: function (response) {
if ('errors' in response) {
displayAjaxErrors(response.errors);
}
},
});
});
});

View File

@@ -0,0 +1,28 @@
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
$(document).ready(function () {
const headTabs = $('#head_tabs_inpost');
$('#head_tabs').html(headTabs.html());
headTabs.remove();
});

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,318 @@
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
$(document).ready(function () {
$('#inpost-create-shipment-modal').on('shown.bs.modal', function() {
$(document).off('focusin.modal');
});
$(document).on('click', '.js-submit-shipment-form', function (e) {
e.preventDefault();
const button = $(this);
const form = $('#inpost-shipment-form');
const formData = new FormData(form.get(0));
formData.append('ajax', '1');
inPostShippingXhr({
type: 'POST',
url: form.attr('action'),
data: formData,
callbackJson: function (response) {
if (response.status === true) {
window.location.reload();
} else {
const errorsWrapper = $('#inpost-shipment-form-errors');
const errors = response.errors.join('</li><li>');
errorsWrapper.html(`<article class="alert alert-danger"><ul><li>${errors}</li></ul></article>`);
scrollElementIntoView(errorsWrapper);
if ('shipmentId' in response) {
form.find('.form-wrapper').remove();
button.remove();
$('#inpost-create-shipment-modal').on('hidden.bs.modal', function () {
window.location.reload();
});
}
}
},
});
});
$(document).on('click', '.js-submit-dispatch-order-form', function (e) {
e.preventDefault();
submitDispatchOrderForm();
});
$(document).on('click', '.js-printDispatchOrder', function(e) {
e.preventDefault();
inPostShippingXhr({
url: $(this).attr('href'),
callbackBlob: blobFileDownload,
callbackJson: function (response) {
if ('errors' in response) {
showErrorMessage(response.errors.join('<br/>'));
}
},
});
});
$(document).on('click', '.js-submit-print-label-form', function (e) {
e.preventDefault();
submitPrintLabelForm(function (response) {
if ('errors' in response) {
showErrorMessage(response.errors.join('<br/>'));
}
});
});
let id_shipment = null;
$(document).on('click', '.js-view-inpost-shipment-details', function (e) {
e.preventDefault();
const dataId = $(this).data('id-shipment');
if (id_shipment !== dataId) {
$.ajax({
url: $(this).attr('href'),
dataType: 'json',
success: function (response) {
if (response.status === true) {
id_shipment = dataId;
const contentWrapper = $('#inpost-shipment-details-content-wrapper');
contentWrapper.html(response.content);
if (shopIs177) {
contentWrapper.find('[data-toggle="pstooltip"]').pstooltip();
}
$('#inpost-shipment-details-modal').modal('show');
} else {
showErrorMessage(response.errors.join('<br/>'));
}
},
});
} else {
$('#inpost-shipment-details-modal').modal('show');
}
});
$(document).on('click', '.js-inpost-new-dispatch-order', function (e) {
e.preventDefault();
const url = new URL($(this).attr('href'));
url.searchParams.set('back', window.location.href);
window.location.href = url.toString();
});
$(document).on('click', '.js-inpost-clear-point', function (e) {
e.preventDefault();
const input = $($(this).data('target'));
input.data('point', '');
input.val('');
});
$(document).on('change', '#service', changeShippingService);
$(document).on('change', '#sending_method', changeSendingMethod);
$(document).on('change', 'input[name="use_template"]', toggleTemplate);
$(document).on('change', 'input[name="cod"]', toggleCashOnDelivery);
$(document).on('change', 'input[name="insurance"]', toggleInsurance);
changeShippingService();
toggleCashOnDelivery();
const map = new InPostShippingModalMap();
function openMap(selector, payment = false, weekendDelivery = false, callback = null) {
map.openMap({
payment: payment,
weekendDelivery: weekendDelivery,
pointName: selector.data('point'),
type: selector.data('type'),
function: selector.data('function'),
callback: callback,
});
}
$(document).on('click', '.js-inpost-show-map-input', function (e) {
e.preventDefault();
const input = $($(this).data('target-input'));
let payment, weekendDelivery = false;
if (input.data('payment')) {
payment = $('#cod_on').is(':checked');
weekendDelivery = $('#weekend_delivery_on').is(':checked');
}
openMap(input, payment, weekendDelivery, function (point) {
input.data('point', point.name);
input.val(point.name);
});
});
$(document).on('click', '.js-inpost-show-map', function () {
openMap($(this));
});
const lockerAddress = $('.js-inpost-locker-address');
if (lockerAddress.length > 0) {
const target = shopIs177 ? '#addressShipping' : '#addressShipping .col-sm-6:not(.hidden-print)';
lockerAddress.appendTo(target).show();
}
});
function toggleTemplate() {
if ($('input[name="use_template"]:checked').val() === '1') {
$('#template').closest('.form-group').show();
$('#js-inpost-package-dimensions').hide();
} else {
$('#template').closest('.form-group').hide();
$('#js-inpost-package-dimensions').show();
}
}
function toggleCashOnDelivery() {
if ($('input[name="cod"]:checked').val() === '1') {
$('input[name="cod_amount"]').closest('.form-group').show();
} else {
$('input[name="cod_amount"]').closest('.form-group').hide();
}
updateInsuranceDisplay();
}
function toggleInsurance() {
if ($('input[name="insurance"]:checked').val() === '1') {
$('input[name="insurance_amount"]').closest('.form-group').show();
} else {
$('input[name="insurance_amount"]').closest('.form-group').hide();
}
}
function updateInsuranceDisplay() {
if ($('#service').val() !== inPostLockerStandard && $('#cod_on').is(':checked')) {
$('#insurance_on').prop('checked', true).trigger('change');
$('input[name="insurance"]').closest('.form-group').hide();
$('label[for="insurance_amount"]').addClass('required');
} else {
$('input[name="insurance"]').closest('.form-group').show();
$('label[for="insurance_amount"]').removeClass('required');
}
}
function changeShippingService() {
const service = $('#service').val();
if (service === inPostLockerStandard) {
$('#inpost-locker-content-wrapper').show();
} else {
$('#inpost-locker-content-wrapper').hide();
}
if (inPostLockerServices.indexOf(service) !== -1) {
$('#js-inpost-dimension-template-content-wrapper').show();
} else {
$('#js-inpost-dimension-template-content-wrapper').hide();
$('#template_off').prop('checked', true);
toggleTemplate();
}
updateSendingMethodOptions();
updateInsuranceDisplay();
}
function updateSendingMethodOptions() {
const selectedService = $('#service option:selected');
const availableSendingMethods = selectedService.data('sending-methods');
$('#sending_method option').each(function () {
const disable = availableSendingMethods.indexOf($(this).val()) === -1;
$(this)
.prop('disabled', disable)
.prop('hidden', disable);
});
if ($('#sending_method option:selected').is(':disabled')) {
const defaultSendingMethod = selectedService.data('default-sending-method');
if (defaultSendingMethod) {
$(`#sending_method option[value="${defaultSendingMethod}"]`).prop('selected', true);
} else {
$('#sending_method option:not(:disabled):first').prop('selected', true);
}
}
changeSendingMethod();
}
function updateTemplateOptions() {
const unavailableTemplates = $('#sending_method option:selected').data('unavailable-templates') || [];
const selectedService = $('#service option:selected');
let availableTemplates = selectedService.data('templates') || [];
if (unavailableTemplates.length) {
availableTemplates = availableTemplates.filter(function (template) {
return unavailableTemplates.indexOf(template) === -1
});
}
$('#template option').each(function () {
const disable = availableTemplates.indexOf($(this).val()) === -1;
$(this)
.prop('disabled', disable)
.prop('hidden', disable);
});
if ($('#template option:selected').is(':disabled')) {
const defaultTemplate = selectedService.data('default-template');
if (defaultTemplate && unavailableTemplates.indexOf(defaultTemplate) === -1) {
$(`#template option[value="${defaultTemplate}"]`).prop('selected', true);
} else {
$('#template option:not(:disabled):first').prop('selected', true);
}
}
}
function changeSendingMethod() {
const popGroup = $('#dropoff_pop').closest('.form-group');
const lockerGroup = $('#dropoff_locker').closest('.form-group');
const sendingMethod = $('#sending_method').val();
popGroup.hide();
lockerGroup.hide();
if (sendingMethod === 'parcel_locker') {
lockerGroup.show();
} else if (
sendingMethod === 'pop' &&
inPostLockerServices.indexOf($('#service').val()) !== -1
) {
popGroup.show();
}
updateTemplateOptions();
}

View File

@@ -0,0 +1,131 @@
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
$(document).ready(function () {
$(document).on('click', '.js-inpost-bulk-create-shipments', function (e) {
e.preventDefault();
submitBulkCreateShipments(function (response) {
if ('redirect' in response) {
window.location.href = response.redirect;
}
});
});
$(document).on('click', '.js-inpost-bulk-create-print-shipments', function (e) {
e.preventDefault();
openPrintLabelModal($(this).data('action'));
});
$(document).on('click', '.js-submit-print-label-form', function (e) {
e.preventDefault();
submitBulkCreateShipments(function (response) {
if ('shipmentIds' in response) {
const formData = new FormData();
$(response.shipmentIds).each(function (idx, value) {
formData.append('inpost_shipmentBox[]', value);
});
submitPrintLabelForm(function (response) {
if ('errors' in response) {
displayAjaxErrors(response.errors);
}
}, formData);
}
});
});
$(document).on('click', '.js-inpost-bulk-create-dispatch-orders', function (e) {
e.preventDefault();
openDispatchOrderModal($(this).data('action'));
});
$(document).on('click', '.js-submit-dispatch-order-form', function (e) {
e.preventDefault();
submitDispatchOrderForm(getOrderBoxData());
});
$(document).on('click', '.js-inpost-bulk-print-dispatch-orders', function(e) {
e.preventDefault();
inPostShippingXhr({
type: 'POST',
url: $(this).data('action'),
data: getOrderBoxData(),
callbackBlob: blobFileDownload,
callbackJson: function (response) {
if ('errors' in response) {
displayAjaxErrors(response.errors);
}
},
});
});
$(document).on('click', '.js-inpost-bulk-refresh-shipment-status', function (e) {
e.preventDefault();
inPostShippingXhr({
type: 'POST',
url: $(this).data('action'),
data: getOrderBoxData(),
callbackJson: function (response) {
if ('errors' in response) {
displayAjaxErrors(response.errors);
} else {
displayAjaxSuccess(response.message);
}
},
});
});
});
function submitBulkCreateShipments(callback) {
inPostShippingXhr({
type: 'POST',
url: $('.js-inpost-bulk-create-shipments').data('action'),
data: getOrderBoxData(),
callbackJson: function (response) {
if ('errors' in response) {
displayAjaxErrors(response.errors);
}
callback(response);
},
});
}
function getOrderBoxData() {
const formData = new FormData();
const boxes = shopIs177
? $('.js-bulk-action-checkbox:checked')
: $('#form-order input[name="orderBox[]"]:checked');
boxes.each(function () {
formData.append('orderIds[]', $(this).val());
});
return formData;
}

View File

@@ -0,0 +1,137 @@
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
$(document).ready(function () {
$('.bulk-actions a').each(function () {
const that = $(this);
const actionRegex = /sendBulkAction\(.*, ['"]submit(.*)inpost_shipment['"]\)/;
const matches = actionRegex.exec(that.attr('onclick'));
if (matches != null && matches[1]) {
that.removeAttr('onclick');
that.addClass('js-bulk-' + matches[1].replace('Bulk', ''));
that.attr('data-action', matches[1]);
}
});
$(document).on('click', '.js-bulk-printLabels', function (e) {
e.preventDefault();
openPrintLabelModal(
getBulkActionUrl($(this).data('action'))
);
});
$(document).on('click', '.js-bulk-printReturnLabels', function (e) {
e.preventDefault();
openPrintLabelModal(
getBulkActionUrl($(this).data('action')),
false
);
});
$(document).on('click', '.js-bulk-printDispatchOrders', function(e) {
e.preventDefault();
inPostShippingXhr({
type: 'POST',
url: getBulkActionUrl($(this).data('action')),
data: getShipmentBoxData(),
callbackBlob: blobFileDownload,
callbackJson: function (response) {
if ('errors' in response) {
displayAjaxErrors(response.errors);
}
},
});
});
$(document).on('click', '.js-bulk-createDispatchOrders', function (e) {
e.preventDefault();
openDispatchOrderModal(
getBulkActionUrl($(this).data('action'))
);
});
$(document).on('click', '.js-submit-dispatch-order-form', function (e) {
e.preventDefault();
const formData = $('#inpost-dispatch-order-form').attr('action').indexOf('Bulk') !== -1
? getShipmentBoxData()
: null;
submitDispatchOrderForm(formData);
});
$(document).on('click', '.js-printDispatchOrder', function(e) {
e.preventDefault();
inPostShippingXhr({
type: 'GET',
url: $(this).attr('href'),
callbackBlob: blobFileDownload,
callbackJson: function (response) {
if ('errors' in response) {
displayAjaxErrors(response.errors);
}
},
});
});
$(document).on('click', '.js-submit-print-label-form', function (e) {
e.preventDefault();
const formData = $('#inpost-print-shipment-label-form').attr('action').indexOf('Bulk') !== -1
? getShipmentBoxData()
: null;
submitPrintLabelForm(function (response) {
if ('errors' in response) {
displayAjaxErrors(response.errors);
$('#inpost-print-shipment-label-modal').modal('hide');
}
}, formData);
});
});
function getBulkActionUrl(action) {
const url = new URL(controllerUrl);
url.searchParams.set('action', action);
url.searchParams.set('ajax', '1');
return url.toString();
}
function getShipmentBoxData()
{
const formData = new FormData();
$('#form-inpost_shipment input[name="inpost_shipmentBox[]"]:checked').each(function () {
const input = $(this);
formData.append(input.attr('name'), input.val());
});
return formData;
}

View File

@@ -0,0 +1,189 @@
/**
* Copyright 2021-2022 InPost S.A.
*
* NOTICE OF LICENSE
*
* Licensed under the EUPL-1.2 or later.
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
* It is also bundled with this package in the file LICENSE.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Licence is distributed on an AS IS basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions
* and limitations under the Licence.
*
* @author InPost S.A.
* @copyright 2021-2022 InPost S.A.
* @license https://joinup.ec.europa.eu/software/page/eupl
*/
function inPostShippingXhr(config) {
const options = {
type: config.type || 'POST',
url: config.url || window.location.href,
data: config.data || null,
}
const loader = $('.inpost-loader');
loader.addClass('active');
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
const contentType = xhr.getResponseHeader('Content-type');
if (contentType === 'application/json') {
xhr.responseType = 'json';
} else if (contentType === 'text/html') {
xhr.responseType = 'text';
} else {
xhr.responseType = 'blob';
}
} else if (xhr.readyState === XMLHttpRequest.DONE) {
loader.removeClass('active');
if (xhr.status === 200) {
if (xhr.responseType === 'json') {
if (typeof config.callbackJson === 'function') {
config.callbackJson(xhr.response, xhr);
}
} else if (xhr.responseType === 'text') {
if (typeof config.callbackHtml === 'function') {
config.callbackHtml(xhr.response, xhr);
}
} else if (typeof config.callbackBlob === 'function') {
config.callbackBlob(xhr.response, xhr);
}
}
}
}
xhr.open(options.type, options.url, true);
xhr.send(options.data);
}
function blobFileDownload(data, xhr) {
let filename = '';
const disposition = xhr.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
const matches = filenameRegex.exec(disposition);
if (matches != null && matches[1]) {
filename = matches[1].replace(/['"]/g, '');
}
}
const blob = new Blob([data], {
type: xhr.getResponseHeader('Content-type'),
});
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
a.remove();
}
function displayAjaxErrors(errors) {
const ajaxBox = $('#ajaxBox');
errors = errors.join('</li><li>');
ajaxBox
.html(`<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert">&times;</button><ul><li>${errors}</li></ul></div>`)
.show();
scrollElementIntoView(ajaxBox);
}
function displayAjaxSuccess(message) {
const ajaxBox = $('#ajaxBox');
ajaxBox
.html(`<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">&times;</button>${message}</div>`)
.show();
scrollElementIntoView(ajaxBox);
}
function scrollElementIntoView(selector) {
selector.get(0).scrollIntoView({
block: 'end',
behavior: 'smooth',
});
}
function openPrintLabelModal(action, showType = true) {
const form = $('#inpost-print-shipment-label-form');
form.attr('action', action);
if (showType) {
form.find('input[name="label_type"]').closest('.form-group').show();
} else {
form.find('input[name="label_type"]').closest('.form-group').hide();
}
$('#inpost-print-shipment-label-modal').modal('show');
}
function submitPrintLabelForm(callbackJson, formData = null) {
const form = $('#inpost-print-shipment-label-form');
if (formData) {
form.find('input:checked').each(function () {
const input = $(this);
formData.append(input.attr('name'), input.val());
});
} else {
formData = new FormData(form.get(0));
}
inPostShippingXhr({
url: form.attr('action'),
data: formData,
callbackBlob: function(data, xhr) {
blobFileDownload(data, xhr);
$('#inpost-print-shipment-label-modal').modal('hide');
},
callbackJson: callbackJson,
});
}
function openDispatchOrderModal(action) {
const form = $('#inpost-dispatch-order-form');
form.attr('action', action);
$('#inpost-create-dispatch-order-modal').modal('show');
}
function submitDispatchOrderForm(formData = null) {
const form = $('#inpost-dispatch-order-form');
if (formData) {
formData.append('id_dispatch_point', $('#id_dispatch_point').val());
} else {
formData = new FormData(form.get(0));
}
formData.append('ajax', '1');
inPostShippingXhr({
url: form.attr('action'),
data: formData,
callbackJson: function (response) {
if ('errors' in response) {
const errors = response.errors.join('</li><li>');
$('#inpost-dispatch-order-form-errors').html(`<article class="alert alert-danger"><ul><li>${errors}</li></ul></article>`);
} else if ('redirect' in response) {
window.location.href = response.redirect;
} else {
window.location.reload();
}
},
});
}