// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var utils = require('../utils/utils.jsx'); var client = require('../utils/client.jsx'); var UserStore = require('../stores/user_store.jsx'); var TeamStore = require('../stores/team_store.jsx'); var Constants = require('../utils/constants.jsx'); function getStateFromStores() { return {teams: UserStore.getTeams(), currentTeam: TeamStore.getCurrent()}; } var NavbarDropdown = React.createClass({ handleLogoutClick: function(e) { e.preventDefault(); client.logout(); }, blockToggle: false, componentDidMount: function() { UserStore.addTeamsChangeListener(this.onListenerChange); TeamStore.addChangeListener(this.onListenerChange); var self = this; $(this.refs.dropdown.getDOMNode()).on('hide.bs.dropdown', function() { self.blockToggle = true; setTimeout(function() { self.blockToggle = false; }, 100); }); }, componentWillUnmount: function() { UserStore.removeTeamsChangeListener(this.onListenerChange); TeamStore.removeChangeListener(this.onListenerChange); $(this.refs.dropdown.getDOMNode()).off('hide.bs.dropdown'); }, onListenerChange: function() { if (this.isMounted()) { var newState = getStateFromStores(); if (!utils.areStatesEqual(newState, this.state)) { this.setState(newState); } } }, getInitialState: function() { return getStateFromStores(); }, render: function() { var teamLink = ''; var inviteLink = ''; var manageLink = ''; var currentUser = UserStore.getCurrentUser(); var isAdmin = false; var teamSettings = null; if (currentUser != null) { isAdmin = currentUser.roles.indexOf('admin') > -1; inviteLink = (