source: trunk/www/db_po/po.js@ 11444

Last change on this file since 11444 was 11353, checked in by Daniela Dorner, 13 years ago
added script to display and edit entries of the configuration database (ProgramOptions) and scripts which are called by this script
File size: 7.2 KB
Line 
1
2//function
3function get_keys(prog)
4{
5 //alert(prog);
6
7 var xmlhttp;
8 if (window.XMLHttpRequest)
9 {// code for IE7+, Firefox, Chrome, Opera, Safari
10 xmlhttp=new XMLHttpRequest();
11 }
12 else
13 {// code for IE6, IE5
14 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
15 }
16 xmlhttp.open("GET","get_keys.php?fProgram="+prog,false);
17 xmlhttp.send();
18 if (xmlhttp.readyState==4 && xmlhttp.status==200)
19 {
20 document.getElementById('keyfield').innerHTML = xmlhttp.responseText;
21 document.getElementById('valuefield').innerHTML = "";
22 }
23 else
24 document.getElementById('keyfield').innerHTML = "argh";
25
26}
27
28//function
29function get_values(prog, key)
30{
31 //alert(prog+"---"+key);
32 var xmlhttp;
33 if (window.XMLHttpRequest)
34 {// code for IE7+, Firefox, Chrome, Opera, Safari
35 xmlhttp=new XMLHttpRequest();
36 }
37 else
38 {// code for IE6, IE5
39 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
40 }
41 xmlhttp.open("GET","get_values.php?fKey="+key+"&fProgram="+prog,false);
42 xmlhttp.send();
43 if (xmlhttp.readyState==4 && xmlhttp.status==200)
44 {
45 document.getElementById('valuefield').innerHTML = xmlhttp.responseText;
46 if (key=='newkey')
47 addRow(prog, key);
48 }
49 else
50 document.getElementById('valuefield').innerHTML = "argh";
51}
52
53function addRow(prog, key)
54{
55 tabBody=document.getElementById("valtable");
56 row=document.createElement("TR");
57 row.id='val0';
58 cell0 = document.createElement("TD");
59 cell1 = document.createElement("TD");
60 cell2 = document.createElement("TD");
61 cell3 = document.createElement("TD");
62 cell4 = document.createElement("TD");
63 cell5 = document.createElement("TD");
64 //case add new key (value NULL)
65 if (key=='newkey')
66 {
67 input1 = document.createElement("INPUT");
68 input1.value = prog;
69 input1.id = 'prog0';
70 input2 = document.createElement("INPUT");
71 input2.value = 'newkey';
72 input2.id = 'key0';
73 cell3.id = 'newval0';
74 textnode3=document.createTextNode("NULL");
75 input4 = document.createElement("INPUT");
76 input4.id = 'newdescr0';
77 input5 = document.createElement("input");
78 input5.value = 'Add';
79 input5.type = "button";
80 input5.onclick = function () { UpdateRow(1, 0); onclick() }
81 cell1.appendChild(input1);
82 cell2.appendChild(input2);
83 cell3.appendChild(textnode3);
84 cell4.appendChild(input4);
85 cell5.appendChild(input5);
86 //cell5.appendChild(button5);
87 }
88 //case add new val for same key
89 else
90 {
91 cell1.id = 'prog0';
92 cell2.id = 'key0';
93 textnode1=document.createTextNode(prog);
94 textnode2=document.createTextNode(key);
95 input3 = document.createElement("INPUT");
96 input3.id = 'newval0';
97 input4 = document.createElement("INPUT");
98 input4.id = 'newdescr0';
99 input5 = document.createElement("input");
100 input5.value = 'Add';
101 input5.type = "button";
102 input5.onclick = function () { UpdateRow(2, 0); onclick() }
103 cell1.appendChild(textnode1);
104 cell2.appendChild(textnode2);
105 cell3.appendChild(input3);
106 cell4.appendChild(input4);
107 cell5.appendChild(input5);
108 }
109 row.appendChild(cell0);
110 row.appendChild(cell1);
111 row.appendChild(cell2);
112 row.appendChild(cell3);
113 row.appendChild(cell4);
114 row.appendChild(cell5);
115 tabBody.appendChild(row);
116
117 // to be removed later when solution for adding multiple new rows is found
118 document.getElementById('addrow').style.display = "none";
119}
120
121function EditRow(index)
122{
123 oldval=document.getElementById('val'+index).innerHTML;
124 document.getElementById('val'+index).innerHTML = "<input align='right' id='newval"+index+"' value='"+oldval+"'>";
125 olddescr=document.getElementById('descr'+index).innerHTML;
126 document.getElementById('descr'+index).innerHTML = "<input align='right' id='newdescr"+index+"' value='"+olddescr+"'>";
127 document.getElementById('action'+index).innerHTML =
128 "<input type='button' value='Update' onclick='UpdateRow(3,"+index+")'>"
129 +"<input type='button' value='Delete' onclick='UpdateRow(4,"+index+")'>";
130}
131
132function UpdateRow(updcase,index)
133{
134 // three cases of update
135 // 1: add new key
136 // 2: add new val (for same key)
137 // 3: edit val
138 // 4: delete val (ie set to NULL)
139 if (updcase==1)
140 {
141 prog=document.getElementById('prog'+index).value;
142 key=document.getElementById('key'+index).value;
143 }
144 else
145 {
146 prog=document.getElementById('prog'+index).innerHTML;
147 key=document.getElementById('key'+index).innerHTML;
148 }
149 if (updcase==1)
150 val=document.getElementById('newval'+index).innerHTML;
151 else
152 val=document.getElementById('newval'+index).value;
153 descr=document.getElementById('newdescr'+index).value;
154 if (!descr)
155 alert("Please insert description!");
156 if (!key)
157 alert("Please insert key!");
158 if (!val)
159 alert("Please insert value!");
160 if (!val || !descr || !key)
161 return;
162 if (index==0)
163 index=-1;
164
165 phpcall="insert_po.php?fUpdCase="+updcase+"&fIndex="+index+"&fProgram="+prog+"&fKey="+key+"&fValue="+val+"&fDescription="+descr;
166 //alert("u/i --- "+index+" --- "+prog+" --- "+key+" --- "+val+" --- "+descr);
167 //alert(phpcall);
168
169 var xmlhttp;
170 if (window.XMLHttpRequest)
171 {// code for IE7+, Firefox, Chrome, Opera, Safari
172 xmlhttp=new XMLHttpRequest();
173 }
174 else
175 {// code for IE6, IE5
176 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
177 }
178 xmlhttp.open("GET", phpcall, false);
179 xmlhttp.send();
180 if (xmlhttp.readyState==4 && xmlhttp.status==200)
181 alert(xmlhttp.responseText);
182 else
183 alert("Mist! "+xmlhttp.responseText);
184
185 var xmlhttp2;
186 if (window.XMLHttpRequest)
187 {// code for IE7+, Firefox, Chrome, Opera, Safari
188 xmlhttp2=new XMLHttpRequest();
189 }
190 else
191 {// code for IE6, IE5
192 xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
193 }
194 xmlhttp2.open("GET","get_values.php?fKey="+key+"&fProgram="+prog,false);
195 xmlhttp2.send();
196 if (xmlhttp2.readyState==4 && xmlhttp2.status==200)
197 {
198 document.getElementById('valuefield').innerHTML = xmlhttp2.responseText;
199 if (key=='newkey')
200 addRow(prog, key);
201 }
202 else
203 document.getElementById('valuefield').innerHTML = "argh";
204}
205
206
207// printf("<div id='showcurrent'>\n<button onClick='ShowCurrent();'>Show Current</button>\n</div>\n");
208
209function ShowCurrent()
210{
211 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
212 if(document.getElementById('old'+i))
213 document.getElementById('old'+i).style.display = "none";
214 document.getElementById('showcurrent').style.display = "none";
215 document.getElementById('showall').style.display = "";
216}
217
218function ShowAll()
219{
220 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++)
221 if(document.getElementById('old'+i))
222 document.getElementById('old'+i).style.display = "";
223 document.getElementById('showcurrent').style.display = "";
224 document.getElementById('showall').style.display = "none";
225}
226
227
Note: See TracBrowser for help on using the repository browser.