aboutsummaryrefslogtreecommitdiffstats
path: root/public/js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2014-08-24 21:46:41 -0700
committerAdam Soltys <[email protected]>2014-08-24 21:46:41 -0700
commitaaadb000fd4dc2fb9758ba92d1ea3d15871c096f (patch)
treece8074d2e0933f88003196c1a83a9ab9b8db6710 /public/js
parentaffe228986f76b06aa96b3789852a01f8a950644 (diff)
downloadcoinos-server-aaadb000fd4dc2fb9758ba92d1ea3d15871c096f.tar.gz
coinos-server-aaadb000fd4dc2fb9758ba92d1ea3d15871c096f.zip
Transaction notes and delete function
Diffstat (limited to 'public/js')
-rw-r--r--public/js/report.coffee47
1 files changed, 42 insertions, 5 deletions
diff --git a/public/js/report.coffee b/public/js/report.coffee
index 99a0df25..72000fc8 100644
--- a/public/js/report.coffee
+++ b/public/js/report.coffee
@@ -56,20 +56,57 @@ display = (transactions) ->
else
$('.alert').hide()
$.each(transactions, ->
- exchange = parseFloat(this.exchange)
- received = parseFloat(this.received)
+ exchange = parseFloat(@exchange)
+ received = parseFloat(@received)
amount = received * exchange
+ notes = @notes
+ txid = @txid
+ date = moment(@date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma')
- $('.report tbody').append("""
- <tr>
- <td>#{moment(this.date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma')}</td>
+ row = $("""
+ <tr id='#{@txid}'>
+ <td>#{date}&nbsp;&nbsp;<span class='glyphicon glyphicon-tag hidden'></span></td>
<td>#{exchange.toFixed(2)}</td>
<td>#{received.toFixed(8)}</td>
<td>#{amount.toFixed(2)}</td>
</tr>
""")
+
+ if notes
+ row.attr('data-notes', notes)
+ row.find('span').removeClass('hidden')
+
+ $('.report tbody').append(row)
+
+ row.click(->
+ notes = $(this).attr('data-notes')
+
+ $('#modal').modal()
+ $('#modal textarea').val('')
+
+ $('#modal .btn-danger').off().click(->
+ $.ajax(type: 'delete', url: "/#{$('#user').val()}/transactions/#{txid}")
+ $('#modal').modal('hide')
+ row.remove()
+ )
+
+ $('#modal textarea').off().change(->
+ notes = $(this).val()
+ $.post("/transactions/#{txid}", notes: $(this).val()) if txid
+
+ row.find('span').addClass('hidden')
+ if notes
+ row.find('span').removeClass('hidden')
+
+ row.attr('data-notes', $(this).val())
+ )
+
+ if notes
+ $('#modal textarea').val(notes)
+ )
)
+
btc = 0
$('table.report tbody td:nth-child(3)').each(->
btc += parseFloat($(this).html())