// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import $ from 'jquery';
import {Modal} from 'react-bootstrap';
import SettingItemMin from './setting_item_min.jsx';
import SettingItemMax from './setting_item_max.jsx';
import Client from 'client/web_client.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import {FormattedMessage} from 'react-intl';
import React from 'react';
export default class ChannelNotificationsModal extends React.Component {
constructor(props) {
super(props);
this.updateSection = this.updateSection.bind(this);
this.handleSubmitNotifyLevel = this.handleSubmitNotifyLevel.bind(this);
this.handleUpdateNotifyLevel = this.handleUpdateNotifyLevel.bind(this);
this.createNotifyLevelSection = this.createNotifyLevelSection.bind(this);
this.handleSubmitMarkUnreadLevel = this.handleSubmitMarkUnreadLevel.bind(this);
this.handleUpdateMarkUnreadLevel = this.handleUpdateMarkUnreadLevel.bind(this);
this.createMarkUnreadLevelSection = this.createMarkUnreadLevelSection.bind(this);
this.state = {
activeSection: '',
notifyLevel: '',
unreadLevel: ''
};
}
updateSection(section) {
$('.settings-modal .modal-body').scrollTop(0).perfectScrollbar('update');
this.setState({activeSection: section});
}
componentWillReceiveProps(nextProps) {
if (!this.props.show && nextProps.show) {
this.setState({
notifyLevel: nextProps.channelMember.notify_props.desktop,
unreadLevel: nextProps.channelMember.notify_props.mark_unread
});
}
}
handleSubmitNotifyLevel() {
var channelId = this.props.channel.id;
var notifyLevel = this.state.notifyLevel;
if (this.props.channelMember.notify_props.desktop === notifyLevel) {
this.updateSection('');
return;
}
var data = {};
data.channel_id = channelId;
data.user_id = this.props.currentUser.id;
data.desktop = notifyLevel;
//TODO: This should be moved to event_helpers
Client.updateChannelNotifyProps(data,
() => {
// YUCK
var member = ChannelStore.getMember(channelId);
member.notify_props.desktop = notifyLevel;
ChannelStore.setChannelMember(member);
this.updateSection('');
},
(err) => {
this.setState({serverError: err.message});
}
);
}
handleUpdateNotifyLevel(notifyLevel) {
this.setState({notifyLevel});
}
createNotifyLevelSection(serverError) {
// Get glabal user setting for notifications
const globalNotifyLevel = this.props.currentUser.notify_props.desktop;
let globalNotifyLevelName;
if (globalNotifyLevel === 'all') {
globalNotifyLevelName = (