-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.dev.js
More file actions
416 lines (358 loc) · 13.1 KB
/
script.dev.js
File metadata and controls
416 lines (358 loc) · 13.1 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
// Die IDs der Gebäude und Fahrzeuge, um nachher (beim Zählen) die Namen auszugeben.
var buildingsById = {
0: 'Feuerwache',
1: 'Feuerwehrschule',
2: 'Rettungswache',
3: 'Rettungsschule',
4: 'Krankenhaus',
5: 'Rettungshubschrauber-Station',
6: 'Polizeiwache',
7: 'Leitstelle',
8: 'Polizeischule',
9: 'THW',
10: 'THW Schule',
11: 'Bereitschaftspolizei'
}
var carsById = {
0: 'LF 20',
1: 'LF 10',
2: 'DLK 23',
3: 'ELW 1',
4: 'RW',
5: 'GW-A',
6: 'LF 8/6',
7: 'LF 20/16',
8: 'LF 10/6',
9: 'LF 16-TS',
10: 'GW-Öl',
11: 'GW-L2-Wasser',
12: 'GW-Messtechnik',
13: 'SW 1000',
14: 'SW 2000',
15: 'SW 2000-Tr',
16: 'SW KatS',
17: 'TLF 2000',
18: 'TLF 3000',
19: 'TLF 8/8',
20: 'TLF 8/18',
21: 'TLF 16/24-Tr',
22: 'TLF 16/25',
23: 'TLF 16/45',
24: 'TLF 20/40',
25: 'TLF 20/40-SL',
26: 'TLF 16',
27: 'GW-Gefahrgut',
28: 'RTW',
29: 'NEF',
30: 'HLF 20',
31: 'RTH',
32: 'FuStW',
33: 'GW-Höhenrettung',
34: 'ELW 2',
35: 'leBefKw',
36: 'MTW',
37: 'TSF-W',
38: 'KTW',
39: 'GKW',
40: 'MTW-TZ',
41: 'MzKW',
42: 'LKW K9',
43: 'BRmG R',
44: 'Anh. DLE',
45: 'MLW 5',
46: 'WLF',
47: 'AB-Rüst',
48: 'AB-Atemschutz',
49: 'AB-Öl',
50: 'GruKw',
51: 'FüKw',
52: 'GefKw'
}
jQuery = $;
// Arrays, um nachher die (verfügbaren) Fahrzeuge und Wachen zu zählen
var buildingAmount = Array(), carAmount = Array(), carAvailableAmount = Array();
// Array, um die Einstellungen des Nutzers zu speichern
var userSettings;
$('.aao').bind('click', function(e)
{
$(this).css('border', '2px solid black');
}
)
// Fallunterscheidung für die verschiedenen Seiten
if (window.location.pathname == '/') {
// Startseite
tabsForMissions();
fayeEvent();
hideLogo();
changeTabTitleByCall();
restoreWellDiv();
showStationSearch();
showChatSearch();
// Faye dazu anweisen, die Funktion fayeEvent aufzurufen
faye.subscribe('/private-user'+ user_id +'de', function(data) {
fayeEvent();
});
if (alliance_id != undefined) {
faye.subscribe('/privatealliance-'+ alliance_id +'de', function(data) {
fayeEvent();
});
}
} else if (window.location.pathname.match('missions/')) {
// Einsätze
showCarTypesInsteadOfStation();
useEasyHotkeys();
} else if (window.location.pathname.match('buildings/')) {
}
// Funktion wird immer angerufen, wenn ein Event von faye komm (bspw. Statuswechsel, neuer Einsatz etc.)
function fayeEvent()
{
prepareBuildingAndCarCounter();
showBuildingSearch();
showCarSearch();
showBuildingAmount();
showCarAmount();
changeTabTitleByCall();
showMissionCounterInTab();
countPatients();
}
// Einstellungen des Users bekommen
function getUserSettings()
{
}
// zwei Divs für die Fahrzeuge und Wachen erstellen
function prepareBuildingAndCarCounter()
{
// bisherige Tabellen entfernen, damit diese nicht doppelt und dreifach auftauchen
$('.row-fluid:eq(3)').remove();
$('.row-fluid:eq(2)').after('<div class="row-fluid"><div id="scriptBuildingAmount" class="span6 well"></div><div id="scriptCarAmount" class="span6 well"></div></div>');
}
// Gebäude zählen und in Array speichern
function countBuildings()
{
// alle Zählerstände der Gebäude auf 0 setzen
for (var i = 0; i <= 12; i++) {
buildingAmount[i] = 0;
}
// für jedes Gebäude, was in der Liste gefunden wird, +1 im Array buildingAmount rechnen
$('#building_list').find('.building_list_li').each(function(index, element) {
buildingAmount[$(element).attr('building_type_id')]++;
});
return buildingAmount;
}
// alle Fahrzeuge zählen und in Array speichern
function countCars()
{
// alle Zählerstände der Fahrzeuge auf 0 setzen
for (var i = 0; i <= 53; i++) {
carAmount[i] = 0;
}
// für jedes Fahrzeug, was in der Liste gefunden wird, +1 im Array carAmount rechnen
$('.building_list_vehicle_element').each(function(index, element) {
carAmount[$(element).find('a').attr('vehicle_type_id')]++;
});
return carAmount;
}
// alle verfügbaren Fahrzeuge zählen und in Array speichern
function countAvailableCars()
{
// alle Zählerstände der Fahrzeuge auf 0 setzen
for (var i = 0; i <= 53; i++) {
carAvailableAmount[i] = 0;
}
// für jedes Fahrzeug, was in der Liste gefunden wird und Status 1 oder 2 ist, +1 im Array carAvailableAmount rechnen
$('.building_list_vehicle_element').each(function(index, element) {
if ($(element).find('span').html() == "2") {
carAvailableAmount[$(element).find('a').attr('vehicle_type_id')]++;
}
});
return carAvailableAmount;
}
// gezählte Gebäude ausgeben
function showBuildingAmount()
{
var buildings = countBuildings();
$('#scriptBuildingAmount').append('<table class="table table-bordered table-condensed table-striped table-hover"><thead><tr><th>Gebäude</th><th>Anzahl</th></tr></thead><tbody id="scriptBuildingAmountTable"></tbody></table>');
for (var i = 0; i < buildings.length; i++) {
if (buildings[i] > 0) {
$('#scriptBuildingAmountTable').append('<tr><td>'+ buildingsById[i] +'</td><td>'+ buildings[i] +'</td></tr>');
}
}
}
// gezählte Fahrzeuge ausgeben
function showCarAmount()
{
var cars = countCars();
var carsAva = countAvailableCars();
$('#scriptCarAmount').append('<table class="table table-bordered table-condensed table-striped table-hover"><thead><tr><th>Fahrzeug</th><th>Anzahl</th><th>Verfügbar</th></tr></thead><tbody id="scriptCarAmountTable"></tbody></table>');
for (var i = 0; i < cars.length; i++) {
if (cars[i] > 0) {
$('#scriptCarAmountTable').append('<tr><td>'+ carsById[i] +'</td><td>'+ cars[i] +'</td><td>'+ carsAva[i] +'</td></tr>');
}
}
}
// Suchleiste für die Gebäudeübersicht erstellen
function showBuildingSearch()
{
$('#scriptBuildingAmount').append('<input id="scriptBuildingSearch" class="input-medium search-query" placeholder="Suchen" type="text"><br /><br />');
$('#scriptBuildingSearch').bind('keyup', function(e) {
var searchWord = $('#scriptBuildingSearch').val().toLowerCase();
$('#scriptBuildingAmountTable').find('tr').each(function(index, element) {
// zunächst die Zeile wieder sichtbar machen
$(element).show();
// nun die Zelle prüfen, ob der Suchbegriff vorhanden ist
if (!$(element).find('td:eq(0)').html().toLowerCase().match(searchWord)) {
$(element).hide();
}
});
});
}
// Suchleiste für die Fahrzeugübersicht erstellen
function showCarSearch()
{
$('#scriptCarAmount').append('<input id="scriptCarSearch" class="input-medium search-query" placeholder="Suchen" type="text"><br /><br />');
$('#scriptCarSearch').bind('keyup', function(e) {
var searchWord = $('#scriptCarSearch').val().toLowerCase();
$('#scriptCarAmountTable').find('tr').each(function(index, element) {
// zunächst die Zeile wieder sichtbar machen
$(element).show();
// nun die Zelle prüfen, ob der Suchbegriff vorhanden ist
if (!$(element).find('td:eq(0)').html().toLowerCase().match(searchWord)) {
$(element).hide();
}
});
});
}
// großes Logo ganz oben auf der Seite verstecken
function hideLogo()
{
$('.logo').parent().hide();
}
// Div "well" um die Einsatzliste setzen, damit es einheitlich aussieht
function restoreWellDiv()
{
$('#missions').addClass('well');
}
// Tabs bei Einsatzliste
function tabsForMissions()
{
// Bisherige Button ausblenden
$('#missions').find('.btn-group').hide();
$('#missions').find('h3').hide();
// Tabs erstellen
$('#mission_list').before('<div id="scriptMissionTab"><button type="button" id="scriptShowMenu" class="btn btn-mini" style="cursor:pointer">Menü</button></div><br />');
$('#scriptShowMenu').bind('click', function(e)
{
$('#scriptMissionMenu').slideToggle();
}
);
$('#scriptMissionTab').append('<div id="scriptMissionMenu" style="display:none"><br /><ul class="nav nav-tabs"><li class="active"><a href="#scriptEmergencies" data-toggle="tab">NF (<span id="scriptEmergencyCounter"></span>)</a></li><li><a href="#scriptTransports" data-toggle="tab">KTP (<span id="scriptTransportCounter"></span>)</a></li><li><a href="#scriptAlliances" data-toggle="tab">VE (<span id="scriptAllianceCounter"></span>)</a></li></ul><br /></div>');
$('#scriptMissionTab').append('<div class="tab-content" id="scriptTabContent"></div>');
var missionList = $('#mission_list').html();
$('#mission_list').remove();
$('#scriptTabContent').append('<div class="tab-pane active" id="scriptEmergencies"><ul id="mission_list">'+ missionList +'</ul></div>');
var missionListKrankentransporte = $('#mission_list_krankentransporte').html();
$('#mission_list_krankentransporte').remove();
$('#scriptTabContent').append('<div class="tab-pane" id="scriptTransports"><ul id="mission_list_krankentransporte">'+ missionListKrankentransporte +'</ul></div>');
var missionListAlliance = $('#mission_list_alliance').html();
$('#mission_list_alliance').remove();
$('#scriptTabContent').append('<div class="tab-pane" id="scriptAlliances"><ul id="mission_list_alliance">'+ missionListAlliance +'</ul></div>');
}
// Suchleiste für Wachenliste
function showStationSearch()
{
$('#buildings').find('h3').before('<input id="scriptStationSearch" class="input-medium search-query" placeholder="Suchen" type="text"><br /><br />');
$('#buildings').find('h3').hide();
$('#scriptStationSearch').bind('keyup', function(e) {
var searchWord = $('#scriptStationSearch').val().toLowerCase();
$('#building_list').find('.map_position_mover').each(function(index, element) {
// zunächst die Wache wieder sichtbar machen
$(element).parent().parent().show();
// nun den Namen prüfen, ob der Suchbegriff vorhanden ist
if (!$(element).html().toLowerCase().match(searchWord)) {
$(element).parent().parent().hide();
}
});
});
}
// Suchleiste für Verbandschat
function showChatSearch()
{
$('#alliance_chat').find('h3').before('<input id="scriptChatSearch" class="input-medium search-query" placeholder="Suchen" type="text"><br /><br />');
$('#alliance_chat').find('h3').hide();
$('#scriptChatSearch').bind('keyup', function(e) {
var searchWord = $('#scriptChatSearch').val().toLowerCase();
$('#mission_chat_messages').find('li').each(function(index, element) {
// zunächst die Wache wieder sichtbar machen
$(element).show();
// nun den Namen prüfen, ob der Suchbegriff vorhanden ist
if (!$(element).html().toLowerCase().match(searchWord)) {
$(element).hide();
}
});
});
}
// Falls es Sprechwünsche gibt, soll der Titel des Tabs geändert werden
function changeTabTitleByCall()
{
if ($('#radio_messages_important').children().length > 0) {
document.title = "Sprechwunsch!";
} else {
document.title = "LEITSTELLENSPIEL.DE - baue deine eigene Leitstelle, in deiner Stadt!";
}
}
// Einsatzzahlen in den Einsatztabs anzeigen
function showMissionCounterInTab()
{
$('#scriptEmergencyCounter').html($('#missions').find('.btn-group').find('a:eq(0)').html().replace(')', '').split('(')[1]);
$('#scriptTransportCounter').html($('#missions').find('.btn-group').find('a:eq(1)').html().replace(')', '').split('(')[1]);
$('#scriptAllianceCounter').html($('#missions').find('.btn-group').find('a:eq(2)').html().replace(')', '').split('(')[1]);
}
// Patienten zählen und anzeigen
function countPatients()
{
var patientsAmount = 0; // Patienten gesamt
var patientsTreatment = 0; // Patienten in Behandlung
var patientsReady = 0; // Patienten transportbereit
patientsAmount = $('#mission_list').find('.patient_progress:visible').length;
patientsTreatment = $('#mission_list').find('.patient_progress.active:visible').length;
patientsReady = $('#mission_list').find('.patient_progress').find('.bar-success').length;
$('#scriptPatientsCounter').remove();
$('#scriptMissionMenu').append('<small id="scriptPatientsCounter">Pat.: '+ patientsAmount +' insg., '+ patientsTreatment +' in Behandlung, '+ patientsReady +' transpf.</small>');
}
// Fahrzeugtypen statt Name bei Klick auf Button
function showCarTypesInsteadOfStation()
{
// Button neben dem ersten "Alarmieren"-Button erstellen
$('#missionH1').after('<button type="button" id="scriptShowCarTypes" class="btn btn-info btn-mini">Fzg.-Typen anzeigen</button>');
$('#scriptShowCarTypes').bind('click', function(e)
{
$('td[vehicle_type_id]').each(function(ind, tdEl)
{
$(tdEl).parent().find('td:eq(2)').html(carsById[$(tdEl).attr('vehicle_type_id')]);
}
);
$('a[vehicle_type_id]').each(function(ind, aEl)
{
$(aEl).html(carsById[$(aEl).attr('vehicle_type_id')]);
}
);
}
)
}
function useEasyHotkeys() {
$(document).on('keydown', function(e) {
var keynum;
if(window.event) {
keynum = e.keyCode;
} else {
keynum = e.which
}
var hotkey = String.fromCharCode(keynum).trim();
if($('#mission_reply_content').is(':focus')) {
return;
}
if(hotkey != " " && hotkey != "") {
$('[accesskey='+ hotkey +']').click();
}
});
}