mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: button on/off products
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -19,16 +19,49 @@ Produtos
|
||||
|
||||
<body>
|
||||
<div class="grid-container">
|
||||
<div class="pico"><input class="pico" type="text"></div>
|
||||
<button class="pico" id="openModal">Adicionar Novo Produto</button>
|
||||
<div ><input type="text"></div>
|
||||
<button id="openModal">Adicionar Novo Produto</button>
|
||||
|
||||
<table id="list-products">
|
||||
<tr>
|
||||
<th style="text-align: left;">Produto</th>
|
||||
<th style="text-align: left;">Preço</th>
|
||||
<th style="text-align: left;">Quantidade</th>
|
||||
<th style="text-align: left;">Categoria</th>
|
||||
<th style="text-align: left;">Ações</th>
|
||||
</tr>
|
||||
|
||||
{% for product in products %}
|
||||
|
||||
<tr>
|
||||
<td>{{product.name}}</td>
|
||||
<td>R$ {{product.price}}</td>
|
||||
<td>{{product.quantity}}</td>
|
||||
<td>{{product.category.name}}</td>
|
||||
<td>
|
||||
<div class="grid-buttons">
|
||||
<button>📝 Editar</button>
|
||||
|
||||
<form action="{% url 'onOffproduct' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="id-product" value="{{ product.id }}">
|
||||
|
||||
{% if product.active == True %}
|
||||
<button style="background-color: red;">🚫 Desativar</button>
|
||||
{% else %}
|
||||
<button style="background-color: green;" >✅ Ativar</button>
|
||||
|
||||
{% endif %}
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<div class="card">
|
||||
{{product.name}}
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -36,8 +69,11 @@ Produtos
|
||||
|
||||
|
||||
|
||||
<div class="modal" id="Modal-create-product">
|
||||
<div class="modal-content">
|
||||
|
||||
|
||||
<dialog id='Modal-create-product' >
|
||||
<article>
|
||||
|
||||
<form action="{% url 'create_product' %}" id="productForm" method="post" >
|
||||
{% csrf_token %}
|
||||
<h2>Cadastro de Produto</h2>
|
||||
@@ -55,8 +91,11 @@ Produtos
|
||||
<button type="submit">Salvar</button>
|
||||
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</article>
|
||||
</dialog>
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="{% static 'products/js/products.js' %}"></script>
|
||||
|
||||
@@ -5,5 +5,6 @@ from . import views
|
||||
urlpatterns = [
|
||||
path('', views.products, name='products'),
|
||||
path('create_product', views.createProduct, name='create_product'),
|
||||
path('onOffproduct', views.onOffProduct, name='onOffproduct'),
|
||||
|
||||
]
|
||||
|
||||
@@ -18,4 +18,13 @@ def createProduct(request):
|
||||
product = Product(name=name, description=description, price=price, category=category)
|
||||
product.save()
|
||||
return redirect('/products')
|
||||
# return render(request, 'products.html')
|
||||
# return render(request, 'products.html')
|
||||
|
||||
|
||||
def onOffProduct(request):
|
||||
id = request.POST.get('id-product')
|
||||
product_id = int(id)
|
||||
product = Product.objects.get(id=product_id)
|
||||
product.active = not product.active
|
||||
product.save()
|
||||
return redirect('products')
|
||||
Reference in New Issue
Block a user