source: tmcsimulator/trunk/webapps/einotebook/script/script.js @ 401

Revision 401, 5.8 KB checked in by jdalbey, 7 years ago (diff)

Fix #149, #112. Add emphasis to timebox. Partial fix to highlighting problem. Use Scoreboard font in CMS monitor.

  • Property svn:executable set to *
Line 
1/**
2 * Holds references to the events and incidents.
3 */
4function Script()
5{
6        Script.events = null;
7        Script.incidents = null;
8}
9
10/**
11 * Scrolls to the last event executed based on time.
12 */
13function jumpToLastExecutedEvent()
14{       
15        var lastEvent = Script.events.getLastExecutedEvent(readCookie("time"));
16       
17        // IF a current event exists THEN
18        if (lastEvent != null)
19        {
20                lastEvent.focus();
21        }
22        else
23        {
24                alert("No events have been executed yet.");
25        }
26}
27
28/**
29 * Finds the Event that was last executed by based on time and highlights it.
30 * Removes highlighting from old events.
31 * @return
32 */
33function highlightLatestEvent() 
34{
35        var currentEvent = Script.events.getLastExecutedEvent(readCookie("time"));
36
37        // IF the old event is has not been set THEN
38        if (typeof highlightLatestEvent.oldEvent == 'undefined')
39        {
40                highlightLatestEvent.oldEvent = new Object();
41                highlightLatestEvent.oldEvent.id = Event.invalidID;
42        }
43       
44        // IF a current event exists THEN
45        if (currentEvent != null)
46        {
47                // IF there is a new current event THEN
48                if (highlightLatestEvent.oldEvent.id != currentEvent.id)
49                {
50                        currentEvent.highlight();
51                       
52                        // IF there was previously a current event THEN
53                        if (highlightLatestEvent.oldEvent.id != Event.invalidID && currentEvent.id != 0)
54                        {
55                                highlightLatestEvent.oldEvent.unhighlight();
56                        }
57                       
58                        highlightLatestEvent.oldEvent = currentEvent;                   
59                }
60        }
61
62    // Set timer to do this again in one second
63        setTimeout("highlightLatestEvent()", 1000);
64}
65
66
67/** Change color of text of expired events so they appear disabled.
68  * @param events The list of events
69  * @param currEvent The current event
70  */
71function greyOldEvents(events, currEvent)
72{
73          // Examine all events
74   for (var evtNum = 0; evtNum < events.length; evtNum++)
75   {
76                // Change color of those before current time and Event
77      if (events[evtNum].time.compareTo(currEvent.time) < 0 && currEvent.id != events[evtNum].id) 
78      {
79                        events[evtNum].unhighlight();
80      }
81        }
82}
83
84/**
85 * Loads the the script tab for the given document.
86 * @pre script.html must be completely loaded
87 * @param aDocument
88 */
89function loadScript(theEvents, theIncidents)
90{
91        Script.incidents = theIncidents;
92        Script.events = theEvents;
93        Script.events.win = document.getElementById("view").contentWindow;
94        Script.events.doc = getDocumentFromFrame('view');
95
96        var html = "";
97       
98        // FOR each Event
99        for (var i = 0; i < Script.events.length; i++)
100        {
101                // add the Event's html
102                html += Script.events[i].html();
103        }
104       
105       
106        // display events in iframe
107        getDocumentFromFrame('view').body.innerHTML = html;     
108       
109        // resize iframe to appropriate height
110        resizeIframe();
111        window.onresize = resizeIframe;
112    // This line is causing an error
113        //window.frames['view'].setEvents(Script.events);
114       
115        Script.events.win.scrollTo(0, readCookie('scriptScrollY'));
116       
117        greyOldEvents(Script.events, Script.events.getLastExecutedEvent(readCookie("time")));
118        highlightLatestEvent();
119
120}
121
122/**
123 * @param id The id of the frame element.
124 * @return The document of the frame element.
125 */
126function getDocumentFromFrame(id)
127{
128    var frame=document.getElementById(id);
129    var doc=(frame.contentWindow || frame.contentDocument);
130   
131    if (doc.document)doc=doc.document;
132   
133    return doc;
134}
135
136/**
137 * Finds the height of an element relative to the BODY tag.
138 * @param elem The element to find the height of.
139 * @return The y-coordinate of the given element relative to the BODY tag.
140 */
141function pageY(elem) 
142{
143    return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
144}
145
146/**
147 * Resizes the view for the events so that the view's height is at the bottom of its
148 * container.
149 */
150function resizeIframe() 
151{
152    var height = document.documentElement.clientHeight;
153    height -= pageY(document.getElementById('view'));
154    height = (height < 0) ? 0 : height - 10;
155    document.getElementById('view').style.height = height + 'px';
156}
157
158/**
159 * Highlights the text of an input text element after a small delay.
160 * This method was made because using the code "onFocus='this.focus()'" did not work.
161 * @pre textField must have an 'id' attribute
162 * @param textField An input text element.
163 */
164function highlightTextField(textField)
165{
166        setTimeout("document.getElementById('" + textField.id + "').select();", 100);
167}
168
169/**
170 * Formats a two digit textbox. If the text box contains only one digit, then a zero
171 * is appended to the front.
172 * @param textField An input text element.
173 */
174function formatTimeTextfield(textField)
175{
176        // IF the text field contains 1 digits THEN
177        if (textField.value.length == 1)
178        {
179                textField.value = "0".concat(textField.value);
180        }
181}
182
183/**
184 * Scrolls to the event latest executed event if the current simulation time was given
185 * by text fields 'timeTextSeconds', 'timeTextMinutes', 'timeTextHours'.
186 */
187function jumpToTime()
188{
189        var seconds = parseInt(document.getElementById('timeTextSeconds').value, 10);
190        var minutes = parseInt(document.getElementById('timeTextMinutes').value, 10);
191        var hours = parseInt(document.getElementById('timeTextHours').value, 10);
192
193        var lastEvent = Script.events.getLastExecutedEvent(new Time(hours, minutes, seconds).getSeconds());
194
195        // IF an event was executed THEN
196        if (lastEvent != null)
197        {
198                lastEvent.focus();
199        }
200}
201
202/**
203 * Collapses the elements based on the value of the dropdownbox with id 'domain'.
204 */
205function collapse()
206{
207        var selection = document.getElementById('domain');
208        var selectedIndex = selection.selectedIndex;
209        var selectedValue = selection.options[selectedIndex].value;
210       
211        eval("Script.events.collapseAll" + selectedValue + "();");
212}
213
214/**
215 * Expands the elements based on the value of the dropdownbox with id 'domain'.
216 */
217function expand()
218{
219        var selection = document.getElementById('domain');
220        var selectedIndex = selection.selectedIndex;
221        var selectedValue = selection.options[selectedIndex].value;
222       
223        eval("Script.events.expandAll" + selectedValue + "();");
224}
225
Note: See TracBrowser for help on using the repository browser.