From aed4b62f07337bc1f7aab1b4af2bee07159f0752 Mon Sep 17 00:00:00 2001 From: flifloo Date: Fri, 6 Mar 2020 15:56:26 +0100 Subject: [PATCH] Plate can avoid sauce --- app/models.py | 1 + app/sockets.py | 3 ++- app/static/js/pc.js | 12 ++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models.py b/app/models.py index 0cb0b31..50e2266 100644 --- a/app/models.py +++ b/app/models.py @@ -65,6 +65,7 @@ class Plate(db.Model): price = db.Column(db.Integer, default=0) avoid_ingredient = db.Column(db.Boolean, default=False) + avoid_sauce = db.Column(db.Boolean, default=False) command = db.relationship("Command", backref="plate", lazy="dynamic") diff --git a/app/sockets.py b/app/sockets.py index 2cb43a6..f051cfa 100644 --- a/app/sockets.py +++ b/app/sockets.py @@ -197,7 +197,8 @@ def errcmd(json): def lsplate(): plates = [] for p in Plate.query.all(): - plates.append({"id": p.id, "name": p.name, "price": p.price, "avoid ingredient": p.avoid_ingredient}) + plates.append({"id": p.id, "name": p.name, "price": p.price, "avoid_ingredient": p.avoid_ingredient, + "avoid_sauce": p.avoid_sauce}) emit("list plate", {"list": plates}) diff --git a/app/static/js/pc.js b/app/static/js/pc.js index 91d341f..b780bae 100644 --- a/app/static/js/pc.js +++ b/app/static/js/pc.js @@ -54,7 +54,7 @@ function addplate(id, name) { let e = document.querySelector(`input[id=${id} ]`); e.addEventListener("click", () => { radiocheck(e, "plate",0); - document.querySelectorAll("input[name=ingredient],input[name=sauce]").forEach( el => { + document.querySelectorAll("input[name=ingredient]").forEach( el => { if (e.checked && !db["plate"][e.id]["avoid ingredient"]) el.disabled = false; else { @@ -62,6 +62,14 @@ function addplate(id, name) { el.checked = false } }); + document.querySelectorAll("input[name=sauce]").forEach( el => { + if (e.checked && !db["plate"][e.id]["avoid sauce"]) + el.disabled = false; + else { + el.disabled = true; + el.checked = false + } + }); }) } @@ -207,7 +215,7 @@ socket.on("list plate", data => { } for (let p of data.list) { addplate(p.id, p.name); - db["plate"][p.id] = {"name": p.name, "price": p.price, "avoid ingredient": p["avoid ingredient"]} + db["plate"][p.id] = {"name": p.name, "price": p.price, "avoid ingredient": p.avoid_ingredient, "avoid sauce": p.avoid_sauce} } });