diff --git a/gestaoRaul/balcao/__pycache__/htmx_views.cpython-310.pyc b/gestaoRaul/balcao/__pycache__/htmx_views.cpython-310.pyc index 622af60..e0d61e7 100644 Binary files a/gestaoRaul/balcao/__pycache__/htmx_views.cpython-310.pyc and b/gestaoRaul/balcao/__pycache__/htmx_views.cpython-310.pyc differ diff --git a/gestaoRaul/balcao/htmx_views.py b/gestaoRaul/balcao/htmx_views.py index 79c45b6..69568a7 100644 --- a/gestaoRaul/balcao/htmx_views.py +++ b/gestaoRaul/balcao/htmx_views.py @@ -30,7 +30,7 @@ def addProductBalcao(request, product_id, comanda_id, qtd): total += produto.product.price return render(request, "htmx_components/htmx_list_products_in_balcao.html",{'consumo': consumo, 'total': total}) - +@csrf_exempt def addProductBalcaoTeclado(request, product_id, comanda_id, qtd): qtd = int(request.COOKIES.get('qtd')) for i in range(qtd): diff --git a/gestaoRaul/balcao/templates/viewBalcao.html b/gestaoRaul/balcao/templates/viewBalcao.html index 4fd5fca..7e966b3 100644 --- a/gestaoRaul/balcao/templates/viewBalcao.html +++ b/gestaoRaul/balcao/templates/viewBalcao.html @@ -80,7 +80,14 @@ placeholder="Buscar Produto" > -
+
{% for product in products %} @@ -90,7 +97,7 @@
@@ -105,6 +112,7 @@
diff --git a/gestaoRaul/db.sqlite3 b/gestaoRaul/db.sqlite3 index b190cf5..0a5b572 100644 Binary files a/gestaoRaul/db.sqlite3 and b/gestaoRaul/db.sqlite3 differ diff --git a/gestaoRaul/templates/htmx_components/htmx_list_products_balcao.html b/gestaoRaul/templates/htmx_components/htmx_list_products_balcao.html index 303497a..0e7f4e6 100644 --- a/gestaoRaul/templates/htmx_components/htmx_list_products_balcao.html +++ b/gestaoRaul/templates/htmx_components/htmx_list_products_balcao.html @@ -8,7 +8,7 @@ name="productBox" id="productId-{{ product.id }}" style="background-color: #293552;" - + onclick="addProductClick({{product.id}} , {{comanda_id}})" > @@ -22,7 +22,7 @@ name="productBox" id="productId-{{ product.id }}" style="background-color: #293552;" - + onclick="addProductClick({{product.id}} , {{comanda_id}})" > {{product.name}}
R$ {{product.price}} diff --git a/gestaoRaul/templates/static/comandas/js/viewbalcao.js b/gestaoRaul/templates/static/comandas/js/viewbalcao.js index d38058d..18cf46c 100644 --- a/gestaoRaul/templates/static/comandas/js/viewbalcao.js +++ b/gestaoRaul/templates/static/comandas/js/viewbalcao.js @@ -104,7 +104,7 @@ document.onkeydown = teclado function teclado(event){ if (event.keyCode == 13){ addProductBalcao() - reloadPage() + // reloadPage() }else{ console.log(event.keyCode) } @@ -128,8 +128,15 @@ function addProductBalcao() { }, }) + .then(function(response) { + return response.text(); + }).then(function(text) { + var listProductsBalcaoElement = document.getElementById("list-products-balcao"); + listProductsBalcaoElement.innerHTML = text; + }) - reloadPage() + + // reloadPage() } @@ -168,16 +175,21 @@ function searchProduct() { } function addProductClick(productId, comandaId) { - var xhr = new XMLHttpRequest(); - xhr.open("GET", "{% url 'addProductBalcaoTeclado' product.id comanda.id 1 %}", true); - xhr.onreadystatechange = function() { - if (xhr.readyState === 4 && xhr.status === 200) { - var response = JSON.parse(xhr.responseText); - var listProductsBalcaoElement = document.getElementById("list-products-balcao"); - listProductsBalcaoElement.innerHTML = response.html; - } - }; - xhr.send(); + console.log(productId, comandaId) + var qtd = document.getElementById('qtd-product').value + fetch(`/balcao/addProductBalcaoTeclado${productId}/${comandaId}/${qtd}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json'} + }) + + .then(function(response) { + return response.text(); + }).then(function(text) { + var listProductsBalcaoElement = document.getElementById("list-products-balcao"); + listProductsBalcaoElement.innerHTML = text; + }) + }