-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathksaEventOps.js
182 lines (158 loc) · 8.01 KB
/
ksaEventOps.js
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
// refactor complete (for launch events only)
function loadEventsAJAX(xhttp) {
strCurrentLaunchVessel = "";
strCurrentManeuverVessel = "";
// stop both spinners
$("#launch").spin(false);
$("#maneuver").spin(false);
// separate the launch & maneuver event returns
var events = xhttp.responseText.split("^");
// is there an upcoming launch?
var launches = events[0].split("|");
if (launches[0] != "null") {
// load the launches into a list, already sorted by name and UT
var launchEventList = [];
var firstLaunchTime = 9999999999;
launches.forEach(function(launchEvent) {
var launchDetails = launchEvent.split(";");
launchEventList.push({UT: parseFloat(launchDetails[0]),
LaunchTime: parseFloat(launchDetails[1]),
db: launchDetails[2],
Title: launchDetails[3],
Desc: launchDetails[4]
});
// decide if this vessel still has yet to launch and is launching first
if (strCurrentLaunchVessel != launchDetails[2] && launchDetails[1] < firstLaunchTime && launchDetails[1] > currUT()) {
strCurrentLaunchVessel = launchDetails[2];
firstLaunchTime = launchDetails[1];
}
});
// find the current launch event attributed to the launch vessel, if there is one that still hasn't launched
var launchData = null;
if (strCurrentLaunchVessel.length) {
launchEventList.forEach(function(vessel) {
if (vessel.UT <= currUT() && vessel.db == strCurrentLaunchVessel &&
(vessel.LaunchTime > currUT() || vessel.LaunchTime == vessel.UT)) // also check that this is a hold
launchData = vessel;
});
}
writeLaunchInfo(launchData);
// find the next update attributed to the launch vessel
launchEventList.forEach(function(vessel) {
if (vessel.UT > currUT() && vessel.db == strCurrentLaunchVessel && ops.updatesList.length == ops.updatesListSize) {
ops.updatesList.push({ type: "event", UT: vessel.UT });
}
});
// if we didn't find a future update for the current launch vehicle, try to find any future update
if (ops.updatesList.length == ops.updatesListSize) {
launchEventList.forEach(function(vessel) {
if (vessel.UT > currUT() && ops.updatesList.length == ops.updatesListSize) {
ops.updatesList.push({ type: "event", UT: vessel.UT });
}
});
}
} else writeLaunchInfo();
// is there an upcoming maneuver?
var maneuvers = events[1].split("|");
if (maneuvers[0] != "null") {
// to be completed once the launch selection works as intended
} else writeManeuverinfo();
// do the menu load after events load so the event box is always sized before the menu
if (!isMenuDataLoaded) loadDB("loadMenuData.asp?UT=" + currUT(), loadMenuAJAX);
// if this is a crew page, no need to wait for GGB to load
if (ops.pageType.includes("crew")) activateEventLinks();
}
function writeLaunchInfo(data) {
var size = w2utils.getSize("#launch", 'height');
var currHTML = $("#launch").html();
if (data) {
var strHTML = "<strong>Next Launch</strong><br>";
strHTML += "<span id='launchLink' db='" + data.db + "'>" + wrapText(100, data.Title, 16) + "</span><br>";
// regular launch, or hold event?
if (data.LaunchTime != data.UT) {
strHTML += "<span id='launchTime'>" + UTtoDateTime(data.LaunchTime, true, false) + "</span><br>"
strHTML += "<span id='launchCountdown'>" + formatTime(data.LaunchTime - currUT()) + "</span>";
launchCountdown = data.LaunchTime;
} else {
strHTML += "<span id='launchTime'>COUNTDOWN HOLD</span><br><span id='launchCountdown'>Awaiting new L-0 time</span>";
launchCountdown = "null";
// if we are actively viewing the vessel, update the launch text
if (ops.currentVessel && ops.currentVessel.Catalog.DB == strCurrentLaunchVessel && ops.pageType == "vessel") {
flashUpdate("#dataField0", "#77C6FF", "#FFF");
$("#dataField0").html("<b>" + ops.currentVessel.CraftData.MissionStartTerm + ":</b><span style='cursor:help' class='tip-update' data-tipped-options=\"inline: 'metTip', maxWidth: 300\"> <u>To Be Determined</u>");
$("#metTip").html("launch time currently being assessed");
if (is_touch_device()) { showOpt = 'click'; }
else { showOpt = 'mouseenter'; }
Tipped.create('.tip-update', { showOn: showOpt, hideOnClickOutside: is_touch_device(), detach: false, hideOn: {element: 'mouseleave'} });
}
}
$("#launch").html(strHTML);
// add an info tooltip
Tipped.create("#launchLink", data.Desc, { offset: { y: -10 }, maxWidth: 150, position: 'top' });
} else $("#launch").html("<strong>Next Launch</strong><br>None Scheduled");
// if there was a change in height with the new text update the box using the default size with no launches or maneuvers
// make sure we don't shrink smaller than the maneuver text
if (size != w2utils.getSize("#launch", 'height')) {
size = w2utils.getSize("#launch", 'height');
if (size < w2utils.getSize("#maneuver", 'height')) size = w2utils.getSize("#maneuver", 'height');
$("#eventBox").css("height", (37 + size) + "px");
$('#menuBox').css("height", (ops.maxMenuHeight - w2utils.getSize("#eventBox", 'height')) + "px");
setTimeout(function() {
if (isMenuDataLoaded) {
w2ui['menu'].refresh();
if (w2ui['menu'].find({selected: true}).length) w2ui['menu'].scrollIntoView(w2ui['menu'].find({selected: true})[0].id);
}
}, 250);
}
// if the menu data is already loaded this was a refresh, so highlight the box and activate the links
// also check if any change has been made to the contents
if (isMenuDataLoaded && data && currHTML != $("#launch").html()) {
flashUpdate("#launch", "#FF0000", "#77C6FF");
activateEventLinks();
}
}
function writeManeuverinfo(data) {
var size = w2utils.getSize("#maneuver", 'height');
var currHTML = $("#maneuver").html();
if (data) {
var fields = data.split(";");
strHTML = "<strong>Next Maneuver</strong><br>";
strHTML += "<span id='manueverLink' db='" + fields[2] + "'>" + wrapText(150, fields[3], 16) + "</span><br>";
strCurrentManeuverVessel = fields[2];
strHTML += "<span id='maneuverTime'>" + UTtoDateTime(parseFloat(fields[1]), true, false) + "</span><br>"
strHTML += "<span id='maneuverCountdown'>" + formatTime(parseFloat(fields[1]) - (currUT())) + "</span>";
maneuverCountdown = parseFloat(data[1]);
$("#maneuver").html(strHTML);
// add an info tooltip
Tipped.create("#maneuverLink", fields[4], { offset: { y: -10 }, maxWidth: 150, position: 'top' });
} else $("#maneuver").html("<strong>Next Maneuver</strong><br>None Scheduled");
if (size != w2utils.getSize("#maneuver", 'height')) {
size = w2utils.getSize("#maneuver", 'height');
if (size < w2utils.getSize("#launch", 'height')) size = w2utils.getSize("#launch", 'height');
$("#eventBox").css("height", (37 + size) + "px");
$('#menuBox').css("height", (ops.maxMenuHeight - w2utils.getSize("#eventBox", 'height')) + "px");
setTimeout(function() {
if (isMenuDataLoaded) {
w2ui['menu'].refresh();
if (w2ui['menu'].find({selected: true}).length) w2ui['menu'].scrollIntoView(w2ui['menu'].find({selected: true})[0].id);
}
}, 250);
}
// if the menu data is already loaded this was a refresh, so highlight the box and activate the links
// also check if any change has been made to the contents
if (isMenuDataLoaded && data && currHTML != $("#maneuver").html()) {
flashUpdate("#maneuver", "#FF0000", "#77C6FF");
activateEventLinks();
}
}
// called once the GGB figure is done loading so switching to a vessel doesn't cut off the load
function activateEventLinks() {
$("#manueverLink").addClass("fauxLink");
$("#manueverLink").click(function() {
swapContent('vessel', $("#manueverLink").attr("db"));
});
$("#launchLink").addClass("fauxLink");
$("#launchLink").click(function() {
swapContent('vessel', $("#launchLink").attr("db"));
});
}