From 0acab11cf46a9e279d16e803ad32b8aa67e20679 Mon Sep 17 00:00:00 2001
From: nickago <ngonella@calpoly.edu>
Date: Fri, 17 Jul 2015 14:44:13 -0700
Subject: When closing out of a modal, unsaved data and text inside of it is
 erased.

---
 web/react/components/user_settings.jsx | 46 +++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

(limited to 'web/react/components/user_settings.jsx')

diff --git a/web/react/components/user_settings.jsx b/web/react/components/user_settings.jsx
index 1fbbf16ed..17b8a5e30 100644
--- a/web/react/components/user_settings.jsx
+++ b/web/react/components/user_settings.jsx
@@ -95,11 +95,18 @@ var NotificationsTab = React.createClass({
             }.bind(this)
         );
     },
+    handleClose: function() {
+        this.setState({server_error: null});
+    },
     componentDidMount: function() {
         UserStore.addChangeListener(this._onChange);
+
+        $('#user_settings1').on('hidden.bs.modal', this.handleClose);
     },
     componentWillUnmount: function() {
         UserStore.removeChangeListener(this._onChange);
+
+        $('#user_settings1').off('hidden.bs.modal', this.handleClose);
     },
     _onChange: function() {
         var newState = getNotificationsStateFromStores();
@@ -502,6 +509,23 @@ var SecurityTab = React.createClass({
     handleDevicesOpen: function() {
         $("#user_settings1").modal('hide');
     },
+    handleClose: function() {
+        if(this.props.activeSection === 'password') {
+            this.refs.curPass.getDOMNode().value = "";
+            this.refs.newPass.getDOMNode().value = "";
+            this.refs.reNewPass.getDOMNode().value = "";
+
+            this.setState({current_password: '', new_password: '', confirm_password: ''});
+        }
+
+        this.setState({server_error: null, password_error: null});
+    },
+    componentDidMount: function() {
+        $('#user_settings1').on('hidden.bs.modal', this.handleClose);
+    },
+    componentWillUnmount: function() {
+        $('#user_settings1').off('hidden.bs.modal', this.handleClose);
+    },
     getInitialState: function() {
         return { current_password: '', new_password: '', confirm_password: '' };
     },
@@ -518,7 +542,7 @@ var SecurityTab = React.createClass({
                 <div className="form-group">
                     <label className="col-sm-5 control-label">Current Password</label>
                     <div className="col-sm-7">
-                        <input className="form-control" type="password" onChange={this.updateCurrentPassword} value={this.state.current_password}/>
+                        <input ref="curPass" className="form-control" type="password" onChange={this.updateCurrentPassword} value={this.state.current_password}/>
                     </div>
                 </div>
             );
@@ -526,7 +550,7 @@ var SecurityTab = React.createClass({
                 <div className="form-group">
                     <label className="col-sm-5 control-label">New Password</label>
                     <div className="col-sm-7">
-                        <input className="form-control" type="password" onChange={this.updateNewPassword} value={this.state.new_password}/>
+                        <input ref="newPass" className="form-control" type="password" onChange={this.updateNewPassword} value={this.state.new_password}/>
                     </div>
                 </div>
             );
@@ -534,7 +558,7 @@ var SecurityTab = React.createClass({
                 <div className="form-group">
                     <label className="col-sm-5 control-label">Retype New Password</label>
                     <div className="col-sm-7">
-                        <input className="form-control" type="password" onChange={this.updateConfirmPassword} value={this.state.confirm_password}/>
+                        <input ref="reNewPass" className="form-control" type="password" onChange={this.updateConfirmPassword} value={this.state.confirm_password}/>
                     </div>
                 </div>
             );
@@ -735,6 +759,15 @@ var GeneralTab = React.createClass({
         this.submitActive = false
         this.props.updateSection(section);
     },
+    handleClose: function() {
+        this.setState({client_error: null, server_error: null, email_error: null});
+    },
+    componentDidMount: function() {
+        $('#user_settings1').on('hidden.bs.modal', this.handleClose);
+    },
+    componentWillUnmount: function() {
+        $('#user_settings1').off('hidden.bs.modal', this.handleClose);
+    },
     getInitialState: function() {
         var user = this.props.user;
 
@@ -978,10 +1011,14 @@ var AppearanceTab = React.createClass({
         var hex = utils.rgb2hex(e.target.style.backgroundColor);
         this.setState({ theme: hex.toLowerCase() });
     },
+    handleClose: function() {
+        this.setState({server_error: null});    
+    },
     componentDidMount: function() {
         if (this.props.activeSection === "theme") {
             $(this.refs[this.state.theme].getDOMNode()).addClass('active-border');
         }
+        $('#user_settings1').on('hidden.bs.modal', this.handleClose);
     },
     componentDidUpdate: function() {
         if (this.props.activeSection === "theme") {
@@ -989,6 +1026,9 @@ var AppearanceTab = React.createClass({
             $(this.refs[this.state.theme].getDOMNode()).addClass('active-border');
         }
     },
+    componentWillUnmount: function() {
+        $('#user_settings1').off('hidden.bs.modal', this.handleClose);
+    },
     getInitialState: function() {
         var user = UserStore.getCurrentUser();
         var theme = config.ThemeColors != null ? config.ThemeColors[0] : "#2389d7";
-- 
cgit v1.2.3-1-g7c22

