|
|
@@ -247,147 +247,196 @@
|
|
|
}
|
|
|
});
|
|
|
Livewire.on('load-anagrafica-modal', () => {
|
|
|
- const modalsAnag = [
|
|
|
- "anag_birth_town_id",
|
|
|
- "anag_residenza_town_id",
|
|
|
- "anag_documento_rilasciato_da_di_foreign_localita",
|
|
|
- "anag_sede_legale_town_id",
|
|
|
- "anag_foreign_birth_country",
|
|
|
- "anag_foreign_residence_country",
|
|
|
- "anag_pg_foreign_residence_country"
|
|
|
- ];
|
|
|
-
|
|
|
- const countryFields = [
|
|
|
- "anag_foreign_birth_country",
|
|
|
- "anag_foreign_residence_country"
|
|
|
- ];
|
|
|
-
|
|
|
- function modalsAnagSelect(value) {
|
|
|
- $('.' + value).select2({
|
|
|
- dropdownParent: $("#anagraficaParte"),
|
|
|
- theme: 'bootstrap4',
|
|
|
- ajax: {
|
|
|
- url: '/localita',
|
|
|
- dataType: 'json'
|
|
|
- },
|
|
|
- width: '100%'
|
|
|
- }).on('change', function (e) {
|
|
|
- var data = $('.' + value).select2("val");
|
|
|
- @this.set(value, data);
|
|
|
- });
|
|
|
-
|
|
|
- const currentValue = $('.' + value).val();
|
|
|
- const currentText = $('.' + value).find('option:selected').text();
|
|
|
- if (currentValue) {
|
|
|
- let option = new Option(currentText, currentValue, true, true);
|
|
|
- $('.' + value).append(option).trigger('change');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function initializeCountrySelects(value) {
|
|
|
- $('.' + value).select2({
|
|
|
- dropdownParent: $("#anagraficaParte .modal-content"),
|
|
|
- theme: 'bootstrap4',
|
|
|
- ajax: {
|
|
|
- url: '/countries',
|
|
|
- dataType: 'json'
|
|
|
- },
|
|
|
- width: '100%'
|
|
|
- }).on('change', function (e) {
|
|
|
- var data = $('.' + value).select2("val");
|
|
|
- @this.set(value, data);
|
|
|
- });
|
|
|
+ const modalsAnag = [
|
|
|
+ "anag_birth_town_id",
|
|
|
+ "anag_residenza_town_id",
|
|
|
+ "anag_documento_rilasciato_da_di_foreign_localita",
|
|
|
+ "anag_sede_legale_town_id",
|
|
|
+ "anag_foreign_birth_country",
|
|
|
+ "anag_foreign_residence_country",
|
|
|
+ "anag_pg_foreign_residence_country"
|
|
|
+ ];
|
|
|
+
|
|
|
+ const countryFields = [
|
|
|
+ "anag_foreign_birth_country",
|
|
|
+ "anag_foreign_residence_country"
|
|
|
+ ];
|
|
|
+
|
|
|
+ function modalsAnagSelect(value) {
|
|
|
+ $('.' + value).select2({
|
|
|
+ dropdownParent: $("#anagraficaParte"),
|
|
|
+ theme: 'bootstrap4',
|
|
|
+ ajax: {
|
|
|
+ url: '/localita',
|
|
|
+ dataType: 'json'
|
|
|
+ },
|
|
|
+ width: '100%'
|
|
|
+ }).on('change', function (e) {
|
|
|
+ var data = $('.' + value).select2("val");
|
|
|
+ @this.set(value, data);
|
|
|
+ });
|
|
|
|
|
|
- const currentValue = $('.' + value).val();
|
|
|
- const currentText = $('.' + value).find('option:selected').text();
|
|
|
- if (currentValue) {
|
|
|
- let option = new Option(currentText, currentValue, true, true);
|
|
|
- $('.' + value).append(option).trigger('change');
|
|
|
- }
|
|
|
- }
|
|
|
+ const currentValue = $('.' + value).val();
|
|
|
+ const currentText = $('.' + value).find('option:selected').text();
|
|
|
+ if (currentValue) {
|
|
|
+ let option = new Option(currentText, currentValue, true, true);
|
|
|
+ $('.' + value).append(option).trigger('change');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function initializeCountrySelects(value) {
|
|
|
+ $('.' + value).select2({
|
|
|
+ dropdownParent: $("#anagraficaParte .modal-content"),
|
|
|
+ theme: 'bootstrap4',
|
|
|
+ ajax: {
|
|
|
+ url: '/countries',
|
|
|
+ dataType: 'json'
|
|
|
+ },
|
|
|
+ width: '100%'
|
|
|
+ }).on('change', function (e) {
|
|
|
+ var data = $('.' + value).select2("val");
|
|
|
+ @this.set(value, data);
|
|
|
+ });
|
|
|
|
|
|
- function initializeModalState() {
|
|
|
- const currentType = $('input[name="anag_type"]:checked').val();
|
|
|
- if (currentType == 0 || !currentType) {
|
|
|
- $("#boxPersonaFisica").show();
|
|
|
- $("#boxPersonaGiuridica").hide();
|
|
|
+ const currentValue = $('.' + value).val();
|
|
|
+ const currentText = $('.' + value).find('option:selected').text();
|
|
|
+ if (currentValue) {
|
|
|
+ let option = new Option(currentText, currentValue, true, true);
|
|
|
+ $('.' + value).append(option).trigger('change');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Funzione per gestire la visibilità dei campi di nascita
|
|
|
+ function toggleNationalityFields() {
|
|
|
+ const nationality = $('select[wire\\:model="anag_nazionalita"]').val();
|
|
|
+ const foreignBirthCountry = $("#foreignBirthCountry");
|
|
|
+ const foreignBirthCity = $("#foreignBirthCity");
|
|
|
+ const italianBirthTown = $("#pippo");
|
|
|
+
|
|
|
+ if (nationality === '1') { // Straniera
|
|
|
+ foreignBirthCountry.show();
|
|
|
+ foreignBirthCity.show();
|
|
|
+ italianBirthTown.hide();
|
|
|
+ } else { // Italiana o non selezionata
|
|
|
+ foreignBirthCountry.hide();
|
|
|
+ foreignBirthCity.hide();
|
|
|
+ italianBirthTown.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Funzione per gestire la visibilità dei campi di residenza
|
|
|
+ function toggleResidenceFields() {
|
|
|
+ const residenceType = $('select[wire\\:model="anag_residenza_tipo"]').val();
|
|
|
+ const italianFields = $("#italianResidenceFields");
|
|
|
+ const foreignCountry = $("#foreignResidenceCountry");
|
|
|
+ const foreignCity = $("#foreignResidenceCity");
|
|
|
+
|
|
|
+ // Nascondi tutti i campi
|
|
|
+ italianFields.hide();
|
|
|
+ foreignCountry.hide();
|
|
|
+ foreignCity.hide();
|
|
|
+
|
|
|
+ // Mostra i campi appropriati
|
|
|
+ if (residenceType === '0') { // Italiana
|
|
|
+ italianFields.show();
|
|
|
+ } else if (residenceType === '1') { // Straniera
|
|
|
+ foreignCountry.show();
|
|
|
+ foreignCity.show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function initializeModalState() {
|
|
|
+ const currentType = $('input[name="anag_type"]:checked').val();
|
|
|
+ if (currentType == 0 || !currentType) {
|
|
|
+ $("#boxPersonaFisica").show();
|
|
|
+ $("#boxPersonaGiuridica").hide();
|
|
|
+ } else {
|
|
|
+ $("#boxPersonaFisica").hide();
|
|
|
+ $("#boxPersonaGiuridica").show();
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
- $("#boxPersonaFisica").hide();
|
|
|
- $("#boxPersonaGiuridica").show();
|
|
|
- }
|
|
|
+ setTimeout(() => {
|
|
|
+ modalsAnag.forEach(modalsAnagSelect);
|
|
|
+ }, 100);
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ countryFields.forEach(initializeCountrySelects);
|
|
|
+ }, 100);
|
|
|
+
|
|
|
+ // Inizializza la visibilità dei campi basata sui valori attuali
|
|
|
+ setTimeout(() => {
|
|
|
+ toggleNationalityFields();
|
|
|
+ toggleResidenceFields();
|
|
|
+ }, 200);
|
|
|
+ }
|
|
|
+
|
|
|
+ initializeModalState();
|
|
|
+
|
|
|
+ $('input[name="anag_type"]').change(function () {
|
|
|
+ var x = $('input[name="anag_type"]:checked').val();
|
|
|
+ if (x == 0) {
|
|
|
+ $("#boxPersonaFisica").show();
|
|
|
+ $("#boxPersonaGiuridica").hide();
|
|
|
+ @this.changeAnagType(0);
|
|
|
+ } else {
|
|
|
+ $("#boxPersonaFisica").hide();
|
|
|
+ $("#boxPersonaGiuridica").show();
|
|
|
+ setTimeout(() => {
|
|
|
+ modalsAnag.forEach(modalsAnagSelect);
|
|
|
+ }, 100);
|
|
|
+ @this.changeAnagType(1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // Event listener per la nazionalità (nascita)
|
|
|
+ $('select[wire\\:model="anag_nazionalita"]').change(function () {
|
|
|
+ toggleNationalityFields();
|
|
|
+ });
|
|
|
+
|
|
|
+ // Event listener per il tipo di residenza
|
|
|
+ $('select[wire\\:model="anag_residenza_tipo"]').change(function () {
|
|
|
+ toggleResidenceFields();
|
|
|
+ });
|
|
|
+
|
|
|
+ Livewire.on('change-visualization', (type) => {
|
|
|
+ $('input:radio[name="anag_type"]').filter('[value="' + type + '"]').prop('checked', true);
|
|
|
+ if (type == 0) {
|
|
|
+ $("#boxPersonaFisica").show();
|
|
|
+ $("#boxPersonaGiuridica").hide();
|
|
|
+ } else {
|
|
|
+ $("#boxPersonaFisica").hide();
|
|
|
+ $("#boxPersonaGiuridica").show();
|
|
|
+ setTimeout(() => {
|
|
|
+ modalsAnag.forEach(modalsAnagSelect);
|
|
|
+ }, 100);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // Gestione per le aziende (persona giuridica)
|
|
|
+ $('select[wire\\:model="nazionalita"]').change(function () {
|
|
|
+ const isPGStraniera = $(this).val() === "1";
|
|
|
+ $("#foreignPGResidenceCountry")[isPGStraniera ? 'show' : 'hide']();
|
|
|
+ $("#foreignPGResidenceCity")[isPGStraniera ? 'show' : 'hide']();
|
|
|
+ $("#italianAddressFields")[isPGStraniera ? 'hide' : 'show']();
|
|
|
+
|
|
|
+ if (!isPGStraniera) {
|
|
|
+ @this.set('anag_foreign_residence_country', '');
|
|
|
+ @this.set('anag_foreign_residence_city', '');
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- setTimeout(() => {
|
|
|
- modalsAnag.forEach(modalsAnagSelect);
|
|
|
- }, 100);
|
|
|
+ $('#anagraficaParte').on('show.bs.modal', function () {
|
|
|
+ initializeModalState();
|
|
|
+ });
|
|
|
|
|
|
- setTimeout(() => {
|
|
|
- countryFields.forEach(initializeCountrySelects);
|
|
|
- }, 100);
|
|
|
+ $('#anagraficaParte').on('hidden.bs.modal', function () {
|
|
|
+ modalsAnag.forEach(value => {
|
|
|
+ if ($('.' + value).data('select2')) {
|
|
|
+ $('.' + value).select2('destroy');
|
|
|
}
|
|
|
-
|
|
|
- initializeModalState();
|
|
|
-
|
|
|
- $('input[name="anag_type"]').change(function () {
|
|
|
- var x = $('input[name="anag_type"]:checked').val();
|
|
|
- if (x == 0) {
|
|
|
- $("#boxPersonaFisica").show();
|
|
|
- $("#boxPersonaGiuridica").hide();
|
|
|
- @this.changeAnagType(0);
|
|
|
- } else {
|
|
|
- $("#boxPersonaFisica").hide();
|
|
|
- $("#boxPersonaGiuridica").show();
|
|
|
- setTimeout(() => {
|
|
|
- modalsAnag.forEach(modalsAnagSelect);
|
|
|
- }, 100);
|
|
|
- @this.changeAnagType(1);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- Livewire.on('change-visualization', (type) => {
|
|
|
- $('input:radio[name="anag_type"]').filter('[value="' + type + '"]').prop('checked', true);
|
|
|
- if (type == 0) {
|
|
|
- $("#boxPersonaFisica").show();
|
|
|
- $("#boxPersonaGiuridica").hide();
|
|
|
- } else {
|
|
|
- $("#boxPersonaFisica").hide();
|
|
|
- $("#boxPersonaGiuridica").show();
|
|
|
- setTimeout(() => {
|
|
|
- modalsAnag.forEach(modalsAnagSelect);
|
|
|
- }, 100);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- $('select[wire\\:model="nazionalita"]').change(function () {
|
|
|
- const isPGStraniera = $(this).val() === "1";
|
|
|
- $("#foreignPGResidenceCountry")[isPGStraniera ? 'show' : 'hide']();
|
|
|
- $("#foreignPGResidenceCity")[isPGStraniera ? 'show' : 'hide']();
|
|
|
-
|
|
|
- if (isPGStraniera) {
|
|
|
- $(".anag_sede_legale_town_id").closest('.row').hide();
|
|
|
- $(".anag_sede_legale_cap").closest('.row').hide();
|
|
|
- $(".anag_sede_legale_prov_id").closest('.row').hide();
|
|
|
- } else {
|
|
|
- $(".anag_sede_legale_town_id").closest('.row').show();
|
|
|
- $(".anag_sede_legale_cap").closest('.row').show();
|
|
|
- $(".anag_sede_legale_prov_id").closest('.row').show();
|
|
|
- @this.set('anag_foreign_residence_country', '');
|
|
|
- @this.set('anag_foreign_residence_city', '');
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- $('#anagraficaParte').on('show.bs.modal', function () {
|
|
|
- initializeModalState();
|
|
|
- });
|
|
|
-
|
|
|
- $('#anagraficaParte').on('hidden.bs.modal', function () {
|
|
|
- modalsAnag.forEach(value => {
|
|
|
- if ($('.' + value).data('select2')) {
|
|
|
- $('.' + value).select2('destroy');
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
});
|
|
|
+ });
|
|
|
+});
|
|
|
|
|
|
Livewire.on('load-select-modal', () => {
|
|
|
|
|
|
@@ -776,6 +825,8 @@
|
|
|
@this.set('valida_al', $(this).val());
|
|
|
});
|
|
|
|
|
|
+
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
@endpush
|