Difference between revisions of "Show a text grid and a single question in the same page"

From Catglobe Wiki
Jump to: navigation, search
Line 1: Line 1:
<source lang="javascript" line="1">quest.onInit = function()<source>
+
<source lang="javascript" line="1">
<source lang="javascript" line="2">{<source>
+
var SingleQuestion = {
<source lang="javascript" line="3">var single = "{{Single.Value}}";<source>
+
onInit: function(_label, _answerOptionValues, _answerOptionTexts)
<source lang="javascript" line="4">var aoV = new Array();<source>
+
{
<source lang="javascript" line="5">aoV[0] = 1;<source>
+
this.label = "QUESTION." + _label;
<source lang="javascript" line="6">aoV[1] = 2;<source>
+
this.aoValues = _answerOptionValues;
<source lang="javascript" line="7">var aoT = new Array();<source>
+
this.aoTexts = _answerOptionTexts;
<source lang="javascript" line="8">aoT[0] = "I do not want to give those information";<source>
+
this.selectedValue = "";
<source lang="javascript" line="9">aoT[1] = "I do not have time for this"<source>
+
},
<source lang="javascript" line="10">SingleQuestion.onInit("Single", aoV, aoT);<source>
+
optClick: function(value)
<source lang="javascript" line="11"><source>
+
{
<source lang="javascript" line="12">//look for the outer grid<source>
+
if (this.selectedValue == value)//click the checkbox twice => unchecked
<source lang="javascript" line="13">$(".grid_outer").append(<source>
+
{
<source lang="javascript" line="14">$("<tr>").css("background-color", "white").append($("<td>").append(SingleQuestion.getHTML()))<source>
+
this.selectedValue = "";
<source lang="javascript" line="15">);<source>
+
$("input:text").attr("disabled", "");
<source lang="javascript" line="16"><source>
+
$("input:checkbox").attr("checked", "");
<source lang="javascript" line="17">if (single != "")<source>
+
}
<source lang="javascript" line="18">{<source>
+
else
<source lang="javascript" line="19">SingleQuestion.optClick(single);<source>
+
{
<source lang="javascript" line="20">}<source>
+
//disable all other inputs
<source lang="javascript" line="21"><source>
+
this.selectedValue = value;
<source lang="javascript" line="22">TextGridQuestion.onInit(this);<source>
+
$("input:text").attr("disabled", "disabled");
<source lang="javascript" line="23">$("input:text").width("200px");<source>
+
 +
$("input:checkbox").each(
 +
function(i)
 +
{
 +
if ($(this).val() == value)
 +
$(this).attr("checked", "checked");
 +
else
 +
$(this).attr("checked", "");
 +
}
 +
);
 +
}
 +
},
 +
getHTML: function()
 +
{
 +
var t = $("<table>");
 +
var n = this.aoValues.length;
 +
for (var i = 0; i<n; i++)
 +
{
 +
t.append(this.getHTML_AO(i));
 +
}
 +
t.append($("<input type = \"hidden\">").attr("name", this.label).val(""));
 +
return t;
 +
},
 +
getHTML_AO: function(index)
 +
{
 +
var value = this.aoValues[index];
 +
var text = this.aoTexts[index];
 +
return $("<tr>")
 +
.append(
 +
$("<td>").width("16px").attr("valign", "top")
 +
.append(
 +
$("<input type=\"checkbox\">").attr("name", this.label).val(value).click(
 +
function()
 +
{
 +
SingleQuestion.optClick(value);
 +
}
 +
)
 +
)
 +
)
 +
.append(
 +
$("<td>").append($("<a class=\"option_link\" href=\"javascript:SingleQuestion.optClick(" + value + ");\">" + text + "</a>"))
 +
);
 +
}
 +
}
 +
 
 +
var TextGridQuestion =
 +
{
 +
onInit: function(_quest)
 +
{
 +
this.quest = _quest;
 +
},
 +
questionCheck: function()
 +
{
 +
acont = new Array();
 +
    msg = "";
 +
    cont = true;
 +
 
 +
for (i=0; i < this.quest.questions.length; i++)
 +
acont[i] = (trim(document["query"][this.quest.questions[i].label].value) != "");
 +
 
 +
msg = this.quest.ingridrequiredtext+"\n";
 +
for (i = 0; i < this.quest.questions.length; i++)
 +
{
 +
// If the sub question is not visible or answering this
 +
// sub question is not answered and not required to be
 +
// then we continue with the next sub question
 +
if(!this.quest.questions[i].visible || (!this.quest.questions[i].required && !acont[i]))
 +
continue;
 +
 
 +
if(this.quest.questions[i].required && !acont[i])
 +
{
 +
tmp = this.quest.questions[i].text;
 +
tmp = tmp.replace(/(<!\-\-|\-\->)/ig, "");
 +
tmp = tmp.replace(/&nbsp;/ig, " ");
 +
msg += " - '"+trim(tmp.replace(/<[^>]*>/ig, ""))+"'\n";
 +
cont = false;
 +
continue;
 +
}
 +
}
 +
 
 +
if (!cont)
 +
{
 +
ErrorMessages.getInstance().showErrorMessage(msg);
 +
return false;
 +
}
 +
return true;
 +
}
 +
}
 +
 
 +
this.questioncheck = function()
 +
{
 +
ErrorMessages.getInstance().clearErrorMessages();
 +
if (SingleQuestion.selectedValue != "")
 +
return true;
 +
 +
return TextGridQuestion.questionCheck();
 +
}
 +
 
 +
quest.onInit = function()
 +
{
 +
var single = "{{Single.Value}}";
 +
var aoV = new Array();
 +
aoV[0] = 1;
 +
aoV[1] = 2;
 +
var aoT = new Array();
 +
aoT[0] = "I do not want to give those information";
 +
aoT[1] = "I do not have time for this"
 +
SingleQuestion.onInit("Single", aoV, aoT);
 +
 +
//look for the outer grid
 +
$(".grid_outer").append(
 +
$("<tr>").css("background-color", "white").append($("<td>").append(SingleQuestion.getHTML()))
 +
);
 +
 +
if (single != "")
 +
{
 +
SingleQuestion.optClick(single);
 +
}
 +
 +
TextGridQuestion.onInit(this);
 +
$("input:text").width("200px");
 +
}
 +
</source>

Revision as of 08:14, 18 December 2008

  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(/&nbsp;/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 }