const itemsSearchBox = [{id_item:'#select2CategorieMadri', value_item: ''}, {id_item:'#select2Province', value_item: ''}, {id_item:'#textRicercaArtigiani', value_item: ''}]; const selectIndices = ['#select2CategorieMadri', '#select2Province']; function getItemsValuesSearchBox(){ itemsSearchBox.forEach(itemIndex => { itemIndex.value_item = $(`${itemIndex.id_item}`).val(); }); } function settingsIcons(el){ $("#"+el.data('btn-remove')).removeClass('d-none'); $("#"+el.data('btn-remove')).addClass('trash-custom'); $("#"+el.data('btn-remove')).addClass('js-trigger-search-box'); $("#"+el.data('id-icon')).addClass('d-none'); } function asyncSearchBox(callAsyncSearchBox, el, change_icon){ if(callAsyncSearchBox) { $.ajax({ url: 'https://www.ilcercartigianodiqualita.it/assets/ajax/async.search.box.php', type: 'POST', data: {'items_search_box': JSON.stringify(itemsSearchBox)}, dataType: 'json', beforeSend: function () { $('#btnRicercaArtigiani') .html('LABELS_RICERCA...   '); $('#containerResultsSearchBox').css('opacity', '0.3'); }, success: function (response) { if (response.status == 'success') { let html = response.html; $('#btnRicercaArtigiani').html('LABELS_CERCA'); $('#containerResultsSearchBox').css('opacity', '1'); $('#containerResultsSearchBox').html(html); if (response.elenco == 'elenco_artigiani') { $('.titleSearchBox').html("LABELS_ELENCO_AZIENDE"); if( $('.titleSearchBoxNomeCategoria').length > 0 ) { $('.titleSearchBoxNomeCategoria').html(''); } if( $("#attivita_trovate").length > 0 ) { $("#attivita_trovate").removeClass('d-none'); } if( $("#readyPagination") ){ $("#readyPagination").addClass('d-none'); } if($('.box-title').length > 0){ $('.box-title').addClass("mb-0"); } if( $("#attivita_trovate").length > 0 && response.count_artigiani ){ $("#attivita_trovate div strong").html(response.count_artigiani + ' attività trovate'); } else { $("#attivita_trovate div strong").html(''); } } else if (response.elenco == 'elenco_sottocategorie') { $('.titleSearchBox').html("LABELS_SEI_NELLA_PAGINA_CATEGORIE_ATTIVITA_DEL_SETTORE:"); $('.titleSearchBoxNomeCategoria').addClass('mb-md-3 mb-2'); $('.titleSearchBoxNomeCategoria').html(response.elenco_categorie); if( $("#attivita_trovate").length > 0 ){ $("#attivita_trovate").addClass('d-none'); $("#attivita_trovate div strong").html(''); } if($('.box-title').length > 0){ $('.box-title').addClass("mb-4"); } } else if ('elenco_categorie'){ $('.titleSearchBox').html("LABELS_SEI_NELLA_PAGINA_CATEGORIE_ATTIVITA"); $('.titleSearchBoxNomeCategoria').html(''); if( $("#attivita_trovate").length > 0 ){ $("#attivita_trovate").addClass('d-none'); $("#attivita_trovate div strong").html(''); } if($('.box-title').length > 0){ $('.box-title').addClass("mb-4"); } } if( $("#tutti_artigiani").length > 0 ){ $("#tutti_artigiani").addClass('d-none'); } if(change_icon) { settingsIcons(el); } } else if (response.status == 'no-results') { if(change_icon) { settingsIcons(el); } $('#btnRicercaArtigiani').html('LABELS_CERCA'); $('#containerResultsSearchBox').css('opacity', '1'); $('#containerResultsSearchBox').html('
LABELS_NESSUN_RISULTATO
'); if( $("#readyPagination").length > 0 ){ $("#readyPagination").addClass('d-none'); } if( $('.titleSearchBoxNomeCategoria').length > 0 ) { $('.titleSearchBoxNomeCategoria').html(''); } $("#attivita_trovate").html(''); } }, error: function (xhr, status, error) { console.error('Errore AJAX:', error); } }); } } selectIndices.forEach(index => { const $select = $(`select${index}`).select2(); $select.on('change', function (e) { /** * Automatic Event or Manually Event */ let callAsyncSearchBox = ''; let change_icon = true; if( $('#categorieCercaArtigiano').length > 0 ){ callAsyncSearchBox = true; if (typeof event == "undefined") { change_icon = false; } } else { if (event) { callAsyncSearchBox = event.isTrusted; } else { callAsyncSearchBox = false; } } getItemsValuesSearchBox(); asyncSearchBox(callAsyncSearchBox, $(this), change_icon); }); });