]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
began work on iphone-targeted web interface
authorScott Torborg <scott@crookedmedia.com>
Wed, 11 Nov 2009 18:46:34 +0000 (10:46 -0800)
committerScott Torborg <scott@crookedmedia.com>
Wed, 11 Nov 2009 18:48:28 +0000 (10:48 -0800)
bluechips/controllers/status.py
bluechips/lib/base.py
bluechips/public/css/mobile.css [new file with mode: 0644]
bluechips/public/icons/apple-touch.png [new file with mode: 0644]
bluechips/public/js/mobile.js [new file with mode: 0644]
bluechips/templates/mobile/base.mako [new file with mode: 0644]
bluechips/templates/mobile/error.mako [new file with mode: 0644]
bluechips/templates/mobile/status/index.mako [new file with mode: 0644]
bluechips/templates/spend/index.mako

index 04ad79b6a5bce8476f51942fe8172f81ca1770d5..7e81cd505854151136b98797c4659689d6ca413f 100644 (file)
@@ -66,6 +66,7 @@ class StatusController(BaseController):
                 model.Transfer.debtor==request.environ['user'],
                 model.Transfer.creditor==request.environ['user'])).\
                 limit(10).all()
+        c.users = meta.Session.query(model.User.id, model.User)
         
         return render('/status/index.mako')
     
