diff options
author | Andrew Bartlett <abartlet@samba.org> | 2007-09-07 03:08:44 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 15:05:21 -0500 |
commit | f8573766bc17af0afacc5d44d3c3d8234b426dbf (patch) | |
tree | 55dfe87448d6332ff48ba6e74fd3226fdd7422f6 /swat/scripting/client/call.js | |
parent | 8f3ab786f03e1bb5bf73fe9d7264b1b0bbb90a75 (diff) | |
download | samba-f8573766bc17af0afacc5d44d3c3d8234b426dbf.tar.gz samba-f8573766bc17af0afacc5d44d3c3d8234b426dbf.tar.bz2 samba-f8573766bc17af0afacc5d44d3c3d8234b426dbf.zip |
r24985: Start to revert us back to the old-style SWAT, while trying not to
loose some of the fixes in the meantime.
Andrew Bartlett
(This used to be commit 13acff5ed259e7b5859fd2324ea7740b8f9e5fd7)
Diffstat (limited to 'swat/scripting/client/call.js')
-rw-r--r-- | swat/scripting/client/call.js | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/swat/scripting/client/call.js b/swat/scripting/client/call.js new file mode 100644 index 0000000000..2886471db2 --- /dev/null +++ b/swat/scripting/client/call.js @@ -0,0 +1,118 @@ +/* + client side js functions for remote calls into the server + + Copyright Andrew Tridgell 2005 + released under the GNU GPL Version 2 or later +*/ + +var __call = new Object(); + +/* + we can't use the qooxdoo portability layer for this, as it assumes + you are using an XML transport, so instead replicate the portability + code for remote calls here. Don't look too closely or you will go + blind. +*/ +__call._activex = window.ActiveXObject && !(new QxClient).isOpera() ? true : false; +__call._activexobj = null; +__call._ok = QxXmlHttpLoader._http || QxXmlHttpLoader._activex; + +if (__call._activex) { + var servers = ["MSXML2", "Microsoft", "MSXML", "MSXML3"]; + for (var i=0; i<servers.length; i++) { + try { + var o = new ActiveXObject(servers[i] + ".XMLHTTP"); + __call._activexobj = servers[i]; + o = null; + } catch(ex) {}; + }; +}; + +/* + return a http object ready for a remote call +*/ +function __http_object() { + return __call._activex ? + new ActiveXObject(__call._activexobj + ".XMLHTTP") : + new XMLHttpRequest(); +} + +/* + usage: + + vserver_call(url, func, callback, args); + + 'func' is a function name to call on the server + any additional arguments are passed to func() on the server + + The callback() function is called with the returned + object. 'callback' may be null. +*/ +function vserver_call_url(url, func, callback, args) { + var args2 = new Object(); + args2.length = args.length; + var i; + for (i=0;i<args.length;i++) { + args2[i] = args[i]; + } + var req = __http_object(); + req.open("POST", url, true); + req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + req.send("ajaj_func=" + func + "&ajaj_args=" + encodeObject(args2)); + req.onreadystatechange = function() { + if (4 == req.readyState && callback != null) { + var o = decodeObject(req.responseText); + callback(o.res); + } + } +} + + +/* + usage: + + server_call_url(url, func, callback, ...); + + 'func' is a function name to call on the server + any additional arguments are passed to func() on the server + + The callback() function is called with the returned + object. 'callback' may be null. +*/ +function server_call_url(url, func, callback) { + var args = new Object(); + var i; + for (i=3;i<arguments.length;i++) { + args[i-3] = arguments[i]; + } + args.length = i-3; + vserver_call_url(url, func, callback, args); +} + + +/* + call printf on the server +*/ +function srv_printf() { + vserver_call_url('/scripting/general_calls.esp', 'srv_printf', null, arguments); +} + +/* + usage: + + server_call(func, callback, ...); + + 'func' is a function name to call on the server + any additional arguments are passed to func() on the server + + The callback() function is called with the returned + object. 'callback' may be null. +*/ +function server_call(func, callback) { + var args = new Array(arguments.length-2); + var i; + for (i=0;i<args.length;i++) { + args[i] = arguments[i+1]; + } + vserver_call_url("@request.REQUEST_URI", func, callback, args); +} |