1/********************************************************************\
4 Created by: Stefan Ritt
6 Contents: Obsolete functions from the JavaScript midas library used by mhttpd
8\********************************************************************/
10function XMLHttpRequestGeneric()
14 request = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
18 request = new ActiveXObject('Msxml2.XMLHTTP'); // Internet Explorer
22 request = new ActiveXObject('Microsoft.XMLHTTP');
25 alert('Your browser does not support AJAX!');
36function ODBSetURL(url)
41function ODBSet(path, value, pwdname)
43 var value, request, url;
45 if (pwdname != undefined)
46 pwd = prompt('Please enter password', '');
50 var request = XMLHttpRequestGeneric();
52 url = ODBUrlBase + '?cmd=jset&odb=' + path + '&value=' + encodeURIComponent(value);
54 if (pwdname != undefined)
55 url += '&pnam=' + pwdname;
57 request.open('GET', url, false);
59 if (pwdname != undefined)
60 request.setRequestHeader('Cookie', 'cpwd='+pwd);
64 if (request.status != 200 || request.responseText != 'OK')
65 alert('ODBSet error:\nPath: '+path+'\nHTTP Status: '+request.status+'\nMessage: '+request.responseText+'\n'+document.location) ;
68function ODBGet(path, format, defval, len, type)
70 var request = XMLHttpRequestGeneric();
72 var url = ODBUrlBase + '?cmd=jget&odb=' + path;
73 if (format != undefined && format != '')
74 url += '&format=' + format;
75 request.open('GET', url, false);
78 if (path.match(/[*]/)) {
79 if (request.responseText == null)
81 if (request.responseText == '<DB_NO_KEY>') {
82 url = '?cmd=jset&odb=' + path + '&value=' + defval + '&len=' + len + '&type=' + type;
84 request.open('GET', url, false);
88 var array = request.responseText.split('\n');
92 if ((request.responseText == '<DB_NO_KEY>' ||
93 request.responseText == '<DB_OUT_OF_RANGE>') && defval != undefined) {
94 url = '?cmd=jset&odb=' + path + '&value=' + defval + '&len=' + len + '&type=' + type;
96 request.open('GET', url, false);
100 return request.responseText.split('\n')[0];
104function ODBMGet(paths, callback, formats)
106 var request = XMLHttpRequestGeneric();
108 var url = ODBUrlBase + '?cmd=jget';
109 for (var i=0 ; i<paths.length ; i++) {
110 url += '&odb'+i+'='+paths[i];
111 if (formats != undefined && formats != '')
112 url += '&format'+i+'=' + formats[i];
115 if (callback != undefined) {
116 request.onreadystatechange = function()
118 if (request.readyState == 4) {
119 if (request.status == 200) {
120 var array = request.responseText.split('$#----#$\n');
121 for (var i=0 ; i<array.length ; i++)
122 if (paths[i].match(/[*]/)) {
123 array[i] = array[i].split('\n');
126 array[i] = array[i].split('\n')[0];
131 request.open('GET', url, true);
133 request.open('GET', url, false);
136 if (callback == undefined) {
137 var array = request.responseText.split('$#----#$\n');
138 for (var i=0 ; i<array.length ; i++) {
139 if (paths[i].match(/[*]/)) {
140 array[i] = array[i].split('\n');
143 array[i] = array[i].split('\n')[0];
149function ODBGetRecord(path)
151 var request = XMLHttpRequestGeneric();
153 var url = ODBUrlBase + '?cmd=jget&odb=' + path + '&name=1';
154 request.open('GET', url, false);
156 return request.responseText;
159function ODBExtractRecord(record, key)
161 var array = record.split('\n');
162 for (var i=0 ; i<array.length ; i++) {
163 var ind = array[i].indexOf(':');
165 var k = array[i].substr(0, ind);
167 return array[i].substr(ind+1, array[i].length);
169 var ind = array[i].indexOf('[');
171 var k = array[i].substr(0, ind);
174 for (var j=0 ; ; j++,i++) {
175 if (array[i].substr(0, ind) != key)
177 var k = array[i].indexOf(':');
178 a[j] = array[i].substr(k+1, array[i].length);
189 var request = XMLHttpRequestGeneric();
191 var url = ODBUrlBase + '?cmd=jkey&odb=' + path;
192 request.open('GET', url, false);
194 if (request.responseText == null)
196 var res = request.responseText.split('\n');
199 this.num_values = res[2];
200 this.item_size = res[3];
201 this.last_written = res[4];
204function ODBCopy(path, format)
206 var request = XMLHttpRequestGeneric();
208 var url = ODBUrlBase + '?cmd=jcopy&odb=' + path;
209 if (format != undefined && format != '')
210 url += '&format=' + format;
211 request.open('GET', url, false);
213 return request.responseText;
216function ODBCall(url, callback)
218 var request = XMLHttpRequestGeneric();
220 if (callback != undefined) {
221 request.onreadystatechange = function()
223 if (request.readyState == 4) {
224 if (request.status == 200) {
225 callback(request.responseText);
229 request.open('GET', url, true);
234 request.open('GET', url, false);
236 return request.responseText;
239function ODBMCopy(paths, callback, encoding)
241 var url = ODBUrlBase + '?cmd=jcopy';
242 for (var i=0 ; i<paths.length ; i++) {
243 url += '&odb'+i+'='+encodeURIComponent(paths[i]);
246 if (encoding != undefined && encoding != '')
247 url += '&encoding=' + encodeURIComponent(encoding);
249 return ODBCall(url, callback);
252function ODBMLs(paths, callback)
254 var url = ODBUrlBase + '?cmd=jcopy&encoding=json-norecurse';
255 for (var i=0 ; i<paths.length ; i++) {
256 url += '&odb'+i+'='+encodeURIComponent(paths[i]);
259 return ODBCall(url, callback);
262function ODBMCreate(paths, types, arraylengths, stringlengths, callback)
264 var url = ODBUrlBase + '?cmd=jcreate';
265 for (var i=0 ; i<paths.length ; i++) {
266 url += '&odb'+i+'='+encodeURIComponent(paths[i]);
267 url += '&type'+i+'='+encodeURIComponent(types[i]);
268 if (arraylengths != undefined) {
269 url += '&arraylen'+i+'='+encodeURIComponent(arraylengths[i]);
271 if (stringlengths != undefined) {
272 url += '&strlen'+i+'='+encodeURIComponent(stringlengths[i]);
275 return ODBCall(url, callback);
278function ODBMResize(paths, arraylengths, stringlengths, callback)
280 var url = ODBUrlBase + '?cmd=jresize';
281 for (var i=0 ; i<paths.length ; i++) {
282 url += '&odb'+i+'='+encodeURIComponent(paths[i]);
283 url += '&arraylen'+i+'='+encodeURIComponent(arraylengths[i]);
284 url += '&strlen'+i+'='+encodeURIComponent(stringlengths[i]);
286 return ODBCall(url, callback);
289function ODBMRename(paths, names, callback)
291 var url = ODBUrlBase + '?cmd=jrename';
292 for (var i=0 ; i<paths.length ; i++) {
293 url += '&odb'+i+'='+encodeURIComponent(paths[i]);
294 url += '&name'+i+'='+encodeURIComponent(names[i]);
296 return ODBCall(url, callback);
299function ODBMLink(paths, links, callback)
301 var url = ODBUrlBase + '?cmd=jlink';
302 for (var i=0 ; i<paths.length ; i++) {
303 url += '&dest'+i+'='+encodeURIComponent(paths[i]);
304 url += '&odb'+i+'='+encodeURIComponent(links[i]);
306 return ODBCall(url, callback);
309function ODBMReorder(paths, indices, callback)
311 var url = ODBUrlBase + '?cmd=jreorder';
312 for (var i=0 ; i<paths.length ; i++) {
313 url += '&odb'+i+'='+encodeURIComponent(paths[i]);
314 url += '&index'+i+'='+encodeURIComponent(indices[i]);
316 return ODBCall(url, callback);
319function ODBMKey(paths, callback)
321 var url = ODBUrlBase + '?cmd=jkey&encoding=json';
322 for (var i=0 ; i<paths.length ; i++) {
323 url += '&odb'+i+'='+encodeURIComponent(paths[i]);
325 return ODBCall(url, callback);
328function ODBMDelete(paths, callback)
330 var url = ODBUrlBase + '?cmd=jdelete';
331 for (var i=0 ; i<paths.length ; i++) {
332 url += '&odb'+i+'='+encodeURIComponent(paths[i]);
334 return ODBCall(url, callback);
337function ODBRpc_rev0(name, rpc, args)
339 var request = XMLHttpRequestGeneric();
341 var url = ODBUrlBase + '?cmd=jrpc_rev0&name=' + name + '&rpc=' + rpc;
342 for (var i = 2; i < arguments.length; i++) {
343 url += '&arg'+(i-2)+'='+arguments[i];
345 request.open('GET', url, false);
347 if (request.responseText == null)
349 this.reply = request.responseText.split('\n');
352function ODBRpc_rev1(name, rpc, max_reply_length, args)
354 var request = XMLHttpRequestGeneric();
356 var url = ODBUrlBase + '?cmd=jrpc_rev1&name=' + name + '&rpc=' + rpc + '&max_reply_length=' + max_reply_length;
357 for (var i = 3; i < arguments.length; i++) {
358 url += '&arg'+(i-3)+'='+arguments[i];
360 request.open('GET', url, false);
362 if (request.responseText == null)
364 return request.responseText;
367function ODBRpc(program_name, command_name, arguments_string, callback, max_reply_length)
369 var url = ODBUrlBase + '?cmd=jrpc';
370 url += '&name=' + encodeURIComponent(program_name);
371 url += '&rcmd=' + encodeURIComponent(command_name);
372 url += '&rarg=' + encodeURIComponent(arguments_string);
373 if (max_reply_length) {
374 url += '&max_reply_length=' + encodeURIComponent(max_reply_length);
376 return ODBCall(url, callback);
379function ODBGetMsg(facility, start, n)
381 var request = XMLHttpRequestGeneric();
383 var url = ODBUrlBase + '?cmd=jmsg&f='+facility+'&t=' + start+'&n=' + n;
384 request.open('GET', url, false);
387 if (n > 1 || n == 0) {
388 var array = request.responseText.split('\n');
389 while (array.length > 1 && array[array.length-1] == "")
390 array = array.slice(0, array.length-1);
393 return request.responseText;
396function ODBGenerateMsg(type,facility,user,msg)
398 var request = XMLHttpRequestGeneric();
400 var url = ODBUrlBase + '?cmd=jgenmsg';
401 url += '&type='+type;
402 url += '&facility='+facility;
403 url += '&user='+user;
404 url += '&msg=' + encodeURIComponent(msg);
405 request.open('GET', url, false);
407 return request.responseText;
410function ODBGetAlarms()
412 var request = XMLHttpRequestGeneric();
413 request.open('GET', ODBUrlBase + '?cmd=jalm', false);
415 var a = request.responseText.split('\n');
416 a.length = a.length-1;
420function ODBEdit(path)
422 var value = ODBGet(encodeURIComponent(path));
423 var new_value = prompt('Please enter new value', value);
424 if (new_value != undefined) {
425 ODBSet(encodeURIComponent(path), new_value);
426 window.location.reload();
430function getMouseXY(e)
432 // to activate getMouseXY(), do this:
433 // document.onmousemove = getMouseXY;
438 var p = 'abs: ' + x + '/' + y;
439 i = document.getElementById('refimg');
442 document.body.style.cursor = 'crosshair';
445 while (i = i.offsetParent) {
449 p += ' rel: ' + x + '/' + y;
463 * indent-tabs-mode: nil