Ticket #5513: bulk_notifications_management.diff
File bulk_notifications_management.diff, 6.7 KB (added by , 10 years ago) |
---|
-
src/bp-templates/bp-legacy/buddypress-functions.php
171 171 'messages_markread' => 'bp_legacy_theme_ajax_message_markread', 172 172 'messages_markunread' => 'bp_legacy_theme_ajax_message_markunread', 173 173 'messages_send_reply' => 'bp_legacy_theme_ajax_messages_send_reply', 174 175 //Notifications 176 'notifications_bulk_management' => 'bp_legacy_theme_ajax_notifications_bulk_management', 174 177 ); 175 178 176 179 /** … … 1449 1452 1450 1453 exit; 1451 1454 } 1455 1456 /** 1457 * Handles bulk management (mark as read/unread, delete) of notifications via a POST request. 1458 * 1459 * @return String HTML 1460 * @since BuddyPress (2.2) 1461 */ 1462 function bp_legacy_theme_ajax_notifications_bulk_management() { 1463 1464 // Bail if not a POST action 1465 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1466 return; 1467 1468 check_ajax_referer( 'notifications_bulk_nonce', 'notifications_bulk_nonce' ); 1469 1470 if ( ! isset( $_POST['notification_ids'] ) ) { 1471 echo "-1<div id='message' class='error'><p>" . __( 'There was a problem managing your notifications.', 'buddypress' ) . '</p></div>'; 1472 1473 } else { 1474 $notifications = explode( ',', $_POST['notification_ids'] ); 1475 1476 switch ( $_POST['do_action'] ) : 1477 case 'delete' : 1478 for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) { 1479 bp_notifications_delete_notification( (int) $notifications[$i] ); 1480 } 1481 _e( 'Notifications deleted', 'buddypress' ); 1482 break; 1483 1484 case 'read' : 1485 for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) { 1486 bp_notifications_mark_notification( (int) $notifications[$i], false ); 1487 } 1488 _e( 'Notifications marked as read', 'buddypress' ); 1489 break; 1490 1491 case 'unread' : 1492 for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) { 1493 bp_notifications_mark_notification( (int) $notifications[$i], true ); 1494 } 1495 _e( 'Notifications marked as unread', 'buddypress' ); 1496 break; 1497 endswitch; 1498 } 1499 1500 exit; 1501 } -
src/bp-templates/bp-legacy/js/buddypress.js
1525 1525 return false; 1526 1526 }); 1527 1527 1528 /* Bulk manage notifications */ 1529 jq( 'body.notifications #notification-bulk-manage' ).on( 'click', function() { 1530 1531 checkboxes_tosend = ''; 1532 checkboxes = jq('table.notifications tr td input[type="checkbox"]'); 1533 1534 jq('#message').remove(); 1535 jq(this).addClass('loading'); 1536 1537 jq(checkboxes).each( function(i) { 1538 if( jq(this).is(':checked') ) { 1539 checkboxes_tosend += jq(this).attr('value') + ','; 1540 } 1541 }); 1542 1543 if ( '' === checkboxes_tosend ) { 1544 jq(this).removeClass('loading'); 1545 return false; 1546 } 1547 1548 jq.post( ajaxurl, { 1549 action: 'notifications_bulk_management', 1550 'notification_ids': checkboxes_tosend, 1551 'notifications_bulk_nonce': jq('#notifications_bulk_nonce').attr('value'), 1552 'do_action': jq('#notification-select').val() 1553 }, function(response) { 1554 if ( response[0] + response[1] === '-1' ) { 1555 jq('table.notifications').prepend( response.substr( 2, response.length ) ); 1556 } else { 1557 jq('table.notifications').before( '<div id="message" class="updated"><p>' + response + '</p></div>' ); 1558 1559 jq(checkboxes).each( function(i) { 1560 if( jq(this).is(':checked') ) { 1561 // We need to uncheck because message is only hidden 1562 // Otherwise, AJAX will be fired again with same data 1563 jq(this).prop( 'checked', false ); 1564 jq(this).parent().parent().fadeOut(150); 1565 } 1566 }); 1567 } 1568 1569 jq('#message').hide().slideDown(150); 1570 jq('#notification-bulk-manage').removeClass('loading'); 1571 }); 1572 1573 return false; 1574 }); 1575 1576 /* Selecting/Deselcting all notifications */ 1577 jq('#select-all-notifications').click(function(event) { 1578 if( this.checked ) { 1579 jq('.notification-check').each(function() { 1580 this.checked = true; 1581 }); 1582 } else { 1583 jq('.notification-check').each(function() { 1584 this.checked = false; 1585 }); 1586 } 1587 }); 1588 1528 1589 /* Close site wide notices in the sidebar */ 1529 1590 jq('#close-notice').on( 'click', function() { 1530 1591 jq(this).addClass('loading'); -
src/bp-templates/bp-legacy/buddypress/members/single/notifications/notifications-loop.php
5 5 <th class="title"><?php _e( 'Notification', 'buddypress' ); ?></th> 6 6 <th class="date"><?php _e( 'Date Received', 'buddypress' ); ?></th> 7 7 <th class="actions"><?php _e( 'Actions', 'buddypress' ); ?></th> 8 <th><?php _e( 'Select all', 'buddypress' ); ?> <input id="select-all-notifications" type="checkbox"></th> 8 9 </tr> 9 10 </thead> 10 11 … … 17 18 <td><?php bp_the_notification_description(); ?></td> 18 19 <td><?php bp_the_notification_time_since(); ?></td> 19 20 <td><?php bp_the_notification_action_links(); ?></td> 21 <td><input id="<?php bp_the_notification_id(); ?>" type="checkbox" name="notifications[]" value="<?php bp_the_notification_id(); ?>" class="notification-check"></td> 20 22 </tr> 21 23 22 24 <?php endwhile; ?> 23 25 24 26 </tbody> 25 </table> 26 No newline at end of file 27 </table> 28 29 <div class="notifications-options-nav"> 30 <?php bp_notifications_bulk_management(); ?> 31 </div><!-- .notifications-options-nav --> -
src/bp-notifications/bp-notifications-template.php
1049 1049 1050 1050 <?php 1051 1051 } 1052 1053 /** 1054 * Output the form for bulk management of notifications 1055 * 1056 * @since BuddyPress (2.2.0) 1057 */ 1058 function bp_notifications_bulk_management() { 1059 1060 wp_nonce_field( 'notifications_bulk_nonce', 'notifications_bulk_nonce' ); 1061 ?> 1062 1063 <select name="notification-action" id="notification-select"> 1064 <?php if ( bp_current_action() == 'unread' ) { ?> 1065 <option value="read"><?php _e( 'Mark selected as read', 'buddypress' ); ?></option> 1066 <?php } elseif ( bp_current_action() == 'read' ) { ?> 1067 <option value="unread"><?php _e( 'Mark selected as unread', 'buddypress' ); ?></option> 1068 <?php } ?> 1069 <option value="delete"><?php _e( 'Delete selected', 'buddypress' ); ?></option> 1070 </select> 1071 <input type="submit" id="notification-bulk-manage" class="button action" value="<?php _e( 'Apply', 'buddypress' ); ?>"> 1072 <?php 1073 }