| 1 | /* |
|---|
| 2 | function loadXMLDoc() |
|---|
| 3 | { |
|---|
| 4 | if (window.XMLHttpRequest) |
|---|
| 5 | { |
|---|
| 6 | xmlhttp = new XMLHttpRequest(); |
|---|
| 7 | } |
|---|
| 8 | else |
|---|
| 9 | { |
|---|
| 10 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | xmlhttp.onreadystatechange=function() |
|---|
| 14 | { |
|---|
| 15 | if (xmlhttp.readyState==4 && xmlhttp.status==200) |
|---|
| 16 | { |
|---|
| 17 | document.getElementById("myDiv").innerHTML = xmlhttp.responseText; |
|---|
| 18 | } |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | xmlhttp.open("GET", "ajax_info.txt", true); |
|---|
| 22 | xmlhttp.send(""); |
|---|
| 23 | } |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | /** |
|---|
| 27 | * Sets the selected tab to the summary tab and loads the summary page. |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | function setupNotebook() |
|---|
| 31 | { |
|---|
| 32 | console.log("setupNotebook() starting"); |
|---|
| 33 | changeTab('summaryTab'); |
|---|
| 34 | showContent('summaryPageContent') |
|---|
| 35 | loadSummary(); |
|---|
| 36 | setCookie("time", "0"); |
|---|
| 37 | setCookie("scriptScrollY", 0); |
|---|
| 38 | setCookie("summaryScrollY", 0); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * Runs the script. |
|---|
| 43 | */ |
|---|
| 44 | function run() |
|---|
| 45 | { |
|---|
| 46 | run.initialDelay = 1000; |
|---|
| 47 | |
|---|
| 48 | setTimeout("run.run()", run.initialDelay); |
|---|
| 49 | |
|---|
| 50 | run.run = function() |
|---|
| 51 | { |
|---|
| 52 | // document.getElementById("simulationStatus").innerHTML = "RUNNING"; |
|---|
| 53 | setTime(); |
|---|
| 54 | updateStatus(); |
|---|
| 55 | }; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * Displays fading text alerts in the status box (left-top corner). |
|---|
| 60 | */ |
|---|
| 61 | function updateStatus() |
|---|
| 62 | { |
|---|
| 63 | // IF last event if it has not been set before THEN |
|---|
| 64 | if (typeof updateStatus.lastEvent == 'undefined') |
|---|
| 65 | { |
|---|
| 66 | updateStatus.lastEvent = null; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | var latestEvent = events.getLastExecutedEvent(readCookie("time")); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | // IF a new event executed THEN |
|---|
| 73 | if (updateStatus.lastEvent != latestEvent) |
|---|
| 74 | { |
|---|
| 75 | // IF the new event has evaluations THEN |
|---|
| 76 | if (latestEvent.evaluations.evaluations.length == 0) |
|---|
| 77 | { |
|---|
| 78 | // document.getElementById('updateStatus').innerHTML = "New Event"; |
|---|
| 79 | } |
|---|
| 80 | else |
|---|
| 81 | { |
|---|
| 82 | // document.getElementById('updateStatus').innerHTML = "New Evaluation"; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | // fades the text |
|---|
| 86 | updateStatus.fade = function fade() |
|---|
| 87 | { |
|---|
| 88 | // IF the fade color is not black yet THEN |
|---|
| 89 | if (fade.hex < 255) |
|---|
| 90 | { |
|---|
| 91 | fade.hex += 5; |
|---|
| 92 | // document.getElementById('updateStatus').style.color = |
|---|
| 93 | "rgb(" + fade.hex + ", " + fade.hex + ", " + fade.hex + ")"; |
|---|
| 94 | setTimeout("updateStatus.fade()", 100); |
|---|
| 95 | } |
|---|
| 96 | else |
|---|
| 97 | { |
|---|
| 98 | // document.getElementById('updateStatus').style.color = "white"; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | }; |
|---|
| 102 | |
|---|
| 103 | updateStatus.fade.hex = 0; |
|---|
| 104 | updateStatus.fade(); |
|---|
| 105 | updateStatus.lastEvent = latestEvent; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | setTimeout("updateStatus();", 1000); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Sets 'simulationTime' to the current simulation time in seconds. |
|---|
| 113 | * This method runs itself every second to keep the time current. |
|---|
| 114 | * Sets the cookie 'time' to the value of 'simulationTime'. |
|---|
| 115 | * @return |
|---|
| 116 | */ |
|---|
| 117 | function setTime() |
|---|
| 118 | { |
|---|
| 119 | /** Load the sim time file and extract the seconds */ |
|---|
| 120 | loadJSON("../dynamicdata/sim_elapsedtime.json", function(response) |
|---|
| 121 | { |
|---|
| 122 | try { |
|---|
| 123 | simclockjson = JSON.parse(response); |
|---|
| 124 | seconds = simclockjson.elapsedtime; |
|---|
| 125 | setTime.time = seconds; |
|---|
| 126 | // increment time by one second (or initialize it if it has not been set before) |
|---|
| 127 | // setTime.time = (typeof setTime.time == 'undefined') ? 0 : ++setTime.time; |
|---|
| 128 | |
|---|
| 129 | setCookie("time", "" + setTime.time); |
|---|
| 130 | |
|---|
| 131 | // display the latest simulation time |
|---|
| 132 | document.getElementById("simulationTime").innerHTML = |
|---|
| 133 | Time.formatTime(setTime.time); |
|---|
| 134 | } catch(e) { |
|---|
| 135 | console.log("Error attempt to parse sim_elapsedtime.json: "+response) |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | setTimeout("setTime()", 1000); |
|---|
| 139 | }); |
|---|
| 140 | } |
|---|
| 141 | /** |
|---|
| 142 | * Selects a new tab to be viewed. |
|---|
| 143 | * @param id The id for the tab to be selected |
|---|
| 144 | */ |
|---|
| 145 | function changeTab(id) |
|---|
| 146 | { |
|---|
| 147 | /* Set all tabs to not being active */ |
|---|
| 148 | document.getElementById("summaryTab").className = "notActive"; |
|---|
| 149 | document.getElementById("scriptTab").className = "notActive"; |
|---|
| 150 | document.getElementById("CADTab").className = "notActive"; |
|---|
| 151 | document.getElementById("mapsTab").className = "notActive"; |
|---|
| 152 | |
|---|
| 153 | /* Set the selected tab to being active */ |
|---|
| 154 | document.getElementById(id).className = "activeTab"; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | /** |
|---|
| 158 | * Loads the script tab page; |
|---|
| 159 | */ |
|---|
| 160 | function loadScript() |
|---|
| 161 | { |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | /** |
|---|
| 165 | * Loads the summary tab page; |
|---|
| 166 | */ |
|---|
| 167 | function loadSummary() |
|---|
| 168 | { |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | /** |
|---|
| 172 | * @param id The id of the frame element. |
|---|
| 173 | * @return The document of the frame element. |
|---|
| 174 | */ |
|---|
| 175 | function getDocumentFromFrame(id) |
|---|
| 176 | { |
|---|
| 177 | var frame=document.getElementById(id); |
|---|
| 178 | var doc=(frame.contentWindow || frame.contentDocument); |
|---|
| 179 | |
|---|
| 180 | if (doc.document)doc=doc.document; |
|---|
| 181 | |
|---|
| 182 | return doc; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | /** |
|---|
| 186 | * Hides a tab page |
|---|
| 187 | * @param d The div of the page to hide. |
|---|
| 188 | */ |
|---|
| 189 | function hideContent(d) |
|---|
| 190 | { |
|---|
| 191 | document.getElementById(d).style.display = "none"; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | /** |
|---|
| 195 | * Switches the tab page. |
|---|
| 196 | * @param d The div of the page to show. |
|---|
| 197 | */ |
|---|
| 198 | function showContent(d) |
|---|
| 199 | { |
|---|
| 200 | hideContent('summaryPageContent'); |
|---|
| 201 | hideContent('scriptPageContent'); |
|---|
| 202 | hideContent('cadPageContent'); |
|---|
| 203 | hideContent('mapsPageContent'); |
|---|
| 204 | document.getElementById(d).style.display = "block"; |
|---|
| 205 | } |
|---|