diff --git a/modules/comune/js/ajax.js b/modules/comune/js/ajax.js
index 81ef6f0..a2fdfee 100755
--- a/modules/comune/js/ajax.js
+++ b/modules/comune/js/ajax.js
@@ -1,192 +1,77 @@
'use strict';
-jQuery(document).ready(
- function ($) {
+jQuery(document).ready(function ($) {
+ /// DA RIMUOVERE
+ //$('select').niceSelect();
- /// DA RIMUOVERE
- //$('select').niceSelect();
+ const {
+ __,
+ _x,
+ _n,
+ _nx
+ } = wp.i18n;
+ var scegli = '';
+ var attendere = '';
+ var comune = '';
+ var provincia = '';
+ var regione = '';
+ var gcmi_comu_mail_value = '';
+ var gcmi_istance_kind = '';
+ var gcmi_istance_filtername = '';
+ var myID = '';
+ var regione_desc = '';
+ var provincia_desc = '';
+ var comune_desc = '';
+ var predefiniti = '';
+ // da versione 2.0.0 .
+ var choichesLoaded = $.isFunction(window.Choices);
+ var el = '';
+ $("select[id$='gcmi_regione']").val("");
+ $("select[id$='gcmi_regione']").removeAttr("disabled");
+ $("select[id$='gcmi_province']").html(scegli);
+ $("select[id$='gcmi_province']").attr("disabled", "disabled");
+ $("select[id$='gcmi_comuni']").html(scegli);
+ $("select[id$='gcmi_comuni']").attr("disabled", "disabled");
+ $("[id$='gcmi_icon']").hide();
+ $("input[id$='gcmi_targa']").val("");
+ $("input[id$='gcmi_mail']").val("");
+ /* compatibilità con JQuery Nice Select */
+ if (typeof $.fn.niceSelect !== 'undefined') {
+ var targetNodes = $("select[id*='gcmi'][style='display: none']");
+ var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
+ var myObserver = new MutationObserver(mutationHandler);
+ var obsConfig = {
+ childList: true,
+ characterData: true,
+ attributes: true,
+ subtree: true
+ };
+ //--- Add a target node to the observer. Can only add one node at a time.
+ targetNodes.each(function () {
+ myObserver.observe(this, obsConfig);
+ });
- const {__, _x, _n, _nx} = wp.i18n;
- var scegli = '';
- var attendere = '';
- var comune = '';
- var provincia = '';
- var regione = '';
- var gcmi_comu_mail_value = '';
- var gcmi_istance_kind = '';
- var gcmi_istance_filtername = '';
- var myID = '';
-
- var regione_desc = '';
- var provincia_desc = '';
- var comune_desc = '';
- var predefiniti = '';
-
- // da versione 2.0.0 .
- var choichesLoaded = $.isFunction(window.Choices);
- var el = '';
-
- $("select[id$='gcmi_regione']").val("");
- $("select[id$='gcmi_regione']").removeAttr("disabled");
- $("select[id$='gcmi_province']").html(scegli);
- $("select[id$='gcmi_province']").attr("disabled", "disabled");
- $("select[id$='gcmi_comuni']").html(scegli);
- $("select[id$='gcmi_comuni']").attr("disabled", "disabled");
- $("[id$='gcmi_icon']").hide();
- $("input[id$='gcmi_targa']").val("");
- $("input[id$='gcmi_mail']").val("");
-
- /* compatibilità con JQuery Nice Select */
- if (typeof $.fn.niceSelect !== 'undefined') {
- var targetNodes = $("select[id*='gcmi'][style='display: none']");
- var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
- var myObserver = new MutationObserver(mutationHandler);
- var obsConfig = {
- childList: true,
- characterData: true,
- attributes: true,
- subtree: true
- };
- //--- Add a target node to the observer. Can only add one node at a time.
- targetNodes.each(function () {
- myObserver.observe(this, obsConfig);
- });
- function mutationHandler(mutationRecords) {
- var target = mutationRecords[0].target;
- $(target).niceSelect('update');
- }
+ function mutationHandler(mutationRecords) {
+ var target = mutationRecords[0].target;
+ $(target).niceSelect('update');
}
- /* FINE compatibilità con JQuery Nice Select */
-
- $("select[id$='gcmi_regione']").change(
- function () {
- window.MyPrefix = this.id.substring(0, (this.id.length - ("gcmi_regione").length));
- regione = $("select#" + window.MyPrefix + "gcmi_regione option:selected").attr('value');
- regione_desc = $("select#" + window.MyPrefix + "gcmi_regione option:selected").text();
- $("input#" + window.MyPrefix + "gcmi_reg_desc").val(regione_desc);
- $("input#" + window.MyPrefix + "gcmi_prov_desc").val('');
- $("input#" + window.MyPrefix + "gcmi_comu_desc").val('');
-
- gcmi_istance_kind = $("input#" + window.MyPrefix + "gcmi_kind").attr('value');
- gcmi_istance_filtername = $("input#" + window.MyPrefix + "gcmi_filtername").attr('value');
-
- if (!regione == '') {
- if (regione != '00') {
- el = $("select#" + window.MyPrefix + "gcmi_province");
- el.html(attendere);
- el.attr("disabled", "disabled");
- if (choichesLoaded && el.hasClass('choicesjs-select')) {
- $(el).data('choicesjs').setChoices(
- Array.from($(el)[0].options),
- 'value',
- 'label',
- true,
- );
- $(el).data('choicesjs').disable();
- }
-
- el = $("select#" + window.MyPrefix + "gcmi_comuni");
- el.html(scegli);
- el.attr("disabled", "disabled");
- if (choichesLoaded && el.hasClass('choicesjs-select')) {
- $(el).data('choicesjs').setChoices(
- Array.from($(el)[0].options),
- 'value',
- 'label',
- true,
- );
- $(el).data('choicesjs').disable();
- }
-
- $.ajax(
- {
- type: 'POST',
- url: gcmi_ajax.ajaxurl,
- data: {
- action: 'the_ajax_hook_prov',
- nonce_ajax: gcmi_ajax.nonce,
- codice_regione: regione,
- gcmi_kind: gcmi_istance_kind,
- gcmi_filtername: gcmi_istance_filtername
- },
- success: function (data) {
- el = $("select#" + window.MyPrefix + "gcmi_province");
- el.removeAttr("disabled");
- el.html(data);
-
- if (choichesLoaded && el.hasClass('choicesjs-select')) {
- $(el).data('choicesjs').setChoices(
- Array.from($(el)[0].options),
- 'value',
- 'label',
- true,
- );
- $(el).data('choicesjs').enable();
- }
- // fine nuovo.
- },
- async: false
- }
- );
- } else {
- el = $("select#" + window.MyPrefix + "gcmi_comuni");
- el.html(attendere);
- el.attr("disabled", "disabled");
- if (choichesLoaded && el.hasClass('choicesjs-select')) {
- $(el).data('choicesjs').setChoices(
- Array.from($(el)[0].options),
- 'value',
- 'label',
- true,
- );
- $(el).data('choicesjs').disable();
- }
-
- el = $("select#" + window.MyPrefix + "gcmi_province");
- el.html(attendere);
- el.attr("disabled", "disabled");
- if (choichesLoaded && el.hasClass('choicesjs-select')) {
- $(el).data('choicesjs').setChoices(
- Array.from($(el)[0].options),
- 'value',
- 'label',
- true,
- );
- $(el).data('choicesjs').disable();
- }
-
- $.ajax(
- {
- type: 'POST',
- url: gcmi_ajax.ajaxurl,
- data: {
- action: 'the_ajax_hook_prov',
- nonce_ajax: gcmi_ajax.nonce,
- codice_regione: regione,
- gcmi_kind: gcmi_istance_kind,
- gcmi_filtername: gcmi_istance_filtername
- },
- success: function (data) {
- el = $("select#" + window.MyPrefix + "gcmi_comuni");
- el.removeAttr("disabled");
- el.html(data);
- if (choichesLoaded && el.hasClass('choicesjs-select')) {
- $(el).data('choicesjs').setChoices(
- Array.from($(el)[0].options),
- 'value',
- 'label',
- true,
- );
- $(el).data('choicesjs').enable();
- }
-
- },
- async: false
- }
- );
- }
- } else {
+ }
+ /* FINE compatibilità con JQuery Nice Select */
+
+ // Seleziono una regione.
+ $("select[id$='gcmi_regione']").change(
+ function () {
+ window.MyPrefix = this.id.substring(0, (this.id.length - ("gcmi_regione").length));
+ regione = $("select#" + window.MyPrefix + "gcmi_regione option:selected").attr('value');
+ regione_desc = $("select#" + window.MyPrefix + "gcmi_regione option:selected").text();
+ $("input#" + window.MyPrefix + "gcmi_reg_desc").val(regione_desc);
+ $("input#" + window.MyPrefix + "gcmi_prov_desc").val('');
+ $("input#" + window.MyPrefix + "gcmi_comu_desc").val('');
+ gcmi_istance_kind = $("input#" + window.MyPrefix + "gcmi_kind").attr('value');
+ gcmi_istance_filtername = $("input#" + window.MyPrefix + "gcmi_filtername").attr('value');
+ if (!regione == '') {
+ if (regione != '00') {
el = $("select#" + window.MyPrefix + "gcmi_province");
- el.html(scegli);
+ el.html(attendere);
el.attr("disabled", "disabled");
if (choichesLoaded && el.hasClass('choicesjs-select')) {
$(el).data('choicesjs').setChoices(
@@ -194,9 +79,10 @@ jQuery(document).ready(
'value',
'label',
true,
- );
+ );
$(el).data('choicesjs').disable();
}
+
el = $("select#" + window.MyPrefix + "gcmi_comuni");
el.html(scegli);
el.attr("disabled", "disabled");
@@ -206,203 +92,333 @@ jQuery(document).ready(
'value',
'label',
true,
- );
+ );
$(el).data('choicesjs').disable();
}
- }
- $("#" + window.MyPrefix + "gcmi_icon").hide();
- $("#" + window.MyPrefix + "gcmi_info").hide();
- }
- );
-
- $("select[id$='gcmi_province']").change(
- function () {
- window.MyPrefix = this.id.substring(0, (this.id.length - ("gcmi_province").length));
- provincia = $("select#" + window.MyPrefix + "gcmi_province option:selected").attr('value');
- provincia_desc = $("select#" + window.MyPrefix + "gcmi_province option:selected").text();
- $("input#" + window.MyPrefix + "gcmi_prov_desc").val(provincia_desc);
- $("input#" + window.MyPrefix + "gcmi_comu_desc").val('');
- gcmi_istance_kind = $("input#" + window.MyPrefix + "gcmi_kind").attr('value');
- gcmi_istance_filtername = $("input#" + window.MyPrefix + "gcmi_filtername").attr('value');
- el = $("select#" + window.MyPrefix + "gcmi_comuni");
- el.html(attendere);
- el.attr("disabled", "disabled");
- if (choichesLoaded && el.hasClass('choicesjs-select')) {
- $(el).data('choicesjs').setChoices(
- Array.from($(el)[0].options),
- 'value',
- 'label',
- true,
- );
- $(el).data('choicesjs').disable();
- }
- if (!provincia == '') {
- $.ajax(
- {
- type: 'POST',
- url: gcmi_ajax.ajaxurl,
- data: {
- action: 'the_ajax_hook_comu',
- nonce_ajax: gcmi_ajax.nonce,
- codice_provincia: provincia,
- gcmi_kind: gcmi_istance_kind,
- gcmi_filtername: gcmi_istance_filtername
- },
- success: function (data) {
- el.removeAttr("disabled");
- el.html(data);
- if (choichesLoaded && el.hasClass('choicesjs-select')) {
- $(el).data('choicesjs').setChoices(
- Array.from($(el)[0].options),
- 'value',
- 'label',
- true,
- );
- $(el).data('choicesjs').enable();
- }
- },
- async: false
- }
- );
+ $.ajax({
+ type: 'POST',
+ url: gcmi_ajax.ajaxurl,
+ data: {
+ action: 'the_ajax_hook_prov',
+ nonce_ajax: gcmi_ajax.nonce,
+ codice_regione: regione,
+ gcmi_kind: gcmi_istance_kind,
+ gcmi_filtername: gcmi_istance_filtername
+ },
+ success: function (data) {
+ el = $("select#" + window.MyPrefix + "gcmi_province");
+ el.removeAttr("disabled");
+ el.html(data);
+ if (choichesLoaded && el.hasClass('choicesjs-select')) {
+ $(el).data('choicesjs').setChoices(
+ Array.from($(el)[0].options),
+ 'value',
+ 'label',
+ true,
+ );
+ $(el).data('choicesjs').enable();
+ }
+ hideSingleProvince( window.MyPrefix );
+ // fine nuovo.
+ },
+ async: false
+ });
} else {
- el.html(scegli);
+ el = $("select#" + window.MyPrefix + "gcmi_comuni");
+ el.html(attendere);
+ el.attr("disabled", "disabled");
if (choichesLoaded && el.hasClass('choicesjs-select')) {
$(el).data('choicesjs').setChoices(
Array.from($(el)[0].options),
'value',
'label',
true,
- );
+ );
+ $(el).data('choicesjs').disable();
}
- }
- $("#" + window.MyPrefix + "gcmi_icon").hide();
- $("#" + window.MyPrefix + "gcmi_info").hide();
- }
- );
- $("select[id$='gcmi_comuni']").change(
- function () {
- window.MyPrefix = this.id.substring(0, (this.id.length - ("gcmi_comuni").length));
- comune = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").attr('value');
-
- gcmi_istance_kind = $("input#" + window.MyPrefix + "gcmi_kind").attr('value');
- gcmi_istance_filtername = $("input#" + window.MyPrefix + "gcmi_filtername").attr('value');
+ el = $("select#" + window.MyPrefix + "gcmi_province");
+ el.html(attendere);
+ el.attr("disabled", "disabled");
+ if (choichesLoaded && el.hasClass('choicesjs-select')) {
+ $(el).data('choicesjs').setChoices(
+ Array.from($(el)[0].options),
+ 'value',
+ 'label',
+ true,
+ );
+ $(el).data('choicesjs').disable();
+ }
- comune_desc = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").text();
- $("input#" + window.MyPrefix + "gcmi_comu_desc").val(comune_desc);
- $.ajax(
- {
+ $.ajax({
type: 'POST',
url: gcmi_ajax.ajaxurl,
data: {
- action: 'the_ajax_hook_targa',
+ action: 'the_ajax_hook_prov',
nonce_ajax: gcmi_ajax.nonce,
- codice_comune: comune,
+ codice_regione: regione,
gcmi_kind: gcmi_istance_kind,
gcmi_filtername: gcmi_istance_filtername
},
success: function (data) {
- $("input#" + window.MyPrefix + "gcmi_targa").val(data);
- if (regione != '00') {
- var gcmi_comu_form_value = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").text() + ' (' + $("input#" + window.MyPrefix + "gcmi_targa").val() + ')';
- } else {
- var gcmi_comu_form_value = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").text() + ' - (sopp.)' + ' (' + $("input#" + window.MyPrefix + "gcmi_targa").val() + ')';
- }
- $("input#" + window.MyPrefix + "gcmi_formatted").attr('value', gcmi_comu_form_value);
- $("#" + window.MyPrefix + "gcmi_info").hide();
- if ($("select#" + window.MyPrefix + "gcmi_comuni option:selected").val() != "") {
- $("#" + window.MyPrefix + "gcmi_icon").show();
- } else {
- $("#" + window.MyPrefix + "gcmi_icon").hide();
+ el = $("select#" + window.MyPrefix + "gcmi_comuni");
+ el.removeAttr("disabled");
+ el.html(data);
+ if (choichesLoaded && el.hasClass('choicesjs-select')) {
+ $(el).data('choicesjs').setChoices(
+ Array.from($(el)[0].options),
+ 'value',
+ 'label',
+ true,
+ );
+ $(el).data('choicesjs').enable();
}
+
},
async: false
- }
+ });
+ }
+ } else {
+ el = $("select#" + window.MyPrefix + "gcmi_province");
+ el.html(scegli);
+ el.attr("disabled", "disabled");
+ if (choichesLoaded && el.hasClass('choicesjs-select')) {
+ $(el).data('choicesjs').setChoices(
+ Array.from($(el)[0].options),
+ 'value',
+ 'label',
+ true,
+ );
+ $(el).data('choicesjs').disable();
+ }
+ el = $("select#" + window.MyPrefix + "gcmi_comuni");
+ el.html(scegli);
+ el.attr("disabled", "disabled");
+ if (choichesLoaded && el.hasClass('choicesjs-select')) {
+ $(el).data('choicesjs').setChoices(
+ Array.from($(el)[0].options),
+ 'value',
+ 'label',
+ true,
+ );
+ $(el).data('choicesjs').disable();
+ }
+ }
+ $("#" + window.MyPrefix + "gcmi_icon").hide();
+ $("#" + window.MyPrefix + "gcmi_info").hide();
+ }
+ );
+
+ // Seleziono una provincia.
+ $("select[id$='gcmi_province']").change(
+ function () {
+ window.MyPrefix = this.id.substring(0, (this.id.length - ("gcmi_province").length));
+ provincia = $("select#" + window.MyPrefix + "gcmi_province option:selected").attr('value');
+ provincia_desc = $("select#" + window.MyPrefix + "gcmi_province option:selected").text();
+ $("input#" + window.MyPrefix + "gcmi_prov_desc").val(provincia_desc);
+ $("input#" + window.MyPrefix + "gcmi_comu_desc").val('');
+ gcmi_istance_kind = $("input#" + window.MyPrefix + "gcmi_kind").attr('value');
+ gcmi_istance_filtername = $("input#" + window.MyPrefix + "gcmi_filtername").attr('value');
+ el = $("select#" + window.MyPrefix + "gcmi_comuni");
+ el.html(attendere);
+ el.attr("disabled", "disabled");
+ if (choichesLoaded && el.hasClass('choicesjs-select')) {
+ $(el).data('choicesjs').setChoices(
+ Array.from($(el)[0].options),
+ 'value',
+ 'label',
+ true,
);
+ $(el).data('choicesjs').disable();
}
- );
- $("[id$='gcmi_icon']").click(
- function () {
- window.MyPrefix = event.target.id.substring(0, (event.target.id.length - ("gcmi_icon").length));
- comune = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").attr('value');
- $.post(
- gcmi_ajax.ajaxurl,
- {
- action: 'the_ajax_hook_info',
+ if (!provincia == '') {
+ $.ajax({
+ type: 'POST',
+ url: gcmi_ajax.ajaxurl,
+ data: {
+ action: 'the_ajax_hook_comu',
nonce_ajax: gcmi_ajax.nonce,
- codice_comune: comune,
+ codice_provincia: provincia,
+ gcmi_kind: gcmi_istance_kind,
gcmi_filtername: gcmi_istance_filtername
},
- function (data) {
- if ($.trim(data)){
- $("#" + window.MyPrefix + "gcmi_info").html(data);
- $("#" + window.MyPrefix + "gcmi_info").dialog(
- {
- autoOpen: false,
- hide: "puff",
- show: "slide",
- width: 'auto',
- maxWidth: 600,
- height: "auto",
- minWidth: 300,
- title: __('Municipality details', 'campi-moduli-italiani'),
- closeText: __('Close', 'campi-moduli-italiani')
- }
+ success: function (data) {
+ el.removeAttr("disabled");
+ el.html(data);
+ if (choichesLoaded && el.hasClass('choicesjs-select')) {
+ $(el).data('choicesjs').setChoices(
+ Array.from($(el)[0].options),
+ 'value',
+ 'label',
+ true,
);
- $("#" + window.MyPrefix + "gcmi_info").dialog('open');
+ $(el).data('choicesjs').enable();
}
- }
- );
+ },
+ async: false
+ });
+ } else {
+ el.html(scegli);
+ if (choichesLoaded && el.hasClass('choicesjs-select')) {
+ $(el).data('choicesjs').setChoices(
+ Array.from($(el)[0].options),
+ 'value',
+ 'label',
+ true,
+ );
+ }
}
- );
+ $("#" + window.MyPrefix + "gcmi_icon").hide();
+ $("#" + window.MyPrefix + "gcmi_info").hide();
+ }
+ );
- // tooltip.
- $("[id^='TTVar']").mouseover(
- function () {
- event.target.id.tooltip();
- }
- );
+ // Seleziono un comune.
+ $("select[id$='gcmi_comuni']").change(
+ function () {
+ window.MyPrefix = this.id.substring(0, (this.id.length - ("gcmi_comuni").length));
+ comune = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").attr('value');
+ gcmi_istance_kind = $("input#" + window.MyPrefix + "gcmi_kind").attr('value');
+ gcmi_istance_filtername = $("input#" + window.MyPrefix + "gcmi_filtername").attr('value');
+ comune_desc = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").text();
+ $("input#" + window.MyPrefix + "gcmi_comu_desc").val(comune_desc);
+ $.ajax({
+ type: 'POST',
+ url: gcmi_ajax.ajaxurl,
+ data: {
+ action: 'the_ajax_hook_targa',
+ nonce_ajax: gcmi_ajax.nonce,
+ codice_comune: comune,
+ gcmi_kind: gcmi_istance_kind,
+ gcmi_filtername: gcmi_istance_filtername
+ },
+ success: function (data) {
+ $("input#" + window.MyPrefix + "gcmi_targa").val(data);
+ if (regione != '00') {
+ var gcmi_comu_form_value = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").text() + ' (' + $("input#" + window.MyPrefix + "gcmi_targa").val() + ')';
+ } else {
+ var gcmi_comu_form_value = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").text() + ' - (sopp.)' + ' (' + $("input#" + window.MyPrefix + "gcmi_targa").val() + ')';
+ }
+ $("input#" + window.MyPrefix + "gcmi_formatted").attr('value', gcmi_comu_form_value);
+ $("#" + window.MyPrefix + "gcmi_info").hide();
+ if ($("select#" + window.MyPrefix + "gcmi_comuni option:selected").val() != "") {
+ $("#" + window.MyPrefix + "gcmi_icon").show();
+ } else {
+ $("#" + window.MyPrefix + "gcmi_icon").hide();
+ }
+ },
+ async: false
+ });
+ }
+ );
- async function setDefault(CurPrefix, predefiniti) {
- try {
- let response = await $('select#' + CurPrefix + 'gcmi_regione')
- .find('option[value="' + predefiniti.substring(0, 2) + '"]')
- .prop('selected', true)
- .trigger('change');
- } catch (e) {
- console.log(e);
- }
- if ($('select#' + CurPrefix + 'gcmi_regione').val() != '00') {
- try {
- let response = await $('select#' + CurPrefix + 'gcmi_province')
- .find('option[value="' + predefiniti.substring(2, 5) + '"]')
- .prop('selected', true)
- .trigger('change');
- } catch (e) {
- console.log(e);
+ // Click sull'icona per le info.
+ $("[id$='gcmi_icon']").click(
+ function () {
+ window.MyPrefix = event.target.id.substring(0, (event.target.id.length - ("gcmi_icon").length));
+ comune = $("select#" + window.MyPrefix + "gcmi_comuni option:selected").attr('value');
+ $.post(
+ gcmi_ajax.ajaxurl, {
+ action: 'the_ajax_hook_info',
+ nonce_ajax: gcmi_ajax.nonce,
+ codice_comune: comune,
+ gcmi_filtername: gcmi_istance_filtername
+ },
+ function (data) {
+ if ($.trim(data)) {
+ $("#" + window.MyPrefix + "gcmi_info").html(data);
+ $("#" + window.MyPrefix + "gcmi_info").dialog({
+ autoOpen: false,
+ hide: "puff",
+ show: "slide",
+ width: 'auto',
+ maxWidth: 600,
+ height: "auto",
+ minWidth: 300,
+ title: __('Municipality details', 'campi-moduli-italiani'),
+ closeText: __('Close', 'campi-moduli-italiani')
+ });
+ $("#" + window.MyPrefix + "gcmi_info").dialog('open');
+ }
}
- }
+ );
+ }
+ );
+
+ // tooltip.
+ $("[id^='TTVar']").mouseover(
+ function () {
+ event.target.id.tooltip();
+ }
+ );
+
+ // Imposta i valori di default.
+ async function setDefault(CurPrefix, predefiniti) {
+ try {
+ let response = await $('select#' + CurPrefix + 'gcmi_regione')
+ .find('option[value="' + predefiniti.substring(0, 2) + '"]')
+ .prop('selected', true)
+ .trigger('change');
+ } catch (e) {
+ console.log(e);
+ }
+ if ($('select#' + CurPrefix + 'gcmi_regione').val() != '00') {
try {
- let response = await $('select#' + CurPrefix + 'gcmi_comuni')
- .find('option[value="' + predefiniti.substring(5) + '"]')
+ let response = await $('select#' + CurPrefix + 'gcmi_province')
+ .find('option[value="' + predefiniti.substring(2, 5) + '"]')
.prop('selected', true)
.trigger('change');
} catch (e) {
console.log(e);
}
}
+ try {
+ let response = await $('select#' + CurPrefix + 'gcmi_comuni')
+ .find('option[value="' + predefiniti.substring(5) + '"]')
+ .prop('selected', true)
+ .trigger('change');
+ } catch (e) {
+ console.log(e);
+ }
+ }
- $("select[id$='gcmi_comuni']").each(
- function () {
- var CurPrefix = this.id.substring(0, (this.id.length - ("gcmi_comuni").length));
- predefiniti = $(this).attr('data-prval');
- if (typeof predefiniti !== typeof undefined && predefiniti !== false) {
- setDefault(CurPrefix, predefiniti);
- 1
- }
+ $("select[id$='gcmi_comuni']").each(
+ function () {
+ var CurPrefix = this.id.substring(0, (this.id.length - ("gcmi_comuni").length));
+ predefiniti = $(this).attr('data-prval');
+ if (typeof predefiniti !== typeof undefined && predefiniti !== false) {
+ setDefault(CurPrefix, predefiniti);
+ 1
}
- );
+ }
+ );
+
+ function hideSingleRegion() {
+ // se sono solo 2 le opzioni, nella regione seleziono la seconda
+ $("select[id$='gcmi_regione']").each(function () {
+ window.MyPrefix = this.id.substring(0, (this.id.length - ("gcmi_regione").length));
+ let RegOps = $(this).children('option').length;
+ if (2 === RegOps) {
+ $("#" + window.MyPrefix + "gcmi_regione option").eq(1).prop('selected', true);
+ $("#" + window.MyPrefix + "gcmi_regione").trigger("change");
+ $("label[for='" + window.MyPrefix + "gcmi_regione'").hide();
+ $(this).hide();
+ }
+ });
+ }
+ hideSingleRegion();
+
+ function hideSingleProvince( MyPrefix ) {
+ //nasconde la selezione delle province se è inutile (solo 1 provincia selezionabile)
+ let ProOps = $("#" + MyPrefix + "gcmi_province").children('option').length;
+ if (2 === ProOps) {
+ $("#" + MyPrefix + "gcmi_province option").eq(1).prop('selected', true);
+ $("#" + MyPrefix + "gcmi_province").trigger("change");
+ //$("#" + MyPrefix + "gcmi_province").attr("hidden",true);
+ $("label[for='" + MyPrefix + "gcmi_province" ).hide();
+ $("#" + MyPrefix + "gcmi_province").hide();
+ }
}
-);
+});
\ No newline at end of file
diff --git a/modules/comune/js/ajax.min.js b/modules/comune/js/ajax.min.js
index 3e62898..dec685e 100644
--- a/modules/comune/js/ajax.min.js
+++ b/modules/comune/js/ajax.min.js
@@ -1,2 +1,2 @@
/*! campi-moduli-italiani 2.1.0 */
-"use strict";jQuery(document).ready(function(c){const e=wp.i18n["__"];var i,t,a,o,s,n,l,d,r='",m='",g="",h="",u="",_="",w=c.isFunction(window.Choices),f="";c("select[id$='gcmi_regione']").val(""),c("select[id$='gcmi_regione']").removeAttr("disabled"),c("select[id$='gcmi_province']").html(r),c("select[id$='gcmi_province']").attr("disabled","disabled"),c("select[id$='gcmi_comuni']").html(r),c("select[id$='gcmi_comuni']").attr("disabled","disabled"),c("[id$='gcmi_icon']").hide(),c("input[id$='gcmi_targa']").val(""),c("input[id$='gcmi_mail']").val(""),void 0!==c.fn.niceSelect&&(n=c("select[id*='gcmi'][style='display: none']"),l=new(window.MutationObserver||window.WebKitMutationObserver)(function(i){i=i[0].target;c(i).niceSelect("update")}),d={childList:!0,characterData:!0,attributes:!0,subtree:!0},n.each(function(){l.observe(this,d)})),c("select[id$='gcmi_regione']").change(function(){window.MyPrefix=this.id.substring(0,this.id.length-"gcmi_regione".length),h=c("select#"+window.MyPrefix+"gcmi_regione option:selected").attr("value"),t=c("select#"+window.MyPrefix+"gcmi_regione option:selected").text(),c("input#"+window.MyPrefix+"gcmi_reg_desc").val(t),c("input#"+window.MyPrefix+"gcmi_prov_desc").val(""),c("input#"+window.MyPrefix+"gcmi_comu_desc").val(""),u=c("input#"+window.MyPrefix+"gcmi_kind").attr("value"),_=c("input#"+window.MyPrefix+"gcmi_filtername").attr("value"),""==!h?"00"!=h?((f=c("select#"+window.MyPrefix+"gcmi_province")).html(m),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),(f=c("select#"+window.MyPrefix+"gcmi_comuni")).html(r),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),c.ajax({type:"POST",url:gcmi_ajax.ajaxurl,data:{action:"the_ajax_hook_prov",nonce_ajax:gcmi_ajax.nonce,codice_regione:h,gcmi_kind:u,gcmi_filtername:_},success:function(i){(f=c("select#"+window.MyPrefix+"gcmi_province")).removeAttr("disabled"),f.html(i),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").enable())},async:!1})):((f=c("select#"+window.MyPrefix+"gcmi_comuni")).html(m),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),(f=c("select#"+window.MyPrefix+"gcmi_province")).html(m),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),c.ajax({type:"POST",url:gcmi_ajax.ajaxurl,data:{action:"the_ajax_hook_prov",nonce_ajax:gcmi_ajax.nonce,codice_regione:h,gcmi_kind:u,gcmi_filtername:_},success:function(i){(f=c("select#"+window.MyPrefix+"gcmi_comuni")).removeAttr("disabled"),f.html(i),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").enable())},async:!1})):((f=c("select#"+window.MyPrefix+"gcmi_province")).html(r),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),(f=c("select#"+window.MyPrefix+"gcmi_comuni")).html(r),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable())),c("#"+window.MyPrefix+"gcmi_icon").hide(),c("#"+window.MyPrefix+"gcmi_info").hide()}),c("select[id$='gcmi_province']").change(function(){window.MyPrefix=this.id.substring(0,this.id.length-"gcmi_province".length),i=c("select#"+window.MyPrefix+"gcmi_province option:selected").attr("value"),a=c("select#"+window.MyPrefix+"gcmi_province option:selected").text(),c("input#"+window.MyPrefix+"gcmi_prov_desc").val(a),c("input#"+window.MyPrefix+"gcmi_comu_desc").val(""),u=c("input#"+window.MyPrefix+"gcmi_kind").attr("value"),_=c("input#"+window.MyPrefix+"gcmi_filtername").attr("value"),(f=c("select#"+window.MyPrefix+"gcmi_comuni")).html(m),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),""==!i?c.ajax({type:"POST",url:gcmi_ajax.ajaxurl,data:{action:"the_ajax_hook_comu",nonce_ajax:gcmi_ajax.nonce,codice_provincia:i,gcmi_kind:u,gcmi_filtername:_},success:function(i){f.removeAttr("disabled"),f.html(i),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").enable())},async:!1}):(f.html(r),w&&f.hasClass("choicesjs-select")&&c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0)),c("#"+window.MyPrefix+"gcmi_icon").hide(),c("#"+window.MyPrefix+"gcmi_info").hide()}),c("select[id$='gcmi_comuni']").change(function(){window.MyPrefix=this.id.substring(0,this.id.length-"gcmi_comuni".length),g=c("select#"+window.MyPrefix+"gcmi_comuni option:selected").attr("value"),u=c("input#"+window.MyPrefix+"gcmi_kind").attr("value"),_=c("input#"+window.MyPrefix+"gcmi_filtername").attr("value"),o=c("select#"+window.MyPrefix+"gcmi_comuni option:selected").text(),c("input#"+window.MyPrefix+"gcmi_comu_desc").val(o),c.ajax({type:"POST",url:gcmi_ajax.ajaxurl,data:{action:"the_ajax_hook_targa",nonce_ajax:gcmi_ajax.nonce,codice_comune:g,gcmi_kind:u,gcmi_filtername:_},success:function(i){c("input#"+window.MyPrefix+"gcmi_targa").val(i),i="00"!=h?c("select#"+window.MyPrefix+"gcmi_comuni option:selected").text()+" ("+c("input#"+window.MyPrefix+"gcmi_targa").val()+")":c("select#"+window.MyPrefix+"gcmi_comuni option:selected").text()+" - (sopp.) ("+c("input#"+window.MyPrefix+"gcmi_targa").val()+")",c("input#"+window.MyPrefix+"gcmi_formatted").attr("value",i),c("#"+window.MyPrefix+"gcmi_info").hide(),""!=c("select#"+window.MyPrefix+"gcmi_comuni option:selected").val()?c("#"+window.MyPrefix+"gcmi_icon").show():c("#"+window.MyPrefix+"gcmi_icon").hide()},async:!1})}),c("[id$='gcmi_icon']").click(function(){window.MyPrefix=event.target.id.substring(0,event.target.id.length-"gcmi_icon".length),g=c("select#"+window.MyPrefix+"gcmi_comuni option:selected").attr("value"),c.post(gcmi_ajax.ajaxurl,{action:"the_ajax_hook_info",nonce_ajax:gcmi_ajax.nonce,codice_comune:g,gcmi_filtername:_},function(i){c.trim(i)&&(c("#"+window.MyPrefix+"gcmi_info").html(i),c("#"+window.MyPrefix+"gcmi_info").dialog({autoOpen:!1,hide:"puff",show:"slide",width:"auto",maxWidth:600,height:"auto",minWidth:300,title:e("Municipality details","campi-moduli-italiani"),closeText:e("Close","campi-moduli-italiani")}),c("#"+window.MyPrefix+"gcmi_info").dialog("open"))})}),c("[id^='TTVar']").mouseover(function(){event.target.id.tooltip()}),c("select[id$='gcmi_comuni']").each(function(){var i=this.id.substring(0,this.id.length-"gcmi_comuni".length);void 0!==(s=c(this).attr("data-prval"))&&!1!==s&&!async function(i,e){try{await c("select#"+i+"gcmi_regione").find('option[value="'+e.substring(0,2)+'"]').prop("selected",!0).trigger("change")}catch(i){console.log(i)}if("00"!=c("select#"+i+"gcmi_regione").val())try{await c("select#"+i+"gcmi_province").find('option[value="'+e.substring(2,5)+'"]').prop("selected",!0).trigger("change")}catch(i){console.log(i)}try{await c("select#"+i+"gcmi_comuni").find('option[value="'+e.substring(5)+'"]').prop("selected",!0).trigger("change")}catch(i){console.log(i)}}(i,s)})});
\ No newline at end of file
+"use strict";jQuery(document).ready(function(c){const e=wp.i18n["__"];var i,t,o,a,n,s,l,d,r='",m='",g="",h="",_="",u="",w=c.isFunction(window.Choices),f="";c("select[id$='gcmi_regione']").val(""),c("select[id$='gcmi_regione']").removeAttr("disabled"),c("select[id$='gcmi_province']").html(r),c("select[id$='gcmi_province']").attr("disabled","disabled"),c("select[id$='gcmi_comuni']").html(r),c("select[id$='gcmi_comuni']").attr("disabled","disabled"),c("[id$='gcmi_icon']").hide(),c("input[id$='gcmi_targa']").val(""),c("input[id$='gcmi_mail']").val(""),void 0!==c.fn.niceSelect&&(s=c("select[id*='gcmi'][style='display: none']"),l=new(window.MutationObserver||window.WebKitMutationObserver)(function(i){i=i[0].target;c(i).niceSelect("update")}),d={childList:!0,characterData:!0,attributes:!0,subtree:!0},s.each(function(){l.observe(this,d)})),c("select[id$='gcmi_regione']").change(function(){window.MyPrefix=this.id.substring(0,this.id.length-"gcmi_regione".length),h=c("select#"+window.MyPrefix+"gcmi_regione option:selected").attr("value"),t=c("select#"+window.MyPrefix+"gcmi_regione option:selected").text(),c("input#"+window.MyPrefix+"gcmi_reg_desc").val(t),c("input#"+window.MyPrefix+"gcmi_prov_desc").val(""),c("input#"+window.MyPrefix+"gcmi_comu_desc").val(""),_=c("input#"+window.MyPrefix+"gcmi_kind").attr("value"),u=c("input#"+window.MyPrefix+"gcmi_filtername").attr("value"),""==!h?"00"!=h?((f=c("select#"+window.MyPrefix+"gcmi_province")).html(m),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),(f=c("select#"+window.MyPrefix+"gcmi_comuni")).html(r),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),c.ajax({type:"POST",url:gcmi_ajax.ajaxurl,data:{action:"the_ajax_hook_prov",nonce_ajax:gcmi_ajax.nonce,codice_regione:h,gcmi_kind:_,gcmi_filtername:u},success:function(i){(f=c("select#"+window.MyPrefix+"gcmi_province")).removeAttr("disabled"),f.html(i),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").enable()),i=window.MyPrefix,2===c("#"+i+"gcmi_province").children("option").length&&(c("#"+i+"gcmi_province option").eq(1).prop("selected",!0),c("#"+i+"gcmi_province").trigger("change"),c("label[for='"+i+"gcmi_province").hide(),c("#"+i+"gcmi_province").hide())},async:!1})):((f=c("select#"+window.MyPrefix+"gcmi_comuni")).html(m),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),(f=c("select#"+window.MyPrefix+"gcmi_province")).html(m),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),c.ajax({type:"POST",url:gcmi_ajax.ajaxurl,data:{action:"the_ajax_hook_prov",nonce_ajax:gcmi_ajax.nonce,codice_regione:h,gcmi_kind:_,gcmi_filtername:u},success:function(i){(f=c("select#"+window.MyPrefix+"gcmi_comuni")).removeAttr("disabled"),f.html(i),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").enable())},async:!1})):((f=c("select#"+window.MyPrefix+"gcmi_province")).html(r),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),(f=c("select#"+window.MyPrefix+"gcmi_comuni")).html(r),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable())),c("#"+window.MyPrefix+"gcmi_icon").hide(),c("#"+window.MyPrefix+"gcmi_info").hide()}),c("select[id$='gcmi_province']").change(function(){window.MyPrefix=this.id.substring(0,this.id.length-"gcmi_province".length),i=c("select#"+window.MyPrefix+"gcmi_province option:selected").attr("value"),o=c("select#"+window.MyPrefix+"gcmi_province option:selected").text(),c("input#"+window.MyPrefix+"gcmi_prov_desc").val(o),c("input#"+window.MyPrefix+"gcmi_comu_desc").val(""),_=c("input#"+window.MyPrefix+"gcmi_kind").attr("value"),u=c("input#"+window.MyPrefix+"gcmi_filtername").attr("value"),(f=c("select#"+window.MyPrefix+"gcmi_comuni")).html(m),f.attr("disabled","disabled"),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").disable()),""==!i?c.ajax({type:"POST",url:gcmi_ajax.ajaxurl,data:{action:"the_ajax_hook_comu",nonce_ajax:gcmi_ajax.nonce,codice_provincia:i,gcmi_kind:_,gcmi_filtername:u},success:function(i){f.removeAttr("disabled"),f.html(i),w&&f.hasClass("choicesjs-select")&&(c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0),c(f).data("choicesjs").enable())},async:!1}):(f.html(r),w&&f.hasClass("choicesjs-select")&&c(f).data("choicesjs").setChoices(Array.from(c(f)[0].options),"value","label",!0)),c("#"+window.MyPrefix+"gcmi_icon").hide(),c("#"+window.MyPrefix+"gcmi_info").hide()}),c("select[id$='gcmi_comuni']").change(function(){window.MyPrefix=this.id.substring(0,this.id.length-"gcmi_comuni".length),g=c("select#"+window.MyPrefix+"gcmi_comuni option:selected").attr("value"),_=c("input#"+window.MyPrefix+"gcmi_kind").attr("value"),u=c("input#"+window.MyPrefix+"gcmi_filtername").attr("value"),a=c("select#"+window.MyPrefix+"gcmi_comuni option:selected").text(),c("input#"+window.MyPrefix+"gcmi_comu_desc").val(a),c.ajax({type:"POST",url:gcmi_ajax.ajaxurl,data:{action:"the_ajax_hook_targa",nonce_ajax:gcmi_ajax.nonce,codice_comune:g,gcmi_kind:_,gcmi_filtername:u},success:function(i){c("input#"+window.MyPrefix+"gcmi_targa").val(i),i="00"!=h?c("select#"+window.MyPrefix+"gcmi_comuni option:selected").text()+" ("+c("input#"+window.MyPrefix+"gcmi_targa").val()+")":c("select#"+window.MyPrefix+"gcmi_comuni option:selected").text()+" - (sopp.) ("+c("input#"+window.MyPrefix+"gcmi_targa").val()+")",c("input#"+window.MyPrefix+"gcmi_formatted").attr("value",i),c("#"+window.MyPrefix+"gcmi_info").hide(),""!=c("select#"+window.MyPrefix+"gcmi_comuni option:selected").val()?c("#"+window.MyPrefix+"gcmi_icon").show():c("#"+window.MyPrefix+"gcmi_icon").hide()},async:!1})}),c("[id$='gcmi_icon']").click(function(){window.MyPrefix=event.target.id.substring(0,event.target.id.length-"gcmi_icon".length),g=c("select#"+window.MyPrefix+"gcmi_comuni option:selected").attr("value"),c.post(gcmi_ajax.ajaxurl,{action:"the_ajax_hook_info",nonce_ajax:gcmi_ajax.nonce,codice_comune:g,gcmi_filtername:u},function(i){c.trim(i)&&(c("#"+window.MyPrefix+"gcmi_info").html(i),c("#"+window.MyPrefix+"gcmi_info").dialog({autoOpen:!1,hide:"puff",show:"slide",width:"auto",maxWidth:600,height:"auto",minWidth:300,title:e("Municipality details","campi-moduli-italiani"),closeText:e("Close","campi-moduli-italiani")}),c("#"+window.MyPrefix+"gcmi_info").dialog("open"))})}),c("[id^='TTVar']").mouseover(function(){event.target.id.tooltip()}),c("select[id$='gcmi_comuni']").each(function(){var i=this.id.substring(0,this.id.length-"gcmi_comuni".length);void 0!==(n=c(this).attr("data-prval"))&&!1!==n&&!async function(i,e){try{await c("select#"+i+"gcmi_regione").find('option[value="'+e.substring(0,2)+'"]').prop("selected",!0).trigger("change")}catch(i){console.log(i)}if("00"!=c("select#"+i+"gcmi_regione").val())try{await c("select#"+i+"gcmi_province").find('option[value="'+e.substring(2,5)+'"]').prop("selected",!0).trigger("change")}catch(i){console.log(i)}try{await c("select#"+i+"gcmi_comuni").find('option[value="'+e.substring(5)+'"]').prop("selected",!0).trigger("change")}catch(i){console.log(i)}}(i,n)}),c("select[id$='gcmi_regione']").each(function(){window.MyPrefix=this.id.substring(0,this.id.length-"gcmi_regione".length),2===c(this).children("option").length&&(c("#"+window.MyPrefix+"gcmi_regione option").eq(1).prop("selected",!0),c("#"+window.MyPrefix+"gcmi_regione").trigger("change"),c("label[for='"+window.MyPrefix+"gcmi_regione'").hide(),c(this).hide())})});
\ No newline at end of file