File tree Expand file tree Collapse file tree 6 files changed +983
-0
lines changed Expand file tree Collapse file tree 6 files changed +983
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Vending Machine</ title >
6
+ </ head >
7
+ < body >
8
+ < div id ="vending-container ">
9
+ < h1 > Elige un producto</ h1 >
10
+ < div id ="items-list "> </ div >
11
+ < button id ="close-btn "> Cerrar</ button >
12
+ </ div >
13
+
14
+ < script >
15
+ window . addEventListener ( 'message' , function ( event ) {
16
+ var data = event . data ;
17
+
18
+ if ( data . action == 'open' ) {
19
+ document . getElementById ( 'vending-container' ) . style . display = 'block' ;
20
+ var itemsList = document . getElementById ( 'items-list' ) ;
21
+ itemsList . innerHTML = '' ;
22
+
23
+ data . items . forEach ( function ( item ) {
24
+ var itemDiv = document . createElement ( 'div' ) ;
25
+ itemDiv . textContent = item . label + ' - $' + item . price ;
26
+ itemDiv . onclick = function ( ) {
27
+ fetch ( 'https://muhaddil-machines/selectItem' , {
28
+ method : 'POST' ,
29
+ headers : {
30
+ 'Content-Type' : 'application/json' ,
31
+ } ,
32
+ body : JSON . stringify ( {
33
+ itemName : item . name ,
34
+ itemPrice : item . price ,
35
+ machineName : data . machineName
36
+ } )
37
+ } ) . then ( res => res . json ( ) ) ;
38
+ } ;
39
+ itemsList . appendChild ( itemDiv ) ;
40
+ } ) ;
41
+ } else if ( data . action == 'close' ) {
42
+ document . getElementById ( 'vending-container' ) . style . display = 'none' ;
43
+ }
44
+ } ) ;
45
+
46
+ document . getElementById ( 'close-btn' ) . onclick = function ( ) {
47
+ fetch ( 'https://muhaddil-machines/close' , {
48
+ method : 'POST' ,
49
+ } ) ;
50
+ } ;
51
+ </ script >
52
+ </ body >
53
+ </ html >
You can’t perform that action at this time.
0 commit comments