//Getting value from "ajax.php". function fill( article, material, color, description, part, arttype, cmcreport, cmcreportdate, reportof, kindtest ) { $('#articlepartvalue').val(article) $('#materialpartvalue').val(material) $('#colorvalue').val(color) $('#descriptionpartvalue').val(description) $('#partid').val(part) $('#arttypeid').val(arttype) $('#cmcreportnumber').val(cmcreport) $('#cmcdatereport').val(cmcreportdate) $('#reportof').val(reportof) $('#combo').val(kindtest).change() $('#display').hide() } function toggleHide(id, newHide, button) { // Cambia l'icona e il colore immediatamente const $button = $(button) const $icon = $button.find('i') $icon .removeClass('fa-eye fa-eye-slash') .addClass(newHide === 'Y' ? 'fa-eye-slash' : 'fa-eye') .css('color', newHide === 'Y' ? 'red' : 'green') // Cambia il colore $.ajax({ type: 'POST', url: 'searchengine/togglehide.php', data: { ididentificationparts: id, hide: newHide, }, success: function (response) { // Aggiorna la ricerca per riflettere il cambiamento performSearch() }, error: function (xhr, status, error) { console.log('Errore AJAX: ' + status + ' - ' + error) // Ripristina l'icona e il colore originale in caso di errore $icon .removeClass('fa-eye fa-eye-slash') .addClass(newHide === 'Y' ? 'fa-eye' : 'fa-eye-slash') .css('color', newHide === 'Y' ? 'green' : 'red') $('#display').html("Errore durante l'aggiornamento. Riprova.") }, }) } $(document).ready(function () { // Funzione per eseguire la ricerca function performSearch() { var name = $('#articlepartvalue').val() var showHidden = $('#showHiddenParts').is(':checked') if (name == '') { $('#display').html('') } else { $.ajax({ type: 'POST', url: 'searchengine/ajaxsearch.php', data: { articlepartvalue: encodeURIComponent(name), showHidden: showHidden, }, success: function (html) { $('#display').html(html).show() }, error: function (xhr, status, error) { console.log('Errore AJAX: ' + status + ' - ' + error) $('#display').html('Errore durante la ricerca. Riprova.') }, }) } } // Esegui la ricerca quando l'utente digita nel campo $('#articlepartvalue').keyup(function () { performSearch() }) // Esegui la ricerca quando l'utente cambia il checkbox $('#showHiddenParts').change(function () { performSearch() }) })