2019-03-13 19:55:11 +00:00
|
|
|
/**
|
|
|
|
* Handles the version picker form.
|
|
|
|
*
|
2022-06-08 01:39:59 +00:00
|
|
|
* @package
|
2019-03-13 19:55:11 +00:00
|
|
|
*/
|
|
|
|
|
2022-06-08 01:58:25 +00:00
|
|
|
// eslint-disable-next-line no-undef
|
2022-06-08 01:39:59 +00:00
|
|
|
jQuery( function ( $ ) {
|
2018-06-06 16:26:48 +00:00
|
|
|
/**
|
2019-03-13 19:55:11 +00:00
|
|
|
* Version picker
|
2018-06-06 16:26:48 +00:00
|
|
|
*/
|
2022-06-08 01:39:59 +00:00
|
|
|
const wc_beta_tester_version_picker = {
|
2018-06-06 16:26:48 +00:00
|
|
|
/**
|
|
|
|
* Initialize Version Information click
|
|
|
|
*/
|
2022-06-08 01:39:59 +00:00
|
|
|
init() {
|
2022-10-07 17:29:02 +00:00
|
|
|
instance = this;
|
2018-06-06 16:26:48 +00:00
|
|
|
instance.new_version = undefined;
|
|
|
|
|
2022-06-08 01:39:59 +00:00
|
|
|
$( '#wcbt-modal-version-switch-confirm' ).on(
|
|
|
|
'click',
|
|
|
|
this.showConfirmVersionSwitchModal
|
|
|
|
);
|
|
|
|
$( 'input[type=radio][name=wcbt_switch_to_version]' )
|
|
|
|
.change( function () {
|
|
|
|
if ( $( this ).is( ':checked' ) ) {
|
|
|
|
instance.new_version = $( this ).val();
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.trigger( 'change' );
|
2018-06-06 16:26:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for showing/hiding version switch modal
|
2022-06-08 01:39:59 +00:00
|
|
|
*
|
2022-06-08 01:58:25 +00:00
|
|
|
* @param {Event} event
|
2018-06-06 16:26:48 +00:00
|
|
|
*/
|
2022-06-08 01:39:59 +00:00
|
|
|
showConfirmVersionSwitchModal( event ) {
|
2018-06-06 16:26:48 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if ( ! instance.new_version ) {
|
2022-06-08 01:58:25 +00:00
|
|
|
// eslint-disable-next-line no-undef
|
2018-06-06 16:26:48 +00:00
|
|
|
alert( wc_beta_tester_version_picker_params.i18n_pick_version );
|
|
|
|
} else {
|
2022-06-08 01:39:59 +00:00
|
|
|
$( this ).WCBackboneModal( {
|
2018-06-06 16:26:48 +00:00
|
|
|
template: 'wcbt-version-switch-confirm',
|
|
|
|
variable: {
|
|
|
|
new_version: instance.new_version,
|
|
|
|
},
|
2022-06-08 01:39:59 +00:00
|
|
|
} );
|
2018-06-06 16:26:48 +00:00
|
|
|
|
2022-06-08 01:39:59 +00:00
|
|
|
$( '#wcbt-submit-version-switch' ).on(
|
|
|
|
'click',
|
|
|
|
instance.submitSwitchVersionForm
|
|
|
|
);
|
2018-06-06 16:26:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit form to switch version of WooCommerce.
|
2022-06-08 01:39:59 +00:00
|
|
|
*
|
2022-06-08 01:58:25 +00:00
|
|
|
* @param {Event} event
|
2018-06-06 16:26:48 +00:00
|
|
|
*/
|
2022-06-08 01:39:59 +00:00
|
|
|
submitSwitchVersionForm( event ) {
|
2018-06-06 16:26:48 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
2019-03-13 19:55:11 +00:00
|
|
|
$( 'form[name=wcbt-select-version]' ).get( 0 ).submit();
|
2018-06-06 16:26:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
wc_beta_tester_version_picker.init();
|
2022-06-08 01:39:59 +00:00
|
|
|
} );
|