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