1 var SingleQuestion = {
2 onInit: function(_label, _answerOptionValues, _answerOptionTexts)
3 {
4 this.label = "QUESTION." + _label;
5 this.aoValues = _answerOptionValues;
6 this.aoTexts = _answerOptionTexts;
7 this.selectedValue = "";
8 },
9 optClick: function(value)
10 {
11 if (this.selectedValue == value)//click the checkbox twice => unchecked
12 {
13 this.selectedValue = "";
14 $("input:text").attr("disabled", "");
15 $("input:checkbox").attr("checked", "");
16 }
17 else
18 {
19 //disable all other inputs
20 this.selectedValue = value;
21 $("input:text").attr("disabled", "disabled");
22
23 $("input:checkbox").each(
24 function(i)
25 {
26 if ($(this).val() == value)
27 $(this).attr("checked", "checked");
28 else
29 $(this).attr("checked", "");
30 }
31 );
32 }
33 },
34 getHTML: function()
35 {
36 var t = $("<table>");
37 var n = this.aoValues.length;
38 for (var i = 0; i<n; i++)
39 {
40 t.append(this.getHTML_AO(i));
41 }
42 t.append($("<input type = \"hidden\">").attr("name", this.label).val(""));
43 return t;
44 },
45 getHTML_AO: function(index)
46 {
47 var value = this.aoValues[index];
48 var text = this.aoTexts[index];
49 return $("<tr>")
50 .append(
51 $("<td>").width("16px").attr("valign", "top")
52 .append(
53 $("<input type=\"checkbox\">").attr("name", this.label).val(value).click(
54 function()
55 {
56 SingleQuestion.optClick(value);
57 }
58 )
59 )
60 )
61 .append(
62 $("<td>").append($("<a class=\"option_link\" href=\"javascript:SingleQuestion.optClick(" + value + ");\">" + text + "</a>"))
63 );
64 }
65 }
66
67 var TextGridQuestion =
68 {
69 onInit: function(_quest)
70 {
71 this.quest = _quest;
72 },
73 questionCheck: function()
74 {
75 acont = new Array();
76 msg = "";
77 cont = true;
78
79 for (i=0; i < this.quest.questions.length; i++)
80 acont[i] = (trim(document["query"][this.quest.questions[i].label].value) != "");
81
82 msg = this.quest.ingridrequiredtext+"\n";
83 for (i = 0; i < this.quest.questions.length; i++)
84 {
85 // If the sub question is not visible or answering this
86 // sub question is not answered and not required to be
87 // then we continue with the next sub question
88 if(!this.quest.questions[i].visible || (!this.quest.questions[i].required && !acont[i]))
89 continue;
90
91 if(this.quest.questions[i].required && !acont[i])
92 {
93 tmp = this.quest.questions[i].text;
94 tmp = tmp.replace(/(<!\-\-|\-\->)/ig, "");
95 tmp = tmp.replace(/ /ig, " ");
96 msg += " - '"+trim(tmp.replace(/<[^>]*>/ig, ""))+"'\n";
97 cont = false;
98 continue;
99 }
100 }
101
102 if (!cont)
103 {
104 ErrorMessages.getInstance().showErrorMessage(msg);
105 return false;
106 }
107 return true;
108 }
109 }
110
111 this.questioncheck = function()
112 {
113 ErrorMessages.getInstance().clearErrorMessages();
114 if (SingleQuestion.selectedValue != "")
115 return true;
116
117 return TextGridQuestion.questionCheck();
118 }
119
120 quest.onInit = function()
121 {
122 var single = "{{Single.Value}}";
123 var aoV = new Array();
124 aoV[0] = 1;
125 aoV[1] = 2;
126 var aoT = new Array();
127 aoT[0] = "I do not want to give those information";
128 aoT[1] = "I do not have time for this"
129 SingleQuestion.onInit("Single", aoV, aoT);
130
131 //look for the outer grid
132 $(".grid_outer").append(
133 $("<tr>").css("background-color", "white").append($("<td>").append(SingleQuestion.getHTML()))
134 );
135
136 if (single != "")
137 {
138 SingleQuestion.optClick(single);
139 }
140
141 TextGridQuestion.onInit(this);
142 $("input:text").width("200px");
143 }