From 02c4ec04aee564fc65c32e6c3c788a8c40aa5317 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Wed, 16 Sep 2015 13:10:06 -0400 Subject: [PATCH] Implement routing We want a single Dashboard js app that includes both the general ledger and chart of accounts. --- www/assets/dashboard.css.spt | 7 ++++ www/assets/dashboard.js | 59 ++++++++++++++++++++++++++++++-- www/dashboard/%index.spt | 57 ++++++++++++++++++++++++++++++ www/dashboard/accounts/index.spt | 43 ----------------------- www/dashboard/index.spt | 13 ------- www/dashboard/ledger.spt | 21 ------------ www/v2/accounts/index.spt | 12 +++++++ 7 files changed, 132 insertions(+), 80 deletions(-) create mode 100644 www/assets/dashboard.css.spt create mode 100644 www/dashboard/%index.spt delete mode 100644 www/dashboard/accounts/index.spt delete mode 100644 www/dashboard/index.spt delete mode 100644 www/dashboard/ledger.spt create mode 100644 www/v2/accounts/index.spt diff --git a/www/assets/dashboard.css.spt b/www/assets/dashboard.css.spt new file mode 100644 index 0000000000..c9af77662a --- /dev/null +++ b/www/assets/dashboard.css.spt @@ -0,0 +1,7 @@ +[---] +[---] text/css via scss +#dashboard { + section { + display: none; + } +} diff --git a/www/assets/dashboard.js b/www/assets/dashboard.js index d009f8184e..96f500f912 100644 --- a/www/assets/dashboard.js +++ b/www/assets/dashboard.js @@ -1,5 +1,21 @@ Dashboard = {models: {}, views: {}, collections: {}}; +Dashboard.Router = Backbone.Router.extend({ + routes: {'ledger': 'ledger', 'accounts': 'accounts'}, + ledger: function() { + $('section').hide(); + $('#general-ledger').show(); + }, + accounts: function() { + $('section').hide(); + $('#chart-of-accounts').show(); + } +}); + + +// Models +// ====== + Dashboard.models.Account = Backbone.Model.extend({ defaults: { number: null, @@ -8,21 +24,54 @@ Dashboard.models.Account = Backbone.Model.extend({ } }); + +// Collections +// =========== + Dashboard.collections.Accounts = Backbone.Collection.extend({ - url: '/dashboard/accounts/', + url: '/v2/accounts/', model: Dashboard.models.Account, parse: function(data) { return data.accounts; } }); + +// Views +// ===== + +Dashboard.views.Main = Backbone.View.extend({ + el: 'body', + initialize: function() { + new Dashboard.views.GeneralLedger; + new Dashboard.views.ChartOfAccounts; + + this.router = new Dashboard.Router; + Backbone.history.start({pushState: true, root: "/dashboard/"}); + }, + events: { + 'click #navigation a': 'loadSection' + }, + loadSection: function(e) { + this.router.navigate($(e.currentTarget).attr('href'), {trigger: true}); + e.preventDefault(); + }, +}); + +Dashboard.views.GeneralLedger = Backbone.View.extend({ + el: '#general-ledger', + initialize: function() { + this.$tbody= this.$('tbody'); + }, +}); + Dashboard.views.ChartOfAccounts = Backbone.View.extend({ el: '#chart-of-accounts', initialize: function() { this.$tbody= this.$('tbody'); this.data = new Dashboard.collections.Accounts(); - this.data.fetch({reset:true}); this.listenTo(this.data, 'reset', this.addAll); + this.data.fetch({reset:true}); }, addOne: function (account) { var view = new Dashboard.views.AccountRow({model: account}); @@ -46,6 +95,10 @@ Dashboard.views.AccountRow = Backbone.View.extend({ } }); + +// Entrypoint +// ========== + Dashboard.init = function() { - new Dashboard.views.ChartOfAccounts(); + new Dashboard.views.Main(); }; diff --git a/www/dashboard/%index.spt b/www/dashboard/%index.spt new file mode 100644 index 0000000000..d88759e774 --- /dev/null +++ b/www/dashboard/%index.spt @@ -0,0 +1,57 @@ +from aspen import Response +[---] +if user.ANON: + raise Response(401) +if not user.ADMIN: + raise Response(403) +[---] text/html + + + Dashboard + + + + + + + + +

Dashboard

+ + +
+

General Ledger

+ + + + + + + +
AccountDebitsCredits
+
+ +
+

Chart of Accounts

+ + + + + + + +
NumberNameType
+
+ + + + diff --git a/www/dashboard/accounts/index.spt b/www/dashboard/accounts/index.spt deleted file mode 100644 index 0c9c6fdad4..0000000000 --- a/www/dashboard/accounts/index.spt +++ /dev/null @@ -1,43 +0,0 @@ -from aspen import Response -[---] -if user.ANON: - raise Response(401) -if not user.ADMIN: - raise Response(403) - -out = {"accounts": [ {"number": "100", "name": "accounts receivable", "kind": "asset"} - , {"number": "200", "name": "accounts payable", "kind": "liability"} - ]} -[---] application/json via json_dump -out -[---] text/html - - - - Chart of Accounts - - - - - - - -

Chart of Accounts

- - - - - - - -
NumberNameType
- - - - diff --git a/www/dashboard/index.spt b/www/dashboard/index.spt deleted file mode 100644 index a6629c5365..0000000000 --- a/www/dashboard/index.spt +++ /dev/null @@ -1,13 +0,0 @@ -from aspen import Response -[---] -if user.ANON: - raise Response(401) -if not user.ADMIN: - raise Response(403) -[---] text/html -

Dashboard

- diff --git a/www/dashboard/ledger.spt b/www/dashboard/ledger.spt deleted file mode 100644 index 5949017cd2..0000000000 --- a/www/dashboard/ledger.spt +++ /dev/null @@ -1,21 +0,0 @@ -from aspen import Response -[---] -if user.ANON: - raise Response(401) -if not user.ADMIN: - raise Response(403) -[---] text/html - - - - - - -
- - -
-

Hello {{yourName}}!

-
- - diff --git a/www/v2/accounts/index.spt b/www/v2/accounts/index.spt new file mode 100644 index 0000000000..c7eb8d2f1e --- /dev/null +++ b/www/v2/accounts/index.spt @@ -0,0 +1,12 @@ +from aspen import Response +[---] +if user.ANON: + raise Response(401) +if not user.ADMIN: + raise Response(403) + +out = {"accounts": [ {"number": "100", "name": "accounts receivable", "type": "asset"} + , {"number": "200", "name": "accounts payable", "type": "liability"} + ]} +[---] application/json via json_dump +out