-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpooltracker
155 lines (141 loc) · 6.5 KB
/
pooltracker
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
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Pool Tracker" height="35">
<Require feature="wave" />
</ModulePrefs>
<Content type="html">
<![CDATA[
<style type="text/css">
#content.edit #view {display : none; }
#name { float: left; font-weight: bold; margin-right: 1em;}
ul { padding: 0; margin: 0.2em; float: left; font-size: 0.8em;}
li { display: inline; height: 1em; float: left; width : 1em; margin: 0 0.1em; -moz-border-radius: 1em; -webkit-border-radius: 1em;}
li.unavalable { display:none; }
li.clear, li.full, li.empty { cursor: pointer; }
li.full { background-color: #000; }
li.empty { background-color: #BBB; }
li.breaker { width: .5em; }
#content.view #edit {display: none; }
form { display: inline; font-size: .8em;}
#reset { text-decoration:underline; cursor:pointer;}
#item.noreset .reset { display: none; }
</style>
<script type="text/javascript">
function set_pool(item) {
wave.getState().submitValue('pool', item._count);
}
function set_value(value, name) {
wave.getState().submitValue(name, value);
}
function reset() {
var state = wave.getState();
var reset_value = parseInt(state.get('resetvalue', state.get('min', 0)));
set_value(reset_value, 'pool');
}
function updateAll() {
var state = wave.getState();
var resetable = state.get('resetable', 0);
document.getElementById('item').className = (resetable != 0 ? 'reset' : 'noreset');
document.getElementById('resetable').checked = resetable != 0;
var available = parseInt(state.get('cap', 10));
var lowest = parseInt(state.get('min', 0));
var active = parseInt(state.get('pool', 0));
var reset_value = parseInt(state.get('resetvalue', lowest));
var name = state.get('name', '');
update_pool(lowest, available, active);
update_selector(available, available+10, "maxvalue");
update_selector(lowest, available, "minvalue");
update_selector(reset_value, available, "resetvalue");
update_name(name);
}
function update_name(name) {
document.getElementById('namein').value = name;
document.getElementById('name').textContent = name;
}
function update_pool(lowest, available, active) {
var element = document.getElementById("pool");
var count = 0;
var value = Math.max(lowest, active);
var match = /full|empty|unavalable/;
for (var i in element.childNodes) {
var node = element.childNodes[i];
if (match.test(node.className)) {
if ( count >= available )
node.className = 'unavalable';
else
node.className = (count < value) ? 'full' : 'empty';
count += 1;
}
}
for (var i = count; i < available ; i ++) {
var newli = document.createElement('li');
newli.onclick = function() { set_pool(this);}
newli.className = (i < value) ? 'full' : 'empty';
newli._count = i+1;
element.appendChild(newli);
if (i%5 == 4){
var newdevider = document.createElement('li');
newdevider.className="breaker";
element.appendChild(newdevider);
}
}
document.getElementById("clear").style.display = (lowest > 0 ? "none" : "");
}
function update_selector(value, highpoint, name) {
var selector = document.getElementById(name);
var count = 0;
for( var i in selector.childNodes) {
if (selector.childNodes[i].tagName == "OPTION") {
selector.childNodes[i].style.display = (count <= highpoint ? "" : "none");
count += 1;
}
}
for (var i = count; i <= highpoint ; i ++) {
var newoption = document.createElement('option');
newoption.textContent = i;
newoption.value = i;
selector.appendChild(newoption);
}
selector.selectedIndex = value;
}
function updateMode(mode) {
document.getElementById('content').className = (mode == wave.Mode.EDIT ? 'edit' : 'view');
}
gadgets.util.registerOnLoadHandler(function() {
document.getElementById("clear")._count = 0;
wave.setStateCallback(updateAll);
wave.setModeCallback(updateMode);
});
</script>
<div id="content">
<div id="item">
<div id="view">
<span id="name"></span>
<ul class="pool" id="pool">
<li class="clear" id="clear" onClick="set_pool(this);">X</li>
</ul>
<span class="reset" id="reset" onclick="reset()">Reset</span>
</div>
<form id="edit">
<label>Name</label>
<input type="text" id="namein" name="name" onchange="set_value(this.value, 'name');"></input>
<label>Min Value</label>
<select name="minvalue" id="minvalue" onchange="set_value(this.selectedIndex, 'min');">
<option value="0">0</option>
</select>
<label>Max Value</label>
<select name="maxvalue" id="maxvalue" onchange="set_value(this.selectedIndex, 'cap');">
<option value="0">0</option>
</select>
<label>Resetable?</label>
<input type="checkbox" id="resetable" onchange="set_value(this.checked ? 1 : 0, 'resetable');" />
<label class="reset">Reset Value</label>
<select name="resetvalue" class="reset" id="resetvalue" onchange="set_value(this.selectedIndex, 'resetvalue');">
<option value="0">0</option>
</select>
</form>
</div>
</div>
]]>
</Content>
</Module>