1 |
wakaba |
1.1 |
//
|
2 |
|
|
// Licensed Materials - Property of IBM
|
3 |
|
|
// 5724D51
|
4 |
|
|
// (C) Copyright IBM Corp. 1995, 2003 All Rights Reserved.
|
5 |
|
|
//
|
6 |
|
|
/*
|
7 |
|
|
■ イベントで呼び出す関数
|
8 |
|
|
|
9 |
|
|
HpbELQInit() - BODY の onload で呼び出す
|
10 |
|
|
HpbELQCheck() - 送信ボタンで呼び出す
|
11 |
|
|
HpbELQReset() - リセットボタンで呼び出す
|
12 |
|
|
|
13 |
|
|
*/
|
14 |
|
|
|
15 |
|
|
//
|
16 |
|
|
// GLOBAL DEFINITIONS
|
17 |
|
|
//
|
18 |
|
|
var HpbELQObj = null; // アンケート処理オブジェクトのインスタンス
|
19 |
|
|
var HpbELQ_FormName = "HPB_ELQ_QUESTION"; // アンケートFORMの名前
|
20 |
|
|
var HpbELQ_SubmitBtn = "HPB_ELQ_SUBMIT"; // 「送信」INPUTボタン名
|
21 |
|
|
var HpbELQMsg_NoData = "アンケート用のデータが定義されていません。\n回答は送信できません。";
|
22 |
|
|
var HpbELQMsg_OK = "";
|
23 |
|
|
var HpbELQMsg_AnsNotDefined = "回答が定義されていません。";
|
24 |
|
|
var HpbELQMsg_AnsMissing = "必須設問に回答してください。";
|
25 |
|
|
|
26 |
|
|
//
|
27 |
|
|
// EXPORT FUNCTIONS
|
28 |
|
|
//
|
29 |
|
|
function HpbELQInit()
|
30 |
|
|
{
|
31 |
|
|
if(typeof HpbELQData == "object"){
|
32 |
|
|
HpbELQObj = new ELQuestionnaire(HpbELQData);
|
33 |
|
|
} else {
|
34 |
|
|
alert(HpbELQMsg_NoData); // No Data
|
35 |
|
|
}
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
function HpbELQCheck()
|
39 |
|
|
{
|
40 |
|
|
if(HpbELQObj != null){
|
41 |
|
|
return HpbELQObj.doCheck();
|
42 |
|
|
} else {
|
43 |
|
|
alert(HpbELQMsg_NoData); // No Data
|
44 |
|
|
return false;
|
45 |
|
|
}
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
function HpbELQReset()
|
49 |
|
|
{
|
50 |
|
|
if(HpbELQObj != null){
|
51 |
|
|
return HpbELQObj.doReset();
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
//
|
56 |
|
|
// OBJECT
|
57 |
|
|
//
|
58 |
|
|
function ELQuestionnaire(data)
|
59 |
|
|
{
|
60 |
|
|
var missingElm;
|
61 |
|
|
// Attributes
|
62 |
|
|
this.data = data;
|
63 |
|
|
|
64 |
|
|
this.doCheck = function()
|
65 |
|
|
{
|
66 |
|
|
var err_msg = HpbELQMsg_OK;
|
67 |
|
|
var nQ = this.data.questions.length;
|
68 |
|
|
missingElm = null;
|
69 |
|
|
for(var i=0; i<nQ; i++){
|
70 |
|
|
var objQ = this.data.questions[i];
|
71 |
|
|
if (objQ.mandatory == true) {
|
72 |
|
|
var id = this.data.idPrefix + (i+1).toString();
|
73 |
|
|
var func = eval("this.checkEach" + objQ.type);
|
74 |
|
|
if(typeof func == "function"){
|
75 |
|
|
var msg_each = func(this, objQ, id);
|
76 |
|
|
if (msg_each != HpbELQMsg_OK) {
|
77 |
|
|
var item = this.getQ(id + "_head");
|
78 |
|
|
if (item != null && typeof item.innerHTML != "undefined")
|
79 |
|
|
item = item.innerHTML;
|
80 |
|
|
else
|
81 |
|
|
item = id;
|
82 |
|
|
err_msg += (msg_each + ": " + item + "\n");
|
83 |
|
|
}
|
84 |
|
|
} else {
|
85 |
|
|
alert("回答を検査する関数がありません:checkEach" + objQ.type);
|
86 |
|
|
return false;
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
if (err_msg == HpbELQMsg_OK) {
|
91 |
|
|
// 送信ボタンを無効に
|
92 |
|
|
this.enableFormItem(HpbELQ_SubmitBtn, false);
|
93 |
|
|
return true;
|
94 |
|
|
} else {
|
95 |
|
|
alert(err_msg);
|
96 |
|
|
// 最初の未回答項目にフォーカスをあてる
|
97 |
|
|
if (missingElm != null) missingElm.focus();
|
98 |
|
|
return false;
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
this.doReset = function()
|
103 |
|
|
{
|
104 |
|
|
this.enableFormItem(HpbELQ_SubmitBtn, true);
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
this.getQ = function(id)
|
108 |
|
|
{
|
109 |
|
|
if( eval("typeof "+id) == "undefined" )
|
110 |
|
|
return null;
|
111 |
|
|
return eval(id);
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
this.getFormItem = function(id)
|
115 |
|
|
{
|
116 |
|
|
return this.getQ(HpbELQ_FormName + "." + id);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
this.enableFormItem = function(name, f)
|
120 |
|
|
{
|
121 |
|
|
var item = this.getFormItem(name);
|
122 |
|
|
if (item != null)
|
123 |
|
|
item.disabled = !f;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
//-------------------
|
127 |
|
|
// check mandatories
|
128 |
|
|
this.checkEachSelection = function(doc, obj, id)
|
129 |
|
|
{
|
130 |
|
|
if(obj.single){
|
131 |
|
|
// Single Selection
|
132 |
|
|
var ansObj = doc.getFormItem(id);
|
133 |
|
|
if (ansObj != null) {
|
134 |
|
|
var count = 0;
|
135 |
|
|
for(var i=0; i<ansObj.length; i++) {
|
136 |
|
|
if(ansObj[i].checked)
|
137 |
|
|
count++;
|
138 |
|
|
}
|
139 |
|
|
if (count == 1)
|
140 |
|
|
return HpbELQMsg_OK; //ok
|
141 |
|
|
else {
|
142 |
|
|
if (missingElm == null) missingElm = ansObj[0];
|
143 |
|
|
return HpbELQMsg_AnsMissing;
|
144 |
|
|
}
|
145 |
|
|
} else
|
146 |
|
|
return HpbELQMsg_AnsMissing;
|
147 |
|
|
} else {
|
148 |
|
|
// Multiple Selection
|
149 |
|
|
var count = 0;
|
150 |
|
|
for(var i=1; i<=obj.n_selection; i++){
|
151 |
|
|
var ans = doc.getFormItem(id + "_" + i);
|
152 |
|
|
if (ans != null) {
|
153 |
|
|
if (ans.checked)
|
154 |
|
|
count++;
|
155 |
|
|
} else
|
156 |
|
|
return HpbELQMsg_AnsNotDefined;
|
157 |
|
|
}
|
158 |
|
|
if (count > 0)
|
159 |
|
|
return HpbELQMsg_OK; //ok
|
160 |
|
|
else {
|
161 |
|
|
if (missingElm == null) missingElm = doc.getFormItem(id + "_1");
|
162 |
|
|
return HpbELQMsg_AnsMissing;
|
163 |
|
|
}
|
164 |
|
|
}
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
this.checkEachDescription = function(doc, obj, id)
|
168 |
|
|
{
|
169 |
|
|
var ans = doc.getFormItem(id);
|
170 |
|
|
if (ans != null) {
|
171 |
|
|
if (ans.value != "")
|
172 |
|
|
return HpbELQMsg_OK; //ok
|
173 |
|
|
else {
|
174 |
|
|
if (missingElm == null) missingElm = ans;
|
175 |
|
|
return HpbELQMsg_AnsMissing;
|
176 |
|
|
}
|
177 |
|
|
} else
|
178 |
|
|
return HpbELQMsg_AnsNotDefined;
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
}
|
182 |
|
|
|