aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2012-11-22 15:29:36 -0800
committerAdam Soltys <[email protected]>2012-11-22 15:29:36 -0800
commitb1169d28812e8bf77435b657c8680dc5928355f3 (patch)
tree8e55ac77fbfa0893198c4b9d7945cb0cb49d9278
parentd63fd390890174a4f734fb13ed9cbd500fe004ca (diff)
downloadcoinos-server-b1169d28812e8bf77435b657c8680dc5928355f3.tar.gz
coinos-server-b1169d28812e8bf77435b657c8680dc5928355f3.zip
Implement transactions date filter
-rw-r--r--public/js/report.coffee62
1 files 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("""
- <tr>
- <td>#{this.date}</td>
- <td>#{this.address}</td>
- <td>#{parseFloat(this.exchange).toFixed(2)}</td>
- <td>#{parseFloat(this.received).toFixed(2)}</td>
- <td>#{(this.received * this.exchange).toFixed(2)}</td>
- </tr>
- """)
+ 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("""
+ <tr>
+ <td>#{this.date}</td>
+ <td>#{this.address}</td>
+ <td>#{parseFloat(this.exchange).toFixed(2)}</td>
+ <td>#{parseFloat(this.received).toFixed(2)}</td>
+ <td>#{(this.received * this.exchange).toFixed(2)}</td>
+ </tr>
+ """)
+ )
+
+ 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))