jQuery(document).ready(function($) {
|--------------------------------------------------------------------------
| Ninja Forms THREE Upgrade App
|--------------------------------------------------------------------------
container: '#nfUpgradeApp',
test: wp.template( 'test' ),
table: wp.template( 'table' ),
legend: wp.template( 'legend' ),
headers: [ 'Title', 'Status' ],
if( 'checking' == this.step ) {
data.title = 'Form Upgrade List';
data.legend = this.tmpl.legend( {
no_issues_detected: 'No Issues Detected',
will_need_attention: 'Will Need Attention After Upgrade',
data.next = 'Start Upgrade';
_.each(this.forms, function (form) {
if ( ! form.checked ) data.readyToConvert = 0;
if( 'converting' == this.step ) {
data.title = 'Converting Forms';
_.each(this.forms, function (form) {
if ( ! form.converted ) redirectToThree = 0;
if ( form.failed ) data.showSupportLink = 1;
jQuery( window ).unbind( 'beforeunload' );
window.location.href = nfThreeUpgrade.redirectURL;
jQuery( this.container ).html( this.tmpl.table( data ) );
var form = this.forms[ this.formCheckPointer ] || null;
if( form ) this.checkForm( form );
checkForm: function( form ) {
$.post( ajaxurl, { action: 'ninja_forms_upgrade_check', formID: form.id }, function( response ) {
var icon = ( response.canUpgrade ) ? '' : 'flag';
var flagged = ( response.canUpgrade ) ? 0 : 1;
that.updateForm( form.id, 'title', response.title );
that.updateForm( form.id, 'icon', icon );
that.updateForm( form.id, 'checked', true );
that.updateForm( form.id, 'flagged', flagged );
updateForm: function( formID, property, value ) {
_.each( this.forms, function( form ) {
if( formID != form.id ) return;
form[ property ] = value;
_.each( nfThreeUpgrade.forms, function( formID ) {
jQuery( '#nfUpgradeApp' ).on( 'click','.js-nfUpgrade-startConversion', function() {
that.startConversion( that );
startConversion: function( app ) {
// Add a notice if the user tries to navigate away during conversion.
jQuery( window ).bind( 'beforeunload', function(){
return 'You have unsaved changes.';
$.post( ajaxurl, { nf2to3: 1, action: 'ninja_forms_ajax_migrate_database', security: nfThreeUpgrade.nonce }, function( response ) {
$.post( ajaxurl, { action: 'nfThreeUpgrade_GetSerializedFields' }, function( fieldsExport ) {
$.post(ajaxurl, { nf2to3: 1, fields: fieldsExport.serialized, action: 'ninja_forms_ajax_import_fields', security: nfThreeUpgrade.nonce }, function ( fieldsImport ) {
convertForms: function() {
var form = this.forms[ this.formConvertPointer ] || null;
if( form ) this.convertForm( form );
this.formConvertPointer++;
convertForm: function( form ) {
console.log( 'Converting...' );
$.post(ajaxurl, {action: 'nfThreeUpgrade_GetSerializedForm', formID: form.id}, function ( formExport ) {
$.post(ajaxurl, { nf2to3: 1, action: 'ninja_forms_ajax_import_form', security: nfThreeUpgrade.nonce, formID: form.id, import: formExport.serialized, flagged: form.flagged }, function ( formImport ) {
}, 'json').fail( function() {