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

Revision 631, 6.2 KB checked in by jdalbey, 5 years ago (diff)

appendRatingToLog.py evalratings.csv New files added for #251.

  • 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.recordRating = recordRating;
28    this.writeRating = writeRating;
29   
30    //========== private methods ==========//
31    this.smallScaleForm = smallScaleForm;
32    this.evaluationForm = evaluationForm;
33   
34    //========== function definitions ==========//
35    /**
36     * @return The html representation of this evaluation.
37     */
38    function html()
39    {
40        var text = "<table class='evaluation'>" +
41                         "<tr>" +
42                         "<th class='evaluationType' colspan='2'>" + type + " Evaluation</th>" +
43                         "</tr>" +
44                         "<tr>" +
45                         "<td><table class='evaluationInner2'>";
46       
47        for (i = 0; i < this.data.length; i += 2)
48        {
49            text += "<tr>" +
50                   "<td class='evaluationLabel'>" + this.data[i] + "</td>" +
51                   "<td class='evaluationCriteria'>" + this.data[i+1] + "</td>" +
52                   "</tr>";
53        }
54        /*  Displays the comment input field
55        text += "<tr><td colspan='2' class='evaluationResponse'>" +
56            "<input onchange='events.getEvaluation(" + this.id + ").recordText();'" +
57            " id='" + this.textID + "' type='text' value='" + this.text + "'" +
58            " class='evaluationResponseText' />"
59            + "</td>";
60        */
61        text +=    "</table>";
62        /*  Displays the ranking bubbles  */
63        text += "</td>" +
64                      "<td class='evaluationScale'>" + this.evaluationForm() + "</td>" +
65                   "</tr>";
66       
67        text +=    "</table>";
68
69               
70        return text;
71    }
72   
73    /**
74     * Stores the rating given by the evaluation scale radio button form. --OBSOLETE
75     */
76    function recordRating(givenRating) 
77    { 
78
79        this.rating = givenRating;
80        //console.log(this.ratingGroupName + " recordRating of " + this.rating )
81    }
82    /**
83     * Write an individual rating to a log file
84     */
85    function writeRating(givenRating)
86    {
87        //alert("writeRating: " + givenRating + " : " + this.evttime.format())
88        // Build a string for the log in this format:
89        //03:01:00, Evaluation, CMS, Poor
90        logString = this.evttime.format() + ", Evaluation, " + this.type + ", " + this.ratingQualities[givenRating] + "\n"
91        // Using POST to send the data
92        var xhr = new XMLHttpRequest();
93        xhr.open("POST", "/cgi-bin/appendRatingToLog.py", true);
94        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
95        // send the collected data
96        xhr.send("msg="+logString);
97    }
98
99    /**
100     * Stores the text in the written response text box.
101     */
102    function recordText() 
103    { 
104        this.text = events.doc.getElementById(this.textID).value; 
105    }
106   
107    /**
108     * @return The html for appropriate evaluation form for grading.
109     */
110    function evaluationForm()
111    {
112        return this.smallScaleForm();
113    }
114   
115    /**
116     * @return The html for a 1-5 grading scale.
117     */
118    function smallScaleForm()
119    {
120        return "<form>" +
121               "<table align='right' class='evaluationScale'>" +
122               "<tr>" +
123               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[5]+"</td>" +
124               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[4]+"</td>" +
125               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[3]+"</td>" +
126               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[2]+"</td>" +
127               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[1]+"</td>" +
128               "</tr>" +
129               "<tr>" +
130               "<td align='center'><input type='radio' " + 
131                       (this.rating == 5 ? "checked='true'" : "") + 
132                       " onchange='events.getEvaluation(" + this.id + 
133                       ").writeRating(5)' name='" + this.ratingGroupName + 
134                       "' value='5'></td>" +
135               "<td align='center'><input type='radio' " + 
136                       (this.rating == 4 ? "checked='true'" : "") + 
137                       " onchange='events.getEvaluation(" + this.id + 
138                       ").writeRating(4)' name='" + this.ratingGroupName + 
139                       "' value='4'></td>" +
140               "<td align='center'><input type='radio' " + 
141                       (this.rating == 3 ? "checked='true'" : "") + 
142                       " onchange='events.getEvaluation(" + this.id + 
143                       ").writeRating(3)' name='" + this.ratingGroupName + 
144                       "' value='3'></td>" +
145               "<td align='center'><input type='radio' " + 
146                       (this.rating == 2 ? "checked='true'" : "") + 
147                       " onchange='events.getEvaluation(" + this.id + 
148                       ").writeRating(2)' name='" + this.ratingGroupName + 
149                       "' value='2'></td>" +
150               "<td align='center'><input type='radio' " + 
151                       (this.rating == 1 ? "checked='true'" : "") + 
152                       " onchange='events.getEvaluation(" + this.id + 
153                       ").writeRating(1)' name='" + this.ratingGroupName + 
154                       "' value='1'></td>" +
155               "</tr>" +
156               "</table>"  +
157               "</form>";
158    }
159}
Note: See TracBrowser for help on using the repository browser.