diff --git a/admin/admin.php b/admin/admin.php
index db5bf61..e9e6b6e 100644
--- a/admin/admin.php
+++ b/admin/admin.php
@@ -28,6 +28,8 @@
$gcmi_fb = new GCMI_Comune_Filter_Builder();
add_action( 'wp_ajax_gcmi_fb_requery_comuni', array( $gcmi_fb, 'ajax_get_tabs_html' ), 10, 0 );
add_action( 'wp_ajax_gcmi_fb_create_filter', array( $gcmi_fb, 'ajax_create_filter' ), 10, 0 );
+ add_action( 'wp_ajax_gcmi_fb_create_filter_multi', array( $gcmi_fb, 'ajax_create_filters_multi' ), 10, 0 );
+ add_action( 'wp_ajax_gcmi_fb_save_filter_slice', array( $gcmi_fb, 'ajax_save_filters_slice' ), 10, 0 );
add_action( 'wp_ajax_gcmi_fb_get_locale', array( $gcmi_fb, 'ajax_get_locale' ), 10, 0 );
add_action( 'wp_ajax_gcmi_fb_get_filters', array( $gcmi_fb, 'ajax_get_filters_html' ), 10, 0 );
add_action( 'wp_ajax_gcmi_fb_delete_filter', array( $gcmi_fb, 'ajax_delete_filter' ), 10, 0 );
diff --git a/admin/css/styles.css b/admin/css/styles.css
index abea2bd..cceaffb 100644
--- a/admin/css/styles.css
+++ b/admin/css/styles.css
@@ -25,10 +25,22 @@
width: 34%;
}
.gcmi-fb-main-container {
- display: block;
padding-right: 10px;
- /*width: 90%;
- */
+ display: flex;
+ flex-flow: column;
+ height: 100%;
+}
+ .gcmi-fb-main-container .gcmi-fb-filters-container{
+ flex: 0 1 auto;
+}
+ .gcmi-fb-box-container{
+ display: contents;
+}
+ .gcmi-fb-main-container .gcmi-fb-tabs-container{
+ flex: 1 1 100px;
+}
+ .gcmi-fb-main-container .dummy-footer {
+ flex: 0 1 40px;
}
.gcmi-fb-regione-container {
display: grid;
@@ -44,18 +56,18 @@
row-gap: 20px;
column-gap: 15px;
}
-.gcmi-fb-regione-blocco, .gcmi-fb-lettera-blocco {
- display: flex;
- flex-direction: column;
- row-gap: 12px;
+ .gcmi-fb-regione-blocco, .gcmi-fb-lettera-blocco {
+ display: flex;
+ flex-direction: column;
+ row-gap: 12px;
}
-.gcmi-fb-checkall-container{
- display: flex;
- flex-direction: row;
- justify-content: flex-start;
- gap: 20px;
- align-items: end;
- background-color: #f6f7f7;
+ .gcmi-fb-checkall-container{
+ display: flex;
+ flex-direction: row;
+ justify-content: flex-start;
+ gap: 20px;
+ align-items: end;
+ background-color: #f6f7f7;
}
.gcmi-fb-regione-name {
font-weight: bold;
@@ -200,4 +212,4 @@
input[type="checkbox"].gcmi-ui-toggle:checked:after {
content: 'ON';
background-color: #2271b1;
-}
+}
\ No newline at end of file
diff --git a/admin/css/styles.min.css b/admin/css/styles.min.css
index 1addfde..00350b2 100644
--- a/admin/css/styles.min.css
+++ b/admin/css/styles.min.css
@@ -1 +1 @@
-#toplevel_page_gcmi div.wp-menu-image{background:transparent url('../img/icon.png') no-repeat scroll center 0;height:32px}#toplevel_page_gcmi.current div.wp-menu-image,#toplevel_page_gcmi.wp-has-current-submenu div.wp-menu-image,#toplevel_page_gcmi:hover div.wp-menu-image{background:transparent url('../img/icon.png') no-repeat scroll center -28px}.wp-list-table .column-gcmi-icon{width:5%}.wp-list-table .column-gcmi-dataname{width:15%}.wp-list-table .column-gcmi-rows{width:5%;text-align:right}.wp-list-table .column-gcmi-remotedate{width:18%}.wp-list-table .column-gcmi-localdate{width:18%}.wp-list-table .column-gcmi-dataURL{width:34%}.gcmi-fb-main-container{display:block;padding-right:10px}.gcmi-fb-regione-container{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));row-gap:12px}.gcmi-fb-regione-item{white-space:nowrap}.gcmi-fb-province-container{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));row-gap:20px;column-gap:15px}.gcmi-fb-lettera-blocco,.gcmi-fb-regione-blocco{display:flex;flex-direction:column;row-gap:12px}.gcmi-fb-checkall-container{display:flex;flex-direction:row;justify-content:flex-start;gap:20px;align-items:end;background-color:#f6f7f7}.gcmi-fb-regione-name{font-weight:700}.gcmi-fb-provincia-item{white-space:normal}.gcmi-fb-comuni-container{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));row-gap:20px;column-gap:15px}.gcmi-fb-lettera-comune{font-weight:700}.gcmi-fb-comune-item{white-space:nowrap}.gcmi-fb-filters-container{margin-left:auto;margin-right:0;box-sizing:border-box;max-width:750px}.gcmi-fb-button-delete-wrapper{white-space:nowrap}.gcmi-fb-button-edit-wrapper{white-space:nowrap}.gcmi-fb-button-new-wrapper{white-space:nowrap}.gcmi-fb-commit-buttons-wrapper{display:flex;flex-direction:row;flex-wrap:wrap;justify-content:flex-start;align-content:flex-start;gap:5px;max-width:min-content}.gcmi-fb-table-name-wrapper{flex-grow:2;flex-basis:0}.gcmi-fb-button-new-wrapper{flex-grow:1;flex-basis:0;white-space:nowrap}.gcmi-fb-button-reset-wrapper{flex-grow:1;flex-basis:0;white-space:nowrap}.gcmi-fb-button-save-wrapper{flex-grow:1;flex-basis:0;white-space:nowrap}.gcmi-fb-button{text-align:center;width:100%}.gcmi-fb-button>span{vertical-align:middle;margin-right:4px;margin-top:0;margin-bottom:4px}.gcmi-fb-button-delete-filter:hover:not(:disabled){box-shadow:inset 0 0 0 1px var(--wp-components-color-accent-darker-10,var(--wp-admin-theme-color-darker-10,#2145e6))}.gcmi-fb-button-delete-filter{--wp-components-color-accent:#cc1818;--wp-components-color-accent-darker-10:#9e1313;--wp-components-color-accent-darker-20:#710d0d background: transparent;color:var(--wp-components-color-accent,var(--wp-admin-theme-color,#3858e9))!important;outline:1px solid transparent;border-color:var(--wp-components-color-accent,var(--wp-admin-theme-color,#3858e9))!important}.gcmi-fb-filters-name{text-align:left;font-style:italic}input[type=checkbox].gcmi-ui-toggle{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-tap-highlight-color:transparent;width:auto;height:auto;vertical-align:middle;position:relative;border:0;outline:0;cursor:pointer;margin:0 4px;background:0 0;box-shadow:none}input[type=checkbox].gcmi-ui-toggle:focus{box-shadow:none}input[type=checkbox].gcmi-ui-toggle:after{content:'';font-size:8px;font-weight:400;line-height:18px;text-indent:-14px;color:#fff;width:36px;height:18px;display:inline-block;background-color:#a7aaad;border-radius:72px;box-shadow:0 0 12px rgb(0 0 0 / 15%) inset}input[type=checkbox].gcmi-ui-toggle:before{content:'';width:14px;height:14px;display:block;position:absolute;top:2px;left:2px;margin:0;border-radius:50%;background-color:#fff}input[type=checkbox].gcmi-ui-toggle:checked:before{left:20px;margin:0;background-color:#fff}input[type=checkbox].gcmi-ui-toggle,input[type=checkbox].gcmi-ui-toggle:after,input[type=checkbox].gcmi-ui-toggle:before,input[type=checkbox].gcmi-ui-toggle:checked:after,input[type=checkbox].gcmi-ui-toggle:checked:before{transition:ease .15s}input[type=checkbox].gcmi-ui-toggle:checked:after{content:'ON';background-color:#2271b1}
\ No newline at end of file
+#toplevel_page_gcmi div.wp-menu-image{background:transparent url('../img/icon.png') no-repeat scroll center 0;height:32px}#toplevel_page_gcmi.current div.wp-menu-image,#toplevel_page_gcmi.wp-has-current-submenu div.wp-menu-image,#toplevel_page_gcmi:hover div.wp-menu-image{background:transparent url('../img/icon.png') no-repeat scroll center -28px}.wp-list-table .column-gcmi-icon{width:5%}.wp-list-table .column-gcmi-dataname{width:15%}.wp-list-table .column-gcmi-rows{width:5%;text-align:right}.wp-list-table .column-gcmi-remotedate{width:18%}.wp-list-table .column-gcmi-localdate{width:18%}.wp-list-table .column-gcmi-dataURL{width:34%}.gcmi-fb-main-container{padding-right:10px;display:flex;flex-flow:column;height:100%}.gcmi-fb-main-container .gcmi-fb-filters-container{flex:0 1 auto}.gcmi-fb-box-container{display:contents}.gcmi-fb-main-container .gcmi-fb-tabs-container{flex:1 1 100px}.gcmi-fb-main-container .dummy-footer{flex:0 1 40px}.gcmi-fb-regione-container{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));row-gap:12px}.gcmi-fb-regione-item{white-space:nowrap}.gcmi-fb-province-container{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));row-gap:20px;column-gap:15px}.gcmi-fb-lettera-blocco,.gcmi-fb-regione-blocco{display:flex;flex-direction:column;row-gap:12px}.gcmi-fb-checkall-container{display:flex;flex-direction:row;justify-content:flex-start;gap:20px;align-items:end;background-color:#f6f7f7}.gcmi-fb-regione-name{font-weight:700}.gcmi-fb-provincia-item{white-space:normal}.gcmi-fb-comuni-container{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));row-gap:20px;column-gap:15px}.gcmi-fb-lettera-comune{font-weight:700}.gcmi-fb-comune-item{white-space:nowrap}.gcmi-fb-filters-container{margin-left:auto;margin-right:0;box-sizing:border-box;max-width:750px}.gcmi-fb-button-delete-wrapper{white-space:nowrap}.gcmi-fb-button-edit-wrapper{white-space:nowrap}.gcmi-fb-button-new-wrapper{white-space:nowrap}.gcmi-fb-commit-buttons-wrapper{display:flex;flex-direction:row;flex-wrap:wrap;justify-content:flex-start;align-content:flex-start;gap:5px;max-width:min-content}.gcmi-fb-table-name-wrapper{flex-grow:2;flex-basis:0}.gcmi-fb-button-new-wrapper{flex-grow:1;flex-basis:0;white-space:nowrap}.gcmi-fb-button-reset-wrapper{flex-grow:1;flex-basis:0;white-space:nowrap}.gcmi-fb-button-save-wrapper{flex-grow:1;flex-basis:0;white-space:nowrap}.gcmi-fb-button{text-align:center;width:100%}.gcmi-fb-button>span{vertical-align:middle;margin-right:4px;margin-top:0;margin-bottom:4px}.gcmi-fb-button-delete-filter:hover:not(:disabled){box-shadow:inset 0 0 0 1px var(--wp-components-color-accent-darker-10,var(--wp-admin-theme-color-darker-10,#2145e6))}.gcmi-fb-button-delete-filter{--wp-components-color-accent:#cc1818;--wp-components-color-accent-darker-10:#9e1313;--wp-components-color-accent-darker-20:#710d0d background: transparent;color:var(--wp-components-color-accent,var(--wp-admin-theme-color,#3858e9))!important;outline:1px solid transparent;border-color:var(--wp-components-color-accent,var(--wp-admin-theme-color,#3858e9))!important}.gcmi-fb-filters-name{text-align:left;font-style:italic}input[type=checkbox].gcmi-ui-toggle{-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-tap-highlight-color:transparent;width:auto;height:auto;vertical-align:middle;position:relative;border:0;outline:0;cursor:pointer;margin:0 4px;background:0 0;box-shadow:none}input[type=checkbox].gcmi-ui-toggle:focus{box-shadow:none}input[type=checkbox].gcmi-ui-toggle:after{content:'';font-size:8px;font-weight:400;line-height:18px;text-indent:-14px;color:#fff;width:36px;height:18px;display:inline-block;background-color:#a7aaad;border-radius:72px;box-shadow:0 0 12px rgb(0 0 0 / 15%) inset}input[type=checkbox].gcmi-ui-toggle:before{content:'';width:14px;height:14px;display:block;position:absolute;top:2px;left:2px;margin:0;border-radius:50%;background-color:#fff}input[type=checkbox].gcmi-ui-toggle:checked:before{left:20px;margin:0;background-color:#fff}input[type=checkbox].gcmi-ui-toggle,input[type=checkbox].gcmi-ui-toggle:after,input[type=checkbox].gcmi-ui-toggle:before,input[type=checkbox].gcmi-ui-toggle:checked:after,input[type=checkbox].gcmi-ui-toggle:checked:before{transition:ease .15s}input[type=checkbox].gcmi-ui-toggle:checked:after{content:'ON';background-color:#2271b1}
\ No newline at end of file
diff --git a/admin/includes/class-gcmi-comune-filter-builder.php b/admin/includes/class-gcmi-comune-filter-builder.php
index 8c14e12..1e02de9 100644
--- a/admin/includes/class-gcmi-comune-filter-builder.php
+++ b/admin/includes/class-gcmi-comune-filter-builder.php
@@ -31,9 +31,11 @@ public static function show_comune_filter_builder_page(): void {
$html .= '';
$html .= '
';
+ $html .= '
';
$html .= '
';
$html .= self::print_filtri();
$html .= '
';
+ $html .= '
';
$html .= '
';
$html .= '
';
+ $html .= '';
+ $html .= '
';
+ $html .= '
';
echo $html; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
@@ -103,6 +111,13 @@ public static function ajax_get_tabs_html(): void {
}
if ( false !== $filter_name ) {
+ if ( 0 !== strpos( $filter_name, 'tmp_', 0 ) ) {
+ if ( self::has_view_cessati( $filter_name ) ) {
+ $includi_cessati = 'true';
+ } else {
+ $includi_cessati = 'false';
+ }
+ }
$reg_selected = self::get_cod_regioni_in_view( $filter_name );
$pro_selected = self::get_cod_province_in_view( $filter_name );
$com_selected = self::get_cod_comuni_in_view( $filter_name );
@@ -683,7 +698,10 @@ function ( $codice ) {
/**
* Crea un filtro del database
*
+ * La funzione è utilizzata per la creazione di un filtro con singolo invio di codici
* Funzione richiamata da una chiamata AJAX.
+ *
+ * @return void
*/
public static function ajax_create_filter(): void {
check_ajax_referer( 'gcmi_fb_nonce' );
@@ -692,80 +710,286 @@ public static function ajax_create_filter(): void {
if ( $error->has_errors() ) {
wp_send_json_error( $error, 422 );
}
-
$sanitized_name = self::sanitize_table_name( sanitize_key( wp_unslash( $_POST['filtername'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
$use_cessati = strval( sanitize_text_field( wp_unslash( $_POST['includi'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
$codici = $_POST['codici']; // phpcs:ignore
if ( false !== $sanitized_name ) {
- $view_result = self::create_view( $sanitized_name, $use_cessati, $codici );
+ self::save_filter( $sanitized_name, $use_cessati, $codici );
+ }
+ }
- if ( false === $view_result ) {
- $error_string = esc_html__( 'The creation of the filter, failed.', 'campi-moduli-italiani' );
- $error->add( '-8', $error_string );
+ /**
+ * Crea un filtro del database
+ *
+ * La funzione è utilizzata per la creazione di un filtro con multipli invii di codici
+ * Funzione richiamata da una chiamata AJAX.
+ *
+ * @return void
+ */
+ public static function ajax_create_filters_multi(): void {
+ check_ajax_referer( 'gcmi_fb_nonce' );
+ $error = self::check_filter_creation_fields_multi( $_POST );
+ if ( $error->has_errors() ) {
+ wp_send_json_error( $error, 422 );
+ }
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ $total_slices = gcmi_safe_intval( sanitize_text_field( wp_unslash( $_POST['total'] ) ) );
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ $total_codici = gcmi_safe_intval( sanitize_text_field( wp_unslash( $_POST['count'] ) ) );
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ $sanitized_name = self::sanitize_table_name( sanitize_key( wp_unslash( $_POST['filtername'] ) ) );
+ $use_cessati = '';
+ $codici = array();
+
+ for ( $i = 0; $i < $total_slices; $i++ ) {
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ $option_name = 'gcmi-fb-com-' . $sanitized_name . '-' . strval( $i + 1 ) . '_' . sanitize_text_field( wp_unslash( $_POST['total'] ) );
+ $option_value = get_option( $option_name, false );
+ if ( false === $option_value ) {
+ $error->add( '-12', esc_html__( 'Request to store the partial filter was refused', 'campi-moduli-italiani' ) );
+ wp_send_json_error( $error, 422 );
+ }
+ if ( ! is_array( $option_value ) ) {
+ $error->add( '-13', esc_html__( 'Request to store the partial filter was refused', 'campi-moduli-italiani' ) );
wp_send_json_error( $error, 422 );
}
- $input_t = count( $_POST['codici'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
- $count_1 = self::count_view_entries( $sanitized_name, false );
- $count_2 = self::count_view_entries( $sanitized_name, true );
- $output_t = $count_1 + $count_2;
+ if ( '' === $use_cessati && array_key_exists( 'includi', $option_value ) ) {
+ $use_cessati = $option_value['includi'];
+ } else {
+ $use_cessati = 'false';
+ }
+ if ( is_array( $option_value['codici'] ) ) {
+ $codici = array_merge( $codici, $option_value['codici'] );
+ }
+ $delete_array[] = $option_name;
+ }
+ if ( count( $codici ) !== $total_codici ) {
+ $error->add( '-14', esc_html__( 'Retrieved number of codes doesn\'t match expected', 'campi-moduli-italiani' ) );
+ wp_send_json_error( $error, 422 );
+ }
- $response = array(
- 'num_in' => $input_t,
- 'attuali' => $count_1,
- 'cessati' => $count_2,
- 'num_out' => $output_t,
- );
+ if ( ( false !== $sanitized_name ) && ( isset( $delete_array ) ) ) {
+ foreach ( $delete_array as $delete_option ) {
+ $delete = delete_option( $delete_option );
+ if ( false === $delete ) {
+ $error->add( '-15', esc_html__( 'Error in deleting option', 'campi-moduli-italiani' ) );
+ wp_send_json_error( $error, 422 );
+ }
+ }
+ self::save_filter( $sanitized_name, $use_cessati, $codici );
+ }
+ }
+
+ /**
+ * Salva il filtro nel database
+ *
+ * Utilizzata dalle due funzioni: ajax_create_filters e ajax_create_filters_multi.
+ *
+ * @param string $sanitized_name Nome del filtro.
+ * @param string $use_cessati 'true' se utilizza i cessati.
+ * @param array $codici array con i codici dei comuni.
+ * @return void
+ */
+ private static function save_filter( $sanitized_name, $use_cessati, $codici ) {
+ $view_result = self::create_view( $sanitized_name, $use_cessati, $codici );
+
+ if ( false === $view_result ) {
+ $error = new WP_Error();
+ $error->add( '-8', esc_html__( 'The creation of the filter, failed.', 'campi-moduli-italiani' ) );
+ wp_send_json_error( $error, 422 );
+ }
+
+ $input_t = count( $codici ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ $count_1 = self::count_view_entries( $sanitized_name, false );
+ $count_2 = self::count_view_entries( $sanitized_name, true );
+ $output_t = $count_1 + $count_2;
+
+ $response = array(
+ 'num_in' => $input_t,
+ 'attuali' => $count_1,
+ 'cessati' => $count_2,
+ 'num_out' => $output_t,
+ );
+ wp_send_json_success( $response, 200 );
+ }
+
+ /**
+ * Controlla che i valori passati per la creazione di un filtro multi siano corretti.
+ *
+ * @param array $posted The $_POST array.
+ * @return WP_Error
+ */
+ private static function check_filter_creation_fields_multi( $posted ) {
+ $error = self::check_filter_creation_common_fields( $posted );
+ $error_string = esc_html__( 'Received an incomplete request to create a filter.', 'campi-moduli-italiani' );
+ if (
+ ! is_array( $posted ) ||
+ ! array_key_exists( 'total', $posted ) ||
+ ! array_key_exists( 'count', $posted )
+ ) {
+ $error->add( '-1', $error_string );
+ return $error; // necessario perché in PHP7 l'assegnazione successiva, genera un error.
+ }
+
+ if ( ! is_numeric( $posted['total'] ) ||
+ 0 > gcmi_safe_intval( $posted['total'] ) ||
+ ! is_numeric( $posted['count'] ) ||
+ 0 > gcmi_safe_intval( $posted['count'] )
+ ) {
+ $error->add( '-1', $error_string );
+ }
+ return $error;
+ }
+
+ /**
+ * Salva un'opzione nel database, contenente il pezzo dell'array dei codici
+ *
+ * @return void
+ */
+ public static function ajax_save_filters_slice(): void {
+ check_ajax_referer( 'gcmi_fb_nonce' );
+ $error = self::check_save_filter_slices_fields( $_POST );
+
+ if ( $error->has_errors() ) {
+ $error->add( '-10', esc_html__( 'Request to store the partial filter, not processed', 'campi-moduli-italiani' ) );
+ wp_send_json_error( $error, 422 );
+ }
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ $response = sanitize_text_field( wp_unslash( $_POST['slice'] ) ) . '_' . sanitize_text_field( wp_unslash( $_POST['total'] ) );
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ $filtername = self::sanitize_table_name( sanitize_key( wp_unslash( $_POST['filtername'] ) ) );
+ $option_name = 'gcmi-fb-com-' . $filtername . '-' . $response;
+
+ $option_value = array(
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ 'includi' => strval( sanitize_text_field( wp_unslash( $_POST['includi'] ) ) ),
+ 'filtername' => $filtername,
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ 'codici' => array_map( 'sanitize_text_field', wp_unslash( $_POST['codici'] ) ),
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ 'total' => gcmi_safe_intval( sanitize_text_field( wp_unslash( $_POST['total'] ) ) ),
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
+ 'slice' => gcmi_safe_intval( sanitize_text_field( wp_unslash( $_POST['slice'] ) ) ),
+ );
+
+ $option = update_option( $option_name, $option_value, false );
+ $ret_val = get_option( $option_name );
+ if ( true === $option && $option_value === $ret_val ) {
wp_send_json_success( $response, 200 );
+ } else {
+ $error->add(
+ '-11',
+ sprintf(
+ // translators: %s is the name of the temporary option.
+ esc_html__( 'Request to store the partial filter was refused. Option name: %s', 'campi-moduli-italiani' ),
+ $option_name
+ )
+ );
+ wp_send_json_error( $error, 422 );
}
}
/**
- * Controlla che i valori passati per la crazione di un filtro siano corretti.
+ * Controlla che i valori passati nelle richieste parziali
+ * per la creazione di un filtro sliced siano corretti.
*
* @param array $posted The $_POST array.
- * @return \WP_Error
+ * @return WP_Error
+ */
+ private static function check_save_filter_slices_fields( $posted ) {
+ $error = self::check_filter_creation_fields( $posted );
+
+ if (
+ ! array_key_exists( 'total', $posted ) ||
+ ! array_key_exists( 'slice', $posted )
+ ) {
+ $error->add( '-9', esc_html__( 'Received an incomplete request to create a filter.', 'campi-moduli-italiani' ) );
+ return $error; // necessario perché in PHP7 l'assegnazione successiva, genera un error.
+ }
+
+ if (
+ ( ! is_numeric( $posted['total'] ) ) ||
+ ( ! is_numeric( $posted['slice'] ) ) ||
+ ( gcmi_safe_intval( $posted['slice'] ) > gcmi_safe_intval( $posted['total'] ) ) ||
+ ( 0 === gcmi_safe_intval( $posted['total'] ) ) ||
+ ( 0 === gcmi_safe_intval( $posted['slice'] ) )
+ ) {
+ $error->add( '-10', esc_html__( 'Received an invalid slice of codes.', 'campi-moduli-italiani' ) );
+ }
+ return $error;
+ }
+
+ /**
+ * Controlla che i valori passati per la creazione di un filtro siano corretti.
+ *
+ * @param array $posted The $_POST array.
+ * @return WP_Error
*/
private static function check_filter_creation_fields( $posted ) {
+ $error = self::check_filter_creation_common_fields( $posted );
+ $error->merge_from( self::check_filter_creation_codici( $posted ) );
+ return $error;
+ }
+
+ /**
+ * Controlla che i valori comuni passati per la creazione di un filtro siano corretti.
+ *
+ * @param array $posted The $_POST array.
+ * @return WP_Error
+ */
+ private static function check_filter_creation_common_fields( $posted ) {
$error = new WP_Error();
if (
! is_array( $posted ) ||
! array_key_exists( 'filtername', $posted ) ||
- ! array_key_exists( 'includi', $posted ) ||
- ! array_key_exists( 'codici', $posted )
+ ! array_key_exists( 'includi', $posted )
) {
- $error_string = esc_html__( 'Received an incomplete request to create a filter.', 'campi-moduli-italiani' );
- $error->add( '-1', $error_string );
+ $error->add( '-1', esc_html__( 'Received an incomplete request to create a filter.', 'campi-moduli-italiani' ) );
return $error; // necessario perché in PHP7 l'assegnazione successiva, genera un error.
}
$filter_name = gcmi_safe_strval( $posted['filtername'] );
$use_cessati = gcmi_safe_strval( $posted['includi'] );
- $codici = $posted['codici'];
$sanitized_name = self::sanitize_table_name( $filter_name );
if ( false === $sanitized_name ) {
- $error_string = esc_html__( 'The filter name is not valid. Please use only lowercase alphanumeric characters and single underscores.', 'campi-moduli-italiani' );
- $error->add( '-2', $error_string );
+ $error->add( '-2', esc_html__( 'The filter name is not valid. Please use only lowercase alphanumeric characters and single underscores.', 'campi-moduli-italiani' ) );
} elseif ( 20 < strlen( $sanitized_name ) ) {
- $error_string = esc_html__( 'No more than 20 characters are allowed for the filter\'s name.', 'campi-moduli-italiani' );
- $error->add( '-3', $error_string );
+ $error->add( '-3', esc_html__( 'No more than 20 characters are allowed for the filter\'s name.', 'campi-moduli-italiani' ) );
}
if ( 'true' !== $use_cessati && 'false' !== $use_cessati ) {
- $error_string = esc_html__( 'Unexpected value for parameter use_cessati.', 'campi-moduli-italiani' );
- $error->add( '-4', $error_string );
+ $error->add( '-4', esc_html__( 'Unexpected value for parameter use_cessati.', 'campi-moduli-italiani' ) );
}
+ return $error;
+ }
+ /**
+ * Controlla che i codici passati per la crazione di un filtro siano corretti.
+ *
+ * @param array $posted The $_POST array.
+ * @return WP_Error
+ */
+ private static function check_filter_creation_codici( $posted ) {
+ $error = new WP_Error();
+
+ if (
+ ! is_array( $posted ) ||
+ ! array_key_exists( 'codici', $posted ) ||
+ ! is_array( $posted['codici'] )
+ ) {
+ $error->add( '-1', esc_html__( 'Received an incomplete request to create a filter.', 'campi-moduli-italiani' ) );
+ return $error; // necessario perché in PHP7 l'assegnazione successiva, genera un error.
+ }
+ $codici = $posted['codici'];
if ( count( $codici ) === 0 ) {
- $error_string = esc_html__( 'The array of the codes of the municipalities is empty.', 'campi-moduli-italiani' );
- $error->add( '-5', $error_string );
+ $error->add( '-5', esc_html__( 'The array of the codes of the municipalities is empty.', 'campi-moduli-italiani' ) );
}
if ( false === gcmi_is_one_dimensional_string_array( $codici ) ) {
- $error_string = esc_html__( 'The array of the codes of the municipalities is invalid.', 'campi-moduli-italiani' );
- $error->add( '-6', $error_string );
+ $error->add( '-6', esc_html__( 'The array of the codes of the municipalities is invalid.', 'campi-moduli-italiani' ) );
}
$check_codici = true;
foreach ( $codici as $val ) {
@@ -778,12 +1002,37 @@ private static function check_filter_creation_fields( $posted ) {
}
}
if ( false === $check_codici ) {
- $error_string = esc_html__( 'The array with the codes of the municipalities contains incorrect values.', 'campi-moduli-italiani' );
- $error->add( '-7', $error_string );
+ $error->add( '-7', esc_html__( 'The array with the codes of the municipalities contains incorrect values.', 'campi-moduli-italiani' ) );
}
return $error;
}
+ /**
+ * Verifica se un filtro utilizza i comuni cessati
+ *
+ * @global type $wpdb
+ * @param string $filter_name Il nome del filtro.
+ * @return bool
+ */
+ private static function has_view_cessati( $filter_name ) {
+ global $wpdb;
+ $full_view_name = GCMI_SVIEW_PREFIX . 'comuni_soppressi_' . $filter_name;
+ if ( false === self::check_view_exists( $full_view_name ) ) {
+ return false;
+ } else {
+ $count = $wpdb->get_var(
+ $wpdb->prepare(
+ 'SELECT COUNT(`id`) AS \'NUM\' FROM `%1$s` WHERE 1',
+ $full_view_name
+ )
+ );
+ if ( gcmi_safe_intval( $count ) > 0 ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Restituisce un array dei codici regione (preceduti da R) utilizzati nel filtro
*
@@ -952,7 +1201,7 @@ private static function get_cod_comuni_in_view( $filter_name ) {
* @global type $wpdb
* @return bool
*/
- public static function create_view( $viewname, $use_cessati, $codici ) {
+ private static function create_view( $viewname, $use_cessati, $codici ) {
global $wpdb;
$where_clause_attuali = self::create_filter_sql( $codici, false );
diff --git a/admin/js/scripts.js b/admin/js/scripts.js
index 75fbe90..f1ef704 100644
--- a/admin/js/scripts.js
+++ b/admin/js/scripts.js
@@ -1,936 +1,1241 @@
-jQuery(document).ready(
- function ($) {
- // imposto tutto a unchecked
- $("input[type=checkbox][id^='gcmi-']").prop('checked', false);
+'use strict';
+jQuery(document).ready(function ($) {
+ // imposto tutto a unchecked
+ $("input[type=checkbox][id^='gcmi-']").prop("checked", false);
- // imposto a checked solo quelle da aggiornare
- $("input[type=hidden][id^='gcmi-updated-']").each(
- function (index) {
- if('false' == $(this).val()) {
- window.MySuffix = $(this).attr('id').substring(("gcmi-updated-").length, ($(this).attr('id').length));
- $("input[type=checkbox][id='gcmi-" + window.MySuffix + "']").prop('checked', true);
- }
- }
- );
+ // imposto a checked solo quelle da aggiornare
+ $("input[type=hidden][id^='gcmi-updated-']").each(function (index) {
+ if ("false" == $(this).val()) {
+ window.MySuffix = $(this)
+ .attr("id")
+ .substring("gcmi-updated-".length, $(this).attr("id").length);
+ $("input[type=checkbox][id='gcmi-" + window.MySuffix + "']").prop(
+ "checked",
+ true
+ );
+ }
+ });
+
+ /*
+ * Funzioni per il filter builder
+ */
- // Funzioni per il filter builder
- // Nascondo il frame con il generatore di filtri
- $('#gcmi-fb-tabs').hide();
- //Click sul pulsante per aggiunta di un nuovo filtro
- $(document).on('click', "#gcmi-fb-addnew-filter",
- function () {
- $('#gcmi-fb-tabs').show();
- disableFilters();
- cleaningTabs();
- waitingTabs();
- // in questo caso, parto sempre senza includere i comuni cessati
- $("input[type='checkbox'][id='gcmi-fb-include-ceased']").removeAttr('checked');
- printTabsContent();
- }
- );
- // Click sul pulsante per modifica di un filtro esistente
- $(document).on('click', "button[id^='gcmi-fb-edit-filter-']",
- function () {
- let editfiltername = $(this).attr('id').split("-").pop();
- $('#gcmi-fb-tabs').show();
- disableFilters();
- cleaningTabs();
- waitingTabs();
- printTabsEditFilter( editfiltername );
- }
- );
- //Click sul pulsante per eliminazione di un filtro esistente
- $(document).on('click', "button[id^='gcmi-fb-delete-filter-']",
- function () {
- let delfiltername = $(this).attr('id').split("-").pop();
- let title = 'Conferma eliminazione filtro';
- let message = '' +
- 'Vuoi davvero cancellare il filtro: ' + delfiltername + '?
' +
- 'ATTENZIONE: Questa operazione non può controllare se il filtro è attualmente in uso nei tuoi moduli.';
- $.when(customConfirm(message, title)).then(
- function () {
- $.ajax({
- type: 'post',
- dataType: 'json',
- url: gcmi_fb_obj.ajax_url,
- data: {
- action: 'gcmi_fb_delete_filter',
- _ajax_nonce: gcmi_fb_obj.nonce,
- filtername: delfiltername
- },
- success: function (res) {
- print_filters();
- },
- error: function (res) {
- let title = "Errore nella eliminazione del filtro";
- let message = '';
- let arrData = res.responseJSON.data;
- for (let i = 0; i < arrData.length; i++) {
- message = message + 'Err: ' + arrData[i].code + '
' +
- '' + arrData[i].message + '
';
- }
- $.when(customOkMessage(message, title)).then(
- function () {
- });
- return;
- }
- });
- }
- );
- }
- );
- //Click sul pulsante per annullare aggiunta del filtro
- $(document).on('click', "#gcmi-fb-button-cancel",
- function () {
- let title = 'Conferma annullamento operazione';
- let message = '' +
- 'Vuoi annullare la creazione/modifica del filtro?';
- $.when(customConfirm(message, title)).then(
- function () {
- $('#gcmi-fb-tabs').hide();
- $("button[id^='gcmi-fb-delete-filter-']").removeAttr("disabled");
- $("button[id^='gcmi-fb-edit-filter-']").removeAttr("disabled");
- $('#gcmi-fb-addnew-filter').attr("disabled", false);
- },
- function () {}
- );
- }
- );
- //Click sul pulsante per salvare il nuovo filtro
- $(document).on('click', "#gcmi-fb-button-save",
- function () {
- // controllo quanti sono i comuni selezionati
- event.preventDefault();
- var searchIDs = $('#gcmi-fb-tabs-4').find('input[type=checkbox]:checked').not("[id^='fb-gcmi-chkallcom-']").map(function () {
- return $(this).val();
- }).get();
- var myfiltername;
- if(0 === searchIDs.length) {
- let title = "Errore nel salvataggio";
- let message = '' +
- 'Non è stato selezionato nessun comune da includere nel filtro.';
- $.when(customOkMessage(message, title)).then(
- function () {
- $('#ui-id-4').click();
- }
- );
- return;
- }
- let rawfiltername = $('#fb_gcmi_filter_name').val();
- if(rawfiltername === "") {
- let title = "Errore nel salvataggio";
- let message = '' +
- 'Non è stato indicato il nome del filtro.';
- $.when(customOkMessage(message, title)).then(
- function () {
- $('#fb_gcmi_filter_name').focus();
- });
- return;
- }
- if(rawfiltername.length > 20) {
- let title = "Errore nel salvataggio";
- let message = '' +
- 'Non più di 20 caratteri ammessi per il nome del filtro.';
- $.when(customConfirm(message, title)).then(
- function () {
- $('#fb_gcmi_filter_name').val(rawfiltername.substring(0, 20));
- $('#fb_gcmi_filter_name').focus();
- });
- return;
- }
- let includi = $('#gcmi-fb-include-ceased').prop('checked');
- myfiltername = sanitize_table_name(rawfiltername).substring(0, 20);
- if(false === myfiltername) {
- let title = "Errore nel salvataggio";
- let message = '' +
- 'Non è stato indicato un nome valido per il filtro.';
- $.when(customOkMessage(message, title)).then(
- function () {
- $('#fb_gcmi_filter_name').focus();
- });
- return;
- }
- if(rawfiltername !== myfiltername) {
- let title = "Errore nel salvataggio";
- let message = '' +
- 'Il valore indicato per il nome del filtro:' + rawfiltername + ' non è utilizzabile.
' +
- 'Vuoi utilizzare: ' + myfiltername + ' ?';
- $.when(customConfirm(message, title)).then(
- function () {
- $('#fb_gcmi_filter_name').val(myfiltername);
+ /*
+ * Numero massimo di codici inviati in un singolo invio ajax
+ * @type Number
+ */
+ const chunkSize = 300;
- } //,
- //function () {}
- );
- return;
- }
- let filter_array = $('.gcmi-fb-filters-container').find('span.gcmi-fb-filters-name').map(function () {
- return $(this).text();
- }).get();
- let sovrascrivi = false;
- filter_array.forEach( function(i) {
- if( myfiltername === i ) {
- sovrascrivi = true;
- }
- } );
- if ( true === sovrascrivi ) {
- let title = "Sovrascrivi";
- let message = '' +
- 'Stai sovrascrivendo il filtro:' + myfiltername + '.
' +
- 'Vuoi continuare?';
- $.when(customConfirm(message, title)).then(
- function() {
- // saveFilter deve gestire le richieste troppo grandi in invio.
- saveFilter(includi, myfiltername, searchIDs);
- }
- );
- return;
- }
- saveFilter(includi, myfiltername, searchIDs);
- }
- );
+ var realFilterName = "";
+ // Nascondo il frame con il generatore di filtri
+ $("#gcmi-fb-tabs").hide();
+ //Click sul pulsante per aggiunta di un nuovo filtro
+ $(document).on("click", "#gcmi-fb-addnew-filter", function () {
+ $("#gcmi-fb-tabs").show();
+ disableFilters();
+ cleaningTabs();
+ waitingTabs();
+ // in questo caso, parto sempre senza includere i comuni cessati
+ $("input[type='checkbox'][id='gcmi-fb-include-ceased']").removeAttr(
+ "checked"
+ );
+ printTabsContent();
+ });
+ // Click sul pulsante per modifica di un filtro esistente
+ $(document).on("click", "button[id^='gcmi-fb-edit-filter-']", function () {
+ let editfiltername = $(this).attr("id").split("-").pop();
+ realFilterName = editfiltername;
+ $("#gcmi-fb-tabs").show();
+ disableFilters();
+ cleaningTabs();
+ waitingTabs();
+ printTabsEditFilter(editfiltername);
+ waitForEl("#fb_gcmi_filter_name", function() {
+ $("#fb_gcmi_filter_name").val(realFilterName);
+ });
+
+ });
+ //Click sul pulsante per eliminazione di un filtro esistente
+ $(document).on("click", "button[id^='gcmi-fb-delete-filter-']", function () {
+ let delfiltername = $(this).attr("id").split("-").pop();
+ let title = "Conferma eliminazione filtro";
+ let message =
+ '' +
+ "Vuoi davvero cancellare il filtro: " +
+ delfiltername +
+ "?
" +
+ "ATTENZIONE: Questa operazione non può controllare se il filtro è " +
+ "attualmente in uso nei tuoi moduli.";
+ $.when(customConfirm(message, title)).then(function () {
+ $.ajax({
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ data: {
+ action: "gcmi_fb_delete_filter",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ filtername: delfiltername,
+ },
+ success: function (res) {
+ print_filters();
+ },
+ error: function (res) {
+ let title = "Errore nella eliminazione del filtro";
+ let message =
+ '';
+ let arrData = res.responseJSON.data;
+ for (let i = 0; i < arrData.length; i++) {
+ message =
+ message +
+ "Err: " +
+ arrData[i].code +
+ "
" +
+ "" +
+ arrData[i].message +
+ "
";
+ }
+ $.when(customOkMessage(message, title)).then(function () {});
+ return;
+ },
+ });
+ });
+ });
+ //Click sul pulsante per annullare aggiunta del filtro
+ $(document).on("click", "#gcmi-fb-button-cancel", function () {
+ let title = "Conferma annullamento operazione";
+ let message =
+ '' +
+ "Vuoi annullare la creazione/modifica del filtro?";
+ $.when(customConfirm(message, title)).then(
+ function () {
+ $("#gcmi-fb-tabs").hide();
+ $("button[id^='gcmi-fb-delete-filter-']").removeAttr("disabled");
+ $("button[id^='gcmi-fb-edit-filter-']").removeAttr("disabled");
+ $("#gcmi-fb-addnew-filter").attr("disabled", false);
+ },
+ function () {}
+ );
+ });
+ //Click sul pulsante per salvare il nuovo filtro
+ $(document).on("click", "#gcmi-fb-button-save", function () {
+ // controllo quanti sono i comuni selezionati
+ event.preventDefault();
+ var searchIDs = $("#gcmi-fb-tabs-4")
+ .find("input[type=checkbox]:checked")
+ .not("[id^='fb-gcmi-chkallcom-']")
+ .map(function () {
+ return $(this).val();
+ })
+ .get();
+ var myfiltername;
+ if (0 === searchIDs.length) {
+ let title = "Errore nel salvataggio";
+ let message =
+ '' +
+ "Non è stato selezionato nessun comune da includere nel filtro.";
+ $.when(customOkMessage(message, title)).then(function () {
+ $("#ui-id-4").click();
+ });
+ return;
+ }
+ let rawfiltername = $("#fb_gcmi_filter_name").val();
+ if (rawfiltername === "") {
+ let title = "Errore nel salvataggio";
+ let message =
+ '' +
+ "Non è stato indicato il nome del filtro.";
+ $.when(customOkMessage(message, title)).then(function () {
+ $("#fb_gcmi_filter_name").focus();
+ });
+ return;
+ }
+ if (rawfiltername.length > 20) {
+ let title = "Errore nel salvataggio";
+ let message =
+ '' +
+ "Non più di 20 caratteri ammessi per il nome del filtro.";
+ $.when(customConfirm(message, title)).then(function () {
+ $("#fb_gcmi_filter_name").val(rawfiltername.substring(0, 20));
+ $("#fb_gcmi_filter_name").focus();
+ });
+ return;
+ }
+ let includi = $("#gcmi-fb-include-ceased").prop("checked");
+ myfiltername = sanitize_table_name(rawfiltername).substring(0, 20);
+ if (false === myfiltername) {
+ let title = "Errore nel salvataggio";
+ let message =
+ '' +
+ "Non è stato indicato un nome valido per il filtro.";
+ $.when(customOkMessage(message, title)).then(function () {
+ $("#fb_gcmi_filter_name").focus();
+ });
+ return;
+ }
+ if (rawfiltername !== myfiltername) {
+ let title = "Errore nel salvataggio";
+ let message =
+ '' +
+ "Il valore indicato per il nome del filtro:" +
+ rawfiltername +
+ " non è utilizzabile.
" +
+ "Vuoi utilizzare: " +
+ myfiltername +
+ " ?";
+ $.when(customConfirm(message, title)).then(
+ function () {
+ $("#fb_gcmi_filter_name").val(myfiltername);
+ } //,
+ //function () {}
+ );
+ return;
+ }
+ let filter_array = $(".gcmi-fb-filters-container")
+ .find("span.gcmi-fb-filters-name")
+ .map(function () {
+ return $(this).text();
+ })
+ .get();
+ let sovrascrivi = false;
+ filter_array.forEach(function (i) {
+ if (myfiltername === i) {
+ sovrascrivi = true;
+ }
+ });
+ if (true === sovrascrivi) {
+ let title = "Sovrascrivi";
+ let message =
+ '' +
+ "Stai sovrascrivendo il filtro:" +
+ myfiltername +
+ ".
" +
+ "Vuoi continuare?";
+ $.when(customConfirm(message, title)).then(function () {
+ saveFilter(includi, myfiltername, searchIDs);
+ });
+ return;
+ }
+ saveFilter(includi, myfiltername, searchIDs);
+ });
+ // Creo le tabs per il filter builder
+ $("#gcmi-fb-tabs").tabs({
+ active: 0,
+ collapsible: true,
+ heightStyle: "content",
+ classes: {
+ "ui-tabs": "ui-corner-none",
+ "ui-tabs-nav": "ui-corner-none",
+ "ui-tabs-tab": "ui-corner-none",
+ "ui-tabs-panel": "ui-corner-none"
+ }
+ });
+ // click su regioni
+ $(document).on("change", "input[type='checkbox'][id^='fb-gcmi-reg-']", function () {
+ var chk = $(this);
+ var codreg = $(this).attr("id").split("-").pop();
+ if (false === chk.prop("checked")) {
+ // disabilito le province della regione
+ $("#gcmi-fb-regione-blocco-" + codreg)
+ .find('input[type=checkbox][id^="fb-gcmi-prov-"]:checked')
+ .removeAttr("checked");
+ $("#gcmi-fb-regione-blocco-" + codreg)
+ .find('input[type=checkbox][id^="fb-gcmi-prov-"]')
+ .trigger("change");
+ // rendo invisibile il blocco
+ $("#gcmi-fb-regione-blocco-" + codreg).hide();
+ } else {
+ // li abilito (difficile capire qui cosa gli utenti possono preferire)
+ $("#gcmi-fb-regione-blocco-" + codreg)
+ .find('input[type=checkbox][id^="fb-gcmi-prov-"]:not(:checked)')
+ .prop("checked", true);
+ $("#gcmi-fb-regione-blocco-" + codreg)
+ .find('input[type=checkbox][id^="fb-gcmi-prov-"]')
+ .trigger("change");
+ $("#gcmi-fb-regione-blocco-" + codreg).show();
+ }
+ });
+ // click su province
+ $(document).on("change", "input[type='checkbox'][id^='fb-gcmi-prov-']", function () {
+ var chk = $(this);
+ var codprov = $(this).attr("id").split("-").pop();
+ var codreg = $(this).parent().attr("class").split("-").pop();
+ if (false === chk.prop("checked")) {
+ // Rimuovo il check da checkall
+ $("[id='fb-gcmi-chkallpr-" + codreg).removeAttr("checked");
+ // disabilito tutti i comuni della provincia
+ $("[name^='gcmi-com-cod-pro-" + codprov)
+ .find("input[type=checkbox]:checked")
+ .removeAttr("checked");
+ // li nascondo
+ $("[name^='gcmi-com-cod-pro-" + codprov).hide();
+ hideemptyletters();
+ } else {
+ // li visualizzo
+ $("[name^='gcmi-com-cod-pro-" + codprov).show();
+ // li abilito (difficile capire qui cosa gli utenti possono preferire)
+ $("[name^='gcmi-com-cod-pro-" + codprov)
+ .find("input[type=checkbox]:not(:checked)")
+ .prop("checked", true);
+ hideemptyletters();
+ }
+ // metto il check a checkall se sono tutte checked
+ if (
+ $("[id='gcmi-fb-regione-blocco-" + codreg).find(
+ "input[type=checkbox][id^=fb-gcmi-prov-]:checked"
+ ).length ===
+ $("[id='gcmi-fb-regione-blocco-" + codreg).find(
+ "input[type=checkbox][id^=fb-gcmi-prov-]"
+ ).length
+ ) {
+ $("[id='fb-gcmi-chkallpr-" + codreg).prop("checked", true);
+ }
+ });
+ // click su un comune
+ $(document).on("change", "input[type='checkbox'][id^='fb-gcmi-com-']", function () {
+ let letteraIniziale = Array.from(
+ $("label[for='" + this.name + "']").text()
+ )[0];
+ // Rimuovo il check da checkall
+ $("[id='fb-gcmi-chkallcom-" + letteraIniziale).removeAttr("checked");
+ // metto il check a checkall se sono tutte checked
+ if (
+ $("[id='gcmi-fb-lettera-blocco-" + letteraIniziale).find(
+ "input[type=checkbox][id^=fb-gcmi-com-]:visible:checked"
+ ).length ===
+ $("[id='gcmi-fb-lettera-blocco-" + letteraIniziale).find(
+ "input[type=checkbox][id^=fb-gcmi-com-]:visible"
+ ).length
+ ) {
+ $("[id='fb-gcmi-chkallcom-" + letteraIniziale).prop("checked", true);
+ }
+ });
+ // seleziona/deseleziona tutte le province della regione
+ $(document).on("change", "input[type='checkbox'][id^='fb-gcmi-chkallpr-']", function () {
+ var chk = $(this);
+ var codreg = $(this).attr("id").split("-").pop();
+ if (false === chk.prop("checked")) {
+ // disabilito le province della regione
+ $("#gcmi-fb-regione-blocco-" + codreg)
+ .find("input[type=checkbox]:checked")
+ .not("[id^='fb-gcmi-chkallpr-']")
+ .removeAttr("checked");
+ $("#gcmi-fb-regione-blocco-" + codreg)
+ .find("input[type=checkbox]")
+ .not("[id^='fb-gcmi-chkallpr-']")
+ .trigger("change");
+ } else {
+ $("#gcmi-fb-regione-blocco-" + codreg)
+ .find("input[type=checkbox]:not(:checked)")
+ .not("[id^='fb-gcmi-chkallpr-']")
+ .prop("checked", true);
+ $("#gcmi-fb-regione-blocco-" + codreg)
+ .find("input[type=checkbox]")
+ .not("[id^='fb-gcmi-chkallpr-']")
+ .trigger("change");
+ }
+ });
+ // seleziona/deseleziona tutti i comuni con la lettera
+ $(document).on("change", "input[type='checkbox'][id^='fb-gcmi-chkallcom-']", function () {
+ var chk = $(this);
+ var lettera = $(this).attr("id").split("-").pop();
+ if (false === chk.prop("checked")) {
+ // disabilito i comuni con l'iniziale
+ $("#gcmi-fb-lettera-blocco-" + lettera)
+ .find("input[type=checkbox]:checked:visible")
+ .not("[id^='fb-gcmi-chkallcom-']")
+ .removeAttr("checked");
+ } else {
+ $("#gcmi-fb-lettera-blocco-" + lettera)
+ .find("input[type=checkbox]:not(:checked):visible")
+ .not("[id^='fb-gcmi-chkallcom-']")
+ .prop("checked", true);
+ }
+ });
+ // click su selettore cessati
+ $(document).on("change", "input[type='checkbox'][id='gcmi-fb-include-ceased']",function () {
+ realFilterName = $("#fb_gcmi_filter_name").val();
+ var cdate = new Date();
+ var tmpFilterName = "tmp_" + cdate.getTime();
+ var includi = $("#gcmi-fb-include-ceased").prop("checked");
+ event.preventDefault();
+ var searchIDs = $("#gcmi-fb-tabs-4")
+ .find("input[type=checkbox]:checked")
+ .not("[id^='fb-gcmi-chkallcom-']")
+ .map(function () {
+ return $(this).val();
+ })
+ .get();
+ cleaningTabs();
+ waitingTabs();
+ saveFilter(includi, tmpFilterName, searchIDs, true );
+ waitForEl("#fb_gcmi_filter_name", function() {
+ $("#fb_gcmi_filter_name").val(realFilterName);
+ });
+ });
-
+ function disableFilters() {
+ $("button[id^='gcmi-fb-delete-filter-']").attr("disabled", "disabled");
+ $("button[id^='gcmi-fb-edit-filter-']").attr("disabled", "disabled");
+ $("#gcmi-fb-addnew-filter").attr("disabled", "disabled");
+ }
- // Creo le tabs per il filter builder
- $('#gcmi-fb-tabs').tabs({
- active: false,
- collapsible: true,
- classes: {
- 'ui-tabs': 'ui-corner-none',
- 'ui-tabs-nav': 'ui-corner-none',
- 'ui-tabs-tab': 'ui-corner-none',
- 'ui-tabs-panel': 'ui-corner-none'
- }
- });
+ function cleaningTabs() {
+ $("#gcmi-fb-tabs-2").empty();
+ $("#gcmi-fb-tabs-3").empty();
+ $("#gcmi-fb-tabs-4").empty();
+ $("#gcmi-fb-tabs-5").empty();
+ }
- // click su regioni
- $(document).on('change', "input[type='checkbox'][id^='fb-gcmi-reg-']",
- //$( "input[type='checkbox'][id^='fb-gcmi-reg-']" ).change(
- function () {
- var chk = $(this);
- var codreg = $(this).attr('id').split("-").pop();
- if(false === chk.prop('checked')) {
- // disabilito le province della regione
- $('#gcmi-fb-regione-blocco-' + codreg).find('input[type=checkbox][id^="fb-gcmi-prov-"]:checked').removeAttr('checked');
- $('#gcmi-fb-regione-blocco-' + codreg).find('input[type=checkbox][id^="fb-gcmi-prov-"]').trigger('change');
- // rendo invisibile il blocco
- $('#gcmi-fb-regione-blocco-' + codreg).hide();
- } else {
- // li abilito (difficile capire qui cosa gli utenti possono preferire)
- $('#gcmi-fb-regione-blocco-' + codreg).find('input[type=checkbox][id^="fb-gcmi-prov-"]:not(:checked)').prop('checked', true);
- $('#gcmi-fb-regione-blocco-' + codreg).find('input[type=checkbox][id^="fb-gcmi-prov-"]').trigger('change');
- $('#gcmi-fb-regione-blocco-' + codreg).show();
- }
- }
- );
- // click su province
- $(document).on('change', "input[type='checkbox'][id^='fb-gcmi-prov-']",
- //$( "input[type='checkbox'][id^='fb-gcmi-prov-']" ).change(
- function () {
- var chk = $(this);
- var codprov = $(this).attr('id').split("-").pop();
- var codreg = $(this).parent().attr('class').split("-").pop();
- if(false === chk.prop('checked')) {
- // Rimuovo il check da checkall
- $("[id='fb-gcmi-chkallpr-" + codreg).removeAttr('checked');
- // disabilito tutti i comuni della provincia
- $("[name^='gcmi-com-cod-pro-" + codprov).find('input[type=checkbox]:checked').removeAttr('checked');
- // li nascondo
- $("[name^='gcmi-com-cod-pro-" + codprov).hide();
- hideemptyletters();
- } else {
- // li visualizzo
- $("[name^='gcmi-com-cod-pro-" + codprov).show();
- // li abilito (difficile capire qui cosa gli utenti possono preferire)
- $("[name^='gcmi-com-cod-pro-" + codprov).find('input[type=checkbox]:not(:checked)').prop('checked', true);
- hideemptyletters();
- }
- // metto il check a checkall se sono tutte checked
- if($("[id='gcmi-fb-regione-blocco-" + codreg).find('input[type=checkbox][id^=fb-gcmi-prov-]:checked').length === $("[id='gcmi-fb-regione-blocco-" + codreg).find('input[type=checkbox][id^=fb-gcmi-prov-]').length) {
- $("[id='fb-gcmi-chkallpr-" + codreg).prop('checked', true);
- }
- }
- );
- // click su un comune
- $(document).on('change', "input[type='checkbox'][id^='fb-gcmi-com-']",
- function () {
- let letteraIniziale = Array.from( $("label[for='"+this.name+"']").text() )[0];
- // Rimuovo il check da checkall
- $("[id='fb-gcmi-chkallcom-" + letteraIniziale).removeAttr('checked');
- // metto il check a checkall se sono tutte checked
- if($("[id='gcmi-fb-lettera-blocco-" + letteraIniziale).find('input[type=checkbox][id^=fb-gcmi-com-]:visible:checked').length === $("[id='gcmi-fb-lettera-blocco-" + letteraIniziale).find('input[type=checkbox][id^=fb-gcmi-com-]:visible').length) {
- $("[id='fb-gcmi-chkallcom-" + letteraIniziale).prop('checked', true);
- }
- }
- );
- // seleziona/deseleziona tutte le province della regione
- $(document).on('change', "input[type='checkbox'][id^='fb-gcmi-chkallpr-']",
- //$( "input[type='checkbox'][id^='fb-gcmi-chkallpr-']" ).change(
- function () {
- var chk = $(this);
- var codreg = $(this).attr('id').split("-").pop();
- if(false === chk.prop('checked')) {
- // disabilito le province della regione
- $('#gcmi-fb-regione-blocco-' + codreg).find('input[type=checkbox]:checked').not("[id^='fb-gcmi-chkallpr-']").removeAttr('checked');
- $('#gcmi-fb-regione-blocco-' + codreg).find('input[type=checkbox]').not("[id^='fb-gcmi-chkallpr-']").trigger('change');
- } else {
- $('#gcmi-fb-regione-blocco-' + codreg).find('input[type=checkbox]:not(:checked)').not("[id^='fb-gcmi-chkallpr-']").prop('checked', true);
- $('#gcmi-fb-regione-blocco-' + codreg).find('input[type=checkbox]').not("[id^='fb-gcmi-chkallpr-']").trigger('change');
- }
- }
- );
- // seleziona/deseleziona tutti i comuni con la lettera
- $(document).on('change', "input[type='checkbox'][id^='fb-gcmi-chkallcom-']",
- function () {
- var chk = $(this);
- var lettera = $(this).attr('id').split("-").pop();
- if(false === chk.prop('checked')) {
- // disabilito i comuni con l'iniziale
- $('#gcmi-fb-lettera-blocco-' + lettera).find('input[type=checkbox]:checked:visible').not("[id^='fb-gcmi-chkallcom-']").removeAttr('checked');
- } else {
- $('#gcmi-fb-lettera-blocco-' + lettera).find('input[type=checkbox]:not(:checked):visible').not("[id^='fb-gcmi-chkallcom-']").prop('checked', true);
- }
- }
- );
-
- // codice AJAX per il selettore cessati - trigger per la richiesta dati
- // qui devo gestire se sta modificando un filtro o meno
- $(document).on('change', "input[type='checkbox'][id='gcmi-fb-include-ceased']",
- function(){
- var realFilterName = $('#fb_gcmi_filter_name').val();
- var cdate = new Date();
- var tmpFilterName = 'tmp_' + cdate.getTime();
- var includi = $('#gcmi-fb-include-ceased').prop('checked');
- event.preventDefault();
- var searchIDs = $('#gcmi-fb-tabs-4').find('input[type=checkbox]:checked').not("[id^='fb-gcmi-chkallcom-']").map(function () {
- return $(this).val();
- }).get();
- cleaningTabs();
- waitingTabs();
- $.ajax({
- type: 'post',
- dataType: 'json',
- url: gcmi_fb_obj.ajax_url,
- data: {
- action: 'gcmi_fb_create_filter',
- _ajax_nonce: gcmi_fb_obj.nonce,
- includi: includi,
- filtername: tmpFilterName,
- codici: searchIDs
- },
- success: function (res) {
- // stampo le nuove tabs
- printTabsEditFilter( tmpFilterName );
- // rimuovo il filtro temporaneo dal database
- $.ajax({
- type: 'post',
- dataType: 'json',
- url: gcmi_fb_obj.ajax_url,
- data: {
- action: 'gcmi_fb_delete_filter',
- _ajax_nonce: gcmi_fb_obj.nonce,
- filtername: tmpFilterName
- },
- error: function (res) {
- console.log(res);
- }
- });
- // imposto al valore precedente il campo nome del filtro
- $('#fb_gcmi_filter_name').val(realFilterName);
- },
- error: function (res) {
- console.log( "Fallita creazione filtro temporaneo");
- printTabsContent();
- }
- });
- }
- );
- function disableFilters(){
- $("button[id^='gcmi-fb-delete-filter-']").attr("disabled", "disabled");
- $("button[id^='gcmi-fb-edit-filter-']").attr("disabled", "disabled");
- $('#gcmi-fb-addnew-filter').attr("disabled", "disabled");
- }
- function cleaningTabs(){
- $('#gcmi-fb-tabs-2').empty();
- $('#gcmi-fb-tabs-3').empty();
- $('#gcmi-fb-tabs-4').empty();
- $('#gcmi-fb-tabs-5').empty();
- }
- function waitingTabs(){
- var waiting_string = "In attesa dei dati...";
- $('#gcmi-fb-tabs-2').append(waiting_string);
- $('#gcmi-fb-tabs-3').append(waiting_string);
- $('#gcmi-fb-tabs-4').append(waiting_string);
- $('#gcmi-fb-tabs-5').append(waiting_string);
+ function waitingTabs() {
+ var waiting_string = "In attesa dei dati...";
+ $("#gcmi-fb-tabs-2").append(waiting_string);
+ $("#gcmi-fb-tabs-3").append(waiting_string);
+ $("#gcmi-fb-tabs-4").append(waiting_string);
+ $("#gcmi-fb-tabs-5").append(waiting_string);
+ }
+
+ function printTabsContent() {
+ var includi = $("#gcmi-fb-include-ceased").prop("checked");
+ $.ajax({
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ data: {
+ action: "gcmi_fb_requery_comuni",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ includi: includi
+ },
+ success: function (res) {
+ cleaningTabs();
+ $("#gcmi-fb-tabs-2").append(res.regioni_html);
+ $("#gcmi-fb-tabs-3").append(res.province_html);
+ $("#gcmi-fb-tabs-4").append(res.comuni_html);
+ $("#gcmi-fb-tabs-5").append(res.commit_buttons);
+ },
+ });
+ }
+
+ function printTabsEditFilter(editfiltername) {
+ var includi = $("#gcmi-fb-include-ceased").prop("checked");
+ $.ajax({
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+// async: false,
+ data: {
+ action: "gcmi_fb_edit_filter",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ includi: includi,
+ filtername: editfiltername
+ },
+ success: function (res) {
+ cleaningTabs();
+ if ("true" === res.includi) {
+ $("input[type='checkbox'][id='gcmi-fb-include-ceased']").prop(
+ "checked",
+ true
+ );
+ } else {
+ $("input[type='checkbox'][id='gcmi-fb-include-ceased']").removeAttr(
+ "checked"
+ );
}
- function printTabsContent() {
- var includi = $('#gcmi-fb-include-ceased').prop('checked');
- $.ajax({
- type: 'post',
- dataType: 'json',
- url: gcmi_fb_obj.ajax_url,
- data: {
- action: 'gcmi_fb_requery_comuni',
- _ajax_nonce: gcmi_fb_obj.nonce,
- includi: includi
- },
- success: function (res) {
- cleaningTabs();
- $('#gcmi-fb-tabs-2').append(res.regioni_html);
- $('#gcmi-fb-tabs-3').append(res.province_html);
- $('#gcmi-fb-tabs-4').append(res.comuni_html);
- $('#gcmi-fb-tabs-5').append(res.commit_buttons);
- }
- });
+ $("#gcmi-fb-tabs-2").append(res.regioni_html);
+ $("#gcmi-fb-tabs-3").append(res.province_html);
+ $("#gcmi-fb-tabs-4").append(res.comuni_html);
+ $("#gcmi-fb-tabs-5").append(res.commit_buttons);
+
+ // se non sono selezionate le regioni nel primo quadro, metto l'uncheck al checkall della regione
+ $("#gcmi-fb-tabs-2 input[type=checkbox]:not(:checked)")
+ .not("[id^='fb-gcmi-chkall-']")
+ .each(function () {
+ $(this).change();
+ });
+ $("#gcmi-fb-tabs-3 input[type=checkbox]:not(:checked)")
+ .not("[id^='fb-gcmi-chkallpr-']")
+ .each(function () {
+ $(this).change();
+ });
+ $( ".gcmi-fb-lettera-blocco" )
+ .each(function (){
+ $(this).find(":checkbox").not("[id^='fb-gcmi-chkallcom-']")
+ .first()
+ .change();
+ });
+ // $("#gcmi-fb-tabs-4 input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkallcom-']").each(function () {
+ // $(this).change();
+ // });
+ },
+ error: function (res) {
+ showResErrorMessage(res, "RetrieveFilter");
+ }
+ });
+ }
+
+ function print_filters() {
+ $.ajax({
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ data: {
+ action: "gcmi_fb_get_filters",
+ _ajax_nonce: gcmi_fb_obj.nonce
+ },
+ success: function (res) {
+ $("#gcmi-fb-filters-container").html("");
+ $("#gcmi-fb-filters-container").append(res.data.filters_html);
+ },
+ });
+ }
+
+ function sanitize_table_name(name) {
+ let clean;
+ if (typeof name === "string" || name instanceof String) {
+ if (0 === name.length) {
+ return false;
+ }
+ clean = name.trim();
+ // caratteri ascii da 128 a 255
+ let thisRegex = new RegExp(/[\x80-\xff]/g);
+ if (thisRegex.test(clean)) {
+ //clean = clean.normalize("NFKC").replace(/[\u0300-\u036f]/g, "");
+ //clean = clean.normalize("NFD").replace(/\p{Diacritic}/gu, "");
+ clean = remove_accents(clean);
+ }
+ clean = clean
+ .toLowerCase()
+ .replace(/[^a-z0-9_\-]/g, "")
+ .replace(/-/g, "_")
+ .replace(/(_)\1+/g, "_")
+ .replace(/^_+/, "")
+ .replace(/_+$/, "");
+ if (clean.length === 0) {
+ return false;
+ } else {
+ return clean;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ function remove_accents(string) {
+ let chars = {
+ // Decompositions for Latin-1 Supplement.
+ ª: "a",
+ º: "o",
+ À: "A",
+ Á: "A",
+ Â: "A",
+ Ã: "A",
+ Ä: "A",
+ Å: "A",
+ Æ: "AE",
+ Ç: "C",
+ È: "E",
+ É: "E",
+ Ê: "E",
+ Ë: "E",
+ Ì: "I",
+ Í: "I",
+ Î: "I",
+ Ï: "I",
+ Ð: "D",
+ Ñ: "N",
+ Ò: "O",
+ Ó: "O",
+ Ô: "O",
+ Õ: "O",
+ Ö: "O",
+ Ù: "U",
+ Ú: "U",
+ Û: "U",
+ Ü: "U",
+ Ý: "Y",
+ Þ: "TH",
+ ß: "s",
+ à: "a",
+ á: "a",
+ â: "a",
+ ã: "a",
+ ä: "a",
+ å: "a",
+ æ: "ae",
+ ç: "c",
+ è: "e",
+ é: "e",
+ ê: "e",
+ ë: "e",
+ ì: "i",
+ í: "i",
+ î: "i",
+ ï: "i",
+ ð: "d",
+ ñ: "n",
+ ò: "o",
+ ó: "o",
+ ô: "o",
+ õ: "o",
+ ö: "o",
+ ø: "o",
+ ù: "u",
+ ú: "u",
+ û: "u",
+ ü: "u",
+ ý: "y",
+ þ: "th",
+ ÿ: "y",
+ Ø: "O",
+ // Decompositions for Latin Extended-A.
+ Ā: "A",
+ ā: "a",
+ Ă: "A",
+ ă: "a",
+ Ą: "A",
+ ą: "a",
+ Ć: "C",
+ ć: "c",
+ Ĉ: "C",
+ ĉ: "c",
+ Ċ: "C",
+ ċ: "c",
+ Č: "C",
+ č: "c",
+ Ď: "D",
+ ď: "d",
+ Đ: "D",
+ đ: "d",
+ Ē: "E",
+ ē: "e",
+ Ĕ: "E",
+ ĕ: "e",
+ Ė: "E",
+ ė: "e",
+ Ę: "E",
+ ę: "e",
+ Ě: "E",
+ ě: "e",
+ Ĝ: "G",
+ ĝ: "g",
+ Ğ: "G",
+ ğ: "g",
+ Ġ: "G",
+ ġ: "g",
+ Ģ: "G",
+ ģ: "g",
+ Ĥ: "H",
+ ĥ: "h",
+ Ħ: "H",
+ ħ: "h",
+ Ĩ: "I",
+ ĩ: "i",
+ Ī: "I",
+ ī: "i",
+ Ĭ: "I",
+ ĭ: "i",
+ Į: "I",
+ į: "i",
+ İ: "I",
+ ı: "i",
+ IJ: "IJ",
+ ij: "ij",
+ Ĵ: "J",
+ ĵ: "j",
+ Ķ: "K",
+ ķ: "k",
+ ĸ: "k",
+ Ĺ: "L",
+ ĺ: "l",
+ Ļ: "L",
+ ļ: "l",
+ Ľ: "L",
+ ľ: "l",
+ Ŀ: "L",
+ ŀ: "l",
+ Ł: "L",
+ ł: "l",
+ Ń: "N",
+ ń: "n",
+ Ņ: "N",
+ ņ: "n",
+ Ň: "N",
+ ň: "n",
+ ʼn: "n",
+ Ŋ: "N",
+ ŋ: "n",
+ Ō: "O",
+ ō: "o",
+ Ŏ: "O",
+ ŏ: "o",
+ Ő: "O",
+ ő: "o",
+ Œ: "OE",
+ œ: "oe",
+ Ŕ: "R",
+ ŕ: "r",
+ Ŗ: "R",
+ ŗ: "r",
+ Ř: "R",
+ ř: "r",
+ Ś: "S",
+ ś: "s",
+ Ŝ: "S",
+ ŝ: "s",
+ Ş: "S",
+ ş: "s",
+ Š: "S",
+ š: "s",
+ Ţ: "T",
+ ţ: "t",
+ Ť: "T",
+ ť: "t",
+ Ŧ: "T",
+ ŧ: "t",
+ Ũ: "U",
+ ũ: "u",
+ Ū: "U",
+ ū: "u",
+ Ŭ: "U",
+ ŭ: "u",
+ Ů: "U",
+ ů: "u",
+ Ű: "U",
+ ű: "u",
+ Ų: "U",
+ ų: "u",
+ Ŵ: "W",
+ ŵ: "w",
+ Ŷ: "Y",
+ ŷ: "y",
+ Ÿ: "Y",
+ Ź: "Z",
+ ź: "z",
+ Ż: "Z",
+ ż: "z",
+ Ž: "Z",
+ ž: "z",
+ ſ: "s",
+ // Decompositions for Latin Extended-B.
+ Ə: "E",
+ ǝ: "e",
+ Ș: "S",
+ ș: "s",
+ Ț: "T",
+ ț: "t",
+ // Euro sign.
+ "€": "E",
+ // GBP (Pound) sign.
+ "£": "",
+ // Vowels with diacritic (Vietnamese). Unmarked.
+ Ơ: "O",
+ ơ: "o",
+ Ư: "U",
+ ư: "u",
+ // Grave accent.
+ Ầ: "A",
+ ầ: "a",
+ Ằ: "A",
+ ằ: "a",
+ Ề: "E",
+ ề: "e",
+ Ồ: "O",
+ ồ: "o",
+ Ờ: "O",
+ ờ: "o",
+ Ừ: "U",
+ ừ: "u",
+ Ỳ: "Y",
+ ỳ: "y",
+ // Hook.
+ Ả: "A",
+ ả: "a",
+ Ẩ: "A",
+ ẩ: "a",
+ Ẳ: "A",
+ ẳ: "a",
+ Ẻ: "E",
+ ẻ: "e",
+ Ể: "E",
+ ể: "e",
+ Ỉ: "I",
+ ỉ: "i",
+ Ỏ: "O",
+ ỏ: "o",
+ Ổ: "O",
+ ổ: "o",
+ Ở: "O",
+ ở: "o",
+ Ủ: "U",
+ ủ: "u",
+ Ử: "U",
+ ử: "u",
+ Ỷ: "Y",
+ ỷ: "y",
+ // Tilde.
+ Ẫ: "A",
+ ẫ: "a",
+ Ẵ: "A",
+ ẵ: "a",
+ Ẽ: "E",
+ ẽ: "e",
+ Ễ: "E",
+ ễ: "e",
+ Ỗ: "O",
+ ỗ: "o",
+ Ỡ: "O",
+ ỡ: "o",
+ Ữ: "U",
+ ữ: "u",
+ Ỹ: "Y",
+ ỹ: "y",
+ // Acute accent.
+ Ấ: "A",
+ ấ: "a",
+ Ắ: "A",
+ ắ: "a",
+ Ế: "E",
+ ế: "e",
+ Ố: "O",
+ ố: "o",
+ Ớ: "O",
+ ớ: "o",
+ Ứ: "U",
+ ứ: "u",
+ // Dot below.
+ Ạ: "A",
+ ạ: "a",
+ Ậ: "A",
+ ậ: "a",
+ Ặ: "A",
+ ặ: "a",
+ Ẹ: "E",
+ ẹ: "e",
+ Ệ: "E",
+ ệ: "e",
+ Ị: "I",
+ ị: "i",
+ Ọ: "O",
+ ọ: "o",
+ Ộ: "O",
+ ộ: "o",
+ Ợ: "O",
+ ợ: "o",
+ Ụ: "U",
+ ụ: "u",
+ Ự: "U",
+ ự: "u",
+ Ỵ: "Y",
+ ỵ: "y",
+ // Vowels with diacritic (Chinese, Hanyu Pinyin).
+ ɑ: "a",
+ // Macron.
+ Ǖ: "U",
+ ǖ: "u",
+ // Acute accent.
+ Ǘ: "U",
+ ǘ: "u",
+ // Caron.
+ Ǎ: "A",
+ ǎ: "a",
+ Ǐ: "I",
+ ǐ: "i",
+ Ǒ: "O",
+ ǒ: "o",
+ Ǔ: "U",
+ ǔ: "u",
+ Ǚ: "U",
+ ǚ: "u",
+ // Grave accent.
+ Ǜ: "U",
+ ǜ: "u"
+ };
+ var locale_from_server;
+ $.ajax({
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ async: false,
+ data: {
+ action: "gcmi_fb_get_locale",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ },
+ success: function (res) {
+ locale_from_server = res.locale;
+ },
+ error: function (res) {
+ locale_from_server = "unknown";
+ }
+ });
+ if (locale_from_server.startsWith("de")) {
+ chars["Ä"] = "Ae";
+ chars["ä"] = "ae";
+ chars["Ö"] = "Oe";
+ chars["ö"] = "oe";
+ chars["Ü"] = "Ue";
+ chars["ü"] = "ue";
+ chars["ß"] = "ss";
+ } else if ("da_DK" === locale_from_server) {
+ chars["Æ"] = "Ae";
+ chars["æ"] = "ae";
+ chars["Ø"] = "Oe";
+ chars["ø"] = "oe";
+ chars["Å"] = "Aa";
+ chars["å"] = "aa";
+ } else if ("ca" === locale_from_server) {
+ chars["l·l"] = "ll";
+ } else if (
+ "sr_RS" === locale_from_server ||
+ "bs_BA" === locale_from_server
+ ) {
+ chars["Đ"] = "DJ";
+ chars["đ"] = "dj";
+ }
+ let replaced_string = "";
+ for (let i = 0; i < string.length; i++) {
+ if (string.charAt(i) in chars) {
+ replaced_string = replaced_string + chars[string.charAt(i)];
+ } else {
+ replaced_string = replaced_string + string.charAt(i);
+ }
+ }
+ return replaced_string;
+ }
+ // Rende invisibili i blocchi con le lettere se tutti i comuni sono non selezionati
+ function hideemptyletters() {
+ $("div[class^='gcmi-fb-lettera-blocco']").each(function () {
+ var wrap = $(this);
+ if (
+ wrap.find("input[type=checkbox][id^='fb-gcmi-com-']:checked").length ===
+ 0
+ ) {
+ wrap.hide();
+ } else {
+ wrap.show();
+ }
+ });
+ }
+ // a confirmation dialog using deferred object
+ function customConfirm(customMessage, title) {
+ var dfd = new jQuery.Deferred();
+ $("#gcmi-fb-dialog").html(customMessage);
+ //$("#gcmi-fb-dialog").prop('title', title );
+ $("#gcmi-fb-dialog").dialog({
+ resizable: false,
+ height: 240,
+ modal: true,
+ title: title,
+ buttons: {
+ OK: function () {
+ $(this).dialog("close");
+ dfd.resolve();
+ },
+ Cancel: function () {
+ $(this).dialog("close");
+ dfd.reject();
}
- function printTabsEditFilter( editfiltername ) {
- var includi = $('#gcmi-fb-include-ceased').prop('checked');
- $.ajax({
- type: 'post',
- dataType: 'json',
- url: gcmi_fb_obj.ajax_url,
- async: false,
- data: {
- action: 'gcmi_fb_edit_filter',
- _ajax_nonce: gcmi_fb_obj.nonce,
- includi: includi,
- filtername: editfiltername
- },
- success: function (res) {
- cleaningTabs();
- if ("true" === res.includi ) {
- $("input[type='checkbox'][id='gcmi-fb-include-ceased']").prop('checked', true);
- } else {
- $("input[type='checkbox'][id='gcmi-fb-include-ceased']").removeAttr('checked');
- }
- $('#gcmi-fb-tabs-2').append(res.regioni_html);
- $('#gcmi-fb-tabs-3').append(res.province_html);
- $('#gcmi-fb-tabs-4').append(res.comuni_html);
- $('#gcmi-fb-tabs-5').append(res.commit_buttons);
+ }
+ });
+ return dfd.promise();
+ }
- // se non sono selezionate le regioni nel primo quadro, metto l'uncheck al checkall della regione
- $("#gcmi-fb-tabs-2 input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkall-']").each(function () {
- $(this).change();
- });
- $("#gcmi-fb-tabs-3 input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkallpr-']").each(function () {
- $(this).change();
- });
-// $("#gcmi-fb-tabs-4 input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkallcom-']").each(function () {
-// $(this).change();
-// });
- },
- error: function (res) {
- console.log(res);
- }
- });
+ function customOkMessage(customMessage, title) {
+ var dfd = new jQuery.Deferred();
+ $("#gcmi-fb-dialog").html(customMessage);
+ //$("#gcmi-fb-dialog").prop('title', title );
+ $("#gcmi-fb-dialog").dialog({
+ resizable: false,
+ height: 240,
+ modal: true,
+ title: title,
+ buttons: {
+ OK: function () {
+ $(this).dialog("close");
+ dfd.resolve();
}
- function print_filters() {
+ }
+ });
+ return dfd.promise();
+ }
+
+ function saveFilter(includi, myfiltername, searchIDs, tmp=false) {
+ /*
+ * Nel caso in cui l'array spedito sia molto grande (nel test,
+ * superiore a 997 elementi) il JS lo manda intero, ma il codice PHP
+ * lato server lo tronca.
+ * In linea astratta, un filtro può contenetere fino a circa 10.000
+ * elementi (comuni cessati, più comuni attuali).
+ * Non sembra che la variabile max_input_vars abbia un effetto su questa
+ * cosa, e comunque il valore impotato di default è 1.000.
+ * È possibile che la questione riguardi la dimensione massima dell'header
+ * HTTP impostato nei server (a seconda dei server, compresa tra 4k e 16k).
+ *
+ * Il codice seguente, gestisce questa eventualità con una strategia di
+ * invii multipli dei codici, che verranno poi riassemblati lato server.
+ *
+ * Il meccanismo utilizza chiamate multiple ajax e deferred objects.
+ *
+ * La const chunkSize, indica il numero massimo di codici inviati
+ * per ogni singola chiamata ajax.
+ */
+ if (searchIDs.length > chunkSize) {
+ saveFilterMulti(includi, myfiltername, searchIDs, tmp);
+ } else {
+ saveFilterSingular(includi, myfiltername, searchIDs, tmp);
+ }
+ }
+
+ function saveFilterSingular(includi, myfiltername, searchIDs, tmp) {
+ $.ajax({
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ data: {
+ action: "gcmi_fb_create_filter",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ includi: includi,
+ filtername: myfiltername,
+ codici: searchIDs
+ },
+ success: function (res) {
+ if ( false === tmp ) {
+ print_filters();
+ $("#gcmi-fb-tabs").hide();
+ } else {
+ // stampo le nuove tabs
+ printTabsEditFilter(myfiltername);
+ // rimuovo il filtro temporaneo dal database
+ waitForEl("#fb_gcmi_filter_name", function() {
$.ajax({
- type: 'post',
- dataType: 'json',
- url: gcmi_fb_obj.ajax_url,
- data: {
- action: 'gcmi_fb_get_filters',
- _ajax_nonce: gcmi_fb_obj.nonce
- },
- success: function (res) {
- $('#gcmi-fb-filters-container').html("");
- $('#gcmi-fb-filters-container').append(res.filters_html);
- }
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ data: {
+ action: "gcmi_fb_delete_filter",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ filtername: myfiltername
+ },
+ error: function (res) {
+ console.log(res);
+ }
});
+ });
+ }
+ },
+ error: function (res) {
+ if ( false === tmp ) {
+ showResErrorMessage(res, "CreateFilter");
+ return;
+ } else {
+ showResErrorMessage(res, "TmpFilterFailed");
+ return;
}
- function sanitize_table_name(name) {
- let clean;
- if(typeof name === 'string' || name instanceof String) {
- if(0 === name.length) {
- return false;
- }
- clean = name.trim();
- // caratteri ascii da 128 a 255
- let thisRegex = new RegExp(/[\x80-\xff]/g);
- if(thisRegex.test(clean)) {
- //clean = clean.normalize("NFKC").replace(/[\u0300-\u036f]/g, "");
- //clean = clean.normalize("NFD").replace(/\p{Diacritic}/gu, "");
- clean = remove_accents(clean);
- }
- clean = clean
- .toLowerCase()
- .replace(/[^a-z0-9_\-]/g, '')
- .replace(/-/g, '_')
- .replace(/(_)\1+/g, '_')
- .replace(/^_+/, '')
- .replace(/_+$/, '');
- if(clean.length === 0) {
- return false;
- } else {
- return clean;
- }
+ }
+ });
+ }
+
+ function saveFilterMulti(includi, myfiltername, searchIDs, tmp=false) {
+ var chunkedArray = splitArray(searchIDs, chunkSize);
+ let TotalSlices = chunkedArray.length;
+ var sliceSent = 0;
+ var sliceIndex;
+ var TotalSuccess = 0;
+ var TotalSelected = searchIDs.length;
+
+ // Save all requests in an array of jqXHR objects
+ var requests = chunkedArray.map(async function (slice, sliceIndex) {
+ await sleep(1000);
+ return $.ajax({
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ tryCount: 0,
+ retryLimit: 3,
+ data: {
+ action: "gcmi_fb_save_filter_slice",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ includi: includi,
+ filtername: myfiltername,
+ codici: slice,
+ total: TotalSlices,
+ slice: sliceIndex + 1,
+ },
+ success: function (res) {
+ TotalSuccess++;
+ },
+ error: function (res) {
+ if (res.status == 422) {
+ this.tryCount++;
+ if (this.tryCount <= this.retryLimit) {
+ $.ajax(this);
+ return;
} else {
- return false;
+ // devo dirgli qualcosa
+ showResErrorMessage(res, "CreateFilter");
+ return;
}
- }
- function remove_accents(string) {
- let chars = {
- // Decompositions for Latin-1 Supplement.
- 'ª': 'a',
- 'º': 'o',
- 'À': 'A',
- 'Á': 'A',
- 'Â': 'A',
- 'Ã': 'A',
- 'Ä': 'A',
- 'Å': 'A',
- 'Æ': 'AE',
- 'Ç': 'C',
- 'È': 'E',
- 'É': 'E',
- 'Ê': 'E',
- 'Ë': 'E',
- 'Ì': 'I',
- 'Í': 'I',
- 'Î': 'I',
- 'Ï': 'I',
- 'Ð': 'D',
- 'Ñ': 'N',
- 'Ò': 'O',
- 'Ó': 'O',
- 'Ô': 'O',
- 'Õ': 'O',
- 'Ö': 'O',
- 'Ù': 'U',
- 'Ú': 'U',
- 'Û': 'U',
- 'Ü': 'U',
- 'Ý': 'Y',
- 'Þ': 'TH',
- 'ß': 's',
- 'à': 'a',
- 'á': 'a',
- 'â': 'a',
- 'ã': 'a',
- 'ä': 'a',
- 'å': 'a',
- 'æ': 'ae',
- 'ç': 'c',
- 'è': 'e',
- 'é': 'e',
- 'ê': 'e',
- 'ë': 'e',
- 'ì': 'i',
- 'í': 'i',
- 'î': 'i',
- 'ï': 'i',
- 'ð': 'd',
- 'ñ': 'n',
- 'ò': 'o',
- 'ó': 'o',
- 'ô': 'o',
- 'õ': 'o',
- 'ö': 'o',
- 'ø': 'o',
- 'ù': 'u',
- 'ú': 'u',
- 'û': 'u',
- 'ü': 'u',
- 'ý': 'y',
- 'þ': 'th',
- 'ÿ': 'y',
- 'Ø': 'O',
- // Decompositions for Latin Extended-A.
- 'Ā': 'A',
- 'ā': 'a',
- 'Ă': 'A',
- 'ă': 'a',
- 'Ą': 'A',
- 'ą': 'a',
- 'Ć': 'C',
- 'ć': 'c',
- 'Ĉ': 'C',
- 'ĉ': 'c',
- 'Ċ': 'C',
- 'ċ': 'c',
- 'Č': 'C',
- 'č': 'c',
- 'Ď': 'D',
- 'ď': 'd',
- 'Đ': 'D',
- 'đ': 'd',
- 'Ē': 'E',
- 'ē': 'e',
- 'Ĕ': 'E',
- 'ĕ': 'e',
- 'Ė': 'E',
- 'ė': 'e',
- 'Ę': 'E',
- 'ę': 'e',
- 'Ě': 'E',
- 'ě': 'e',
- 'Ĝ': 'G',
- 'ĝ': 'g',
- 'Ğ': 'G',
- 'ğ': 'g',
- 'Ġ': 'G',
- 'ġ': 'g',
- 'Ģ': 'G',
- 'ģ': 'g',
- 'Ĥ': 'H',
- 'ĥ': 'h',
- 'Ħ': 'H',
- 'ħ': 'h',
- 'Ĩ': 'I',
- 'ĩ': 'i',
- 'Ī': 'I',
- 'ī': 'i',
- 'Ĭ': 'I',
- 'ĭ': 'i',
- 'Į': 'I',
- 'į': 'i',
- 'İ': 'I',
- 'ı': 'i',
- 'IJ': 'IJ',
- 'ij': 'ij',
- 'Ĵ': 'J',
- 'ĵ': 'j',
- 'Ķ': 'K',
- 'ķ': 'k',
- 'ĸ': 'k',
- 'Ĺ': 'L',
- 'ĺ': 'l',
- 'Ļ': 'L',
- 'ļ': 'l',
- 'Ľ': 'L',
- 'ľ': 'l',
- 'Ŀ': 'L',
- 'ŀ': 'l',
- 'Ł': 'L',
- 'ł': 'l',
- 'Ń': 'N',
- 'ń': 'n',
- 'Ņ': 'N',
- 'ņ': 'n',
- 'Ň': 'N',
- 'ň': 'n',
- 'ʼn': 'n',
- 'Ŋ': 'N',
- 'ŋ': 'n',
- 'Ō': 'O',
- 'ō': 'o',
- 'Ŏ': 'O',
- 'ŏ': 'o',
- 'Ő': 'O',
- 'ő': 'o',
- 'Œ': 'OE',
- 'œ': 'oe',
- 'Ŕ': 'R',
- 'ŕ': 'r',
- 'Ŗ': 'R',
- 'ŗ': 'r',
- 'Ř': 'R',
- 'ř': 'r',
- 'Ś': 'S',
- 'ś': 's',
- 'Ŝ': 'S',
- 'ŝ': 's',
- 'Ş': 'S',
- 'ş': 's',
- 'Š': 'S',
- 'š': 's',
- 'Ţ': 'T',
- 'ţ': 't',
- 'Ť': 'T',
- 'ť': 't',
- 'Ŧ': 'T',
- 'ŧ': 't',
- 'Ũ': 'U',
- 'ũ': 'u',
- 'Ū': 'U',
- 'ū': 'u',
- 'Ŭ': 'U',
- 'ŭ': 'u',
- 'Ů': 'U',
- 'ů': 'u',
- 'Ű': 'U',
- 'ű': 'u',
- 'Ų': 'U',
- 'ų': 'u',
- 'Ŵ': 'W',
- 'ŵ': 'w',
- 'Ŷ': 'Y',
- 'ŷ': 'y',
- 'Ÿ': 'Y',
- 'Ź': 'Z',
- 'ź': 'z',
- 'Ż': 'Z',
- 'ż': 'z',
- 'Ž': 'Z',
- 'ž': 'z',
- 'ſ': 's',
- // Decompositions for Latin Extended-B.
- 'Ə': 'E',
- 'ǝ': 'e',
- 'Ș': 'S',
- 'ș': 's',
- 'Ț': 'T',
- 'ț': 't',
- // Euro sign.
- '€': 'E',
- // GBP (Pound) sign.
- '£': '',
- // Vowels with diacritic (Vietnamese). Unmarked.
- 'Ơ': 'O',
- 'ơ': 'o',
- 'Ư': 'U',
- 'ư': 'u',
- // Grave accent.
- 'Ầ': 'A',
- 'ầ': 'a',
- 'Ằ': 'A',
- 'ằ': 'a',
- 'Ề': 'E',
- 'ề': 'e',
- 'Ồ': 'O',
- 'ồ': 'o',
- 'Ờ': 'O',
- 'ờ': 'o',
- 'Ừ': 'U',
- 'ừ': 'u',
- 'Ỳ': 'Y',
- 'ỳ': 'y',
- // Hook.
- 'Ả': 'A',
- 'ả': 'a',
- 'Ẩ': 'A',
- 'ẩ': 'a',
- 'Ẳ': 'A',
- 'ẳ': 'a',
- 'Ẻ': 'E',
- 'ẻ': 'e',
- 'Ể': 'E',
- 'ể': 'e',
- 'Ỉ': 'I',
- 'ỉ': 'i',
- 'Ỏ': 'O',
- 'ỏ': 'o',
- 'Ổ': 'O',
- 'ổ': 'o',
- 'Ở': 'O',
- 'ở': 'o',
- 'Ủ': 'U',
- 'ủ': 'u',
- 'Ử': 'U',
- 'ử': 'u',
- 'Ỷ': 'Y',
- 'ỷ': 'y',
- // Tilde.
- 'Ẫ': 'A',
- 'ẫ': 'a',
- 'Ẵ': 'A',
- 'ẵ': 'a',
- 'Ẽ': 'E',
- 'ẽ': 'e',
- 'Ễ': 'E',
- 'ễ': 'e',
- 'Ỗ': 'O',
- 'ỗ': 'o',
- 'Ỡ': 'O',
- 'ỡ': 'o',
- 'Ữ': 'U',
- 'ữ': 'u',
- 'Ỹ': 'Y',
- 'ỹ': 'y',
- // Acute accent.
- 'Ấ': 'A',
- 'ấ': 'a',
- 'Ắ': 'A',
- 'ắ': 'a',
- 'Ế': 'E',
- 'ế': 'e',
- 'Ố': 'O',
- 'ố': 'o',
- 'Ớ': 'O',
- 'ớ': 'o',
- 'Ứ': 'U',
- 'ứ': 'u',
- // Dot below.
- 'Ạ': 'A',
- 'ạ': 'a',
- 'Ậ': 'A',
- 'ậ': 'a',
- 'Ặ': 'A',
- 'ặ': 'a',
- 'Ẹ': 'E',
- 'ẹ': 'e',
- 'Ệ': 'E',
- 'ệ': 'e',
- 'Ị': 'I',
- 'ị': 'i',
- 'Ọ': 'O',
- 'ọ': 'o',
- 'Ộ': 'O',
- 'ộ': 'o',
- 'Ợ': 'O',
- 'ợ': 'o',
- 'Ụ': 'U',
- 'ụ': 'u',
- 'Ự': 'U',
- 'ự': 'u',
- 'Ỵ': 'Y',
- 'ỵ': 'y',
- // Vowels with diacritic (Chinese, Hanyu Pinyin).
- 'ɑ': 'a',
- // Macron.
- 'Ǖ': 'U',
- 'ǖ': 'u',
- // Acute accent.
- 'Ǘ': 'U',
- 'ǘ': 'u',
- // Caron.
- 'Ǎ': 'A',
- 'ǎ': 'a',
- 'Ǐ': 'I',
- 'ǐ': 'i',
- 'Ǒ': 'O',
- 'ǒ': 'o',
- 'Ǔ': 'U',
- 'ǔ': 'u',
- 'Ǚ': 'U',
- 'ǚ': 'u',
- // Grave accent.
- 'Ǜ': 'U',
- 'ǜ': 'u'
- };
- var locale_from_server;
+ return;
+ }
+ if (res.status != 422) {
+ // devo dirgli qualcosa
+ showResErrorMessage(res);
+ return;
+ }
+ return;
+ },
+ });
+ });
+ $.when(...requests).then((...responses) => {
+ // do something with responses
+ // console.log( responses );
+
+ if (TotalSlices === TotalSuccess) {
+ // procedo con la richiesta di filtro
+ sendSplittedSaveReq(includi, myfiltername, TotalSlices, TotalSelected, tmp);
+ }
+ });
+ }
+
+ function splitArray(array, chunkSize) {
+ let result = [];
+ for (let i = 0; i < array.length; i += chunkSize) {
+ let chunk = array.slice(i, i + chunkSize);
+ result.push(chunk);
+ }
+ return result;
+ }
+
+ function sendSplittedSaveReq(includi, myfiltername, TotalSlices, TotalSelected, tmp=false) {
+ $.ajax({
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ tryCount: 0,
+ retryLimit: 3,
+ data: {
+ action: "gcmi_fb_create_filter_multi",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ includi: includi,
+ filtername: myfiltername,
+ total: TotalSlices,
+ count: TotalSelected
+ },
+ success: function (res) {
+ // filtro creato
+ if ( false === tmp ) {
+ print_filters();
+ $("#gcmi-fb-tabs").hide();
+ } else {
+ // stampo le nuove tabs
+ printTabsEditFilter(myfiltername);
+ // rimuovo il filtro temporaneo dal database
+ waitForEl("#fb_gcmi_filter_name", function() {
$.ajax({
- type: 'post',
- dataType: 'json',
- url: gcmi_fb_obj.ajax_url,
- async: false,
- data: {
- action: 'gcmi_fb_get_locale',
- _ajax_nonce: gcmi_fb_obj.nonce,
- },
- success: function (res) {
- locale_from_server = res.locale;
- },
- error: function (res) {
- locale_from_server = "unknown";
- }
- });
- if(locale_from_server.startsWith('de')) {
- chars['Ä'] = 'Ae';
- chars['ä'] = 'ae';
- chars['Ö'] = 'Oe';
- chars['ö'] = 'oe';
- chars['Ü'] = 'Ue';
- chars['ü'] = 'ue';
- chars['ß'] = 'ss';
- } else if('da_DK' === locale_from_server) {
- chars['Æ'] = 'Ae';
- chars['æ'] = 'ae';
- chars['Ø'] = 'Oe';
- chars['ø'] = 'oe';
- chars['Å'] = 'Aa';
- chars['å'] = 'aa';
- } else if('ca' === locale_from_server) {
- chars['l·l'] = 'll';
- } else if(('sr_RS' === locale_from_server) || ('bs_BA' === locale_from_server)) {
- chars['Đ'] = 'DJ';
- chars['đ'] = 'dj';
- }
- let replaced_string = "";
- for(let i = 0; i < string.length; i++) {
- if(string.charAt(i) in chars) {
- replaced_string = replaced_string + chars[string.charAt(i)];
- } else {
- replaced_string = replaced_string + string.charAt(i);
- }
- }
- return replaced_string;
- }
- // Rende invisibili i blocchi con le lettere se tutti i comuni sono non selezionati
- function hideemptyletters() {
- $("div[class^='gcmi-fb-lettera-blocco']").each(function () {
- var wrap = $(this);
- if(wrap.find("input[type=checkbox][id^='fb-gcmi-com-']:checked").length === 0) {
- wrap.hide();
- } else {
- wrap.show();
- }
+ type: "post",
+ dataType: "json",
+ url: gcmi_fb_obj.ajax_url,
+ data: {
+ action: "gcmi_fb_delete_filter",
+ _ajax_nonce: gcmi_fb_obj.nonce,
+ filtername: myfiltername
+ },
+ error: function (res) {
+ console.log(res);
+ }
});
+ });
}
- // a confirmation dialog using deferred object
- function customConfirm(customMessage, title) {
- var dfd = new jQuery.Deferred();
- $("#gcmi-fb-dialog").html(customMessage);
- //$("#gcmi-fb-dialog").prop('title', title );
- $("#gcmi-fb-dialog").dialog({
- resizable: false,
- height: 240,
- modal: true,
- title: title,
- buttons: {
- "OK": function () {
- $(this).dialog("close");
- dfd.resolve();
- },
- Cancel: function () {
- $(this).dialog("close");
- dfd.reject();
- }
- }
- });
- return dfd.promise();
+ },
+ error: function (res) {
+ if (res.status == 422) {
+ this.tryCount++;
+ if (this.tryCount <= this.retryLimit) {
+ $.ajax(this);
+ return;
+ } else {
+ if ( false === tmp ) {
+ showResErrorMessage(res, "CreateFilter");
+ } else {
+ showResErrorMessage(res, "TmpFilterFailed");
+ }
+ return;
+ }
+ return;
}
- function customOkMessage(customMessage, title) {
- var dfd = new jQuery.Deferred();
- $("#gcmi-fb-dialog").html(customMessage);
- //$("#gcmi-fb-dialog").prop('title', title );
- $("#gcmi-fb-dialog").dialog({
- resizable: false,
- height: 240,
- modal: true,
- title: title,
- buttons: {
- "OK": function () {
- $(this).dialog("close");
- dfd.resolve();
- }
- }
- });
- return dfd.promise();
+ if (res.status != 422) {
+ if ( false === tmp ) {
+ showResErrorMessage(res, "CreateFilter");
+ } else {
+ showResErrorMessage(res, "TmpFilterFailed");
+ }
+ return;
}
- function saveFilter(includi, myfiltername, searchIDs) {
- $.ajax({
- type: 'post',
- dataType: 'json',
- url: gcmi_fb_obj.ajax_url,
- data: {
- action: 'gcmi_fb_create_filter',
- _ajax_nonce: gcmi_fb_obj.nonce,
- includi: includi,
- filtername: myfiltername,
- codici: searchIDs
- },
- success: function (res) {
- print_filters();
- $('#gcmi-fb-tabs').hide();
- },
- error: function (res) {
- let title = "Errore nella creazione del filtro";
- let message = '';
- let arrData = res.responseJSON.data;
- for (let i = 0; i < arrData.length; i++) {
- message = message + 'Err: ' + arrData[i].code + '
' +
- '' + arrData[i].message + '
';
- }
- $.when(customOkMessage(message, title)).then(
- function () {
- $('#fb_gcmi_filter_name').focus();
- });
- return;
- }
- });
+ return;
+ }
+ });
+ }
+
+ function focusFilter() {
+ $("#fb_gcmi_filter_name").focus();
+ }
+
+ function sleep(ms) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+ }
+
+ function waitForEl(selector, callback) {
+ if ($(selector).length) {
+ callback();
+ } else {
+ setTimeout(function() {
+ waitForEl(selector, callback);
+ }, 100);
+ }
+ }
+
+ function showResErrorMessage(res, errCode) {
+ let errTitle = "";
+ let errMessageIcon =
+ '';
+ let errMessage = errMessageIcon;
+ let arrData;
+ switch (errCode) {
+ case "CreateFilter":
+ errTitle = "Errore nella creazione del filtro";
+ break;
+ case "RetrieveFilter":
+ errTitle = "Errore nel recupero dei dati";
+ break;
+ case "TmpFilterFailed":
+ errTitle = "Errore nella creazione del filtro temporaneo";
+ break;
+ default:
+ errTitle = "Ricevuto errore dal server";
+ }
+ if ( res.responseJSON ) {
+ arrData = res.responseJSON.data;
+ for (let i = 0; i < arrData.length; i++) {
+ errMessage =
+ errMessage +
+ "Err: " +
+ arrData[i].code +
+ "
" +
+ "" +
+ arrData[i].message +
+ "
";
}
+ } else {
+ errMessage = errMessageIcon + "Err: Errore non definito
";
+ }
+ switch (errCode) {
+ case "CreateFilter":
+ $.when(customOkMessage(errMessage, errTitle)).then(focusFilter());
+ return;
+
+ case "TmpFilterFailed":
+ $.when(customOkMessage(errMessage, errTitle)).then(printTabsContent());
+ return;
+ default:
+ return;
}
-);
\ No newline at end of file
+ }
+});
diff --git a/admin/js/scripts.min.js b/admin/js/scripts.min.js
index 5e50c7b..521868c 100644
--- a/admin/js/scripts.min.js
+++ b/admin/js/scripts.min.js
@@ -1,2 +1,2 @@
/*! campi-moduli-italiani 2.1.0 */
-jQuery(document).ready(function(o){function i(){o("button[id^='gcmi-fb-delete-filter-']").attr("disabled","disabled"),o("button[id^='gcmi-fb-edit-filter-']").attr("disabled","disabled"),o("#gcmi-fb-addnew-filter").attr("disabled","disabled")}function n(){o("#gcmi-fb-tabs-2").empty(),o("#gcmi-fb-tabs-3").empty(),o("#gcmi-fb-tabs-4").empty(),o("#gcmi-fb-tabs-5").empty()}function a(){var e="In attesa dei dati...";o("#gcmi-fb-tabs-2").append(e),o("#gcmi-fb-tabs-3").append(e),o("#gcmi-fb-tabs-4").append(e),o("#gcmi-fb-tabs-5").append(e)}function l(){var e=o("#gcmi-fb-include-ceased").prop("checked");o.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_requery_comuni",_ajax_nonce:gcmi_fb_obj.nonce,includi:e},success:function(e){n(),o("#gcmi-fb-tabs-2").append(e.regioni_html),o("#gcmi-fb-tabs-3").append(e.province_html),o("#gcmi-fb-tabs-4").append(e.comuni_html),o("#gcmi-fb-tabs-5").append(e.commit_buttons)}})}function r(e){var i=o("#gcmi-fb-include-ceased").prop("checked");o.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,async:!1,data:{action:"gcmi_fb_edit_filter",_ajax_nonce:gcmi_fb_obj.nonce,includi:i,filtername:e},success:function(e){n(),"true"===e.includi?o("input[type='checkbox'][id='gcmi-fb-include-ceased']").prop("checked",!0):o("input[type='checkbox'][id='gcmi-fb-include-ceased']").removeAttr("checked"),o("#gcmi-fb-tabs-2").append(e.regioni_html),o("#gcmi-fb-tabs-3").append(e.province_html),o("#gcmi-fb-tabs-4").append(e.comuni_html),o("#gcmi-fb-tabs-5").append(e.commit_buttons),o("#gcmi-fb-tabs-2 input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkall-']").each(function(){o(this).change()}),o("#gcmi-fb-tabs-3 input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkallpr-']").each(function(){o(this).change()})},error:function(e){console.log(e)}})}function t(){o.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_get_filters",_ajax_nonce:gcmi_fb_obj.nonce},success:function(e){o("#gcmi-fb-filters-container").html(""),o("#gcmi-fb-filters-container").append(e.filters_html)}})}function f(){o("div[class^='gcmi-fb-lettera-blocco']").each(function(){var e=o(this);0===e.find("input[type=checkbox][id^='fb-gcmi-com-']:checked").length?e.hide():e.show()})}function p(e,i){var c=new jQuery.Deferred;return o("#gcmi-fb-dialog").html(e),o("#gcmi-fb-dialog").dialog({resizable:!1,height:240,modal:!0,title:i,buttons:{OK:function(){o(this).dialog("close"),c.resolve()},Cancel:function(){o(this).dialog("close"),c.reject()}}}),c.promise()}function b(e,i){var c=new jQuery.Deferred;return o("#gcmi-fb-dialog").html(e),o("#gcmi-fb-dialog").dialog({resizable:!1,height:240,modal:!0,title:i,buttons:{OK:function(){o(this).dialog("close"),c.resolve()}}}),c.promise()}function s(e,i,c){o.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_create_filter",_ajax_nonce:gcmi_fb_obj.nonce,includi:e,filtername:i,codici:c},success:function(e){t(),o("#gcmi-fb-tabs").hide()},error:function(e){let i='';var c=e.responseJSON.data;for(let e=0;eErr: "+c[e].code+""+c[e].message+"
";o.when(b(i,"Errore nella creazione del filtro")).then(function(){o("#fb_gcmi_filter_name").focus()})}})}o("input[type=checkbox][id^='gcmi-']").prop("checked",!1),o("input[type=hidden][id^='gcmi-updated-']").each(function(e){"false"==o(this).val()&&(window.MySuffix=o(this).attr("id").substring("gcmi-updated-".length,o(this).attr("id").length),o("input[type=checkbox][id='gcmi-"+window.MySuffix+"']").prop("checked",!0))}),o("#gcmi-fb-tabs").hide(),o(document).on("click","#gcmi-fb-addnew-filter",function(){o("#gcmi-fb-tabs").show(),i(),n(),a(),o("input[type='checkbox'][id='gcmi-fb-include-ceased']").removeAttr("checked"),l()}),o(document).on("click","button[id^='gcmi-fb-edit-filter-']",function(){var e=o(this).attr("id").split("-").pop();o("#gcmi-fb-tabs").show(),i(),n(),a(),r(e)}),o(document).on("click","button[id^='gcmi-fb-delete-filter-']",function(){let e=o(this).attr("id").split("-").pop();var i='Vuoi davvero cancellare il filtro: '+e+"?
ATTENZIONE: Questa operazione non può controllare se il filtro è attualmente in uso nei tuoi moduli.";o.when(p(i,"Conferma eliminazione filtro")).then(function(){o.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_delete_filter",_ajax_nonce:gcmi_fb_obj.nonce,filtername:e},success:function(e){t()},error:function(e){let i='';var c=e.responseJSON.data;for(let e=0;eErr: "+c[e].code+""+c[e].message+"
";o.when(b(i,"Errore nella eliminazione del filtro")).then(function(){})}})})}),o(document).on("click","#gcmi-fb-button-cancel",function(){o.when(p('Vuoi annullare la creazione/modifica del filtro?',"Conferma annullamento operazione")).then(function(){o("#gcmi-fb-tabs").hide(),o("button[id^='gcmi-fb-delete-filter-']").removeAttr("disabled"),o("button[id^='gcmi-fb-edit-filter-']").removeAttr("disabled"),o("#gcmi-fb-addnew-filter").attr("disabled",!1)},function(){})}),o(document).on("click","#gcmi-fb-button-save",function(){event.preventDefault();var c=o("#gcmi-fb-tabs-4").find("input[type=checkbox]:checked").not("[id^='fb-gcmi-chkallcom-']").map(function(){return o(this).val()}).get();if(0===c.length)o.when(b('Non è stato selezionato nessun comune da includere nel filtro.',"Errore nel salvataggio")).then(function(){o("#ui-id-4").click()});else{let i=o("#fb_gcmi_filter_name").val();if(""===i)o.when(b('Non è stato indicato il nome del filtro.',"Errore nel salvataggio")).then(function(){o("#fb_gcmi_filter_name").focus()});else if(20Non più di 20 caratteri ammessi per il nome del filtro.',"Errore nel salvataggio")).then(function(){o("#fb_gcmi_filter_name").val(i.substring(0,20)),o("#fb_gcmi_filter_name").focus()});else{let e=o("#gcmi-fb-include-ceased").prop("checked");var t=function(e){let i;{if("string"==typeof e||e instanceof String){if(0===e.length)return!1;i=e.trim();e=new RegExp(/[\x80-\xff]/g);return 0!==(i=(i=e.test(i)?function(i){var c={"ª":"a","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"s","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ø":"O","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Ĉ":"C","ĉ":"c","Ċ":"C","ċ":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"D","đ":"d","Ē":"E","ē":"e","Ĕ":"E","ĕ":"e","Ė":"E","ė":"e","Ę":"E","ę":"e","Ě":"E","ě":"e","Ĝ":"G","ĝ":"g","Ğ":"G","ğ":"g","Ġ":"G","ġ":"g","Ģ":"G","ģ":"g","Ĥ":"H","ĥ":"h","Ħ":"H","ħ":"h","Ĩ":"I","ĩ":"i","Ī":"I","ī":"i","Ĭ":"I","ĭ":"i","Į":"I","į":"i","İ":"I","ı":"i","IJ":"IJ","ij":"ij","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","ĺ":"l","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ŀ":"L","ŀ":"l","Ł":"L","ł":"l","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","ʼn":"n","Ŋ":"N","ŋ":"n","Ō":"O","ō":"o","Ŏ":"O","ŏ":"o","Ő":"O","ő":"o","Œ":"OE","œ":"oe","Ŕ":"R","ŕ":"r","Ŗ":"R","ŗ":"r","Ř":"R","ř":"r","Ś":"S","ś":"s","Ŝ":"S","ŝ":"s","Ş":"S","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","Ť":"T","ť":"t","Ŧ":"T","ŧ":"t","Ũ":"U","ũ":"u","Ū":"U","ū":"u","Ŭ":"U","ŭ":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","ſ":"s","Ə":"E","ǝ":"e","Ș":"S","ș":"s","Ț":"T","ț":"t","€":"E","£":"","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Ầ":"A","ầ":"a","Ằ":"A","ằ":"a","Ề":"E","ề":"e","Ồ":"O","ồ":"o","Ờ":"O","ờ":"o","Ừ":"U","ừ":"u","Ỳ":"Y","ỳ":"y","Ả":"A","ả":"a","Ẩ":"A","ẩ":"a","Ẳ":"A","ẳ":"a","Ẻ":"E","ẻ":"e","Ể":"E","ể":"e","Ỉ":"I","ỉ":"i","Ỏ":"O","ỏ":"o","Ổ":"O","ổ":"o","Ở":"O","ở":"o","Ủ":"U","ủ":"u","Ử":"U","ử":"u","Ỷ":"Y","ỷ":"y","Ẫ":"A","ẫ":"a","Ẵ":"A","ẵ":"a","Ẽ":"E","ẽ":"e","Ễ":"E","ễ":"e","Ỗ":"O","ỗ":"o","Ỡ":"O","ỡ":"o","Ữ":"U","ữ":"u","Ỹ":"Y","ỹ":"y","Ấ":"A","ấ":"a","Ắ":"A","ắ":"a","Ế":"E","ế":"e","Ố":"O","ố":"o","Ớ":"O","ớ":"o","Ứ":"U","ứ":"u","Ạ":"A","ạ":"a","Ậ":"A","ậ":"a","Ặ":"A","ặ":"a","Ẹ":"E","ẹ":"e","Ệ":"E","ệ":"e","Ị":"I","ị":"i","Ọ":"O","ọ":"o","Ộ":"O","ộ":"o","Ợ":"O","ợ":"o","Ụ":"U","ụ":"u","Ự":"U","ự":"u","Ỵ":"Y","ỵ":"y","ɑ":"a","Ǖ":"U","ǖ":"u","Ǘ":"U","ǘ":"u","Ǎ":"A","ǎ":"a","Ǐ":"I","ǐ":"i","Ǒ":"O","ǒ":"o","Ǔ":"U","ǔ":"u","Ǚ":"U","ǚ":"u","Ǜ":"U","ǜ":"u"};var t;o.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,async:!1,data:{action:"gcmi_fb_get_locale",_ajax_nonce:gcmi_fb_obj.nonce},success:function(e){t=e.locale},error:function(e){t="unknown"}}),t.startsWith("de")?(c["Ä"]="Ae",c["ä"]="ae",c["Ö"]="Oe",c["ö"]="oe",c["Ü"]="Ue",c["ü"]="ue",c["ß"]="ss"):"da_DK"===t?(c["Æ"]="Ae",c["æ"]="ae",c["Ø"]="Oe",c["ø"]="oe",c["Å"]="Aa",c["å"]="aa"):"ca"===t?c["l·l"]="ll":"sr_RS"!==t&&"bs_BA"!==t||(c["Đ"]="DJ",c["đ"]="dj");let n="";for(let e=0;eNon è stato indicato un nome valido per il filtro.',"Errore nel salvataggio")).then(function(){o("#fb_gcmi_filter_name").focus()});else if(i!==t)n='Il valore indicato per il nome del filtro:'+i+" non è utilizzabile.
Vuoi utilizzare: "+t+" ?",o.when(p(n,"Errore nel salvataggio")).then(function(){o("#fb_gcmi_filter_name").val(t)});else{var n=o(".gcmi-fb-filters-container").find("span.gcmi-fb-filters-name").map(function(){return o(this).text()}).get();let i=!1;n.forEach(function(e){t===e&&(i=!0)}),!0===i?o.when(p('Stai sovrascrivendo il filtro:'+t+".
Vuoi continuare?","Sovrascrivi")).then(function(){s(e,t,c)}):s(e,t,c)}}}}),o("#gcmi-fb-tabs").tabs({active:!1,collapsible:!0,classes:{"ui-tabs":"ui-corner-none","ui-tabs-nav":"ui-corner-none","ui-tabs-tab":"ui-corner-none","ui-tabs-panel":"ui-corner-none"}}),o(document).on("change","input[type='checkbox'][id^='fb-gcmi-reg-']",function(){var e=o(this),i=o(this).attr("id").split("-").pop();!1===e.prop("checked")?(o("#gcmi-fb-regione-blocco-"+i).find('input[type=checkbox][id^="fb-gcmi-prov-"]:checked').removeAttr("checked"),o("#gcmi-fb-regione-blocco-"+i).find('input[type=checkbox][id^="fb-gcmi-prov-"]').trigger("change"),o("#gcmi-fb-regione-blocco-"+i).hide()):(o("#gcmi-fb-regione-blocco-"+i).find('input[type=checkbox][id^="fb-gcmi-prov-"]:not(:checked)').prop("checked",!0),o("#gcmi-fb-regione-blocco-"+i).find('input[type=checkbox][id^="fb-gcmi-prov-"]').trigger("change"),o("#gcmi-fb-regione-blocco-"+i).show())}),o(document).on("change","input[type='checkbox'][id^='fb-gcmi-prov-']",function(){var e=o(this),i=o(this).attr("id").split("-").pop(),c=o(this).parent().attr("class").split("-").pop();!1===e.prop("checked")?(o("[id='fb-gcmi-chkallpr-"+c).removeAttr("checked"),o("[name^='gcmi-com-cod-pro-"+i).find("input[type=checkbox]:checked").removeAttr("checked"),o("[name^='gcmi-com-cod-pro-"+i).hide()):(o("[name^='gcmi-com-cod-pro-"+i).show(),o("[name^='gcmi-com-cod-pro-"+i).find("input[type=checkbox]:not(:checked)").prop("checked",!0)),f(),o("[id='gcmi-fb-regione-blocco-"+c).find("input[type=checkbox][id^=fb-gcmi-prov-]:checked").length===o("[id='gcmi-fb-regione-blocco-"+c).find("input[type=checkbox][id^=fb-gcmi-prov-]").length&&o("[id='fb-gcmi-chkallpr-"+c).prop("checked",!0)}),o(document).on("change","input[type='checkbox'][id^='fb-gcmi-com-']",function(){var e=Array.from(o("label[for='"+this.name+"']").text())[0];o("[id='fb-gcmi-chkallcom-"+e).removeAttr("checked"),o("[id='gcmi-fb-lettera-blocco-"+e).find("input[type=checkbox][id^=fb-gcmi-com-]:visible:checked").length===o("[id='gcmi-fb-lettera-blocco-"+e).find("input[type=checkbox][id^=fb-gcmi-com-]:visible").length&&o("[id='fb-gcmi-chkallcom-"+e).prop("checked",!0)}),o(document).on("change","input[type='checkbox'][id^='fb-gcmi-chkallpr-']",function(){var e=o(this),i=o(this).attr("id").split("-").pop();!1===e.prop("checked")?o("#gcmi-fb-regione-blocco-"+i).find("input[type=checkbox]:checked").not("[id^='fb-gcmi-chkallpr-']").removeAttr("checked"):o("#gcmi-fb-regione-blocco-"+i).find("input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkallpr-']").prop("checked",!0),o("#gcmi-fb-regione-blocco-"+i).find("input[type=checkbox]").not("[id^='fb-gcmi-chkallpr-']").trigger("change")}),o(document).on("change","input[type='checkbox'][id^='fb-gcmi-chkallcom-']",function(){var e=o(this),i=o(this).attr("id").split("-").pop();!1===e.prop("checked")?o("#gcmi-fb-lettera-blocco-"+i).find("input[type=checkbox]:checked:visible").not("[id^='fb-gcmi-chkallcom-']").removeAttr("checked"):o("#gcmi-fb-lettera-blocco-"+i).find("input[type=checkbox]:not(:checked):visible").not("[id^='fb-gcmi-chkallcom-']").prop("checked",!0)}),o(document).on("change","input[type='checkbox'][id='gcmi-fb-include-ceased']",function(){var i=o("#fb_gcmi_filter_name").val(),c="tmp_"+(new Date).getTime(),e=o("#gcmi-fb-include-ceased").prop("checked"),t=(event.preventDefault(),o("#gcmi-fb-tabs-4").find("input[type=checkbox]:checked").not("[id^='fb-gcmi-chkallcom-']").map(function(){return o(this).val()}).get());n(),a(),o.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_create_filter",_ajax_nonce:gcmi_fb_obj.nonce,includi:e,filtername:c,codici:t},success:function(e){r(c),o.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_delete_filter",_ajax_nonce:gcmi_fb_obj.nonce,filtername:c},error:function(e){console.log(e)}}),o("#fb_gcmi_filter_name").val(i)},error:function(e){console.log("Fallita creazione filtro temporaneo"),l()}})})});
\ No newline at end of file
+"use strict";jQuery(document).ready(function(b){b("input[type=checkbox][id^='gcmi-']").prop("checked",!1),b("input[type=hidden][id^='gcmi-updated-']").each(function(e){"false"==b(this).val()&&(window.MySuffix=b(this).attr("id").substring("gcmi-updated-".length,b(this).attr("id").length),b("input[type=checkbox][id='gcmi-"+window.MySuffix+"']").prop("checked",!0))});const u=300;var c="";function i(){b("button[id^='gcmi-fb-delete-filter-']").attr("disabled","disabled"),b("button[id^='gcmi-fb-edit-filter-']").attr("disabled","disabled"),b("#gcmi-fb-addnew-filter").attr("disabled","disabled")}function n(){b("#gcmi-fb-tabs-2").empty(),b("#gcmi-fb-tabs-3").empty(),b("#gcmi-fb-tabs-4").empty(),b("#gcmi-fb-tabs-5").empty()}function o(){var e="In attesa dei dati...";b("#gcmi-fb-tabs-2").append(e),b("#gcmi-fb-tabs-3").append(e),b("#gcmi-fb-tabs-4").append(e),b("#gcmi-fb-tabs-5").append(e)}function a(){var e=b("#gcmi-fb-include-ceased").prop("checked");b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_requery_comuni",_ajax_nonce:gcmi_fb_obj.nonce,includi:e},success:function(e){n(),b("#gcmi-fb-tabs-2").append(e.regioni_html),b("#gcmi-fb-tabs-3").append(e.province_html),b("#gcmi-fb-tabs-4").append(e.comuni_html),b("#gcmi-fb-tabs-5").append(e.commit_buttons)}})}function m(e){var i=b("#gcmi-fb-include-ceased").prop("checked");b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_edit_filter",_ajax_nonce:gcmi_fb_obj.nonce,includi:i,filtername:e},success:function(e){n(),"true"===e.includi?b("input[type='checkbox'][id='gcmi-fb-include-ceased']").prop("checked",!0):b("input[type='checkbox'][id='gcmi-fb-include-ceased']").removeAttr("checked"),b("#gcmi-fb-tabs-2").append(e.regioni_html),b("#gcmi-fb-tabs-3").append(e.province_html),b("#gcmi-fb-tabs-4").append(e.comuni_html),b("#gcmi-fb-tabs-5").append(e.commit_buttons),b("#gcmi-fb-tabs-2 input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkall-']").each(function(){b(this).change()}),b("#gcmi-fb-tabs-3 input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkallpr-']").each(function(){b(this).change()}),b(".gcmi-fb-lettera-blocco").each(function(){b(this).find(":checkbox").not("[id^='fb-gcmi-chkallcom-']").first().change()})},error:function(e){_(e,"RetrieveFilter")}})}function g(){b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_get_filters",_ajax_nonce:gcmi_fb_obj.nonce},success:function(e){b("#gcmi-fb-filters-container").html(""),b("#gcmi-fb-filters-container").append(e.data.filters_html)}})}function r(){b("div[class^='gcmi-fb-lettera-blocco']").each(function(){var e=b(this);0===e.find("input[type=checkbox][id^='fb-gcmi-com-']:checked").length?e.hide():e.show()})}function l(e,i){var t=new jQuery.Deferred;return b("#gcmi-fb-dialog").html(e),b("#gcmi-fb-dialog").dialog({resizable:!1,height:240,modal:!0,title:i,buttons:{OK:function(){b(this).dialog("close"),t.resolve()},Cancel:function(){b(this).dialog("close"),t.reject()}}}),t.promise()}function f(e,i){var t=new jQuery.Deferred;return b("#gcmi-fb-dialog").html(e),b("#gcmi-fb-dialog").dialog({resizable:!1,height:240,modal:!0,title:i,buttons:{OK:function(){b(this).dialog("close"),t.resolve()}}}),t.promise()}function s(e,i,t,c=!1){if(t.length>u){var[a,r,n,l=!1]=[e,i,t,c];var f=function(i,t){var c=[];for(let e=0;esetTimeout(e,t)),b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,tryCount:0,retryLimit:3,data:{action:"gcmi_fb_save_filter_slice",_ajax_nonce:gcmi_fb_obj.nonce,includi:a,filtername:r,codici:e,total:o,slice:i+1},success:function(e){s++},error:function(e){if(422==e.status)return this.tryCount++,this.tryCount<=this.retryLimit?void b.ajax(this):void _(e,"CreateFilter");422!=e.status&&_(e)}})});b.when(...n).then(()=>{var e,i,t,c,n;o===s&&([e,i,t,c,n=!1]=[a,r,o,p,l],b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,tryCount:0,retryLimit:3,data:{action:"gcmi_fb_create_filter_multi",_ajax_nonce:gcmi_fb_obj.nonce,includi:e,filtername:i,total:t,count:c},success:function(e){!1===n?(g(),b("#gcmi-fb-tabs").hide()):(m(i),h("#fb_gcmi_filter_name",function(){b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_delete_filter",_ajax_nonce:gcmi_fb_obj.nonce,filtername:i},error:function(e){console.log(e)}})}))},error:function(e){if(422==e.status)return this.tryCount++,this.tryCount<=this.retryLimit?void b.ajax(this):void _(e,!1===n?"CreateFilter":"TmpFilterFailed");422!=e.status&&_(e,!1===n?"CreateFilter":"TmpFilterFailed")}}))})}else o=i,d=c,b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_create_filter",_ajax_nonce:gcmi_fb_obj.nonce,includi:e,filtername:o,codici:t},success:function(e){!1===d?(g(),b("#gcmi-fb-tabs").hide()):(m(o),h("#fb_gcmi_filter_name",function(){b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_delete_filter",_ajax_nonce:gcmi_fb_obj.nonce,filtername:o},error:function(e){console.log(e)}})}))},error:function(e){_(e,!1===d?"CreateFilter":"TmpFilterFailed")}});var o,d}function h(e,i){b(e).length?i():setTimeout(function(){h(e,i)},100)}function _(e,i){let t="";var c,n='';let o=n;switch(i){case"CreateFilter":t="Errore nella creazione del filtro";break;case"RetrieveFilter":t="Errore nel recupero dei dati";break;case"TmpFilterFailed":t="Errore nella creazione del filtro temporaneo";break;default:t="Ricevuto errore dal server"}if(e.responseJSON){c=e.responseJSON.data;for(let e=0;eErr: "+c[e].code+""+c[e].message+"
"}else o=n+"Err: Errore non definito
";switch(i){case"CreateFilter":return void b.when(f(o,t)).then(void b("#fb_gcmi_filter_name").focus());case"TmpFilterFailed":return void b.when(f(o,t)).then(a())}}b("#gcmi-fb-tabs").hide(),b(document).on("click","#gcmi-fb-addnew-filter",function(){b("#gcmi-fb-tabs").show(),i(),n(),o(),b("input[type='checkbox'][id='gcmi-fb-include-ceased']").removeAttr("checked"),a()}),b(document).on("click","button[id^='gcmi-fb-edit-filter-']",function(){var e=b(this).attr("id").split("-").pop();c=e,b("#gcmi-fb-tabs").show(),i(),n(),o(),m(e),h("#fb_gcmi_filter_name",function(){b("#fb_gcmi_filter_name").val(c)})}),b(document).on("click","button[id^='gcmi-fb-delete-filter-']",function(){let e=b(this).attr("id").split("-").pop();var i='Vuoi davvero cancellare il filtro: '+e+"?
ATTENZIONE: Questa operazione non può controllare se il filtro è attualmente in uso nei tuoi moduli.";b.when(l(i,"Conferma eliminazione filtro")).then(function(){b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,data:{action:"gcmi_fb_delete_filter",_ajax_nonce:gcmi_fb_obj.nonce,filtername:e},success:function(e){g()},error:function(e){let i='';var t=e.responseJSON.data;for(let e=0;eErr: "+t[e].code+""+t[e].message+"
";b.when(f(i,"Errore nella eliminazione del filtro")).then(function(){})}})})}),b(document).on("click","#gcmi-fb-button-cancel",function(){b.when(l('Vuoi annullare la creazione/modifica del filtro?',"Conferma annullamento operazione")).then(function(){b("#gcmi-fb-tabs").hide(),b("button[id^='gcmi-fb-delete-filter-']").removeAttr("disabled"),b("button[id^='gcmi-fb-edit-filter-']").removeAttr("disabled"),b("#gcmi-fb-addnew-filter").attr("disabled",!1)},function(){})}),b(document).on("click","#gcmi-fb-button-save",function(){event.preventDefault();var t=b("#gcmi-fb-tabs-4").find("input[type=checkbox]:checked").not("[id^='fb-gcmi-chkallcom-']").map(function(){return b(this).val()}).get();if(0===t.length)b.when(f('Non è stato selezionato nessun comune da includere nel filtro.',"Errore nel salvataggio")).then(function(){b("#ui-id-4").click()});else{let i=b("#fb_gcmi_filter_name").val();if(""===i)b.when(f('Non è stato indicato il nome del filtro.',"Errore nel salvataggio")).then(function(){b("#fb_gcmi_filter_name").focus()});else if(20Non più di 20 caratteri ammessi per il nome del filtro.',"Errore nel salvataggio")).then(function(){b("#fb_gcmi_filter_name").val(i.substring(0,20)),b("#fb_gcmi_filter_name").focus()});else{let e=b("#gcmi-fb-include-ceased").prop("checked");var c=function(e){let i;{if("string"==typeof e||e instanceof String){if(0===e.length)return!1;i=e.trim();e=new RegExp(/[\x80-\xff]/g);return 0!==(i=(i=e.test(i)?function(i){var t={"ª":"a","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"s","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ø":"O","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Ĉ":"C","ĉ":"c","Ċ":"C","ċ":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"D","đ":"d","Ē":"E","ē":"e","Ĕ":"E","ĕ":"e","Ė":"E","ė":"e","Ę":"E","ę":"e","Ě":"E","ě":"e","Ĝ":"G","ĝ":"g","Ğ":"G","ğ":"g","Ġ":"G","ġ":"g","Ģ":"G","ģ":"g","Ĥ":"H","ĥ":"h","Ħ":"H","ħ":"h","Ĩ":"I","ĩ":"i","Ī":"I","ī":"i","Ĭ":"I","ĭ":"i","Į":"I","į":"i","İ":"I","ı":"i","IJ":"IJ","ij":"ij","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","ĺ":"l","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ŀ":"L","ŀ":"l","Ł":"L","ł":"l","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","ʼn":"n","Ŋ":"N","ŋ":"n","Ō":"O","ō":"o","Ŏ":"O","ŏ":"o","Ő":"O","ő":"o","Œ":"OE","œ":"oe","Ŕ":"R","ŕ":"r","Ŗ":"R","ŗ":"r","Ř":"R","ř":"r","Ś":"S","ś":"s","Ŝ":"S","ŝ":"s","Ş":"S","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","Ť":"T","ť":"t","Ŧ":"T","ŧ":"t","Ũ":"U","ũ":"u","Ū":"U","ū":"u","Ŭ":"U","ŭ":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","ſ":"s","Ə":"E","ǝ":"e","Ș":"S","ș":"s","Ț":"T","ț":"t","€":"E","£":"","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Ầ":"A","ầ":"a","Ằ":"A","ằ":"a","Ề":"E","ề":"e","Ồ":"O","ồ":"o","Ờ":"O","ờ":"o","Ừ":"U","ừ":"u","Ỳ":"Y","ỳ":"y","Ả":"A","ả":"a","Ẩ":"A","ẩ":"a","Ẳ":"A","ẳ":"a","Ẻ":"E","ẻ":"e","Ể":"E","ể":"e","Ỉ":"I","ỉ":"i","Ỏ":"O","ỏ":"o","Ổ":"O","ổ":"o","Ở":"O","ở":"o","Ủ":"U","ủ":"u","Ử":"U","ử":"u","Ỷ":"Y","ỷ":"y","Ẫ":"A","ẫ":"a","Ẵ":"A","ẵ":"a","Ẽ":"E","ẽ":"e","Ễ":"E","ễ":"e","Ỗ":"O","ỗ":"o","Ỡ":"O","ỡ":"o","Ữ":"U","ữ":"u","Ỹ":"Y","ỹ":"y","Ấ":"A","ấ":"a","Ắ":"A","ắ":"a","Ế":"E","ế":"e","Ố":"O","ố":"o","Ớ":"O","ớ":"o","Ứ":"U","ứ":"u","Ạ":"A","ạ":"a","Ậ":"A","ậ":"a","Ặ":"A","ặ":"a","Ẹ":"E","ẹ":"e","Ệ":"E","ệ":"e","Ị":"I","ị":"i","Ọ":"O","ọ":"o","Ộ":"O","ộ":"o","Ợ":"O","ợ":"o","Ụ":"U","ụ":"u","Ự":"U","ự":"u","Ỵ":"Y","ỵ":"y","ɑ":"a","Ǖ":"U","ǖ":"u","Ǘ":"U","ǘ":"u","Ǎ":"A","ǎ":"a","Ǐ":"I","ǐ":"i","Ǒ":"O","ǒ":"o","Ǔ":"U","ǔ":"u","Ǚ":"U","ǚ":"u","Ǜ":"U","ǜ":"u"};var c;b.ajax({type:"post",dataType:"json",url:gcmi_fb_obj.ajax_url,async:!1,data:{action:"gcmi_fb_get_locale",_ajax_nonce:gcmi_fb_obj.nonce},success:function(e){c=e.locale},error:function(e){c="unknown"}}),c.startsWith("de")?(t["Ä"]="Ae",t["ä"]="ae",t["Ö"]="Oe",t["ö"]="oe",t["Ü"]="Ue",t["ü"]="ue",t["ß"]="ss"):"da_DK"===c?(t["Æ"]="Ae",t["æ"]="ae",t["Ø"]="Oe",t["ø"]="oe",t["Å"]="Aa",t["å"]="aa"):"ca"===c?t["l·l"]="ll":"sr_RS"!==c&&"bs_BA"!==c||(t["Đ"]="DJ",t["đ"]="dj");let n="";for(let e=0;eNon è stato indicato un nome valido per il filtro.',"Errore nel salvataggio")).then(function(){b("#fb_gcmi_filter_name").focus()});else if(i!==c)n='Il valore indicato per il nome del filtro:'+i+" non è utilizzabile.
Vuoi utilizzare: "+c+" ?",b.when(l(n,"Errore nel salvataggio")).then(function(){b("#fb_gcmi_filter_name").val(c)});else{var n=b(".gcmi-fb-filters-container").find("span.gcmi-fb-filters-name").map(function(){return b(this).text()}).get();let i=!1;n.forEach(function(e){c===e&&(i=!0)}),!0===i?b.when(l('Stai sovrascrivendo il filtro:'+c+".
Vuoi continuare?","Sovrascrivi")).then(function(){s(e,c,t)}):s(e,c,t)}}}}),b("#gcmi-fb-tabs").tabs({active:0,collapsible:!0,heightStyle:"content",classes:{"ui-tabs":"ui-corner-none","ui-tabs-nav":"ui-corner-none","ui-tabs-tab":"ui-corner-none","ui-tabs-panel":"ui-corner-none"}}),b(document).on("change","input[type='checkbox'][id^='fb-gcmi-reg-']",function(){var e=b(this),i=b(this).attr("id").split("-").pop();!1===e.prop("checked")?(b("#gcmi-fb-regione-blocco-"+i).find('input[type=checkbox][id^="fb-gcmi-prov-"]:checked').removeAttr("checked"),b("#gcmi-fb-regione-blocco-"+i).find('input[type=checkbox][id^="fb-gcmi-prov-"]').trigger("change"),b("#gcmi-fb-regione-blocco-"+i).hide()):(b("#gcmi-fb-regione-blocco-"+i).find('input[type=checkbox][id^="fb-gcmi-prov-"]:not(:checked)').prop("checked",!0),b("#gcmi-fb-regione-blocco-"+i).find('input[type=checkbox][id^="fb-gcmi-prov-"]').trigger("change"),b("#gcmi-fb-regione-blocco-"+i).show())}),b(document).on("change","input[type='checkbox'][id^='fb-gcmi-prov-']",function(){var e=b(this),i=b(this).attr("id").split("-").pop(),t=b(this).parent().attr("class").split("-").pop();!1===e.prop("checked")?(b("[id='fb-gcmi-chkallpr-"+t).removeAttr("checked"),b("[name^='gcmi-com-cod-pro-"+i).find("input[type=checkbox]:checked").removeAttr("checked"),b("[name^='gcmi-com-cod-pro-"+i).hide()):(b("[name^='gcmi-com-cod-pro-"+i).show(),b("[name^='gcmi-com-cod-pro-"+i).find("input[type=checkbox]:not(:checked)").prop("checked",!0)),r(),b("[id='gcmi-fb-regione-blocco-"+t).find("input[type=checkbox][id^=fb-gcmi-prov-]:checked").length===b("[id='gcmi-fb-regione-blocco-"+t).find("input[type=checkbox][id^=fb-gcmi-prov-]").length&&b("[id='fb-gcmi-chkallpr-"+t).prop("checked",!0)}),b(document).on("change","input[type='checkbox'][id^='fb-gcmi-com-']",function(){var e=Array.from(b("label[for='"+this.name+"']").text())[0];b("[id='fb-gcmi-chkallcom-"+e).removeAttr("checked"),b("[id='gcmi-fb-lettera-blocco-"+e).find("input[type=checkbox][id^=fb-gcmi-com-]:visible:checked").length===b("[id='gcmi-fb-lettera-blocco-"+e).find("input[type=checkbox][id^=fb-gcmi-com-]:visible").length&&b("[id='fb-gcmi-chkallcom-"+e).prop("checked",!0)}),b(document).on("change","input[type='checkbox'][id^='fb-gcmi-chkallpr-']",function(){var e=b(this),i=b(this).attr("id").split("-").pop();!1===e.prop("checked")?b("#gcmi-fb-regione-blocco-"+i).find("input[type=checkbox]:checked").not("[id^='fb-gcmi-chkallpr-']").removeAttr("checked"):b("#gcmi-fb-regione-blocco-"+i).find("input[type=checkbox]:not(:checked)").not("[id^='fb-gcmi-chkallpr-']").prop("checked",!0),b("#gcmi-fb-regione-blocco-"+i).find("input[type=checkbox]").not("[id^='fb-gcmi-chkallpr-']").trigger("change")}),b(document).on("change","input[type='checkbox'][id^='fb-gcmi-chkallcom-']",function(){var e=b(this),i=b(this).attr("id").split("-").pop();!1===e.prop("checked")?b("#gcmi-fb-lettera-blocco-"+i).find("input[type=checkbox]:checked:visible").not("[id^='fb-gcmi-chkallcom-']").removeAttr("checked"):b("#gcmi-fb-lettera-blocco-"+i).find("input[type=checkbox]:not(:checked):visible").not("[id^='fb-gcmi-chkallcom-']").prop("checked",!0)}),b(document).on("change","input[type='checkbox'][id='gcmi-fb-include-ceased']",function(){c=b("#fb_gcmi_filter_name").val();var e="tmp_"+(new Date).getTime(),i=b("#gcmi-fb-include-ceased").prop("checked"),t=(event.preventDefault(),b("#gcmi-fb-tabs-4").find("input[type=checkbox]:checked").not("[id^='fb-gcmi-chkallcom-']").map(function(){return b(this).val()}).get());n(),o(),s(i,e,t,!0),h("#fb_gcmi_filter_name",function(){b("#fb_gcmi_filter_name").val(c)})})});
\ No newline at end of file
diff --git a/settings.php b/settings.php
index 5e0bbb8..f9f0836 100644
--- a/settings.php
+++ b/settings.php
@@ -154,8 +154,8 @@ function gcmi_add_index_on_tables(): void {
/**
* Controlla se su un campo di una tabella è presente già un indice
*
- * @param string $table_name
- * @param string $field_name
+ * @param string $table_name Nome tabella.
+ * @param string $field_name Nome del campo.
* @since 2.2.0
* @return bool
*/
diff --git a/tests/test-class-gcmi-comune-filter-builder.php b/tests/test-class-gcmi-comune-filter-builder.php
index d8063a1..889fe6a 100644
--- a/tests/test-class-gcmi-comune-filter-builder.php
+++ b/tests/test-class-gcmi-comune-filter-builder.php
@@ -17,10 +17,16 @@ public function set_up() {
add_action( 'wp_ajax_gcmi_fb_requery_comuni', array( $this->gcmi_fb, 'ajax_get_tabs_html' ) );
add_action( 'wp_ajax_gcmi_fb_get_filters', array( $this->gcmi_fb, 'ajax_get_filters_html' ) );
add_action( 'wp_ajax_gcmi_fb_get_locale', array( $this->gcmi_fb, 'ajax_get_locale' ) );
+ add_action( 'wp_ajax_gcmi_fb_save_filter_slice', array( $this->gcmi_fb, 'ajax_save_filters_slice' ) );
+ add_action( 'wp_ajax_gcmi_fb_create_filter_multi', array( $this->gcmi_fb, 'ajax_create_filters_multi' ) );
+
+ self::create_wp_options();
}
public function tear_down() {
+ //self::delete_wp_options();
parent::tear_down();
+
}
protected static function getMethod( $name ) {
@@ -30,6 +36,47 @@ protected static function getMethod( $name ) {
return $method;
}
+ protected static function create_wp_options(){
+ $data_array = self::provideFilterSlice();
+ foreach( $data_array as $datum ){
+ if( true === $datum[1] ) {
+ $option_name = 'gcmi-fb-com-test_' . $datum[0]['filtername'] . '-' . $datum[0]['slice'] . '_' . $datum[0]['total'];
+ $option_value = array(
+ 'includi' => $datum[0]['includi'],
+ 'filtername' => 'test_' . $datum[0]['filtername'],
+ 'codici' => $datum[0]['codici'],
+ 'total' => intval( $datum[0]['total'] ),
+ 'slice' => intval( $datum[0]['slice'] )
+ );
+
+ update_option( $option_name, $option_value, false );
+ }
+ }
+ $fake_option_1_name = 'gcmi-fb-com-fake_filter-1_2';
+ $fake_option_1_value = 'a string';
+ update_option( $fake_option_1_name, $fake_option_1_value, false );
+
+ $fake_option_2_name = 'gcmi-fb-com-fake_filter-2_2';
+ $fake_option_2_value = array(
+ 'includi' => $data_array[0][0]['includi'],
+ 'filtername' => $data_array[0][0]['filtername'],
+ 'codici' => $data_array[0][0]['codici'],
+ 'total' => intval( $data_array[0][0]['total'] ),
+ 'slice' => intval( $data_array[0][0]['slice'] )
+ );
+ update_option( $fake_option_2_name, $fake_option_2_value, false );
+ }
+
+ protected static function delete_wp_options() {
+ delete_option( 'gcmi-fb-com-test_bo_e_prov_sopp-1_4' );
+ delete_option( 'gcmi-fb-com-test_bo_e_prov_sopp-2_4' );
+ delete_option( 'gcmi-fb-com-test_bo_e_prov_sopp-3_4' );
+ delete_option( 'gcmi-fb-com-test_bo_e_prov_sopp-4_4' );
+ delete_option( 'gcmi-fb-com-fake_filter-1_2' );
+ delete_option( 'gcmi-fb-com-fake_filter-2_2' );
+ }
+
+
/**
* @group html
*/
@@ -190,6 +237,236 @@ public function provideCreateFilterData() {
];
}
+ /**
+ * @dataProvider provideFilterSlice
+ * @group ajax
+ */
+ function test_ajax_save_filters_slice( $input, $expectedResult ) {
+ $this->_setRole( 'administrator' );
+ $_POST['_ajax_nonce'] = wp_create_nonce( 'gcmi_fb_nonce' );
+ if ( array_key_exists( 'filtername', $input ) ) {
+ $_POST['filtername'] = $input['filtername'];
+ }
+ if ( array_key_exists( 'includi', $input ) ) {
+ $_POST['includi'] = $input['includi'];
+ }
+ if ( array_key_exists( 'codici', $input ) ) {
+ $_POST['codici'] = $input['codici'];
+ }
+ if ( array_key_exists( 'total', $input ) ) {
+ $_POST['total'] = $input['total'];
+ }
+ if ( array_key_exists( 'slice', $input ) ) {
+ $_POST['slice'] = $input['slice'];
+ }
+ try {
+ $this->_handleAjax( 'gcmi_fb_save_filter_slice' );
+ } catch ( WPAjaxDieContinueException $e ) {
+ }
+ $this->assertTrue( isset( $e ), 'WPAjaxDieContinueException not raised' );
+ $response = json_decode( $this->_last_response );
+
+ $this->assertEquals( $expectedResult, $response->success );
+ }
+
+ static function provideFilterSlice() {
+ return [
+ [
+ // $_POST .
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'codici' => ['C037001', 'C037002', 'C037003', 'C037005', 'C037006', 'C037007', 'C037008', 'C037009', 'C037010', 'C037011', 'C037012', 'C037013', 'C037014', 'C037015', 'C037016', 'C037017', 'C037019'],
+ 'total' => '4',
+ 'slice' => '1'
+ ],
+ // success .
+ true
+ ],
+ [
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'codici' => ['C037001', 'C037002', 'C037003', 'C037005', 'C037006', 'C037007', 'C037008', 'C037009', 'C037010', 'C037011', 'C037012', 'C037013', 'C037014', 'C037015', 'C037016', 'C037017', 'C037019'],
+ // 'total' => '4', // <--.
+ 'slice' => '1'
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'codici' => ['C037001', 'C037002', 'C037003', 'C037005', 'C037006', 'C037007', 'C037008', 'C037009', 'C037010', 'C037011', 'C037012', 'C037013', 'C037014', 'C037015', 'C037016', 'C037017', 'C037019'],
+ 'total' => '4',
+ // 'slice' => '1' // <--.
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'codici' => ['C037020', 'C037021', 'C037022', 'C037024', 'C037025', 'C037026', 'C037027', 'C037028', 'C037030', 'C037031', 'C037032', 'C037033', 'C037034', 'C037035', 'C037036', 'C037037', 'C037038'],
+ 'total' => '1', // <--.
+ 'slice' => '2'
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'codici' => ['C037020', 'C037021', 'C037022', 'C037024', 'C037025', 'C037026', 'C037027', 'C037028', 'C037030', 'C037031', 'C037032', 'C037033', 'C037034', 'C037035', 'C037036', 'C037037', 'C037038'],
+ 'total' => '4',
+ 'slice' => '2'
+ ],
+ true
+ ],
+ [
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => true, // <--.
+ 'codici' => ['C037039', 'C037040', 'C037041', 'C037042', 'C037044', 'C037045', 'C037046', 'C037047', 'C037048', 'C037050', 'C037051', 'C037052', 'C037053', 'C037054', 'C037055', 'C037056', 'C037057'],
+ 'total' => '4',
+ 'slice' => '3'
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'codici' => ['C037039', 'C037040', 'C037041', 'C037042', 'C037044', 'C037045', 'C037046', 'C037047', 'C037048', 'C037050', 'C037051', 'C037052', 'C037053', 'C037054', 'C037055', 'C037056', 'C037057'],
+ 'total' => '4',
+ 'slice' => '3'
+ ],
+ true
+ ],
+ [
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'codici' => [], //<--.
+ 'total' => '4',
+ 'slice' => '4'
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'codici' => ['C037059', 'C037060', 'C037061', 'C037062', 'C037004', 'C037018', 'C037023', 'C037029', 'C037043', 'C037049', 'C037058', 'C037801', 'C037802'],
+ 'total' => '4',
+ 'slice' => '4'
+ ],
+ true
+ ],
+ [
+ [
+ 'filtername' => 'alloptions',
+ 'includi' => 'true',
+ 'codici' => 'C037059', //<--.
+ 'total' => '4',
+ 'slice' => '4'
+ ],
+ false
+ ]
+ ];
+ }
+
+ /**
+ * @group ajax
+ * @dataProvider provideFilterNamesMulti
+ */
+ function test_ajax_create_filters_multi( $input, $expectedResult ) {
+ $this->_setRole( 'administrator' );
+ $_POST['_ajax_nonce'] = wp_create_nonce( 'gcmi_fb_nonce' );
+ if ( array_key_exists( 'filtername', $input ) ) {
+ $_POST['filtername'] = $input['filtername'];
+ }
+ if ( array_key_exists( 'includi', $input ) ) {
+ $_POST['includi'] = $input['includi'];
+ }
+ if ( array_key_exists( 'total', $input ) ) {
+ $_POST['total'] = $input['total'];
+ }
+ if ( array_key_exists( 'count', $input ) ) {
+ $_POST['count'] = $input['count'];
+ }
+ try {
+ $this->_handleAjax( 'gcmi_fb_create_filter_multi' );
+ } catch ( WPAjaxDieContinueException $e ) {
+ }
+ $this->assertTrue( isset( $e ), 'WPAjaxDieContinueException not raised' );
+ $response = json_decode( $this->_last_response );
+
+ $this->assertEquals( $expectedResult, $response->success );
+ }
+
+ function provideFilterNamesMulti() {
+ return [
+ [
+ // $_POST .
+ [
+ 'filtername' => 'test_bo_e_prov_ins', // <--.
+ 'includi' => 'true',
+ 'total' => '4',
+ 'count' => '64',
+ ],
+ // success .
+ false
+ ],
+ [
+ [
+ 'filtername' => 'test_bo_e_prov_sopp',
+ 'includi' => true, // <--.
+ 'total' => '4',
+ 'count' => '64',
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'test_bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'total' => '4',
+ 'count' => '60', // <--.
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'test_bo_e_prov_sopp',
+ 'includi' => 'true',
+ 'total' => '3', // <--.
+ 'count' => '64',
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'fake_filter',
+ 'includi' => 'true',
+ 'total' => '2',
+ 'count' => '17',
+ ],
+ false
+ ],
+ [
+ [
+ 'filtername' => 'fake_filter',
+ 'includi' => 'true',
+ 'total' => '4',
+ 'count' => '64',
+ ],
+ false
+ ]
+ ];
+ }
+
+
/**
* @group ajax
* @dataProvider provideFilterNames