From 4eb26869c8a67e39b0444a0b57a9df26f7b6e950 Mon Sep 17 00:00:00 2001 From: Scott Torborg Date: Thu, 12 Nov 2009 20:16:17 -0800 Subject: [PATCH] more refinements to the iphone targeted interface, improved validation functionality and added lazy-loading with ajax --- bluechips/lib/helpers.py | 19 ++- bluechips/public/css/mobile.css | 3 - bluechips/public/js/mobile.js | 13 +- bluechips/templates/mobile/base.mako | 123 ++++++++++++++++++ bluechips/templates/mobile/spend/index.mako | 6 + bluechips/templates/mobile/status/index.mako | 108 +-------------- .../templates/mobile/transfer/index.mako | 6 + 7 files changed, 167 insertions(+), 111 deletions(-) create mode 100644 bluechips/templates/mobile/spend/index.mako create mode 100644 bluechips/templates/mobile/transfer/index.mako diff --git a/bluechips/lib/helpers.py b/bluechips/lib/helpers.py index 8da5a57..0f49a54 100644 --- a/bluechips/lib/helpers.py +++ b/bluechips/lib/helpers.py @@ -3,6 +3,10 @@ Consists of functions to typically be used within templates, but also available to Controllers. This module is available to both as 'h'. """ +from datetime import date +from decimal import Decimal + +from pylons import request from routes import url_for, redirect_to from webhelpers.html import escape, literal, url_escape from webhelpers.html.tags import * @@ -10,7 +14,6 @@ from webhelpers.html.secure_form import * from webhelpers.pylonslib import Flash as _Flash -from decimal import Decimal def currency(name, value, *args, **kwargs): if 'class_' not in kwargs: @@ -19,4 +22,18 @@ def currency(name, value, *args, **kwargs): value = "%0.2f" % (int(value) / 100.) return text(name, value, *args, **kwargs) + +def grab(obj, attr): + if obj: + return getattr(obj, attr) + else: + if attr == 'date': + return date.today() + elif attr in ('spender_id', 'creditor_id', 'debtor_id'): + return request.environ['user'].id + elif attr == 'amount': + return 0 + else: + return '' + flash = _Flash() diff --git a/bluechips/public/css/mobile.css b/bluechips/public/css/mobile.css index e79d9e5..78a669d 100644 --- a/bluechips/public/css/mobile.css +++ b/bluechips/public/css/mobile.css @@ -34,6 +34,3 @@ body { div.tab { display: none; } -#tab-status { - display: block; -} diff --git a/bluechips/public/js/mobile.js b/bluechips/public/js/mobile.js index 6d01307..a7ab326 100644 --- a/bluechips/public/js/mobile.js +++ b/bluechips/public/js/mobile.js @@ -8,12 +8,21 @@ $(function() { console.log("ready()"); $('#tabs a').click(function() { - $('div.tab').hide(); $('#tabs a').removeClass('selected'); $(this).addClass('selected'); - $('#tab-' + $(this).attr('id')).show(); + $('div.tab').hide(); + + /* See if that tab has been rendered to the page. */ + tabname = '#tab-' + $(this).attr('id'); + tab = $(tabname); + if(tab.children().length < 1) { + /* If not, return true so that we actually reload. */ + tab.load($(this).attr('href') + ' ' + tabname + '> *'); + } + tab.show(); return false; }); + $('#tabs a.selected').click(); console.log("ready() done"); }); diff --git a/bluechips/templates/mobile/base.mako b/bluechips/templates/mobile/base.mako index fa2ea6d..b96ce4f 100644 --- a/bluechips/templates/mobile/base.mako +++ b/bluechips/templates/mobile/base.mako @@ -10,12 +10,19 @@ + % for message in h.flash.pop_messages(): +
${message | n}
+ % endfor ${next.body()} ${h.javascript_link('/js/jquery-1.3.2.js')} ${h.javascript_link('/js/mobile.js')} +<%! + from datetime import date +%> + <%def name="title()">BlueChips % if c.title != '': :: ${c.title} @@ -29,3 +36,119 @@ ${user.name} % endif + +<%def name="tabs(selected)"> +
+ % for name in ('status', 'spend', 'transfer'): + <% + if name == selected: + klass = 'selected' + else: + klass = 'unselected' + %> + + + ${name.capitalize()} + + % endfor +
+ + +<%def name="spendForm()"> +
+ <% + if c.id != '': + id = c.id + else: + id = None + %> +
+ ${h.auth_token_hidden_field()} + + + + + + + + + + + + + + + + + +
${h.select('spender_id', [h.grab(c.expenditure, 'spender_id')], c.users)}
${h.currency('amount', h.grab(c.expenditure, 'amount'), size=8)}
${h.text('date', h.grab(c.expenditure, 'date').strftime('%m/%d/%Y'), size=16)}
${h.text('description', h.grab(c.expenditure, 'description'))}
+ +

Change how an expenditure is split up.

+ + + % for ii, user_row in enumerate(c.users): + <% + user_id, user = user_row + if user.resident: + percent = 1 + else: + percent = 0 + %> + + + + + % endfor + + + +
+ ${h.text('shares-%d.amount' % ii, percent)} + ${h.hidden('shares-%d.user_id' % ii, user.id)} +
+ ${h.submit(None, 'Submit', class_="submitbutton")} +
+
+
+ + +<%def name="transferForm()"> + <% + if c.id != '': + id = c.id + else: + id = None + %> +
+
+ ${h.auth_token_hidden_field()} + + + + + + + + + + + + + + + + + + + + + + + + +
${h.select('debtor_id', [h.grab(c.transfer, 'debtor_id')], c.users)}
${h.select('creditor_id', [h.grab(c.transfer, 'creditor_id')], c.users)}
${h.currency('amount', h.grab(c.transfer, 'amount'), size=8)}
${h.text('date', h.grab(c.transfer, 'date').strftime('%m/%d/%Y'), size=16)}
${h.text('description', h.grab(c.transfer, 'description'))}
+ +
+
+
+ diff --git a/bluechips/templates/mobile/spend/index.mako b/bluechips/templates/mobile/spend/index.mako new file mode 100644 index 0000000..e3949a4 --- /dev/null +++ b/bluechips/templates/mobile/spend/index.mako @@ -0,0 +1,6 @@ +<%inherit file="/mobile/base.mako"/> + +${self.tabs('spend')} +${self.spendForm()} +
+
diff --git a/bluechips/templates/mobile/status/index.mako b/bluechips/templates/mobile/status/index.mako index 08069e1..4fc9af9 100644 --- a/bluechips/templates/mobile/status/index.mako +++ b/bluechips/templates/mobile/status/index.mako @@ -1,29 +1,8 @@ <%inherit file="/mobile/base.mako"/> -<%! - from datetime import date -%> - -
- - - Dashboard - - - - Expense - - - - Transfer - -
+${self.tabs('status')}
- % for message in h.flash.pop_messages(): -
${message | n}
- % endfor - % if len(c.settle) == 0:

No need! The books are balanced!

% else: @@ -45,86 +24,5 @@ % endif
- -
-
- ${h.auth_token_hidden_field()} - - - - - - - - - - - - - - - - - -
${h.select('spender_id', [request.environ['user'].id], c.users)}
${h.currency('amount', 0, size=8)}
${h.text('date', date.today().strftime('%m/%d/%Y'), size=16)}
${h.text('description')}
- -

Change how an expenditure is split up.

- - - % for ii, user_row in enumerate(c.users): - <% - user_id, user = user_row - if user.resident: - percent = 1 - else: - percent = 0 - %> - - - - - % endfor - - - -
- ${h.text('shares-%d.amount' % ii, percent)} - ${h.hidden('shares-%d.user_id' % ii, user.id)} -
- ${h.submit(None, 'Submit', class_="submitbutton")} -
-
-
- -
-
- ${h.auth_token_hidden_field()} - - - - - - - - - - - - - - - - - - - - - - - - -
${h.select('debtor_id', request.environ['user'].id, c.users)}
${h.select('creditor_id', None, c.users)}
${h.currency('amount', 0, size=8)}
${h.text('date', date.today().strftime('%m/%d/%Y'), size=16)}
${h.text('description')}
- -
-
-
+${self.spendForm()} +${self.transferForm()} diff --git a/bluechips/templates/mobile/transfer/index.mako b/bluechips/templates/mobile/transfer/index.mako new file mode 100644 index 0000000..82386bc --- /dev/null +++ b/bluechips/templates/mobile/transfer/index.mako @@ -0,0 +1,6 @@ +<%inherit file="/mobile/base.mako"/> + +${self.tabs('transfer')} +${self.transferForm()} +
+
-- 2.45.2