mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
refactor: update method saveLocal for 'POST'
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -13,6 +13,7 @@ RRB&C - Mapa de Mesas
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block 'body' %}
|
{% block 'body' %}
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
#mapa {
|
#mapa {
|
||||||
|
|||||||
@@ -8,6 +8,4 @@ urlpatterns = [
|
|||||||
path('locationMesa/<int:mesaId>/<str:location>/', views.locationMesa, name='locationMesa'),
|
path('locationMesa/<int:mesaId>/<str:location>/', views.locationMesa, name='locationMesa'),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
from django.shortcuts import render,redirect, HttpResponse
|
from django.shortcuts import render
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
|
|
||||||
|
|
||||||
from mesas.models import Mesa
|
from mesas.models import Mesa
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
|
|
||||||
def mesas(request):
|
def mesas(request):
|
||||||
mesas = Mesa.objects.all()
|
mesas = Mesa.objects.all()
|
||||||
@@ -22,14 +20,8 @@ def mapMesas(request):
|
|||||||
return render(request, 'mesas_map.html', {'mesas': mesas, 'eixosXY': eixosXY})
|
return render(request, 'mesas_map.html', {'mesas': mesas, 'eixosXY': eixosXY})
|
||||||
|
|
||||||
def locationMesa(request, mesaId, location):
|
def locationMesa(request, mesaId, location):
|
||||||
|
print('inicioul')
|
||||||
mesa = Mesa.objects.get(id=mesaId)
|
mesa = Mesa.objects.get(id=mesaId)
|
||||||
mesa.location = location
|
mesa.location = location
|
||||||
mesa.save()
|
mesa.save()
|
||||||
return JsonResponse({'status': 'ok'})
|
return JsonResponse({'status': 'ok'})
|
||||||
# def onOffmesa(request):
|
|
||||||
# id = request.POST.get('id-mesa')
|
|
||||||
# mesa_id = int(id)
|
|
||||||
# mesa = Mesa.objects.get(id=mesa_id)
|
|
||||||
# mesa.active = not mesa.active
|
|
||||||
# mesa.save()
|
|
||||||
# return redirect('mesas')
|
|
||||||
@@ -47,15 +47,18 @@ const mesaId = mesaElement.id
|
|||||||
|
|
||||||
const targetId = targetElement.id;
|
const targetId = targetElement.id;
|
||||||
const url = `/mesas/locationMesa/${mesaId}/${targetId}/`;
|
const url = `/mesas/locationMesa/${mesaId}/${targetId}/`;
|
||||||
var resposta = fetch(url, {method: 'GET', headers: {'Content-Type': 'application/json'
|
var resposta = fetch(url, {method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json',
|
||||||
|
'X-CSRFToken': document.querySelector('[name="csrfmiddlewaretoken"]').value
|
||||||
},}).then(response => response.json())
|
},}).then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log(data);
|
|
||||||
if(data.status != 'ok'){
|
if(data.status != 'ok'){
|
||||||
alert('Erro ao salvar local:', error)
|
alert('Erro ao salvar local:', error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
alert('Erro ao salvar local:', error)
|
||||||
|
console.log(document.cookie)
|
||||||
console.error('Erro ao salvar local:', error);
|
console.error('Erro ao salvar local:', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user