From aaadb000fd4dc2fb9758ba92d1ea3d15871c096f Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 24 Aug 2014 21:46:41 -0700 Subject: Transaction notes and delete function --- public/js/report.coffee | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'public/js') 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(""" - - #{moment(this.date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma')} + row = $(""" + + #{date}   #{exchange.toFixed(2)} #{received.toFixed(8)} #{amount.toFixed(2)} """) + + 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()) -- cgit v1.2.3