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();
}
},
});
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,218 @@
/**
* 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 () {
const inpostChooseMachineButtonSelector = '.js-inpost-shipping-choose-machine';
const inpostCustomerChangeButtonSelector = '.js-inpost-shipping-customer-change';
const inpostCustomerSaveButtonSelector = '.js-inpost-shipping-customer-form-save-button';
const inpostInputSelector = '.js-inpost-shipping-input';
const $carrierAreaFormSubmitButton = 'button[name=processCarrier]';
const map = new InPostShippingModalMap();
$(document).on('click', inpostChooseMachineButtonSelector, function (e) {
e.preventDefault();
const $that = $(this);
const payment = parseInt($that.attr('data-inpost-shipping-payment'));
const weekendDelivery = parseInt($that.attr('data-inpost-shipping-weekend-delivery'));
const input = $(inpostInputSelector);
map.openMap({
payment: payment,
weekendDelivery: weekendDelivery,
pointName: input.val(),
callback: function (point) {
const $machineInfo = $('.js-inpost-shipping-machine-info');
const $customerInfo = $('.js-inpost-shipping-machine-customer-info');
const $machineName = $('.js-inpost-shipping-machine-name');
const $machineAddress = $('.js-inpost-shipping-machine-address');
const $inpostChooseMachineButton = $('.js-inpost-shipping-choose-machine');
const inpostChooseMachineButtonSelectorText = $inpostChooseMachineButton.attr('data-inpost-shipping-existing-text');
$machineName.html(point.name);
$machineAddress.html(`${point.address.line1}, ${point.address.line2}`);
$machineInfo.removeClass('hidden');
$customerInfo.removeClass('hidden');
$inpostChooseMachineButton.html(inpostChooseMachineButtonSelectorText);
input.val(point.name).trigger('change');
}
});
$('.widget-modal').parent('div').addClass('inpost-shipping-backdrop');
});
$(document).on('click', inpostCustomerChangeButtonSelector, function () {
const $inpostCustomerChangeForm = $('.inpost-shipping-customer-change-form');
$inpostCustomerChangeForm.slideToggle(300);
});
$(document).on('click', inpostCustomerSaveButtonSelector, function () {
const $inpostErrorsWrapper = $('.js-inpost-shipping-errors');
const $inpostCustomerEmailInfo = $('.js-inpost-shipping-customer-info-email');
const $inpostCustomerPhoneInfo = $('.js-inpost-shipping-customer-info-phone');
const $inpostCustomerEmail = $('.js-inpost-shipping-email').val();
const $inpostCustomerPhone = $('.js-inpost-shipping-phone').val();
const $inpostCustomerChangeForm = $('.inpost-shipping-customer-change-form');
const $inpostCustomerInputs = $inpostCustomerChangeForm.find('input.form-control');
const formData = new FormData();
$.each($inpostCustomerInputs, function (index, element) {
formData.append(element.name, element.value);
});
formData.append('action', 'updateReceiverDetails');
$.ajax({
method: 'post',
url: inPostAjaxController,
data: formData,
processData: false,
contentType: false,
dataType: 'json',
success: function (response) {
if (response.success) {
$inpostErrorsWrapper.html('');
$inpostCustomerEmailInfo.html($inpostCustomerEmail);
$inpostCustomerPhoneInfo.html($inpostCustomerPhone);
$inpostCustomerChangeForm.slideUp(300);
} else {
const errors = getInPostErrors(response, ['phone', 'email']);
$inpostErrorsWrapper.html(`<article class="alert alert-danger"><ul>${errors}</ul></article>`);
}
},
});
});
$(document).on('change', inpostInputSelector, function () {
const $that = $(this);
const $inpostErrorsWrapper = $('.js-inpost-shipping-errors');
const formData = new FormData();
formData.append($that.attr('name'), $that.val());
formData.append('action', 'updateTargetLocker');
$.ajax({
method: 'post',
url: inPostAjaxController,
data: formData,
processData: false,
contentType: false,
dataType: 'json',
success: function (response) {
if (response.success) {
$inpostErrorsWrapper.html('');
} else {
const errors = getInPostErrors(response);
$inpostErrorsWrapper.html(`<article class="alert alert-danger"><ul>${errors}</ul></article>`);
}
},
});
});
$(document).on('click', $carrierAreaFormSubmitButton, function () {
const $inpostInput = $(inpostInputSelector);
if ($inpostInput.length && !$inpostInput.val().length) {
const errorText = $inpostInput.attr('data-error-text')
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: `<p class="fancybox-error">${errorText}</p>`
}],
{
padding: 0
});
else {
alert(errorText);
}
} else {
return true;
}
return false;
});
const $paymentLinkSelector = '#opc_payment_methods-content a';
$(document).on('click', $paymentLinkSelector, function (e) {
const $inpostCustomerChangeForm = $('.js-inpost-shipping-container');
if ($inpostCustomerChangeForm.length) {
e.preventDefault();
const $that = $(this);
const $inpostCustomerInputs = $inpostCustomerChangeForm.find('input.form-control');
const formData = new FormData();
$.each($inpostCustomerInputs, function (index, element) {
formData.append(element.name, element.value);
});
formData.append('action', 'updateChoice');
$.ajax({
method: 'post',
url: inPostAjaxController,
data: formData,
processData: false,
contentType: false,
dataType: 'json',
success: function (response) {
if (response.success) {
window.location.href = $that.attr('href');
} else {
const errors = getInPostErrors(response);
if (!!$.prototype.fancybox)
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
minWidth: 280,
content: `<article class="alert alert-danger" style="margin-bottom: 0"><ul>${errors}</ul></article>`
}],
{
padding: 0
});
else {
alert(errors);
}
}
},
});
}
});
function getInPostErrors(response, types = ['phone', 'email', 'locker']) {
let errors = '';
$(types).each(function (idx, value) {
if (value in response.errors) {
errors += `<li>${response.errors[value]}</li>`;
}
});
return errors;
}
});

View File

@@ -0,0 +1,152 @@
/**
* 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 () {
const inpostChooseMachineButtonSelector = '.js-inpost-shipping-choose-machine';
const inpostCustomerChangeButtonSelector = '.js-inpost-shipping-customer-change';
const inpostCustomerSaveButtonSelector = '.js-inpost-shipping-customer-form-save-button';
const inpostCustomerEmailSelector = '.js-inpost-shipping-email';
const inpostCustomerPhoneSelector = '.js-inpost-shipping-phone';
const inpostCustomerInfoEmail = $('.js-inpost-shipping-customer-info-email');
const inpostCustomerInfoPhone = $('.js-inpost-shipping-customer-info-phone');
const map = new InPostShippingModalMap();
$(document).on('click', inpostChooseMachineButtonSelector, function (e) {
e.preventDefault();
const $that = $(this);
const $paczkomatInput = $that.parents('.carrier-extra-content').find('.js-inpost-shipping-input');
const payment = parseInt($that.attr('data-inpost-shipping-payment'));
const weekendDelivery = parseInt($that.attr('data-inpost-shipping-weekend-delivery'));
map.openMap({
payment: payment,
weekendDelivery: weekendDelivery,
pointName: $paczkomatInput.val(),
callback: function (point) {
const $choosedMethod = $paczkomatInput.parents('.carrier-extra-content');
const $machineInfo = $choosedMethod.find('.js-inpost-shipping-machine-info');
const $customerInfo = $choosedMethod.find('.js-inpost-shipping-machine-customer-info');
const $machineName = $choosedMethod.find('.js-inpost-shipping-machine-name');
const $machineAddress = $choosedMethod.find('.js-inpost-shipping-machine-address');
const $inpostChooseMachineButton = $choosedMethod.find('.js-inpost-shipping-choose-machine');
const $errorsContainer = $choosedMethod.find('.js-inpost-shipping-locker-errors');
const inpostChooseMachineButtonSelectorText = $inpostChooseMachineButton.attr('data-inpost-shipping-existing-text');
const formData = new FormData();
formData.append($paczkomatInput.attr('name'), point.name);
formData.append('action', 'updateTargetLocker');
$.ajax({
method: 'post',
url: inPostAjaxController,
data: formData,
processData: false,
contentType: false,
dataType: 'json',
success: function (response) {
if (response.success) {
$errorsContainer.html('');
$machineName.html(point.name);
$machineAddress.html(`${point.address.line1}, ${point.address.line2}`);
$machineInfo.removeClass('hidden');
$customerInfo.removeClass('hidden');
$inpostChooseMachineButton.html(inpostChooseMachineButtonSelectorText);
$paczkomatInput.val(point.name);
} else if ('locker' in response.errors) {
$errorsContainer.html(`<li class="alert alert-danger">${response.errors.locker}</li>`);
} else {
alert(response.errors[0]);
}
},
});
}
});
$('.widget-modal').parent('div').addClass('inpost-shipping-backdrop');
});
$(document).on('click', inpostCustomerChangeButtonSelector, function () {
const $that = $(this);
const $inpostCustomerChangeForm = $that.parents('.carrier-extra-content').find('.inpost-shipping-customer-change-form');
$inpostCustomerChangeForm.slideToggle(300);
})
$(document).on('click', inpostCustomerSaveButtonSelector, function () {
const $that = $(this);
const $inpostCustomerChangeForm = $that.parents('.carrier-extra-content').find('.inpost-shipping-customer-change-form');
const $emailField = $inpostCustomerChangeForm.find(inpostCustomerEmailSelector);
const $emailGroup = $emailField.closest('.form-group');
const $emailErrorsContainer = $emailGroup.find('.help-block ul');
const $phoneField = $inpostCustomerChangeForm.find(inpostCustomerPhoneSelector);
const $phoneGroup = $phoneField.closest('.form-group');
const $phoneErrorsContainer = $phoneGroup.find('.help-block ul');
const formData = new FormData();
formData.append($emailField.attr('name'), $emailField.val());
formData.append($phoneField.attr('name'), $phoneField.val());
formData.append('action', 'updateReceiverDetails');
$.ajax({
method: 'post',
url: inPostAjaxController,
data: formData,
processData: false,
contentType: false,
dataType: 'json',
success: function (response) {
if (response.success) {
$emailGroup.removeClass('has-errors');
$emailErrorsContainer.html('');
$phoneGroup.removeClass('has-errors');
$phoneErrorsContainer.html('');
$inpostCustomerChangeForm.slideUp(300);
} else {
if ('email' in response.errors) {
$emailGroup.addClass('has-errors');
$emailErrorsContainer.html(`<li class="alert alert-danger">${response.errors.email}</li>`);
}
if ('phone' in response.errors) {
$phoneGroup.addClass('has-errors');
$phoneErrorsContainer.html(`<li class="alert alert-danger">${response.errors.phone}</li>`);
}
}
},
});
});
$(document).on('input', inpostCustomerEmailSelector, function () {
let val = $(this).val();
$(inpostCustomerEmailSelector).val(val);
inpostCustomerInfoEmail.html(val);
});
$(document).on('input', inpostCustomerPhoneSelector, function () {
let val = $(this).val();
$(inpostCustomerPhoneSelector).val($(this).val());
inpostCustomerInfoPhone.html(val);
});
});

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,92 @@
/**
* 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
*/
class InPostShippingModalMap {
constructor() {
this.type = null;
this.function = null;
}
openMap(config) {
const options = {
payment: config.payment || false,
weekendDelivery: config.weekendDelivery || false,
pointName: config.pointName || '',
type: 'parcel_locker_only' === config.type || 'pop' === config.type ? config.type : 'parcel_locker',
function: 'parcel_send' === config.function ? 'parcel_send' : 'parcel_collect',
};
if (options.payment || options.weekendDelivery) {
options.type = 'parcel_locker_only';
}
if (options.type !== this.type || options.function !== this.function) {
this.type = options.type;
this.function = options.function;
const widget = $('#widget-modal');
if (widget.length) {
widget.remove();
}
const widgetConfig = {
map: {
initialTypes: [options.type],
},
points: {
types: [options.type],
functions: ['parcel', options.function],
},
display: {
showTypesFilters: false,
showSearchBar: true,
},
};
// if showOnlyWithPayment is set, only points that allow credit card payments are shown on the map
/*
if (options.payment) {
widgetConfig.paymentFilter = {
showOnlyWithPayment: true,
};
}
*/
easyPack.init(widgetConfig);
}
const modal = easyPack.modalMap(function (point, modal) {
modal.closeModal();
if (typeof config.callback === 'function') {
config.callback(point);
}
}, {});
const widget = $('#widget-modal');
widget.css('max-height', '90%');
if ('' !== options.pointName) {
modal.searchLockerPoint(options.pointName);
}
}
}

View File

@@ -0,0 +1,57 @@
/**
* 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
*/
$(() => {
if ('function' === typeof addSupercheckoutOrderValidator) {
addSupercheckoutOrderValidator(() => {
const $contentWrapper = $('.js-inpost-shipping-container:visible');
if ($contentWrapper.length > 0) {
const formData = new FormData();
formData.append('action', 'updateChoice');
$contentWrapper.find(':input').each((index, element) => {
const $input = $(element);
formData.append($input.attr('name'), $input.val());
});
$.ajax({
async: false,
method: 'post',
url: inPostAjaxController,
data: formData,
processData: false,
contentType: false,
dataType: 'json'
}).then((response) => {
if (false === response.success) {
const errors = $.map(response.errors, (error) => `<li>${error}</li>`).join('');
throw {
message: `<ul>${errors}</ul>`
}
}
});
}
});
}
});