diff --git a/static/accounts.js b/static/accounts.js index f89f2e3..1f7a3f9 100644 --- a/static/accounts.js +++ b/static/accounts.js @@ -2,25 +2,227 @@ var ListGroup = ReactBootstrap.ListGroup; var ListGroupItem = ReactBootstrap.ListGroupItem; -var AccountList = React.createClass({ +var Grid = ReactBootstrap.Grid; +var Row = ReactBootstrap.Row; +var Col = ReactBootstrap.Col; + +var Button = ReactBootstrap.Button; +var ButtonGroup = ReactBootstrap.ButtonGroup; +var Glyphicon = ReactBootstrap.Glyphicon; + +var Modal = ReactBootstrap.Modal; + +var Combobox = ReactWidgets.Combobox; + +const recursiveAccountDisplayInfo = function(account, prefix) { + var name = prefix + account.Name; + var accounts = [{AccountId: account.AccountId, Name: name}]; + for (var i = 0; i < account.Children.length; i++) + accounts = accounts.concat(recursiveAccountDisplayInfo(account.Children[i], name + "/")); + return accounts +}; +const getAccountDisplayList = function(account_list, includeRoot, rootName) { + var accounts = [] + if (includeRoot) + accounts.push({AccountId: -1, Name: rootName}); + for (var i = 0; i < account_list.length; i++) { + if (account_list[i].ParentAccountId == -1) + accounts = accounts.concat(recursiveAccountDisplayInfo(account_list[i], "")); + } + return accounts; +}; + +const AccountCombobox = React.createClass({ + 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]) + } + }, + render: function() { + var accounts = getAccountDisplayList(this.props.accounts, true, "New Root Account"); + return ( + + ); + } +}); + +const NewAccountModal = React.createClass({ getInitialState: function() { return { + security: 1, + parentaccountid: -1, + type: 1, + name: "" }; }, + handleCancel: function() { + if (this.props.onCancel != null) + this.props.onCancel(); + }, + handleChange: function() { + this.setState({ + name: this.refs.name.getValue(), + }); + }, + handleSecurityChange: function(security) { + if (security.hasOwnProperty('SecurityId')) + this.setState({ + security: security.SecurityId + }); + }, + handleTypeChange: function(type) { + if (type.hasOwnProperty('TypeId')) + this.setState({ + type: type.TypeId + }); + }, + handleParentChange: function(parentAccount) { + this.setState({parentaccountid: parentAccount.AccountId}); + }, + handleSubmit: function() { + var a = new Account(); + + a.Name = this.state.name; + a.ParentAccountId = this.state.parentaccountid; + a.SecurityId = this.state.security; + a.Type = this.state.type; + + this.handleSaveSettings(a); + }, + handleSaveSettings: function(account) { + if (this.props.onSubmit != null) + this.props.onSubmit(account); + }, + render: function() { + return ( + + + Create New Account + + +
+ + + + + + + + + + + +
+ + + + + + +
+ ); + } +}); + +const AccountsTab = React.createClass({ + getInitialState: function() { + return { + creatingNewAccount: false + }; + }, + handleNewAccount: function() { + this.setState({creatingNewAccount: true}); + }, + handleEditAccount: function() { + console.log("handleEditAccount"); + }, + handleDeleteAccount: function() { + console.log("handleDeleteAccount"); + }, + handleCreationCancel: function() { + this.setState({creatingNewAccount: false}); + }, + handleCreateAccount: function(account) { + if (this.props.onCreateAccount != null) + this.props.onCreateAccount(account); + this.setState({creatingNewAccount: false}); + }, render: function() { var accounts = this.props.accounts; var account_map = this.props.account_map; - var listGroupItems; - - for (var i = 0; i < accounts.length; i++) { - listGroupItems += {accounts[i].Name}; - } + var listGroupItems = accounts.map(function(account) { + return ( + {account.Name} + ); + }); return ( - - {listGroupItems} - + + + + + {listGroupItems} + + + + + + + + blah + + ); } }); diff --git a/static/models.js b/static/models.js index 5f60c1b..11bde73 100644 --- a/static/models.js +++ b/static/models.js @@ -16,7 +16,7 @@ function User() { this.Email = ""; } -var BogusPassword = "password"; +const BogusPassword = "password"; User.prototype.toJSON = function() { var json_obj = {}; @@ -76,7 +76,55 @@ Session.prototype.isSession = function() { this.UserId != empty_session.UserId; } -var AccountType = { +const SecurityType = { + Banknote: 1, + Bond: 2, + Stock: 3, + MutualFund: 4 +} +var SecurityTypeList = []; +for (var type in SecurityType) { + if (SecurityType.hasOwnProperty(type)) { + SecurityTypeList.push({'TypeId': SecurityType[type], 'Name': type}); + } +} + +function Security() { + this.SecurityId = -1; + this.Name = ""; + this.Precision = -1; + this.Type = -1; +} + +Security.prototype.toJSON = function() { + var json_obj = {}; + json_obj.SecurityId = this.SecurityId; + json_obj.Name = this.Name; + json_obj.Precision = this.Precision; + json_obj.Type = this.Type; + return JSON.stringify(json_obj); +} + +Security.prototype.fromJSON = function(json_input) { + var json_obj = getJSONObj(json_input); + + if (json_obj.hasOwnProperty("SecurityId")) + this.SecurityId = json_obj.SecurityId; + if (json_obj.hasOwnProperty("Name")) + this.Name = json_obj.Name; + if (json_obj.hasOwnProperty("Precision")) + this.Precision = json_obj.Precision; + if (json_obj.hasOwnProperty("Type")) + this.Type = json_obj.Type; +} + +Security.prototype.isSecurity = function() { + var empty_account = new Security(); + return this.SecurityId != empty_account.SecurityId || + this.Type != empty_account.Type; +} + +const AccountType = { Bank: 1, Cash: 2, Asset: 3, @@ -85,6 +133,12 @@ var AccountType = { Income: 6, Expense: 7 } +var AccountTypeList = []; +for (var type in AccountType) { + if (AccountType.hasOwnProperty(type)) { + AccountTypeList.push({'TypeId': AccountType[type], 'Name': type}); + } +} function Account() { this.AccountId = -1; @@ -183,7 +237,7 @@ Split.prototype.isSplit = function() { this.AccountId != empty_split.AccountId; } -var TransactionStatus = { +const TransactionStatus = { Entered: 1, Cleared: 2, Reconciled: 3, diff --git a/static/stylesheet.css b/static/stylesheet.css index c8ed91d..cfeaad3 100644 --- a/static/stylesheet.css +++ b/static/stylesheet.css @@ -1,5 +1,6 @@ div#content { width: 95%; + height: 100%; min-width: 75em; max-width: 100em; display: block; diff --git a/static/ui.js b/static/ui.js index 8f2e6c8..340be20 100644 --- a/static/ui.js +++ b/static/ui.js @@ -1,5 +1,7 @@ // Import all the objects we want to use from ReactBootstrap var Jumbotron = ReactBootstrap.Jumbotron; +var TabbedArea = ReactBootstrap.TabbedArea; +var TabPane = ReactBootstrap.TabPane; var Panel = ReactBootstrap.Panel; var ButtonGroup = ReactBootstrap.ButtonGroup; @@ -299,6 +301,8 @@ var MoneyGoApp = React.createClass({ user: new User(), accounts: [], account_map: {}, + securities: [], + security_map: {}, error: new Error() }; }, @@ -345,6 +349,7 @@ var MoneyGoApp = React.createClass({ this.setState({session: s}); this.getUser(); this.getAccounts(); + this.getSecurities(); }.bind(this), error: this.ajaxError }); @@ -370,6 +375,35 @@ var MoneyGoApp = React.createClass({ error: this.ajaxError }); }, + getSecurities: function() { + if (!this.state.session.isSession()) { + this.setState({securities: [], security_map: {}}); + return; + } + $.ajax({ + type: "GET", + dataType: "json", + url: "security/", + success: function(data, status, jqXHR) { + var e = new Error(); + var securities = []; + var security_map = {}; + e.fromJSON(data); + if (e.isError()) { + this.setState({error: e}); + } else { + for (var i = 0; i < data.securities.length; i++) { + var s = new Security(); + s.fromJSON(data.securities[i]); + securities.push(s); + security_map[s.SecurityId] = s; + } + } + this.setState({securities: securities, security_map: security_map}); + }.bind(this), + error: this.ajaxError + }); + }, getAccounts: function() { if (!this.state.session.isSession()) { this.setState({accounts: [], account_map: {}}); @@ -518,17 +552,29 @@ var MoneyGoApp = React.createClass({ mainContent = } else { if (this.state.user.isUser()) - mainContent = + mainContent = + + + + + Scheduled transactions go here... + Budgets go here... + Reports go here... + else mainContent = -

MoneyGo

-

Go manage your money.

+
+

MoneyGo

+

Go manage your money.

+
}