Changeset 237 for Dev/branches/jos-branch/js/questionEditorScripts.js
- Timestamp:
- 01/17/12 18:17:51 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/jos-branch/js/questionEditorScripts.js
r236 r237 21 21 } 22 22 23 function updateIdentifier() {24 var identField = document.getElementById("questionIdentifierField");25 if (identField.value == undefined && identField.value == "") {26 return;27 }28 var headerField = document.getElementById("header_identifier");29 headerField.innerHTML = identField.value;30 }31 32 33 //////////////////////////////////////////34 /* QUESTION EDITOR CLASS BASED APPROACH */35 //////////////////////////////////////////36 37 23 function QuestionEditor() { 38 24 // Properties … … 47 33 // Basic functionality 48 34 this.setValues = function(arguments) { 49 var question = JSON.parse(arguments); 35 debugger; 36 var question = JSON.parse(arguments)[0]; 37 var qeTypeField = ge("qeTypeField"); 38 ge("qeCodeField").value = question.code; 39 ge("qeBodyTextField").value = question.description; 40 switch (question.type.toLowerCase()) { 41 case "int": 42 // First make sure all the necessary fields are present 43 me.type_Integer(); 44 // Then fill them in using the available data 45 qeTypeField.value = "int"; 46 ge("qeMinValueField").value = question.minValue; 47 ge("qeMaxValueField").value = question.maxValue; 48 break; 49 case "scale": 50 me.type_Scale(); 51 qeTypeField.value = "scale"; 52 ge("qeNumChoicesField").value = question.numChoices; 53 ge("qeLegendsEnabledField").checked = question.legendsEnabled; 54 ge("qeLowerLegendField").value = question.lowerLegend; 55 ge("qeUpperLegendField").value = question.upperLegend; 56 break; 57 case "choice": 58 me.type_Choice(); 59 qeTypeField.value = "choice"; 60 ge("qeNumOptionsFIeld").value = question.numOptions; 61 ge("qeMultipleAnswersField").value = question.multipleAnswers; 62 // then some more to add textboxes (qeParamAnswerGroup) for all the possble choices. 63 // Maybe a central version that appends these groups/textinputs? Maybe not, though. Don't want stuff too abstracted... 64 break; 65 case "text": 66 me.type_Text(); 67 qeTypeField.value = "text"; 68 ge("qeTextMaxLengthField").value = question.maxTextLength; 69 break; 70 71 } 50 72 } 51 73 this.init = function() { … … 150 172 this.save = function() { 151 173 var request = { 152 "title": ge("qeTitleField").value, 153 "type": ge("qeTypeField").value 174 "title": ge("qeTitleField").innerHTML, 175 "code": ge("qeCodeField").value, 176 "description": ge("qeBodyTextField").value 154 177 } 155 178 … … 158 181 request.answerType = "int"; 159 182 request.minValue = parseInt(ge("qeMinValueField").value); 183 if (request.minValue == "NaN") request.minValue = -1; // Is this the correct way to do this? 160 184 request.maxValue = parseInt(ge("qeMaxValueField").value); 185 if (request.maxValue == "NaN") request.maxValue = -1; 186 // Include error checking and form validation!! 161 187 break; 162 188 case "scale": … … 166 192 request.lowerLegend = ge("qeLowerLegendField").value; 167 193 request.upperLegend = ge("qeUpperLegendField").value; 194 // Include error checking and form validation!! 168 195 break; 169 196 case "choice": 170 197 request.answerType = "choice"; 198 request.multipleAnswers = ge("qeMultipleAnswersField").checked; 199 request.possibleAnswers = array(); 200 var answerFieldset = ge("qeParamsAnswerFieldset"); 201 var count = ge("qeNumOptionsField").value; 202 203 for (var i = 0; i < count; i++) { 204 var el = ge("qeAnswerField"+i); 205 request.possibleAnswers.push(el.value); 206 } 207 // Include error checking and form validation!! 171 208 break; 172 209 case "text": 173 210 request.answerType = "text"; 174 break; 175 } 176 177 newAjaxRequest(requestString, "createObject.php", function(result){ 178 // Display a success message, or throw an error. 179 }, true); 211 request.maxTextLength = ge("qeTextMaxLength").value; 212 // Include error checking and form validation!! 213 break; 214 } 215 216 requestString = "args="+JSON.stringify(request); 217 218 newAjaxRequest(requestString, "setQuestion.php", function(result){ 219 // Then add the returned uid, if existing, to the sequencer.survey.questions array and set it for update 220 debugger; 221 var response = JSON.parse(result.responseText); 222 console.log(response); 223 if (response.created == true) { 224 if (response.uid) { 225 // Created a new question, add it to the sequencer content array and set it for an update 226 sequencer.survey.questions.uids.push(response.uid); 227 sequencer.survey.questions.upToDate.push(false); 228 } 229 else { 230 alert("ERROR!"); 231 } 232 } else { 233 if (response.uid){ 234 // Edited an existing question that was already in the sequencer content. Set it for an update 235 sequencer.survey.questions.upToDate[sequencer.survey.questions.uids.indexOf(response.uid)] = false; 236 } 237 else { 238 alert("ERROR!"); 239 } 240 } 241 242 243 // Then remove the editor from the sequencer content, so that it can be replaced with the correct question view. 244 me.element.parentNode.removeChild(me.element); 245 sequencer.state.editing = false; 246 updateSequencer(); 247 }, true); 248 } 249 this.discard = function() { 250 me.element.parentNode.removeChild(me.element); 251 me.init(); 252 sequencer.state.loaded = true; 253 sequencer.state.editing = false; 180 254 } 181 255 this.reset = function() { … … 340 414 } 341 415 this.type_Choice_CheckAnswerFields = function() { 342 debugger;343 416 var container = ge("qeParamsAnswerFieldset"); 344 417 var numAnswers = parseInt(document.getElementById("qeNumOptionsField").value, 10); … … 358 431 // Extra inputs need to be added 359 432 var n = numAnswers - numAnswerFields; 360 for (var x = 0; x < n; x++) {433 for (var x = 1; x < n+1; x++) { 361 434 var group = ce("div"); 362 435 group.className = "qeChoiceAnswerGroup"; … … 387 460 // Editing 388 461 this.editQuestion = function(uid) { 462 debugger; 389 463 if (sequencer.state.editing == true) return; 390 464 if (sequencer.state.loaded == false) return; 391 465 sequencer.state.editing = true; 392 393 var request = { 394 "type": "Question", 395 "uid": uid 396 } 397 466 sequencer.state.loaded = false; 467 468 var request = new Array({ 469 type: "Question", 470 uid: uid 471 }); 472 me.init(); 473 var oldElement = ge(uid); 474 if (oldElement) { 475 // There really should be.... I don't know why I am doing this check... 476 oldElement.parentNode.replaceChild(me.element, oldElement); 477 } 398 478 var requestString = "args="+JSON.stringify(request); 399 sequencer.state.loaded = false; 400 newAjaxRequest(requestString, getObject.php, function(result){ 479 newAjaxRequest(requestString, "getObject.php", function(result){ 401 480 // Once results are in 402 questionEditor.setValues(result.responseText);481 me.setValues(result.responseText); 403 482 sequencer.state.loaded = true; 404 483 }, true); … … 406 485 this.createNewQuestion = function() { 407 486 if (sequencer.state.editing == true) return; 408 if (sequencer.state.loading == true) return;487 if (sequencer.state.loading == false) return; 409 488 sequencer.state.editing = true; 410 489 … … 414 493 } 415 494 } 495 496 // IT LIIIIIIVESSSSS 497 // TODO: Add database fields for all the necessary question parameters. Maybe only one question parameter property that holds all the settings, then read it out in javascript? 498 // Why have a question Description? Is this even necessary? 499 // Needed properties: 500 // Also not exactly sure what "question->category" is for. Is this one of those questionSet things that Julia was talking about? 501 //
Note: See TracChangeset
for help on using the changeset viewer.