Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../assets/js
File: admin-settings.js
jQuery(document).ready(function($) {
[0] Fix | Delete
var working = false;
[1] Fix | Delete
var message, container, messageBox, deleteInput, deleteMsgs, buttons, confirm, cancel, lineBreak;
[2] Fix | Delete
container = document.createElement( 'div' );
[3] Fix | Delete
messageBox = document.createElement( 'p' );
[4] Fix | Delete
deleteInput = document.createElement( 'input' );
[5] Fix | Delete
deleteInput.type = 'text';
[6] Fix | Delete
deleteInput.id = 'confirmDeleteInput';
[7] Fix | Delete
buttons = document.createElement( 'div' );
[8] Fix | Delete
buttons.style.marginTop = '10px';
[9] Fix | Delete
buttons.style.backgroundColor = '#f4f5f6';
[10] Fix | Delete
confirm = document.createElement( 'div' );
[11] Fix | Delete
confirm.style.padding = '8px';
[12] Fix | Delete
confirm.style.cursor = 'default';
[13] Fix | Delete
confirm.style.backgroundColor = '#d9534f';
[14] Fix | Delete
confirm.style.borderColor = '#d9534f';
[15] Fix | Delete
confirm.style.fontSize = '14pt';
[16] Fix | Delete
confirm.style.fontWeight = 'bold';
[17] Fix | Delete
confirm.style.color = '#ffffff';
[18] Fix | Delete
confirm.style.borderRadius = '4px';
[19] Fix | Delete
cancel = document.createElement( 'div' );
[20] Fix | Delete
cancel.style.padding = '8px';
[21] Fix | Delete
cancel.style.cursor = 'default';
[22] Fix | Delete
cancel.style.backgroundColor = '#5bc0de';
[23] Fix | Delete
cancel.style.borderColor = '#5bc0de';
[24] Fix | Delete
cancel.style.fontSize = '14pt';
[25] Fix | Delete
cancel.style.fontWeight = 'bold';
[26] Fix | Delete
cancel.style.color = '#ffffff';
[27] Fix | Delete
cancel.style.borderRadius = '4px';
[28] Fix | Delete
lineBreak = document.createElement( 'br' );
[29] Fix | Delete
container.classList.add( 'message' );
[30] Fix | Delete
messageBox.innerHTML += 'This will DELETE all forms, form submissions,' +
[31] Fix | Delete
' and deactivate Ninja Forms';
[32] Fix | Delete
[33] Fix | Delete
messageBox.appendChild( lineBreak );
[34] Fix | Delete
messageBox.innerHTML += '<br>Type <span style="color:red;">DELETE</span>' +
[35] Fix | Delete
' to' +
[36] Fix | Delete
' confirm';
[37] Fix | Delete
[38] Fix | Delete
container.appendChild( messageBox );
[39] Fix | Delete
container.appendChild( deleteInput );
[40] Fix | Delete
container.appendChild( lineBreak );
[41] Fix | Delete
deleteMsgs = document.createElement( 'div' );
[42] Fix | Delete
deleteMsgs.id = 'progressMsg';
[43] Fix | Delete
deleteMsgs.style.display = 'none';
[44] Fix | Delete
deleteMsgs.style.color = 'red';
[45] Fix | Delete
container.appendChild( deleteMsgs );
[46] Fix | Delete
confirm.innerHTML = 'Delete';
[47] Fix | Delete
confirm.classList.add( 'confirm', 'nf-button', 'primary' );
[48] Fix | Delete
confirm.style.float = 'left';
[49] Fix | Delete
cancel.innerHTML = 'Cancel';
[50] Fix | Delete
cancel.classList.add( 'cancel', 'nf-button', 'secondary', 'cancel-delete-all' );
[51] Fix | Delete
cancel.style.float = 'right';
[52] Fix | Delete
buttons.appendChild( confirm );
[53] Fix | Delete
buttons.appendChild( cancel );
[54] Fix | Delete
buttons.classList.add( 'buttons' );
[55] Fix | Delete
container.appendChild( buttons );
[56] Fix | Delete
message = document.createElement( 'div' );
[57] Fix | Delete
message.appendChild( container );
[58] Fix | Delete
[59] Fix | Delete
var downgradeContainer, downgradeTitle, downgradeWarning, downgradeCTA, downgradeInput;
[60] Fix | Delete
downgradeInput = document.createElement( 'input' );
[61] Fix | Delete
downgradeInput.setAttribute( 'type', 'text' );
[62] Fix | Delete
downgradeInput.id = 'downgradeConfirmInput';
[63] Fix | Delete
downgradeInput.style.marginBottom = '15px';
[64] Fix | Delete
downgradeInput.style.padding = '7px';
[65] Fix | Delete
downgradeInput.style.border = '1px solid #D3D3D3';
[66] Fix | Delete
downgradeInput.style.width = '100%';
[67] Fix | Delete
downgradeInput.style.height = '3em';
[68] Fix | Delete
downgradeCTA = document.createElement( 'p' );
[69] Fix | Delete
downgradeCTA.innerHTML = nfAdmin.i18n.downgradeConfirmMessage;
[70] Fix | Delete
downgradeWarning = document.createElement( 'p' );
[71] Fix | Delete
downgradeWarning.innerHTML = nfAdmin.i18n.downgradeWarningMessage;
[72] Fix | Delete
downgradeWarning.style.color = 'red';
[73] Fix | Delete
downgradeTitle = document.createElement( 'h3' );
[74] Fix | Delete
downgradeTitle.innerHTML = nfAdmin.i18n.downgradeMessage;
[75] Fix | Delete
downgradeContainer = document.createElement( 'div' );
[76] Fix | Delete
downgradeContainer.appendChild( downgradeTitle );
[77] Fix | Delete
downgradeContainer.appendChild( downgradeWarning );
[78] Fix | Delete
downgradeContainer.appendChild( downgradeCTA );
[79] Fix | Delete
downgradeContainer.appendChild( downgradeInput );
[80] Fix | Delete
[81] Fix | Delete
[82] Fix | Delete
[83] Fix | Delete
// set up delete model with all the elements created above
[84] Fix | Delete
deleteAllDataModal = new jBox( 'Modal', {
[85] Fix | Delete
width: 450,
[86] Fix | Delete
addClass: 'dashboard-modal',
[87] Fix | Delete
overlay: true,
[88] Fix | Delete
closeOnClick: 'body'
[89] Fix | Delete
} );
[90] Fix | Delete
[91] Fix | Delete
deleteAllDataModal.setContent( message.innerHTML );
[92] Fix | Delete
deleteAllDataModal.setTitle( 'Delete All Ninja Forms Data?' );
[93] Fix | Delete
[94] Fix | Delete
// add event listener for cancel button
[95] Fix | Delete
var btnCancel = deleteAllDataModal.container[0].getElementsByClassName('cancel')[0];
[96] Fix | Delete
btnCancel.addEventListener('click', function() {
[97] Fix | Delete
if( ! working ) {
[98] Fix | Delete
deleteAllDataModal.close();
[99] Fix | Delete
}
[100] Fix | Delete
} );
[101] Fix | Delete
[102] Fix | Delete
var doAllDataDeletions = function( formIndex ) {
[103] Fix | Delete
var last_form = 0;
[104] Fix | Delete
// Gives the user confidence things are happening
[105] Fix | Delete
$( '#progressMsg' ).html( 'Deleting submissions for '
[106] Fix | Delete
+ nfAdmin.forms[ formIndex ].title + "" + ' ( ID: '
[107] Fix | Delete
+ nfAdmin.forms[ formIndex ].id + ' )' );
[108] Fix | Delete
$( '#progressMsg').show();
[109] Fix | Delete
// notify php this is the last one so it delete data and deactivate NF
[110] Fix | Delete
if( formIndex === nfAdmin.forms.length - 1 ) {
[111] Fix | Delete
last_form = 1;
[112] Fix | Delete
}
[113] Fix | Delete
// do this deletion thang
[114] Fix | Delete
$.post(
[115] Fix | Delete
nfAdmin.ajax_url,
[116] Fix | Delete
{
[117] Fix | Delete
'action': 'nf_delete_all_data',
[118] Fix | Delete
'form': nfAdmin.forms[ formIndex ].id,
[119] Fix | Delete
'security': nfAdmin.nonce,
[120] Fix | Delete
'last_form': last_form
[121] Fix | Delete
}
[122] Fix | Delete
).then (function( response ) {
[123] Fix | Delete
formIndex = formIndex + 1;
[124] Fix | Delete
response = JSON.parse( response );
[125] Fix | Delete
[126] Fix | Delete
if(response.data.hasOwnProperty('errors')) {
[127] Fix | Delete
var errors = response.data.errors;
[128] Fix | Delete
var errorMsg = '';
[129] Fix | Delete
[130] Fix | Delete
if (Array.isArray(errors)) {
[131] Fix | Delete
errors.forEach(function(error) {
[132] Fix | Delete
errors += error + "\n";
[133] Fix | Delete
})
[134] Fix | Delete
} else {
[135] Fix | Delete
errors = errors;
[136] Fix | Delete
}
[137] Fix | Delete
console.log('Delete All Data Errors: ', errors);
[138] Fix | Delete
alert(errors);
[139] Fix | Delete
return null;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
// we expect success and then move to the next form
[143] Fix | Delete
if( response.data.success ) {
[144] Fix | Delete
if( formIndex < nfAdmin.forms.length ) {
[145] Fix | Delete
doAllDataDeletions( formIndex )
[146] Fix | Delete
} else {
[147] Fix | Delete
// if we're finished deleting data then redirect to plugins
[148] Fix | Delete
if( response.data.plugin_url ) {
[149] Fix | Delete
window.location = response.data.plugin_url;
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
} ).fail( function( xhr, status, error ) {
[154] Fix | Delete
// writes error messages to console to help us debug
[155] Fix | Delete
console.log( xhr.status + ' ' + error + '\r\n' +
[156] Fix | Delete
'There was an error deleting submissions for '
[157] Fix | Delete
+ nfAdmin.forms[ formIndex ].title );
[158] Fix | Delete
});
[159] Fix | Delete
};
[160] Fix | Delete
// Add event listener for delete button
[161] Fix | Delete
var btnDelete = deleteAllDataModal.container[0].getElementsByClassName('confirm')[0];
[162] Fix | Delete
btnDelete.addEventListener('click', function() {
[163] Fix | Delete
var confirmVal = $('#confirmDeleteInput').val();
[164] Fix | Delete
[165] Fix | Delete
if (! working) {
[166] Fix | Delete
working = true;
[167] Fix | Delete
// Gotta type DELETE to play
[168] Fix | Delete
if ('DELETE' === confirmVal) {
[169] Fix | Delete
this.style.backgroundColor = '#9f9f9f';
[170] Fix | Delete
this.style.borderColor = '#3f3f3f';
[171] Fix | Delete
[172] Fix | Delete
var cancelBtn = $( '.cancel-delete-all' );
[173] Fix | Delete
cancelBtn.css( 'backgroundColor', '#9f9f9f' );
[174] Fix | Delete
cancelBtn.css( 'borderColor', '#3f3f3f');
[175] Fix | Delete
[176] Fix | Delete
// this is the first one, so we'll start with index 0
[177] Fix | Delete
doAllDataDeletions(0);
[178] Fix | Delete
} else {
[179] Fix | Delete
deleteAllDataModal.close();
[180] Fix | Delete
working = false;
[181] Fix | Delete
}
[182] Fix | Delete
}
[183] Fix | Delete
} );
[184] Fix | Delete
[185] Fix | Delete
$( '.js-delete-saved-field' ).click( function(){
[186] Fix | Delete
[187] Fix | Delete
var that = this;
[188] Fix | Delete
[189] Fix | Delete
var data = {
[190] Fix | Delete
'action': 'nf_delete_saved_field',
[191] Fix | Delete
'field': {
[192] Fix | Delete
id: $( that ).data( 'id' )
[193] Fix | Delete
},
[194] Fix | Delete
'security': nfAdmin.nonce
[195] Fix | Delete
};
[196] Fix | Delete
[197] Fix | Delete
$.post( nfAdmin.ajax_url, data )
[198] Fix | Delete
.done( function( response ) {
[199] Fix | Delete
$( that ).closest( 'tr').fadeOut().remove();
[200] Fix | Delete
});
[201] Fix | Delete
});
[202] Fix | Delete
[203] Fix | Delete
// Start building our downgrade model.
[204] Fix | Delete
jQuery( '#nfDowngrade' ).click( function( e ) {
[205] Fix | Delete
var data = {
[206] Fix | Delete
class: 'nfDowngradeModal',
[207] Fix | Delete
closeOnClick: 'body',
[208] Fix | Delete
closeOnEsc: true,
[209] Fix | Delete
// TODO: Maybe this should be build using DOM node construction?
[210] Fix | Delete
content: downgradeContainer.innerHTML,
[211] Fix | Delete
btnPrimary: {
[212] Fix | Delete
text: nfAdmin.i18n.downgradeButtonPrimary,
[213] Fix | Delete
class: 'nfDowngradeButtonPrimary',
[214] Fix | Delete
callback: function( e ) {
[215] Fix | Delete
// If our "Downgrade" button does not have have an attribute of disabled...
[216] Fix | Delete
if( 'disabled' !== $('.nfDowngradeButtonPrimary').prop( 'disabled' ) ){
[217] Fix | Delete
// ...get the url...
[218] Fix | Delete
var url = window.location.href;
[219] Fix | Delete
// ...split the url based on the question mark from the query string...
[220] Fix | Delete
url = url.split( '?' );
[221] Fix | Delete
// build the downgrade url and redirect the user.
[222] Fix | Delete
url[0] = url[0] + '?page=ninja-forms&nf-switcher=rollback&security=' + nfAdmin.nonce;
[223] Fix | Delete
window.location.replace( url[0] );
[224] Fix | Delete
}
[225] Fix | Delete
}
[226] Fix | Delete
},
[227] Fix | Delete
btnSecondary: {
[228] Fix | Delete
text: nfAdmin.i18n.downgradeButtonSecondary,
[229] Fix | Delete
class: 'nfDowngradeButtonSecondary',
[230] Fix | Delete
callback: function( e ) {
[231] Fix | Delete
// Close the modal if this button is clicked.
[232] Fix | Delete
downgradeModel.toggleModal( false );
[233] Fix | Delete
}
[234] Fix | Delete
},
[235] Fix | Delete
useProgressBar: false,
[236] Fix | Delete
};
[237] Fix | Delete
var downgradeModel = new NinjaModal( data );
[238] Fix | Delete
// Style and add the disabled tag by default.
[239] Fix | Delete
$('.nfDowngradeButtonPrimary').css( 'background', '#ccc' );
[240] Fix | Delete
$('.nfDowngradeButtonPrimary').css( 'border', '#ccc 1px solid' );
[241] Fix | Delete
$('.nfDowngradeButtonPrimary').prop( 'disabled', 'disabled' );
[242] Fix | Delete
[243] Fix | Delete
// Listen to our input and...
[244] Fix | Delete
$('#downgradeConfirmInput').on( 'keyup', function(){
[245] Fix | Delete
// ...if DOWNGRADE is typed then...
[246] Fix | Delete
if( 'DOWNGRADE' == $('#downgradeConfirmInput').val() ) {
[247] Fix | Delete
// ...apply our blue styling to button and remove disabled attribute.
[248] Fix | Delete
$('.nfDowngradeButtonPrimary').css( 'background', '#1EA9EA' );
[249] Fix | Delete
$('.nfDowngradeButtonPrimary').css( 'border', '#1EA9EA 1px solid' );
[250] Fix | Delete
$('.nfDowngradeButtonPrimary').prop( 'disabled','' );
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
// ...if DOWNGRADE is not typed then...
[254] Fix | Delete
if( 'DOWNGRADE' !== $('#downgradeConfirmInput').val() ) {
[255] Fix | Delete
// ...set styling back to default and reapply the disabled prop.
[256] Fix | Delete
$('.nfDowngradeButtonPrimary').css( 'background', '#ccc' );
[257] Fix | Delete
$('.nfDowngradeButtonPrimary').css( 'border', '#ccc 1px solid' );
[258] Fix | Delete
$('.nfDowngradeButtonPrimary').prop( 'disabled', 'disabled' );
[259] Fix | Delete
}
[260] Fix | Delete
})
[261] Fix | Delete
});
[262] Fix | Delete
[263] Fix | Delete
$( document ).on( 'click', '#delete_on_uninstall', function( e ) {
[264] Fix | Delete
deleteAllDataModal.open();
[265] Fix | Delete
} );
[266] Fix | Delete
[267] Fix | Delete
$( document ).on( 'click', '.nf-delete-on-uninstall-yes', function( e ) {
[268] Fix | Delete
e.preventDefault();
[269] Fix | Delete
$( "#delete_on_uninstall" ).attr( 'checked', true );
[270] Fix | Delete
[271] Fix | Delete
} );
[272] Fix | Delete
[273] Fix | Delete
// If we're allowed to track site data...
[274] Fix | Delete
if ( '1' == nfAdmin.allow_telemetry ) {
[275] Fix | Delete
// Show the optout button.
[276] Fix | Delete
$( '#nfTelOptin' ).addClass( 'hidden' );
[277] Fix | Delete
$( '#nfTelOptout' ).removeClass( 'hidden' );
[278] Fix | Delete
} // Otherwise...
[279] Fix | Delete
else {
[280] Fix | Delete
// Show the optin button.
[281] Fix | Delete
$( '#nfTelOptout' ).addClass( 'hidden' );
[282] Fix | Delete
$( '#nfTelOptin' ).removeClass( 'hidden' );
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
// If optin is clicked...
[286] Fix | Delete
$( '#nfTelOptin' ).click( function( e ) {
[287] Fix | Delete
// Hide the button.
[288] Fix | Delete
$( '#nfTelOptin' ).addClass( 'hidden' );
[289] Fix | Delete
$( '#nfTelSpinner' ).css( 'display', 'inline-block' );
[290] Fix | Delete
// Hit AJAX endpoint and opt-in.
[291] Fix | Delete
$.post( ajaxurl, { action: 'nf_optin', ninja_forms_opt_in: 1 },
[292] Fix | Delete
function( response ) {
[293] Fix | Delete
$( '#nfTelOptout' ).removeClass( 'hidden' );
[294] Fix | Delete
$( '#nfTelSpinner' ).css( 'display', 'none' );
[295] Fix | Delete
} );
[296] Fix | Delete
} );
[297] Fix | Delete
[298] Fix | Delete
// If optout is clicked...
[299] Fix | Delete
$( '#nfTelOptout' ).click( function( e ) {
[300] Fix | Delete
// Hide the button.
[301] Fix | Delete
$( '#nfTelOptout' ).addClass( 'hidden' );
[302] Fix | Delete
$( '#nfTelSpinner' ).css( 'display', 'inline-block' );
[303] Fix | Delete
// Hit AJAX endpoint and opt-out.
[304] Fix | Delete
$.post( ajaxurl, { action: 'nf_optin', ninja_forms_opt_in: 0 },
[305] Fix | Delete
function( response ) {
[306] Fix | Delete
$( '#nfTelOptin' ).removeClass( 'hidden' );
[307] Fix | Delete
$( '#nfTelSpinner' ).css( 'display', 'none' );
[308] Fix | Delete
} );
[309] Fix | Delete
} );
[310] Fix | Delete
[311] Fix | Delete
jQuery( '#nfTrashExpiredSubmissions' ).click( function( e ) {
[312] Fix | Delete
var settings = {
[313] Fix | Delete
content: '<p>' + nfAdmin.i18n.trashExpiredSubsMessage + '</p>',
[314] Fix | Delete
btnPrimaryText: nfAdmin.i18n.trashExpiredSubsButtonPrimary,
[315] Fix | Delete
btnSecondaryText: nfAdmin.i18n.trashExpiredSubsButtonSecondary,
[316] Fix | Delete
batch_type: 'expired_submission_cleanup',
[317] Fix | Delete
// extraData: [ 'test1', 'test2', 'test3' ]
[318] Fix | Delete
}
[319] Fix | Delete
new NinjaBatchProcessor( settings );
[320] Fix | Delete
});
[321] Fix | Delete
[322] Fix | Delete
jQuery( '#nfRemoveMaintenanceMode' ).click( function( e ) {
[323] Fix | Delete
[324] Fix | Delete
var that = this;
[325] Fix | Delete
[326] Fix | Delete
jQuery( this ).addClass( 'disabled' ).attr( 'disabled', 'disabled' );
[327] Fix | Delete
jQuery( '#nf_maintenanceModeProgress' ).html("<strong>Removing Maintenance Mode...</strong>" );
[328] Fix | Delete
jQuery( '#nf_maintenanceModeProgress' ).fadeIn( 1 );
[329] Fix | Delete
[330] Fix | Delete
var data = {
[331] Fix | Delete
action: 'nf_remove_maintenance_mode',
[332] Fix | Delete
security: nf_settings.nonce,
[333] Fix | Delete
};
[334] Fix | Delete
$.post(
[335] Fix | Delete
nf_settings.ajax_url,
[336] Fix | Delete
data
[337] Fix | Delete
).then (function( response ) {
[338] Fix | Delete
response = JSON.parse( response );
[339] Fix | Delete
// if there are errors then, console it out
[340] Fix | Delete
if( response.data.errors ) {
[341] Fix | Delete
console.log( response.data.errors );
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
jQuery( that ).removeClass( 'disabled' ).removeAttr( 'disabled' );
[345] Fix | Delete
jQuery( '#nf_maintenanceModeProgress' ).html("<strong>Done.</strong>" );
[346] Fix | Delete
jQuery( '#nf_maintenanceModeProgress' ).fadeOut( 600 );
[347] Fix | Delete
[348] Fix | Delete
} ).fail( function( xhr, status, error ) {
[349] Fix | Delete
// writes error messages to console to help us debug
[350] Fix | Delete
console.log( xhr.status + ' ' + error + '\r\n' +
[351] Fix | Delete
'There was an error resetting maintenance mode' );
[352] Fix | Delete
});
[353] Fix | Delete
[354] Fix | Delete
} );
[355] Fix | Delete
});
[356] Fix | Delete
[357] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function