Add user creation popup
This commit is contained in:
parent
24618dc111
commit
6d0f000787
3 changed files with 64 additions and 29 deletions
|
@ -1,4 +1,4 @@
|
||||||
import {alert, prompt, confirm} from "./popups.js";
|
import {alert, confirm, createUserPopup} from "./popups.js";
|
||||||
|
|
||||||
const socket = io();
|
const socket = io();
|
||||||
const list = document.querySelector(".list");
|
const list = document.querySelector(".list");
|
||||||
|
@ -157,18 +157,12 @@ function price() {
|
||||||
async function addUser() {
|
async function addUser() {
|
||||||
let firstName, lastName;
|
let firstName, lastName;
|
||||||
do {
|
do {
|
||||||
firstName = await prompt("First name");
|
[firstName, lastName] = await createUserPopup(current.client);
|
||||||
} while (firstName === "");
|
} while (firstName === "" || lastName === "");
|
||||||
if (firstName) {
|
if (firstName && lastName)
|
||||||
do {
|
|
||||||
lastName = await prompt("Last name");
|
|
||||||
} while (lastName === "");
|
|
||||||
if (lastName)
|
|
||||||
socket.emit("add user", {username: current.client, firstName: firstName, lastName: lastName});
|
socket.emit("add user", {username: current.client, firstName: firstName, lastName: lastName});
|
||||||
}
|
else
|
||||||
if (!firstName|| !lastName) {
|
|
||||||
await alert("User creation aborted");
|
await alert("User creation aborted");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCommand() {
|
function addCommand() {
|
||||||
|
@ -304,7 +298,7 @@ document.querySelector(".validation").addEventListener("click", async ev => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
if (!current.dish && !current.ingredient.length && !current.sauce.length && !current.drink && !current.dessert)
|
if (!current.dish && !current.ingredient.length && !current.sauce.length && !current.drink && !current.dessert)
|
||||||
await alert("Empty command !");
|
await alert("Empty command !");
|
||||||
else if (user.style.color === "red")
|
else if (current.client && user.style.color === "red")
|
||||||
await addUser();
|
await addUser();
|
||||||
else
|
else
|
||||||
addCommand();
|
addCommand();
|
||||||
|
|
|
@ -93,3 +93,50 @@ export function prompt(message, inputArgs) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createUserPopup(username) {
|
||||||
|
return new Promise(next => {
|
||||||
|
if (document.getElementById("popup-container"))
|
||||||
|
throw new Error("Popup already exist !")
|
||||||
|
document.querySelector("body").insertAdjacentHTML("afterend", `<div id="popup-container">
|
||||||
|
<div id="popup">
|
||||||
|
<h1>Creation of user ${username}</h1>
|
||||||
|
<div class="wrap-input2">
|
||||||
|
<input class="input2" id="firstName" type="text" placeholder="First Name">
|
||||||
|
</div>
|
||||||
|
<div class="wrap-input2">
|
||||||
|
<input class="input2" id="lastName" type="text" placeholder="Last Name">
|
||||||
|
</div>
|
||||||
|
<div id="popup-validation">
|
||||||
|
<div class="container-contact2-form-btn">
|
||||||
|
<div class="wrap-contact2-form-btn">
|
||||||
|
<div class="contact2-form-bgbtn"></div>
|
||||||
|
<a><button id="popup-cancel" class="contact2-form-btn">Cancel</button></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="container-contact2-form-btn">
|
||||||
|
<div class="wrap-contact2-form-btn">
|
||||||
|
<div class="contact2-form-bgbtn"></div>
|
||||||
|
<a><button id="popup-ok" class="contact2-form-btn">Ok</button></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`);
|
||||||
|
let ok = document.getElementById("popup-ok");
|
||||||
|
document.getElementById("lastName").addEventListener("keyup", ev => {
|
||||||
|
if (ev.key === "Enter")
|
||||||
|
ok.click()
|
||||||
|
});
|
||||||
|
ok.addEventListener("click", () => {
|
||||||
|
let firstName = document.getElementById("firstName").value;
|
||||||
|
let lastName = document.getElementById("lastName").value;
|
||||||
|
document.getElementById("popup-container").remove();
|
||||||
|
next([firstName, lastName]);
|
||||||
|
});
|
||||||
|
document.getElementById("popup-cancel").addEventListener("click", () => {
|
||||||
|
document.getElementById("popup-container").remove();
|
||||||
|
next(null, null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {alert, prompt} from "./popups.js";
|
import {alert, createUserPopup} from "./popups.js";
|
||||||
|
|
||||||
let socket = io();
|
let socket = io();
|
||||||
let users = {};
|
let users = {};
|
||||||
|
@ -7,16 +7,11 @@ let usersAdd = [];
|
||||||
async function addUser(username) {
|
async function addUser(username) {
|
||||||
let firstName, lastName;
|
let firstName, lastName;
|
||||||
do {
|
do {
|
||||||
firstName = await prompt("First name for " + username);
|
[firstName, lastName] = await createUserPopup(username);
|
||||||
} while (firstName === "");
|
} while (firstName === "" || lastName === "");
|
||||||
if (firstName) {
|
if (firstName && lastName)
|
||||||
do {
|
|
||||||
lastName = await prompt("Last name for " + username);
|
|
||||||
} while (lastName === "");
|
|
||||||
if (lastName)
|
|
||||||
socket.emit("add user", {username: username, firstName: firstName, lastName: lastName});
|
socket.emit("add user", {username: username, firstName: firstName, lastName: lastName});
|
||||||
}
|
else
|
||||||
if (!firstName|| !lastName)
|
|
||||||
await alert("User creation aborted for " + username);
|
await alert("User creation aborted for " + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +20,7 @@ async function next() {
|
||||||
await addUser(usersAdd.pop());
|
await addUser(usersAdd.pop());
|
||||||
else
|
else
|
||||||
socket.emit("set service", users);
|
socket.emit("set service", users);
|
||||||
|
console.log(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
function hinter(ev) {
|
function hinter(ev) {
|
||||||
|
@ -40,9 +36,8 @@ socket.on("connected", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("list service", data => {
|
socket.on("list service", data => {
|
||||||
for (let s in data) {
|
for (let s in data)
|
||||||
document.getElementById(s).value = data[s]
|
document.getElementById(s).value = data[s];
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("list user", data => {
|
socket.on("list user", data => {
|
||||||
|
@ -66,7 +61,6 @@ socket.on("add user", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("set service", () => {
|
socket.on("set service", () => {
|
||||||
console.log("close !")
|
|
||||||
window.close();
|
window.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -86,7 +80,7 @@ document.querySelectorAll("input[type='text']").forEach(e => {
|
||||||
|
|
||||||
document.querySelector("button").addEventListener("click", async () => {
|
document.querySelector("button").addEventListener("click", async () => {
|
||||||
document.querySelectorAll("input[type='text']").forEach(e=> {
|
document.querySelectorAll("input[type='text']").forEach(e=> {
|
||||||
if (e.style.color)
|
if (e.value && e.style.color)
|
||||||
usersAdd.push(e.value);
|
usersAdd.push(e.value);
|
||||||
users[e.id] = e.value;
|
users[e.id] = e.value;
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue