2013-11-14 16:58:10 -05:00
|
|
|
jQuery( document ).ready(function( $ ) {
|
|
|
|
$( '#link_rel' ).prop( 'readonly', true );
|
|
|
|
$( '#linkxfndiv input' ).bind( 'click keyup', function() {
|
|
|
|
var isMe = $( '#me' ).is( ':checked' ), inputs = '';
|
|
|
|
$( 'input.valinp' ).each( function() {
|
|
|
|
if ( isMe ) {
|
|
|
|
$( this ).prop( 'disabled', true ).parent().addClass( 'disabled' );
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
2013-11-14 16:58:10 -05:00
|
|
|
$( this ).removeAttr( 'disabled' ).parent().removeClass( 'disabled' );
|
|
|
|
if ( $( this ).is( ':checked' ) && $( this ).val() !== '') {
|
|
|
|
inputs += $( this ).val() + ' ';
|
|
|
|
}
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
});
|
2013-11-14 16:58:10 -05:00
|
|
|
$( '#link_rel' ).val( ( isMe ) ? 'me' : inputs.substr( 0,inputs.length - 1 ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
});
|
2018-05-01 20:03:27 -04:00
|
|
|
|
|
|
|
// Privacy request action handling
|
|
|
|
jQuery( document ).ready( function( $ ) {
|
|
|
|
var strings = window.privacyToolsL10n || {};
|
|
|
|
|
|
|
|
function set_action_state( $action, state ) {
|
|
|
|
$action.children().hide();
|
|
|
|
$action.children( '.' + state ).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearResultsAfterRow( $requestRow ) {
|
|
|
|
if ( $requestRow.next().hasClass( 'request-results' ) ) {
|
|
|
|
$requestRow.next().remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) {
|
|
|
|
clearResultsAfterRow( $requestRow );
|
2018-05-01 22:16:25 -04:00
|
|
|
|
|
|
|
var itemList = '';
|
2018-05-01 20:03:27 -04:00
|
|
|
if ( additionalMessages.length ) {
|
2018-05-01 22:16:25 -04:00
|
|
|
$.each( additionalMessages, function( index, value ) {
|
|
|
|
itemList = itemList + '<li>' + value + '</li>';
|
|
|
|
} );
|
|
|
|
itemList = '<ul>' + itemList + '</ul>';
|
2018-05-01 20:03:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$requestRow.after( function() {
|
2018-05-01 22:16:25 -04:00
|
|
|
return '<tr class="request-results"><td colspan="5">' +
|
|
|
|
'<div class="notice inline notice-alt ' + classes + '">' +
|
|
|
|
'<p>' + summaryMessage + '</p>' +
|
|
|
|
itemList +
|
|
|
|
'</div>' +
|
|
|
|
'</td>' +
|
|
|
|
'</tr>';
|
2018-05-01 20:03:27 -04:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2018-05-01 22:16:25 -04:00
|
|
|
$( '.export_personal_data a' ).click( function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
var $this = $( this );
|
|
|
|
var $action = $this.parents( '.export_personal_data' );
|
|
|
|
var $requestRow = $this.parents( 'tr' );
|
|
|
|
var requestID = $action.data( 'request-id' );
|
|
|
|
var nonce = $action.data( 'nonce' );
|
|
|
|
var exportersCount = $action.data( 'exporters-count' );
|
|
|
|
var sendAsEmail = $action.data( 'send-as-email' ) ? true : false;
|
|
|
|
|
|
|
|
$action.blur();
|
|
|
|
clearResultsAfterRow( $requestRow );
|
|
|
|
|
|
|
|
function on_export_done_success( zipUrl ) {
|
|
|
|
set_action_state( $action, 'export_personal_data_success' );
|
|
|
|
if ( 'undefined' !== typeof zipUrl ) {
|
|
|
|
window.location = zipUrl;
|
|
|
|
} else if ( ! sendAsEmail ) {
|
|
|
|
on_export_failure( strings.noExportFile );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function on_export_failure( errorMessage ) {
|
|
|
|
set_action_state( $action, 'export_personal_data_failed' );
|
|
|
|
if ( errorMessage ) {
|
|
|
|
appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_next_export( exporterIndex, pageIndex ) {
|
|
|
|
$.ajax(
|
|
|
|
{
|
|
|
|
url: window.ajaxurl,
|
|
|
|
data: {
|
|
|
|
action: 'wp-privacy-export-personal-data',
|
|
|
|
exporter: exporterIndex,
|
|
|
|
id: requestID,
|
|
|
|
page: pageIndex,
|
|
|
|
security: nonce,
|
|
|
|
sendAsEmail: sendAsEmail
|
|
|
|
},
|
|
|
|
method: 'post'
|
|
|
|
}
|
|
|
|
).done( function( response ) {
|
|
|
|
if ( ! response.success ) {
|
|
|
|
// e.g. invalid request ID
|
|
|
|
on_export_failure( response.data );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var responseData = response.data;
|
|
|
|
if ( ! responseData.done ) {
|
|
|
|
setTimeout( do_next_export( exporterIndex, pageIndex + 1 ) );
|
|
|
|
} else {
|
|
|
|
if ( exporterIndex < exportersCount ) {
|
|
|
|
setTimeout( do_next_export( exporterIndex + 1, 1 ) );
|
|
|
|
} else {
|
|
|
|
on_export_done_success( responseData.url );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} ).fail( function( jqxhr, textStatus, error ) {
|
|
|
|
// e.g. Nonce failure
|
|
|
|
on_export_failure( error );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// And now, let's begin
|
|
|
|
set_action_state( $action, 'export_personal_data_processing' );
|
|
|
|
do_next_export( 1, 1 );
|
|
|
|
} );
|
|
|
|
|
2018-05-01 20:03:27 -04:00
|
|
|
$( '.remove_personal_data a' ).click( function( event ) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
var $this = $( this );
|
|
|
|
var $action = $this.parents( '.remove_personal_data' );
|
|
|
|
var $requestRow = $this.parents( 'tr' );
|
|
|
|
var requestID = $action.data( 'request-id' );
|
|
|
|
var nonce = $action.data( 'nonce' );
|
|
|
|
var erasersCount = $action.data( 'erasers-count' );
|
|
|
|
|
|
|
|
var removedCount = 0;
|
|
|
|
var retainedCount = 0;
|
|
|
|
var messages = [];
|
|
|
|
|
|
|
|
$action.blur();
|
|
|
|
clearResultsAfterRow( $requestRow );
|
|
|
|
|
|
|
|
function on_erasure_done_success() {
|
|
|
|
set_action_state( $action, 'remove_personal_data_idle' );
|
|
|
|
var summaryMessage = strings.noDataFound;
|
|
|
|
var classes = 'notice-success';
|
2018-05-01 20:21:25 -04:00
|
|
|
if ( 0 === removedCount ) {
|
|
|
|
if ( 0 === retainedCount ) {
|
2018-05-01 20:03:27 -04:00
|
|
|
summaryMessage = strings.noDataFound;
|
|
|
|
} else {
|
|
|
|
summaryMessage = strings.noneRemoved;
|
|
|
|
classes = 'notice-warning';
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-01 20:21:25 -04:00
|
|
|
if ( 0 === retainedCount ) {
|
2018-05-01 20:03:27 -04:00
|
|
|
summaryMessage = strings.foundAndRemoved;
|
|
|
|
} else {
|
|
|
|
summaryMessage = strings.someNotRemoved;
|
|
|
|
classes = 'notice-warning';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
|
|
|
|
}
|
|
|
|
|
2018-05-01 20:15:25 -04:00
|
|
|
function on_erasure_failure() {
|
2018-05-01 20:03:27 -04:00
|
|
|
set_action_state( $action, 'remove_personal_data_failed' );
|
2018-05-01 22:16:25 -04:00
|
|
|
appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] );
|
2018-05-01 20:03:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function do_next_erasure( eraserIndex, pageIndex ) {
|
|
|
|
$.ajax( {
|
2018-05-01 20:15:25 -04:00
|
|
|
url: window.ajaxurl,
|
2018-05-01 20:03:27 -04:00
|
|
|
data: {
|
|
|
|
action: 'wp-privacy-erase-personal-data',
|
|
|
|
eraser: eraserIndex,
|
|
|
|
id: requestID,
|
|
|
|
page: pageIndex,
|
2018-05-01 20:15:25 -04:00
|
|
|
security: nonce
|
2018-05-01 20:03:27 -04:00
|
|
|
},
|
|
|
|
method: 'post'
|
|
|
|
} ).done( function( response ) {
|
|
|
|
if ( ! response.success ) {
|
2018-05-01 20:15:25 -04:00
|
|
|
on_erasure_failure();
|
2018-05-01 20:03:27 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var responseData = response.data;
|
|
|
|
if ( responseData.num_items_removed ) {
|
|
|
|
removedCount += responseData.num_items_removed;
|
|
|
|
}
|
|
|
|
if ( responseData.num_items_retained ) {
|
|
|
|
retainedCount += responseData.num_items_removed;
|
|
|
|
}
|
|
|
|
if ( responseData.messages ) {
|
|
|
|
messages = messages.concat( responseData.messages );
|
|
|
|
}
|
|
|
|
if ( ! responseData.done ) {
|
|
|
|
setTimeout( do_next_erasure( eraserIndex, pageIndex + 1 ) );
|
|
|
|
} else {
|
|
|
|
if ( eraserIndex < erasersCount ) {
|
|
|
|
setTimeout( do_next_erasure( eraserIndex + 1, 1 ) );
|
|
|
|
} else {
|
|
|
|
on_erasure_done_success();
|
|
|
|
}
|
|
|
|
}
|
2018-05-01 20:15:25 -04:00
|
|
|
} ).fail( function() {
|
|
|
|
on_erasure_failure();
|
2018-05-01 20:03:27 -04:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
// And now, let's begin
|
|
|
|
set_action_state( $action, 'remove_personal_data_processing' );
|
|
|
|
|
|
|
|
do_next_erasure( 1, 1 );
|
2018-05-01 20:15:25 -04:00
|
|
|
} );
|
2018-05-01 20:03:27 -04:00
|
|
|
} );
|