/* * Scripts needed for operation of the survey editor */ var surveyEditor = { uid: "", // the uid of the currently opened survey title: "No title", // the name of the currently opened survey description: "No description", // the description of the currently opened survey numQuestions: 0, // the number of questions contained in this survey questions: [], // the array containing question objectliterals/uids state: { // used for checks in onClick events editing: false, // whether or not a question is currently being edited editUid: "" // the uid of the question being edited, if any } } // Deze scripts worden gedeeld door bijna alle editors, en deze moeten dan ook in een common scripts // file komen te staan in plaats van in elk document weer opnieuw invoeren. // Dit gaat ongetwijfeld conflicten opleveren als er in een van de functies iets veranderd moet worden. function stringToArray(s, c) { var a = s.split(c); for (var i = 0; i < a.length; i++) { // remove empty items if (a[i] == "") { a.splice(i, 1); i--; } } return a; } function arrayToString(a, c) { var s = ""; for (var i = 0; i < a.length; i++) { if (a[i] != "") { s += a[i]+c; } } return s; } function loadSurvey() { /* * Take the values from the hiddenfields on the page, load them into the object literal defined at the top of this script, * Then delete these fields from the HTML page, since they are not needed anymore. * This is possibly more secure than leaving them on the page, and results in cleaner HTML markup */ debugger; var fTitle = document.getElementById("surveyTitle"); if (fTitle != undefined && fTitle.value != "") { surveyEditor.title = fTitle.value; } else { surveyEditor.title = "Undefined title"; } var fNumQuestions = document.getElementById("numQuestions"); if (fNumQuestions != undefined && fNumQuestions.value != "") { surveyEditor.numQuestions = fNumQuestions; } else { surveyEditor.numQuestions = 0; return; } var fQuestions = document.getElementById("questionUids"); if (fQuestions != undefined && surveyEditor.numQuestions > 0) { surveyEditor.questions = stringToArray(fQuestions.value, ","); if (surveyEditor.questions.length != surveyEditor.numQuestions) { alert("numQuestions and the questions array passed do not match!"); return; } } else { alert("Questions field not found!"); return; } } function drawQuestions(firstTime) { var length = surveyEditor.questions.length; if (length <= 0) return; var container = document.getElementById("surveyEditorContent"); if (firstTime == true) { // Loop through questions, add a new smallFrame div for each question with id=question->uid // do this via AJAX calls, returnQuestion.php // dependencies: stringToArray/arrayToString var requestString = "uids="; requestString += arrayToString(surveyEditor.questions, ","); newAjaxRequest(requestString, "returnQuestionDisplay.php", function(result) { //var holderDiv = document.createElement("div"); //holderDiv.innerHTML = result.responseText; container.innerHTML = result.responseText; }); } }