// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var client = require('../utils/client.jsx'); var AsyncClient = require('../utils/async_client.jsx'); var UserStore = require('../stores/user_store.jsx'); var ChannelStore = require('../stores/channel_store.jsx'); var TeamStore = require('../stores/team_store.jsx'); var MessageWrapper = require('./message_wrapper.jsx'); var NotifyCounts = require('./notify_counts.jsx'); var Constants = require('../utils/constants.jsx'); var ActionTypes = Constants.ActionTypes; var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); function getStateFromStores() { return { channel: ChannelStore.getCurrent(), member: ChannelStore.getCurrentMember(), users: ChannelStore.getCurrentExtraInfo().members }; } module.exports = React.createClass({ displayName: 'Navbar', propTypes: { teamDisplayName: React.PropTypes.string }, componentDidMount: function() { ChannelStore.addChangeListener(this.onListenerChange); ChannelStore.addExtraInfoChangeListener(this.onListenerChange); $('.inner__wrap').click(this.hideSidebars); $('body').on('click.infopopover', function handlePopoverClick(e) { if ($(e.target).attr('data-toggle') !== 'popover' && $(e.target).parents('.popover.in').length === 0) { $('.info-popover').popover('hide'); } }); }, componentWillUnmount: function() { ChannelStore.removeChangeListener(this.onListenerChange); }, handleSubmit: function(e) { e.preventDefault(); }, handleLeave: function() { client.leaveChannel(this.state.channel.id, function success() { AsyncClient.getChannels(true); window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/town-square'; }, function error(err) { AsyncClient.dispatchError(err, 'handleLeave'); } ); }, hideSidebars: function(e) { var windowWidth = $(window).outerWidth(); if (windowWidth <= 768) { AppDispatcher.handleServerAction({ type: ActionTypes.RECIEVED_SEARCH, results: null }); AppDispatcher.handleServerAction({ type: ActionTypes.RECIEVED_POST_SELECTED, results: null }); if (e.target.className !== 'navbar-toggle' && e.target.className !== 'icon-bar') { $('.inner__wrap').removeClass('move--right move--left move--left-small'); $('.sidebar--left').removeClass('move--right'); $('.sidebar--right').removeClass('move--left'); $('.sidebar--menu').removeClass('move--left'); } } }, toggleLeftSidebar: function() { $('.inner__wrap').toggleClass('move--right'); $('.sidebar--left').toggleClass('move--right'); }, toggleRightSidebar: function() { $('.inner__wrap').toggleClass('move--left-small'); $('.sidebar--menu').toggleClass('move--left'); }, onListenerChange: function() { this.setState(getStateFromStores()); $('#navbar .navbar-brand .description').popover({placement: 'bottom', trigger: 'click', html: true}); }, getInitialState: function() { return getStateFromStores(); }, render: function() { var currentId = UserStore.getCurrentId(); var popoverContent = ''; var channelTitle = this.props.teamDisplayName; var isAdmin = false; var isDirect = false; var channel = this.state.channel; if (channel) { popoverContent = React.renderToString(); isAdmin = this.state.member.roles.indexOf('admin') > -1; if (channel.type === 'O') { channelTitle = channel.display_name; } else if (channel.type === 'P') { channelTitle = channel.display_name; } else if (channel.type === 'D') { isDirect = true; if (this.state.users.length > 1) { if (this.state.users[0].id === currentId) { channelTitle = UserStore.getProfile(this.state.users[1].id).username; } else { channelTitle = UserStore.getProfile(this.state.users[0].id).username; } } } if (channel.description.length === 0) { popoverContent = React.renderToString(
No channel description yet.
Click here to add one.
); } } var navbarCollapseButton = null; if (currentId == null) { navbarCollapseButton = (); } var sidebarCollapseButton = null; if (currentId != null) { sidebarCollapseButton = (); } var rightSidebarCollapseButton = null; if (currentId != null) { rightSidebarCollapseButton = (); } var channelMenuDropdown = null; if (channel) { var viewInfoOption =
  • View Info
  • var addMembersOption = null; if (!isDirect && !ChannelStore.isDefault(channel)) { addMembersOption =
  • Add Members
  • ; } var manageMembersOption = null; if (!isDirect && isAdmin && !ChannelStore.isDefault(channel)) { manageMembersOption =
  • Manage Members
  • ; } var setChannelDescriptionOption =
  • Set Channel Description...
  • ; var notificationPreferenceOption = null; if (!isDirect) { notificationPreferenceOption =
  • Notification Preferences
  • ; } var renameChannelOption = null; if (!isDirect && isAdmin && !ChannelStore.isDefault(channel)) { renameChannelOption =
  • Rename Channel...
  • ; } var deleteChannelOption = null; if (!isDirect && isAdmin && !ChannelStore.isDefault(channel)) { deleteChannelOption =
  • Delete Channel...
  • ; } var leaveChannelOption = null; if (!isDirect && !ChannelStore.isDefault(channel)) { leaveChannelOption =
  • Leave Channel
  • ; } channelMenuDropdown = (
    {channelTitle}
      {viewInfoOption} {addMembersOption} {manageMembersOption} {setChannelDescriptionOption} {notificationPreferenceOption} {renameChannelOption} {deleteChannelOption} {leaveChannelOption}
    ); } else { channelMenuDropdown = (
    {channelTitle}
    ); } return ( ); } });