- ${errors}
/** * 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('