19 } |
19 } |
20 }); |
20 }); |
21 $( '#link_rel' ).val( ( isMe ) ? 'me' : inputs.substr( 0,inputs.length - 1 ) ); |
21 $( '#link_rel' ).val( ( isMe ) ? 'me' : inputs.substr( 0,inputs.length - 1 ) ); |
22 }); |
22 }); |
23 }); |
23 }); |
24 |
|
25 // Privacy request action handling |
|
26 jQuery( document ).ready( function( $ ) { |
|
27 var strings = window.privacyToolsL10n || {}; |
|
28 |
|
29 function setActionState( $action, state ) { |
|
30 $action.children().hide(); |
|
31 $action.children( '.' + state ).show(); |
|
32 } |
|
33 |
|
34 function clearResultsAfterRow( $requestRow ) { |
|
35 $requestRow.removeClass( 'has-request-results' ); |
|
36 |
|
37 if ( $requestRow.next().hasClass( 'request-results' ) ) { |
|
38 $requestRow.next().remove(); |
|
39 } |
|
40 } |
|
41 |
|
42 function appendResultsAfterRow( $requestRow, classes, summaryMessage, additionalMessages ) { |
|
43 var itemList = '', |
|
44 resultRowClasses = 'request-results'; |
|
45 |
|
46 clearResultsAfterRow( $requestRow ); |
|
47 |
|
48 if ( additionalMessages.length ) { |
|
49 $.each( additionalMessages, function( index, value ) { |
|
50 itemList = itemList + '<li>' + value + '</li>'; |
|
51 }); |
|
52 itemList = '<ul>' + itemList + '</ul>'; |
|
53 } |
|
54 |
|
55 $requestRow.addClass( 'has-request-results' ); |
|
56 |
|
57 if ( $requestRow.hasClass( 'status-request-confirmed' ) ) { |
|
58 resultRowClasses = resultRowClasses + ' status-request-confirmed'; |
|
59 } |
|
60 |
|
61 if ( $requestRow.hasClass( 'status-request-failed' ) ) { |
|
62 resultRowClasses = resultRowClasses + ' status-request-failed'; |
|
63 } |
|
64 |
|
65 $requestRow.after( function() { |
|
66 return '<tr class="' + resultRowClasses + '"><th colspan="5">' + |
|
67 '<div class="notice inline notice-alt ' + classes + '">' + |
|
68 '<p>' + summaryMessage + '</p>' + |
|
69 itemList + |
|
70 '</div>' + |
|
71 '</td>' + |
|
72 '</tr>'; |
|
73 }); |
|
74 } |
|
75 |
|
76 $( '.export-personal-data-handle' ).click( function( event ) { |
|
77 |
|
78 var $this = $( this ), |
|
79 $action = $this.parents( '.export-personal-data' ), |
|
80 $requestRow = $this.parents( 'tr' ), |
|
81 requestID = $action.data( 'request-id' ), |
|
82 nonce = $action.data( 'nonce' ), |
|
83 exportersCount = $action.data( 'exporters-count' ), |
|
84 sendAsEmail = $action.data( 'send-as-email' ) ? true : false; |
|
85 |
|
86 event.preventDefault(); |
|
87 event.stopPropagation(); |
|
88 |
|
89 $action.blur(); |
|
90 clearResultsAfterRow( $requestRow ); |
|
91 |
|
92 function onExportDoneSuccess( zipUrl ) { |
|
93 setActionState( $action, 'export-personal-data-success' ); |
|
94 if ( 'undefined' !== typeof zipUrl ) { |
|
95 window.location = zipUrl; |
|
96 } else if ( ! sendAsEmail ) { |
|
97 onExportFailure( strings.noExportFile ); |
|
98 } |
|
99 } |
|
100 |
|
101 function onExportFailure( errorMessage ) { |
|
102 setActionState( $action, 'export-personal-data-failed' ); |
|
103 if ( errorMessage ) { |
|
104 appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] ); |
|
105 } |
|
106 } |
|
107 |
|
108 function doNextExport( exporterIndex, pageIndex ) { |
|
109 $.ajax( |
|
110 { |
|
111 url: window.ajaxurl, |
|
112 data: { |
|
113 action: 'wp-privacy-export-personal-data', |
|
114 exporter: exporterIndex, |
|
115 id: requestID, |
|
116 page: pageIndex, |
|
117 security: nonce, |
|
118 sendAsEmail: sendAsEmail |
|
119 }, |
|
120 method: 'post' |
|
121 } |
|
122 ).done( function( response ) { |
|
123 var responseData = response.data; |
|
124 |
|
125 if ( ! response.success ) { |
|
126 |
|
127 // e.g. invalid request ID |
|
128 onExportFailure( response.data ); |
|
129 return; |
|
130 } |
|
131 |
|
132 if ( ! responseData.done ) { |
|
133 setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) ); |
|
134 } else { |
|
135 if ( exporterIndex < exportersCount ) { |
|
136 setTimeout( doNextExport( exporterIndex + 1, 1 ) ); |
|
137 } else { |
|
138 onExportDoneSuccess( responseData.url ); |
|
139 } |
|
140 } |
|
141 }).fail( function( jqxhr, textStatus, error ) { |
|
142 |
|
143 // e.g. Nonce failure |
|
144 onExportFailure( error ); |
|
145 }); |
|
146 } |
|
147 |
|
148 // And now, let's begin |
|
149 setActionState( $action, 'export-personal-data-processing' ); |
|
150 doNextExport( 1, 1 ); |
|
151 }); |
|
152 |
|
153 $( '.remove-personal-data-handle' ).click( function( event ) { |
|
154 |
|
155 var $this = $( this ), |
|
156 $action = $this.parents( '.remove-personal-data' ), |
|
157 $requestRow = $this.parents( 'tr' ), |
|
158 requestID = $action.data( 'request-id' ), |
|
159 nonce = $action.data( 'nonce' ), |
|
160 erasersCount = $action.data( 'erasers-count' ), |
|
161 hasRemoved = false, |
|
162 hasRetained = false, |
|
163 messages = []; |
|
164 |
|
165 event.stopPropagation(); |
|
166 |
|
167 $action.blur(); |
|
168 clearResultsAfterRow( $requestRow ); |
|
169 |
|
170 function onErasureDoneSuccess() { |
|
171 var summaryMessage = strings.noDataFound; |
|
172 var classes = 'notice-success'; |
|
173 |
|
174 setActionState( $action, 'remove-personal-data-idle' ); |
|
175 |
|
176 if ( false === hasRemoved ) { |
|
177 if ( false === hasRetained ) { |
|
178 summaryMessage = strings.noDataFound; |
|
179 } else { |
|
180 summaryMessage = strings.noneRemoved; |
|
181 classes = 'notice-warning'; |
|
182 } |
|
183 } else { |
|
184 if ( false === hasRetained ) { |
|
185 summaryMessage = strings.foundAndRemoved; |
|
186 } else { |
|
187 summaryMessage = strings.someNotRemoved; |
|
188 classes = 'notice-warning'; |
|
189 } |
|
190 } |
|
191 appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, messages ); |
|
192 } |
|
193 |
|
194 function onErasureFailure() { |
|
195 setActionState( $action, 'remove-personal-data-failed' ); |
|
196 appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] ); |
|
197 } |
|
198 |
|
199 function doNextErasure( eraserIndex, pageIndex ) { |
|
200 $.ajax({ |
|
201 url: window.ajaxurl, |
|
202 data: { |
|
203 action: 'wp-privacy-erase-personal-data', |
|
204 eraser: eraserIndex, |
|
205 id: requestID, |
|
206 page: pageIndex, |
|
207 security: nonce |
|
208 }, |
|
209 method: 'post' |
|
210 }).done( function( response ) { |
|
211 var responseData = response.data; |
|
212 |
|
213 if ( ! response.success ) { |
|
214 onErasureFailure(); |
|
215 return; |
|
216 } |
|
217 if ( responseData.items_removed ) { |
|
218 hasRemoved = hasRemoved || responseData.items_removed; |
|
219 } |
|
220 if ( responseData.items_retained ) { |
|
221 hasRetained = hasRetained || responseData.items_retained; |
|
222 } |
|
223 if ( responseData.messages ) { |
|
224 messages = messages.concat( responseData.messages ); |
|
225 } |
|
226 if ( ! responseData.done ) { |
|
227 setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) ); |
|
228 } else { |
|
229 if ( eraserIndex < erasersCount ) { |
|
230 setTimeout( doNextErasure( eraserIndex + 1, 1 ) ); |
|
231 } else { |
|
232 onErasureDoneSuccess(); |
|
233 } |
|
234 } |
|
235 }).fail( function() { |
|
236 onErasureFailure(); |
|
237 }); |
|
238 } |
|
239 |
|
240 // And now, let's begin |
|
241 setActionState( $action, 'remove-personal-data-processing' ); |
|
242 |
|
243 doNextErasure( 1, 1 ); |
|
244 }); |
|
245 }); |
|
246 |
|
247 ( function( $ ) { |
|
248 |
|
249 // Privacy policy page, copy button. |
|
250 $( document ).on( 'click', function( event ) { |
|
251 var $target = $( event.target ); |
|
252 var $parent, $container, range; |
|
253 |
|
254 if ( $target.is( 'button.privacy-text-copy' ) ) { |
|
255 $parent = $target.parent().parent(); |
|
256 $container = $parent.find( 'div.wp-suggested-text' ); |
|
257 |
|
258 if ( ! $container.length ) { |
|
259 $container = $parent.find( 'div.policy-text' ); |
|
260 } |
|
261 |
|
262 if ( $container.length ) { |
|
263 try { |
|
264 window.getSelection().removeAllRanges(); |
|
265 range = document.createRange(); |
|
266 $container.addClass( 'hide-privacy-policy-tutorial' ); |
|
267 |
|
268 range.selectNodeContents( $container[0] ); |
|
269 window.getSelection().addRange( range ); |
|
270 document.execCommand( 'copy' ); |
|
271 |
|
272 $container.removeClass( 'hide-privacy-policy-tutorial' ); |
|
273 window.getSelection().removeAllRanges(); |
|
274 } catch ( er ) {} |
|
275 } |
|
276 } |
|
277 }); |
|
278 |
|
279 } ( jQuery ) ); |
|