Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add delete feature

+ css optimizations
  • Loading branch information...
commit c7a4b00d9a2faa0ecaca95477d062a4bdb703e94 1 parent 321be6e
@iStefo authored
View
14 index.coffee
@@ -5,6 +5,8 @@ test = require 'assert'
Db = require('mongodb').Db
Connection = require('mongodb').Connection
Server = require('mongodb').Server
+BSON = require('mongodb').BSONPure
+
host = 'localhost'
port = Connection.DEFAULT_PORT
@@ -85,11 +87,21 @@ app.post '/pay/', (req, res) ->
collection.insert { subject: req.body.payment.subject, value: req.body.payment.value, by: req.session.user.name }
res.redirect '/'
-
app.get '/pay*', (req, res) ->
if not req.session.login
res.redirect '/login/'
return 0
res.render 'pay'
+app.post '/delete', (req, res) ->
+ if not req.session.login
+ res.redirect '/login/'
+ return 0
+ console.log "Delete #{req.body.id}"
+ db.open (err, db) ->
+ db.collection 'payment', (err, collection) ->
+ collection.remove { _id: BSON.ObjectID.createFromHexString(req.body.id) }, (err, result) ->
+ console.log err, result
+ res.send JSON.stringify err
+
app.listen 1337
View
22 index.js
@@ -1,5 +1,5 @@
(function() {
- var Connection, Db, Server, app, db, express, fs, host, port, test;
+ var BSON, Connection, Db, Server, app, db, express, fs, host, port, test;
fs = require('fs');
@@ -18,6 +18,8 @@
Server = require('mongodb').Server;
+ BSON = require('mongodb').BSONPure;
+
host = 'localhost';
port = Connection.DEFAULT_PORT;
@@ -145,6 +147,24 @@
return res.render('pay');
});
+ app.post('/delete', function(req, res) {
+ if (!req.session.login) {
+ res.redirect('/login/');
+ return 0;
+ }
+ console.log("Delete " + req.body.id);
+ return db.open(function(err, db) {
+ return db.collection('payment', function(err, collection) {
+ return collection.remove({
+ _id: BSON.ObjectID.createFromHexString(req.body.id)
+ }, function(err, result) {
+ console.log(err, result);
+ return res.send(JSON.stringify(err));
+ });
+ });
+ });
+ });
+
app.listen(1337);
}).call(this);
View
94 public/lib/jgestures.min.js
@@ -0,0 +1,94 @@
+/*
+ * jSwipe - jQuery Plugin
+ * http://plugins.jquery.com/project/swipe
+ * http://ryanscherf.com/demos/swipe/
+ *
+ * Copyright (c) 2009 Ryan Scherf <http://ryanscherf.com/>
+ * Modified by Mathias Bynens <http://mathiasbynens.be/>
+ * Modified by Karl Swedberg <http://learningjquery.com/>
+ * Licensed under the MIT license
+ *
+ * $Date: 2011-05-25 (Wed, 25 May 2011) $
+ * $version: 0.2.2
+ *
+ * This jQuery plugin will work on any device that supports touch events,
+ * while degrading gracefully (without throwing errors) on others.
+ */
+(function($) {
+
+ $.fn.swipe = function(options) {
+
+ // Default thresholds & swipe functions
+ options = $.extend(true, {}, $.fn.swipe.options, options);
+
+ return this.each(function() {
+
+ var self = this,
+ originalCoord = { 'x': 0, 'y': 0 },
+ finalCoord = { 'x': 0, 'y': 0 };
+
+ // Screen touched, store the initial coordinates
+ function touchStart(event) {
+ var touch = event.originalEvent.targetTouches[0];
+ originalCoord.x = touch.pageX;
+ originalCoord.y = touch.pageY;
+ }
+
+ // Store coordinates as finger is swiping
+ function touchMove(event) {
+ var touch = event.originalEvent.targetTouches[0];
+ finalCoord.x = touch.pageX; // Updated X,Y coordinates
+ finalCoord.y = touch.pageY;
+ //event.preventDefault();
+ }
+
+ // Done swiping
+ // Swipe should only be on X axis, ignore if swipe on Y axis
+ // Calculate if the swipe was left or right
+ function touchEnd() {
+ var changeY = originalCoord.y - finalCoord.y,
+ changeX,
+ threshold = options.threshold,
+ y = threshold.y,
+ x = threshold.x;
+ if (changeY < y && changeY > (- y)) {
+ changeX = originalCoord.x - finalCoord.x;
+ if (changeX > x) {
+ options.swipeLeft.call(self);
+ } else if (changeX < (- x)) {
+ options.swipeRight.call(self);
+ }
+ }
+ }
+
+ // Swipe was canceled
+ function touchCancel() {
+ //console.log('Canceling swipe gesture…')
+ }
+
+ // Add gestures to all swipable areas
+ $(self).bind({
+ 'touchstart.swipe': touchStart,
+ 'touchmove.swipe': touchMove,
+ 'touchend.swipe': touchEnd,
+ 'touchcancel.swipe': touchCancel
+ });
+
+ });
+
+ };
+
+ $.fn.swipe.options = {
+ 'threshold': {
+ 'x': 30,
+ 'y': 10
+ },
+ 'swipeLeft': function() {
+ alert('swiped left');
+ },
+ 'swipeRight': function() {
+ alert('swiped right');
+ }
+ };
+
+}(jQuery));
View
18 public/style.css
@@ -2,6 +2,12 @@ html, body, * {
margin: 0;
padding: 0;
font-family: "Helvetica", Arial;
+
+}
+
+body, htmö {
+ background: #e4e4e4;
+ min-height: 436px;
}
header {
@@ -14,6 +20,16 @@ header {
z-index: 10;
}
+header.login {
+ position: absolute;
+ left: 0;
+ top: 0;
+}
+
+#loginbutton {
+ position: absolute;
+}
+
header h1 {
margin: 20px 20px;
display: block;
@@ -65,8 +81,6 @@ header h1 {
top: 80px;
left: 0;
right: 0;
- bottom: 0;
- background: #e4e4e4;
}
#logincontainer label {
View
18 views/index.jade
@@ -1,6 +1,6 @@
header
h1 #{name}
- if balance > 0
+ if balance >= 0
#paybutton.navbutton.green
span #{balance/100}
span +
@@ -11,11 +11,11 @@ header
#container
for payment in payments
if payment.by == name
- .payment
+ .payment(data-subject=payment.subject, data-by=payment.by, data-id=payment._id)
span.subject #{payment.subject}
span.value #{payment.value/100}
else
- .payment.alien
+ .payment.alien(data-subject=payment.subject, data-by=payment.by, data-id=payment._id)
span.subject #{payment.subject}
span.value -#{payment.value/100}
div(style="width:0; height: 0; visibility: hidden")
@@ -24,4 +24,14 @@ script
$('#paybutton').click(function() {
$('#payform').submit();
//location.replace('/pay');
- });
+ });
+ $('#container div').swipe({swipeRight: function() {
+ var answer = confirm("Delete " + $(this).data('subject') + " by " + $(this).data('by') + "?");
+ self = $(this);
+ if (answer) {
+ $.post("/delete", { id: self.data('id')}, function(data){
+ self.fadeOut();
+ location.replace('/');
+ });
+ }
+ }});
View
5 views/layout.jade
@@ -4,5 +4,6 @@ html
link(rel="stylesheet", type="text/css", href="/style.css")
meta(name="apple-mobile-web-app-capable", content="no")
meta(name="viewport", content="user-scalable=no, width=device-width")
- script(src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js")
- body!= body
+ script(src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js")
+ script(src="/lib/jgestures.min.js")
+ body(onload="setTimeout(function() { window.scrollTo(0, 1) }, 1);")!= body
View
2  views/loginform.jade
@@ -1,4 +1,4 @@
-header
+header.login
h1 Borrowmeter
#loginbutton.navbutton.green
span Login
Please sign in to comment.
Something went wrong with that request. Please try again.