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