////////////////////// /* HELPER FUNCTIONS */ ////////////////////// function hasClass(ele,cls) { if (ele.className) return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); } function addClass(ele,cls) { if (!this.hasClass(ele,cls)) ele.className += " "+cls; } function removeClass(ele,cls) { if (hasClass(ele,cls)) { var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); ele.className=ele.className.replace(reg,' '); } } ////////////////////////// /* END HELPER FUNCTIONS */ ////////////////////////// var qUID, parentObjectUID, qName, qTag, qType, qAnswerLength; function selectAnswerType(){ var selectBox = document.getElementById("questionType"); if (selectBox.value != undefined && selectBox.value != "") { qType = selectBox.value; } else { return; } removeWrongAnswerFields(selectBox); switch (qType) { case "int": selectIntType(); break; case "scale": selectScaleType(); break; case "choice": //selectChoiceType(); break; case "text": //selectTextType(); break; default: alert("Invalid answer type selected!"); break; } } function createNewElement(tag, type, id, cl, value) { var newElement = document.createElement(tag); if (type != undefined) newElement.type = type; if (id != undefined) newElement.id = id; if (cl != undefined) newElement.className = cl; if (value != undefined) { newElement.value = value; newElement.text = value; } return newElement; } function createNewInputLabel(text, target) { var newLabel = document.createElement("label"); if (target) newLabel.setAttribute("for",target); newLabel.innerHTML = text; return newLabel; } function removeWrongAnswerFields(el) { while (el.nextSibling) { el.parentNode.removeChild(el.nextSibling); } } function updateIdentifier() { var identField = document.getElementById("questionIdentifierField"); if (identField.value == undefined && identField.value == "") { return; } var headerField = document.getElementById("header_identifier"); headerField.innerHTML = identField.value; } /////////////////// /* INT SELECTION */ /////////////////// function selectIntType() { var selectBox = document.getElementById("questionType"); var content = document.getElementById("questionEditor_questionParams"); // Add minimum value input var minValueBox = createNewElement("input","text","minValueBox", "questionParamField", null); var minValueBoxLabel = createNewInputLabel("Minimum value:", "minValueBox"); addClass(minValueBoxLabel, "formLineBreak"); content.appendChild(minValueBoxLabel); content.appendChild(minValueBox); // Add maximum value input var maxValueBox = createNewElement("input", "text", "maxValueBox", "questionParamField", null); var maxValueBoxLabel = createNewInputLabel("Maximum value:","maxValueBox"); addClass(maxValueBoxLabel, "formLineBreak"); content.appendChild(maxValueBoxLabel); content.appendChild(maxValueBox); } ///////////////////// /* SCALE SELECTION */ ///////////////////// function selectScaleType() { // I heard you like walls of text! var content = document.getElementById("questionEditor_questionParams"); // Add number of choices input var numChoicesBox = createNewElement("select", null, "numChoicesBox","questionParamField",null); var numChoicesBoxLabel = createNewInputLabel("Scale size:","numChoicesBox"); for (var i = 0; i < 10; i++) { var option = createNewElement("option"); option.text = i+1; option.value = i+1; numChoicesBox.appendChild(option); } addClass(numChoicesBoxLabel, "formLineBreak"); content.appendChild(numChoicesBoxLabel); content.appendChild(numChoicesBox); // Add legends enabled input var legendsEnabledCheckBox = createNewElement("input","checkbox","legendsEnabledCheckbox","questionParamField",null); var legendsEnabledCheckBoxLabel = createNewInputLabel("Enable legends","legendsEnabledCheckBox"); addClass(legendsEnabledCheckBoxLabel, "formLineBreak"); content.appendChild(legendsEnabledCheckBoxLabel); content.appendChild(legendsEnabledCheckBox); // Add legend labels boxes var upperLegendBox = createNewElement("input","text","upperLegendBox","questionParamField"); var lowerLegendBox = createNewElement("input","text","lowerLegendBox","questionParamField"); var lowerLegendBoxLabel = createNewInputLabel("Lower legend","lowerLegendBox"); var upperLegendBoxLabel = createNewInputLabel("Upper legend","upperLegendBox"); addClass(lowerLegendBoxLabel,"formLineBreak"); content.appendChild(lowerLegendBoxLabel); content.appendChild(lowerLegendBox); addClass(upperLegendBoxLabel,"formLineBreak"); content.appendChild(upperLegendBoxLabel); content.appendChild(upperLegendBox); // Disable these boxes, since the checkbox is unchecked by default lowerLegendBox.disabled = true; upperLegendBox.disabled = true; if (legendsEnabledCheckBox.addEventListener) { legendsEnabledCheckBox.addEventListener("click", toggleScaleLegends, true); } } function toggleScaleLegends() { var content = document.getElementById("questionEditor_questionParams"); var checkbox = document.getElementById("legendsEnabledCheckbox"); var upperLegendBox = document.getElementById("upperLegendBox"); var lowerLegendBox = document.getElementById("lowerLegendBox"); if (checkbox.checked == true) { upperLegendBox.disabled = false; lowerLegendBox.disabled = false; } else { upperLegendBox.disabled = true; lowerLegendBox.disabled = true; } } /////////////////////////////// /* MULTIPLE CHOICE SELECTION */ /////////////////////////////// function selectChoiceType() { var selectionBox = document.getElementById("questionType"); var content = document.getElementById("questionEditor_questionParams"); } function resizeTextArea() { var textArea = document.getElementById("questionEditor_bodyText"); if (document.getElementById("hiddenScalingDiv")) { var hiddenDiv = document.getElementById("hiddenScalingDiv"); } else { var hiddenDiv = document.createElement("div"); hiddenDiv.style.visibility = "hidden"; textArea.appendChild(hiddenDiv); } debugger; hiddenDiv.innerHTML = ""; var userText = textArea.firstChild; alert(userText); }