-
Notifications
You must be signed in to change notification settings - Fork 0
/
help_controls.js
324 lines (302 loc) · 8.24 KB
/
help_controls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// initial values for either Nosy, Superseder, Keyword and Waiting On,
// depending on which has called
original_field = form[field].value;
// Some browsers (ok, IE) don't define the "undefined" variable.
undefined = document.geez_IE_is_really_friggin_annoying;
function trim(value) {
var temp = value;
var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
var obj = / /g;
while (temp.match(obj)) { temp = temp.replace(obj, " "); }
return temp;
}
function determineList() {
// generate a comma-separated list of the checked items
var list = new String('');
// either a checkbox object or an array of checkboxes
var check = document.frm_help.check;
if ((check.length == undefined) && (check.checked != undefined)) {
// only one checkbox on page
if (check.checked) {
list = check.value;
}
} else {
// array of checkboxes
for (box=0; box < check.length; box++) {
if (check[box].checked) {
if (list.length == 0) {
separator = '';
}
else {
separator = ',';
}
// we used to use an Array and push / join, but IE5.0 sux
list = list + separator + check[box].value;
}
}
}
return list;
}
/**
* update the field in the opening window;
* the text_field variable must be set in the calling page
*/
function updateOpener() {
// write back to opener window
if (document.frm_help.check==undefined) { return; }
form[field].value = text_field.value;
}
function updateList() {
// write back to opener window
if (document.frm_help.check==undefined) { return; }
form[field].value = determineList();
}
function updatePreview() {
// update the preview box
if (document.frm_help.check==undefined) { return; }
writePreview(determineList());
}
function clearList() {
// uncheck all checkboxes
if (document.frm_help.check==undefined) { return; }
for (box=0; box < document.frm_help.check.length; box++) {
document.frm_help.check[box].checked = false;
}
}
function reviseList_framed(form, textfield) {
// update the checkboxes based on the preview field
// alert('reviseList_framed')
// alert(form)
if (form.check==undefined)
return;
// alert(textfield)
var to_check;
var list = textfield.value.split(",");
if (form.check.length==undefined) {
check = form.check;
to_check = false;
for (val in list) {
if (check.value==trim(list[val])) {
to_check = true;
break;
}
}
check.checked = to_check;
} else {
for (box=0; box < form.check.length; box++) {
check = form.check[box];
to_check = false;
for (val in list) {
if (check.value==trim(list[val])) {
to_check = true;
break;
}
}
check.checked = to_check;
}
}
}
function reviseList(vals) {
// update the checkboxes based on the preview field
if (document.frm_help.check==undefined) { return; }
var to_check;
var list = vals.split(",");
if (document.frm_help.check.length==undefined) {
check = document.frm_help.check;
to_check = false;
for (val in list) {
if (check.value==trim(list[val])) {
to_check = true;
break;
}
}
check.checked = to_check;
} else {
for (box=0; box < document.frm_help.check.length; box++) {
check = document.frm_help.check[box];
to_check = false;
for (val in list) {
if (check.value==trim(list[val])) {
to_check = true;
break;
}
}
check.checked = to_check;
}
}
}
function resetList() {
// reset preview and check boxes to initial values
if (document.frm_help.check==undefined) { return; }
writePreview(original_field);
reviseList(original_field);
}
function writePreview(val) {
// writes a value to the text_preview
document.frm_help.text_preview.value = val;
}
function focusField(name) {
for(i=0; i < document.forms.length; ++i) {
var obj = document.forms[i].elements[name];
if (obj && obj.focus) {obj.focus();}
}
}
function selectField(name) {
for(i=0; i < document.forms.length; ++i) {
var obj = document.forms[i].elements[name];
if (obj && obj.focus){obj.focus();}
if (obj && obj.select){obj.select();}
}
}
function checkRequiredFields(fields)
{
var bonk='';
var res='';
var argv = checkRequiredFields.arguments;
var argc = argv.length;
var input = '';
var val='';
for (var i=0; i < argc; i++) {
fi = argv[i];
input = document.getElementById(fi);
if (input) {
val = input.value
if (val == '' || val == '-1' || val == -1) {
if (res == '') {
res = fi;
bonk = input;
} else {
res += ', '+fi;
}
}
} else {
alert('Field with id='+fi+' not found!')
}
}
if (res == '') {
return submit_once();
} else {
alert('Missing value here ('+res+')!');
if (window.event && window.event.returnvalue) {
event.returnValue = 0; // work-around for IE
}
bonk.focus();
return false;
}
}
/**
* seeks the given value (2nd argument)
* in the value of the given input element (1st argument),
* which is considered a list of values, separated by commas
*/
function has_value(input, val)
{
var actval = input.value
var arr = feld.value.split(',');
var max = arr.length;
for (i=0;i<max;i++) {
if (trim(arr[i]) == val) {
return true
}
}
return false
}
/**
* Switch Value:
* change the value of the given input field (might be of type text or hidden),
* adding or removing the value of the given checkbox field (might be a radio
* button as well)
*
* This function doesn't care whether or not the checkboxes of all values of
* interest are present; but of course it doesn't have total control of the
* text field.
*/
function switch_val(text, check)
{
var switched_val = check.value
var arr = text.value.split(',')
var max = arr.length
if (check.checked) {
for (i=0; i<max; i++) {
if (trim(arr[i]) == switched_val) {
return
}
}
if (text.value)
text.value = text.value+','+switched_val
else
text.value = switched_val
} else {
var neu = ''
var changed = false
for (i=0; i<max; i++) {
if (trim(arr[i]) == switched_val) {
changed=true
} else {
neu = neu+','+trim(arr[i])
}
}
if (changed) {
text.value = neu.substr(1)
}
}
}
/**
* append the given value (2nd argument) to an input field
* (1st argument) which contains comma-separated values;
* see --> remove_val()
*
* This will work nicely even for batched lists
*/
function append_val(name, val)
{
var feld = document.itemSynopsis[name];
var actval = feld.value;
if (actval == '') {
feld.value = val
} else {
var arr = feld.value.split(',');
var max = arr.length;
for (i=0;i<max;i++) {
if (trim(arr[i]) == val) {
return
}
}
feld.value = actval+','+val
}
}
/**
* remove the given value (2nd argument) from the comma-separated values
* of the given input element (1st argument); see --> append_val()
*/
function remove_val(name, val)
{
var feld = document.itemSynopsis[name];
var actval = feld.value;
var changed=false;
if (actval == '') {
return
} else {
var arr = feld.value.split(',');
var max = arr.length;
var neu = ''
for (i=0;i<max;i++) {
if (trim(arr[i]) == val) {
changed=true
} else {
neu = neu+','+trim(arr[i])
}
}
if (changed) {
feld.value = neu.substr(1)
}
}
}
/**
* give the focus to the element given by id
*/
function focus2id(name)
{
document.getElementById(name).focus();
}