diff --git a/plugins/woocommerce-beta-tester/assets/js/version-picker.js b/plugins/woocommerce-beta-tester/assets/js/version-picker.js new file mode 100644 index 00000000000..64b7604d76c --- /dev/null +++ b/plugins/woocommerce-beta-tester/assets/js/version-picker.js @@ -0,0 +1,60 @@ +jQuery(function( $ ) { + + //var instance = undefined; + /** + * Version information + */ + var wc_beta_tester_version_picker = { + + /** + * Initialize Version Information click + */ + init: function() { + instance = this; + instance.new_version = undefined; + + $( '#wcbt-modal-version-switch-confirm' ) + .on( 'click', this.showConfirmVersionSwitchModal ); + $( 'input[type=radio][name=wcbt_switch_to_version]' ).change(function() { + instance.new_version = this.value; + }); + + + }, + + /** + * Handler for showing/hiding version switch modal + */ + showConfirmVersionSwitchModal: function( event ) { + event.preventDefault(); + + if ( ! instance.new_version ) { + alert( wc_beta_tester_version_picker_params.i18n_pick_version ); + } else { + $( this ).WCBackboneModal({ + template: 'wcbt-version-switch-confirm', + variable: { + new_version: instance.new_version, + }, + }); + + $( '#wcbt-submit-version-switch' ) + .on( 'click', instance.submitSwitchVersionForm ); + } + + + }, + + /** + * Submit form to switch version of WooCommerce. + */ + submitSwitchVersionForm: function( event ) { + event.preventDefault(); + + $( 'form[name=wcbt-select-version]' ).get(0).submit(); + }, + }; + + wc_beta_tester_version_picker.init(); + +}); diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-assets.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-assets.php index 3e1b70d919c..6b784ac9c53 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-assets.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-admin-assets.php @@ -29,6 +29,7 @@ class WC_Beta_Tester_Admin_Assets { wp_enqueue_style( 'woocommerce_admin_styles' ); wp_register_script( 'wc-beta-tester-version-info', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-information' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION ); + wp_register_script( 'wc-beta-tester-version-picker', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-picker' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION ); $version = WC_VERSION; @@ -41,7 +42,16 @@ class WC_Beta_Tester_Admin_Assets { ) ); + wp_localize_script( + 'wc-beta-tester-version-picker', + 'wc_beta_tester_version_picker_params', + array( + 'i18n_pick_version' => __( 'Please pick a WooCommerce version.', 'woocommerce-beta-tester' ), + ) + ); + wp_enqueue_script( 'wc-beta-tester-version-info' ); + wp_enqueue_script( 'wc-beta-tester-version-picker' ); } } diff --git a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-version-picker.php b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-version-picker.php index 3f79ce687f5..5f52a5f0667 100644 --- a/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-version-picker.php +++ b/plugins/woocommerce-beta-tester/includes/class-wc-beta-tester-version-picker.php @@ -40,20 +40,6 @@ class WC_Beta_Tester_Version_Picker { array( $this, 'select_versions_form_html' ) ); } - /** - * - */ - public function admin_scripts() { - wp_localize_script( - 'wc-beta-tester-version-info', - 'wc_beta_tester_version_info_params', - array( - 'version' => $version, - 'description' => WC_Beta_Tester::instance()->get_version_information( $version ), - ) - ); - } - /** * Return HTML code representation of list of WooCommerce versions for the selected channel. * @@ -78,7 +64,7 @@ class WC_Beta_Tester_Version_Picker { foreach ( $tags as $tag_version ) { $versions_html .= '