| 1 | /** |
|---|
| 2 | * Sets the selected tab to the summary tab and loads the summary page. |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | function setupNotebook() |
|---|
| 6 | { |
|---|
| 7 | console.log("setupNotebook() starting"); |
|---|
| 8 | changeTab('summaryTab'); // Initially show Summary tab |
|---|
| 9 | showContent('summaryPageContent') |
|---|
| 10 | loadSummaryPage(); |
|---|
| 11 | loadPages(); |
|---|
| 12 | setCookie("time", "0"); |
|---|
| 13 | setCookie("scriptScrollY", 0); |
|---|
| 14 | setCookie("summaryScrollY", 0); |
|---|
| 15 | run(); // start the script scrolling |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | /** |
|---|
| 19 | * Loads the summary tab page; |
|---|
| 20 | */ |
|---|
| 21 | function loadSummaryPage() |
|---|
| 22 | { |
|---|
| 23 | incidents.doc = getDocumentFromFrame('summaryTabPage'); |
|---|
| 24 | window.frames[0].loadSummary(incidents); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * Loads content of the pages for Simulation Script and Current Event |
|---|
| 29 | */ |
|---|
| 30 | function loadPages() |
|---|
| 31 | { |
|---|
| 32 | window.frames[1].loadScript(events, incidents); |
|---|
| 33 | window.frames[2].loadScript(events, incidents); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * Start scrolling the script in an infinite loop. |
|---|
| 38 | */ |
|---|
| 39 | function run() |
|---|
| 40 | { |
|---|
| 41 | run.initialDelay = 1000; |
|---|
| 42 | setTimeout("run.run()", run.initialDelay); |
|---|
| 43 | |
|---|
| 44 | run.run = function() |
|---|
| 45 | { |
|---|
| 46 | setTime(); |
|---|
| 47 | }; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * Sets 'simulationTime' to the current simulation time in seconds. |
|---|
| 52 | * This method runs itself every second to keep the time current. |
|---|
| 53 | * Sets the cookie 'time' to the value of 'simulationTime'. |
|---|
| 54 | * @return |
|---|
| 55 | */ |
|---|
| 56 | function setTime() |
|---|
| 57 | { |
|---|
| 58 | /** Load the sim time file and extract the seconds */ |
|---|
| 59 | loadJSON("../dynamicdata/sim_elapsedtime.json", function(response) |
|---|
| 60 | { |
|---|
| 61 | try { |
|---|
| 62 | simclockjson = JSON.parse(response); |
|---|
| 63 | seconds = simclockjson.elapsedtime; |
|---|
| 64 | setTime.time = seconds; |
|---|
| 65 | // increment time by one second (or initialize it if it has not been set before) |
|---|
| 66 | // setTime.time = (typeof setTime.time == 'undefined') ? 0 : ++setTime.time; |
|---|
| 67 | |
|---|
| 68 | setCookie("time", "" + setTime.time); |
|---|
| 69 | |
|---|
| 70 | // display the latest simulation time |
|---|
| 71 | document.getElementById("simulationTime").innerHTML = |
|---|
| 72 | Time.formatTime(setTime.time); |
|---|
| 73 | } catch(e) { |
|---|
| 74 | console.log("Error attempt to parse sim_elapsedtime.json: "+response) |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | setTimeout("setTime()", 1000); |
|---|
| 78 | }); |
|---|
| 79 | } |
|---|
| 80 | /** |
|---|
| 81 | * Selects a new tab to be viewed. |
|---|
| 82 | * @param id The id for the tab to be selected |
|---|
| 83 | */ |
|---|
| 84 | function changeTab(id) |
|---|
| 85 | { |
|---|
| 86 | /* Set all tabs to not being active */ |
|---|
| 87 | document.getElementById("summaryTab").className = "notActive"; |
|---|
| 88 | document.getElementById("scriptTab").className = "notActive"; |
|---|
| 89 | document.getElementById("currentTab").className = "notActive"; |
|---|
| 90 | document.getElementById("mapsTab").className = "notActive"; |
|---|
| 91 | |
|---|
| 92 | /* Set the selected tab to being active */ |
|---|
| 93 | document.getElementById(id).className = "activeTab"; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | /** |
|---|
| 97 | * @param id The id of the frame element. |
|---|
| 98 | * @return The document of the frame element. |
|---|
| 99 | */ |
|---|
| 100 | function getDocumentFromFrame(id) |
|---|
| 101 | { |
|---|
| 102 | var frame=document.getElementById(id); |
|---|
| 103 | var doc=(frame.contentWindow || frame.contentDocument); |
|---|
| 104 | |
|---|
| 105 | if (doc.document)doc=doc.document; |
|---|
| 106 | |
|---|
| 107 | return doc; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | * Hides a tab page |
|---|
| 112 | * @param d The div of the page to hide. |
|---|
| 113 | */ |
|---|
| 114 | function hideContent(d) |
|---|
| 115 | { |
|---|
| 116 | document.getElementById(d).style.display = "none"; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | /** |
|---|
| 120 | * Switches the tab page. |
|---|
| 121 | * @param d The div of the page to show. |
|---|
| 122 | */ |
|---|
| 123 | function showContent(d) |
|---|
| 124 | { |
|---|
| 125 | hideContent('summaryPageContent'); |
|---|
| 126 | hideContent('scriptPageContent'); |
|---|
| 127 | hideContent('currentEventPageContent'); |
|---|
| 128 | hideContent('mapsPageContent'); |
|---|
| 129 | document.getElementById(d).style.display = "block"; |
|---|
| 130 | } |
|---|