| 1 | /** |
|---|
| 2 | * Represents an evaluation (e.g., a "CMS evaluation"). |
|---|
| 3 | * @param type {String} Ex: "CMS" or "ATMS" ... |
|---|
| 4 | * @param data Array(label1, text1, label2, text2, ...) |
|---|
| 5 | */ |
|---|
| 6 | function Evaluation(type, evttime, data) |
|---|
| 7 | { |
|---|
| 8 | //========== private static members ==========// |
|---|
| 9 | Evaluation.id = (typeof Evaluation.id == 'undefined') ? 0 : ++Evaluation.id; |
|---|
| 10 | |
|---|
| 11 | //========== public constants ==========// |
|---|
| 12 | this.ratingQualities = ["", "Worst","Poor","Average","Good","Best"]; |
|---|
| 13 | this.id = Evaluation.id; |
|---|
| 14 | this.ratingGroupName = "evaluationGroup" + this.id; |
|---|
| 15 | this.textID = "evaluationText" + this.id; |
|---|
| 16 | this.type = type; |
|---|
| 17 | this.data = data; |
|---|
| 18 | this.evttime = evttime; |
|---|
| 19 | |
|---|
| 20 | //========== public read-only members ==========// |
|---|
| 21 | this.text = ""; |
|---|
| 22 | this.rating = -1; |
|---|
| 23 | |
|---|
| 24 | //========== public methods ==========// |
|---|
| 25 | this.html = html; |
|---|
| 26 | this.recordText = recordText; |
|---|
| 27 | this.writeRating = writeRating; |
|---|
| 28 | |
|---|
| 29 | //========== private methods ==========// |
|---|
| 30 | this.smallScaleForm = smallScaleForm; |
|---|
| 31 | this.evaluationForm = evaluationForm; |
|---|
| 32 | |
|---|
| 33 | //========== function definitions ==========// |
|---|
| 34 | /** |
|---|
| 35 | * @return The html representation of this evaluation. |
|---|
| 36 | */ |
|---|
| 37 | function html() |
|---|
| 38 | { |
|---|
| 39 | var text = "<table class='evaluation'>" + |
|---|
| 40 | "<tr>" + |
|---|
| 41 | "<th class='evaluationType' colspan='2'>" + type + " Evaluation</th>" + |
|---|
| 42 | "</tr>" + |
|---|
| 43 | "<tr>" + |
|---|
| 44 | "<td><table class='evaluationInner2'>"; |
|---|
| 45 | |
|---|
| 46 | for (i = 0; i < this.data.length; i += 2) |
|---|
| 47 | { |
|---|
| 48 | text += "<tr>" + |
|---|
| 49 | "<td class='evaluationLabel'>" + this.data[i] + "</td>" + |
|---|
| 50 | "<td class='evaluationCriteria'>" + this.data[i+1] + "</td>" + |
|---|
| 51 | "</tr>"; |
|---|
| 52 | } |
|---|
| 53 | /* Displays the comment input field |
|---|
| 54 | text += "<tr><td colspan='2' class='evaluationResponse'>" + |
|---|
| 55 | "<input onchange='events.getEvaluation(" + this.id + ").recordText();'" + |
|---|
| 56 | " id='" + this.textID + "' type='text' value='" + this.text + "'" + |
|---|
| 57 | " class='evaluationResponseText' />" |
|---|
| 58 | + "</td>"; |
|---|
| 59 | */ |
|---|
| 60 | text += "<tr>" |
|---|
| 61 | /* Displays the ranking bubbles */ |
|---|
| 62 | text += "</td>" |
|---|
| 63 | + "<td class='evaluationScale'>" + this.evaluationForm() |
|---|
| 64 | + "</td>" |
|---|
| 65 | text += "<td colspan='2' class='evaluationResponse'>" |
|---|
| 66 | + "<input id='" + this.textID + "' type='text' value='" + this.text + "'" |
|---|
| 67 | + " class='evaluationResponseText' " |
|---|
| 68 | + " onchange='events.getEvaluation(" + this.id + ").recordText();' />" |
|---|
| 69 | + "</td>"; |
|---|
| 70 | text += "</tr>"; |
|---|
| 71 | text += "</table>"; |
|---|
| 72 | |
|---|
| 73 | text += "</table>"; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | return text; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * Write an individual rating to a log file |
|---|
| 82 | */ |
|---|
| 83 | function writeRating(givenRating) |
|---|
| 84 | { |
|---|
| 85 | // Build a string for the log in this format: |
|---|
| 86 | //03:01:00, Evaluation, CMS, Poor |
|---|
| 87 | logString = this.evttime.format() + ", Evaluation, " + this.type + ", " |
|---|
| 88 | + this.ratingQualities[givenRating] + "\n" |
|---|
| 89 | postMessage(logString) |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | * Stores the text in the written response text box. |
|---|
| 94 | */ |
|---|
| 95 | function recordText() |
|---|
| 96 | { |
|---|
| 97 | this.text = events.doc.getElementById(this.textID).value; |
|---|
| 98 | // Build a string for the log in this format: |
|---|
| 99 | //03:01:00, Evaluation, CMS, 'comment' |
|---|
| 100 | logString = this.evttime.format() + ", Evaluation, " + this.type + ", '" |
|---|
| 101 | + this.text + "'\n" |
|---|
| 102 | postMessage(logString) |
|---|
| 103 | // Change the text color as feedback to user |
|---|
| 104 | // events.doc.getElementById(this.textID).style.color = "lightgrey"; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | function postMessage(logString) |
|---|
| 108 | { |
|---|
| 109 | // Using POST to send the data |
|---|
| 110 | var xhr = new XMLHttpRequest(); |
|---|
| 111 | xhr.open("POST", "/cgi-bin/appendRatingToLog.py", true); |
|---|
| 112 | xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); |
|---|
| 113 | // send the collected data |
|---|
| 114 | xhr.send("msg="+logString); |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | /** |
|---|
| 118 | * @return The html for appropriate evaluation form for grading. |
|---|
| 119 | */ |
|---|
| 120 | function evaluationForm() |
|---|
| 121 | { |
|---|
| 122 | return this.smallScaleForm(); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /** |
|---|
| 126 | * @return The html for a 1-5 grading scale. |
|---|
| 127 | */ |
|---|
| 128 | function smallScaleForm() |
|---|
| 129 | { |
|---|
| 130 | return "<form>" + |
|---|
| 131 | "<table align='right' class='evaluationScale'>" + |
|---|
| 132 | "<tr>" + |
|---|
| 133 | "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[5]+"</td>" + |
|---|
| 134 | "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[4]+"</td>" + |
|---|
| 135 | "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[3]+"</td>" + |
|---|
| 136 | "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[2]+"</td>" + |
|---|
| 137 | "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[1]+"</td>" + |
|---|
| 138 | "</tr>" + |
|---|
| 139 | "<tr>" + |
|---|
| 140 | "<td align='center'><input type='radio' " + |
|---|
| 141 | (this.rating == 5 ? "checked='true'" : "") + |
|---|
| 142 | " onchange='events.getEvaluation(" + this.id + |
|---|
| 143 | ").writeRating(5)' name='" + this.ratingGroupName + |
|---|
| 144 | "' value='5'></td>" + |
|---|
| 145 | "<td align='center'><input type='radio' " + |
|---|
| 146 | (this.rating == 4 ? "checked='true'" : "") + |
|---|
| 147 | " onchange='events.getEvaluation(" + this.id + |
|---|
| 148 | ").writeRating(4)' name='" + this.ratingGroupName + |
|---|
| 149 | "' value='4'></td>" + |
|---|
| 150 | "<td align='center'><input type='radio' " + |
|---|
| 151 | (this.rating == 3 ? "checked='true'" : "") + |
|---|
| 152 | " onchange='events.getEvaluation(" + this.id + |
|---|
| 153 | ").writeRating(3)' name='" + this.ratingGroupName + |
|---|
| 154 | "' value='3'></td>" + |
|---|
| 155 | "<td align='center'><input type='radio' " + |
|---|
| 156 | (this.rating == 2 ? "checked='true'" : "") + |
|---|
| 157 | " onchange='events.getEvaluation(" + this.id + |
|---|
| 158 | ").writeRating(2)' name='" + this.ratingGroupName + |
|---|
| 159 | "' value='2'></td>" + |
|---|
| 160 | "<td align='center'><input type='radio' " + |
|---|
| 161 | (this.rating == 1 ? "checked='true'" : "") + |
|---|
| 162 | " onchange='events.getEvaluation(" + this.id + |
|---|
| 163 | ").writeRating(1)' name='" + this.ratingGroupName + |
|---|
| 164 | "' value='1'></td>" + |
|---|
| 165 | "</tr>" + |
|---|
| 166 | "</table>" + |
|---|
| 167 | "</form>"; |
|---|
| 168 | } |
|---|
| 169 | } |
|---|