// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var SettingItemMin = require('./setting_item_min.jsx'); var SettingItemMax = require('./setting_item_max.jsx'); var utils = require('../utils/utils.jsx'); var client = require('../utils/client.jsx'); var UserStore = require('../stores/user_store.jsx'); var ChannelStore = require('../stores/channel_store.jsx'); module.exports = React.createClass({ componentDidMount: function() { ChannelStore.addChangeListener(this._onChange); var self = this; $(this.refs.modal.getDOMNode()).on('show.bs.modal', function(e) { var button = e.relatedTarget; var channel_id = button.dataset.channelid; var notifyLevel = ChannelStore.getMember(channel_id).notify_level; var quietMode = false; if (notifyLevel === "quiet") quietMode = true; self.setState({ notify_level: notifyLevel, quiet_mode: quietMode, title: button.dataset.title, channel_id: channel_id }); }); }, componentWillUnmount: function() { ChannelStore.removeChangeListener(this._onChange); }, _onChange: function() { if (!this.state.channel_id) return; var notifyLevel = ChannelStore.getMember(this.state.channel_id).notify_level; var quietMode = false; if (notifyLevel === "quiet") quietMode = true; var newState = this.state; newState.notify_level = notifyLevel; newState.quiet_mode = quietMode; if (!utils.areStatesEqual(this.state, newState)) { this.setState(newState); } }, updateSection: function(section) { this.setState({ activeSection: section }); }, getInitialState: function() { return { notify_level: "", title: "", channel_id: "", activeSection: "" }; }, handleUpdate: function() { var channel_id = this.state.channel_id; var notify_level = this.state.quiet_mode ? "quiet" : this.state.notify_level; var data = {}; data["channel_id"] = channel_id; data["user_id"] = UserStore.getCurrentId(); data["notify_level"] = notify_level; if (!data["notify_level"] || data["notify_level"].length === 0) return; client.updateNotifyLevel(data, function(data) { var member = ChannelStore.getMember(channel_id); member.notify_level = notify_level; ChannelStore.setChannelMember(member); this.updateSection(""); }.bind(this), function(err) { this.setState({ server_error: err.message }); }.bind(this) ); }, handleRadioClick: function(notifyLevel) { this.setState({ notify_level: notifyLevel, quiet_mode: false }); this.refs.modal.getDOMNode().focus(); }, handleQuietToggle: function(quietMode) { this.setState({ notify_level: "none", quiet_mode: quietMode }); this.refs.modal.getDOMNode().focus(); }, render: function() { var server_error = this.state.server_error ?
: null; var self = this; var desktopSection; if (this.state.activeSection === 'desktop') { var notifyActive = [false, false, false]; if (this.state.notify_level === "mention") { notifyActive[1] = true; } else if (this.state.notify_level === "all") { notifyActive[0] = true; } else { notifyActive[2] = true; } var inputs = []; inputs.push(