source: tmcsimulator/trunk/webapps/einotebook/scripts/Event.js @ 538

Revision 538, 7.0 KB checked in by jdalbey, 6 years ago (diff)

Remove obsolete code from einotebook

  • Property svn:executable set to *
Line 
1/**
2 * Represents an event.
3 * @param time {Time}
4 * @param incident {Incident}
5 * @param properties {Properties}
6 * @param properties {Evaluations}
7 */
8function Event(time, incident, properties, evaluations)
9{
10        //========== private static members ==========//
11        Event.invalidID = -1;
12       
13        //========== private static members ==========//
14        Event.id = (typeof Event.id == 'undefined') ? 0 : ++Event.id;
15       
16        //========== public constants ==========//
17        this.id = Event.id;
18        this.expandOptionID = "eventExpandOption" + this.id;
19        this.dataID = "eventData" + this.id;
20        this.eventHeaderID = "eventHeader" + this.id;
21       
22        //========== public read-only members ==========//
23        this.expanded = true;
24        this.highlighted = false;
25        this.time = time;
26        this.incident = incident;
27        this.evaluations = evaluations;
28        this.properties = properties;
29       
30        //========== public methods ==========//
31        this.html = html;
32        this.expandAction = expandAction;
33        this.highlight = highlight;
34        this.unhighlight = unhighlight;
35    this.normalize = normalize;
36        this.focus = focus;
37       
38        //========== private methods ==========//
39        this.expandOptionSymbol = expandOptionSymbol;
40        this.headerHTML = headerHTML;
41        this.expandOptionHTML = expandOptionHTML;
42        this.refresh = refresh;
43        this.dataHTML = dataHTML;
44        this.expandAction = expandAction;
45        this.html = html;
46
47    // Color constants (TODO: assign incident numbers dynamically)
48/*    var incidentColor = {
49187: "#d8f0f3",        // PowderBlue
50188: "#dfecdf",        // DarkSeaGreen
51189: "#fff5cc",        // CornSilk
52190: "#ffe8e6",        // MistyRose
53191: "#ffffcc",       // Dark Orange
54181: "#d8f0f3" }
55*/
56       
57        //========== function definitions ===========//
58        /**
59         * Returns the symbol for the expand/collapse option.
60         * @return "+" or "-" depending on whether this event is collapsed or expanded.
61         */
62        function expandOptionSymbol() 
63        { 
64                return this.expanded ? "–" : "+"; 
65        }
66         
67        /**
68         * @return The rectangle containing the expand/collapse symbol,
69         *         incident time, incident number and
70         *         incident title that this event belongs to.
71         */
72        function headerHTML()
73        {
74        if (this.incident == undefined)
75        {
76            console.log(this.time.format());
77        }
78                return "<table class='eventHeader'>" +
79                                "<tr class='eventHeader'>" +
80                                "<td class='eventExpandOption'>" + this.expandOptionHTML() + "</td>" +
81                                "<td class='eventTime'>Time: " + this.time.format() + "</td>" +
82                                "<td class='eventNumber'>" + this.incident.number + "</td>" +
83                                "<td class='eventTitle'>" + this.incident.title + "</td>" + 
84                                "</tr>" +
85                                "</table>";
86        }
87       
88        /**
89         * @return The html of the expand/collapse symbol.
90         */
91        function expandOptionHTML()
92        {
93        return "&nbsp;"
94/*  In 2019 we don't think we want expand option any longer
95                return "<button class='eventExpandButton' id='" + this.expandOptionID +
96                                "' onclick='events.get(" +
97                                this.id + ").expandAction();'>" + this.expandOptionSymbol()
98                                + "</button>";
99*/
100        }
101
102        /**
103         * Updates the expand option symbol and the visibility of the event data depending on
104         * whether this event is collapsed or expanded.
105         */
106        function refresh()
107        {
108                events.doc.getElementById(this.dataID).innerHTML = 
109                        this.expanded ? this.dataHTML() : "";
110                       
111                // IF the event is highlighted THEN
112                if (this.highlighted)
113                {
114                        this.highlight();
115                }
116                else
117                {
118                        this.unhighlight();
119                }
120                       
121                events.doc.getElementById(this.expandOptionID).innerHTML = 
122                        this.expandOptionSymbol();
123        }
124       
125        /**
126         * @return The html for the properties and the evaluations.
127         */
128        function dataHTML()
129        {
130                return properties.html() + evaluations.html();
131        }
132
133        /**
134         * Expands or collapses this event depending on whether this event is
135         * already expanded or collapsed.
136         */
137        function expandAction() 
138        { 
139                this.expanded = !this.expanded; 
140                this.refresh(); 
141        }
142
143        /**
144         * @return The html representation of this event.
145         */
146        function html()
147        {
148                return "<table class='event'>" +
149                           "<tr>" +
150                           "<td class='eventHeader' style='background-color:" + this.incident.color + "'" +
151               "id='" + this.eventHeaderID + "'>" + 
152                              this.headerHTML() + "</td>" +
153                           "</tr>" +
154                           "<tr>" + 
155                           "<td class='eventData' style='background-color:" + this.incident.color + "' id='" + this.dataID + "'>" + 
156                           (this.expanded ? this.dataHTML() : "") + 
157                           "</td>" +
158                           "</tr>" +
159                           "</table>";
160        }
161       
162        /**
163         * Scrolls the window to this Event.
164         * @param window The window to scroll.
165         */
166        function focus()
167        {
168                /* This method was discarded because it moved the scroll bar of the parent of
169                 * the given window in addition to the scroll bar of the given window..
170                var positionOfPound = window.location.indexOf("#");
171                var rootLocation = window.location.substring(0, positionOfPound);
172                window.location = rootLocation + "#" + eventAnchorName;
173                */
174                events.win.scrollTo(0, absoluteTop(events.doc.getElementById(this.eventHeaderID)));
175        }
176       
177        /**
178         * Highlights this Event.
179         */
180        function highlight()
181        {
182                this.highlighted = true;
183                events.doc.getElementById(this.eventHeaderID).style.borderColor = "blue";
184                events.doc.getElementById(this.eventHeaderID).style.backgroundColor = "yellow";
185                events.doc.getElementById(this.eventHeaderID).style.color = "black";
186                events.doc.getElementById(this.dataID).style.color = "black";
187        events.doc.getElementById(this.dataID).style.backgroundColor = this.incident.color;
188               
189                // IF this event is expanded THEN
190                if (this.expanded) 
191                {
192                        events.doc.getElementById(this.dataID).style.border = "2px solid blue";
193                }
194                else
195                {
196                        events.doc.getElementById(this.dataID).style.border = "none";
197                }
198       
199        }
200       
201        /**
202         * Unhighlights this event.
203         * @return
204         */
205        function unhighlight()
206        {
207                this.highlighted = false;
208                events.doc.getElementById(this.eventHeaderID).style.backgroundColor = "white";
209                events.doc.getElementById(this.eventHeaderID).style.borderColor = "gainsboro";
210                events.doc.getElementById(this.eventHeaderID).style.color = "gray";
211                events.doc.getElementById(this.dataID).style.border = "0px solid red";
212                events.doc.getElementById(this.dataID).style.backgroundColor = "white";
213                events.doc.getElementById(this.dataID).style.color = "gray";
214        }
215        /**
216         * Normalize this Event: provide normal background and text colors.
217         */
218        function normalize()
219        {
220        var myColor = this.incident.color;
221                events.doc.getElementById(this.eventHeaderID).style.backgroundColor = "white";
222                events.doc.getElementById(this.eventHeaderID).style.borderColor = "black";
223                events.doc.getElementById(this.eventHeaderID).style.color = "black";
224                events.doc.getElementById(this.dataID).style.color = "black";
225        events.doc.getElementById(this.dataID).style.backgroundColor = myColor;
226                events.doc.getElementById(this.eventHeaderID).style.backgroundColor = myColor;
227    }           
228
229       
230        /**
231         * Returns the number of pixels from the top of the given element to the top
232         * of the body element.
233         * @param elem The element whose y-coordinate will be found.
234         * @return The y-coordinate of the given element.
235         */
236        function absoluteTop(elem)
237        {
238                var offset = elem.offsetTop;
239                var parent = elem.offsetParent;
240               
241                if (parent.tagName == "BODY")
242                {
243                        return offset;
244                }
245                else
246                {
247                        return offset + absoluteTop(parent);
248                }
249        }
250}
Note: See TracBrowser for help on using the repository browser.