mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
feat: edit product
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -17,12 +17,17 @@ Produtos
|
||||
{% block 'body' %}
|
||||
|
||||
|
||||
<body>
|
||||
<body><br>
|
||||
<div class="grid-container">
|
||||
<div >
|
||||
<input type="text" id="search-product" name="search-product" placeholder="Buscar Produto" hx-get="{% url 'searchProduct' %}" hx-trigger="keyup" hx-target="#product-list"><br>
|
||||
<div class="grid-top">
|
||||
<button style="
|
||||
width: 30%;
|
||||
margin: 5px 10px 20px 10px;
|
||||
|
||||
"
|
||||
onclick="openModal()" id="openModal">Adicionar Novo Produto</button>
|
||||
<input type="text" id="search-product" name="search-product" placeholder="Buscar Produto" hx-get="{% url 'searchProduct' %}" hx-trigger="keyup" hx-target="#product-list">
|
||||
</div>
|
||||
<button onclick="openModal()" id="openModal">Adicionar Novo Produto</button>
|
||||
|
||||
<table id="product-list">
|
||||
<tr>
|
||||
@@ -77,6 +82,7 @@ Produtos
|
||||
<article >
|
||||
|
||||
<form action="{% url 'create_product' %}" id="productForm" method="post" >
|
||||
|
||||
{% csrf_token %}
|
||||
<h2>Cadastro de Produto</h2>
|
||||
<input type="text" id="productId" name="productId" hidden ><br>
|
||||
@@ -92,7 +98,8 @@ Produtos
|
||||
</select>
|
||||
<textarea id="productDescription" name="description" rows="4" placeholder="Descrição"></textarea><br>
|
||||
<footer class="grid-buttons">
|
||||
<button type="submit">Salvar</button>
|
||||
<button id="save" type="submit">Salvar</button>
|
||||
<button onclick="closeModal()" type="button" id="edit" hx-post="{% url 'editProduct' 1 %}" hx-trigger="click" hx-target="#product-list" >Alterar</button>
|
||||
<button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
@@ -35,8 +35,9 @@ def onOffProduct(request):
|
||||
return redirect('products')
|
||||
|
||||
def editProduct(request, productId):
|
||||
# id = request.POST.get('productId')
|
||||
product_id = productId
|
||||
print('wwwwwwwwwwwwwwwwwwwwwwww ', request.POST.get('productId'),' ooooooooooo')
|
||||
product_id = int(request.POST.get('productId'))
|
||||
# product_id = productId
|
||||
product = Product.objects.get(id=product_id)
|
||||
product.name = request.POST.get('name')
|
||||
product.description = request.POST.get('description')
|
||||
@@ -44,4 +45,11 @@ def editProduct(request, productId):
|
||||
product.quantity = request.POST.get('qtd')
|
||||
product.category = Categories.objects.get(id = int(request.POST.get('select-categorie')))
|
||||
product.save()
|
||||
return redirect('products')
|
||||
print(request.GET.get("search-product"))
|
||||
product = request.GET.get("search-product")
|
||||
if product == None:
|
||||
product = ''
|
||||
products = Product.objects.filter(name__icontains=product)
|
||||
return render(request, "htmx_components/products/htmx_search_products.html", {"products": products})
|
||||
# return render(request, 'products.html')
|
||||
# return redirect('/products')
|
||||
@@ -76,6 +76,11 @@ input, textarea {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.grid-top {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.card {
|
||||
width: 100%;
|
||||
height: 120px;
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
function openModal() {
|
||||
document.getElementById('Modal-create-product').style.display = 'block';
|
||||
var productId = document.getElementById('productId');
|
||||
var productName = document.getElementById('productName');
|
||||
var productPrice = document.getElementById('productPrice');
|
||||
var productDescription = document.getElementById('productDescription');
|
||||
var productqtd = document.getElementById('productqtd');
|
||||
var categorie = document.getElementById('select-categorie');
|
||||
var buttonEdit = document.getElementById('edit');
|
||||
var buttonSave = document.getElementById('save');
|
||||
buttonEdit.style.display = 'none';
|
||||
buttonSave.style.display = 'block';
|
||||
|
||||
productId.value = '';
|
||||
productName.value = '';
|
||||
productPrice.value = '';
|
||||
productDescription.value ='';
|
||||
productqtd.value = '';
|
||||
categorie.value = 1;
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
@@ -8,14 +25,19 @@ function closeModal() {
|
||||
|
||||
function editProduct(id) {
|
||||
|
||||
openModal();
|
||||
var buttonSave = document.getElementById('save');
|
||||
var buttonEdit = document.getElementById('edit');
|
||||
buttonSave.style.display = 'none';
|
||||
buttonEdit.style.display = 'block';
|
||||
var productId = document.getElementById('productId');
|
||||
var productName = document.getElementById('productName');
|
||||
var productPrice = document.getElementById('productPrice');
|
||||
var productDescription = document.getElementById('productDescription');
|
||||
var productqtd = document.getElementById('productqtd');
|
||||
var categorie = document.getElementById('select-categorie');
|
||||
openModal();
|
||||
// productId.innerHTML = id;
|
||||
|
||||
productId.value = id;
|
||||
productName.value = document.getElementById('name-'+id).innerHTML;
|
||||
var preco = document.getElementById('price-'+id).innerHTML;
|
||||
preco = preco.replace('R$ ', '');
|
||||
@@ -23,7 +45,7 @@ function editProduct(id) {
|
||||
productPrice.value = preco;
|
||||
productDescription.value = document.getElementById('description-'+id).value;
|
||||
productqtd.value = document.getElementById('quantity-'+id).innerHTML;
|
||||
console.log(document.getElementById('h-category-'+id).value)
|
||||
// console.log(document.getElementById('h-category-'+id).value)
|
||||
categorie.value = document.getElementById('h-category-'+id).value;
|
||||
|
||||
// const url = `/products/editProduct/${id}/`;
|
||||
|
||||
Reference in New Issue
Block a user