first commit
This commit is contained in:
176
web/js/basket-delivery-list.js.bck
Normal file
176
web/js/basket-delivery-list.js.bck
Normal file
@@ -0,0 +1,176 @@
|
||||
jQuery(function ($) {
|
||||
const shoppingCartDelivery = $('#shopping-cart-delivery');
|
||||
const deliveryModal = $('#delivery-modal');
|
||||
const deliveryMessageModal = $('#delivery-message-modal');
|
||||
const deliveryCountry = $('#delivery-country');
|
||||
let selectedDelivery = shoppingCartDelivery.find('.delivery-radio:checked');
|
||||
let selectedCountryId = deliveryCountry.val();
|
||||
let userAuthenticated = false;
|
||||
|
||||
function selectedPickupPointUpdate(pickupPointContainer, pickupPoint) {
|
||||
const selectedPickupPoint = pickupPointContainer.find('.selected-pickup-point');
|
||||
|
||||
if (pickupPoint) {
|
||||
selectedPickupPoint.find('.name').html(pickupPoint.name);
|
||||
selectedPickupPoint.find('.address').html(pickupPoint.address);
|
||||
selectedPickupPoint.find('.post-code').html(pickupPoint.postCode);
|
||||
selectedPickupPoint.find('.city').html(pickupPoint.city);
|
||||
selectedPickupPoint.show();
|
||||
} else {
|
||||
selectedPickupPoint.hide();
|
||||
}
|
||||
}
|
||||
|
||||
function onChangeDeliveryHandle() {
|
||||
selectedDelivery = $(this);
|
||||
const orderFormDelivery = $('#order_form_delivery');
|
||||
const differentDelivery = $('#different_delivery');
|
||||
|
||||
shoppingCartDelivery.find('.selected-pickup-point').hide();
|
||||
|
||||
if (selectedDelivery.data('delivery-pickup-point')) {
|
||||
const pickupPoint = $.deliveryPickupPoint.get();
|
||||
const pickupPointContainer = selectedDelivery.closest('label').find('.delivery-pickup-point-container');
|
||||
|
||||
selectedPickupPointUpdate(pickupPointContainer, pickupPoint); console.log(pickupPoint );
|
||||
$('#delivery_pickup_point').val(JSON.stringify(pickupPoint));
|
||||
|
||||
orderFormDelivery.hide();
|
||||
|
||||
if (differentDelivery.prop('checked')) {
|
||||
differentDelivery.get(0).click();
|
||||
}
|
||||
|
||||
differentDelivery.prop('disabled', true);
|
||||
} else {
|
||||
|
||||
if (userAuthenticated) {
|
||||
orderFormDelivery.show();
|
||||
}
|
||||
|
||||
differentDelivery.prop('disabled', false);
|
||||
}
|
||||
|
||||
$(window).trigger('resize');
|
||||
}
|
||||
|
||||
$.initBasketDeliveryList = function(isUserAuthenticated) {
|
||||
userAuthenticated = isUserAuthenticated;
|
||||
onChangeDeliveryHandle.call(shoppingCartDelivery.find('.delivery-radio:checked'));
|
||||
}
|
||||
|
||||
$.deliveryModal = {
|
||||
showPreloader: () => {
|
||||
deliveryModal.find('.preloader').show();
|
||||
},
|
||||
hidePreloader: () => {
|
||||
deliveryModal.find('.preloader').hide();
|
||||
},
|
||||
show: () => {
|
||||
deliveryModal.modal('show');
|
||||
},
|
||||
hide: () => {
|
||||
deliveryModal.modal('hide');
|
||||
},
|
||||
updateContent: (content) => {
|
||||
deliveryModal.find('.modal-body-content').html(content);
|
||||
}
|
||||
}
|
||||
|
||||
$.deliveryMessageModal = {
|
||||
show: (message) => {
|
||||
deliveryMessageModal.find('.modal-body').html(message);
|
||||
deliveryMessageModal.modal('show');
|
||||
},
|
||||
showError: (message) => {
|
||||
$.deliveryMessageModal.show('<div class="has-error"><div class="help-block">' + message + '</div></div>');
|
||||
}
|
||||
}
|
||||
|
||||
$.delivery = {
|
||||
updatePickupPoint: (pickupPointId, pickupPointName, pickupPointAddress, pickupPointPostCode, pickupPointCity, pickupCountryCode, pickupPointCod, pickupWeekend, custom) => {
|
||||
$.deliveryPickupPoint.set(pickupPointId, pickupPointName, pickupPointAddress, pickupPointPostCode, pickupPointCity, pickupCountryCode, pickupPointCod, pickupWeekend, custom);
|
||||
|
||||
if (!selectedDelivery.prop('checked')) {
|
||||
selectedDelivery.prop('checked', true).change();
|
||||
} else {
|
||||
const pickupPointContainer = selectedDelivery.closest('label').find('.delivery-pickup-point-container');
|
||||
const pickupPoint = $.deliveryPickupPoint.get();
|
||||
selectedPickupPointUpdate(pickupPointContainer, pickupPoint);
|
||||
$(window).trigger('resize');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.deliveryPickupPoint = {
|
||||
set: (id, name, address, postCode, city, countryCode, cod, weekend, custom) => {
|
||||
const point = {
|
||||
id: id,
|
||||
name: name,
|
||||
address: address,
|
||||
postCode: postCode,
|
||||
city: city,
|
||||
countryCode: countryCode,
|
||||
cod: cod,
|
||||
weekend: weekend,
|
||||
custom: custom,
|
||||
};
|
||||
point.name = 'Paczkomat - ' + point.name;
|
||||
const jsonPoint = JSON.stringify(point);
|
||||
$('#delivery_pickup_point').val(jsonPoint);
|
||||
window.localStorage.setItem($.deliveryPickupPoint.getPointNamespace(), jsonPoint);
|
||||
$('#delivery-modal').modal('hide');
|
||||
},
|
||||
get: () => {
|
||||
const value = window.localStorage.getItem($.deliveryPickupPoint.getPointNamespace());
|
||||
return value ? JSON.parse(value) : undefined;
|
||||
},
|
||||
getPointNamespace: () => {
|
||||
return 'delivery_pickup_point.' + selectedDelivery.data('delivery-type') + '.' + selectedCountryId
|
||||
}
|
||||
}
|
||||
|
||||
shoppingCartDelivery.on('change', '#delivery-country', function() {
|
||||
selectedCountryId = $(this).val();
|
||||
});
|
||||
|
||||
deliveryModal
|
||||
.on('show.bs.modal', function (event) {
|
||||
const modal = $(this);
|
||||
const trigger = $(event.relatedTarget);
|
||||
selectedDelivery = trigger.closest('.radio').find('.delivery-radio');
|
||||
const selectedPayment = $('#shopping-cart-payment .radio input[type=radio]:checked');
|
||||
const pickupPoint = $.deliveryPickupPoint.get(selectedDelivery.data('delivery-type'));
|
||||
const parameters = {
|
||||
id: selectedDelivery.val(),
|
||||
cod: selectedPayment.data('payment-cod'),
|
||||
country_id: selectedCountryId,
|
||||
pickup_point: pickupPoint,
|
||||
};
|
||||
|
||||
|
||||
|
||||
$.post(modal.data('action'), parameters, function (response) {
|
||||
$.deliveryModal.updateContent(response);
|
||||
$.deliveryModal.hidePreloader();
|
||||
});
|
||||
|
||||
modal.find('.modal-title').html(selectedDelivery.data('delivery-name'));
|
||||
}).on('hide.bs.modal', function () {
|
||||
$.deliveryModal.showPreloader();
|
||||
}).on('hidden.bs.modal', function () {
|
||||
$.deliveryModal.updateContent('');
|
||||
});
|
||||
|
||||
deliveryMessageModal.on('show.bs.modal', function (event) {
|
||||
deliveryMessageModal.find('.modal-title').html(selectedDelivery.data('delivery-name'));
|
||||
});
|
||||
|
||||
shoppingCartDelivery.on('change', '.delivery-radio', onChangeDeliveryHandle);
|
||||
|
||||
if (deliveryMessageModal.data('show-error').length > 0) {
|
||||
$.deliveryMessageModal.showError(deliveryMessageModal.data('show-error'));
|
||||
}
|
||||
|
||||
shoppingCartDelivery.find('[data-toggle=tooltip]').tooltip({ html: true, trigger: 'click hover focus', delay: { show: 100, hide: 0 } });
|
||||
});
|
||||
Reference in New Issue
Block a user