Added a condition to close event listeners on modals when the component

is unmounted, and set all unsaved data to be cleared from user settings
Этот коммит содержится в:
nickago
2015-07-23 09:20:37 -07:00
родитель 0acab11cf4
Коммит dbbe40e893
4 изменённых файлов: 40 добавлений и 27 удалений

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

@@ -30,15 +30,19 @@ module.exports = React.createClass({
handleUserInput: function(e) { handleUserInput: function(e) {
this.setState({ description: e.target.value }); this.setState({ description: e.target.value });
}, },
handleClose: function() {
this.setState({description: "", server_error: ""});
},
componentDidMount: function() { componentDidMount: function() {
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(e) {
var button = e.relatedTarget; var button = e.relatedTarget;
self.setState({ description: $(button).attr('data-desc'), title: $(button).attr('data-title'), channel_id: $(button).attr('data-channelid'), server_error: "" }); self.setState({ description: $(button).attr('data-desc'), title: $(button).attr('data-title'), channel_id: $(button).attr('data-channelid'), server_error: "" });
}); });
$(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function() { $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', this.handleClose)
self.setState({description: ""}); },
}) componentWillUnmount: function() {
$(this.refs.modal.getDOMNode()).off('hidden.bs.modal', this.handleClose)
}, },
getInitialState: function() { getInitialState: function() {
return { description: "", title: "", channel_id: "" }; return { description: "", title: "", channel_id: "" };

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

@@ -89,15 +89,19 @@ module.exports = React.createClass({
this.refs.channel_name.getDOMNode().value = channel_name; this.refs.channel_name.getDOMNode().value = channel_name;
this.setState({ channel_name: channel_name }) this.setState({ channel_name: channel_name })
}, },
handleClose: function() {
this.setState({display_name: "", channel_name: "", display_name_error: "", server_error: "", name_error: ""});
},
componentDidMount: function() { componentDidMount: function() {
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(e) {
var button = $(e.relatedTarget); var button = $(e.relatedTarget);
self.setState({ display_name: button.attr('data-display'), title: button.attr('data-name'), channel_id: button.attr('data-channelid') }); self.setState({ display_name: button.attr('data-display'), title: button.attr('data-name'), channel_id: button.attr('data-channelid') });
}); });
$(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function() { $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', this.handleClose);
self.setState({display_name: "", channel_name: "", display_name_error: "", server_error: "", name_error: ""}); },
}); componentWillUnmount: function() {
$(this.refs.modal.getDOMNode()).off('hidden.bs.modal', this.handleClose);
}, },
getInitialState: function() { getInitialState: function() {
return { display_name: "", channel_name: "", channel_id: "" }; return { display_name: "", channel_name: "", channel_id: "" };

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

@@ -44,11 +44,14 @@ module.exports = React.createClass({
onNameChange: function() { onNameChange: function() {
this.setState({ name: this.refs.name.getDOMNode().value }) this.setState({ name: this.refs.name.getDOMNode().value })
}, },
handleClose: function() {
this.setState({ name: this.props.teamDisplayName, name_error: "", server_error: ""});
},
componentDidMount: function() { componentDidMount: function() {
var self = this; $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', this.handleClose);
$(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function(e) { },
self.setState({ name: self.props.teamDisplayName, name_error: "", server_error: ""}); componentWillUnmount: function() {
}); $(this.refs.modal.getDOMNode()).off('hidden.bs.modal', this.handleClose);
}, },
getInitialState: function() { getInitialState: function() {
return { name: this.props.teamDisplayName }; return { name: this.props.teamDisplayName };

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

@@ -11,6 +11,7 @@ var client = require('../utils/client.jsx');
var AsyncClient = require('../utils/async_client.jsx'); var AsyncClient = require('../utils/async_client.jsx');
var utils = require('../utils/utils.jsx'); var utils = require('../utils/utils.jsx');
var Constants = require('../utils/constants.jsx'); var Constants = require('../utils/constants.jsx');
var assign = require('object-assign');
function getNotificationsStateFromStores() { function getNotificationsStateFromStores() {
var user = UserStore.getCurrentUser(); var user = UserStore.getCurrentUser();
@@ -96,16 +97,18 @@ var NotificationsTab = React.createClass({
); );
}, },
handleClose: function() { handleClose: function() {
this.setState({server_error: null}); $(this.getDOMNode()).find(".form-control").each(function() {
this.value = "";
});
this.setState(assign({},getNotificationsStateFromStores(),{server_error: null}));
}, },
componentDidMount: function() { componentDidMount: function() {
UserStore.addChangeListener(this._onChange); UserStore.addChangeListener(this._onChange);
$('#user_settings1').on('hidden.bs.modal', this.handleClose); $('#user_settings1').on('hidden.bs.modal', this.handleClose);
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
UserStore.removeChangeListener(this._onChange); UserStore.removeChangeListener(this._onChange);
$('#user_settings1').off('hidden.bs.modal', this.handleClose); $('#user_settings1').off('hidden.bs.modal', this.handleClose);
}, },
_onChange: function() { _onChange: function() {
@@ -510,15 +513,10 @@ var SecurityTab = React.createClass({
$("#user_settings1").modal('hide'); $("#user_settings1").modal('hide');
}, },
handleClose: function() { handleClose: function() {
if(this.props.activeSection === 'password') { $(this.getDOMNode()).find(".form-control").each(function() {
this.refs.curPass.getDOMNode().value = ""; this.value = "";
this.refs.newPass.getDOMNode().value = ""; });
this.refs.reNewPass.getDOMNode().value = ""; this.setState({current_password: '', new_password: '', confirm_password: '', server_error: null, password_error: null});
this.setState({current_password: '', new_password: '', confirm_password: ''});
}
this.setState({server_error: null, password_error: null});
}, },
componentDidMount: function() { componentDidMount: function() {
$('#user_settings1').on('hidden.bs.modal', this.handleClose); $('#user_settings1').on('hidden.bs.modal', this.handleClose);
@@ -542,7 +540,7 @@ var SecurityTab = React.createClass({
<div className="form-group"> <div className="form-group">
<label className="col-sm-5 control-label">Current Password</label> <label className="col-sm-5 control-label">Current Password</label>
<div className="col-sm-7"> <div className="col-sm-7">
<input ref="curPass" className="form-control" type="password" onChange={this.updateCurrentPassword} value={this.state.current_password}/> <input className="form-control" type="password" onChange={this.updateCurrentPassword} value={this.state.current_password}/>
</div> </div>
</div> </div>
); );
@@ -550,7 +548,7 @@ var SecurityTab = React.createClass({
<div className="form-group"> <div className="form-group">
<label className="col-sm-5 control-label">New Password</label> <label className="col-sm-5 control-label">New Password</label>
<div className="col-sm-7"> <div className="col-sm-7">
<input ref="newPass" className="form-control" type="password" onChange={this.updateNewPassword} value={this.state.new_password}/> <input className="form-control" type="password" onChange={this.updateNewPassword} value={this.state.new_password}/>
</div> </div>
</div> </div>
); );
@@ -558,7 +556,7 @@ var SecurityTab = React.createClass({
<div className="form-group"> <div className="form-group">
<label className="col-sm-5 control-label">Retype New Password</label> <label className="col-sm-5 control-label">Retype New Password</label>
<div className="col-sm-7"> <div className="col-sm-7">
<input ref="reNewPass" className="form-control" type="password" onChange={this.updateConfirmPassword} value={this.state.confirm_password}/> <input className="form-control" type="password" onChange={this.updateConfirmPassword} value={this.state.confirm_password}/>
</div> </div>
</div> </div>
); );
@@ -760,7 +758,11 @@ var GeneralTab = React.createClass({
this.props.updateSection(section); this.props.updateSection(section);
}, },
handleClose: function() { handleClose: function() {
this.setState({client_error: null, server_error: null, email_error: null}); $(this.getDOMNode()).find(".form-control").each(function() {
this.value = "";
});
this.setState(assign({}, this.getInitialState(), {client_error: null, server_error: null, email_error: null}));
}, },
componentDidMount: function() { componentDidMount: function() {
$('#user_settings1').on('hidden.bs.modal', this.handleClose); $('#user_settings1').on('hidden.bs.modal', this.handleClose);