From 9dec8861c409161baafe33b2048d757f53bdbc0b Mon Sep 17 00:00:00 2001 From: HerrVigg Date: Mon, 30 May 2022 00:42:12 +0200 Subject: [PATCH] Generalize double checkboxes in QTX options Add a generic feature to handle double checkboxes in options e.g. for confirmation. The main checkbox must have: - HTML class `qtranxs_double_check` - attribute `data-double-check` giving CSS selector for associated checkbox(es) The associated checkboxes should be disabled by default. Rename `qtranslate_reset` IDs for disambiguation (x3). --- admin/js/options.js | 7 +++++++ admin/qtx_admin_options_update.php | 6 +++--- admin/qtx_import_export.php | 25 +++++++++++++++++-------- dist/options.js | 2 +- qtranslate.php | 2 +- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/admin/js/options.js b/admin/js/options.js index 0a9305b4..39a896f8 100644 --- a/admin/js/options.js +++ b/admin/js/options.js @@ -104,4 +104,11 @@ $(function () { } }); }) + + // Checkboxes with double-check has associated checkbox(es) depending on it. + $('.qtranxs_double_check').on('click', function () { + const check = $($(this).attr('data-double-check')); // There may be more than one checkbox (CSS selector). + check.prop('disabled', !$(this).prop('checked')); + check.prop('checked', false); + }); }); diff --git a/admin/qtx_admin_options_update.php b/admin/qtx_admin_options_update.php index ceb1024a..6a2035c0 100644 --- a/admin/qtx_admin_options_update.php +++ b/admin/qtx_admin_options_update.php @@ -42,7 +42,7 @@ function qtranxf_edit_config() { $original_lang = &$q_config['posted']['original_lang']; // check for action - if ( isset( $_POST['qtranslate_reset'] ) && isset( $_POST['qtranslate_reset2'] ) ) { + if ( isset( $_POST['qtranslate_reset_all'] ) && isset( $_POST['qtranslate_reset_confirm'] ) ) { $messages[] = __( 'qTranslate has been reset.', 'qtranslate' ); } elseif ( isset( $_POST['default_language'] ) ) { // TODO: remove temporary hack - restore QTS options for master dev before migration. @@ -343,7 +343,7 @@ function qtranxf_reset_config() { qtranxf_add_message( __( 'Admin notices have been reset. You will see all applicable notices on admin pages and may dismiss them again.', 'qtranslate' ) ); } - if ( ! isset( $_POST['qtranslate_reset'] ) || ! isset( $_POST['qtranslate_reset2'] ) ) { + if ( ! isset( $_POST['qtranslate_reset_all'] ) || ! isset( $_POST['qtranslate_reset_confirm'] ) ) { return; } @@ -381,7 +381,7 @@ function qtranxf_reset_config() { delete_option( 'qtranslate_versions' ); delete_option( 'qtranslate_disable_header_css' ); - if ( isset( $_POST['qtranslate_reset3'] ) ) { + if ( isset( $_POST['qtranslate_reset_terms'] ) ) { delete_option( 'qtranslate_term_name' ); } diff --git a/admin/qtx_import_export.php b/admin/qtx_import_export.php index 138fb9d9..f662c326 100644 --- a/admin/qtx_import_export.php +++ b/admin/qtx_import_export.php @@ -236,8 +236,8 @@ function qtranxf_admin_section_import_export( $request_uri ) {
@@ -253,20 +253,29 @@ function qtranxf_admin_section_import_export( $request_uri ) { -