matemat/static/js/depositlist.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-04-07 02:41:53 +02:00
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
2021-04-07 09:36:18 +02:00
let product_id = null;
2021-04-07 02:41:53 +02:00
let deposit = '0';
let button = document.createElement('div');
let input = document.getElementById('deposit-wrapper');
let amount = document.getElementById('deposit-amount');
2021-04-07 09:36:18 +02:00
let title = document.getElementById('deposit-title');
2021-04-07 02:41:53 +02:00
button.classList.add('thumblist-item');
button.classList.add('fakelink');
button.innerText = 'Deposit';
button.onclick = (ev) => {
2021-04-07 09:36:18 +02:00
product_id = null;
2021-04-07 02:41:53 +02:00
deposit = '0';
2021-04-07 09:36:18 +02:00
title.innerText = 'Deposit';
2021-04-07 02:41:53 +02:00
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
input.classList.add('show');
};
2021-04-07 09:36:18 +02:00
setup_custom_price = (pid, pname) => {
product_id = pid;
title.innerText = pname;
deposit = '0';
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
input.classList.add('show');
};
2021-04-07 02:41:53 +02:00
deposit_key = (k) => {
if (k == 'ok') {
2021-04-07 09:36:18 +02:00
if (product_id === null) {
window.location.href = '/deposit?n=' + parseInt(deposit);
} else {
window.location.href = '/buy?pid=' + product_id + '&price=' + parseInt(deposit);
}
2021-04-07 02:41:53 +02:00
deposit = '0';
2021-04-07 09:36:18 +02:00
product_id = null;
2021-04-07 02:41:53 +02:00
input.classList.remove('show');
} else if (k == 'del') {
if (deposit == '0') {
2021-04-07 09:36:18 +02:00
product_id = null;
2021-04-07 02:41:53 +02:00
input.classList.remove('show');
}
deposit = deposit.substr(0, deposit.length - 1);
if (deposit.length == 0) {
deposit = '0';
}
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
} else {
if (deposit == '0') {
deposit = k;
} else {
deposit += k;
}
amount.innerText = (Math.floor(parseInt(deposit) / 100)) + '.' + (parseInt(deposit) % 100).pad();
}
};
let list = document.getElementById('depositlist');
list.innerHTML = '';
list.appendChild(button);