// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import ReactDOM from 'react-dom'; import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; import UserStore from 'stores/user_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import PreferenceStore from 'stores/preference_store.jsx'; import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl'; import {Modal} from 'react-bootstrap'; const holders = defineMessages({ nameEx: { id: 'channel_modal.nameEx', defaultMessage: 'E.g.: "Bugs", "Marketing", "客户支持"' } }); import React from 'react'; class NewChannelModal extends React.Component { constructor(props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); this.handleChange = this.handleChange.bind(this); this.onEnterKeyDown = this.onEnterKeyDown.bind(this); this.onPreferenceChange = this.onPreferenceChange.bind(this); this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'); this.state = { displayNameError: '' }; } componentWillReceiveProps(nextProps) { if (nextProps.show === true && this.props.show === false) { this.setState({ displayNameError: '' }); document.addEventListener('keydown', this.onEnterKeyDown); } else if (nextProps.show === false && this.props.show === true) { document.removeEventListener('keydown', this.onEnterKeyDown); } } componentDidMount() { if (Utils.isBrowserIE()) { $('body').addClass('browser--ie'); } PreferenceStore.addChangeListener(this.onPreferenceChange); } componentWillUnmount() { PreferenceStore.removeChangeListener(this.onPreferenceChange); } onPreferenceChange() { this.ctrlSend = PreferenceStore.getBool(Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter'); } onEnterKeyDown(e) { if (this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && e.ctrlKey) { this.handleSubmit(e); } else if (!this.ctrlSend && e.keyCode === Constants.KeyCodes.ENTER && !e.shiftKey && !e.altKey) { this.handleSubmit(e); } } handleSubmit(e) { e.preventDefault(); const displayName = ReactDOM.findDOMNode(this.refs.display_name).value.trim(); if (displayName.length < 1) { this.setState({displayNameError: true}); return; } this.props.onSubmitChannel(); } handleChange() { const newData = { displayName: ReactDOM.findDOMNode(this.refs.display_name).value, purpose: ReactDOM.findDOMNode(this.refs.channel_purpose).value }; this.props.onDataChanged(newData); } render() { var displayNameError = null; var serverError = null; var displayNameClass = 'form-group'; if (this.state.displayNameError) { displayNameError = (

{this.state.displayNameError}

); displayNameClass += ' has-error'; } if (this.props.serverError) { serverError =

{this.props.serverError}

; } let createPublicChannelLink = ( ); let createPrivateChannelLink = ( ); const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); const isSystemAdmin = UserStore.isSystemAdminForCurrentUser(); if (global.window.mm_license.IsLicensed === 'true') { if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { createPublicChannelLink = null; } else if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { createPublicChannelLink = null; } if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { createPrivateChannelLink = null; } else if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { createPrivateChannelLink = null; } } var channelTerm = ''; var channelSwitchText = ''; switch (this.props.channelType) { case 'P': channelTerm = ( ); channelSwitchText = (
{createPublicChannelLink}
); break; case 'O': channelTerm = ( ); channelSwitchText = (
{createPrivateChannelLink}
); break; } const prettyTeamURL = Utils.getShortenedTeamURL(); return ( {channelTerm}
{channelSwitchText}
{displayNameError}

{'URL: ' + prettyTeamURL + this.props.channelData.name + ' ('} {')'}