Changeset 176 for Dev/trunk/js/questionEditorScripts.js
- Timestamp:
- 12/05/11 14:58:27 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/js/questionEditorScripts.js
r175 r176 1 ////////////////////// 2 /* HELPER FUNCTIONS */ 3 ////////////////////// 4 5 function hasClass(ele,cls) { 6 if (ele.className) 7 return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); 8 } 9 10 function addClass(ele,cls) { 11 if (!this.hasClass(ele,cls)) ele.className += " "+cls; 12 } 13 14 function removeClass(ele,cls) { 15 if (hasClass(ele,cls)) { 16 var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); 17 ele.className=ele.className.replace(reg,' '); 18 } 19 } 20 21 ////////////////////////// 22 /* END HELPER FUNCTIONS */ 23 ////////////////////////// 24 25 1 26 var qUID, parentObjectUID, qName, qTag, qType, qAnswerLength; 2 27 3 28 function selectAnswerType(){ 4 5 29 var selectBox = document.getElementById("questionType"); 6 30 if (selectBox.value != undefined && selectBox.value != "") { … … 10 34 return; 11 35 } 12 13 36 removeWrongAnswerFields(selectBox); 14 15 37 switch (qType) { 16 38 case "int": … … 38 60 if (id != undefined) newElement.id = id; 39 61 if (cl != undefined) newElement.className = cl; 40 if (value != undefined) newElement.value = value; 62 if (value != undefined) { 63 newElement.value = value; 64 newElement.text = value; 65 } 41 66 return newElement; 67 } 68 69 function createNewInputLabel(text, target) { 70 var newLabel = document.createElement("label"); 71 if (target) newLabel.setAttribute("for",target); 72 newLabel.innerHTML = text; 73 return newLabel; 42 74 } 43 75 … … 48 80 } 49 81 82 function updateIdentifier() { 83 var identField = document.getElementById("questionIdentifierField"); 84 if (identField.value == undefined && identField.value == "") { 85 return; 86 } 87 var headerField = document.getElementById("header_identifier"); 88 headerField.innerHTML = identField.value; 89 } 50 90 51 91 92 /////////////////// 93 /* INT SELECTION */ 94 /////////////////// 52 95 53 96 function selectIntType() { 54 97 var selectBox = document.getElementById("questionType"); 55 98 var content = document.getElementById("questionEditor_questionParams"); 99 // Add minimum value input 56 100 var minValueBox = createNewElement("input","text","minValueBox", "questionParamField", null); 57 content.innerHTML += "<br />Min value: "; 101 var minValueBoxLabel = createNewInputLabel("Minimum value:", "minValueBox"); 102 addClass(minValueBoxLabel, "formLineBreak"); 103 content.appendChild(minValueBoxLabel); 58 104 content.appendChild(minValueBox); 105 // Add maximum value input 59 106 var maxValueBox = createNewElement("input", "text", "maxValueBox", "questionParamField", null); 60 content.innerHTML += "<br />Max value: "; 107 var maxValueBoxLabel = createNewInputLabel("Maximum value:","maxValueBox"); 108 addClass(maxValueBoxLabel, "formLineBreak"); 109 content.appendChild(maxValueBoxLabel); 61 110 content.appendChild(maxValueBox); 62 63 // set the selected value, because adding a DOM element to the parent element resets the selected value.64 for (var i = 0; i < selectBox.options.length; i++) {65 if (selectBox.options[i].value == "int") {66 selectBox.selectedValue = i;67 selectBox.selectedText = "Integer";68 // DIT WERKT NOG NIET, HIJ SELECTEERT HEM NIET, OOK AL IS SELECTED = TRUE69 // MET ANDERE WOORDEN: WTF.70 }71 }72 111 } 73 112 74 113 ///////////////////// 114 /* SCALE SELECTION */ 115 ///////////////////// 75 116 76 117 function selectScaleType() { 77 debugger; 78 var selectBox = document.getElementById("questionType"); 118 // I heard you like walls of text! 79 119 var content = document.getElementById("questionEditor_questionParams"); 120 // Add number of choices input 80 121 var numChoicesBox = createNewElement("select", null, "numChoicesBox","questionParamField",null); 81 content.innerHTML += "<br />Scale size: ";122 var numChoicesBoxLabel = createNewInputLabel("Scale size:","numChoicesBox"); 82 123 for (var i = 0; i < 10; i++) { 83 124 var option = createNewElement("option"); … … 86 127 numChoicesBox.appendChild(option); 87 128 } 129 addClass(numChoicesBoxLabel, "formLineBreak"); 130 content.appendChild(numChoicesBoxLabel); 88 131 content.appendChild(numChoicesBox); 89 numChoicesBox.addEventListener("change", selectScaleSize, false); 132 // Add legends enabled input 133 var legendsEnabledCheckBox = createNewElement("input","checkbox","legendsEnabledCheckbox","questionParamField",null); 134 var legendsEnabledCheckBoxLabel = createNewInputLabel("Enable legends","legendsEnabledCheckBox"); 135 addClass(legendsEnabledCheckBoxLabel, "formLineBreak"); 136 content.appendChild(legendsEnabledCheckBoxLabel); 137 content.appendChild(legendsEnabledCheckBox); 138 // Add legend labels boxes 139 var upperLegendBox = createNewElement("input","text","upperLegendBox","questionParamField"); 140 var lowerLegendBox = createNewElement("input","text","lowerLegendBox","questionParamField"); 141 var lowerLegendBoxLabel = createNewInputLabel("Lower legend","lowerLegendBox"); 142 var upperLegendBoxLabel = createNewInputLabel("Upper legend","upperLegendBox"); 143 addClass(lowerLegendBoxLabel,"formLineBreak"); 144 content.appendChild(lowerLegendBoxLabel); 145 content.appendChild(lowerLegendBox); 146 addClass(upperLegendBoxLabel,"formLineBreak"); 147 content.appendChild(upperLegendBoxLabel); 148 content.appendChild(upperLegendBox); 149 // Disable these boxes, since the checkbox is unchecked by default 150 lowerLegendBox.disabled = true; 151 upperLegendBox.disabled = true; 152 if (legendsEnabledCheckBox.addEventListener) { 153 legendsEnabledCheckBox.addEventListener("click", toggleScaleLegends, true); 154 } 90 155 } 91 156 92 function selectScaleSize() { 93 var numChoicesBox = document.getElementById("numChoicesBox"); 157 function toggleScaleLegends() { 94 158 var content = document.getElementById("questionEditor_questionParams"); 95 for (var i = 0; i < numChoicesBox.value; i++) { 96 var newBullet = createNewElement("input", "radio", "bullet"+i, "questionParamField","i"); 97 content.appendChild(newBullet); 159 var checkbox = document.getElementById("legendsEnabledCheckbox"); 160 var upperLegendBox = document.getElementById("upperLegendBox"); 161 var lowerLegendBox = document.getElementById("lowerLegendBox"); 162 if (checkbox.checked == true) { 163 upperLegendBox.disabled = false; 164 lowerLegendBox.disabled = false; 165 } 166 else { 167 upperLegendBox.disabled = true; 168 lowerLegendBox.disabled = true; 169 } 170 } 171 172 /////////////////////////////// 173 /* MULTIPLE CHOICE SELECTION */ 174 /////////////////////////////// 175 176 function selectChoiceType() { 177 var selectionBox = document.getElementById("questionType"); 178 var content = document.getElementById("questionEditor_questionParams"); 179 } 180 181 function resizeTextArea() { 182 var textArea = document.getElementById("questionEditor_bodyText"); 183 if (document.getElementById("hiddenScalingDiv")) { 184 var hiddenDiv = document.getElementById("hiddenScalingDiv"); 185 } 186 else { 187 var hiddenDiv = document.createElement("div"); 188 hiddenDiv.style.visibility = "hidden"; 189 textArea.appendChild(hiddenDiv); 98 190 } 99 191 192 debugger; 193 hiddenDiv.innerHTML = ""; 194 var userText = textArea.firstChild.valueOf().value; 195 alert(userText); 100 196 } 101
Note: See TracChangeset
for help on using the changeset viewer.