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 | // Deze scripts worden gedeeld door bijna alle editors, en deze moeten dan ook in een common scripts |
---|
18 | // file komen te staan in plaats van in elk document weer opnieuw invoeren. |
---|
19 | // Dit gaat ongetwijfeld conflicten opleveren als er in een van de functies iets veranderd moet worden. |
---|
20 | |
---|
21 | function stringToArray(s, c) { |
---|
22 | var a = s.split(c); |
---|
23 | for (var i = 0; i < a.length; i++) { // remove empty items |
---|
24 | if (a[i] == "") { |
---|
25 | a.splice(i, 1); |
---|
26 | i--; |
---|
27 | } |
---|
28 | } |
---|
29 | return a; |
---|
30 | } |
---|
31 | |
---|
32 | function arrayToString(a, c) { |
---|
33 | var s = ""; |
---|
34 | for (var i = 0; i < a.length; i++) { |
---|
35 | if (a[i] != "") { |
---|
36 | s += a[i]+c; |
---|
37 | } |
---|
38 | } |
---|
39 | return s; |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | function loadSurvey() { |
---|
45 | |
---|
46 | /* |
---|
47 | * Take the values from the hiddenfields on the page, load them into the object literal defined at the top of this script, |
---|
48 | * Then delete these fields from the HTML page, since they are not needed anymore. |
---|
49 | * This is possibly more secure than leaving them on the page, and results in cleaner HTML markup |
---|
50 | */ |
---|
51 | |
---|
52 | debugger; |
---|
53 | var fTitle = document.getElementById("surveyTitle"); |
---|
54 | if (fTitle != undefined && fTitle.value != "") { |
---|
55 | surveyEditor.title = fTitle.value; |
---|
56 | } |
---|
57 | else { |
---|
58 | surveyEditor.title = "Undefined title"; |
---|
59 | } |
---|
60 | |
---|
61 | var fNumQuestions = document.getElementById("numQuestions"); |
---|
62 | if (fNumQuestions != undefined && fNumQuestions.value != "") { |
---|
63 | surveyEditor.numQuestions = fNumQuestions; |
---|
64 | } |
---|
65 | else { |
---|
66 | surveyEditor.numQuestions = 0; |
---|
67 | return; |
---|
68 | } |
---|
69 | |
---|
70 | var fQuestions = document.getElementById("questionUids"); |
---|
71 | if (fQuestions != undefined && surveyEditor.numQuestions > 0) { |
---|
72 | surveyEditor.questions = stringToArray(fQuestions.value, ","); |
---|
73 | if (surveyEditor.questions.length != surveyEditor.numQuestions) { |
---|
74 | alert("numQuestions and the questions array passed do not match!"); |
---|
75 | return; |
---|
76 | } |
---|
77 | } |
---|
78 | else { |
---|
79 | alert("Questions field not found!"); |
---|
80 | return; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | function drawQuestions(firstTime) { |
---|
85 | var length = surveyEditor.questions.length; |
---|
86 | if (length <= 0) return; |
---|
87 | |
---|
88 | var container = document.getElementById("surveyEditorContent"); |
---|
89 | |
---|
90 | |
---|
91 | if (firstTime == true) { |
---|
92 | // Loop through questions, add a new smallFrame div for each question with id=question->uid |
---|
93 | // do this via AJAX calls, returnQuestion.php |
---|
94 | // dependencies: stringToArray/arrayToString |
---|
95 | var requestString = "uids="; |
---|
96 | requestString += arrayToString(surveyEditor.questions, ","); |
---|
97 | newAjaxRequest(requestString, "returnQuestionDisplay.php", function(result) { |
---|
98 | //var holderDiv = document.createElement("div"); |
---|
99 | //holderDiv.innerHTML = result.responseText; |
---|
100 | container.innerHTML = result.responseText; |
---|
101 | }); |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | } |
---|