estilizando modal produtos

This commit is contained in:
2024-12-11 23:01:11 -03:00
parent e5ef3898d0
commit ae5d47fa7c
8 changed files with 102 additions and 71 deletions

View File

@@ -4,8 +4,7 @@
{% block 'head' %} {% block 'head' %}
<link rel="stylesheet" href="{% static 'products/css/products.css' %}"> <link rel="stylesheet" href="{% static 'products/css/products.css' %}">
<script src="{% static 'products/js/products.js' %}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
{% endblock %} {% endblock %}
@@ -21,9 +20,8 @@ Produtos
<body> <body>
<div class="grid-container"> <div class="grid-container">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal"> <div><input type="text"></div>
Abrir Modal <button class="button" id="openModal">Adicionar Novo Produto</button>
</button>
{% for product in products %} {% for product in products %}
@@ -37,31 +35,23 @@ Produtos
</div> </div>
</body> </body>
{% comment %} <dialog open>
<h2>Titulo modal</h2>
<p>texto qualquer</p>
</dialog> {% endcomment %}
<div class="modal" id="myModal">
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <form id="productForm" method="post" action="{% url 'create_product' %}">
<h5 class="modal-title" id="exampleModalLabel">Título do Modal</h5> <h2>Cadastro de Produto</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <input type="text" id="productName" name="name" required placeholder="Nome"><br>
</div> <input type="number" step="0.01" id="productPrice" name="price" required placeholder="Preço"><br>
<div class="modal-body"> <input type="number" step="1" id="productqtd" name="qtd" required placeholder="Quantidade"><br>
Conteúdo do seu modal. <textarea id="productDescription" name="description" rows="4" required placeholder="Descrição"></textarea><br>
</div> <button type="submit">Salvar</button>
<div class="modal-footer"> <button type="button" onclick="closeModal()" style="background-color:red;">Fechar</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fechar</button> </form>
<button type="button" class="btn btn-primary">Salvar mudanças</button>
</div>
</div>
</div>
</div> </div>
</div>
<script src="{% static 'products/js/products.js' %}"></script>
{% endblock %} {% endblock %}

View File

@@ -4,6 +4,7 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', views.products, name='products'), path('', views.products, name='products'),
path('create_product', views.createProduct, name='create_product'),

View File

@@ -1,8 +1,22 @@
from django.shortcuts import render from django.shortcuts import render, redirect
from categories.models import Categories
from products.models import Product from products.models import Product
def products(request): def products(request):
protucts = Product.objects.all() protucts = Product.objects.all()
return render(request, 'products.html', {'products': protucts}) categories = Categories.objects.all()
return render(request, 'products.html', {'products': protucts, 'categories': categories})
def createProduct(request):
print(request.POST)
name = request.POST.get('name')
description = request.POST.get('description')
price = request.POST.get('price')
category = request.POST.get('category')
product = Product(name=name, description=description, price=price, category=category)
product.save()
return redirect('/products')
# return render(request, 'products.html')

View File

@@ -7,9 +7,11 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="{% static 'base.css' %}"> <link rel="stylesheet" href="{% static 'base.css' %}">
{% block 'head' %}{% endblock %} {% block 'head' %}
{% endblock %}
<title> {% block 'title' %}{% endblock %} </title> <title> {% block 'title' %}{% endblock %} </title>
</head> </head>
<div> <div>

View File

@@ -1,52 +1,71 @@
/* style.css */
button {
background-color: #007BFF;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.modal { .modal {
display: none; /* Oculta o modal por padrão */ display: none;
position: fixed; /* Posiciona o modal fixo na tela */ position: fixed;
z-index: 1; /* Garante que o modal fique acima de outros elementos */ padding: 20px;
left: 0; top: 50%;
top: 0; left: 50%;
width: 100%; width: 100%;
height: 100%; height: 100%;
overflow: auto; /* Permite rolagem se o conteúdo for muito grande */ overflow: auto;
background-color: rgba(0,0,0,0.4); /* Fundo escurecido */ background-color: rgba(0, 0, 0, 0.4);
transform: translate(-50%, -50%);
} }
.modal-content { .modal-content {
background-color: #fefefe; background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */ margin: 15% auto;
padding: 20px; padding: 20px;
border: 1px solid #888; border: 1px solid #888;
width: 80%; border-radius: 10px;
width: 90%;
max-width: 500px;
} }
.close {
color: #aaa; form {
float: right; display: flex;
font-size: 28px; flex-direction: column;
font-weight: bold; gap: 10px;
} }
.close:hover, input, textarea {
.close:focus { width: 95%;
color: black; max-width: 95%;
text-decoration: none; padding: 8px;
cursor: pointer; margin-top: 5px;
border-radius: 5px;
border: 1px solid #ccc;
} }
.grid-container { .grid-container {
display: grid; display: grid;
grid-template-columns: repeat(2, 1fr); grid-template-columns: repeat(2, 1fr);
gap: 20px; gap: 20px;
max-width: 1100px; /* Define a largura máxima do grid */ max-width: 800px; /* Define a largura máxima do grid */
margin: 0 auto; /* Centraliza o grid na página */ margin: 0 auto; /* Centraliza o grid na página */
} }
.card { .card {
width: 100%; width: 100%;
height: 80px; height: 120px;
background-color: #f2f2f2; background-color: #f2f2f2;
border-radius: 15px; border-radius: 15px;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2); box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.2);
@@ -62,16 +81,3 @@
transform: scale(1.05); transform: scale(1.05);
box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.3); box-shadow: 10px 10px 20px rgba(0, 0, 0, 0.3);
} }
dialog::backdrop {
background-color: rgb(0 0 0 / .5);
}
dialog {
border: none;
border-radius: .5rem;
box-shadow: 0 0 1em rgb(0 0 0 / .3);
width: 80%;
}

View File

@@ -1,2 +1,20 @@
function openModal() {
document.getElementById('myModal').style.display = 'block';
}
function closeModal() {
document.getElementById('myModal').style.display = 'none';
}
document.getElementById('openModal').addEventListener('click', openModal);
document.getElementById('productForm').addEventListener('submit', function(event) {
event.preventDefault();
// const productName = document.getElementById('productName').value;
// const productPrice = document.getElementById('productPrice').value;
// const productDescription = document.getElementById('productDescription').value;
// closeModal();
});