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

Revision 632, 5.8 KB checked in by jdalbey, 5 years ago (diff)

Remove code made obsolete by modifications 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.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 +=    "</table>";
61        /*  Displays the ranking bubbles  */
62        text += "</td>" +
63                      "<td class='evaluationScale'>" + this.evaluationForm() + "</td>" +
64                   "</tr>";
65       
66        text +=    "</table>";
67
68               
69        return text;
70    }
71   
72
73    /**
74     * Write an individual rating to a log file
75     */
76    function writeRating(givenRating)
77    {
78        // Build a string for the log in this format:
79        //03:01:00, Evaluation, CMS, Poor
80        logString = this.evttime.format() + ", Evaluation, " + this.type + ", " + this.ratingQualities[givenRating] + "\n"
81        // Using POST to send the data
82        var xhr = new XMLHttpRequest();
83        xhr.open("POST", "/cgi-bin/appendRatingToLog.py", true);
84        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
85        // send the collected data
86        xhr.send("msg="+logString);
87    }
88
89    /**
90     * Stores the text in the written response text box.
91     */
92    function recordText() 
93    { 
94        this.text = events.doc.getElementById(this.textID).value; 
95    }
96   
97    /**
98     * @return The html for appropriate evaluation form for grading.
99     */
100    function evaluationForm()
101    {
102        return this.smallScaleForm();
103    }
104   
105    /**
106     * @return The html for a 1-5 grading scale.
107     */
108    function smallScaleForm()
109    {
110        return "<form>" +
111               "<table align='right' class='evaluationScale'>" +
112               "<tr>" +
113               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[5]+"</td>" +
114               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[4]+"</td>" +
115               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[3]+"</td>" +
116               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[2]+"</td>" +
117               "<td class='eventRadioButtonSmallScale'>"+this.ratingQualities[1]+"</td>" +
118               "</tr>" +
119               "<tr>" +
120               "<td align='center'><input type='radio' " + 
121                       (this.rating == 5 ? "checked='true'" : "") + 
122                       " onchange='events.getEvaluation(" + this.id + 
123                       ").writeRating(5)' name='" + this.ratingGroupName + 
124                       "' value='5'></td>" +
125               "<td align='center'><input type='radio' " + 
126                       (this.rating == 4 ? "checked='true'" : "") + 
127                       " onchange='events.getEvaluation(" + this.id + 
128                       ").writeRating(4)' name='" + this.ratingGroupName + 
129                       "' value='4'></td>" +
130               "<td align='center'><input type='radio' " + 
131                       (this.rating == 3 ? "checked='true'" : "") + 
132                       " onchange='events.getEvaluation(" + this.id + 
133                       ").writeRating(3)' name='" + this.ratingGroupName + 
134                       "' value='3'></td>" +
135               "<td align='center'><input type='radio' " + 
136                       (this.rating == 2 ? "checked='true'" : "") + 
137                       " onchange='events.getEvaluation(" + this.id + 
138                       ").writeRating(2)' name='" + this.ratingGroupName + 
139                       "' value='2'></td>" +
140               "<td align='center'><input type='radio' " + 
141                       (this.rating == 1 ? "checked='true'" : "") + 
142                       " onchange='events.getEvaluation(" + this.id + 
143                       ").writeRating(1)' name='" + this.ratingGroupName + 
144                       "' value='1'></td>" +
145               "</tr>" +
146               "</table>"  +
147               "</form>";
148    }
149}
Note: See TracBrowser for help on using the repository browser.