Changeset 236 for Dev/branches/jos-branch/js/questionEditorScripts.js
- Timestamp:
- 01/16/12 23:12:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/jos-branch/js/questionEditorScripts.js
r235 r236 1 // Old, should not be used anymore after class-based QuestionEditor() is finished!!!!!2 var qUID, parentObjectUID, qName, qTag, qType, qAnswerLength;3 4 1 var questionEditor = new QuestionEditor(); 5 6 function selectAnswerType(){7 var selectBox = document.getElementById("questionType");8 if (selectBox.value != undefined && selectBox.value != "") {9 qType = selectBox.value;10 }11 else {12 return;13 }14 removeWrongAnswerFields(selectBox);15 switch (qType) {16 case "int":17 selectIntType();18 break;19 case "scale":20 selectScaleType();21 break;22 case "choice":23 //selectChoiceType();24 break;25 case "text":26 //selectTextType();27 break;28 default:29 alert("Invalid answer type selected!");30 break;31 }32 33 }34 2 35 3 function createNewElement(tag, type, id, cl, value) { … … 53 21 } 54 22 55 function removeWrongAnswerFields(el) {56 while (el.nextSibling) {57 el.parentNode.removeChild(el.nextSibling);58 }59 }60 61 23 function updateIdentifier() { 62 24 var identField = document.getElementById("questionIdentifierField"); … … 68 30 } 69 31 70 71 /////////////////////72 /* SCALE SELECTION */73 /////////////////////74 75 function selectScaleType() {76 // I heard you like walls of text!77 var content = document.getElementById("questionEditor_questionParams");78 // Add number of choices input79 var numChoicesBox = createNewElement("select", null, "numChoicesBox","questionParamField",null);80 var numChoicesBoxLabel = createNewInputLabel("Scale size:","numChoicesBox");81 for (var i = 0; i < 10; i++) {82 var option = createNewElement("option");83 option.text = i+1;84 option.value = i+1;85 numChoicesBox.appendChild(option);86 }87 addClass(numChoicesBoxLabel, "formLineBreak");88 content.appendChild(numChoicesBoxLabel);89 content.appendChild(numChoicesBox);90 // Add legends enabled input91 var legendsEnabledCheckBox = createNewElement("input","checkbox","legendsEnabledCheckbox","questionParamField",null);92 var legendsEnabledCheckBoxLabel = createNewInputLabel("Enable legends","legendsEnabledCheckBox");93 addClass(legendsEnabledCheckBoxLabel, "formLineBreak");94 content.appendChild(legendsEnabledCheckBoxLabel);95 content.appendChild(legendsEnabledCheckBox);96 // Add legend labels boxes97 var upperLegendBox = createNewElement("input","text","upperLegendBox","questionParamField");98 var lowerLegendBox = createNewElement("input","text","lowerLegendBox","questionParamField");99 var lowerLegendBoxLabel = createNewInputLabel("Lower legend","lowerLegendBox");100 var upperLegendBoxLabel = createNewInputLabel("Upper legend","upperLegendBox");101 addClass(lowerLegendBoxLabel,"formLineBreak");102 content.appendChild(lowerLegendBoxLabel);103 content.appendChild(lowerLegendBox);104 addClass(upperLegendBoxLabel,"formLineBreak");105 content.appendChild(upperLegendBoxLabel);106 content.appendChild(upperLegendBox);107 // Disable these boxes, since the checkbox is unchecked by default108 lowerLegendBox.disabled = true;109 upperLegendBox.disabled = true;110 if (legendsEnabledCheckBox.addEventListener) {111 legendsEnabledCheckBox.addEventListener("click", toggleScaleLegends, true);112 }113 }114 115 function toggleScaleLegends() {116 var content = document.getElementById("questionEditor_questionParams");117 var checkbox = document.getElementById("legendsEnabledCheckbox");118 var upperLegendBox = document.getElementById("upperLegendBox");119 var lowerLegendBox = document.getElementById("lowerLegendBox");120 if (checkbox.checked == true) {121 upperLegendBox.disabled = false;122 lowerLegendBox.disabled = false;123 }124 else {125 upperLegendBox.disabled = true;126 lowerLegendBox.disabled = true;127 }128 }129 130 ///////////////////////////////131 /* MULTIPLE CHOICE SELECTION */132 ///////////////////////////////133 134 function selectChoiceType() {135 var selectionBox = document.getElementById("questionType");136 var content = document.getElementById("questionEditor_questionParams");137 }138 139 function resizeTextArea() {140 var textArea = document.getElementById("questionEditor_bodyText");141 if (document.getElementById("hiddenScalingDiv")) {142 var hiddenDiv = document.getElementById("hiddenScalingDiv");143 }144 else {145 var hiddenDiv = document.createElement("div");146 hiddenDiv.style.visibility = "hidden";147 textArea.appendChild(hiddenDiv);148 }149 150 debugger;151 hiddenDiv.innerHTML = "";152 var userText = textArea.firstChild;153 alert(userText);154 }155 32 156 33 ////////////////////////////////////////// … … 164 41 this.element = null; // The parent div element containing the questionEditor 165 42 this.paramsElement = null; // The parent parameters element where all the input sets will be located 166 this.paramSets = null; // The currently enabled input sets to be displayed in the paramsElement 43 this.paramSets = null; // The currently enabled input sets to be displayed in the paramsElement. 44 //Currently only supports a single param set (based on answer type), but functionality will scale to multiple sets as needed. 167 45 168 46 // Methods … … 205 83 206 84 var basicContainer = ce("div"); 207 basicContainer. className= "basicInputs";85 basicContainer.id = "basicInputs"; 208 86 209 87 var qeCodeField = createNewElement("input", "text", "qeCodeField", "qeParamField", null); … … 276 154 } 277 155 156 switch (ge("qeTypeField").value) { 157 case "int": 158 request.answerType = "int"; 159 request.minValue = parseInt(ge("qeMinValueField").value); 160 request.maxValue = parseInt(ge("qeMaxValueField").value); 161 break; 162 case "scale": 163 request.answerType = "scale"; 164 request.numChoices = parseInt(ge("qeNumChoicesField").value); 165 request.legendsEnabled = ge("qeLegendsEnabledField").checked; 166 request.lowerLegend = ge("qeLowerLegendField").value; 167 request.upperLegend = ge("qeUpperLegendField").value; 168 break; 169 case "choice": 170 request.answerType = "choice"; 171 break; 172 case "text": 173 request.answerType = "text"; 174 break; 175 } 176 278 177 newAjaxRequest(requestString, "createObject.php", function(result){ 279 178 // Display a success message, or throw an error. 280 }, true);179 }, true); 281 180 } 282 181 this.reset = function() { … … 318 217 // Loop through all input containers in the paramsField 319 218 for (var n = 0; n < me.paramsElement.childNodes.length; n++) { 320 if (me.paramsElement.childNodes[n]. className== "basicInputs") continue;321 // Check if the class(inputSet) is currently in paramSets322 if (me.paramSets.indexOf(me.paramsElement.childNodes[n]. className) < 0) {219 if (me.paramsElement.childNodes[n].id == "basicInputs") continue; 220 // Check if the id (inputSet) is currently in paramSets 221 if (me.paramSets.indexOf(me.paramsElement.childNodes[n].id) < 0) { 323 222 me.paramsElement.childNodes[n].parentNode.removeChild(me.paramsElement.childNodes[n]); 324 223 n--; … … 335 234 336 235 me.checkInputSets(); 337 236 237 var container = ce("div"); 238 container.id = "int_basic"; 239 338 240 var qeMinValueField = createNewElement("input", "text", "qeMinValueField", "qeParamField", null); 339 241 var qeMinValueField_lbl = createNewInputLabel("Minimum value: ", "qeMinValueField", "l"); 340 242 var qeMaxValueField = createNewElement("input", "text", "qeMaxValueField", "qeParamField", null); 341 243 var qeMaxValueField_lbl = createNewInputLabel("Maximum value: ", "qeMaxValueField", "l"); 342 var container = ce("div"); 343 container.className = "int_basic"; 244 344 245 container.appendChild(qeMinValueField_lbl); 345 246 container.appendChild(qeMinValueField); … … 358 259 359 260 var container = ce("div"); 360 container. className= "scale_basic";261 container.id = "scale_basic"; 361 262 362 263 // Number of choices SELECT … … 366 267 for (var n = 2; n < 11; n++) { 367 268 var o = ce("option"); 368 o.value = n -1;369 o.text = n -1;269 o.value = n; 270 o.text = n; 370 271 numChoicesField.appendChild(o); 371 272 } … … 391 292 } 392 293 this.type_Text = function () { 393 294 if (me.paramSets.indexOf("text_basic") < 0) { 295 me.paramSets = new Array("text_basic"); 296 } 297 else return; 298 299 me.checkInputSets(); 300 301 var container = ce("div"); 302 container.id="text_basic"; 394 303 } 395 304 this.type_Choice = function() { 396 debugger;397 if (me.paramSets.indexOf("choice_basic") ) {305 //debugger; 306 if (me.paramSets.indexOf("choice_basic") < 0) { 398 307 me.paramSets = new Array("choice_basic"); 399 308 } … … 403 312 404 313 var container = ce("div"); 405 container. className= "choice_basic";314 container.id = "choice_basic"; 406 315 // num options SELECT 407 316 var numOptionsSelect = createNewElement("select", null, "qeNumOptionsField", "qeParamField", null); … … 409 318 for (var n = 2; n < 11; n++) { 410 319 var o = ce("option"); 411 o.value = n -1;412 o.text = n -1;320 o.value = n; 321 o.text = n; 413 322 numOptionsSelect.appendChild(o); 414 323 } 415 324 container.appendChild(numOptionsSelect_lbl); 416 325 container.appendChild(numOptionsSelect); 417 326 numOptionsSelect.addEventListener("change", me.type_Choice_CheckAnswerFields, true); 327 328 var allowMultiple = createNewElement("input", "checkbox", "qeMultipleAnswersField", "qeParamField", null); 329 var allowMultiple_lbl = createNewInputLabel("Allow multiple answers", "qeMultipleAnswersField", "l"); 330 container.appendChild(allowMultiple_lbl); 331 container.appendChild(allowMultiple); 332 333 var answersField = ce("div"); 334 answersField.className = "qeParamFieldset"; 335 answersField.id = "qeParamsAnswerFieldset" 336 container.appendChild(answersField); 337 418 338 me.paramsElement.appendChild(container); 419 } 420 339 me.type_Choice_CheckAnswerFields(); 340 } 341 this.type_Choice_CheckAnswerFields = function() { 342 debugger; 343 var container = ge("qeParamsAnswerFieldset"); 344 var numAnswers = parseInt(document.getElementById("qeNumOptionsField").value, 10); 345 var numAnswerFields = 0; 346 { 347 for (var i = container.childNodes.length-1; i >= 0; i--) { 348 if (container.childNodes[i].className = "qeChoiceAnswerGroup") { 349 numAnswerFields++; 350 } 351 } 352 353 } 354 355 // If there already are the correct number of answer fields, exit the function 356 if (numAnswers == numAnswerFields) return; 357 else if (numAnswers > numAnswerFields) { 358 // Extra inputs need to be added 359 var n = numAnswers - numAnswerFields; 360 for (var x = 0; x < n; x++) { 361 var group = ce("div"); 362 group.className = "qeChoiceAnswerGroup"; 363 var field = createNewElement("input", "text", "qeAnswerField"+(numAnswerFields+x), "qeParamField", null); 364 var field_lbl = createNewInputLabel((numAnswerFields+x), "qeAnswerField"+(numAnswerFields+x), "l"); 365 366 group.appendChild(field_lbl); 367 group.appendChild(field); 368 container.appendChild(group); 369 } 370 } 371 else if (numAnswers < numAnswerFields) { 372 // There are too many inputs and some need to be removed. Start at the end! 373 // TODO: This is SO inefficient. There has to be a better way, perhaps adding elements to an array? 374 // TODO: Another approach would be to use the previousSibling property as a way to prevent having to loop through the entire container tree every time an object needs to be removed. 375 var n = numAnswerFields-numAnswers; 376 for (var x = 0; x < n; x++) { 377 for (var y = container.childNodes.length-1; y >= 0; y--) { 378 if (container.childNodes[y].className == "qeChoiceAnswerGroup") { 379 container.removeChild(container.childNodes[y]); 380 break; 381 } 382 } 383 } 384 } 385 } 386 421 387 // Editing 422 388 this.editQuestion = function(uid) {
Note: See TracChangeset
for help on using the changeset viewer.