]> asedeno.scripts.mit.edu Git - bluechips.git/blobdiff - bluechips/templates/spend/index.mako
Tweak tag implementation
[bluechips.git] / bluechips / templates / spend / index.mako
index e3195f2c367d5467a9158f5a61393669625fb03d..d4064cb58e914a3808e6daf92aa5d33de85cf32c 100644 (file)
@@ -1,10 +1,7 @@
 <%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">
     <tr>
       <th><label for="spender_id">Spender</label></th>
@@ -12,7 +9,7 @@
     </tr>
     <tr>
       <th><label for="amount">Amount</label></th>
-      <td>$${h.text('amount', "%0.2f" % (int(c.expenditure.amount) / 100.), size=8)}</td>
+      <td>${h.currency('amount', c.expenditure.amount, size=8, onkeyup="calcSplit();")}</td>
     </tr>
     <tr>
       <th><label for="date">Date</label></th>
       <th><label for="description">Description</label></th>
       <td>${h.text('description', c.expenditure.description, size=64)}</td>
     </tr>
+    <tr>
+      <th><label for="tags">Tags</label></th>
+      <td>${h.text('tags', c.tags, size=64)}</td>
+    </tr>
   </table>
 
   <p>Change how an expenditure is split up. Enter a percentage, or something like a percentage, for each user. They don't have to add to 100.</p>
 
   <table class="form">
-    % for user_id, user in c.users:
+    % for ii, user_row in enumerate(c.users):
       <%
-        try:
-            percent = c.values['shares-%d.amount' % user_id]
-        except TypeError:
-            if c.id != '':
-                try:
-                    share = [s.share for s in c.expenditure.splits if s.user == user][0]
-                    percent = (Decimal(100) * Decimal(int(share)) / Decimal(int(c.expenditure.amount))).quantize(Decimal("0.001"))
-                except IndexError:
-                    percent = 0
-            else:
-                if user == request.environ['user']:
-                    percent = 1
-                else:
-                    percent = 0
+        user_id, user = user_row
+        percent = c.values['shares-%d.amount' % ii]
       %>
       <tr>
-        <th>
-          <label for="shares-${user_id}amount">${user.name}</label>
-        </th>
+        <th><label for="shares-${ii}amount">${user.name}</label></th>
         <td>
-          ${h.text('shares-%d.amount' % user_id, percent)}
-          ${h.hidden('shares-%d.user_id' % user_id, user.id)}
+          ${h.text('shares-%d.amount' % ii, percent, class_="share-text", onkeyup="calcSplit();")}
+          ${h.hidden('shares-%d.user_id' % ii, user.id)}
+        </td>
+        <td id="shares-${ii}amount-calc" align="right">
+          0.00
         </td>
       </tr>
     % endfor
     <tr>
+      <td></td>
       <td colspan="2">
         ${h.submit(None, 'Submit', class_="submitbutton")}
+        %if c.expenditure.id:
+       <input type="button" value="Delete" onClick="window.location.href='${h.url_for(controller='spend', action='delete', id=c.expenditure.id)}'">
+       %endif
       </td>
     </tr>
   </table>
 </form>
+${h.javascript_link('%s/js/calculator.js' % request.script_name)}