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