This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
348 lines (287 loc) · 9.68 KB
/
Copy pathapp.js
File metadata and controls
348 lines (287 loc) · 9.68 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
$(function () {
UI.registerEventHandlers();
initialize();
try {
Data.state.data_client = new Faye.Client(Data.config.data_client.url);
Data.state.data_client.subscribe('/events', function(event) {
EventHandler.dispatchEvents([event]);
});
Data.config.data_client.connected = true;
log('Connected to local data client...');
} catch(err) {
log('Unable to connect to local data client...');
}
UI.data_client_check();
});
function initialize() {
log('Init...');
stopPolling();
MemberList.clear();
HostileList.clear();
EventList.clear();
ScanList.clear();
Data.load_ships();
Data.load_wormhole_types();
UIPanels.showLoadingPanel(false, function () {
Server.status(function(error, data) {
if (error) {
handleError(error);
if (error.type == 'igb-headers') {
Util.redirectToLoginPath();
} else {
UIPanels.showStartPanel(error);
}
if (error.type === 'trust') {
CCPEVE.requestTrust(location.protocol + '//' + location.hostname);
}
return;
}
Data.populate(function() {
SystemMap.init();
EventHandler.dispatchEvents(data.events);
});
if (Data.state.fleet.key) {
EventList.addEvent({ type: 'youJoined', text: 'You opened this standing fleet', alert: false });
Util.redirectIfNecessary(Data.state.fleet.key, function () {
UIPanels.hidePanel(pollLoop);
});
} else {
if (Util.getUrlKey()) {
joinFleet(Util.getUrlKey());
} else {
UIPanels.showStartPanel();
}
}
});
})
}
function createFleetButtonClick(button) {
var fleetName = $('#create-fleet-name').val();
var fleetPassword = $('#create-fleet-password').val();
createFleet(fleetName, fleetPassword);
}
function createFleet(fleetName, fleetPassword) {
UIPanels.showLoadingPanel('Creating new fleet...', function () {
Server.createFleet(fleetName, fleetPassword, function(error, data) {
if (error) {
UIPanels.showCreatePanel(error);
return;
}
initialize();
});
});
}
function joinFleetButtonClick(button) {
var fleetKey = $('#join-fleet-key').val();
joinFleet(fleetKey);
}
function joinFleet(fleetKey) {
UIPanels.showLoadingPanel('Searching for fleet...', function () {
Server.joinFleet(fleetKey, function(error, data) {
Data.state.fleet.key = fleetKey;
if (error) {
if (error.type === 'password') UIPanels.showPasswordPanel();
else UIPanels.showJoinPanel(error);
return;
}
initialize();
});
});
}
function submitPasswordButtonClick(button) {
var fleetPassword = $('#join-fleet-password').val();
submitPassword(fleetPassword);
}
function submitPassword(fleetPassword) {
var fleetKey = Util.getUrlKey();
if (!fleetKey) fleetKey = Data.state.fleet.key;
UIPanels.showLoadingPanel('Authenticating...', function () {
Server.joinFleetWithPassword(fleetKey, fleetPassword, function (error, data) {
if (error) {
if (error.type === 'password') UIPanels.showPasswordPanel(error);
else UIPanels.showJoinPanel(error);
return;
}
initialize();
});
});
}
function submitScanButtonClick(button) {
var scanData = $('#scan-data').val();
submitScan(scanData);
}
function submitScan(scanData) {
UIPanels.showLoadingPanel('Uploading scan...', function () {
var parsedScanData = ScanList.parse(scanData);
Server.postScan(parsedScanData, function(error, data) {
UIPanels.hidePanel(function () {
if (error) {
handleError(error);
return;
}
EventList.addEvent({ type: 'info', text: 'Scan was uploaded...', alert: true });
});
});
});
}
function scanFilter(button, filter) {
var results = $(button).closest('.scan').find('.type-classes .result')
$(button).closest('ul').find('.btn').removeClass('active');
results.removeClass('selected');
$(button).addClass('active');
$.each(results, function(i, result) {
if ($(result).find('.details-container .distance:contains("-")').length) {
if (filter === 'offgrid') $(result).addClass('selected');
} else {
if (filter === 'grid') $(result).addClass('selected');
}
})
}
function submitStatusButtonClick(button) {
var scanData = $('#status-data').val();
submitStatus("validate", scanData);
}
function submitStatus(reported_status, pilots) {
UIPanels.showLoadingPanel('Uploading status...', function () {
var status = ScanList.addStatus(reported_status, pilots);
Server.postStatus(status, function(error, data) {
UIPanels.hidePanel(function () {
if (error) {
handleError(error);
return;
}
EventList.addEvent({ type: 'info', class: status.text,
text: 'Status was reported on <strong>' +
'<a href="javascript:CCPEVE.showInfo(5, ' + status.systemId + ')">' +
status.systemName + '</a> by you.' });
});
});
});
}
function submitSourcedStatus(status) {
Server.postStatus(status, function(error, data) {
if (error) {
handleError(error);
return;
}
EventList.addEvent({ type: 'info', class: status.text,
text: 'Status was reported on <strong>' +
'<a href="javascript:CCPEVE.showInfo(5, ' + status.systemId + ')">' +
status.systemName + '</a> from your desktop client.' });
});
}
function submitHostileDetailsClick(button) {
var hostile = {'key': $('#hostile-key').val(),
'type': 'hostile',
'characterId': $('#hostile-id').val(),
'characterName': $('#hostile-name').val(),
'shipType': $('#hostile-ship-type').val(),
'systemName': $('#hostile-system-name').val(),
'systemId': $('#hostile-system-id').val(),
'is_docked': $('#hostile-is-docked').is(':checked')
}
submitHostileDetails(hostile);
}
function submitHostileDetails(hostile) {
UIPanels.showLoadingPanel('Uploading status...', function () {
Server.postDetails(hostile, function(error, data) {
UIPanels.hidePanel(function () {
if (error) {
handleError(error);
return;
}
EventList.addEvent({ type: 'info', class: status.text,
text: 'Details were reported on <strong>' +
'<a href="javascript:CCPEVE.showInfo(1377, ' + hostile.characterId + ')">' +
hostile.characterName + '</a> by you.' });
});
});
});
}
function reportAdvisory(button, systemId, type) {
var state = ! $( button ).hasClass('present');
var advisory = {systemId: systemId, type: type, state: state};
$(button).removeAttr('onclick');
Server.postAdvisory(advisory, function(error, data) {
if (error) {
handleError(error);
return;
}
EventList.addEvent({type: 'info', alert: true, text: 'Advisory reported on ' +
'<a href="javascript:CCPEVE.showInfo(5, ' + systemId + ')">' +
Data.systems[systemId].name + '</a> by you.'
});
});
}
function updateWormholeLink(button, from, to, data) {
var payload = {};
if (!data) {
payload.sig_a = $('#sig-a').val();
payload.sig_b = $('#sig-b').val();
payload.type_a = $('#type-a').val();
payload.type_b = $('#type-b').val();
payload.info = $('#wormhole-info').val();
UIPanels.hidePanel();
} else {
payload.info = data;
}
Server.postWormholeLinkUpdate(from, to, payload, function(error, data) {
if (error) {
handleError(error);
return;
}
EventList.addEvent({type: 'info',
alert: true,
text: 'Wormhole jump from ' +
'<a href="javascript:CCPEVE.showInfo(5, ' + from + ')">' + Data.systems[from].name + '</a> ' +
' to ' +
'<a href="javascript:CCPEVE.showInfo(5, ' + to + ')">' + Data.systems[to].name + '</a> ' +
' updated by you.'});
});
}
function leaveFleet() {
UIPanels.showLoadingPanel('Leaving Standing Fleet...', function () {
Server.leaveFleet(function(error, data) {
Util.redirectToBasePath();
});
});
}
function pollLoop() {
UI.startSpin();
Data.state.pollLoop = setTimeout(function() {
Server.poll(function (error, data) {
if (error) return handleError(error);
EventHandler.dispatchEvents(data.events);
UI.stopSpin();
});
pollLoop();
}, Data.config.pollInterval);
}
function stopPolling() {
clearTimeout(Data.state.pollLoop);
}
function handleError (error) {
log(error.message);
if (error.stopPoll) {
Data.poll = false;
stopPolling();
}
if (error.message) UI.showAlert({
type: 'error',
text: error.message
});
}
function log(message) {
if (!Data.config.log) { return; }
if (Data.config.log === 'events') {
EventList.addEvent({
type: 'info',
text: JSON.stringify(message)
});
} else if (Data.config.log === 'console') {
console.log('[' + moment().unix() + '] - ' + JSON.stringify(message));
}
}
$( window ).resize(function() {
UI.update_scrollables();
});