[ 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 viex
 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              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'error' );
 540          },
 541  
 542          resetSearchTerms: function( event ) {
 543              event.preventDefault();
 544  
 545              if ( ! $( event.target ).val() ) {
 546                  $( event.target ).closest( 'form' ).submit();
 547              } else {
 548                  $( event.target ).closest( 'form' ).find( '[type=submit]' ).addClass('bp-show');
 549              }
 550          },
 551  
 552          setSearchTerms: function( event ) {
 553              event.preventDefault();
 554  
 555              this.model.set( {
 556                  search_terms : $( event.target ).find( 'input[type=search]' ).val() || '',
 557                  page         : 1
 558              } );
 559          },
 560  
 561          nextPage: function( event ) {
 562              event.preventDefault();
 563  
 564              this.model.set( 'page', this.model.get( 'page' ) + 1 );
 565          },
 566  
 567          prevPage: function( event ) {
 568              event.preventDefault();
 569  
 570              this.model.set( 'page', this.model.get( 'page' ) - 1 );
 571          }
 572      } );
 573  
 574      bp.Views.inviteUsers = bp.Nouveau.GroupInvites.View.extend( {
 575          tagName   : 'ul',
 576          className : 'item-list bp-list',
 577          id        : 'members-list',
 578  
 579          initialize: function() {
 580              // Load users for the active view
 581              this.requestUsers();
 582  
 583              this.collection.on( 'reset', this.cleanContent, this );
 584              this.collection.on( 'add', this.addUser, this );
 585          },
 586  
 587          requestUsers: function() {
 588              this.collection.reset();
 589  
 590              this.collection.fetch( {
 591                  data    : _.pick( this.options, 'scope' ),
 592                  success : this.usersFetched,
 593                  error   : this.usersFetchError
 594              } );
 595          },
 596  
 597          usersFetched: function( collection, response ) {
 598              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'help' );
 599          },
 600  
 601          usersFetchError: function( collection, response ) {
 602              var type = response.type || 'help';
 603  
 604              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, type );
 605          },
 606  
 607          cleanContent: function() {
 608              _.each( this.views._views[''], function( view ) {
 609                  view.remove();
 610              } );
 611          },
 612  
 613          addUser: function( user ) {
 614              this.views.add( new bp.Views.inviteUser( { model: user } ) );
 615          }
 616      } );
 617  
 618      bp.Views.inviteUser = bp.Nouveau.GroupInvites.View.extend( {
 619          tagName  : 'li',
 620          template : bp.template( 'bp-invites-users' ),
 621  
 622          events: {
 623              'click .group-add-remove-invite-button'    : 'toggleUser',
 624              'click .group-remove-invite-button'        : 'removeInvite'
 625          },
 626  
 627          initialize: function() {
 628              var invite = bp.Nouveau.GroupInvites.invites.get( this.model.get( 'id' ) );
 629  
 630              if ( invite ) {
 631                  this.model.set( 'selected', true, { silent: true } );
 632              }
 633          },
 634  
 635          render: function() {
 636              if ( this.model.get( 'selected' ) ) {
 637                  this.el.className = 'selected';
 638              } else {
 639                  this.el.className = '';
 640              }
 641  
 642              bp.Nouveau.GroupInvites.View.prototype.render.apply( this, arguments );
 643          },
 644  
 645          toggleUser: function( event ) {
 646              event.preventDefault();
 647  
 648              var selected = this.model.get( 'selected' );
 649  
 650              if ( false === selected ) {
 651                  this.model.set( 'selected', true );
 652              } else {
 653                  this.model.set( 'selected', false );
 654  
 655                  if ( ! bp.Nouveau.GroupInvites.invites.length  ) {
 656                      bp.Nouveau.GroupInvites.invites.reset();
 657                  }
 658              }
 659  
 660              // Rerender to update buttons.
 661              this.render();
 662          },
 663  
 664          removeInvite: function( event ) {
 665              event.preventDefault();
 666  
 667              var collection = this.model.collection;
 668  
 669              if ( ! collection.length ) {
 670                  return;
 671              }
 672  
 673              collection.sync( 'delete', this.model.get( 'id' ), {
 674                  success : _.bind( this.inviteRemoved, this ),
 675                  error   : _.bind( this.uninviteError, this )
 676              } );
 677          },
 678  
 679          inviteRemoved: function( response ) {
 680              var collection = this.model.collection;
 681  
 682              if ( ! collection.length ) {
 683                  return;
 684              }
 685  
 686              collection.remove( this.model );
 687              this.remove();
 688  
 689              bp.Nouveau.GroupInvites.removeFeedback();
 690  
 691              if ( false === response.has_invites ) {
 692                  bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'success' );
 693  
 694                  // Hide the invited nav
 695                  bp.Nouveau.GroupInvites.navItems.get( 'invited' ).set( { active: 0, hide: 1 } );
 696              }
 697          },
 698  
 699          uninviteError: function( response ) {
 700              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'error' );
 701          }
 702      } );
 703  
 704      bp.Views.invitesEditor = bp.Nouveau.GroupInvites.View.extend( {
 705          tagName : 'div',
 706          id      : 'send-invites-editor',
 707  
 708          events: {
 709              'click #bp-invites-send'  : 'sendInvites',
 710              'click #bp-invites-reset' : 'clearForm'
 711          },
 712  
 713          initialize: function() {
 714              this.views.add( new bp.Views.selectedUsers( { collection: this.collection } ) );
 715              this.views.add( new bp.Views.invitesForm() );
 716  
 717              this.collection.on( 'reset', this.cleanViews, this );
 718          },
 719  
 720          sendInvites: function( event ) {
 721              event.preventDefault();
 722  
 723              $( this.el ).addClass( 'bp-hide' );
 724  
 725              bp.Nouveau.GroupInvites.displayFeedback( BP_Nouveau.group_invites.invites_sending, 'info' );
 726  
 727              this.collection.sync( 'create', _.pluck( this.collection.models, 'id' ), {
 728                  success : _.bind( this.invitesSent, this ),
 729                  error   : _.bind( this.invitesError, this ),
 730                  data    : {
 731                      message: $( this.el ).find( 'textarea' ).val()
 732                  }
 733              } );
 734          },
 735  
 736          invitesSent: function( response ) {
 737              this.collection.reset();
 738  
 739              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, 'success' );
 740  
 741              // Display the pending invites
 742              if ( 1 === bp.Nouveau.GroupInvites.navItems.get( 'invited' ).get( 'hide' ) && ! BP_Nouveau.group_invites.is_group_create ) {
 743                  bp.Nouveau.GroupInvites.navItems.get( 'invited' ).set( { active: 0, hide: 0 } );
 744              }
 745          },
 746  
 747          invitesError: function( response ) {
 748              var type = response.type || 'help';
 749  
 750              $( this.el ).removeClass( 'bp-hide' );
 751  
 752              bp.Nouveau.GroupInvites.displayFeedback( response.feedback, type );
 753  
 754              if ( ! _.isUndefined( response.users ) ) {
 755                  // Display the pending invites
 756                  if ( 1 === bp.Nouveau.GroupInvites.navItems.get( 'invited' ).get( 'hide' ) && response.users.length < this.collection.length ) {
 757                      bp.Nouveau.GroupInvites.navItems.get( 'invited' ).set( { active: 0, hide: 0 } );
 758                  }
 759  
 760                  _.each( this.collection.models, function( invite ) {
 761                      // If not an error, remove from the selection
 762                      if ( -1 === _.indexOf( response.users, invite.get( 'id' ) ) ) {
 763                          invite.set( 'selected', false );
 764                      }
 765                  }, this );
 766              }
 767          },
 768  
 769          clearForm: function( event ) {
 770              event.preventDefault();
 771  
 772              this.collection.reset();
 773          },
 774  
 775          cleanViews: function() {
 776              _.each( this.views._views[''], function( view ) {
 777                  view.remove();
 778              } );
 779  
 780              bp.Nouveau.GroupInvites.displayFeedback( BP_Nouveau.group_invites.invites_form_reset, 'success' );
 781          }
 782      } );
 783  
 784      bp.Views.invitesForm = bp.Nouveau.GroupInvites.View.extend( {
 785          tagName  : 'div',
 786          id       : 'bp-send-invites-form',
 787          template :  bp.template( 'bp-invites-form' )
 788      } );
 789  
 790      bp.Views.selectedUsers = bp.Nouveau.GroupInvites.View.extend( {
 791          tagName : 'ul',
 792  
 793          initialize: function() {
 794              this.cleanContent();
 795  
 796              _.each( this.collection.models, function( invite ) {
 797                  this.views.add( new bp.Views.selectedUser( { model: invite } ) );
 798              }, this );
 799          },
 800  
 801          cleanContent: function() {
 802              _.each( this.views._views[''], function( view ) {
 803                  view.remove();
 804              } );
 805          }
 806      } );
 807  
 808      bp.Views.selectedUser = bp.Nouveau.GroupInvites.View.extend( {
 809          tagName  : 'li',
 810          template : bp.template( 'bp-invites-selection' ),
 811  
 812          events: {
 813              click : 'removeSelection'
 814          },
 815  
 816          initialize: function() {
 817              this.model.on( 'change:selected', this.removeView, this );
 818  
 819              // Build the BP Tooltip.
 820              if ( ! this.model.get( 'uninviteTooltip' ) ) {
 821                  this.model.set( 'uninviteTooltip',
 822                      BP_Nouveau.group_invites.removeUserInvite.replace( '%s', this.model.get( 'name' ) ),
 823                      { silent: true }
 824                  );
 825              }
 826  
 827              this.el.id = 'uninvite-user-' + this.model.get( 'id' );
 828          },
 829  
 830          removeSelection: function( event ) {
 831              event.preventDefault();
 832  
 833              this.model.set( 'selected', false );
 834          },
 835  
 836          removeView: function( model ) {
 837              if ( false !== model.get( 'selected' ) ) {
 838                  return;
 839              }
 840  
 841              this.remove();
 842          }
 843      } );
 844  
 845      // Launch BP Nouveau Groups
 846      bp.Nouveau.GroupInvites.start();
 847  
 848  } )( window.bp, jQuery );


Generated: Thu May 13 01:01:37 2021 Cross-referenced by PHPXref 0.7.1