1273 // Marry the secondary "Bulk actions" controls to the primary controls: |
1279 // Marry the secondary "Bulk actions" controls to the primary controls: |
1274 marryControls( $('#bulk-action-selector-top'), $('#doaction'), $('#bulk-action-selector-bottom'), $('#doaction2') ); |
1280 marryControls( $('#bulk-action-selector-top'), $('#doaction'), $('#bulk-action-selector-bottom'), $('#doaction2') ); |
1275 |
1281 |
1276 // Marry the secondary "Change role to" controls to the primary controls: |
1282 // Marry the secondary "Change role to" controls to the primary controls: |
1277 marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') ); |
1283 marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') ); |
|
1284 |
|
1285 var addAdminNotice = function( data ) { |
|
1286 var $notice = $( data.selector ), |
|
1287 $headerEnd = $( '.wp-header-end' ), |
|
1288 type, |
|
1289 dismissible, |
|
1290 $adminNotice; |
|
1291 |
|
1292 delete data.selector; |
|
1293 |
|
1294 dismissible = ( data.dismissible && data.dismissible === true ) ? ' is-dismissible' : ''; |
|
1295 type = ( data.type ) ? data.type : 'info'; |
|
1296 |
|
1297 $adminNotice = '<div id="' + data.id + '" class="notice notice-' + data.type + dismissible + '"><p>' + data.message + '</p></div>'; |
|
1298 |
|
1299 // Check if this admin notice already exists. |
|
1300 if ( ! $notice.length ) { |
|
1301 $notice = $( '#' + data.id ); |
|
1302 } |
|
1303 |
|
1304 if ( $notice.length ) { |
|
1305 $notice.replaceWith( $adminNotice ); |
|
1306 } else if ( $headerEnd.length ) { |
|
1307 $headerEnd.after( $adminNotice ); |
|
1308 } else { |
|
1309 if ( 'customize' === pagenow ) { |
|
1310 $( '.customize-themes-notifications' ).append( $adminNotice ); |
|
1311 } else { |
|
1312 $( '.wrap' ).find( '> h1' ).after( $adminNotice ); |
|
1313 } |
|
1314 } |
|
1315 |
|
1316 $document.trigger( 'wp-notice-added' ); |
|
1317 }; |
|
1318 |
|
1319 $( '.bulkactions' ).parents( 'form' ).on( 'submit', function( event ) { |
|
1320 var form = this, |
|
1321 submitterName = event.originalEvent && event.originalEvent.submitter ? event.originalEvent.submitter.name : false, |
|
1322 currentPageSelector = form.querySelector( '#current-page-selector' ); |
|
1323 |
|
1324 if ( currentPageSelector && currentPageSelector.defaultValue !== currentPageSelector.value ) { |
|
1325 return; // Pagination form submission. |
|
1326 } |
|
1327 |
|
1328 // Observe submissions from posts lists for 'bulk_action' or users lists for 'new_role'. |
|
1329 var bulkFieldRelations = { |
|
1330 'bulk_action' : window.bulkActionObserverIds.bulk_action, |
|
1331 'changeit' : window.bulkActionObserverIds.changeit |
|
1332 }; |
|
1333 if ( ! Object.keys( bulkFieldRelations ).includes( submitterName ) ) { |
|
1334 return; |
|
1335 } |
|
1336 |
|
1337 var values = new FormData(form); |
|
1338 var value = values.get( bulkFieldRelations[ submitterName ] ) || '-1'; |
|
1339 |
|
1340 // Check that the action is not the default one. |
|
1341 if ( value !== '-1' ) { |
|
1342 // Check that at least one item is selected. |
|
1343 var itemsSelected = form.querySelectorAll( '.wp-list-table tbody .check-column input[type="checkbox"]:checked' ); |
|
1344 |
|
1345 if ( itemsSelected.length > 0 ) { |
|
1346 return; |
|
1347 } |
|
1348 } |
|
1349 event.preventDefault(); |
|
1350 event.stopPropagation(); |
|
1351 $( 'html, body' ).animate( { scrollTop: 0 } ); |
|
1352 |
|
1353 var errorMessage = __( 'Please select at least one item to perform this action on.' ); |
|
1354 addAdminNotice( { |
|
1355 id: 'no-items-selected', |
|
1356 type: 'error', |
|
1357 message: errorMessage, |
|
1358 dismissible: true, |
|
1359 } ); |
|
1360 |
|
1361 wp.a11y.speak( errorMessage ); |
|
1362 }); |
1278 |
1363 |
1279 /** |
1364 /** |
1280 * Shows row actions on focus of its parent container element or any other elements contained within. |
1365 * Shows row actions on focus of its parent container element or any other elements contained within. |
1281 * |
1366 * |
1282 * @return {void} |
1367 * @return {void} |