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