NOTICKET: Merging OSM/master to OSM/projects
[osm/UI.git] / skyquake / plugins / accounts / src / account / account.jsx
index 45b31fc..1916ef3 100644 (file)
 
 import React from 'react';
 import Button from 'widgets/button/rw.button.js';
-import _ from 'lodash';
+import _cloneDeep from 'lodash/cloneDeep';
 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
 import Crouton from 'react-crouton';
 import TextInput from 'widgets/form_controls/textInput.jsx';
 import {AccountConnectivityStatus} from '../account_sidebar/accountSidebar.jsx';
+
 import 'style/common.scss';
 import './account.scss';
 class Account extends React.Component {
@@ -47,7 +48,6 @@ class Account extends React.Component {
         }
     }
     componentWillUnmount() {
-        this.props.store.closeSocket();
         this.props.store.unlisten(this.storeListener);
     }
     setUp(props){
@@ -95,7 +95,7 @@ class Account extends React.Component {
             }
         }
 
-        let newAccount = _.cloneDeep(removeTrailingWhitespace(Account));
+        let newAccount = _cloneDeep(removeTrailingWhitespace(Account));
         delete newAccount.params;
         newAccount.nestedParams &&
             newAccount.nestedParams['container-name'] &&
@@ -107,8 +107,8 @@ class Account extends React.Component {
             self.props.router.push({pathname:'accounts'});
             self.props.flux.actions.global.hideScreenLoader.defer();
         },
-         function() {
-            self.props.flux.actions.global.showNotification("There was an error creating your account. Please contact your system administrator.");
+         function(error) {
+            self.props.flux.actions.global.showNotification(error);
             self.props.flux.actions.global.hideScreenLoader.defer();
          });
     }
@@ -170,7 +170,7 @@ class Account extends React.Component {
     }
     evaluateSubmit = (e) => {
         if (e.keyCode == 13) {
-            if (this.props.edit) {
+            if (this.props.params.name != 'create') {
                 this.update(e);
             } else {
                 this.create(e);
@@ -264,7 +264,16 @@ class Account extends React.Component {
                     value = Account.params[node.ref];
                 }
                 paramsStack.push(
-                    <TextInput key={node.label} className="accountForm-input" label={node.label} required={!node.optional}  onChange={this.props.store.handleParamChange(node)} value={value} />
+                    <TextInput
+                        key={node.label}
+                        className="accountForm-input"
+                        label={node.label}
+                        required={!node.optional}
+                        onChange={this.props.store.handleParamChange(node)}
+                        value={value}
+                        readonly={self.props.readonly}
+
+                        />
                 );
             }
 
@@ -288,7 +297,16 @@ class Account extends React.Component {
                     //     </label>
                     // );
                     nestedParamsStack.push(
-                          <TextInput key={node.label} label={node.label} required={!node.optional} className="create-fleet-pool-input" type="text" onChange={this.props.store.handleNestedParamChange(Account.nestedParams['container-name'], node)} value={value}/>
+                          <TextInput
+                            key={node.label}
+                            label={node.label}
+                            required={!node.optional}
+                            className="create-fleet-pool-input"
+                            type="text"
+                            onChange={this.props.store.handleNestedParamChange(Account.nestedParams['container-name'], node)}
+                            value={value}
+                            readonly={self.props.readonly}
+                            />
                     );
                 }
             }
@@ -331,7 +349,7 @@ class Account extends React.Component {
                             <AccountConnectivityStatus status={Account['connection-status'].status} />
                             {Account['connection-status'] && Account['connection-status'].status &&  Account['connection-status'].status.toUpperCase()}
                         </div>
-                            <Button className="refreshList light" onClick={this.props.store.refreshAccount.bind(this, Account.name, AccountType)} label="REFRESH STATUS"></Button>
+                            <Button is-disabled={self.props.readonly} className="refreshList light" onClick={this.props.store.refreshAccount.bind(this, Account.name, AccountType)} label="REFRESH STATUS"></Button>
                     </div>
                     {
                         (Account['connection-status'] && Account['connection-status'].status && Account['connection-status'].status.toUpperCase()) === 'FAILURE' ?
@@ -388,7 +406,7 @@ class Account extends React.Component {
                       {params}
                   </ol>
                   <div className="form-actions">
-                      {buttons}
+                      {!self.props.readonly ? buttons : null}
                   </div>
               </form>
         )
@@ -396,6 +414,11 @@ class Account extends React.Component {
     }
 }
 
+Account.contextTypes = {
+    router: React.PropTypes.object,
+    userProfile: React.PropTypes.object
+}
+
 function displayFailureMessage(msg) {
     return (
         <div className="accountForm-content" style={{maxWidth: '600px'}}>