[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Mon Nov 18 01:01:37 2019 Cross-referenced by PHPXref 0.7.1