source: tmcsimulator/trunk/webapps/einotebook/script/simscript.js @ 548

Revision 548, 5.1 KB checked in by jdalbey, 6 years ago (diff)

Evaluation.js restore radio buttons and simplify recordRating(). Add submit button to scrollframe and add collectRatings function to retrieve any rating that have been set.

  • 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 lastEventArray = Script.events.getLastExecutedEvent(readCookie("time"));
16
17        // IF a current event exists THEN
18        if (lastEventArray != null)
19        {
20        // Move window focus to first event of the current ones
21        var last = lastEventArray.length - 1;
22            lastEventArray[last].focus();
23        }
24        else
25        {
26                alert("No events have been executed yet.");
27        }
28}
29
30/**
31 * Finds the Event that was last executed by based on time and highlights it.
32 * Removes highlighting from old events.
33 * @return
34 */
35function highlightLatestEvent() 
36{
37    Script.events.setEmphasis();  // Set text colors on all events
38
39    var currentEventArray = Script.events.getLastExecutedEvent(readCookie("time"));
40        /* highlight the items in the current event array */
41    for (var i=0; i<currentEventArray.length; i++) 
42    {
43                currentEventArray[i].highlight();
44        }
45
46    // Set timer to do this again in one second
47        setTimeout("highlightLatestEvent()", 1000);
48}
49
50/**
51 * Loads the the script tab for the given document.
52 * @pre script.html must be completely loaded
53 * @param aDocument
54 */
55function loadScript(theEvents, theIncidents)
56{
57        Script.incidents = theIncidents;
58        Script.events = theEvents;
59        Script.events.win = document.getElementById("view").contentWindow;
60        Script.events.doc = getDocumentFromFrame('view');
61
62        var html = "";
63       
64        // FOR each Event
65        for (var i = 0; i < Script.events.length; i++)
66        {
67                // add the Event's html
68                html += Script.events[i].html();
69        //console.log(Script.events[i].html());
70        }
71       
72    // Add a submit button to the very bottom
73    html += "<button style=\"float: right\" onclick=\"collectRatings();\">Submit Ratings</button>"
74        // display events in iframe
75        getDocumentFromFrame('view').body.innerHTML = html;     
76       
77        // resize iframe to appropriate height
78        resizeIframe();
79        window.onresize = resizeIframe;
80    // Pass the events to the scroll frame window
81        document.getElementById("view").contentWindow.setEvents(Script.events);
82   
83        Script.events.win.scrollTo(0, readCookie('scriptScrollY'));
84       
85        highlightLatestEvent();
86
87}
88
89/**
90 * @param id The id of the frame element.
91 * @return The document of the frame element.
92 */
93function getDocumentFromFrame(id)
94{
95    var frame=document.getElementById(id);
96    var doc=(frame.contentWindow || frame.contentDocument);
97   
98    if (doc.document)doc=doc.document;
99   
100    return doc;
101}
102
103/**
104 * Finds the height of an element relative to the BODY tag.
105 * @param elem The element to find the height of.
106 * @return The y-coordinate of the given element relative to the BODY tag.
107 */
108function pageY(elem) 
109{
110    return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
111}
112
113/**
114 * Resizes the view for the events so that the view's height is at the bottom of its
115 * container.
116 */
117function resizeIframe() 
118{
119    var height = document.documentElement.clientHeight;
120    height -= pageY(document.getElementById('view'));
121    height = (height < 0) ? 0 : height - 10;
122    document.getElementById('view').style.height = height + 'px';
123}
124
125/**
126 * Highlights the text of an input text element after a small delay.
127 * This method was made because using the code "onFocus='this.focus()'" did not work.
128 * @pre textField must have an 'id' attribute
129 * @param textField An input text element.
130 */
131function highlightTextField(textField)
132{
133        setTimeout("document.getElementById('" + textField.id + "').select();", 100);
134}
135
136/**
137 * Formats a two digit textbox. If the text box contains only one digit, then a zero
138 * is appended to the front.
139 * @param textField An input text element.
140 */
141function formatTimeTextfield(textField)
142{
143        // IF the text field contains 1 digits THEN
144        if (textField.value.length == 1)
145        {
146                textField.value = "0".concat(textField.value);
147        }
148}
149
150/**
151 * Scrolls to the event latest executed event if the current simulation time was given
152 * by text fields 'timeTextSeconds', 'timeTextMinutes', 'timeTextHours'.
153 */
154function jumpToTime()
155{
156        var seconds = parseInt(document.getElementById('timeTextSeconds').value, 10);
157        var minutes = parseInt(document.getElementById('timeTextMinutes').value, 10);
158        var hours = parseInt(document.getElementById('timeTextHours').value, 10);
159
160        var lastEvent = Script.events.getLastExecutedEvent(new Time(hours, minutes, seconds).getSeconds());
161
162        // IF an event was executed THEN
163        if (lastEvent != null)
164        {
165                lastEvent.focus();
166        }
167}
168
169/**
170 * Collapses the elements based on the value of the dropdownbox with id 'domain'.
171 */
172function collapse()
173{
174        var selection = document.getElementById('domain');
175        var selectedIndex = selection.selectedIndex;
176        var selectedValue = selection.options[selectedIndex].value;
177       
178        eval("Script.events.collapseAll" + selectedValue + "();");
179}
180
181/**
182 * Expands the elements based on the value of the dropdownbox with id 'domain'.
183 */
184function expand()
185{
186        var selection = document.getElementById('domain');
187        var selectedIndex = selection.selectedIndex;
188        var selectedValue = selection.options[selectedIndex].value;
189       
190        eval("Script.events.expandAll" + selectedValue + "();");
191}
192
Note: See TracBrowser for help on using the repository browser.