-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.html
651 lines (574 loc) · 14.4 KB
/
menu.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
<!DOCTYPE html>
<head>
<meta content="width=device-width,initial-scale=1" />
<style>
@import url("https://fonts.googleapis.com/icon?family=Material+Icons");
@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap");
* {
font-family: "Roboto";
}
body {
margin: 0;
}
@media (pointer: coarse) {
body {
zoom: 150%;
}
}
button {
border: none;
}
.overlay {
top: 0;
left: 0;
z-index: 10;
width: 100%;
height: 100%;
display: flex;
position: fixed;
align-items: center;
justify-content: center;
transition: opacity 666ms;
}
body .overlay.invisible {
pointer-events: none;
opacity: 0;
}
#code-overlay {
background-image: radial-gradient(#eee, #fff 127%);
}
#code-overlay > div {
width: 300pt;
background-color: white;
box-shadow: 0 0 7pt #00000040;
border-radius: 3pt;
padding: 10pt;
font-size: 16pt;
}
.stp-button {
border: none;
color: white;
padding: 4pt 10pt;
text-align: center;
font-size: 13pt;
font-weight: 700;
box-shadow: 0 0 5pt #00000040;
border-radius: 3pt;
background-color: #f00d1e;
}
.stp-button:hover {
background-color: #cc1127;
}
#code-button {
box-shadow: 0 0 4pt #00000040;
margin-top: 10pt;
float: right;
}
#code-field {
width: 100%;
transition: border-color 250ms;
border-top-style: hidden;
border-right-style: hidden;
border-left-style: hidden;
border-bottom-style: solid;
border-bottom-width: 1.5pt;
border-color: gainsboro;
background-color: white;
text-transform: uppercase;
letter-spacing: 4pt;
text-align: center;
font-size: 60pt;
height: 60pt;
}
#code-field:placeholder-shown {
font-size: 16pt;
text-transform: none;
font-weight: normal;
color: transparent;
letter-spacing: 0;
}
#code-field:focus {
border-color: #f00d1e;
outline: none;
}
#code-field:invalid {
color: #f00d1e;
transition: 250ms color;
}
#code-label {
transition: color 250ms;
font-size: 12pt;
margin-top: 3pt;
margin-left: 2pt;
color: #f00d1e;
float: left;
}
#plte-overlay {
background-color: #00000080;
}
#plte-overlay > div {
width: 300pt;
background-color: white;
box-shadow: 0 0 7pt #00000040;
border-radius: 3pt;
font-size: 16pt;
}
#plte-lst {
width: 100%;
border-bottom: solid 1pt lightgrey;
padding: 10pt 0;
}
.plte-item {
width: 100%;
text-align: left;
background-color: white;
padding: 6pt 13pt 7pt;
display: grid;
grid-template-columns: auto 20pt;
}
.plte-item:hover {
background-color: #eee;
}
.plte-name {
font-size: 13pt;
}
.plte-info {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
font-size: 10pt;
display: block;
color: grey;
width: 100%;
grid-row: 2;
}
.plte-rem {
font-family: "Material Icons";
float: right;
margin: auto;
display: block;
grid-column: 2;
grid-row: span 2;
width: 25pt;
height: 25pt;
font-size: 13pt;
border-radius: 50%;
box-sizing: border-box;
background-color: transparent;
padding: 0 6.5pt;
color: grey;
}
.plte-rem:hover {
background-color: #ddd;
}
#snd-button {
float: right;
margin: 7pt 10pt;
}
.plte-button {
float: right;
margin: 8pt -6pt 0 0;
border: none;
color: black;
padding: 4pt 10pt;
text-align: center;
font-size: 11pt;
border-radius: 3pt;
background-color: transparent;
}
.plte-button:hover {
color: #f00d1e;
}
header {
top: 0;
position: fixed;
height: 40pt;
width: 100%;
z-index: 2;
padding: 10.5pt;
box-sizing: border-box;
color: white;
font-weight: 500;
font-size: 16pt;
background-color: #f00d1e;
box-shadow: 0 0 5pt #00000080;
display: flex;
}
#back-button {
font-family: "Material Icons";
background: none;
color: white;
font-size: 16pt;
}
#tble-label {
margin-left: 2pt;
}
#menu-grid {
width: min(1000pt, 100%);
justify-content: center;
margin: 45pt auto;
padding: 4pt;
display: flex;
flex-wrap: wrap;
box-sizing: border-box;
}
.menu-itm {
flex: 1;
min-width: 300pt;
height: 300pt;
padding: 4pt;
display: block;
}
.menu-ttl {
top: 0;
position: relative;
font-weight: 400;
display: block;
font-size: 16pt;
height: 20pt;
padding: 10pt 10pt 20pt;
background-image: linear-gradient(black, transparent);
color: white;
}
.menu-img {
width: 100%;
height: 100%;
object-fit: cover;
margin-top: -50pt;
}
.menu-inc {
float: right;
box-shadow: 0 0 5pt #ffffff80;
background-color: white;
text-align: center;
border-radius: 5pt;
box-sizing: border-box;
height: 20pt;
vertical-align: middle;
display: table-cell;
}
.menu-cnt {
color: black;
font-size: 13pt;
display: inline-block;
font-weight: 500;
}
.menu-unt {
color: gray;
font-size: 10pt;
display: inline-block;
font-weight: 400;
margin: 0 -2pt 0 2pt;
font-variant: petite-caps;
font-style: italic;
}
.menu-add,
.menu-rem {
color: grey;
font-family: "Material Icons";
outline: none;
border: none;
height: 100%;
width: 15pt;
padding: 0;
}
.menu-add {
border-left: solid 1pt darkgrey;
border-radius: 0 5pt 5pt 0;
padding-right: 2pt;
margin-left: 5pt;
float: right;
}
.menu-rem {
border-right: solid 1pt darkgrey;
border-radius: 5pt 0 0 5pt;
padding-left: 2pt;
margin-right: 5pt;
float: left;
}
.menu-add:focus {
outline: none;
}
footer {
grid-template-columns: auto 100pt;
box-shadow: 0 0 7pt #00000040;
background-color: white;
position: fixed;
bottom: 0;
width: 100%;
height: 40pt;
display: grid;
}
#chip-list {
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
padding: 0 10pt 0 10pt;
}
#chip-list::-webkit-scrollbar {
height: 2pt;
}
.chip {
padding: 3.4pt 10pt 0;
background-color: lightgrey;
width: fit-content;
border-radius: 22pt;
height: 22pt;
box-sizing: border-box;
display: inline-block;
margin: 9pt 5pt;
}
.chip > button {
outline: none;
border: none;
font-family: "Material Icons";
background: none;
display: block;
float: right;
font-size: 14pt;
color: grey;
margin: -0.5pt -10pt 0 2pt;
}
#nxt-button {
margin: auto;
}
#nxt-button:disabled {
box-shadow: none;
background-color: lightgrey;
}
</style>
</head>
<body>
<div id="code-overlay" class="overlay">
<div>
<input
id="code-field"
type="tel"
maxlength="4"
pattern="[0-9]+"
spellcheck="false"
placeholder="Please enter your order code."
/>
<div id="code-label" hidden>Invalid order code</div>
<button id="code-button" class="stp-button">NEXT</button>
</div>
</div>
<div id="plte-overlay" class="overlay invisible">
<div>
<div id="plte-lst"></div>
<button id="snd-button" class="stp-button">SEND</button>
<button id="add-button" class="plte-button">ADD</button>
<button id="clr-button" class="plte-button">CLEAR</button>
</div>
</div>
<header><button id="back-button">lock</button><span id="tble-label"></span></header>
<div id="menu-grid"></div>
<footer>
<div id="chip-list"></div>
<button id="nxt-button" class="stp-button">NEXT</button>
</footer>
<script>
const ordr_data = { pltes: {}, tble: "" };
var plte_idx, nxt_plte;
const chip_dct = {};
const elem_dct = {};
const plte_dct = {};
const info_lst = [];
const tlbl = document.getElementById("tble-label");
const grid = document.getElementById("menu-grid");
const chps = document.getElementById("chip-list");
const nxtb = document.getElementById("nxt-button");
const sndb = document.getElementById("snd-button");
const addb = document.getElementById("add-button");
const clrb = document.getElementById("clr-button");
const cdo = document.getElementById("code-overlay");
const cdf = document.getElementById("code-field");
const cdl = document.getElementById("code-label");
const cdb = document.getElementById("code-button");
const bkb = document.getElementById("back-button");
const plo = document.getElementById("plte-overlay");
const pls = document.getElementById("plte-lst");
function showQuantity(info, v) {
var n = info.shortname;
var cnt = elem_dct[n][3];
if (info.limit && v > info.limit) cnt.animate([{ color: "#f00d1e", offset: 0 }], 666);
else if (v >= 0) {
cnt.innerText = v;
if (n in chip_dct) {
if (!v) {
chip_dct[n];
chip_dct[n].remove();
delete chip_dct[n];
}
} else if (v) {
nxtb.disabled = false;
let b = document.createElement("button");
let c = (chip_dct[n] = document.createElement("div"));
b.onclick = () => setvQuantity(info, 0);
c.className = "chip";
b.innerText = "cancel";
c.append(info.name, b);
chps.append(c);
}
var c = info_lst.map((info) => [ordr_data.pltes[plte_idx][info.shortname], info.name]).filter((v) => v[0]);
plte_dct[plte_idx].getElementsByClassName("plte-info")[0].innerText =
c.map((a) => `[${a[0]}] ${a[1]}`).join(", ") || "Empty Order";
if (!c.length) nxtb.disabled = true;
}
}
function setvQuantity(info, v, plte = ordr_data.pltes[plte_idx]) {
if ((v < 0) | (info.limit && v > info.limit)) return;
var n = info.shortname;
if (v) plte[n] = v;
else if (n in plte) delete plte[n];
if (plte == ordr_data.pltes[plte_idx]) showQuantity(info, v);
}
function incrQuantity(info, d, plte = ordr_data.pltes[plte_idx]) {
setvQuantity(info, ~~plte[info.shortname] + d, plte);
return false;
}
function showPlte(n) {
for (let info of info_lst) showQuantity(info, ordr_data.pltes[n][info.shortname] || 0);
tlbl.innerText = `Table #${ordr_data.tble} - Plate #${n}`;
}
function setvPlte(n) {
if (!(n in ordr_data.pltes)) return;
showPlte((plte_idx = n));
}
function showAddPlte(n) {
var elem = document.createElement("button");
var l1 = document.createElement("span");
var l2 = document.createElement("span");
var l3 = document.createElement("button");
l1.className = "plte-name";
l2.className = "plte-info";
l3.className = "plte-rem";
l1.innerText = `Plate #${n}`;
l3.innerText = "delete";
elem.append(l1, l2, l3);
elem.className = "plte-item";
elem.onclick = () => {
plo.classList.add("invisible");
setvPlte(n);
};
l3.onclick = (event) => {
event.stopPropagation();
if (!setvRemPlte(n)) plo.classList.add("invisible");
};
plte_dct[n] = elem;
pls.append(elem);
}
function setvAddPlte() {
var i = nxt_plte++;
ordr_data.pltes[i] = {};
showAddPlte(i);
return i;
}
function showRemPlte(n) {
plte_dct[n].remove();
delete plte_dct[n];
}
function setvRemPlte(i) {
if (!(i in ordr_data.pltes)) return;
delete ordr_data.pltes[i];
showRemPlte(i);
if (--nxt_plte in ordr_data.pltes) nxt_plte++;
var ks = Object.keys(ordr_data.pltes),
l = ks.length;
if (i == plte_idx)
if (l > 0) setvPlte(ks.pop());
else setvClrPltes();
return l;
}
function showClrPltes() {
for (var n in plte_dct) {
plte_dct[n].remove();
delete plte_dct[n];
}
}
function setvClrPltes() {
for (var n in ordr_data.pltes) delete ordr_data.pltes[n];
nxt_plte = 1;
showClrPltes();
setvPlte(setvAddPlte());
}
cdb.onclick = async () => {
var r = await fetch(`/lkp_code?code=${cdf.value}`);
var j = await r.json();
if (j[0]) {
ordr_data.code = cdf.value;
ordr_data.tble = j[0].tble;
cdo.classList.add("invisible");
setvClrPltes();
} else cdl.hidden = false;
};
cdf.onkeydown = () => (cdl.hidden = true);
cdf.onkeyup = () => {
if (event.keyCode == 13) {
event.preventDefault();
cdb.click();
}
};
setTimeout(() => {
document.getElementById("code-field").focus();
}, 1000);
bkb.onclick = () => {
cdo.classList.remove("invisible");
};
nxtb.onclick = () => {
if (!Object.keys(chip_dct).length) sndb.animate([{ backgroundColor: "red" }, { backgroundColor: "#f00d1e" }], 1337);
else plo.classList.remove("invisible");
};
plo.onclick = () => {
plo.classList.add("invisible");
};
addb.onclick = () => {
setvPlte(setvAddPlte());
plo.classList.add("invisible");
};
clrb.onclick = () => {
setvClrPltes();
plo.classList.add("invisible");
};
sndb.onclick = () => {
fetch("/snd_ordr", { method: "POST", body: JSON.stringify(ordr_data) });
sndb.animate([{ backgroundColor: "mediumseagreen" }, { backgroundColor: "#f00d1e" }], 1337);
setvClrPltes();
};
fetch("/ls_menu").then(async (j) => {
info_lst.push(...(await j.json()));
for (let info of info_lst) {
let n = info.shortname;
let itm = document.createElement("div");
let ttl = document.createElement("div");
let inc = document.createElement("div");
let cnt = document.createElement("span");
let unt = document.createElement("span");
let add = document.createElement("button");
let rem = document.createElement("button");
let img = document.createElement("img");
elem_dct[n] = [itm, ttl, inc, cnt, add, rem, img];
img.className = "menu-img";
itm.className = "menu-itm";
ttl.className = "menu-ttl";
inc.className = "menu-inc";
cnt.className = "menu-cnt";
unt.className = "menu-unt";
add.className = "menu-add";
rem.className = "menu-rem";
add.innerText = "arrow_drop_up";
rem.innerText = "arrow_drop_down";
img.src = info.image;
add.onclick = () => incrQuantity(info, +1);
rem.onclick = () => incrQuantity(info, -1);
cnt.innerText = "0";
unt.innerText = info.unit;
ttl.innerText = info.name;
ttl.append(inc);
inc.append(rem, cnt, unt, add);
itm.append(ttl, img);
grid.appendChild(itm);
}
});
</script>
</body>