mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-06 02:41:27 +01:00
82687eb7af
Props allendav, coreymckrill, ericdaams, azaozz. Merges [42986] to the 4.9 branch. See #43637, #43602. Built from https://develop.svn.wordpress.org/branches/4.9@43075 git-svn-id: http://core.svn.wordpress.org/branches/4.9@42904 1a063a9b-81f0-0310-95a4-ce76da25c4cd
139 lines
4.0 KiB
JavaScript
139 lines
4.0 KiB
JavaScript
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' );
|
|
} else {
|
|
$( this ).removeAttr( 'disabled' ).parent().removeClass( 'disabled' );
|
|
if ( $( this ).is( ':checked' ) && $( this ).val() !== '') {
|
|
inputs += $( this ).val() + ' ';
|
|
}
|
|
}
|
|
});
|
|
$( '#link_rel' ).val( ( isMe ) ? 'me' : inputs.substr( 0,inputs.length - 1 ) );
|
|
});
|
|
});
|
|
|
|
// 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 );
|
|
if ( additionalMessages.length ) {
|
|
// TODO - render additionalMessages after the summaryMessage
|
|
}
|
|
|
|
$requestRow.after( function() {
|
|
return '<tr class="request-results"><td colspan="5"><div class="notice inline notice-alt ' + classes + '"><p>' +
|
|
summaryMessage +
|
|
'</p></div></td></tr>';
|
|
} );
|
|
}
|
|
|
|
$( '.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';
|
|
if ( 0 == removedCount ) {
|
|
if ( 0 == retainedCount ) {
|
|
summaryMessage = strings.noDataFound;
|
|
} else {
|
|
summaryMessage = strings.noneRemoved;
|
|
classes = 'notice-warning';
|
|
}
|
|
} else {
|
|
if ( 0 == retainedCount ) {
|
|
summaryMessage = strings.foundAndRemoved;
|
|
} else {
|
|
summaryMessage = strings.someNotRemoved;
|
|
classes = 'notice-warning';
|
|
}
|
|
}
|
|
appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
|
|
}
|
|
|
|
function on_erasure_failure( textStatus, error ) {
|
|
set_action_state( $action, 'remove_personal_data_failed' );
|
|
appendResultsAfterRow( $requestRow, 'notice-error', strings.anErrorOccurred, [] );
|
|
}
|
|
|
|
function do_next_erasure( eraserIndex, pageIndex ) {
|
|
$.ajax( {
|
|
url: ajaxurl,
|
|
data: {
|
|
action: 'wp-privacy-erase-personal-data',
|
|
eraser: eraserIndex,
|
|
id: requestID,
|
|
page: pageIndex,
|
|
security: nonce,
|
|
},
|
|
method: 'post'
|
|
} ).done( function( response ) {
|
|
if ( ! response.success ) {
|
|
on_erasure_failure( 'error', response.data );
|
|
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();
|
|
}
|
|
}
|
|
} ).fail( function( jqxhr, textStatus, error ) {
|
|
on_erasure_failure( textStatus, error );
|
|
} );
|
|
}
|
|
|
|
// And now, let's begin
|
|
set_action_state( $action, 'remove_personal_data_processing' );
|
|
|
|
do_next_erasure( 1, 1 );
|
|
} )
|
|
} );
|