From 931f2262d9ef7f571fe87b176f6cd531b3579a68 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 16 Jan 2017 22:03:44 -0800 Subject: Migrate sales page --- static/js/report.coffee | 148 ------------------------------------------------ static/js/report.js | 143 ---------------------------------------------- 2 files changed, 291 deletions(-) delete mode 100644 static/js/report.coffee delete mode 100644 static/js/report.js (limited to 'static') diff --git a/static/js/report.coffee b/static/js/report.coffee deleted file mode 100644 index 3fee6714..00000000 --- a/static/js/report.coffee +++ /dev/null @@ -1,148 +0,0 @@ -g = exports ? this - -$(-> - from = moment().subtract(7, 'days') - to = moment() - - $('#from').html(from.format("MMMM Do, YYYY")) - $('#to').html(to.format("MMMM Do, YYYY")) - - $('#from_date').val(from.format("MM/DD/YYYY")) - $('#to_date').val(to.format("MM/DD/YYYY")) - - $('#from_date').datepicker(onClose: filterDates) - $('#to_date').datepicker(onClose: filterDates) - - $('#from').click(-> $('#from_date').datepicker('show').blur()) - $('#to').click(-> $('#to_date').datepicker('show').blur()) - - $.getJSON('transactions.json', (data) -> - g.transactions = data.transactions.filter((t) -> t.user is $('#user').val()) - display(g.transactions) - filterDates() - ) -) - -filterDates = -> - $('#from').html(moment($('#from_date').datepicker('getDate')).format("MMMM Do, YYYY")) - $('#to').html(moment($('#to_date').datepicker('getDate')).format("MMMM Do, YYYY")) - - transactions = $.grep(g.transactions, (e, i) -> - return false unless e - - from = moment($('#from_date').val(), "MM/DD/YYYY") - to = moment($('#to_date').val(), "MM/DD/YYYY") - - d = moment(e.date) - amount = parseFloat(e.exchange) * parseFloat(e.received) - - !isNaN(parseFloat(amount)) && isFinite(amount) && - (!from? || d.diff(from, 'days') >= 0) && (!to? || d.diff(to, 'days') <= 0) - ) - - display(transactions) - -display = (transactions) -> - $('.report tbody tr').remove() - - if transactions.length is 0 - $('.report').hide() - $('.alert').fadeIn() - else - $('.alert').hide() - btc_total = btc_tips_total = 0 - fiat_total = fiat_tips_total = 0 - - $.each(transactions, -> - btc_tip_str = "" - fiat_tip_str = "" - - exchange = parseFloat(@exchange) - tip = @tip - btc = parseFloat(@received) - fiat = btc * exchange - - btc_total += parseFloat(btc.toFixed(8)) - fiat_total += parseFloat(fiat.toFixed(2)) - - if tip > 1 - btc = btc / tip - btc_tip = (btc * tip - btc).toFixed(8) - fiat_tip = (btc_tip * exchange).toFixed(2) - - btc_tips_total += parseFloat(btc_tip) - fiat_tips_total += parseFloat(fiat_tip) - - btc_tip_str = "
+ #{btc_tip}" - fiat_tip_str = "
+ #{fiat_tip}" - - fiat = btc * exchange - - notes = @notes - txid = @txid - date = moment(@date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma') - - row = $(""" - - #{date}   - #{exchange.toFixed(2)} - #{btc.toFixed(8)}#{btc_tip_str} - #{fiat.toFixed(2)}#{fiat_tip_str} - - """) - - if notes - row.attr('data-notes', notes) - row.find('span').removeClass('hidden') - - $('.report tbody').append(row) - - row.click(-> - $('#confirm, #yousure').hide() - $('#buttons, #modal textarea').show() - notes = $(this).attr('data-notes') - - $('#modal').modal() - $('#modal textarea').val('') - $('#modal .btn-primary').toggle(txid? and txid.length > 5) - - $('#modal .btn-danger').off().click(-> - $('#yousure, #confirm').show() - $('#buttons, #modal textarea').hide() - ) - - $('#confirm .btn-danger').click(-> - $.ajax(type: 'delete', url: "/#{$('#user').val()}/transactions/#{txid}") - $('#modal').modal('hide') - row.fadeOut('slow') - ) - - $('#modal .btn-primary').off().click(-> - window.open("https://blockchain.info/tx/#{txid}", '_blank') - $('#modal').modal('hide') - ) - - $('#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_total').html("#{parseFloat(btc_total).toFixed(8)}") - $('#fiat_total').html("#{parseFloat(fiat_total).toFixed(2)}") - $('#btc_tips').html("#{parseFloat(btc_tips_total).toFixed(8)}") - $('#fiat_tips').html("#{parseFloat(fiat_tips_total).toFixed(2)}") - $('#btc').html("#{parseFloat(btc_total - btc_tips_total).toFixed(8)}") - $('#fiat').html("#{parseFloat(fiat_total - fiat_tips_total).toFixed(2)}") - - $('.report').fadeIn() diff --git a/static/js/report.js b/static/js/report.js deleted file mode 100644 index 31b3b689..00000000 --- a/static/js/report.js +++ /dev/null @@ -1,143 +0,0 @@ -(function() { - var display, filterDates, g; - - g = typeof exports !== "undefined" && exports !== null ? exports : this; - - $(function() { - var from, to; - from = moment().subtract(7, 'days'); - to = moment(); - $('#from').html(from.format("MMMM Do, YYYY")); - $('#to').html(to.format("MMMM Do, YYYY")); - $('#from_date').val(from.format("MM/DD/YYYY")); - $('#to_date').val(to.format("MM/DD/YYYY")); - $('#from_date').datepicker({ - onClose: filterDates - }); - $('#to_date').datepicker({ - onClose: filterDates - }); - $('#from').click(function() { - return $('#from_date').datepicker('show').blur(); - }); - $('#to').click(function() { - return $('#to_date').datepicker('show').blur(); - }); - return $.getJSON('transactions.json', function(data) { - g.transactions = data.transactions.filter(function(t) { - return t.user === $('#user').val(); - }); - display(g.transactions); - return filterDates(); - }); - }); - - filterDates = function() { - var transactions; - $('#from').html(moment($('#from_date').datepicker('getDate')).format("MMMM Do, YYYY")); - $('#to').html(moment($('#to_date').datepicker('getDate')).format("MMMM Do, YYYY")); - transactions = $.grep(g.transactions, function(e, i) { - var amount, d, from, to; - if (!e) { - return false; - } - from = moment($('#from_date').val(), "MM/DD/YYYY"); - to = moment($('#to_date').val(), "MM/DD/YYYY"); - d = moment(e.date); - amount = parseFloat(e.exchange) * parseFloat(e.received); - return !isNaN(parseFloat(amount)) && isFinite(amount) && ((from == null) || d.diff(from, 'days') >= 0) && ((to == null) || d.diff(to, 'days') <= 0); - }); - return display(transactions); - }; - - display = function(transactions) { - var btc_tips_total, btc_total, fiat_tips_total, fiat_total; - $('.report tbody tr').remove(); - if (transactions.length === 0) { - $('.report').hide(); - return $('.alert').fadeIn(); - } else { - $('.alert').hide(); - btc_total = btc_tips_total = 0; - fiat_total = fiat_tips_total = 0; - $.each(transactions, function() { - var btc, btc_tip, btc_tip_str, date, exchange, fiat, fiat_tip, fiat_tip_str, notes, row, tip, txid; - btc_tip_str = ""; - fiat_tip_str = ""; - exchange = parseFloat(this.exchange); - tip = this.tip; - btc = parseFloat(this.received); - fiat = btc * exchange; - btc_total += parseFloat(btc.toFixed(8)); - fiat_total += parseFloat(fiat.toFixed(2)); - if (tip > 1) { - btc = btc / tip; - btc_tip = (btc * tip - btc).toFixed(8); - fiat_tip = (btc_tip * exchange).toFixed(2); - btc_tips_total += parseFloat(btc_tip); - fiat_tips_total += parseFloat(fiat_tip); - btc_tip_str = "
+ " + btc_tip + ""; - fiat_tip_str = "
+ " + fiat_tip + ""; - } - fiat = btc * exchange; - notes = this.notes; - txid = this.txid; - date = moment(this.date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma'); - row = $("\n " + date + "  \n " + (exchange.toFixed(2)) + "\n " + (btc.toFixed(8)) + btc_tip_str + "\n " + (fiat.toFixed(2)) + fiat_tip_str + "\n"); - if (notes) { - row.attr('data-notes', notes); - row.find('span').removeClass('hidden'); - } - $('.report tbody').append(row); - return row.click(function() { - $('#confirm, #yousure').hide(); - $('#buttons, #modal textarea').show(); - notes = $(this).attr('data-notes'); - $('#modal').modal(); - $('#modal textarea').val(''); - $('#modal .btn-primary').toggle((txid != null) && txid.length > 5); - $('#modal .btn-danger').off().click(function() { - $('#yousure, #confirm').show(); - return $('#buttons, #modal textarea').hide(); - }); - $('#confirm .btn-danger').click(function() { - $.ajax({ - type: 'delete', - url: "/" + ($('#user').val()) + "/transactions/" + txid - }); - $('#modal').modal('hide'); - return row.fadeOut('slow'); - }); - $('#modal .btn-primary').off().click(function() { - window.open("https://blockchain.info/tx/" + txid, '_blank'); - return $('#modal').modal('hide'); - }); - $('#modal textarea').off().change(function() { - notes = $(this).val(); - if (txid) { - $.post("/transactions/" + txid, { - notes: $(this).val() - }); - } - row.find('span').addClass('hidden'); - if (notes) { - row.find('span').removeClass('hidden'); - } - return row.attr('data-notes', $(this).val()); - }); - if (notes) { - return $('#modal textarea').val(notes); - } - }); - }); - $('#btc_total').html("" + (parseFloat(btc_total).toFixed(8))); - $('#fiat_total').html("" + (parseFloat(fiat_total).toFixed(2))); - $('#btc_tips').html("" + (parseFloat(btc_tips_total).toFixed(8))); - $('#fiat_tips').html("" + (parseFloat(fiat_tips_total).toFixed(2))); - $('#btc').html("" + (parseFloat(btc_total - btc_tips_total).toFixed(8))); - $('#fiat').html("" + (parseFloat(fiat_total - fiat_tips_total).toFixed(2))); - return $('.report').fadeIn(); - } - }; - -}).call(this); -- cgit v1.2.3