-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanifest.js
More file actions
350 lines (303 loc) · 9.48 KB
/
manifest.js
File metadata and controls
350 lines (303 loc) · 9.48 KB
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
var groups = {};
var jumpers = {};
var student_jumps = {};
function fill_wishlist(result) {
var html = "<tr><th style=\"width: 30px;\"> </th>";
html += "<th style=\"width: 20px;\"> </th>";
html += "<th>Namn</th><th>Hopptyp</th>";
html += "<th>Flygplan</th><th>Väntat</th></tr>";
jumpers = result;
/* combine groups */
groups = {}
for(idx in result) {
var jumper = result[idx];
if(jumper.group in groups) {
groups[jumper.group].push(idx);
} else {
groups[jumper.group] = [idx];
}
}
/* add jumpers grouped together by the first jumper.
keep track of which jumpers have been added to prevent duplicates. */
var added = {};
var last_color = 1;
var max_color = 0;
/* count number of colors to use */
for(gidx in groups) {
if(groups[gidx].length > 1)
max_color++;
}
for(idx in result) {
var jumper = result[idx];
if(idx in added)
continue;
var group = groups[jumper.group];
var group_color = 0;
if(group.length > 1)
group_color = last_color++;
var hue = 360/max_color * (group_color-1);
for(j in group) {
var jid = group[j];
var jumper = result[jid];
if(jid in added)
continue;
added[jid] = true;
html += "<tr>";
html += "<td>";
if($("#options").length > 0) {
html += "<a data-id='" + jid + "' class='edit' href='#edit' alt='Ändra reservation'>";
html += "<i class='icon-edit'></i></a>";
html += "<a data-id='" + jid + "' class='remove' href='#remove' alt='Ta bort reservation'>";
html += "<i class='icon-remove'></i></a>";
} else {
html += " ";
}
html += "</td>";
if(group_color > 0)
html += "<td style=\"background-color: hsl(" + hue + ", 100%, 75%);\"> </td>";
else
html += "<td> </td>";
html += "<td>" + jumper.jumper + "</td>";
html += "<td>" + jumper.jumptype + " "
+ jumper.altitude + " m</td>";
html += "<td>" + jumper.aircraft + "</td>";
html += "<td>" + format_time(jumper.waited) + "</td>";
html += "</tr>";
}
}
$("#wishlist").html(html);
$(".remove").click(function() {
jumper = jumpers[$(this).data("id")];
if(confirm("Är du säker på att du vill ta bort '" + jumper.jumper + "'?")) {
search_reset();
$.getJSON("book.php?remove=" + jumper.internal, function(result) {
refresh();
});
}
});
$(".edit").click(function() {
jumper = jumpers[$(this).data("id")];
$("#jumper-not-found").slideUp();
$("#search").autocomplete("destroy");
$("#jumper").html(jumper.jumper);
$("#jumper-id").val(jumper.internal);
load_groups();
$("#search-box").slideUp();
$("#options").slideDown();
$("#altitude").val(jumper.altitude);
$("#jumptype").val(jumper.jumptype_internal);
$("#aircraft").val(jumper.aircraft);
$("#comment").val(jumper.comment);
$("#group").val(jumper.group);
$("#settings-solo").slideDown();
$("#btn-edit").show();
$("#btn-reserve").hide();
if(jumper.student) {
$("#group-control").hide();
$("#settings-student").show();
$("#settings-non-student").hide();
$("#studentjumpno").val(jumper.student.jump);
$("#studentjumpno").data("education", jumper.student.education);
var html = "";
for(idx in student_jumps) {
var j = student_jumps[idx];
if(j.education != jumper.student.education)
continue;
if(j.jump == jumper.student.jump) {
html += "<option selected='1' value='" + j.jump + "'>" + j.jump + " - " + j.program + "</option>";
} else {
html += "<option value='" + j.jump + "'>" + j.jump + " - " + j.program + "</option>";
}
}
$("#studentjumpno").html(html);
} else {
$("#group-control").show();
$("#settings-non-student").show();
$("#settings-student").hide();
}
});
}
function fill_time(result) {
var time = new Date(result.time*1000);
var hours = time.getHours();
var minutes = time.getMinutes();
if(hours < 10)
hours = "0" + hours;
if(minutes < 10)
minutes = "0" + minutes;
$("#time").html(hours + ":" + minutes);
}
function fill_load(result) {
for(loadno = 0; loadno < 3; loadno++) {
if($("#load-" + loadno).length == 0)
break;
if(!(loadno in result)) {
/* clear this box */
$("#load-" + loadno + "-aircraft").html("");
$("#load-" + loadno + "-loadno").html("");
$("#load-" + loadno + "-15min").slideUp();
$("#load-" + loadno + "-30min").slideUp();
$("#load-" + loadno).html("");
}
}
for(loadno in result) {
load = result[loadno];
if($("#load-" + loadno).length == 0)
break;
$("#load-" + loadno + "-aircraft").html(load.aircraft);
$("#load-" + loadno + "-loadno").html("(#" + load.load + ")");
if(load.call["15"] == "Y") {
$("#load-" + loadno + "-15min").slideDown();
$("#load-" + loadno + "-30min").slideUp();
} else if(load.call["30"] == "Y") {
$("#load-" + loadno + "-15min").slideUp();
$("#load-" + loadno + "-30min").slideDown();
} else {
$("#load-" + loadno + "-15min").slideUp();
$("#load-" + loadno + "-30min").slideUp();
}
var html = "<tr><th style=\"width: 20px;\"> </th>";
html += "<th style=\"width: 20px;\"> </th>";
html += "<th>Namn</th><th>Höjd</th></tr>";
/* combine groups */
var load_groups = {}
for(idx in load.jumpers) {
var jumper = load.jumpers[idx];
if(jumper.group in load_groups) {
load_groups[jumper.group].push(idx);
} else {
load_groups[jumper.group] = [idx];
}
}
/* add jumpers grouped together by the first jumper.
keep track of which jumpers have been added to prevent duplicates. */
var added = {};
var last_color = 1;
var max_color = 0;
/* count number of colors to use */
for(gidx in load_groups) {
if(gidx == null || gidx == 0)
continue;
if(load_groups[gidx].length > 1)
max_color++;
}
for(idx in load.jumpers) {
var jumper = load.jumpers[idx];
if(idx in added)
continue;
var group = load_groups[jumper.group];
if(jumper.group == null)
group = [idx];
var group_color = 0;
if(group.length > 1)
group_color = last_color++;
var hue = 360/max_color * (group_color-1);
for(j in group) {
var jumper = load.jumpers[group[j]];
if(group[j] in added)
continue;
added[group[j]] = true;
html += "<tr>";
if(group_color > 0)
html += "<td style=\"background-color: hsl(" + hue + ", 100%, 75%);\"> </td>";
else
html += "<td> </td>";
html += "<td>";
if(jumper.student != undefined) {
html += jumper.student.jump;
}
if($.inArray("LOADMASTER", jumper.roles) >= 0)
html += "HM";
else
html += " ";
html += "</td>";
html += "<td>" + jumper.jumper + "</td>";
html += "<td>" + jumper.altitude + "</td>";
}
}
$("#load-" + loadno).html(html);
}
}
function format_time(t) {
var str = ""
if(t > 60*60) {
var h = Math.floor(t/60/60);
if(h > 1)
str = h + " timmar, ";
else
str = "1 timme, ";
t = t - h*60*60;
}
var m = Math.floor(t/60);
str = str + m + " minuter";
return str;
}
function load_groups() {
var html = "";
html += "<option selected='1' value='0'>Solo</option>";
for(gidx in groups) {
jumper = jumpers[groups[gidx][0]];
html += "<option value='" + gidx + "'>" + jumper.jumper + "</option>";
}
$("#group").html(html);
}
function load_options() {
$.getJSON('aircrafts.php', function(result) {
var html = "";
for(idx in result) {
ac = result[idx];
html += "<option value='" + ac.aircraft + "'>" + ac.aircraft + "</option>";
}
$("#aircraft").html(html);
});
$.getJSON('altitudes.php', function(result) {
var html = "";
for(idx in result) {
var alt = result[idx];
// TODO: Use unit instead of hard coded meter
html += "<option value='" + alt + "'>" + alt + " m</option>";
}
$("#altitude").html(html);
});
$.getJSON('jumptypes.php', function(result) {
var html = "";
for(idx in result) {
var jt = result[idx];
if(jt.jumptype == 'O') {
html += "<option selected='1' value='" + jt.jumptype + "'>" + jt.label + "</option>";
} else {
html += "<option value='" + jt.jumptype + "'>" + jt.label + "</option>";
}
}
$("#jumptype").html(html);
});
$.getJSON('studentjumps.php', function(result) {
student_jumps = result;
});
$("#comment").val("");
}
function search_reset() {
$("#btn-edit").hide();
$("#btn-reserve").show();
$("#jumper").html("");
$("#search-box").slideDown();
$("#options").slideUp();
$("#settings-solo").slideDown();
$("#search").autocomplete("destroy");
$("#search").val("");
$("#search").autocomplete({
source: "search.php",
minLength: 2,
select: function(event, ui) {
$(this).val(ui.item.value);
$(this).parents("form").submit(); // this will submit the form.
},
close: function(event) {
var ev = event.originalEvent;
if ( ev.type === "keydown" && ev.keyCode === $.ui.keyCode.ESCAPE ) {
$( this ).val( "" );
}
}
});
$("#search").focus();
}