source: tmcsimulator/trunk/webapps/einotebook/scripts/Evaluation.js @ 633

Revision 633, 6.4 KB checked in by jdalbey, 5 years ago (diff)

Evaluation.js implemented #253 evaluation comments

  • Property svn:executable set to *
Line 
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 */
6function 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    }
104   
105    function postMessage(logString)
106    {
107        // Using POST to send the data
108        var xhr = new XMLHttpRequest();
109        xhr.open("POST", "/cgi-bin/appendRatingToLog.py", true);
110        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
111        // send the collected data
112        xhr.send("msg="+logString);
113    }
114
115    /**
116     * @return The html for appropriate evaluation form for grading.
117     */
118    function evaluationForm()
119    {
120        return this.smallScaleForm();
121    }
122   
123    /**
124     * @return The html for a 1-5 grading scale.
125     */
126    function smallScaleForm()
127    {
128        return "<form>" +
129               "<table align='right' class='evaluationScale'>" +
130               "<tr>" +
131               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[5]+"</td>" +
132               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[4]+"</td>" +
133               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[3]+"</td>" +
134               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[2]+"</td>" +
135               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[1]+"</td>" +
136               "</tr>" +
137               "<tr>" +
138               "<td align='center'><input type='radio' " + 
139                       (this.rating == 5 ? "checked='true'" : "") + 
140                       " onchange='events.getEvaluation(" + this.id + 
141                       ").writeRating(5)' name='" + this.ratingGroupName + 
142                       "' value='5'></td>" +
143               "<td align='center'><input type='radio' " + 
144                       (this.rating == 4 ? "checked='true'" : "") + 
145                       " onchange='events.getEvaluation(" + this.id + 
146                       ").writeRating(4)' name='" + this.ratingGroupName + 
147                       "' value='4'></td>" +
148               "<td align='center'><input type='radio' " + 
149                       (this.rating == 3 ? "checked='true'" : "") + 
150                       " onchange='events.getEvaluation(" + this.id + 
151                       ").writeRating(3)' name='" + this.ratingGroupName + 
152                       "' value='3'></td>" +
153               "<td align='center'><input type='radio' " + 
154                       (this.rating == 2 ? "checked='true'" : "") + 
155                       " onchange='events.getEvaluation(" + this.id + 
156                       ").writeRating(2)' name='" + this.ratingGroupName + 
157                       "' value='2'></td>" +
158               "<td align='center'><input type='radio' " + 
159                       (this.rating == 1 ? "checked='true'" : "") + 
160                       " onchange='events.getEvaluation(" + this.id + 
161                       ").writeRating(1)' name='" + this.ratingGroupName + 
162                       "' value='1'></td>" +
163               "</tr>" +
164               "</table>"  +
165               "</form>";
166    }
167}
Note: See TracBrowser for help on using the repository browser.