diff --git a/barcoder/Views/Home/Mobilepay.cshtml b/barcoder/Views/Home/Mobilepay.cshtml index 63a02f3..87c1bf6 100644 --- a/barcoder/Views/Home/Mobilepay.cshtml +++ b/barcoder/Views/Home/Mobilepay.cshtml @@ -6,18 +6,22 @@
-
+
- - + + +
+
+ +
- + @@ -27,9 +31,9 @@
- - + +
- \ No newline at end of file + diff --git a/barcoder/wwwroot/js/mobilepay.js b/barcoder/wwwroot/js/mobilepay.js index ba6be74..5884647 100644 --- a/barcoder/wwwroot/js/mobilepay.js +++ b/barcoder/wwwroot/js/mobilepay.js @@ -26,47 +26,66 @@ document.querySelectorAll('#barcodeForm input').forEach(item => { function onInputChange(event) { - updateBarcodeData(); - updateImage(); + let shouldUpdateImage = updateBarcodeData(); + + if (shouldUpdateImage) { + document.getElementById("barcodeImg").show(); + + updateImage(); + } else { + document.getElementById("barcodeImg").hide(); + } + } function updateBarcodeData() { + var nr = document.getElementById("qrNr").value; + var amount = document.getElementById("qrAmount").value; + + if (nr == "") + return false + + text = "https://products.mobilepay.dk/box/box?phone=" + nr + "&amount=" + amount; barcode = { - text: document.getElementById("barcodeText").value, + text: text, type: parseInt(document.getElementById("barcodeType").selectedOptions[0].value), width: parseInt(document.getElementById("barcodeSize").value), height: parseInt(document.getElementById("barcodeSize").value), rotate: 0 }; + return true; } function updateImage() { let barcodeImg = document.getElementById("barcodeImg"); var imgUrl = "image.png?" + toQueryString(barcode); - window.xhttp = new XMLHttpRequest(); - window.xhttp.onreadystatechange = function () { + let xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { if (this.readyState == 4) { if (this.status == 200) { - document.getElementById("error_message").hide(); - - barcodeImg.src = imgUrl; - barcodeImg.show(); + showBarcode(barcodeImg, imgUrl) } else { - document.getElementById("error_message").innerText = this.responseText; - document.getElementById("error_message").show(); - barcodeImg.hide(); - + showError(barcodeImg) } } }; - window.xhttp.onerror = function () { - }; + xhttp.open("GET", imgUrl, true); + xhttp.send(); +} - window.xhttp.open("GET", imgUrl, true); - window.xhttp.send(); +function showBarcode(el, imgUrl) { + document.getElementById("error_message").hide(); + + el.src = imgUrl; + el.show(); +} +function showError(el) { + document.getElementById("error_message").innerText = this.responseText; + document.getElementById("error_message").show(); + el.hide(); }