Premiere version : mise en route du suivi.
[auf_roundup.git] / share / roundup / templates / minimal / 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 for (box=0; box < document.frm_help.check.length; box++) {
21 if (document.frm_help.check[box].checked) {
22 if (list.length == 0) {
23 separator = '';
24 }
25 else {
26 separator = ',';
27 }
28 // we used to use an Array and push / join, but IE5.0 sux
29 list = list + separator + document.frm_help.check[box].value;
30 }
31 }
32 return list;
33 }
34
35 function updateList() {
36 // write back to opener window
37 if (document.frm_help.check==undefined) { return; }
38 form[field].value = determineList();
39 }
40
41 function updatePreview() {
42 // update the preview box
43 if (document.frm_help.check==undefined) { return; }
44 writePreview(determineList());
45 }
46
47 function clearList() {
48 // uncheck all checkboxes
49 if (document.frm_help.check==undefined) { return; }
50 for (box=0; box < document.frm_help.check.length; box++) {
51 document.frm_help.check[box].checked = false;
52 }
53 }
54
55 function reviseList(vals) {
56 // update the checkboxes based on the preview field
57 if (document.frm_help.check==undefined) { return; }
58 var to_check;
59 var list = vals.split(",");
60 if (document.frm_help.check.length==undefined) {
61 check = document.frm_help.check;
62 to_check = false;
63 for (val in list) {
64 if (check.value==trim(list[val])) {
65 to_check = true;
66 break;
67 }
68 }
69 check.checked = to_check;
70 } else {
71 for (box=0; box < document.frm_help.check.length; box++) {
72 check = document.frm_help.check[box];
73 to_check = false;
74 for (val in list) {
75 if (check.value==trim(list[val])) {
76 to_check = true;
77 break;
78 }
79 }
80 check.checked = to_check;
81 }
82 }
83 }
84
85 function resetList() {
86 // reset preview and check boxes to initial values
87 if (document.frm_help.check==undefined) { return; }
88 writePreview(original_field);
89 reviseList(original_field);
90 }
91
92 function writePreview(val) {
93 // writes a value to the text_preview
94 document.frm_help.text_preview.value = val;
95 }
96
97 function focusField(name) {
98 for(i=0; i < document.forms.length; ++i) {
99 var obj = document.forms[i].elements[name];
100 if (obj && obj.focus) {obj.focus();}
101 }
102 }
103
104 function selectField(name) {
105 for(i=0; i < document.forms.length; ++i) {
106 var obj = document.forms[i].elements[name];
107 if (obj && obj.focus){obj.focus();}
108 if (obj && obj.select){obj.select();}
109 }
110 }
111