index 586336c3a351ff1c25ce3f14f01624601cc8d03e..8e7c20cfdfefe88a529456f2f335114ccf33250a 100644 (file)
@@ -2,12 +2,15 @@
 
 Provides the BaseController class for subclassing.
 """
+
 from decorator import decorator
 
-from pylons import request, tmpl_context as c
+from pylons import request, session, tmpl_context as c
 from pylons.controllers import WSGIController
 from pylons.i18n import _, ungettext, N_
-from pylons.templating import render_mako as render
+from pylons.templating import render_mako
+
+from mako.exceptions import TopLevelLookupException
 
 import bluechips.lib.helpers as h
 from bluechips import model
@@ -48,6 +51,16 @@ def redirect_on_get(action):
             return func(*args, **kwargs)
     return redirect_on_get_wrap
 
+def render(name, *args, **kwargs):
+    if 'iPhone' in request.user_agent:
+        if session.get('use_non_mobile'):
+            c.mobile_client = True
+        else:
+            try:
+                return render_mako('/mobile' + name, *args, **kwargs)
+            except TopLevelLookupException:
+                pass
+    return render_mako(name, *args, **kwargs)
 
 __all__ = ['c', 'h', 'render', 'model', 'meta', '_', 'ungettext', 'N_',
            'BaseController', 'update_sar', 'redirect_on_get']
diff --git a/bluechips/public/css/mobile.css b/bluechips/public/css/mobile.css
new file mode 100644 (file)
index 0000000..e79d9e5
--- /dev/null
@@ -0,0 +1,39 @@
+body {
+    width: auto;
+    font-size: 1em;
+}
+#tabs img {
+    width: 64px;
+    height: 64px;
+}
+#tabs a {
+    text-align: center;
+    display: block;
+    width: 98px;
+    float: left;
+    border-top: 1px solid #fff;
+    border-bottom: 1px solid #000;
+    padding: 5px 1px;
+}
+#tabs a.selected {
+    border: 1px solid #000;
+    border-bottom: 1px solid #fff;
+    padding: 5px 0;
+    -webkit-border-top-left-radius: 10px;
+    -webkit-border-top-right-radius: 10px;
+}
+#tabs:after {
+    content: ".";
+    display: block;
+    clear: both;
+    visibility: hidden;
+    line-height: 0;
+    height: 0;
+    margin-bottom: 10px;
+}
+div.tab {
+    display: none;
+}
+#tab-status {
+    display: block;
+}
diff --git a/bluechips/public/icons/apple-touch.png b/bluechips/public/icons/apple-touch.png
new file mode 100644 (file)
index 0000000..bce6f9d
Binary files /dev/null and b/bluechips/public/icons/apple-touch.png differ
diff --git a/bluechips/public/js/mobile.js b/bluechips/public/js/mobile.js
new file mode 100644 (file)
index 0000000..6d01307
--- /dev/null
@@ -0,0 +1,20 @@
+try {
+    console.log("init");
+} catch(e) {
+    console = { log: function() {} };
+}
+
+$(function() {
+    console.log("ready()");
+
+    $('#tabs a').click(function() {
+        $('div.tab').hide();
+        $('#tabs a').removeClass('selected');
+        $(this).addClass('selected');
+        $('#tab-' + $(this).attr('id')).show();
+        return false;
+    });
+
+    console.log("ready() done");
+});
+
diff --git a/bluechips/templates/mobile/base.mako b/bluechips/templates/mobile/base.mako
new file mode 100644 (file)
index 0000000..fa2ea6d
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+    <title>${self.title()}</title>
+    ${h.stylesheet_link('/css/main.css')}
+    <link media="only screen and (max-device-width: 480px)" href="/css/mobile.css" type="text/css" rel="stylesheet">
+    <meta name="viewport" content="width = device-width, user-scalable=no">
+    <link rel="apple-touch-icon" href="/icons/apple-touch.png">
+  </head>
+  <body>
+    ${next.body()}
+    ${h.javascript_link('/js/jquery-1.3.2.js')}
+    ${h.javascript_link('/js/mobile.js')}
+  </body>
+</html>
+
+<%def name="title()">BlueChips
+% if c.title != '':
+  :: ${c.title}
+% endif
+</%def>
+
+<%def name="formatUser(user)">
+  % if user == request.environ['user']:
+    <strong>Me</strong>
+  % else:
+    ${user.name}
+  % endif
+</%def>
diff --git a/bluechips/templates/mobile/error.mako b/bluechips/templates/mobile/error.mako
new file mode 100644 (file)
index 0000000..bb891c7
--- /dev/null
@@ -0,0 +1,5 @@
+<%inherit file="/mobile/base.mako"/>
+
+<h1>${c.code}</h1>
+
+<h2><a href="${h.url_for('/')}">Return</a>
diff --git a/bluechips/templates/mobile/status/index.mako b/bluechips/templates/mobile/status/index.mako
new file mode 100644 (file)
index 0000000..08069e1
--- /dev/null
@@ -0,0 +1,130 @@
+<%inherit file="/mobile/base.mako"/>
+
+<%!
+  from datetime import date
+%>
+
+<div id="tabs">
+  <a id="status" class="selected" href="#">
+    <img src="/icons/dashboard.png" alt="">
+    <span>Dashboard</span>
+  </a>
+  <a id="spend" href="#">
+    <img src="/icons/spend.png" alt="">
+    <span>Expense</span>
+  </a>
+  <a id="transfer" href="#">
+    <img src="/icons/transfer.png" alt="">
+    <span>Transfer</span>
+  </a>
+</div>
+
+<div id="tab-status" class="tab">
+  % for message in h.flash.pop_messages():
+    <div class="flash">${message | n}</div>
+  % endfor
+
+  % if len(c.settle) == 0:
+    <p>No need! The books are balanced!</p>
+  % else:
+    <p>To balance the books, the following transfers need to be made:</p>
+
+    <table id="balance">
+      <tr>
+        <th>From</th>
+        <th>To</th>
+        <th>Amount</th>
+      </tr>
+      % for transfer in c.settle:
+        <tr>
+          <td>${transfer[0].name}</td>
+          <td>${transfer[1].name}</td>
+          <td>${transfer[2]}</td>
+        </tr>
+      % endfor
+    </table>
+  % endif
+</div>
+
+<div id="tab-spend" class="tab">
+  <form action="${h.url_for(controller='spend', action='update')}" method="post">
+    ${h.auth_token_hidden_field()}
+    <table class="form">
+      <tr>
+        <th><label for="spender_id">Spender</label></th>
+        <td>${h.select('spender_id', [request.environ['user'].id], c.users)}</td>
+      </tr>
+      <tr>
+        <th><label for="amount">Amount</label></th>
+        <td>${h.currency('amount', 0, size=8)}</td>
+      </tr>
+      <tr>
+        <th><label for="date">Date</label></th>
+        <td>${h.text('date', date.today().strftime('%m/%d/%Y'), size=16)}</td>
+      </tr>
+      <tr>
+        <th><label for="description">Description</label></th>
+        <td>${h.text('description')}</td>
+      </tr>
+    </table>
+
+    <p>Change how an expenditure is split up.</p>
+
+    <table class="form">
+      % for ii, user_row in enumerate(c.users):
+        <%
+          user_id, user = user_row
+          if user.resident:
+            percent = 1
+          else:
+            percent = 0
+        %>
+        <tr>
+          <th><label for="shares-${ii}amount">${user.name}</label></th>
+          <td>
+            ${h.text('shares-%d.amount' % ii, percent)}
+            ${h.hidden('shares-%d.user_id' % ii, user.id)}
+          </td>
+        </tr>
+      % endfor
+      <tr>
+        <td colspan="2">
+          ${h.submit(None, 'Submit', class_="submitbutton")}
+        </td>
+      </tr>
+    </table>
+  </form>
+</div>
+
+<div id="tab-transfer" class="tab">
+  <form action="${h.url_for(controller='transfer', action='update')}" method="post">
+    ${h.auth_token_hidden_field()}
+    <table class="form">
+      <tr>
+        <th><label for="debtor_id">From</label></th>
+        <td>${h.select('debtor_id', request.environ['user'].id, c.users)}</td>
+      </tr>
+      <tr>
+        <th><label for="creditor_id">To</label></th>
+        <td>${h.select('creditor_id', None, c.users)}</td>
+      </tr>
+      <tr>
+        <th><label for="amount">Amount</label></th>
+        <td>${h.currency('amount', 0, size=8)}</td>
+      </tr>
+      <tr>
+        <th><label for="date">Date</label></th>
+        <td>${h.text('date', date.today().strftime('%m/%d/%Y'), size=16)}</td>
+      </tr>
+      <tr>
+        <th><label for="description">Description</label></th>
+        <td>${h.text('description')}</td>
+      </tr>
+      <tr>
+        <td colspan="2">
+          <input type="submit" value="Submit" />
+        </td>
+      </tr>
+    </table>
+  </form>
+</div>
index ff388a3eecace604ab6cb86bd8cb13efb9245091..1b0c6e3c493279f5f25c78ea4b96fcd7a8804582 100644 (file)
@@ -1,9 +1,5 @@
 <%inherit file="/base.mako"/>
 
-<%!
-    from decimal import Decimal
-%>
-
 <form action="${h.url_for(controller='spend', action='update', id=c.expenditure.id)}" method="post">
   ${h.auth_token_hidden_field()}
   <table class="form">