From 5be612cee8528d0dc62ea71c3d462a78fd6af939 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Sat, 4 Jul 2015 21:55:49 -0400 Subject: [PATCH] Add ability to update accounts to UI --- static/accounts.js | 84 ++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/static/accounts.js b/static/accounts.js index 9fe57cd..46d9bf8 100644 --- a/static/accounts.js +++ b/static/accounts.js @@ -38,14 +38,15 @@ const AccountCombobox = React.createClass({ getDefaultProps: function() { return { includeRoot: true, - rootName: "New Root Account" + rootName: "New Top-level Account" }; }, handleAccountChange: function(account) { if (this.props.onSelect != null && account.hasOwnProperty('AccountId') && - this.props.account_map.hasOwnProperty([account.AccountId])) { - this.props.onSelect(this.props.account_map[account.AccountId]) + (this.props.account_map.hasOwnProperty([account.AccountId]) || + account.AccountId == -1)) { + this.props.onSelect(account) } }, render: function() { @@ -62,27 +63,31 @@ const AccountCombobox = React.createClass({ } }); -const NewAccountModal = React.createClass({ +const AddEditAccountModal = React.createClass({ getInitialState: function() { - var security = 1; - var parentaccountid = -1; - var type = 1; - if (this.props.initialParentAccount != null) { - security = this.props.initialParentAccount.SecurityId; - parentaccountid = this.props.initialParentAccount.AccountId; - type = this.props.initialParentAccount.Type; - } - return { - security: security, - parentaccountid: parentaccountid, - type: type, + var s = { + accountid: -1, + security: 1, + parentaccountid: -1, + type: 1, name: "" }; + if (this.props.editAccount != null) { + s.accountid = this.props.editAccount.AccountId; + s.name = this.props.editAccount.Name; + s.security = this.props.editAccount.SecurityId; + s.parentaccountid = this.props.editAccount.ParentAccountId; + s.type = this.props.editAccount.Type; + } else if (this.props.initialParentAccount != null) { + s.security = this.props.initialParentAccount.SecurityId; + s.parentaccountid = this.props.initialParentAccount.AccountId; + s.type = this.props.initialParentAccount.Type; + } + return s; }, handleCancel: function() { if (this.props.onCancel != null) this.props.onCancel(); - this.setState(this.getInitialState()); }, handleChange: function() { this.setState({ @@ -107,17 +112,15 @@ const NewAccountModal = React.createClass({ handleSubmit: function() { var a = new Account(); + if (this.props.editAccount != null) + a.AccountId = this.state.accountid; a.Name = this.state.name; a.ParentAccountId = this.state.parentaccountid; a.SecurityId = this.state.security; a.Type = this.state.type; - this.handleSaveSettings(a); - this.setState(this.getInitialState()); - }, - handleSaveSettings: function(account) { if (this.props.onSubmit != null) - this.props.onSubmit(account); + this.props.onSubmit(a); }, componentWillReceiveProps: function(nextProps) { if (nextProps.show && !this.props.show) { @@ -125,10 +128,12 @@ const NewAccountModal = React.createClass({ } }, render: function() { + var headerText = (this.props.editAccount != null) ? "Edit" : "Create New"; + var rootName = (this.props.editAccount != null) ? "Top-level Account" : "New Top-level Account"; return ( - Create New Account + {headerText} Account
@@ -388,6 +394,7 @@ const AccountsTab = React.createClass({ return { selectedAccount: null, creatingNewAccount: false, + editingAccount: false, deletingAccount: false }; }, @@ -395,7 +402,7 @@ const AccountsTab = React.createClass({ this.setState({creatingNewAccount: true}); }, handleEditAccount: function() { - console.log("handleEditAccount"); + this.setState({editingAccount: true}); }, handleDeleteAccount: function() { this.setState({deletingAccount: true}); @@ -403,6 +410,9 @@ const AccountsTab = React.createClass({ handleCreationCancel: function() { this.setState({creatingNewAccount: false}); }, + handleEditingCancel: function() { + this.setState({editingAccount: false}); + }, handleDeletionCancel: function() { this.setState({deletingAccount: false}); }, @@ -411,10 +421,16 @@ const AccountsTab = React.createClass({ this.props.onCreateAccount(account); this.setState({creatingNewAccount: false}); }, + handleUpdateAccount: function(account) { + if (this.props.onUpdateAccount != null) + this.props.onUpdateAccount(account); + this.setState({editingAccount: false}); + }, handleRemoveAccount: function(account) { if (this.props.onDeleteAccount != null) this.props.onDeleteAccount(account); - this.setState({deletingAccount: false}); + this.setState({deletingAccount: false, + selectedAccount: null}); }, handleAccountSelected: function(account) { this.setState({selectedAccount: account}); @@ -423,10 +439,12 @@ const AccountsTab = React.createClass({ var accounts = this.props.accounts; var account_map = this.props.account_map; + var disabled = (this.state.selectedAccount == null) ? "disabled" : ""; + return ( - + - -