-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.html
359 lines (265 loc) · 13.9 KB
/
panel.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Weather widget</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/CreativeIT/getmdl-select/master/getmdl-select.min.css">
<script defer src="https://cdn.rawgit.com/CreativeIT/getmdl-select/master/getmdl-select.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="http://localhost/intersol/style.css">
<script type="text/javascript" src="http://localhost/intersol/core.js"></script>
</head>
<body>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<h4>Действующие виджеты</h4>
<table id="widget-table" class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Хост</th>
<th class="mdl-data-table__cell--non-numeric">Пользователь</th>
<th class="mdl-data-table__cell--non-numeric">Город</th>
<th class="mdl-data-table__cell--non-numeric">Вид блока</th>
<th class="mdl-data-table__cell--non-numeric">Адрес виджета</th>
<th class="mdl-data-table__cell--non-numeric">Редактировать</th>
<th>Кол-во дней</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<label class="city-chooser mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-1">
<input type="radio" id="option-1" class="mdl-radio__button" name="city" value="Москва" checked>
<span class="mdl-radio__label">Москва</span>
</label>
<label class="city-chooser mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-2">
<input type="radio" id="option-2" class="mdl-radio__button" name="city" value="Санкт-петербург">
<span class="mdl-radio__label">Санкт-петербург</span>
</label>
<label class="city-chooser mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-3">
<input type="radio" id="option-3" class="mdl-radio__button" name="city" value="Нижний Новгород">
<span class="mdl-radio__label">Нижний Новгород</span>
</label>
</div>
</div>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<label class="days-chooser mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-6">
<input type="radio" id="option-6" class="mdl-radio__button" name="days" value="1" checked>
<span class="mdl-radio__label">1 день</span>
</label>
<label class="days-chooser mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-7">
<input type="radio" id="option-7" class="mdl-radio__button" name="days" value="3">
<span class="mdl-radio__label">3 дня</span>
</label>
<label class="days-chooser mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-8">
<input type="radio" id="option-8" class="mdl-radio__button" name="days" value="7">
<span class="mdl-radio__label">Неделя</span>
</label>
</div>
</div>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<label class="pos-chooser mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-4">
<input type="radio" id="option-4" class="mdl-radio__button" name="position" value="Vertical" checked>
<span class="mdl-radio__label">Вертикально</span>
</label>
<label class="pos-chooser mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-5">
<input type="radio" id="option-5" class="mdl-radio__button" name="position" value="Horizontal">
<span class="mdl-radio__label">Горизонтально</span>
</label>
</div>
</div>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label getmdl-select" id="users-list">
<input class="mdl-textfield__input" id="users" name="user" type="text" readonly tabIndex="-1"/>
<label class="mdl-textfield__label" for="users">Users</label>
<ul class="mdl-menu mdl-menu--bottom-left mdl-js-menu" for="users"></ul>
</div>
</div>
</div>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<button id="create" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect">
Создать виджет
</button>
</div>
</div>
<dialog class="mdl-dialog">
<h4 class="mdl-dialog__title">Обновить</h4>
<div class="mdl-dialog__content">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<label class="city-chooser-modal mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-10">
<input type="radio" id="option-10" class="mdl-radio__button" name="city" value="Москва" checked>
<span class="mdl-radio__label">Москва</span>
</label>
<label class="city-chooser-modal mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-11">
<input type="radio" id="option-11" class="mdl-radio__button" name="city" value="Санкт-петербург">
<span class="mdl-radio__label">Санкт-петербург</span>
</label>
<label class="city-chooser-modal mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-12">
<input type="radio" id="option-12" class="mdl-radio__button" name="city" value="Нижний Новгород">
<span class="mdl-radio__label">Нижний Новгород</span>
</label>
</div>
</div>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<label class="days-chooser-modal mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-13">
<input type="radio" id="option-13" class="mdl-radio__button" name="days" value="1">
<span class="mdl-radio__label">1 день</span>
</label>
<label class="days-chooser-modal mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-14">
<input type="radio" id="option-14" class="mdl-radio__button" name="days" value="3">
<span class="mdl-radio__label">3 дня</span>
</label>
<label class="days-chooser-modal mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-15">
<input type="radio" id="option-15" class="mdl-radio__button" name="days" value="7">
<span class="mdl-radio__label">Неделя</span>
</label>
</div>
</div>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<label class="pos-chooser-modal mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-16">
<input type="radio" id="option-16" class="mdl-radio__button" name="position" value="Vertical" checked>
<span class="mdl-radio__label">Вертикально</span>
</label>
<label class="pos-chooser-modal mdl-radio mdl-js-radio mdl-js-ripple-effect" for="option-17">
<input type="radio" id="option-17" class="mdl-radio__button" name="position" value="Horizontal">
<span class="mdl-radio__label">Горизонтально</span>
</label>
</div>
</div>
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--12-col">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label getmdl-select" id="users-list-modal">
<input class="mdl-textfield__input" id="users-modal" name="user" type="text" readonly tabIndex="-1"/>
<label class="mdl-textfield__label" for="users-modal">Users</label>
<ul class="mdl-menu mdl-menu--bottom-left mdl-js-menu" for="users-modal"></ul>
</div>
</div>
</div>
</div>
<div class="mdl-dialog__actions">
<button id="update" type="button" class="mdl-button">Сохранить</button>
<button type="button" class="mdl-button close">Отмена</button>
</div>
</dialog>
<script type="text/javascript">
var updateId = null;
$(document).ready( function() {
Widget.listUsers(function( data ) {
var ul = $('#users-list').find('ul');
var ulModal = $('#users-list-modal').find('ul');
var list = '';
ul.html('');
ulModal.html('');
for(var i=0; i<data.length; i++)
{
list += '<li class="mdl-menu__item" data-val="' + data[i].username + '">' + data[i].username + '</li>'
}
ul.html( list );
ulModal.html( list );
$('#users-list .mdl-menu__item').click(function() {
var username = $(this).text();
$('#users').val( username );
//Stupid framework, you should never used it !!!
$(this).parent().parent().parent().addClass('is-visible');
$(this).parent().parent().parent().addClass('is-focused');
});
$('#users-list-modal .mdl-menu__item').click(function() {
var username = $(this).text();
$('#users-modal').val( username );
//Stupid framework, you should never used it !!!
$(this).parent().parent().parent().addClass('is-visible');
$(this).parent().parent().parent().addClass('is-focused');
});
});
Widget.list( function( data ) {
var table = $('#widget-table');
var tbody = table.find('tbody');
var html = '';
tbody.html('');
for(var i=0; i<data.length; i++)
{
var host = ( typeof data[i].host !== "undefined") ? data[i].host : '-';
html += '<tr>';
html += '<td class="mdl-data-table__cell--non-numeric">' + host + '</td>';
html += '<td class="mdl-data-table__cell--non-numeric">' + data[i].user + '</td>';
html += '<td class="mdl-data-table__cell--non-numeric">' + data[i].city + '</td>';
html += '<td class="mdl-data-table__cell--non-numeric">' + data[i].pos + '</td>';
html += '<td>' + Widget.url + '/get?id=' + data[i].name.slice(6) + '</td>';
html += '<td>' + data[i].days + '</td>';
html += '<td class="show-dialog"><i class="material-icons">edit</i></td>';
html += '</tr>';
}
tbody.html( html );
var dialog = document.querySelector('dialog');
var showDialogButton = $('.show-dialog');
if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
showDialogButton.click(function() {
var row = $(this).parent();
var days = row.find('td:nth-child(6)').text();
var city = row.find('td:nth-child(3)').text();
var pos = row.find('td:nth-child(4)').text();
$('.days-chooser-modal').find('[value="' + days + '"]').trigger('click');
$('.city-chooser-modal').find('[value="' + city + '"]').trigger('click');
$('.pos-chooser-modal').find('[value="' + pos + '"]').trigger('click');
updateId = row.find('td:nth-child(5)').text().split('id')[1].slice(1);
dialog.showModal();
});
dialog.querySelector('.close').addEventListener('click', function() {
dialog.close();
});
} );
});
$('#create').click(function () {
var city = 1, days = 1, position = 1, username = 'admin';
$('.city-chooser').each(function() {
if( $(this).hasClass('is-checked') )
city = $(this).find('.mdl-radio__button').val();
});
$('.days-chooser').each(function() {
if( $(this).hasClass('is-checked') )
days = $(this).find('.mdl-radio__button').val();
});
$('.pos-chooser').each(function() {
if( $(this).hasClass('is-checked') )
position = $(this).find('.mdl-radio__button').val();
});
username = $('#users').val();
Widget.create( city, days, position, username );
});
$('#update').click(function () {
var city = 1, days = 1, position = 1, username = 'admin';
$('.city-chooser-modal').each(function() {
if( $(this).hasClass('is-checked') )
city = $(this).find('.mdl-radio__button').val();
});
$('.days-chooser-modal').each(function() {
if( $(this).hasClass('is-checked') )
days = $(this).find('.mdl-radio__button').val();
});
$('.pos-chooser-modal').each(function() {
if( $(this).hasClass('is-checked') )
position = $(this).find('.mdl-radio__button').val();
});
username = $('#users-modal').val();
if( updateId !== null)
Widget.update( city, days, position, username, updateId );
updateId = null;
});
</script>
</body>
</html>