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
|
<!DOCTYPE html>
<html>
<head>
<title>Light Loop Pi</title>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="/static/css/bootstrap-slider.css"/>
<link rel="stylesheet" href="/static/css/main.css"/>
<script src="/static/js/jquery-2.1.1.min.js"></script>
<script src="/static/js/underscore-min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/bootstrap-slider.min.js"></script>
<script>
function get_data() {
$.get('/data', function(res) {
alert(res);
});
};
function save_data(data) {
$('.light-channel').each(function(_, channel) {
channel = $(channel);
channel.find('.light-row').each(function(_, row) {
var vals = $(row).find('.light-cell-btn').map(function(x) { return $(x).hasClass('active') ? 1 : 0; });
console.log(_.values(vals));
});
console.log(channel.attr('data-light-channel'));
});
$.ajax({
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(data),
dataType: 'json',
url: '/data',
});
}
$(document).ready(function() {
var TREES = 8;
var CHANNELS = 8;
var CELLS = 24;
_.each(_.range(CHANNELS), function(i) {
var row = $(_.template($('#light-row-template').text(), {i: i, channels: CHANNELS, cells: CELLS}));
$('#light-container').append(row);
$('#tree-btns').append($('<button type="button" class="btn btn-default tree-btn" data-tree="' + i + '">Tree ' + i + '</button>'));
});
$('#ex1').slider({
formater: function(value) {
return 'Current value: ' + value;
}
});
$('.tree-btn').click(function() {
var tree = $(this).attr('data-tree');
$('.light-tree').hide();
$('.light-tree[data-light-tree=' + tree +']').show();
});
$('.toggle-row-btn').click(function() {
var row = $(this).parent('.light-row');
$(row).find('.light-cell-btn').toggleClass('active');
})
$('#save-btn').click(function(){
save_data();
});
});
</script>
</head>
<body>
<div class="container">
<h1>Light Loop Pi</h1>
<div class="speed-slider">
<label>Loop speed:</label>
<input id="ex1" data-slider-id='ex1Slider' type="text" data-slider-min="500" data-slider-max="5000" data-slider-step="100" data-slider-value="1000"/>
</div>
<div class="btn-toolbar" role="toolbar">
<div id="tree-btns" class="btn-group"></div>
<div class="btn-group">
<button id="save-btn" type="button" class="btn btn-primary">Save</button>
</div>
</div>
<div id="light-container"></div>
</div>
<script type="text/template" class="template" id="light-row-template">
<div class="light-tree" data-light-tree="<%= i %>">
<h3>Tree <%= i %></h3>
<% _.each(_.range(channels), function(j) { %>
<div class="light-row" data-light-row="<%= j %>">
<span>Channel <%= j %></span>
<% _.each(_.range(cells), function(k) { %>
<button type="button" class="btn btn-success light-cell-btn" data-toggle="button" data-light-cell="<%= k %>"> </button>
<% }); %>
<button type="button" class="btn btn-warning toggle-row-btn">Toggle Row</button>
</div>
<% }); %>
</div>
</script>
</body>
</html>
|