Reformatted channel_notifications.jsx to meet style guide requirements.

Этот коммит содержится в:
JoramWilander
2015-08-31 11:20:31 -04:00
родитель eb80b96641
Коммит 99911d9e4f

Просмотреть файл

@@ -12,17 +12,20 @@ var ChannelStore = require('../stores/channel_store.jsx');
export default class ChannelNotifications extends React.Component { export default class ChannelNotifications extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.onListenerChange = this.onListenerChange.bind(this); this.onListenerChange = this.onListenerChange.bind(this);
this.updateSection = this.updateSection.bind(this); this.updateSection = this.updateSection.bind(this);
this.handleUpdate = this.handleUpdate.bind(this); this.handleUpdate = this.handleUpdate.bind(this);
this.handleRadioClick = this.handleRadioClick.bind(this); this.handleRadioClick = this.handleRadioClick.bind(this);
this.handleQuietToggle = this.handleQuietToggle.bind(this); this.handleQuietToggle = this.handleQuietToggle.bind(this);
this.createDesktopSection = this.createDesktopSection.bind(this);
this.createQuietSection = this.createQuietSection.bind(this);
this.state = {notifyLevel: '', title: '', channelId: '', activeSection: ''}; this.state = {notifyLevel: '', title: '', channelId: '', activeSection: ''};
} }
componentDidMount() { componentDidMount() {
ChannelStore.addChangeListener(this.onListenerChange); ChannelStore.addChangeListener(this.onListenerChange);
var self = this;
$(this.refs.modal.getDOMNode()).on('show.bs.modal', function showModal(e) { $(this.refs.modal.getDOMNode()).on('show.bs.modal', function showModal(e) {
var button = e.relatedTarget; var button = e.relatedTarget;
var channelId = button.getAttribute('data-channelid'); var channelId = button.getAttribute('data-channelid');
@@ -34,8 +37,8 @@ export default class ChannelNotifications extends React.Component {
quietMode = true; quietMode = true;
} }
self.setState({notifyLevel: notifyLevel, quietMode: quietMode, title: button.getAttribute('data-title'), channelId: channelId}); this.setState({notifyLevel: notifyLevel, quietMode: quietMode, title: button.getAttribute('data-title'), channelId: channelId});
}); }.bind(this));
} }
componentWillUnmount() { componentWillUnmount() {
ChannelStore.removeChangeListener(this.onListenerChange); ChannelStore.removeChangeListener(this.onListenerChange);
@@ -98,19 +101,9 @@ export default class ChannelNotifications extends React.Component {
this.setState({notifyLevel: 'none', quietMode: quietMode}); this.setState({notifyLevel: 'none', quietMode: quietMode});
this.refs.modal.getDOMNode().focus(); this.refs.modal.getDOMNode().focus();
} }
render() { createDesktopSection(serverError) {
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 describe = '';
var inputs = [];
var handleUpdateSection; var handleUpdateSection;
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.notifyLevel === 'mention') { if (this.state.notifyLevel === 'mention') {
@@ -121,6 +114,8 @@ export default class ChannelNotifications extends React.Component {
notifyActive[2] = true; notifyActive[2] = true;
} }
var inputs = [];
inputs.push( inputs.push(
<div> <div>
<div className='radio'> <div className='radio'>
@@ -128,7 +123,7 @@ export default class ChannelNotifications extends React.Component {
<input <input
type='radio' type='radio'
checked={notifyActive[0]} checked={notifyActive[0]}
onChange={self.handleRadioClick.bind(this, 'all')} onChange={this.handleRadioClick.bind(this, 'all')}
> >
For all activity For all activity
</input> </input>
@@ -140,7 +135,7 @@ export default class ChannelNotifications extends React.Component {
<input <input
type='radio' type='radio'
checked={notifyActive[1]} checked={notifyActive[1]}
onChange={self.handleRadioClick.bind(this, 'mention')} onChange={this.handleRadioClick.bind(this, 'mention')}
> >
Only for mentions Only for mentions
</input> </input>
@@ -152,7 +147,7 @@ export default class ChannelNotifications extends React.Component {
<input <input
type='radio' type='radio'
checked={notifyActive[2]} checked={notifyActive[2]}
onChange={self.handleRadioClick.bind(this, 'none')} onChange={this.handleRadioClick.bind(this, 'none')}
> >
Never Never
</input> </input>
@@ -162,12 +157,12 @@ export default class ChannelNotifications extends React.Component {
); );
handleUpdateSection = function updateSection(e) { handleUpdateSection = function updateSection(e) {
self.updateSection(''); this.updateSection('');
self.onListenerChange(); this.onListenerChange();
e.preventDefault(); e.preventDefault();
}; }.bind(this);
desktopSection = ( return (
<SettingItemMax <SettingItemMax
title='Send desktop notifications' title='Send desktop notifications'
inputs={inputs} inputs={inputs}
@@ -176,7 +171,9 @@ export default class ChannelNotifications extends React.Component {
updateSection={handleUpdateSection} updateSection={handleUpdateSection}
/> />
); );
} else { }
var describe;
if (this.state.notifyLevel === 'mention') { if (this.state.notifyLevel === 'mention') {
describe = 'Only for mentions'; describe = 'Only for mentions';
} else if (this.state.notifyLevel === 'all') { } else if (this.state.notifyLevel === 'all') {
@@ -186,11 +183,11 @@ export default class ChannelNotifications extends React.Component {
} }
handleUpdateSection = function updateSection(e) { handleUpdateSection = function updateSection(e) {
self.updateSection('desktop'); this.updateSection('desktop');
e.preventDefault(); e.preventDefault();
}; }.bind(this);
desktopSection = ( return (
<SettingItemMin <SettingItemMin
title='Send desktop notifications' title='Send desktop notifications'
describe={describe} describe={describe}
@@ -198,8 +195,8 @@ export default class ChannelNotifications extends React.Component {
/> />
); );
} }
createQuietSection(serverError) {
var quietSection; var handleUpdateSection;
if (this.state.activeSection === 'quiet') { if (this.state.activeSection === 'quiet') {
var quietActive = [false, false]; var quietActive = [false, false];
if (this.state.quietMode) { if (this.state.quietMode) {
@@ -208,6 +205,8 @@ export default class ChannelNotifications extends React.Component {
quietActive[1] = true; quietActive[1] = true;
} }
var inputs = [];
inputs.push( inputs.push(
<div> <div>
<div className='radio'> <div className='radio'>
@@ -215,7 +214,7 @@ export default class ChannelNotifications extends React.Component {
<input <input
type='radio' type='radio'
checked={quietActive[0]} checked={quietActive[0]}
onChange={self.handleQuietToggle.bind(this, true)} onChange={this.handleQuietToggle.bind(this, true)}
> >
On On
</input> </input>
@@ -227,7 +226,7 @@ export default class ChannelNotifications extends React.Component {
<input <input
type='radio' type='radio'
checked={quietActive[1]} checked={quietActive[1]}
onChange={self.handleQuietToggle.bind(this, false)} onChange={this.handleQuietToggle.bind(this, false)}
> >
Off Off
</input> </input>
@@ -245,12 +244,12 @@ export default class ChannelNotifications extends React.Component {
); );
handleUpdateSection = function updateSection(e) { handleUpdateSection = function updateSection(e) {
self.updateSection(''); this.updateSection('');
self.onListenerChange(); this.onListenerChange();
e.preventDefault(); e.preventDefault();
}; }.bind(this);
quietSection = ( return (
<SettingItemMax <SettingItemMax
title='Quiet mode' title='Quiet mode'
inputs={inputs} inputs={inputs}
@@ -259,7 +258,9 @@ export default class ChannelNotifications extends React.Component {
updateSection={handleUpdateSection} updateSection={handleUpdateSection}
/> />
); );
} else { }
var describe;
if (this.state.quietMode) { if (this.state.quietMode) {
describe = 'On'; describe = 'On';
} else { } else {
@@ -267,11 +268,11 @@ export default class ChannelNotifications extends React.Component {
} }
handleUpdateSection = function updateSection(e) { handleUpdateSection = function updateSection(e) {
self.updateSection('quiet'); this.updateSection('quiet');
e.preventDefault(); e.preventDefault();
}; }.bind(this);
quietSection = ( return (
<SettingItemMin <SettingItemMin
title='Quiet mode' title='Quiet mode'
describe={describe} describe={describe}
@@ -279,6 +280,15 @@ export default class ChannelNotifications extends React.Component {
/> />
); );
} }
render() {
var serverError = null;
if (this.state.serverError) {
serverError = <div className='form-group has-error'><label className='control-label'>{this.state.serverError}</label></div>;
}
var desktopSection = this.createDesktopSection(serverError);
var quietSection = this.createQuietSection(serverError);
return ( return (
<div <div