source: tmcsimulator/trunk/webapps/EInotebook/notebook.js @ 359

Revision 359, 5.3 KB checked in by jdalbey, 7 years ago (diff)

Add EINotebook source

  • Property svn:executable set to *
Line 
1/*
2function 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
30function setupNotebook()
31{
32   changeTab('summaryTab');
33   showContent('summaryPageContent')
34   loadSummary();
35   setCookie("time", "0");
36   setCookie("scriptScrollY", 0);
37   setCookie("summaryScrollY", 0);
38}
39
40/**
41 * Runs the script.
42 */
43function run()
44{
45        run.initialDelay = 1000;
46       
47        setTimeout("run.run()", run.initialDelay);
48       
49        run.run = function()
50        {
51//          document.getElementById("simulationStatus").innerHTML = "RUNNING";                 
52                setTime();
53                updateStatus();
54        };
55}
56
57/**
58 * Displays fading text alerts in the status box (left-top corner).
59 */
60function updateStatus()
61{
62        // IF last event if it has not been set before THEN
63    if (typeof updateStatus.lastEvent == 'undefined')
64    {
65        updateStatus.lastEvent = null;
66    }
67   
68    var latestEvent = events.getLastExecutedEvent(readCookie("time"));
69   
70   
71    // IF a new event executed THEN
72    if (updateStatus.lastEvent != latestEvent)
73    {
74                // IF the new event has evaluations THEN
75        if (latestEvent.evaluations.evaluations.length == 0)
76        {
77//              document.getElementById('updateStatus').innerHTML = "New Event";
78        }
79        else
80        {
81//              document.getElementById('updateStatus').innerHTML = "New Evaluation";
82        }
83       
84                // fades the text
85                updateStatus.fade = function fade()
86                {
87                        // IF the fade color is not black yet THEN
88                if (fade.hex < 255)
89                {
90                        fade.hex += 5;
91//                      document.getElementById('updateStatus').style.color =
92                                "rgb(" + fade.hex + ", " + fade.hex + ", " + fade.hex + ")"; 
93                        setTimeout("updateStatus.fade()", 100); 
94                }
95                else
96                {
97//                      document.getElementById('updateStatus').style.color = "white";
98                }
99
100                };
101       
102                updateStatus.fade.hex = 0;
103                updateStatus.fade();
104        updateStatus.lastEvent = latestEvent;
105    }
106   
107    setTimeout("updateStatus();", 1000);
108}
109
110/**
111 * Sets 'simulationTime' to the current simulation time in seconds.
112 * This method runs itself every second to keep the time current.
113 * Sets the cookie 'time' to the value of 'simulationTime'.
114 * @return
115 */
116function setTime()
117{
118    /** Load the sim time file and extract the seconds */
119    loadJSON("../sim_elapsedtime.json", function(response)
120    {
121        try {
122            simclockjson = JSON.parse(response);
123            seconds = simclockjson.elapsedtime;
124            setTime.time = seconds;
125                // increment time by one second (or initialize it if it has not been set before)
126    //      setTime.time = (typeof setTime.time == 'undefined') ? 0 : ++setTime.time;
127
128            setCookie("time", "" + setTime.time);
129           
130                // display the latest simulation time
131                document.getElementById("simulationTime").innerHTML = 
132                        Time.formatTime(setTime.time);
133        } catch(e) {
134            console.log("Error attempt to parse sim_elapsedtime.json: "+response)
135        }
136           
137        setTimeout("setTime()", 1000);
138    });
139}
140// Load the dynamic json file for highways, etc.
141function loadJSON(inFile, callback)
142{
143    var xobj = new XMLHttpRequest();
144    // Assume XML unless filename ends with .json
145    if (inFile.endsWith(".json"))
146    {
147        xobj.overrideMimeType("application/json");
148    }
149    xobj.open('GET', inFile, true);
150    xobj.onreadystatechange = function()
151    {
152        if (xobj.readyState == 4 && xobj.status == "200")
153        {
154            callback(xobj.responseText);
155        }
156    };
157    // We want ajax to ignore any cached responses
158    xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT')
159    xobj.send(null);
160}
161/**
162 * Selects a new tab to be viewed.
163 * @param id The id for the tab to be selected
164 */
165function changeTab(id)
166{
167    /* Set all tabs to not being active */
168    document.getElementById("summaryTab").className = "notActive";
169    document.getElementById("scriptTab").className = "notActive";
170    document.getElementById("CADTab").className = "notActive";
171    document.getElementById("mapsTab").className = "notActive";
172
173    /* Set the selected tab to being active */
174    document.getElementById(id).className = "activeTab";
175}
176
177/**
178 * Loads the script tab page;
179 */
180function loadScript()
181{
182}
183
184/**
185 * Loads the summary tab page;
186 */
187function loadSummary()
188{         
189}
190
191/**
192 * @param id The id of the frame element.
193 * @return The document of the frame element.
194 */
195function getDocumentFromFrame(id)
196{
197    var frame=document.getElementById(id);
198    var doc=(frame.contentWindow || frame.contentDocument);
199   
200    if (doc.document)doc=doc.document;
201   
202    return doc;
203}
204
205/**
206 * Hides a tab page
207 * @param d The div of the page to hide.
208 */
209function hideContent(d) 
210{
211    document.getElementById(d).style.display = "none";
212}
213
214/**
215 * Switches the tab page.
216 * @param d The div of the page to show.
217 */
218function showContent(d) 
219{
220    hideContent('summaryPageContent');
221    hideContent('scriptPageContent');
222    hideContent('cadPageContent');
223    hideContent('mapsPageContent');   
224    document.getElementById(d).style.display = "block"; 
225}
Note: See TracBrowser for help on using the repository browser.