/** * Represents an evaluation (e.g., a "CMS evaluation"). * @param type {String} Ex: "CMS" or "ATMS" ... * @param data Array(label1, text1, label2, text2, ...) */ function Evaluation(type, evttime, data) { //========== private static members ==========// Evaluation.id = (typeof Evaluation.id == 'undefined') ? 0 : ++Evaluation.id; //========== public constants ==========// this.ratingQualities = ["", "Worst","Poor","Average","Good","Best"]; this.id = Evaluation.id; this.ratingGroupName = "evaluationGroup" + this.id; this.textID = "evaluationText" + this.id; this.type = type; this.data = data; this.evttime = evttime; //========== public read-only members ==========// this.text = ""; this.rating = -1; //========== public methods ==========// this.html = html; this.recordText = recordText; this.writeRating = writeRating; //========== private methods ==========// this.smallScaleForm = smallScaleForm; this.evaluationForm = evaluationForm; //========== function definitions ==========// /** * @return The html representation of this evaluation. */ function html() { var text = "" + "" + "" + "" + "" + "
" + type + " Evaluation
"; for (i = 0; i < this.data.length; i += 2) { text += "" + "" + "" + ""; } /* Displays the comment input field text += ""; */ text += "" /* Displays the ranking bubbles */ text += "" + "" text += ""; text += ""; text += "
" + this.data[i] + "" + this.data[i+1] + "
" + "" + "
" + this.evaluationForm() + "" + "" + "
"; text += "
"; return text; } /** * Write an individual rating to a log file */ function writeRating(givenRating) { // Build a string for the log in this format: //03:01:00, Evaluation, CMS, Poor logString = this.evttime.format() + ", Evaluation, " + this.type + ", " + this.ratingQualities[givenRating] + "\n" postMessage(logString) } /** * Stores the text in the written response text box. */ function recordText() { this.text = events.doc.getElementById(this.textID).value; // Build a string for the log in this format: //03:01:00, Evaluation, CMS, 'comment' logString = this.evttime.format() + ", Evaluation, " + this.type + ", '" + this.text + "'\n" postMessage(logString) // Change the text color as feedback to user // events.doc.getElementById(this.textID).style.color = "lightgrey"; } function postMessage(logString) { // Using POST to send the data var xhr = new XMLHttpRequest(); xhr.open("POST", "/cgi-bin/appendRatingToLog.py", true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); // send the collected data xhr.send("msg="+logString); } /** * @return The html for appropriate evaluation form for grading. */ function evaluationForm() { return this.smallScaleForm(); } /** * @return The html for a 1-5 grading scale. */ function smallScaleForm() { return "
" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
"+this.ratingQualities[5]+""+this.ratingQualities[4]+""+this.ratingQualities[3]+""+this.ratingQualities[2]+""+this.ratingQualities[1]+"
" + "
"; } }