From dd69942dd2da7332d27bc9a394fa47d487e2175d Mon Sep 17 00:00:00 2001 From: flifloo Date: Mon, 1 Jun 2020 01:19:19 +0200 Subject: [PATCH] Replace js popups by own popups --- public/javascripts/commands.js | 31 ++++++----- public/javascripts/kitchen.js | 10 ++-- public/javascripts/menu.js | 73 +++++++++++++------------- public/javascripts/popups.js | 95 ++++++++++++++++++++++++++++++++++ public/javascripts/service.js | 32 ++++++------ public/stylesheets/style.css | 42 +++++++-------- views/commands.pug | 15 +----- views/kitchen.pug | 2 +- views/menu.pug | 2 +- views/service.pug | 2 +- 10 files changed, 200 insertions(+), 104 deletions(-) create mode 100644 public/javascripts/popups.js diff --git a/public/javascripts/commands.js b/public/javascripts/commands.js index f0e4d99..e2495b1 100644 --- a/public/javascripts/commands.js +++ b/public/javascripts/commands.js @@ -1,3 +1,5 @@ +import {alert, prompt, confirm} from "./popups.js"; + const socket = io(); const dish = document.querySelector("#dish ul"); const ingredient = document.querySelector("#ingredient ul"); @@ -202,20 +204,20 @@ function price() { socket.emit("price", current); } -function addUser() { +async function addUser() { let firstName, lastName; do { - firstName = prompt("First name"); + firstName = await prompt("First name"); } while (firstName === ""); if (firstName) { do { - lastName = prompt("Last name"); + lastName = await prompt("Last name"); } while (lastName === ""); if (lastName) socket.emit("add user", {username: current.client, firstName: firstName, lastName: lastName}); } if (!firstName|| !lastName) { - alert("User creation aborted"); + await alert("User creation aborted"); } } @@ -434,21 +436,21 @@ socket.on("price", data => { document.querySelector("#resume h2").innerHTML = data+"€"; }) -socket.on("fail add user", () => { - alert("User creation fail !"); - addUser(); +socket.on("fail add user", async () => { + await alert("User creation fail !"); + await addUser(); }); -socket.on("internal error", () => { - alert("An error occurred !"); +socket.on("internal error", async () => { + await alert("An error occurred !"); }) -document.querySelector(".validation").addEventListener("click", ev => { +document.querySelector(".validation").addEventListener("click", async ev => { ev.stopPropagation(); if (!current.dish && !current.ingredient.length && !current.sauce.length && !current.drink && !current.dessert) - alert("Empty command !"); + await alert("Empty command !"); else if (user.style.color === "red") - addUser(); + await addUser(); else addCommand(); }); @@ -461,3 +463,8 @@ document.getElementById("user").addEventListener("keyup", ev => { socket.emit("list user", input.value); current.client = input.value; }); + +document.getElementById("logout").addEventListener("click", async () => { + if (await confirm("Do you really want to log out ?")) + window.location.href = "logout"; +}); diff --git a/public/javascripts/kitchen.js b/public/javascripts/kitchen.js index 31ec5eb..4c55da4 100644 --- a/public/javascripts/kitchen.js +++ b/public/javascripts/kitchen.js @@ -1,3 +1,5 @@ +import {alert} from "./popups.js"; + const socket = io(); const WIP = document.getElementById("WIP"); const done = document.getElementById("done"); @@ -81,9 +83,9 @@ socket.on("list command", data => { waiter(); }); -socket.on("list service", data => { +socket.on("list service", async data => { if (!data || Object.keys(data).length === 0) { - alert("No service set !"); + await alert("No service set !"); } else socket.emit("list command"); }); @@ -122,8 +124,8 @@ socket.on("error command", data => { waiter(); }); -socket.on("internal error", () => { - alert("An error occurred !"); +socket.on("internal error", async () => { + await alert("An error occurred !"); }) document.addEventListener("keyup", ev => { diff --git a/public/javascripts/menu.js b/public/javascripts/menu.js index f8eb26f..839929f 100644 --- a/public/javascripts/menu.js +++ b/public/javascripts/menu.js @@ -1,3 +1,4 @@ +import {alert, confirm} from "./popups.js"; const socket = io(); const dish = document.querySelector("#dish ul"); const ingredient = document.querySelector("#ingredient ul"); @@ -13,34 +14,36 @@ if (window.location.href.endsWith("#popup")) function popup(ob, el) { - document.querySelector("body").insertAdjacentHTML("afterbegin", `