Warning: Can't use blame annotator:
svn blame failed on branches/EInotebook/scripts/Event.js: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/branches/EInotebook/scripts/Event.js @ 350

Revision 350, 5.6 KB checked in by jdalbey, 7 years ago (diff)

Add a branch EInotebook for Electronic Instructor Notebook prototype

  • Property svn:executable set to *
RevLine 
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.focus = focus;
36       
37        //========== private methods ==========//
38        this.expandOptionSymbol = expandOptionSymbol;
39        this.headerHTML = headerHTML;
40        this.expandOptionHTML = expandOptionHTML;
41        this.refresh = refresh;
42        this.dataHTML = dataHTML;
43        this.expandAction = expandAction;
44        this.html = html;
45       
46        //========== function definitions ===========//
47        /**
48         * Returns the symbol for the expand/collapse option.
49         * @return "+" or "-" depending on whether this event is collapsed or expanded.
50         */
51        function expandOptionSymbol() 
52        { 
53                return this.expanded ? "–" : "+"; 
54        }
55         
56        /**
57         * @return The rectangle containing the expand/collapse symbol,
58         *         incident time, incident number and
59         *         incident title that this event belongs to.
60         */
61        function headerHTML()
62        {
63        if (this.incident == undefined)
64        {
65            console.log(this.time.format());
66        }
67                return "<table class='eventHeader'>" +
68                                "<tr class='eventHeader'>" +
69                                "<td class='eventExpandOption'>" + this.expandOptionHTML() + "</td>" +
70                                "<td class='eventTime'>Time: " + this.time.format() + "</td>" +
71                                "<td class='eventNumber'>" + this.incident.number + "</td>" +
72                                "<td class='eventTitle'>" + this.incident.title + "</td>" + 
73                                "</tr>" +
74                                "</table>";
75        }
76       
77        /**
78         * @return The html of the expand/collapse symbol.
79         */
80        function expandOptionHTML()
81        {
82                return "<button class='eventExpandButton' id='" + this.expandOptionID + 
83                                "' onclick='events.get(" + 
84                                this.id + ").expandAction();'>" + this.expandOptionSymbol() 
85                                + "</button>";
86        }
87
88        /**
89         * Updates the expand option symbol and the visibility of the event data depending on
90         * whether this event is collapsed or expanded.
91         */
92        function refresh()
93        {
94                events.doc.getElementById(this.dataID).innerHTML = 
95                        this.expanded ? this.dataHTML() : "";
96                       
97                // IF the event is highlighted THEN
98                if (this.highlighted)
99                {
100                        this.highlight();
101                }
102                else
103                {
104                        this.unhighlight();
105                }
106                       
107                events.doc.getElementById(this.expandOptionID).innerHTML = 
108                        this.expandOptionSymbol();
109        }
110       
111        /**
112         * @return The html for the properties and the evaluations.
113         */
114        function dataHTML()
115        {
116                return properties.html() + evaluations.html();
117        }
118
119        /**
120         * Expands or collapses this event depending on whether this event is
121         * already expanded or collapsed.
122         */
123        function expandAction() 
124        { 
125                this.expanded = !this.expanded; 
126                this.refresh(); 
127        }
128
129        /**
130         * @return The html representation of this event.
131         */
132        function html()
133        {
134                return "<table class='event'>" +
135                           "<tr>" +
136                           "<td class='eventHeader' id='" + this.eventHeaderID + "'>" + 
137                              this.headerHTML() + "</td>" +
138                           "</tr>" +
139                           "<tr>" + 
140                           "<td class='eventData' id='" + this.dataID + "'>" + 
141                           (this.expanded ? this.dataHTML() : "") + 
142                           "</td>" +
143                           "</tr>" +
144                           "</table>";
145        }
146       
147        /**
148         * Scrolls the window to this Event.
149         * @param window The window to scroll.
150         */
151        function focus()
152        {
153                /* This method was discarded because it moved the scroll bar of the parent of
154                 * the given window in addition to the scroll bar of the given window..
155                var positionOfPound = window.location.indexOf("#");
156                var rootLocation = window.location.substring(0, positionOfPound);
157                window.location = rootLocation + "#" + eventAnchorName;
158                */
159                events.win.scrollTo(0, absoluteTop(events.doc.getElementById(this.eventHeaderID)));
160        }
161       
162        /**
163         * Highlights this Event.
164         */
165        function highlight()
166        {
167                this.highlighted = true;
168                events.doc.getElementById(this.eventHeaderID).style.borderColor = "blue";
169                events.doc.getElementById(this.eventHeaderID).style.backgroundColor = "yellow";
170               
171                // IF this event is expanded THEN
172                if (this.expanded) 
173                {
174                        events.doc.getElementById(this.dataID).style.border = "2px solid blue";
175                }
176                else
177                {
178                        events.doc.getElementById(this.dataID).style.border = "none";
179                }
180               
181        }
182       
183        /**
184         * Unhighlights this event.
185         * @return
186         */
187        function unhighlight()
188        {
189                this.highlighted = false;
190                events.doc.getElementById(this.eventHeaderID).style.backgroundColor = "white";
191                events.doc.getElementById(this.eventHeaderID).style.borderColor = "gainsboro";
192                events.doc.getElementById(this.eventHeaderID).style.color = "lightgray";
193                events.doc.getElementById(this.dataID).style.border = "0px solid red";
194        }
195       
196        /**
197         * Returns the number of pixels from the top of the given element to the top
198         * of the body element.
199         * @param elem The element whose y-coordinate will be found.
200         * @return The y-coordinate of the given element.
201         */
202        function absoluteTop(elem)
203        {
204                var offset = elem.offsetTop;
205                var parent = elem.offsetParent;
206               
207                if (parent.tagName == "BODY")
208                {
209                        return offset;
210                }
211                else
212                {
213                        return offset + absoluteTop(parent);
214                }
215        }
216}
Note: See TracBrowser for help on using the repository browser.