| 1 | /** |
|---|
| 2 | * Represents a collection of evaluations that belong to a single event. |
|---|
| 3 | * @param evaluations {Array of Evaluation} The list of Evaluation to be grouped together. |
|---|
| 4 | */ |
|---|
| 5 | function Evaluations(evaluations) |
|---|
| 6 | { |
|---|
| 7 | //========== private static members ==========// |
|---|
| 8 | Evaluations.id = (typeof Evaluations.id == 'undefined') ? 0 : ++Evaluations.id; |
|---|
| 9 | |
|---|
| 10 | //========== public constants ==========// |
|---|
| 11 | this.evaluations = evaluations; |
|---|
| 12 | this.id = Evaluations.id; |
|---|
| 13 | this.expandOptionID = "evalutionsExpandOption" + this.id; |
|---|
| 14 | this.evaluationsID = "evaluations" + this.id; |
|---|
| 15 | |
|---|
| 16 | //========== public read-only members ==========// |
|---|
| 17 | this.expanded = true; |
|---|
| 18 | |
|---|
| 19 | //========== public methods ==========// |
|---|
| 20 | this.html = html; |
|---|
| 21 | this.expandAction = expandAction; |
|---|
| 22 | |
|---|
| 23 | //========== private methods ==========// |
|---|
| 24 | this.expandOption = expandOption; |
|---|
| 25 | this.expandOptionSymbol = expandOptionSymbol; |
|---|
| 26 | this.refresh = refresh; |
|---|
| 27 | this.evaluationsHTML = evaluationsHTML; |
|---|
| 28 | |
|---|
| 29 | //========== function definitions ==========// |
|---|
| 30 | /** |
|---|
| 31 | * @return The html for the "+" or "-" button that expands or collapses these |
|---|
| 32 | * evaluations when clicked. |
|---|
| 33 | */ |
|---|
| 34 | function expandOption() |
|---|
| 35 | { |
|---|
| 36 | return "<button class='evaluationsExpandButton' id='" + |
|---|
| 37 | this.expandOptionID + "' onclick='events.getEvaluations(" |
|---|
| 38 | + this.id + ").expandAction();'>" + |
|---|
| 39 | this.expandOptionSymbol() + "</button>"; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * @return The "-" or "-" symbol for the expand/collapse button. |
|---|
| 44 | */ |
|---|
| 45 | function expandOptionSymbol() |
|---|
| 46 | { |
|---|
| 47 | return this.expanded == true ? "–" : "+"; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * Updates the expand/collapse symbol and whether the evaluations are visible. |
|---|
| 52 | */ |
|---|
| 53 | function refresh() |
|---|
| 54 | { |
|---|
| 55 | // IF the expandOption element exists THEN |
|---|
| 56 | if (events.doc.getElementById(this.expandOptionID)) |
|---|
| 57 | { |
|---|
| 58 | events.doc.getElementById(this.expandOptionID).innerHTML = |
|---|
| 59 | this.expandOptionSymbol(); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | // IF the evaluations element exists THEN |
|---|
| 63 | if (events.doc.getElementById(this.evaluationsID)) |
|---|
| 64 | { |
|---|
| 65 | events.doc.getElementById(this.evaluationsID).innerHTML = |
|---|
| 66 | this.expanded ? this.evaluationsHTML() : ""; |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * @return The html for the evaluations. |
|---|
| 72 | */ |
|---|
| 73 | function evaluationsHTML() |
|---|
| 74 | { |
|---|
| 75 | var html = "<table class='evaluationsInner'>"; |
|---|
| 76 | |
|---|
| 77 | // FOR each evaluation |
|---|
| 78 | for (var i = 0; i < this.evaluations.length; i++) |
|---|
| 79 | { |
|---|
| 80 | // add evaluation html |
|---|
| 81 | html += "<tr>" + |
|---|
| 82 | "<td>" + this.evaluations[i].html() + "</td>" + |
|---|
| 83 | "</tr>"; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | html += "</table>"; |
|---|
| 87 | |
|---|
| 88 | return html; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | /** |
|---|
| 92 | * Expands the evaluations if they are collapsed. |
|---|
| 93 | * Collapses the evaluations if they are expanded. |
|---|
| 94 | */ |
|---|
| 95 | function expandAction() |
|---|
| 96 | { |
|---|
| 97 | this.expanded = !this.expanded; this.refresh(); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | /** |
|---|
| 101 | * @return The html representation of these evaluations. |
|---|
| 102 | */ |
|---|
| 103 | function html() |
|---|
| 104 | { |
|---|
| 105 | var text = ""; |
|---|
| 106 | |
|---|
| 107 | // IF there are any evaluations THEN |
|---|
| 108 | if (this.evaluations.length > 0) |
|---|
| 109 | { |
|---|
| 110 | text = "<table class='evaluationsOuter'>"; |
|---|
| 111 | /* In 2019 we no longer care to expand "Properties" or "Evaluations" */ |
|---|
| 112 | /* |
|---|
| 113 | text += "<tr>" + |
|---|
| 114 | "<td class='evaluationsExpandOption'>" + this.expandOption() + |
|---|
| 115 | " Evaluations</td>" + |
|---|
| 116 | "</tr>"; |
|---|
| 117 | */ |
|---|
| 118 | text += "<tr>" + |
|---|
| 119 | "<td class='evaluations' id='" + this.evaluationsID + "'>" + |
|---|
| 120 | (this.expanded ? this.evaluationsHTML() : "") + "</td>" + |
|---|
| 121 | "</tr>"; |
|---|
| 122 | |
|---|
| 123 | text +="</table>"; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | return text; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | } |
|---|