[178] | 1 | /* |
---|
| 2 | * Scripts needed for operation of the survey editor |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | var surveyEditor = { |
---|
| 6 | uid: "", // the uid of the currently opened survey |
---|
| 7 | title: "No title", // the name of the currently opened survey |
---|
| 8 | description: "No description", // the description of the currently opened survey |
---|
| 9 | numQuestions: 0, // the number of questions contained in this survey |
---|
| 10 | questions: [], // the array containing question objectliterals/uids |
---|
| 11 | state: { // used for checks in onClick events |
---|
| 12 | editing: false, // whether or not a question is currently being edited |
---|
| 13 | editUid: "" // the uid of the question being edited, if any |
---|
| 14 | } |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | function loadSurvey() { |
---|
| 20 | |
---|
| 21 | /* |
---|
| 22 | * Take the values from the hiddenfields on the page, load them into the object literal defined at the top of this script, |
---|
| 23 | * Then delete these fields from the HTML page, since they are not needed anymore. |
---|
| 24 | * This is possibly more secure than leaving them on the page, and results in cleaner HTML markup |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | debugger; |
---|
| 28 | var fTitle = document.getElementById("surveyTitle"); |
---|
| 29 | if (fTitle != undefined && fTitle.value != "") { |
---|
| 30 | surveyEditor.title = fTitle.value; |
---|
| 31 | } |
---|
| 32 | else { |
---|
| 33 | surveyEditor.title = "Undefined title"; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | var fNumQuestions = document.getElementById("numQuestions"); |
---|
| 37 | if (fNumQuestions != undefined && fNumQuestions.value != "") { |
---|
| 38 | surveyEditor.numQuestions = fNumQuestions; |
---|
| 39 | } |
---|
| 40 | else { |
---|
| 41 | surveyEditor.numQuestions = 0; |
---|
| 42 | return; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | var fQuestions = document.getElementById("questionUids"); |
---|
| 46 | if (fQuestions != undefined && surveyEditor.numQuestions > 0) { |
---|
| 47 | surveyEditor.questions = stringToArray(fQuestions.value, ","); |
---|
| 48 | if (surveyEditor.questions.length != surveyEditor.numQuestions) { |
---|
| 49 | alert("numQuestions and the questions array passed do not match!"); |
---|
| 50 | return; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | else { |
---|
| 54 | alert("Questions field not found!"); |
---|
| 55 | return; |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | function drawQuestions(firstTime) { |
---|
| 60 | var length = surveyEditor.questions.length; |
---|
| 61 | if (length <= 0) return; |
---|
| 62 | |
---|
| 63 | var container = document.getElementById("surveyEditorContent"); |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | if (firstTime == true) { |
---|
| 67 | // Loop through questions, add a new smallFrame div for each question with id=question->uid |
---|
| 68 | // do this via AJAX calls, returnQuestion.php |
---|
| 69 | // dependencies: stringToArray/arrayToString |
---|
| 70 | var requestString = "uids="; |
---|
| 71 | requestString += arrayToString(surveyEditor.questions, ","); |
---|
| 72 | newAjaxRequest(requestString, "returnQuestionDisplay.php", function(result) { |
---|
| 73 | //var holderDiv = document.createElement("div"); |
---|
| 74 | //holderDiv.innerHTML = result.responseText; |
---|
| 75 | container.innerHTML = result.responseText; |
---|
| 76 | }); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | } |
---|