<script type="text/javascript">
$(document).on('click', '.clickable_area.area_selected', function () {
let uuidArea = $(this).data('uuid-area');
let url = '{{ path("app_frontend_ajax_get_area", {'uuidArea': 'uuidArea'}) }}';
url = url.replace("uuidArea", uuidArea);
$.ajax({
url: url,
method: "GET",
dataType: 'json',
success: function (area) {
let $modal = $('#removeFromCartModal');
let description = $modal.find('.description').text();
$modal.find('.modal-title').text(area.name);
$modal.find('.description').text(description.replace('%areaName%', area.name));
$modal.find('#input__idArea').val(area.id);
$modal.find('.removeFromCartButton').attr('data-uuid-area', area.uuid);
$modal.modal('show');
}
});
})
.on('click', '.removeFromCartButton', function () {
let $modal = $('#removeFromCartModal');
let uuidArea = $(this).attr('data-uuid-area');
let url = '{{ path("app_frontend_cart_remove_item", {'uuidCustomerAdvertisingArea': 'uuidCustomerAdvertisingArea'}) }}';
let button = $(this);
url = url.replace("uuidCustomerAdvertisingArea", uuidArea);
$.ajax({
url: url,
method: "GET",
dataType: 'json',
success: function (data) {
markAreaAsSelectable(uuidArea);
$('#sponsor_customerAdvertisingArea option[value='+uuidArea+']').attr('selected','');
button.closest('.product-item').fadeOut();
$('#shopping-cart').find('.product-area').children('.product-item').each(function (index, item) {
if ($(item).data('uuid') === data.uuid) {
$(item).fadeOut();
}
});
refreshCartTotalAndItemCount();
$modal.modal('hide');
}
});
});
function markAreaAsSelectable(uuidArea) {
let prefix = 'customer-advertising-area-'
let $area = $('#'+prefix+uuidArea);
$area
.addClass('area_free')
.removeClass('area_selected')
;
}
</script>