From 6b3136dece1e0953ec76252d940186fb531f758e Mon Sep 17 00:00:00 2001 From: nanoy Date: Sun, 23 Dec 2018 12:06:16 +0100 Subject: [PATCH] =?UTF-8?q?Prise=20en=20compte=20des=20pr=C3=A9f=C3=A9renc?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preferences/urls.py | 1 + preferences/views.py | 14 ++++++++++++++ staticfiles/manage.js | 31 ++++++++++++++++++------------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/preferences/urls.py b/preferences/urls.py index 7981698..dd7d3b8 100644 --- a/preferences/urls.py +++ b/preferences/urls.py @@ -14,4 +14,5 @@ urlpatterns = [ path('editPaymentMethod/', views.editPaymentMethod, name="editPaymentMethod"), path('deletePaymentMethod/', views.deletePaymentMethod, name="deletePaymentMethod"), path('inactive', views.inactive, name="inactive"), + path('getConfig', views.get_config, name="getConfig"), ] diff --git a/preferences/views.py b/preferences/views.py index 08c8976..3f9ec6d 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -1,7 +1,11 @@ +import json + from django.shortcuts import render, redirect, get_object_or_404 from django.contrib import messages from django.urls import reverse from django.contrib.auth.decorators import login_required, permission_required +from django.http import HttpResponse +from django.forms.models import model_to_dict from coopeV3.acl import active_required @@ -238,4 +242,14 @@ def inactive(request): """ gp, _ = GeneralPreferences.objects.get_or_create(pk=1) return render(request, 'preferences/inactive.html', {"message": gp.active_message}) + +########## Config ########## + +def get_config(request): + """ + Load the config and return it in a json format + """ + gp,_ = GeneralPreferences.objects.get_or_create(pk=1) + data = json.dumps(model_to_dict(gp)) + return HttpResponse(data, content_type='application/json') \ No newline at end of file diff --git a/staticfiles/manage.js b/staticfiles/manage.js index 7af6bc6..ad2691b 100644 --- a/staticfiles/manage.js +++ b/staticfiles/manage.js @@ -10,7 +10,10 @@ nbPintes = 0; use_pinte_monitoring = false; function get_config(){ - use_pinte_monitoring = true; + res = $.get("../preferences/getConfig", function(data){ + console.log(data.use_pinte_monitoring) + use_pinte_monitoring = data.use_pinte_monitoring; + }); } function get_product(barcode){ @@ -131,19 +134,21 @@ $(document).ready(function(){ }); }); $(".pay_button").click(function(){ - message = "Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?" - while(nbPintes > 0){ - id_pinte = window.prompt(message,""); - if(id_pinte == null){ - return; - }else{ - id_pinte = parseInt(id_pinte); - if(!Number.isInteger(id_pinte) || id_pinte < 0){ - message = "Numéro incorrect. Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?"; + if(use_pinte_monitoring){ + message = "Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?" + while(nbPintes > 0){ + id_pinte = window.prompt(message,""); + if(id_pinte == null){ + return; }else{ - listPintes.push(id_pinte) - nbPintes -= 1; - message = "Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?" + id_pinte = parseInt(id_pinte); + if(!Number.isInteger(id_pinte) || id_pinte < 0){ + message = "Numéro incorrect. Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?"; + }else{ + listPintes.push(id_pinte) + nbPintes -= 1; + message = "Il reste " + nbPintes.toString() + " pintes à renseigner. Numéro de la pinte ?" + } } } }