diff options
Diffstat (limited to 'public')
| -rw-r--r-- | public/css/calculator.less (renamed from public/css/bitcoin_pos.css) | 12 | ||||
| -rw-r--r-- | public/css/common.less | 13 | ||||
| -rw-r--r-- | public/css/report.css | 8 | ||||
| -rw-r--r-- | public/css/report.less | 4 | ||||
| -rw-r--r-- | public/js/bitcoin_pos.js | 159 | ||||
| -rw-r--r-- | public/js/calculator.coffee | 145 | ||||
| -rw-r--r-- | public/js/report.coffee | 29 | ||||
| -rw-r--r-- | public/js/report.js | 29 |
8 files changed, 193 insertions, 206 deletions
diff --git a/public/css/bitcoin_pos.css b/public/css/calculator.less index 7da47f08..8103ed5e 100644 --- a/public/css/bitcoin_pos.css +++ b/public/css/calculator.less @@ -1,6 +1,5 @@ -body { text-align: center; } -body { font-size: 100%; line-height: 100%; } -h1 { width: 100%; text-align: center; } +@import "common"; + p, span, input[type="text"] { font-size: 1.4em; } input[type="text"] { height: 1.4em; } #exchange, #amount { width: 5em; } @@ -9,10 +8,3 @@ small, label { color: #999; font-size: 1.2em; } strong#total { font-size: 2em; } #logo { padding: 10px 0; } #error { margin-top: 10px; } - -div.container-fluid { - width: 600px; - margin-left: auto; - margin-right: auto; - text-align:left; -} diff --git a/public/css/common.less b/public/css/common.less new file mode 100644 index 00000000..fb105aec --- /dev/null +++ b/public/css/common.less @@ -0,0 +1,13 @@ +@import "/css/bootstrap.min.css"; +@import "/css/bootstrap-responsive.min.css"; + +body { text-align: center; } +body { font-size: 100%; line-height: 100%; } +h1 { width: 100%; text-align: center; } + +div.container-fluid { + width: 600px; + margin-left: auto; + margin-right: auto; + text-align:left; +} diff --git a/public/css/report.css b/public/css/report.css deleted file mode 100644 index d7ab9037..00000000 --- a/public/css/report.css +++ /dev/null @@ -1,8 +0,0 @@ -body { font-size: 100%; line-height: 100%; margin-top: 10px; } -td#total { font-weight: bold; text-align: right; } - -div.container-fluid { - margin-left: auto; - margin-right: auto; - text-align:left; -} diff --git a/public/css/report.less b/public/css/report.less new file mode 100644 index 00000000..36852aea --- /dev/null +++ b/public/css/report.less @@ -0,0 +1,4 @@ +@import "common"; +@import "/css/jquery-ui-1.9.0.custom.min.css"; + +td#total { font-weight: bold; text-align: right; } diff --git a/public/js/bitcoin_pos.js b/public/js/bitcoin_pos.js deleted file mode 100644 index 869e72e2..00000000 --- a/public/js/bitcoin_pos.js +++ /dev/null @@ -1,159 +0,0 @@ -$(function() { - var websocket = null; - var client = $('#client').val(); - var title = get('title'); - var address = get('address'); - var commission = get('commission'); - var logo = get('logo'); - var exchange = 0; - - setupPage(); - setupQR(); - setupSocket(); - - if (client != "") { - $.getJSON('client/' + client, function(data) { - var user = data[0]; - title = user.title; - address = user.address; - commission = user.commission; - logo = user.logo; - setupPage(); - }); - } - - $('#amount').keyup(updateTotal); - $('#amount').focus(); - $('#amount').focus(function() { - $('#received').hide(); - $('#payment').fadeIn('slow'); - $(this).val(''); - updateTotal(); - }); - - $('#error').click(function() { - location.reload(); - }); - - function updateTotal() { - var amount = parseFloat($('#amount').val()); - var total = amount / exchange; - total = Math.ceil(total * 10000) / 10000; - - if (!$.isNumeric(total)) { - total = ''; - } - - $('#total').html(total.toString()); - displayQR('bitcoin:' + address + '?amount=' + total.toString()); - } - - function exchangeFail() { - $('#error').show().html("Error fetching exchange rate"); - $('#calculator').hide(); - } - - function fetchExchangeRate() { - $.getJSON('ticker') - .success(function (data) { - if (data == null) { - exchangeFail(); - return; - } - - exchange = 1000 / data.out; - exchange = exchange - exchange * commission * 0.01; - exchange = Math.ceil(exchange * 100) / 100; - $('#exchange').val(exchange.toFixed(2)); - updateTotal(); - - $('#error').hide(); - $('#calculator').fadeIn('slow'); - } - ).error(exchangeFail); - - setTimeout(fetchExchangeRate, 900000); - } - - function setupPage() { - if (address == "") - address = '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr' - - if (commission == "") - commission = 3; - - if (logo != "") - $('#logo').attr('src', logo).show(); - else - $('#title').html(title); - - $('#address').html(address); - $('#received').hide(); - - fetchExchangeRate(); - } - - function setupSocket() { - setTimeout(setupSocket, 10000); - - if (!websocket || websocket.readyState != 1) { - websocket = new WebSocket("ws://api.blockchain.info:8335/inv"); - - websocket.onopen = function() { - websocket.send('{"op":"addr_sub", "addr":"' + address + '"}'); - } - - websocket.onerror = websocket.onclose = function() { - $('#calculator').hide(); - $('#error').show().html("Error connecting to payment server"); - }; - - websocket.onmessage = function(e) { - var results = eval('(' + e.data + ')'); - var from_address = ''; - var total = 0; - var received = 0; - - $.each(results.x.out, function(i, v) { - if (v.addr == address) { - received += v.value / 100000000; - } - }); - - $.each(results.x.inputs, function(i, v) { - from_address = v.prev_out.addr - if (v.prev_out.addr == address) { - input -= v.prev_out.value / 100000000; - } - }); - - if (total <= received) { - $('#amount').blur(); - $('#payment').hide(); - $('#received').fadeIn('slow'); - } - - $.get('record_transaction.php', - { - address: from_address, - date: moment().format("YYYY-MM-DD HH:mm:ss"), - received: received, - exchange: exchange - } - ); - } - } - } -}); - -function get(name) { - name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); - var regexS = "[\\?&]" + name + "=([^&#]*)"; - var regex = new RegExp(regexS); - var results = regex.exec(window.location.search); - - if(results == null) - return ""; - else - return decodeURIComponent(results[1].replace(/\+/g, " ")); -} diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee new file mode 100644 index 00000000..ed199920 --- /dev/null +++ b/public/js/calculator.coffee @@ -0,0 +1,145 @@ +#= require jquery-1.8.2.min.js +#= require moment.min.js +#= require qr.js +#= require bootstrap.min.js + +g = exports ? this + +$(-> + g.websocket = null + g.client = $('#client').val() + g.title = get('title') + g.address = get('address') + g.commission = get('commission') + g.logo = get('logo') + g.exchange = 0 + + setupPage() + setupQR() + setupSocket() + + if client? and client + $.getJSON('client/' + client, (data) -> + user = data[0] + g.title = user.title + g.address = user.address + g.commission = user.commission + g.logo = user.logo + setupPage() + ) + + $('#amount').keyup(updateTotal) + $('#amount').focus() + $('#amount').focus(-> + $('#received').hide() + $('#payment').fadeIn('slow') + $(this).val('') + updateTotal() + ) +) + +updateTotal = -> + amount = parseFloat($('#amount').val()) + total = amount / exchange + total = Math.ceil(total * 10000) / 10000 + + unless $.isNumeric(total) + total = '' + + $('#total').html(total.toString()) + displayQR('bitcoin:' + address + '?amount=' + total.toString()) + +exchangeFail = -> + $('#error').show().html("Error fetching exchange rate") + $('#calculator').hide() + +fetchExchangeRate = -> + $.getJSON('ticker') + .success((data) -> + unless data? + exchangeFail() + return + + exchange = 1000 / data.out + exchange = exchange - exchange * commission * 0.01 + g.exchange = Math.ceil(exchange * 100) / 100 + $('#exchange').val(exchange.toFixed(2)) + updateTotal() + + $('#error').hide() + $('#calculator').fadeIn('slow') + ).error(exchangeFail) + setTimeout(fetchExchangeRate, 900000) + +setupPage = -> + unless address + address = '1VAnbtCAnYccECnjaMCPnWwt81EHCVgNr' + + unless commission + commission = 3 + + if logo + $('#logo').attr('src', logo).show() + else + $('#title').html(title) + + $('#address').html(address) + $('#received').hide() + + fetchExchangeRate() + +setupSocket = -> + setTimeout(setupSocket, 10000) + + unless g.websocket and g.websocket.readyState is 1 + g.websocket = new WebSocket("ws://api.blockchain.info:8335/inv") + + g.websocket.onopen = -> + g.websocket.send('{"op":"addr_sub", "addr":"' + address + '"}') + + + g.websocket.onerror = g.websocket.onclose = -> + $('#calculator').hide() + $('#error').show().html("Error connecting to payment server") + + + g.websocket.onmessage = (e) -> + results = eval('(' + e.data + ')') + from_address = '' + total = 0 + received = 0 + + $.each(results.x.out, (i, v) -> + if (v.addr == address) + received += v.value / 100000000 + ) + + $.each(results.x.inputs, (i, v) -> + from_address = v.prev_out.addr + if (v.prev_out.addr == address) + input -= v.prev_out.value / 100000000 + ) + + if (total <= received) + $('#amount').blur() + $('#payment').hide() + $('#received').fadeIn('slow') + + $.get('record_transaction.php', + address: from_address, + date: moment().format("YYYY-MM-DD HH:mm:ss"), + received: received, + exchange: g.exchange + ) + +get = (name) -> + name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]") + regexS = "[\\?&]" + name + "=([^&#]*)" + regex = new RegExp(regexS) + results = regex.exec(window.location.search) + + if (results == null) + return "" + else + return decodeURIComponent(results[1].replace(/\+/g, " ")) + diff --git a/public/js/report.coffee b/public/js/report.coffee new file mode 100644 index 00000000..650e25b4 --- /dev/null +++ b/public/js/report.coffee @@ -0,0 +1,29 @@ +$(-> + $('.date').datepicker() + + $.getJSON('transactions', (data) -> + $.each(data.transactions, -> + keys = Object.keys(this) + transaction = this + + $.each(keys, (i,v) -> + $('tbody tr:last td:eq(' + i + ')').html(transaction[v]) + }) + + $('tbody:last').append($('tbody tr:last').clone()) + }) + $('tbody tr:last').remove() + + btc = 0 + $('td:nth-child(4)').each(-> + btc += parseFloat($(this).html()) + }) + $('#btc').html(btc) + + cad = 0 + $('td:nth-child(5)').each(-> + cad += parseFloat($(this).html()) + }) + $('#cad').html(cad) + }) +) diff --git a/public/js/report.js b/public/js/report.js deleted file mode 100644 index a470f348..00000000 --- a/public/js/report.js +++ /dev/null @@ -1,29 +0,0 @@ -$(function() { - $('.date').datepicker(); - - $.getJSON('transactions.json', function(data) { - $.each(data.transactions, function() { - var keys = Object.keys(this); - var transaction = this; - - $.each(keys, function(i,v) { - $('tbody tr:last td:eq(' + i + ')').html(transaction[v]); - }); - - $('tbody:last').append($('tbody tr:last').clone()); - }); - $('tbody tr:last').remove(); - - var btc = 0; - $('td:nth-child(4)').each(function() { - btc += parseFloat($(this).html()); - }); - $('#btc').html(btc); - - var cad = 0; - $('td:nth-child(5)').each(function() { - cad += parseFloat($(this).html()); - }); - $('#cad').html(cad); - }); -}); |
