// Copyright (c) 2015 Mattermost, 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'); const Utils = require('../utils/utils.jsx'); var Constants = require('../utils/constants.jsx'); var ActionTypes = Constants.ActionTypes; var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); var Popover = ReactBootstrap.Popover; var OverlayTrigger = ReactBootstrap.OverlayTrigger; export default class Navbar extends React.Component { constructor(props) { super(props); this.onChange = this.onChange.bind(this); this.handleLeave = this.handleLeave.bind(this); this.createCollapseButtons = this.createCollapseButtons.bind(this); this.createDropdown = this.createDropdown.bind(this); this.state = this.getStateFromStores(); } getStateFromStores() { return { channel: ChannelStore.getCurrent(), member: ChannelStore.getCurrentMember(), users: ChannelStore.getCurrentExtraInfo().members }; } componentDidMount() { ChannelStore.addChangeListener(this.onChange); ChannelStore.addExtraInfoChangeListener(this.onChange); $('.inner__wrap').click(this.hideSidebars); } componentWillUnmount() { ChannelStore.removeChangeListener(this.onChange); } handleSubmit(e) { e.preventDefault(); } handleLeave() { 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(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() { $('.inner__wrap').toggleClass('move--right'); $('.sidebar--left').toggleClass('move--right'); } toggleRightSidebar() { $('.inner__wrap').toggleClass('move--left-small'); $('.sidebar--menu').toggleClass('move--left'); } onChange() { this.setState(this.getStateFromStores()); $('#navbar .navbar-brand .description').popover({placement: 'bottom', trigger: 'click', html: true}); } createDropdown(channel, channelTitle, isAdmin, isDirect, popoverContent) { if (channel) { var viewInfoOption = (
  • View Info
  • ); var setChannelDescriptionOption = (
  • Set Channel Description...
  • ); var addMembersOption; var leaveChannelOption; if (!isDirect && !ChannelStore.isDefault(channel)) { addMembersOption = (
  • Add Members
  • ); leaveChannelOption = (
  • Leave Channel
  • ); } var manageMembersOption; var renameChannelOption; var deleteChannelOption; if (!isDirect && isAdmin && !ChannelStore.isDefault(channel)) { manageMembersOption = (
  • Manage Members
  • ); renameChannelOption = (
  • Rename Channel...
  • ); deleteChannelOption = (
  • Delete Channel...
  • ); } var notificationPreferenceOption; if (!isDirect) { notificationPreferenceOption = (
  • Notification Preferences
  • ); } return (
    {channelTitle}
      {viewInfoOption} {addMembersOption} {manageMembersOption} {setChannelDescriptionOption} {notificationPreferenceOption} {renameChannelOption} {deleteChannelOption} {leaveChannelOption}
    ); } return (
    {channelTitle}
    ); } createCollapseButtons(currentId) { var buttons = []; if (currentId == null) { buttons.push( ); } else { buttons.push( ); buttons.push( ); } return buttons; } render() { var currentId = UserStore.getCurrentId(); var channel = this.state.channel; var channelTitle = this.props.teamDisplayName; var popoverContent; var isAdmin = false; var isDirect = false; if (channel) { popoverContent = ( ); isAdmin = Utils.isAdmin(this.state.member.roles); 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 = (
    {'No channel description yet.'}
    {'Click here'} {' to add one.'}
    ); } } var collapseButtons = this.createCollapseButtons(currentId); var channelMenuDropdown = this.createDropdown(channel, channelTitle, isAdmin, isDirect, popoverContent); return ( ); } } Navbar.defaultProps = { teamDisplayName: '' }; Navbar.propTypes = { teamDisplayName: React.PropTypes.string };