Cosmetic reformatting of the channel_notifications.jsx file
Этот коммит содержится в:
@@ -9,159 +9,230 @@ var client = require('../utils/client.jsx');
|
|||||||
var UserStore = require('../stores/user_store.jsx');
|
var UserStore = require('../stores/user_store.jsx');
|
||||||
var ChannelStore = require('../stores/channel_store.jsx');
|
var ChannelStore = require('../stores/channel_store.jsx');
|
||||||
|
|
||||||
module.exports = React.createClass({
|
export default class ChannelNotifications extends React.Component {
|
||||||
componentDidMount: function() {
|
constructor(props) {
|
||||||
ChannelStore.addChangeListener(this._onChange);
|
super(props);
|
||||||
|
this.onListenerChange = this.onListenerChange.bind(this);
|
||||||
|
this.updateSection = this.updateSection.bind(this);
|
||||||
|
this.handleUpdate = this.handleUpdate.bind(this);
|
||||||
|
this.handleRadioClick = this.handleRadioClick.bind(this);
|
||||||
|
this.handleQuietToggle = this.handleQuietToggle.bind(this);
|
||||||
|
this.state = {notifyLevel: '', title: '', channelId: '', activeSection: ''};
|
||||||
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
ChannelStore.addChangeListener(this.onListenerChange);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
$(this.refs.modal.getDOMNode()).on('show.bs.modal', function(e) {
|
$(this.refs.modal.getDOMNode()).on('show.bs.modal', function showModal(e) {
|
||||||
var button = e.relatedTarget;
|
var button = e.relatedTarget;
|
||||||
var channel_id = button.getAttribute('data-channelid');
|
var channelId = button.getAttribute('data-channelid');
|
||||||
|
|
||||||
var notifyLevel = ChannelStore.getMember(channel_id).notify_level;
|
var notifyLevel = ChannelStore.getMember(channelId).notify_level;
|
||||||
var quietMode = false;
|
var quietMode = false;
|
||||||
if (notifyLevel === "quiet") quietMode = true;
|
|
||||||
self.setState({ notify_level: notifyLevel, quiet_mode: quietMode, title: button.getAttribute('data-title'), channel_id: channel_id });
|
if (notifyLevel === 'quiet') {
|
||||||
|
quietMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.setState({notifyLevel: notifyLevel, quietMode: quietMode, title: button.getAttribute('data-title'), channelId: channelId});
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount() {
|
||||||
ChannelStore.removeChangeListener(this._onChange);
|
ChannelStore.removeChangeListener(this.onListenerChange);
|
||||||
},
|
}
|
||||||
_onChange: function() {
|
onListenerChange() {
|
||||||
if (!this.state.channel_id) return;
|
if (!this.state.channelId) {
|
||||||
var notifyLevel = ChannelStore.getMember(this.state.channel_id).notify_level;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var notifyLevel = ChannelStore.getMember(this.state.channelId).notify_level;
|
||||||
var quietMode = false;
|
var quietMode = false;
|
||||||
if (notifyLevel === "quiet") quietMode = true;
|
if (notifyLevel === 'quiet') {
|
||||||
|
quietMode = true;
|
||||||
|
}
|
||||||
|
|
||||||
var newState = this.state;
|
var newState = this.state;
|
||||||
newState.notify_level = notifyLevel;
|
newState.notifyLevel = notifyLevel;
|
||||||
newState.quiet_mode = quietMode;
|
newState.quietMode = quietMode;
|
||||||
|
|
||||||
if (!utils.areStatesEqual(this.state, newState)) {
|
if (!utils.areStatesEqual(this.state, newState)) {
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
updateSection: function(section) {
|
updateSection(section) {
|
||||||
this.setState({ activeSection: section });
|
this.setState({activeSection: section});
|
||||||
},
|
}
|
||||||
getInitialState: function() {
|
handleUpdate() {
|
||||||
return { notify_level: "", title: "", channel_id: "", activeSection: "" };
|
var channelId = this.state.channelId;
|
||||||
},
|
var notifyLevel = this.state.notifyLevel;
|
||||||
handleUpdate: function() {
|
if (this.state.quietMode) {
|
||||||
var channel_id = this.state.channel_id;
|
notifyLevel = 'quiet';
|
||||||
var notify_level = this.state.quiet_mode ? "quiet" : this.state.notify_level;
|
}
|
||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
data["channel_id"] = channel_id;
|
data.channel_id = channelId;
|
||||||
data["user_id"] = UserStore.getCurrentId();
|
data.user_id = UserStore.getCurrentId();
|
||||||
data["notify_level"] = notify_level;
|
data.notify_level = notifyLevel;
|
||||||
|
|
||||||
if (!data["notify_level"] || data["notify_level"].length === 0) return;
|
if (!data.notify_level || data.notify_level.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
client.updateNotifyLevel(data,
|
client.updateNotifyLevel(data,
|
||||||
function(data) {
|
function success() {
|
||||||
var member = ChannelStore.getMember(channel_id);
|
var member = ChannelStore.getMember(channelId);
|
||||||
member.notify_level = notify_level;
|
member.notify_level = notifyLevel;
|
||||||
ChannelStore.setChannelMember(member);
|
ChannelStore.setChannelMember(member);
|
||||||
this.updateSection("");
|
this.updateSection('');
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
function(err) {
|
function error(err) {
|
||||||
this.setState({ server_error: err.message });
|
this.setState({serverError: err.message});
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
handleRadioClick: function(notifyLevel) {
|
handleRadioClick(notifyLevel) {
|
||||||
this.setState({ notify_level: notifyLevel, quiet_mode: false });
|
this.setState({notifyLevel: notifyLevel, quietMode: false});
|
||||||
this.refs.modal.getDOMNode().focus();
|
this.refs.modal.getDOMNode().focus();
|
||||||
},
|
}
|
||||||
handleQuietToggle: function(quietMode) {
|
handleQuietToggle(quietMode) {
|
||||||
this.setState({ notify_level: "none", quiet_mode: quietMode });
|
this.setState({notifyLevel: 'none', quietMode: quietMode});
|
||||||
this.refs.modal.getDOMNode().focus();
|
this.refs.modal.getDOMNode().focus();
|
||||||
},
|
}
|
||||||
render: function() {
|
render() {
|
||||||
var server_error = this.state.server_error ? <div className='form-group has-error'><label className='control-label'>{ this.state.server_error }</label></div> : null;
|
var serverError = null;
|
||||||
|
if (this.state.serverError) {
|
||||||
|
serverError = <div className='form-group has-error'><label className='control-label'>{this.state.serverError}</label></div>;
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var describe = '';
|
||||||
|
var inputs = [];
|
||||||
|
|
||||||
|
var handleUpdateSection;
|
||||||
|
|
||||||
var desktopSection;
|
var desktopSection;
|
||||||
if (this.state.activeSection === 'desktop') {
|
if (this.state.activeSection === 'desktop') {
|
||||||
var notifyActive = [false, false, false];
|
var notifyActive = [false, false, false];
|
||||||
if (this.state.notify_level === "mention") {
|
if (this.state.notifyLevel === 'mention') {
|
||||||
notifyActive[1] = true;
|
notifyActive[1] = true;
|
||||||
} else if (this.state.notify_level === "all") {
|
} else if (this.state.notifyLevel === 'all') {
|
||||||
notifyActive[0] = true;
|
notifyActive[0] = true;
|
||||||
} else {
|
} else {
|
||||||
notifyActive[2] = true;
|
notifyActive[2] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inputs = [];
|
|
||||||
|
|
||||||
inputs.push(
|
inputs.push(
|
||||||
<div>
|
<div>
|
||||||
<div className="radio">
|
<div className='radio'>
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" checked={notifyActive[0]} onClick={function(){self.handleRadioClick("all")}}>For all activity</input>
|
<input
|
||||||
|
type='radio'
|
||||||
|
checked={notifyActive[0]}
|
||||||
|
onChange={self.handleRadioClick.bind(this, 'all')}
|
||||||
|
>
|
||||||
|
For all activity
|
||||||
|
</input>
|
||||||
</label>
|
</label>
|
||||||
<br/>
|
<br/>
|
||||||
</div>
|
</div>
|
||||||
<div className="radio">
|
<div className='radio'>
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" checked={notifyActive[1]} onClick={function(){self.handleRadioClick("mention")}}>Only for mentions</input>
|
<input
|
||||||
|
type='radio'
|
||||||
|
checked={notifyActive[1]}
|
||||||
|
onChange={self.handleRadioClick.bind(this, 'mention')}
|
||||||
|
>
|
||||||
|
Only for mentions
|
||||||
|
</input>
|
||||||
</label>
|
</label>
|
||||||
<br/>
|
<br/>
|
||||||
</div>
|
</div>
|
||||||
<div className="radio">
|
<div className='radio'>
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" checked={notifyActive[2]} onClick={function(){self.handleRadioClick("none")}}>Never</input>
|
<input
|
||||||
|
type='radio'
|
||||||
|
checked={notifyActive[2]}
|
||||||
|
onChange={self.handleRadioClick.bind(this, 'none')}
|
||||||
|
>
|
||||||
|
Never
|
||||||
|
</input>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
handleUpdateSection = function updateSection(e) {
|
||||||
|
self.updateSection('');
|
||||||
|
self.onListenerChange();
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
desktopSection = (
|
desktopSection = (
|
||||||
<SettingItemMax
|
<SettingItemMax
|
||||||
title="Send desktop notifications"
|
title='Send desktop notifications'
|
||||||
inputs={inputs}
|
inputs={inputs}
|
||||||
submit={this.handleUpdate}
|
submit={this.handleUpdate}
|
||||||
server_error={server_error}
|
server_error={serverError}
|
||||||
updateSection={function(e){self.updateSection("");self._onChange();e.preventDefault();}}
|
updateSection={handleUpdateSection}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var describe = "";
|
if (this.state.notifyLevel === 'mention') {
|
||||||
if (this.state.notify_level === "mention") {
|
describe = 'Only for mentions';
|
||||||
describe = "Only for mentions";
|
} else if (this.state.notifyLevel === 'all') {
|
||||||
} else if (this.state.notify_level === "all") {
|
describe = 'For all activity';
|
||||||
describe = "For all activity";
|
|
||||||
} else {
|
} else {
|
||||||
describe = "Never";
|
describe = 'Never';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleUpdateSection = function updateSection(e) {
|
||||||
|
self.updateSection('desktop');
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
desktopSection = (
|
desktopSection = (
|
||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
title="Send desktop notifications"
|
title='Send desktop notifications'
|
||||||
describe={describe}
|
describe={describe}
|
||||||
updateSection={function(e){self.updateSection("desktop");e.preventDefault();}}
|
updateSection={handleUpdateSection}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var quietSection;
|
var quietSection;
|
||||||
if (this.state.activeSection === 'quiet') {
|
if (this.state.activeSection === 'quiet') {
|
||||||
var quietActive = ["",""];
|
var quietActive = [false, false];
|
||||||
if (this.state.quiet_mode) {
|
if (this.state.quietMode) {
|
||||||
quietActive[0] = "active";
|
quietActive[0] = true;
|
||||||
} else {
|
} else {
|
||||||
quietActive[1] = "active";
|
quietActive[1] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inputs = [];
|
|
||||||
|
|
||||||
inputs.push(
|
inputs.push(
|
||||||
<div>
|
<div>
|
||||||
<div className="btn-group" data-toggle="buttons-radio">
|
<div className='radio'>
|
||||||
<button className={"btn btn-default "+quietActive[0]} onClick={function(){self.handleQuietToggle(true)}}>On</button>
|
<label>
|
||||||
<button className={"btn btn-default "+quietActive[1]} onClick={function(){self.handleQuietToggle(false)}}>Off</button>
|
<input
|
||||||
|
type='radio'
|
||||||
|
checked={quietActive[0]}
|
||||||
|
onChange={self.handleQuietToggle.bind(this, true)}
|
||||||
|
>
|
||||||
|
On
|
||||||
|
</input>
|
||||||
|
</label>
|
||||||
|
<br/>
|
||||||
|
</div>
|
||||||
|
<div className='radio'>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type='radio'
|
||||||
|
checked={quietActive[1]}
|
||||||
|
onChange={self.handleQuietToggle.bind(this, false)}
|
||||||
|
>
|
||||||
|
Off
|
||||||
|
</input>
|
||||||
|
</label>
|
||||||
|
<br/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -173,62 +244,85 @@ module.exports = React.createClass({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
handleUpdateSection = function updateSection(e) {
|
||||||
|
self.updateSection('');
|
||||||
|
self.onListenerChange();
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
quietSection = (
|
quietSection = (
|
||||||
<SettingItemMax
|
<SettingItemMax
|
||||||
title="Quiet mode"
|
title='Quiet mode'
|
||||||
inputs={inputs}
|
inputs={inputs}
|
||||||
submit={this.handleUpdate}
|
submit={this.handleUpdate}
|
||||||
server_error={server_error}
|
server_error={serverError}
|
||||||
updateSection={function(e){self.updateSection("");self._onChange();e.preventDefault();}}
|
updateSection={handleUpdateSection}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var describe = "";
|
if (this.state.quietMode) {
|
||||||
if (this.state.quiet_mode) {
|
describe = 'On';
|
||||||
describe = "On";
|
|
||||||
} else {
|
} else {
|
||||||
describe = "Off";
|
describe = 'Off';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleUpdateSection = function updateSection(e) {
|
||||||
|
self.updateSection('quiet');
|
||||||
|
e.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
quietSection = (
|
quietSection = (
|
||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
title="Quiet mode"
|
title='Quiet mode'
|
||||||
describe={describe}
|
describe={describe}
|
||||||
updateSection={function(e){self.updateSection("quiet");e.preventDefault();}}
|
updateSection={handleUpdateSection}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
|
||||||
return (
|
return (
|
||||||
<div className="modal fade" id="channel_notifications" ref="modal" tabIndex="-1" role="dialog" aria-hidden="true">
|
<div
|
||||||
<div className="modal-dialog settings-modal">
|
className='modal fade'
|
||||||
<div className="modal-content">
|
id='channel_notifications'
|
||||||
<div className="modal-header">
|
ref='modal'
|
||||||
<button type="button" className="close" data-dismiss="modal">
|
tabIndex='-1'
|
||||||
<span aria-hidden="true">×</span>
|
role='dialog'
|
||||||
<span className="sr-only">Close</span>
|
aria-hidden='true'
|
||||||
|
>
|
||||||
|
<div className='modal-dialog settings-modal'>
|
||||||
|
<div className='modal-content'>
|
||||||
|
<div className='modal-header'>
|
||||||
|
<button
|
||||||
|
type='button'
|
||||||
|
className='close'
|
||||||
|
data-dismiss='modal'
|
||||||
|
>
|
||||||
|
<span aria-hidden='true'>×</span>
|
||||||
|
<span className='sr-only'>Close</span>
|
||||||
</button>
|
</button>
|
||||||
<h4 className="modal-title">{"Notification Preferences for " + this.state.title}</h4>
|
<h4 className='modal-title'>{'Notification Preferences for ' + this.state.title}</h4>
|
||||||
</div>
|
</div>
|
||||||
<div className="modal-body">
|
<div className='modal-body'>
|
||||||
<div className="settings-table">
|
<div className='settings-table'>
|
||||||
<div className="settings-content">
|
<div className='settings-content'>
|
||||||
<div ref="wrapper" className="user-settings">
|
<div
|
||||||
|
ref='wrapper'
|
||||||
|
className='user-settings'
|
||||||
|
>
|
||||||
<br/>
|
<br/>
|
||||||
<div className="divider-dark first"/>
|
<div className='divider-dark first'/>
|
||||||
{desktopSection}
|
{desktopSection}
|
||||||
<div className="divider-light"/>
|
<div className='divider-light'/>
|
||||||
{quietSection}
|
{quietSection}
|
||||||
<div className="divider-dark"/>
|
<div className='divider-dark'/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{ server_error }
|
{serverError}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user