-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
304 lines (249 loc) · 9.88 KB
/
index.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
<html lang="ru">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Barbot - nau-ra.ru</title>
<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css">
<!-- Main Style -->
<link rel="stylesheet" type="text/css" href="assets/css/main.css">
<!-- Responsive Style -->
<link rel="stylesheet" type="text/css" href="assets/css/responsive.css">
<!--Icon Font-->
<link rel="stylesheet" media="screen" href="assets/fonts/font-awesome/font-awesome.min.css" />
<!-- Extras -->
<link rel="stylesheet" type="text/css" href="assets/extras/animate.css">
<!-- jQuery Load -->
<script src="assets/js/jquery-min.js"></script>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
var WEB_DEBUG = 0;
var GET_STATE_INTERVAL = 200;
var prev_state = -1;
function mark(id, prefix, status)
{
var element = document.getElementById(id);
if(status === 1)
{
if (!element.classList.contains(prefix + "ready") )
{
element.classList.add(prefix + "ready");
}
if (element.classList.contains(prefix + "busy") )
{
element.classList.remove(prefix + "busy");
}
if (element.classList.contains(prefix + "error") )
{
element.classList.remove(prefix + "error");
}
}
else if(status === 2)
{
if (element.classList.contains(prefix + "ready") )
{
element.classList.remove(prefix + "ready");
}
if (!element.classList.contains(prefix + "busy") )
{
element.classList.add(prefix + "busy");
}
if (element.classList.contains(prefix + "error") )
{
element.classList.remove(prefix + "error");
}
}
else if (status === 3)
{
if (element.classList.contains(prefix + "ready") )
{
element.classList.remove(prefix + "ready");
}
if (element.classList.contains(prefix + "busy") )
{
element.classList.remove(prefix + "busy");
}
if (!element.classList.contains(prefix + "error") )
{
element.classList.add(prefix + "error");
}
}
}
function getState()
{
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var data = JSON.parse(request.responseText);
var element = document.getElementById("state");
element.textContent = data.state;
mark("glass", "g_", data.state_code);
mark("bottle1", "b_", data.bottle1);
mark("bottle2", "b_", data.bottle2);
mark("bottle3", "b_", data.bottle3);
mark("bottle4", "b_", data.bottle4);
mark("bottle5", "b_", data.bottle5);
mark("bottle6", "b_", data.bottle6);
for(var i = 0; i < 6; ++i)
{
var btn = document.getElementById("make_coctail_" + i);
if ( btn )
btn.disabled = (data.state_code != 1);
}
var need_show = ((data.state_code == 1) && (prev_state == 2));
prev_state = data.state_code;
if(need_show)
{
for(var i = 0; i < 6; ++i)
{
var btn = document.getElementById("make_coctail_" + i);
btn.classList.remove("pressed");
}
}
}
}
request.open('GET', '/state', true);
request.send();
}
function makeCoctail(CocId)
{
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var data = JSON.parse(request.responseText);
var element = document.getElementById("state");
element.textContent = data.state;
var btn = document.getElementById("make_coctail_" + CocId);
btn.disabled = (data.state_code != 1);
}
};
var btn_pressed = document.getElementById("make_coctail_" + CocId);
btn_pressed.classList.add("pressed");
request.open('POST', '/makeCoctail', true);
request.send("coctail=" + CocId);
}
function fillCoctailsHtml(coctailData)
{
var buttonContainer = document.getElementById("coctailButtonGrid")
var buttonHtml = '';
buttonHtml += '<div class="row coctailRow text-center">';
for (var i = 0; i < coctailData.length; ++i) {
buttonHtml += '<div class="col-md-4"><button class="btn btn-border btn-lg wow fadeInDown animated" id="make_coctail_' + coctailData[i].index + '" onclick="makeCoctail(' + coctailData[i].index + ')" data-wow-offset="10" href="#"><i class="fa fa-check-circle "></i>';
buttonHtml += coctailData[i].name;
buttonHtml += '</button></div>';
}
buttonHtml += '</div>';
document.getElementById('coctailButtonGrid').innerHTML = buttonHtml;
}
function loadCoctails()
{
if (WEB_DEBUG == 0) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var coctailData = JSON.parse(request.responseText);
fillCoctailsHtml(coctailData);
}
};
request.open('GET', 'getCoctails', true);
request.send();
}
else {
coctailData = [{index: 0, name: "Coctail 1"}, {index: 1, name: "Coctail 2"}, {index: 2, name: "Coctail 3"}];
fillCoctailsHtml(coctailData);
}
}
function fillBottlesHtml(bottleData)
{
var divContainer = document.getElementById("bottleDivGrid")
var bottleHtml = '';
bottleHtml += '<div class="row bottleRow text-center wow fadeInLeft animated" data-wow-offset="10">';
for (var i = 0; i < bottleData.length; ++i) {
bottleHtml += '<div class="col-md-4 box-item left"><span id="bottle' + bottleData[i].index + '" class="icon b_ready"><i class="fa fa-flask"></i></span><div class="text">';
bottleHtml += "<h4>" + bottleData[i].name + "</h4>";
bottleHtml += '</div></div>';
}
bottleHtml += '</div>';
document.getElementById('bottleDivGrid').innerHTML = bottleHtml;
}
function loadBottles()
{
if (WEB_DEBUG == 0) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var bottleData = JSON.parse(request.responseText);
fillBottlesHtml(bottleData);
}
};
request.open("GET", "getBottles", true);
request.send();
}
else {
bottleData = [{index: 0, name: "Bottle 1"},
{index: 1, name: "Bottle 2"},
{index: 2, name: "Bottle 3"},
{index: 3, name: "Bottle 4"},
{index: 4, name: "Bottle 5"},
{index: 5, name: "Bottle 6"}];
fillBottlesHtml(bottleData);
}
}
$(document).ready(function() {
loadCoctails();
loadBottles();
getState();
window.setInterval(getState, GET_STATE_INTERVAL);
});
</script>
</head>
<body>
<!-- Nav Menu Section -->
<div class="logo-menu">
<nav class="navbar navbar-default">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header col-md-3">
<a class="navbar-brand" href="index.html"><img src="favicon.ico" alt=""><!-- i class="fa fa-fa fa-cubes"> </i>-->BarBot</a>
</div>
</div>
</div>
</nav>
</div>
<section id="features">
<div class="container">
<div class="row">
<div id="coctailButtonGrid"></div>
</div>
</div>
<!-- рюмка статус -->
<div class="row glassRow text-center">
<div class="col-md-12">
<div class="show-box wow fadeInDown animated" data-wow-offset="10">
<span class="icon">
<i id="glass" class="fa fa-glass bottle g_ready"></i>
</span>
</div>
<div id="state"> </div>
</div>
</div>
<!-- рюмка -->
<div class="container">
<div class="row">
<div id="bottleDivGrid"></div>
</div>
</div>
</section>
<!-- Bootstrap JS -->
<script src="assets/js/bootstrap.js"></script>
<!-- WOW JS plugin for animation -->
<script src="assets/js/wow.js"></script>
<!-- All JS plugin Triggers -->
<script src="assets/js/main.js"></script>
</body>
</html>