[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  /* global wp, BP_Nouveau, _, Backbone */
   2  /* @since 3.0.0 */
   3  /* @version 8.0.0 */
   4  window.wp = window.wp || {};
   5  window.bp = window.bp || {};
   6  
   7  ( function( bp, $ ) {
   8  
   9      // Bail if not set
  10      if ( typeof BP_Nouveau === 'undefined' ) {
  11          return;
  12      }
  13  
  14      _.extend( bp, _.pick( wp, 'Backbone', 'ajax', 'template' ) );
  15  
  16      bp.Models      = bp.Models || {};
  17      bp.Collections = bp.Collections || {};
  18      bp.Views       = bp.Views || {};
  19  
  20      bp.Nouveau = bp.Nouveau || {};
  21  
  22      /**
  23       * [Nouveau description]
  24       * @type {Object}
  25       */
  26      bp.Nouveau.GroupInvites = {
  27          /**
  28           * [start description]
  29           * @return {[type]} [description]
  30           */
  31          start: function() {
  32              this.scope    = null;
  33              this.views    = new Backbone.Collection();
  34              this.navItems = new Backbone.Collection();
  35              this.users    = new bp.Collections.Users();
  36              this.invites  = this.users.clone();
  37  
  38              // Add views
  39              this.setupNav();
  40              this.setupLoops();
  41              this.displayFeedback( BP_Nouveau.group_invites.loading, 'loading' );
  42  
  43              // Add an invite when a user is selected
  44              this.users.on( 'change:selected', this.addInvite, this );
  45  
  46              // Add an invite when a user is selected
  47              this.invites.on( 'change:selected', this.manageInvite, this );
  48  
  49              // And display the Invites nav
  50              this.invites.on( 'add', this.invitesNav, this );
  51              this.invites.on( 'reset', this.hideInviteNav, this );
  52          },
  53  
  54          setupNav: function() {
  55              var activeView;
  56  
  57              // Init the nav
  58              this.nav = new bp.Views.invitesNav( { collection: this.navItems } );
  59  
  60              // loop through available nav items to build it
  61              _.each( BP_Nouveau.group_invites.nav, function( item, index ) {
  62                  if ( ! _.isObject( item ) ) {
  63                      return;
  64                  }
  65  
  66                  // Reset active View
  67                  activeView = 0;
  68  
  69                  if ( 0 === index ) {
  70                      this.scope = item.id;
  71                      activeView = 1;
  72                  }
  73  
  74                  this.navItems.add( {
  75                      id     : item.id,
  76                      name   : item.caption,
  77                      href   : item.href || '#members-list',
  78                      active : activeView,
  79                      hide   : _.isUndefined( item.hide ) ? 0 : item.hide
  80                  } );
  81              }, this );
  82  
  83              // Inject the nav into the DOM
  84              this.nav.inject( '.bp-invites-nav' );
  85  
  86              // Listen to the confirm event
  87              this.nav.on( 'bp-invites:confirm', this.loadConfirmView, this );
  88              this.nav.on( 'bp-invites:loops', this.setupLoops, this );
  89          },
  90  
  91          setupLoops: function( scope ) {
  92              var users;
  93  
  94              scope = scope || this.scope;
  95  
  96              // Reset Views
  97              this.clearViews();
  98  
  99              // Only display the loading message if scope has changed
 100              if ( scope !== this.scope ) {
 101                  // Loading
 102                  this.displayFeedback( BP_Nouveau.group_invites.loading, 'loading' );
 103              }
 104  
 105              // Set global scope to requested one
 106              this.scope = scope;
 107  
 108              // Create the loop view
 109              users = new bp.Views.inviteUsers( { collection: this.users, scope: scope } );
 110  
 111              this.views.add( { id: 'users', view: users } );
 112  
 113              users.inject( '.bp-invites-content' );
 114  
 115              this.displayFilters( this.users );
 116          },
 117  
 118          displayFilters: function( collection ) {
 119              var filters_view;
 120  
 121              // Create the model
 122              this.filters = new Backbone.Model( {
 123                  page         : 1,
 124                  total_page   : 0,
 125                  search_terms : '',
 126                  scope        : this.scope
 127              } );
 128  
 129              // Use it in the filters view.
 130              filters_view = new bp.Views.inviteFilters( { model: this.filters, users: collection } );
 131  
 132              this.views.add( { id: 'filters', view: filters_view } );
 133  
 134              filters_view.inject( '.bp-invites-filters' );
 135          },
 136  
 137          removeFeedback: function() {
 138              var feedback;
 139  
 140              if ( ! _.isUndefined( this.views.get( 'feedback' ) ) ) {
 141                  feedback = this.views.get( 'feedback' );
 142                  feedback.get( 'view' ).remove();
 143                  this.views.remove( { id: 'feedback', view: feedback } );
 144              }
 145          },
 146  
 147          displayFeedback: function( message, type ) {
 148              var feedback;
 149  
 150              // Make sure to remove the feedbacks
 151              this.removeFeedback();
 152  
 153              if ( ! message ) {
 154                  return;
 155              }
 156  
 157              feedback = new bp.Views.Feedback( {
 158                  value : message,
 159                  type  : type || 'info'
 160              } );
 161  
 162              this.views.add( { id: 'feedback', view: feedback } );
 163  
 164              feedback.inject( '.bp-invites-feedback' );
 165          },
 166  
 167          addInvite: function( user ) {
 168              if ( true === user.get( 'selected' ) ) {
 169                  this.invites.add( user );
 170              } else {
 171                  var invite = this.invites.get( user.get( 'id' ) );
 172  
 173                  if ( true === invite.get( 'selected' ) ) {
 174                      this.invites.remove( invite );
 175                  }
 176              }
 177          },
 178  
 179          manageInvite: function( invite ) {
 180              var user = this.users.get( invite.get( 'id' ) );
 181  
 182              // Update the user
 183              if ( user ) {
 184                  user.set( 'selected', false );
 185              }
 186  
 187              // remove the invite
 188              this.invites.remove( invite );
 189  
 190              // No more invites, reset the collection
 191              if ( ! this.invites.length  ) {
 192                  this.invites.reset();
 193              }
 194          },
 195  
 196          invitesNav: function() {
 197              this.navItems.get( 'invites' ).set( { active: 0, hide: 0 } );
 198          },
 199  
 200          hideInviteNav: function() {
 201              this.navItems.get( 'invites' ).set( { active: 0, hide: 1 } );
 202          },
 203  
 204          clearViews: function() {
 205              // Clear views
 206              if ( ! _.isUndefined( this.views.models ) ) {
 207                  _.each( this.views.models, function( model ) {
 208                      model.get( 'view' ).remove();
 209                  }, this );
 210  
 211                  this.views.reset();
 212              }
 213          },
 214  
 215          loadConfirmView: function() {
 216              this.clearViews();
 217  
 218              this.displayFeedback( BP_Nouveau.group_invites.invites_form, 'help' );
 219  
 220              // Activate the loop view
 221              var invites = new bp.Views.invitesEditor( { collection: this.invites } );
 222  
 223              this.views.add( { id: 'invites', view: invites } );
 224  
 225              invites.inject( '.bp-invites-content' );
 226          }
 227      };
 228  
 229      // Item (group or blog or any other)
 230      bp.Models.User = Backbone.Model.extend( {
 231          defaults : {
 232              id       : 0,
 233              avatar   : '',
 234              name     : '',
 235              selected : false
 236          }
 237      } );
 238  
 239      /** Collections ***********************************************************/
 240  
 241      // Items (groups or blogs or any others)
 242      bp.Collections.Users = Backbone.Collection.extend( {
 243          model: bp.Models.User,
 244  
 245          initialize : function() {
 246              this.options = { page: 1, total_page: 0, group_id: BP_Nouveau.group_invites.group_id };
 247          },
 248  
 249          sync: function( method, model, options ) {
 250              options         = options || {};
 251              options.context = this;
 252              options.data    = options.data || {};
 253  
 254              // Add generic nonce
 255              options.data.nonce = BP_Nouveau.nonces.groups;
 256  
 257              if ( this.options.group_id ) {
 258                  options.data.group_id = this.options.group_id;
 259              }
 260  
 261              if ( 'read' === method ) {
 262                  options.data = _.extend( options.data, {
 263                      action: 'groups_get_group_potential_invites'
 264                  } );
 265  
 266                  return bp.ajax.send( options );
 267              }
 268  
 269              if ( 'create' === method ) {
 270                  options.data = _.extend( options.data, {
 271                      action   : 'groups_send_group_invites',
 272                      _wpnonce : BP_Nouveau.group_invites.nonces.send_invites
 273                  } );
 274  
 275                  if ( model ) {
 276                      options.data.users = model;
 277                  }
 278  
 279                  return bp.ajax.send( options );
 280              }
 281  
 282              if ( 'delete' === method ) {
 283                  options.data = _.extend( options.data, {
 284                      action   : 'groups_delete_group_invite',
 285                      _wpnonce : BP_Nouveau.group_invites.nonces.uninvite
 286                  } );
 287  
 288                  if ( model ) {
 289                      options.data.user = model;
 290                  }
 291  
 292                  return bp.ajax.send( options );
 293              }
 294          },
 295  
 296          parse: function( resp ) {
 297  
 298              if ( ! _.isArray( resp.users ) ) {
 299                  resp.users = [resp.users];
 300              }
 301  
 302              _.each( resp.users, function( value, index ) {
 303                  if ( _.isNull( value ) ) {
 304                      return;
 305                  }
 306  
 307                  resp.users[index].id = value.id;
 308                  resp.users[index].avatar = value.avatar;
 309                  resp.users[index].name = value.name;
 310              } );
 311  
 312              if ( ! _.isUndefined( resp.meta ) ) {
 313                  this.options.page = resp.meta.page;
 314                  this.options.total_page = resp.meta.total_page;
 315              }
 316  
 317              return resp.users;
 318          }
 319  
 320      } );
 321  
 322      // Extend wp.Backbone.View with .prepare() and .inject()
 323      bp.Nouveau.GroupInvites.View = bp.Backbone.View.extend( {
 324          inject: function( selector ) {
 325              this.render();
 326              $(selector).html( this.el );
 327              this.views.ready();
 328          },
 329  
 330          prepare: function() {
 331              if ( ! _.isUndefined( this.model ) && _.isFunction( this.model.toJSON ) ) {
 332                  return this.model.toJSON();
 333              } else {
 334                  return {};
 335              }
 336          }
 337      } );
 338  
 339      // Feedback view
 340      bp.Views.Feedback = bp.Nouveau.GroupInvites.View.extend( {
 341          tagName   : 'div',
 342          className : 'bp-invites-feedback',
 343          template  : bp.template( 'bp-group-invites-feedback' ),
 344  
 345          initialize: function() {
 346              this.model = new Backbone.Model( {
 347                  type: this.options.type || 'info',
 348                  message: this.options.value
 349              } );
 350          }
 351      } );
 352  
 353      bp.Views.invitesNav = bp.Nouveau.GroupInvites.View.extend( {
 354          tagName: 'ul',
 355          className: 'subnav',
 356  
 357          events: {
 358              'click .bp-invites-nav-item' : 'toggleView'
 359          },
 360  
 361          initialize: function() {
 362              this.collection.on( 'add', this.outputNav, this );
 363              this.collection.on( 'change:hide', this.showHideNavItem, this );
 364  
 365              window.onbeforeunload = _.bind( this.confirmQuit, this );
 366          },
 367  
 368          outputNav: function( nav ) {
 369              /**
 370               * The delete nav is not added if no avatar
 371               * is set for the object
 372               */
 373              if ( 1 === nav.get( 'hide' ) ) {
 374                  return;
 375              }
 376  
 377              this.views.add( new bp.Views.invitesNavItem( { model: nav } ) );
 378          },
 379  
 380          showHideNavItem: function( item ) {
 381              var isRendered = null;
 382  
 383              /**
 384               * Loop in views to show/hide the nav item
 385               * BuddyPress is only using this for the delete nav
 386               */
 387              _.each( this.views._views[''], function( view ) {
 388                  if ( 1 === view.model.get( 'hide' ) ) {
 389                      view.remove();
 390                  }
 391  
 392                  // Check to see if the nav is not already rendered
 393                  if ( item.get( 'id' ) === view.model.get( 'id' ) ) {
 394                      isRendered = true;
 395                  }
 396              } );
 397  
 398              // Add the Delete nav if not rendered
 399              if ( ! _.isBoolean( isRendered ) ) {
 400                  item.set( 'invites_count', bp.Nouveau.GroupInvites.invites.length );
 401                  this.outputNav( item );
 402              }
 403          },
 404  
 405          toggleView: function( event ) {
 406              var target = $( event.target );
 407              event.preventDefault();
 408  
 409              if ( ! target.data( 'nav' ) && 'SPAN' === event.target.tagName ) {
 410                  target = $( event.target ).parent();
 411              }
 412  
 413              var current_nav_id = target.data( 'nav' );
 414  
 415              _.each( this.collection.models, function( nav ) {
 416                  if ( nav.id === current_nav_id ) {
 417                      nav.set( 'active', 1 );
 418  
 419                      // Specific to the invites view
 420                      if ( 'invites' === nav.id ) {
 421                          this.trigger( 'bp-invites:confirm' );
 422                      } else {
 423                          this.trigger( 'bp-invites:loops', nav.id );
 424                      }
 425  
 426                  } else if ( 1 !== nav.get( 'hide' ) ) {
 427                      nav.set( 'active', 0 );
 428                  }
 429              }, this );
 430          },
 431  
 432          confirmQuit: function() {
 433              if ( bp.Nouveau.GroupInvites.invites && bp.Nouveau.GroupInvites.invites.length ) {
 434                  $( '[data-nav="invites"]' ).focus();
 435  
 436                  return false;
 437              }
 438          }
 439      } );
 440  
 441      bp.Views.invitesNavItem = bp.Nouveau.GroupInvites.View.extend( {
 442          tagName  : 'li',
 443          template : bp.template( 'bp-invites-nav' ),
 444  
 445          initialize: function() {
 446              if ( 1 === this.model.get( 'active' ) ) {
 447                  this.el.className += ' current';
 448              }
 449  
 450              if ( 'invites' === this.model.get( 'id' ) ) {
 451                  this.el.className += ' dynamic';
 452              }
 453  
 454              if ( 'invited' === this.model.get( 'id' ) ) {
 455                  this.el.className += ' pending';
 456              }
 457  
 458              this.model.on( 'change:active', this.toggleClass, this );
 459              this.on( 'ready', this.updateCount, this );
 460  
 461              bp.Nouveau.GroupInvites.invites.on( 'add', this.updateCount, this );
 462              bp.Nouveau.GroupInvites.invites.on( 'remove', this.updateCount, this );
 463          },
 464  
 465          updateCount: function( user, invite ) {
 466              if ( 'invites' !== this.model.get( 'id' ) ) {
 467                  return;
 468              }
 469  
 470              var span_count = _.isUndefined( invite ) ? this.model.get( 'invites_count' ) : invite.models.length;
 471  
 472              if ( $( this.el ).find( 'span' ).length ) {
 473                  $( this.el ).find( 'span' ).html( span_count );
 474              } else {
 475                  $( this.el ).find( 'a' ).append( $( '<span class="count"></span>' ).html( span_count ) );
 476              }
 477          },
 478  
 479          toggleClass: function( model ) {
 480              if ( 0 === model.get( 'active' ) ) {
 481                  $( this.el ).removeClass( 'current' );
 482              } else {
 483                  $( this.el ).addClass( 'current' );
 484              }
 485          }
 486      } );
 487  
 488      bp.Views.Pagination = bp.Nouveau.GroupInvites.View.extend( {
 489          tagName   : 'div',
 490          className : 'last',
 491          template  :  bp.template( 'bp-invites-paginate' )
 492      } );
 493  
 494      bp.Views.inviteFilters = bp.Nouveau.GroupInvites.View.extend( {
 495          tagName: 'div',
 496          template:  bp.template( 'bp-invites-filters' ),
 497  
 498          events : {
 499              'search #group_invites_search'      : 'resetSearchTerms',
 500              'submit #group_invites_search_form' : 'setSearchTerms',
 501              'click #bp-invites-next-page'       : 'nextPage',
 502              'click #bp-invites-prev-page'       : 'prevPage'
 503          },
 504  
 505          initialize: function() {
 506              this.model.on( 'change', this.filterUsers, this );
 507              this.options.users.on( 'sync', this.addPaginatation, this );
 508          },
 509  
 510          addPaginatation: function( collection ) {
 511              _.each( this.views._views[''], function( view ) {
 512                  view.remove();
 513              } );
 514  
 515              if ( 1 === collection.options.total_page ) {
 516                  return;
 517              }
 518  
 519              this.views.add( new bp.Views.Pagination( { model: new Backbone.Model( collection.options ) } ) );
 520          },
 521  
 522          filterUsers: function() {
 523              bp.Nouveau.GroupInvites.displayFeedback( BP_Nouveau.group_invites.loading, 'loading' );
 524  
 525              this.options.users.reset();
 526  
 527              this.options.users.fetch( {
 528                  data    : _.pick( this.model.attributes, ['scope', 'search_terms', 'page'] ),
 529                  success : this.usersFiltered,
 530                  error   : this.usersFilterError
 531              } );
 532          },
 533  
 534          usersFiltered: function() {
 535              bp.Nouveau.GroupInvites.removeFeedback();
 536          },
 537  
 538          usersFilterError: function( collection, response ) {
 539              var type = 'error';
 540  
 541              if ( response.type ) {
 542                  type = response.type;
 543              }
 544  
 545              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, type );
 546          },
 547  
 548          resetSearchTerms: function( event ) {
 549              event.preventDefault();
 550  
 551              if ( ! $( event.target ).val() ) {
 552                  $( event.target ).closest( 'form' ).submit();
 553              } else {
 554                  $( event.target ).closest( 'form' ).find( '[type=submit]' ).addClass('bp-show');
 555              }
 556          },
 557  
 558          setSearchTerms: function( event ) {
 559              event.preventDefault();
 560  
 561              this.model.set( {
 562                  search_terms : $( event.target ).find( 'input[type=search]' ).val() || '',
 563                  page         : 1
 564              } );
 565          },
 566  
 567          nextPage: function( event ) {
 568              event.preventDefault();
 569  
 570              this.model.set( 'page', this.model.get( 'page' ) + 1 );
 571          },
 572  
 573          prevPage: function( event ) {
 574              event.preventDefault();
 575  
 576              this.model.set( 'page', this.model.get( 'page' ) - 1 );
 577          }
 578      } );
 579  
 580      bp.Views.inviteUsers = bp.Nouveau.GroupInvites.View.extend( {
 581          tagName   : 'ul',
 582          className : 'item-list bp-list',
 583          id        : 'members-list',
 584  
 585          initialize: function() {
 586              // Load users for the active view
 587              this.requestUsers();
 588  
 589              this.collection.on( 'reset', this.cleanContent, this );
 590              this.collection.on( 'add', this.addUser, this );
 591          },
 592  
 593          requestUsers: function() {
 594              this.collection.reset();
 595  
 596              this.collection.fetch( {
 597                  data    : _.pick( this.options, 'scope' ),
 598                  success : this.usersFetched,
 599                  error   : this.usersFetchError
 600              } );
 601          },
 602  
 603          usersFetched: function( collection, response ) {
 604              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'help' );
 605          },
 606  
 607          usersFetchError: function( collection, response ) {
 608              var type = response.type || 'help';
 609  
 610              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, type );
 611          },
 612  
 613          cleanContent: function() {
 614              _.each( this.views._views[''], function( view ) {
 615                  view.remove();
 616              } );
 617          },
 618  
 619          addUser: function( user ) {
 620              this.views.add( new bp.Views.inviteUser( { model: user } ) );
 621          }
 622      } );
 623  
 624      bp.Views.inviteUser = bp.Nouveau.GroupInvites.View.extend( {
 625          tagName  : 'li',
 626          template : bp.template( 'bp-invites-users' ),
 627  
 628          events: {
 629              'click .group-add-remove-invite-button'    : 'toggleUser',
 630              'click .group-remove-invite-button'        : 'removeInvite'
 631          },
 632  
 633          initialize: function() {
 634              var invite = bp.Nouveau.GroupInvites.invites.get( this.model.get( 'id' ) );
 635  
 636              if ( invite ) {
 637                  this.model.set( 'selected', true, { silent: true } );
 638              }
 639          },
 640  
 641          render: function() {
 642              if ( this.model.get( 'selected' ) ) {
 643                  this.el.className = 'selected';
 644              } else {
 645                  this.el.className = '';
 646              }
 647  
 648              bp.Nouveau.GroupInvites.View.prototype.render.apply( this, arguments );
 649          },
 650  
 651          toggleUser: function( event ) {
 652              event.preventDefault();
 653  
 654              var selected = this.model.get( 'selected' );
 655  
 656              if ( false === selected ) {
 657                  this.model.set( 'selected', true );
 658              } else {
 659                  this.model.set( 'selected', false );
 660  
 661                  if ( ! bp.Nouveau.GroupInvites.invites.length  ) {
 662                      bp.Nouveau.GroupInvites.invites.reset();
 663                  }
 664              }
 665  
 666              // Rerender to update buttons.
 667              this.render();
 668          },
 669  
 670          removeInvite: function( event ) {
 671              event.preventDefault();
 672  
 673              var collection = this.model.collection;
 674  
 675              if ( ! collection.length ) {
 676                  return;
 677              }
 678  
 679              collection.sync( 'delete', this.model.get( 'id' ), {
 680                  success : _.bind( this.inviteRemoved, this ),
 681                  error   : _.bind( this.uninviteError, this )
 682              } );
 683          },
 684  
 685          inviteRemoved: function( response ) {
 686              var collection = this.model.collection;
 687  
 688              if ( ! collection.length ) {
 689                  return;
 690              }
 691  
 692              collection.remove( this.model );
 693              this.remove();
 694  
 695              bp.Nouveau.GroupInvites.removeFeedback();
 696  
 697              if ( false === response.has_invites ) {
 698                  bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'success' );
 699  
 700                  // Hide the invited nav
 701                  bp.Nouveau.GroupInvites.navItems.get( 'invited' ).set( { active: 0, hide: 1 } );
 702              }
 703          },
 704  
 705          uninviteError: function( response ) {
 706              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'error' );
 707          }
 708      } );
 709  
 710      bp.Views.invitesEditor = bp.Nouveau.GroupInvites.View.extend( {
 711          tagName : 'div',
 712          id      : 'send-invites-editor',
 713  
 714          events: {
 715              'click #bp-invites-send'  : 'sendInvites',
 716              'click #bp-invites-reset' : 'clearForm'
 717          },
 718  
 719          initialize: function() {
 720              this.views.add( new bp.Views.selectedUsers( { collection: this.collection } ) );
 721              this.views.add( new bp.Views.invitesForm() );
 722  
 723              this.collection.on( 'reset', this.cleanViews, this );
 724          },
 725  
 726          sendInvites: function( event ) {
 727              event.preventDefault();
 728  
 729              $( this.el ).addClass( 'bp-hide' );
 730  
 731              bp.Nouveau.GroupInvites.displayFeedback( BP_Nouveau.group_invites.invites_sending, 'info' );
 732  
 733              this.collection.sync( 'create', _.pluck( this.collection.models, 'id' ), {
 734                  success : _.bind( this.invitesSent, this ),
 735                  error   : _.bind( this.invitesError, this ),
 736                  data    : {
 737                      message: $( this.el ).find( 'textarea' ).val()
 738                  }
 739              } );
 740          },
 741  
 742          invitesSent: function( response ) {
 743              this.collection.reset();
 744  
 745              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'success' );
 746  
 747              // Display the pending invites
 748              if ( 1 === bp.Nouveau.GroupInvites.navItems.get( 'invited' ).get( 'hide' ) && ! BP_Nouveau.group_invites.is_group_create ) {
 749                  bp.Nouveau.GroupInvites.navItems.get( 'invited' ).set( { active: 0, hide: 0 } );
 750              }
 751          },
 752  
 753          invitesError: function( response ) {
 754              var type = response.type || 'help';
 755  
 756              $( this.el ).removeClass( 'bp-hide' );
 757  
 758              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, type );
 759  
 760              if ( ! _.isUndefined( response.users ) ) {
 761                  // Display the pending invites
 762                  if ( 1 === bp.Nouveau.GroupInvites.navItems.get( 'invited' ).get( 'hide' ) && response.users.length < this.collection.length ) {
 763                      bp.Nouveau.GroupInvites.navItems.get( 'invited' ).set( { active: 0, hide: 0 } );
 764                  }
 765  
 766                  _.each( this.collection.models, function( invite ) {
 767                      // If not an error, remove from the selection
 768                      if ( -1 === _.indexOf( response.users, invite.get( 'id' ) ) ) {
 769                          invite.set( 'selected', false );
 770                      }
 771                  }, this );
 772              }
 773          },
 774  
 775          clearForm: function( event ) {
 776              event.preventDefault();
 777  
 778              this.collection.reset();
 779          },
 780  
 781          cleanViews: function() {
 782              _.each( this.views._views[''], function( view ) {
 783                  view.remove();
 784              } );
 785  
 786              bp.Nouveau.GroupInvites.displayFeedback( BP_Nouveau.group_invites.invites_form_reset, 'success' );
 787          }
 788      } );
 789  
 790      bp.Views.invitesForm = bp.Nouveau.GroupInvites.View.extend( {
 791          tagName  : 'div',
 792          id       : 'bp-send-invites-form',
 793          template :  bp.template( 'bp-invites-form' )
 794      } );
 795  
 796      bp.Views.selectedUsers = bp.Nouveau.GroupInvites.View.extend( {
 797          tagName : 'ul',
 798  
 799          initialize: function() {
 800              this.cleanContent();
 801  
 802              _.each( this.collection.models, function( invite ) {
 803                  this.views.add( new bp.Views.selectedUser( { model: invite } ) );
 804              }, this );
 805          },
 806  
 807          cleanContent: function() {
 808              _.each( this.views._views[''], function( view ) {
 809                  view.remove();
 810              } );
 811          }
 812      } );
 813  
 814      bp.Views.selectedUser = bp.Nouveau.GroupInvites.View.extend( {
 815          tagName  : 'li',
 816          template : bp.template( 'bp-invites-selection' ),
 817  
 818          events: {
 819              click : 'removeSelection'
 820          },
 821  
 822          initialize: function() {
 823              this.model.on( 'change:selected', this.removeView, this );
 824  
 825              // Build the BP Tooltip.
 826              if ( ! this.model.get( 'uninviteTooltip' ) ) {
 827                  this.model.set( 'uninviteTooltip',
 828                      BP_Nouveau.group_invites.removeUserInvite.replace( '%s', this.model.get( 'name' ) ),
 829                      { silent: true }
 830                  );
 831              }
 832  
 833              this.el.id = 'uninvite-user-' + this.model.get( 'id' );
 834          },
 835  
 836          removeSelection: function( event ) {
 837              event.preventDefault();
 838  
 839              this.model.set( 'selected', false );
 840          },
 841  
 842          removeView: function( model ) {
 843              if ( false !== model.get( 'selected' ) ) {
 844                  return;
 845              }
 846  
 847              this.remove();
 848          }
 849      } );
 850  
 851      // Launch BP Nouveau Groups
 852      bp.Nouveau.GroupInvites.start();
 853  
 854  } )( window.bp, jQuery );


Generated: Fri Apr 19 01:01:08 2024 Cross-referenced by PHPXref 0.7.1