source: tmcsimulator/trunk/webapps/einotebook/notebook.js @ 540

Revision 540, 3.5 KB checked in by jdalbey, 6 years ago (diff)

Add roles page to EINotebook, version 1. Modified index.html, Event.js, LoadEvents?.js, notebook.js

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