Commit 461bd92c authored by Kenneth Hall's avatar Kenneth Hall Committed by KR Moorhouse

Create "Are you sure" modal for downgrading to 2.9.x

parent 1073bcb2
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
......@@ -58,6 +58,30 @@ jQuery(document).ready(function($) {
message = document.createElement( 'div' );
message.appendChild( container );
var downgradeContainer, downgradeTitle, downgradeWarning, downgradeCTA, downgradeInput;
downgradeInput = document.createElement( 'input' );
downgradeInput.setAttribute( 'type', 'text' );
downgradeInput.id = 'downgradeConfirmInput';
downgradeInput.style.marginBottom = '15px';
downgradeInput.style.padding = '7px';
downgradeInput.style.border = '1px solid #D3D3D3';
downgradeInput.style.width = '100%';
downgradeInput.style.height = '3em';
downgradeCTA = document.createElement( 'p' );
downgradeCTA.innerHTML = nf_settings.i18n.downgradeConfirmMessage;
downgradeWarning = document.createElement( 'p' );
downgradeWarning.innerHTML = nf_settings.i18n.downgradeWarningMessage;
downgradeWarning.style.color = 'red';
downgradeTitle = document.createElement( 'h3' );
downgradeTitle.innerHTML = nf_settings.i18n.downgradeMessage;
downgradeContainer = document.createElement( 'div' );
downgradeContainer.appendChild( downgradeTitle );
downgradeContainer.appendChild( downgradeWarning );
downgradeContainer.appendChild( downgradeCTA );
downgradeContainer.appendChild( downgradeInput );
// set up delete model with all the elements created above
deleteAllDataModal = new jBox( 'Modal', {
width: 450,
......@@ -161,13 +185,65 @@ jQuery(document).ready(function($) {
});
});
$( '#nfRollback' ).on( 'click', function( event ){
var rollback = confirm( nf_settings.i18n.rollbackConfirm );
if( ! rollback ){
event.preventDefault();
}
});
// Start building our downgrade model.
jQuery( '#nfDowngrade' ).click( function( e ) {
var data = {
class: 'nfDowngradeModal',
closeOnClick: 'body',
closeOnEsc: true,
// TODO: Maybe this should be build using DOM node construction?
content: downgradeContainer.innerHTML,
btnPrimary: {
text: nf_settings.i18n.downgradeButtonPrimary,
class: 'nfDowngradeButtonPrimary',
callback: function( e ) {
// If our "Downgrade" button does not have have an attribute of disabled...
if( 'disabled' !== $('.nfDowngradeButtonPrimary').attr( 'disabled' ) ){
// ...get the url...
var url = window.location.href;
// ...split the url based on the question mark from the query string...
url = url.split( '?' );
// build the downgrade url and redirect the user.
url[0] = url[0] + '?page=ninja-forms&nf-switcher=rollback';
window.location.replace( url[0] );
}
}
},
btnSecondary: {
text: nf_settings.i18n.downgradeButtonSecondary,
class: 'nfDowngradeButtonSecondary',
callback: function( e ) {
// Close the modal if this button is clicked.
downgradeModel.toggleModal( false );
}
},
useProgressBar: false,
};
var downgradeModel = new NinjaModal( data );
// Style and add the disabled tag by default.
$('.nfDowngradeButtonPrimary').css( 'background', '#ccc' );
$('.nfDowngradeButtonPrimary').css( 'border', '#ccc 1px solid' );
$('.nfDowngradeButtonPrimary').attr( 'disabled', true );
// Listen to our input and...
$('#downgradeConfirmInput').on( 'keyup', function(){
// ...if DOWNGRADE is typed then...
if( 'DOWNGRADE' == $('#downgradeConfirmInput').val() ) {
// ...apply our blue styling to button and remove disabled attribute.
$('.nfDowngradeButtonPrimary').css( 'background', '#1EA9EA' );
$('.nfDowngradeButtonPrimary').css( 'border', '#1EA9EA 1px solid' );
$('.nfDowngradeButtonPrimary').removeAttr( 'disabled' );
}
// ...if DOWNGRADE is not typed then...
if( 'DOWNGRADE' !== $('#downgradeConfirmInput').val() ) {
// ...set styling back to default and reapply the disabled prop.
$('.nfDowngradeButtonPrimary').css( 'background', '#ccc' );
$('.nfDowngradeButtonPrimary').css( 'border', '#ccc 1px solid' );
$('.nfDowngradeButtonPrimary').prop( 'disabled', true );
}
})
});
$( document ).on( 'click', '#delete_on_uninstall', function( e ) {
deleteAllDataModal.open();
......
......@@ -161,7 +161,11 @@ final class NF_Admin_Menus_Settings extends NF_Abstracts_Submenu
'nonce' => wp_create_nonce( "ninja_forms_settings_nonce" ),
'batch_nonce' => wp_create_nonce( 'ninja_forms_batch_nonce' ),
'i18n' => array(
'rollbackConfirm' => __( 'Are you sure you want to rollback?', 'ninja-forms' ),
'downgradeMessage' => __( 'Are you sure you want to downgrade?', 'ninja-forms' ),
'downgradeWarningMessage' => __( 'You WILL lose any forms or submissions created on this version of Ninja Forms.', 'ninja-forms' ),
'downgradeConfirmMessage' => __( 'Type ', 'ninja-forms' ) . '<span style="color: red";>' . 'DOWNGRADE' . "</span>" . __( ' to confirm.', 'ninja-forms' ),
'downgradeButtonPrimary' => __( 'Downgrade', 'ninja-forms'),
'downgradeButtonSecondary' => __( 'Cancel', 'ninja-forms' ),
'trashExpiredSubsMessage' => __( 'Are you sure you want to trash all expired submissions?', 'ninja-forms' ),
'trashExpiredSubsButtonPrimary' => __( 'Trash', 'ninja-forms' ),
'trashExpiredSubsButtonSecondary' => __( 'Cancel', 'ninja-forms' ),
......
......@@ -97,12 +97,12 @@ return apply_filters( 'ninja_forms_plugin_settings_advanced', array(
|--------------------------------------------------------------------------
*/
'rollback' => array(
'id' => 'rollback',
'downgrade' => array(
'id' => 'downgrade',
'type' => 'html',
'html' => '<a id="nfRollback" href="' . admin_url( 'admin.php?page=ninja-forms&nf-switcher=rollback' ) . '" class="button">' . __( 'Rollback', 'ninja-forms' ) . '</a>',
'label' => __( 'Rollback to v2.9.x', 'ninja-forms' ),
'desc' => __( 'Rollback to the most recent 2.9.x release.', 'ninja-forms' ) . '<br /><div style="color: red">' . __( 'IMPORTANT: All 3.0 data will be removed.', 'ninja-forms' ) . '<br />' . __( 'Please export any forms or submissions you do not want to be lost during this process.', 'ninja-forms' ) . '</div>',
'html' => '<div id="nfDowngrade" class="button">' . __( 'Downgrade', 'ninja-forms' ) . '</div>',
'label' => __( 'Downgrade to v2.9.x', 'ninja-forms' ),
'desc' => __( 'Downgrade to the most recent 2.9.x release.', 'ninja-forms' ) . '<br /><div style="color: red">' . __( 'IMPORTANT: All 3.0 data will be removed.', 'ninja-forms' ) . '<br />' . __( 'Please export any forms or submissions you do not want to be lost during this process.', 'ninja-forms' ) . '</div>',
),
'trash_expired_submissions' => array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment