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

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