[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-nouveau/js/ -> buddypress-notifications.js (source)

   1  /* global bp, BP_Nouveau */
   2  /* @version 3.0.0 */
   3  window.bp = window.bp || {};
   4  
   5  ( function( exports, $ ) {
   6  
   7      // Bail if not set.
   8      if ( typeof BP_Nouveau === 'undefined' ) {
   9          return;
  10      }
  11  
  12      bp.Nouveau = bp.Nouveau || {};
  13  
  14      /**
  15       * [Activity description]
  16       * @type {Object}
  17       */
  18      bp.Nouveau.Notifications = {
  19  
  20          /**
  21           * [start description]
  22           * @return {[type]} [description]
  23           */
  24          start: function() {
  25              this.setupGlobals();
  26  
  27              // Listen to events ("Add hooks!").
  28              this.addListeners();
  29          },
  30  
  31          /**
  32           * [setupGlobals description]
  33           * @return {[type]} [description]
  34           */
  35          setupGlobals: function() {
  36              // Always reset sort to Newest notifications
  37              bp.Nouveau.setStorage( 'bp-notifications', 'extras', 'DESC' );
  38          },
  39  
  40          /**
  41           * [addListeners description]
  42           */
  43          addListeners: function() {
  44              // Change the Order actions visibility once the ajax request is done.
  45              $( '#buddypress [data-bp-list="notifications"]' ).on( 'bp_ajax_request', this.prepareDocument );
  46  
  47              // Trigger Notifications order request.
  48              $( '#buddypress [data-bp-list="notifications"]' ).on( 'click', '[data-bp-notifications-order]', bp.Nouveau, this.sortNotifications );
  49  
  50              // Enable the Apply Button once the bulk action is selected.
  51              $( '#buddypress [data-bp-list="notifications"]' ).on( 'change', '#notification-select', this.enableBulkSubmit );
  52  
  53              // Select all displayed notifications.
  54              $( '#buddypress [data-bp-list="notifications"]' ).on( 'click', '#select-all-notifications', this.selectAll );
  55  
  56              // Reset The filter before unload.
  57              $( window ).on( 'unload', this.resetFilter );
  58          },
  59  
  60          /**
  61           * [prepareDocument description]
  62           * @return {[type]} [description]
  63           */
  64          prepareDocument: function() {
  65              var store = bp.Nouveau.getStorage( 'bp-notifications' );
  66  
  67              if ( 'ASC' === store.extras ) {
  68                  $( '[data-bp-notifications-order="DESC"]' ).show();
  69                  $( '[data-bp-notifications-order="ASC"]' ).hide();
  70              } else {
  71                  $( '[data-bp-notifications-order="ASC"]' ).show();
  72                  $( '[data-bp-notifications-order="DESC"]' ).hide();
  73              }
  74  
  75              // Make sure a 'Bulk Action' is selected before submitting the form.
  76              $( '#notification-bulk-manage' ).prop( 'disabled', 'disabled' );
  77          },
  78  
  79          /**
  80           * [sortNotifications description]
  81           * @param  {[type]} event [description]
  82           * @return {[type]}       [description]
  83           */
  84          sortNotifications: function( event ) {
  85              var store = event.data.getStorage( 'bp-notifications' ),
  86                  scope = store.scope || null, filter = store.filter || null,
  87                  sort = store.extra || null, search_terms = '';
  88  
  89              event.preventDefault();
  90  
  91              sort = $( event.currentTarget ).data( 'bp-notifications-order' );
  92              bp.Nouveau.setStorage( 'bp-notifications', 'extras', sort );
  93  
  94              if ( $( '#buddypress [data-bp-search="notifications"] input[type=search]' ).length ) {
  95                  search_terms = $( '#buddypress [data-bp-search="notifications"] input[type=search]' ).val();
  96              }
  97  
  98              bp.Nouveau.objectRequest( {
  99                  object              : 'notifications',
 100                  scope               : scope,
 101                  filter              : filter,
 102                  search_terms        : search_terms,
 103                  extras              : sort,
 104                  page                : 1
 105              } );
 106          },
 107  
 108          /**
 109           * [enableBulkSubmit description]
 110           * @param  {[type]} event [description]
 111           * @return {[type]}       [description]
 112           */
 113          enableBulkSubmit: function( event ) {
 114              $( '#notification-bulk-manage' ).prop( 'disabled', $( event.currentTarget ).val().length <= 0 );
 115          },
 116  
 117          /**
 118           * [selectAll description]
 119           * @param  {[type]} event [description]
 120           * @return {[type]}       [description]
 121           */
 122          selectAll: function( event ) {
 123              $.each( $( '.notification-check' ), function( cb, checkbox ) {
 124                  $( checkbox ).prop( 'checked', $( event.currentTarget ).prop( 'checked' ) );
 125              } );
 126          },
 127  
 128          /**
 129           * [resetFilter description]
 130           * @return {[type]} [description]
 131           */
 132          resetFilter: function() {
 133              bp.Nouveau.setStorage( 'bp-notifications', 'filter', 0 );
 134          }
 135      };
 136  
 137      // Launch BP Nouveau Notifications.
 138      bp.Nouveau.Notifications.start();
 139  
 140  } )( bp, jQuery );


Generated: Sat Dec 5 01:01:41 2020 Cross-referenced by PHPXref 0.7.1