', {id: 'itsec-logs-cache-id-' + id} );
$div.html( jQuery( '#itsec-log-details-container' ).html() );
jQuery( '#itsec-logs-cache' ).append( $div );
},
closeModal: function( e ) {
if ( 'undefined' !== typeof e ) {
e.preventDefault();
// For keyup events, only process esc
if ( 'keyup' === e.type && 27 !== e.which ) {
return;
}
}
try {
if ( '' != itsecLogsPage.originalHREF ) {
window.history.replaceState( {}, '', itsecLogsPage.originalHREF );
}
} catch( err ) {}
jQuery( '.itsec-modal-background' ).fadeOut();
jQuery( '#itsec-log-details-container' ).fadeOut( 200 );
jQuery( 'body' ).removeClass( 'itsec-modal-open' );
},
migrateOldLogs: function() {
var $status = jQuery( '#old-logs-migration-status' );
if ( $status.length < 1 ) {
return;
}
var message = itsec_page.translations.log_migration_started.replace( '%1$s', '

' );
$status.append( '
' );
itsecLogsPage.sendMigrationRequest();
},
handleMigrationCallback: function( results ) {
var clearStatus = false;
if ( results.response && results.response.length ) {
if ( 'incomplete' === results.response ) {
if ( 'undefined' === typeof itsecLogsPage.callCount ) {
itsecLogsPage.callCount = 1;
}
itsecLogsPage.callCount++;
if ( 0 === itsecLogsPage.callCount % 10 ) {
// Every 10 requests, delay a bit to prevent from slamming the server.
setTimeout( itsecLogsPage.sendMigrationRequest, 5000 );
} else {
itsecLogsPage.sendMigrationRequest();
}
return;
}
jQuery('#old-logs-migration-status').html( results.response );
} else {
clearStatus = true;
}
if ( results.errors.length > 0 ) {
if ( 'undefined' === typeof itsecLogsPage.errorCount ) {
itsecLogsPage.errorCount = 0;
}
itsecLogsPage.errorCount++;
if ( itsecLogsPage.errorCount < 10 ) {
// Keep retrying until we reach 10 errors, but delay a bit before retrying.
setTimeout( itsecLogsPage.sendMigrationRequest, 5000 );
return;
}
}
if ( clearStatus ) {
jQuery('#old-logs-migration-status').html( '' );
}
if ( results.errors.length > 0 ) {
var message = '
' + itsec_page.translations.log_migration_failed + '
';
jQuery('#old-logs-migration-status').append( message );
}
if ( results.warnings.length > 0 ) {
jQuery.each( results.warnings, function( index, warning ) {
message = '
';
jQuery('#old-logs-migration-status').append( message );
} );
}
},
sendMigrationRequest: function() {
itsecUtil.sendAJAXRequest( 'logs', 'handle_logs_migration', {}, itsecLogsPage.handleMigrationCallback, itsec_page.ajax_action, itsec_page.ajax_nonce );
}
};
jQuery(document).ready(function( $ ) {
itsecLogsPage.init();
});