From b1169d28812e8bf77435b657c8680dc5928355f3 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 22 Nov 2012 15:29:36 -0800 Subject: Implement transactions date filter --- public/js/report.coffee | 62 +++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/public/js/report.coffee b/public/js/report.coffee index b8a85f3e..8e9ba633 100644 --- a/public/js/report.coffee +++ b/public/js/report.coffee @@ -1,32 +1,50 @@ #= require jquery-1.8.2.min.js #= require jquery-ui-1.9.0.custom.min.js +#= require moment.min.js + +g = exports ? this $(-> - $('.date').datepicker() + $('.date').datepicker(onClose: -> + transactions = $.grep(g.transactions, (e, i) -> + from = moment($('#from').val(), "MM/DD/YYYY") + to = moment($('#to').val(), "MM/DD/YYYY") + d = moment(e.date) - $.getJSON('transactions', (data) -> - $.each(data.transactions, -> - $('tbody').append(""" - - #{this.date} - #{this.address} - #{parseFloat(this.exchange).toFixed(2)} - #{parseFloat(this.received).toFixed(2)} - #{(this.received * this.exchange).toFixed(2)} - - """) + return (!from? || d.diff(from) >= 0) && (!to? || d.diff(to) <= 0) ) - btc = 0 - $('td:nth-child(4)').each(-> - btc += parseFloat($(this).html()) - ) - $('#btc').html(btc.toFixed(2)) + display(transactions) + ) - cad = 0 - $('td:nth-child(5)').each(-> - cad += parseFloat($(this).html()) - ) - $('#cad').html(cad.toFixed(2)) + $.getJSON('transactions', (data) -> + g.transactions = data.transactions + display(g.transactions) ) ) + +display = (transactions) -> + $('tbody tr').remove() + $.each(transactions, -> + $('tbody').append(""" + + #{this.date} + #{this.address} + #{parseFloat(this.exchange).toFixed(2)} + #{parseFloat(this.received).toFixed(2)} + #{(this.received * this.exchange).toFixed(2)} + + """) + ) + + btc = 0 + $('td:nth-child(4)').each(-> + btc += parseFloat($(this).html()) + ) + $('#btc').html(btc.toFixed(2)) + + cad = 0 + $('td:nth-child(5)').each(-> + cad += parseFloat($(this).html()) + ) + $('#cad').html(cad.toFixed(2)) -- cgit v1.2.3