Reformatted user_settings_appearance.jsx to meet style guide requirements.
Этот коммит содержится в:
@@ -7,6 +7,9 @@ export default class TeamSignupAllowedDomainsPage extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.submitBack = this.submitBack.bind(this);
|
||||||
|
this.submitNext = this.submitNext.bind(this);
|
||||||
|
|
||||||
this.state = {};
|
this.state = {};
|
||||||
}
|
}
|
||||||
submitBack(e) {
|
submitBack(e) {
|
||||||
|
|||||||
@@ -4,100 +4,133 @@
|
|||||||
var UserStore = require('../stores/user_store.jsx');
|
var UserStore = require('../stores/user_store.jsx');
|
||||||
var SettingItemMin = require('./setting_item_min.jsx');
|
var SettingItemMin = require('./setting_item_min.jsx');
|
||||||
var SettingItemMax = require('./setting_item_max.jsx');
|
var SettingItemMax = require('./setting_item_max.jsx');
|
||||||
var client = require('../utils/client.jsx');
|
var Client = require('../utils/client.jsx');
|
||||||
var utils = require('../utils/utils.jsx');
|
var Utils = require('../utils/utils.jsx');
|
||||||
|
|
||||||
module.exports = React.createClass({
|
export default class UserSettingsAppearance extends React.Component {
|
||||||
submitTheme: function(e) {
|
constructor(props) {
|
||||||
e.preventDefault();
|
super(props);
|
||||||
var user = UserStore.getCurrentUser();
|
|
||||||
if (!user.props) user.props = {};
|
|
||||||
user.props.theme = this.state.theme;
|
|
||||||
|
|
||||||
client.updateUser(user,
|
this.submitTheme = this.submitTheme.bind(this);
|
||||||
function(data) {
|
this.updateTheme = this.updateTheme.bind(this);
|
||||||
this.props.updateSection("");
|
this.handleClose = this.handleClose.bind(this);
|
||||||
window.location.reload();
|
|
||||||
}.bind(this),
|
this.state = this.getStateFromStores();
|
||||||
function(err) {
|
}
|
||||||
state = this.getInitialState();
|
getStateFromStores() {
|
||||||
state.server_error = err;
|
|
||||||
this.setState(state);
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
},
|
|
||||||
updateTheme: function(e) {
|
|
||||||
var hex = utils.rgb2hex(e.target.style.backgroundColor);
|
|
||||||
this.setState({ theme: hex.toLowerCase() });
|
|
||||||
},
|
|
||||||
handleClose: function() {
|
|
||||||
this.setState({server_error: null});
|
|
||||||
this.props.updateTab('general');
|
|
||||||
},
|
|
||||||
componentDidMount: function() {
|
|
||||||
if (this.props.activeSection === "theme") {
|
|
||||||
$(this.refs[this.state.theme].getDOMNode()).addClass('active-border');
|
|
||||||
}
|
|
||||||
$('#user_settings').on('hidden.bs.modal', this.handleClose);
|
|
||||||
},
|
|
||||||
componentDidUpdate: function() {
|
|
||||||
if (this.props.activeSection === "theme") {
|
|
||||||
$('.color-btn').removeClass('active-border');
|
|
||||||
$(this.refs[this.state.theme].getDOMNode()).addClass('active-border');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
$('#user_settings').off('hidden.bs.modal', this.handleClose);
|
|
||||||
this.props.updateSection('');
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
|
||||||
var user = UserStore.getCurrentUser();
|
var user = UserStore.getCurrentUser();
|
||||||
var theme = config.ThemeColors != null ? config.ThemeColors[0] : "#2389d7";
|
var theme = '#2389d7';
|
||||||
|
if (config.ThemeColors != null) {
|
||||||
|
theme = config.ThemeColors[0];
|
||||||
|
}
|
||||||
if (user.props && user.props.theme) {
|
if (user.props && user.props.theme) {
|
||||||
theme = user.props.theme;
|
theme = user.props.theme;
|
||||||
}
|
}
|
||||||
return { theme: theme.toLowerCase() };
|
|
||||||
},
|
|
||||||
render: function() {
|
|
||||||
var server_error = this.state.server_error ? this.state.server_error : null;
|
|
||||||
|
|
||||||
|
return {theme: theme.toLowerCase()};
|
||||||
|
}
|
||||||
|
submitTheme(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var user = UserStore.getCurrentUser();
|
||||||
|
if (!user.props) {
|
||||||
|
user.props = {};
|
||||||
|
}
|
||||||
|
user.props.theme = this.state.theme;
|
||||||
|
|
||||||
|
Client.updateUser(user,
|
||||||
|
function success() {
|
||||||
|
this.props.updateSection('');
|
||||||
|
window.location.reload();
|
||||||
|
}.bind(this),
|
||||||
|
function fail(err) {
|
||||||
|
var state = this.getStateFromStores();
|
||||||
|
state.serverError = err;
|
||||||
|
this.setState(state);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
updateTheme(e) {
|
||||||
|
var hex = Utils.rgb2hex(e.target.style.backgroundColor);
|
||||||
|
this.setState({theme: hex.toLowerCase()});
|
||||||
|
}
|
||||||
|
handleClose() {
|
||||||
|
this.setState({serverError: null});
|
||||||
|
this.props.updateTab('general');
|
||||||
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
if (this.props.activeSection === 'theme') {
|
||||||
|
$(this.refs[this.state.theme].getDOMNode()).addClass('active-border');
|
||||||
|
}
|
||||||
|
$('#user_settings').on('hidden.bs.modal', this.handleClose);
|
||||||
|
}
|
||||||
|
componentDidUpdate() {
|
||||||
|
if (this.props.activeSection === 'theme') {
|
||||||
|
$('.color-btn').removeClass('active-border');
|
||||||
|
$(this.refs[this.state.theme].getDOMNode()).addClass('active-border');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
componentWillUnmount() {
|
||||||
|
$('#user_settings').off('hidden.bs.modal', this.handleClose);
|
||||||
|
this.props.updateSection('');
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
var serverError;
|
||||||
|
if (this.state.serverError) {
|
||||||
|
serverError = this.state.serverError;
|
||||||
|
}
|
||||||
|
|
||||||
var themeSection;
|
var themeSection;
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (config.ThemeColors != null) {
|
if (config.ThemeColors != null) {
|
||||||
if (this.props.activeSection === 'theme') {
|
if (this.props.activeSection === 'theme') {
|
||||||
var theme_buttons = [];
|
var themeButtons = [];
|
||||||
|
|
||||||
for (var i = 0; i < config.ThemeColors.length; i++) {
|
for (var i = 0; i < config.ThemeColors.length; i++) {
|
||||||
theme_buttons.push(<button ref={config.ThemeColors[i]} type="button" className="btn btn-lg color-btn" style={{backgroundColor: config.ThemeColors[i]}} onClick={this.updateTheme} />);
|
themeButtons.push(
|
||||||
|
<button
|
||||||
|
ref={config.ThemeColors[i]}
|
||||||
|
type='button'
|
||||||
|
className='btn btn-lg color-btn'
|
||||||
|
style={{backgroundColor: config.ThemeColors[i]}}
|
||||||
|
onClick={this.updateTheme}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var inputs = [];
|
var inputs = [];
|
||||||
|
|
||||||
inputs.push(
|
inputs.push(
|
||||||
<li className="setting-list-item">
|
<li className='setting-list-item'>
|
||||||
<div className="btn-group" data-toggle="buttons-radio">
|
<div
|
||||||
{ theme_buttons }
|
className='btn-group'
|
||||||
|
data-toggle='buttons-radio'
|
||||||
|
>
|
||||||
|
{themeButtons}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
|
||||||
themeSection = (
|
themeSection = (
|
||||||
<SettingItemMax
|
<SettingItemMax
|
||||||
title="Theme Color"
|
title='Theme Color'
|
||||||
inputs={inputs}
|
inputs={inputs}
|
||||||
submit={this.submitTheme}
|
submit={this.submitTheme}
|
||||||
server_error={server_error}
|
serverError={serverError}
|
||||||
updateSection={function(e){self.props.updateSection("");e.preventDefault;}}
|
updateSection={function updateSection(e) {
|
||||||
|
self.props.updateSection('');
|
||||||
|
e.preventDefault();
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
themeSection = (
|
themeSection = (
|
||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
title="Theme Color"
|
title='Theme Color'
|
||||||
describe={this.state.theme}
|
describe={this.state.theme}
|
||||||
updateSection={function(){self.props.updateSection("theme");}}
|
updateSection={function updateSection() {
|
||||||
|
self.props.updateSection('theme');
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -105,17 +138,38 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="modal-header">
|
<div className='modal-header'>
|
||||||
<button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
<button
|
||||||
<h4 className="modal-title" ref="title"><i className="modal-back"></i>Appearance Settings</h4>
|
type='button'
|
||||||
|
className='close'
|
||||||
|
data-dismiss='modal'
|
||||||
|
aria-label='Close'
|
||||||
|
>
|
||||||
|
<span aria-hidden='true'>×</span>
|
||||||
|
</button>
|
||||||
|
<h4
|
||||||
|
className='modal-title'
|
||||||
|
ref='title'
|
||||||
|
>
|
||||||
|
<i className='modal-back'></i>Appearance Settings
|
||||||
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<div className="user-settings">
|
<div className='user-settings'>
|
||||||
<h3 className="tab-header">Appearance Settings</h3>
|
<h3 className='tab-header'>Appearance Settings</h3>
|
||||||
<div className="divider-dark first"/>
|
<div className='divider-dark first'/>
|
||||||
{themeSection}
|
{themeSection}
|
||||||
<div className="divider-dark"/>
|
<div className='divider-dark'/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
UserSettingsAppearance.defaultProps = {
|
||||||
|
activeSection: ''
|
||||||
|
};
|
||||||
|
UserSettingsAppearance.propTypes = {
|
||||||
|
activeSection: React.PropTypes.string,
|
||||||
|
updateSection: React.PropTypes.func,
|
||||||
|
updateTab: React.PropTypes.func
|
||||||
|
};
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user