]> asedeno.scripts.mit.edu Git - bluechips.git/commitdiff
more refinements to the iphone targeted interface, improved validation functionality...
authorScott Torborg <scott@crookedmedia.com>
Fri, 13 Nov 2009 04:16:17 +0000 (20:16 -0800)
committerScott Torborg <scott@crookedmedia.com>
Fri, 13 Nov 2009 04:16:17 +0000 (20:16 -0800)
bluechips/lib/helpers.py
bluechips/public/css/mobile.css
bluechips/public/js/mobile.js
bluechips/templates/mobile/base.mako
bluechips/templates/mobile/spend/index.mako [new file with mode: 0644]
bluechips/templates/mobile/status/index.mako
bluechips/templates/mobile/transfer/index.mako [new file with mode: 0644]

index 8da5a575b21d8adf6b6f619147ea416b0f5729c3..0f49a54b6293f6175f1fef9c120296b112a0fb65 100644 (file)
@@ -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()
index e79d9e5c49acb709b5cdaf5247b5172e142433fb..78a669d94dce228d003f0c005fc80977fac70dc0 100644 (file)
@@ -34,6 +34,3 @@ body {
 div.tab {
     display: none;
 }
-#tab-status {
-    display: block;
-}
index 6d01307dd55fb988d4032efa13b678da71850855..a7ab3266d5d65627dd1cde160039b0d1a1009e55 100644 (file)
@@ -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");
 });
index fa2ea6d2c522aa2e6a5b6b08000bc060b8c97712..b96ce4fa6cad83ad377d185a49e39d1c1afb3d8e 100644 (file)
     <link rel="apple-touch-icon" href="/icons/apple-touch.png">
   </head>
   <body>
+    % for message in h.flash.pop_messages():
+      <div class="flash">${message | n}</div>
+    % endfor
     ${next.body()}
     ${h.javascript_link('/js/jquery-1.3.2.js')}
     ${h.javascript_link('/js/mobile.js')}
   </body>
 </html>
 
+<%!
+  from datetime import date
+%>
+
 <%def name="title()">BlueChips
 % if c.title != '':
   :: ${c.title}
     ${user.name}
   % endif
 </%def>
+
+<%def name="tabs(selected)">
+  <div id="tabs">
+    % for name in ('status', 'spend', 'transfer'):
+      <%
+        if name == selected:
+          klass = 'selected'
+        else:
+          klass = 'unselected'
+      %>
+      <a id="${name}" class="${klass}" href="${h.url_for(controller=name, action='index', id=None)}">
+        <img src="/icons/${name}.png" alt="">
+        <span>${name.capitalize()}</span>
+      </a>
+    % endfor
+  </div>
+</%def>
+
+<%def name="spendForm()">
+  <div id="tab-spend" class="tab">
+    <%
+      if c.id != '':
+          id = c.id
+      else:
+          id = None
+    %>
+    <form action="${h.url_for(controller='spend', action='update', id=id)}" method="post">
+      ${h.auth_token_hidden_field()}
+      <table class="form">
+        <tr>
+          <th><label for="spender_id">Spender</label></th>
+          <td>${h.select('spender_id', [h.grab(c.expenditure, 'spender_id')], c.users)}</td>
+        </tr>
+        <tr>
+          <th><label for="amount">Amount</label></th>
+          <td>${h.currency('amount', h.grab(c.expenditure, 'amount'), size=8)}</td>
+        </tr>
+        <tr>
+          <th><label for="date">Date</label></th>
+          <td>${h.text('date', h.grab(c.expenditure, 'date').strftime('%m/%d/%Y'), size=16)}</td>
+        </tr>
+        <tr>
+          <th><label for="description">Description</label></th>
+          <td>${h.text('description', h.grab(c.expenditure, '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>
+</%def>
+
+<%def name="transferForm()">
+  <%
+    if c.id != '':
+        id = c.id
+    else:
+        id = None
+  %>
+  <div id="tab-transfer" class="tab">
+    <form action="${h.url_for(controller='transfer', action='update', id=id)}" method="post">
+      ${h.auth_token_hidden_field()}
+      <table class="form">
+        <tr>
+          <th><label for="debtor_id">From</label></th>
+          <td>${h.select('debtor_id', [h.grab(c.transfer, 'debtor_id')], c.users)}</td>
+        </tr>
+        <tr>
+          <th><label for="creditor_id">To</label></th>
+          <td>${h.select('creditor_id', [h.grab(c.transfer, 'creditor_id')], c.users)}</td>
+        </tr>
+        <tr>
+          <th><label for="amount">Amount</label></th>
+          <td>${h.currency('amount', h.grab(c.transfer, 'amount'), size=8)}</td>
+        </tr>
+        <tr>
+          <th><label for="date">Date</label></th>
+          <td>${h.text('date', h.grab(c.transfer, 'date').strftime('%m/%d/%Y'), size=16)}</td>
+        </tr>
+        <tr>
+          <th><label for="description">Description</label></th>
+          <td>${h.text('description', h.grab(c.transfer, 'description'))}</td>
+        </tr>
+        <tr>
+          <td colspan="2">
+            <input type="submit" value="Submit" />
+          </td>
+        </tr>
+      </table>
+    </form>
+  </div>
+</%def>
diff --git a/bluechips/templates/mobile/spend/index.mako b/bluechips/templates/mobile/spend/index.mako
new file mode 100644 (file)
index 0000000..e3949a4
--- /dev/null
@@ -0,0 +1,6 @@
+<%inherit file="/mobile/base.mako"/>
+
+${self.tabs('spend')}
+${self.spendForm()}
+<div id="tab-status" class="tab"></div>
+<div id="tab-transfer" class="tab"></div>
index 08069e1b67bf341297fbfcbe8deb3ee3f86dbdb1..4fc9af9aa02ead1e95d9c8bf5b827a2371432602 100644 (file)
@@ -1,29 +1,8 @@
 <%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>
+${self.tabs('status')}
 
 <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:
     </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>
+${self.spendForm()}
+${self.transferForm()}
diff --git a/bluechips/templates/mobile/transfer/index.mako b/bluechips/templates/mobile/transfer/index.mako
new file mode 100644 (file)
index 0000000..82386bc
--- /dev/null
@@ -0,0 +1,6 @@
+<%inherit file="/mobile/base.mako"/>
+
+${self.tabs('transfer')}
+${self.transferForm()}
+<div id="tab-status" class="tab"></div>
+<div id="tab-spend" class="tab"></div>