diff options
Diffstat (limited to 'swat/scripting/client')
-rw-r--r-- | swat/scripting/client/call.js | 118 | ||||
-rw-r--r-- | swat/scripting/client/desktop.js | 121 | ||||
-rw-r--r-- | swat/scripting/client/encoder.js | 84 | ||||
-rw-r--r-- | swat/scripting/client/js_scripts.js | 60 | ||||
-rw-r--r-- | swat/scripting/client/regedit.js | 160 | ||||
-rw-r--r-- | swat/scripting/client/status.js | 40 |
6 files changed, 583 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); +} diff --git a/swat/scripting/client/desktop.js b/swat/scripting/client/desktop.js new file mode 100644 index 0000000000..9e1a342936 --- /dev/null +++ b/swat/scripting/client/desktop.js @@ -0,0 +1,121 @@ +/* + Windows, tabs, and general widgetry for SWAT. + + Copyright (C) Deryck Hodge 2005 + released under the GNU GPL Version 2 or later +*/ + +/* Qooxdoo's browser sniffer doesn't distinguish IE version. +We'll cover IE 6 for now, but these checks need to be +revisited for fuller browser coverage. */ +var browser = QxClient().engine; + +// DocX/Y returns the width/height of the page in browser +function docX() +{ + var x; + if (browser != "mshtml") { + x = window.innerWidth; + } else { + x = document.documentElement.clientWidth; + } + return x; +} + +function docY() +{ + var y; + if (browser != "mshtml") { + y = window.innerHeight; + } else { + y = document.documentElement.clientHeight; + } + return y; +} + +// If given a number, sizeX/Y returns in pixels a percentage of the browser +// window. If given a Window object, sizeX/Y returns the size of that object. +function sizeX(s) +{ + var sX; + + if (typeof(s) == 'number') { + sX = Math.floor(docX() * s); + } else { + sX = s.getMinWidth(); + } + + return sX; +} + +function sizeY(s) +{ + var sY; + if (typeof(s) == 'number') { + sY = Math.floor(docY() * s); + } else { + sY = s.getMinHeight(); + } + + return sY; +} + +function getPosX(win) +{ + var y = Math.floor( (docY() - sizeY(win)) * Math.random() ); + return y; +} + +function getPosY(win) +{ + var x = Math.floor( (docX() - sizeX(win)) * Math.random() ); + return x; +} + +function openIn(e) +{ + var blank = new Window("New Menu"); + e.add(blank); + blank.setVisible(true); +} + +function Window(h, src, s) +{ + this.self = new QxWindow(h); + + // Settings for all windows + if (s) { + this.self.setMinWidth(sizeX(s)); + this.self.setMinHeight(sizeY(s)); + } + this.self.setTop(getPosX(this.self)); + this.self.setLeft(getPosY(this.self)); + + this.self.addEventListener("contextmenu", contextMenu); + + return this.self; +} + +function SmallWindow(h, src) +{ + this.self = new Window(h, src, .20); + return this.self; +} + +function StandardWindow(h, src) +{ + this.self = new Window(h, src, .45); + return this.self; +} + +function LargeWindow(h, src) +{ + this.self = new Window(h, src, .70); + return this.self; +} + +Window.small = SmallWindow; +Window.standard = StandardWindow; +Window.large = LargeWindow; + + diff --git a/swat/scripting/client/encoder.js b/swat/scripting/client/encoder.js new file mode 100644 index 0000000000..4aa4cc0954 --- /dev/null +++ b/swat/scripting/client/encoder.js @@ -0,0 +1,84 @@ +/* + client side js functions for encoding/decoding objects into linear strings + + Copyright Andrew Tridgell 2005 + released under the GNU GPL Version 2 or later +*/ +/* + usage: + + enc = encodeObject(obj); + obj = decodeObject(enc); + + The encoded format of the object is a string that is safe to + use in URLs + + Note that only data elements are encoded, not functions +*/ + +function count_members(o) { + var i, count = 0; + for (i in o) { + count++; + } + return count; +} + +function encodeObject(o) { + var i, r = count_members(o) + ":"; + for (i in o) { + var t = typeof(o[i]); + if (t == 'object') { + r = r + "" + i + ":" + t + ":" + encodeObject(o[i]); + } else if (t == 'string') { + var s = encodeURIComponent(o[i]).replace(/%/g,'#'); + r = r + "" + i + ":" + t + ":" + s + ":"; + } else if (t == 'boolean' || t == 'number') { + r = r + "" + i + ":" + t + ":" + o[i] + ":"; + } else if (t == 'undefined' || t == 'null') { + r = r + "" + i + ":" + t + ":"; + } else if (t != 'function') { + alert("Unable to encode type " + t); + } + } + return r; +} + +function decodeObjectArray(a) { + var o = new Object(); + var i, count = a[a.i]; a.i++; + for (i=0;i<count;i++) { + var name = a[a.i]; a.i++; + var type = a[a.i]; a.i++; + var value; + if (type == 'object') { + o[name] = decodeObjectArray(a); + } else if (type == "string") { + value = decodeURIComponent(a[a.i].replace(/#/g,'%')); a.i++; + o[name] = value; + } else if (type == "boolean") { + value = a[a.i]; a.i++; + if (value == 'true') { + o[name] = true; + } else { + o[name] = false; + } + } else if (type == "undefined") { + o[name] = undefined; + } else if (type == "null") { + o[name] = null; + } else if (type == "number") { + value = a[a.i]; a.i++; + o[name] = value * 1; + } else { + alert("Unable to delinearise type " + type); + } + } + return o; +} + +function decodeObject(str) { + var a = str.split(':'); + a.i = 0; + return decodeObjectArray(a); +} diff --git a/swat/scripting/client/js_scripts.js b/swat/scripting/client/js_scripts.js new file mode 100644 index 0000000000..1c6e5806f4 --- /dev/null +++ b/swat/scripting/client/js_scripts.js @@ -0,0 +1,60 @@ +/* + Beginnnigs of a script manager for SWAT. + + Copyright (C) Deryck Hodge 2005 + released under the GNU GPL Version 2 or later +*/ + +var head = document.getElementsByTagName('head')[0]; +var scripts = document.getElementsByTagName('script'); + +function __has_js_script(file) +{ + var i; + for (i=0; i<scripts.length; i++) { + if (scripts[i].src.indexOf(file) > -1) { + return true; + } else { + return false; + } + } +} + +function __get_js_script(file) +{ + var i; + for (i=0; i<scripts.length; i++) { + if (scripts[i].src.indexOf(file) > -1) { + return scripts[i]; + } + } +} + +function __add_js_script(path) +{ + // Create a unique ID for this script + var srcID = new Date().getTime(); + + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.id = srcID; + + head.appendChild(script); + + // IE works only with the path set after appending to the document + document.getElementById(srcID).src = path; +} + +function __remove_js_script(path) +{ + var script = __get_js_script(path); + script.parentNode.removeChild(script); +} + +document.js = new Object(); +document.js.scripts = scripts; +document.js.hasScript = __has_js_script; +document.js.getScript = __get_js_script; +document.js.add = __add_js_script; +document.js.remove = __remove_js_script; + diff --git a/swat/scripting/client/regedit.js b/swat/scripting/client/regedit.js new file mode 100644 index 0000000000..9175017c2e --- /dev/null +++ b/swat/scripting/client/regedit.js @@ -0,0 +1,160 @@ +/* + client side js functions for registry editing + + Copyright Andrew Tridgell 2005 + released under the GNU GPL Version 2 or later +*/ + + +/* + callback from the key enumeration call +*/ +function __folder_keys(fParent, list) +{ + var i; + if (fParent.working == 1) { + fParent.working = 0; + fParent.removeAll(); + } + for (i=0;i<list.length;i++) { + var fChild; + fChild = new QxTreeFolder(list[i]); + fParent.add(fChild); + fChild.binding = fParent.binding; + if (fParent.reg_path == '\\') { + fChild.reg_path = list[i]; + } else { + fChild.reg_path = fParent.reg_path + '\\' + list[i]; + } + fChild.working = 1; + fChild.add(new QxTreeFolder('Working ...')); + fChild.addEventListener("click", function() { + var el = this; __folder_click(el); + }); + } + fParent.setOpen(1); +} + +/* + callback from the key enumeration call +*/ +function __folder_values(fParent, list) +{ + var i; + if (list.length == 0) { + return; + } + if (fParent.working == 1) { + fParent.working = 0; + fParent.removeAll(); + } + for (i=0;i<list.length;i++) { + var fChild; + fChild = new QxTreeFile(list[i].name); + fChild.parent = fParent; + fChild.details = list[i]; + fParent.add(fChild); + } + fParent.setOpen(1); +} + +/* + called when someone clicks on a folder +*/ +function __folder_click(node) +{ + if (!node.populated) { + node.populated = true; + server_call_url("/scripting/server/regedit.esp", 'enum_keys', + function(list) { __folder_keys(node, list); }, + node.binding, node.reg_path); + server_call_url("/scripting/server/regedit.esp", 'enum_values', + function(list) { __folder_values(node, list); }, + node.binding, node.reg_path); + } +} + +/* return a registry tree for the given server */ +function __registry_tree(binding) +{ + var tree = new QxTree("registry: " + binding); + tree.binding = binding; + tree.reg_path = "\\"; + tree.populated = false; + with(tree) { + setBackgroundColor(255); + setBorder(QxBorder.presets.inset); + setOverflow("scroll"); + setStyleProperty("padding", "2px"); + setWidth("50%"); + setHeight("90%"); + setTop("10%"); + } + tree.addEventListener("click", function() { + var el = this; __folder_click(el); + }); + return tree; +} + +/* + the table of values +*/ +function __values_table() +{ + var headings = new Array("Name", "Type", "Size", "Value"); + var table = document.createElement('table'); + table.border = "1"; + var body = document.createElement('tbody'); + table.appendChild(body); + var th = document.createElement('th'); + for (var i=0;i<headings.length;i++) { + var td = document.createElement('td'); + td.appendChild(document.createTextNode(headings[i])); + th.appendChild(td); + } + body.appendChild(th); + return table; +} + +/* + create a registry editing widget and return it as a object +*/ +function regedit_widget(binding) +{ + var fieldSet = new QxFieldSet(); + + fieldSet.binding = binding; + + with(fieldSet) { + setWidth("100%"); + setHeight("100%"); + }; + + var gl = new QxGridLayout("auto,auto,auto,auto,auto", "50%,50%"); + gl.setEdge(0); + gl.setCellPaddingTop(3); + gl.setCellPaddingBottom(3); + + var t = __registry_tree(fieldSet.binding); + + function change_binding(e) { + fieldSet.binding = e.getNewValue(); + srv_printf("changed binding to %s\\n", fieldSet.binding); + gl.remove(t); + t = __registry_tree(fieldSet.binding); + gl.add(t, { row : 2, col : 1 }); + } + + var b = new QxTextField(fieldSet.binding); + b.addEventListener("changeText", change_binding); + + var values = new __values_table(); + + gl.add(b, { row : 1, col : 1 }); + gl.add(t, { row : 2, col : 1 }); +// gl.add(values, { row : 2, col : 2 }); + + fieldSet.add(gl); + + return fieldSet; +}; diff --git a/swat/scripting/client/status.js b/swat/scripting/client/status.js new file mode 100644 index 0000000000..31ee31c43b --- /dev/null +++ b/swat/scripting/client/status.js @@ -0,0 +1,40 @@ +/* + server status library for SWAT + + released under the GNU GPL Version 2 or later +*/ + + +// Format for a server status table +var s = [ + { id : "server", + label : "Server", + content: "text", + defaultValue : "-", + width : 100 + }, + + { id : "status", + label : "Status", + content: "text", + defaultValue : "-", + width: 100 + } +]; + +function __load_status_table(info, container) +{ + var table = new QxListView(s); + var i; + for (i in info) { + table.addData( {server : i, status : info[i]} ); + } + container.add(table); + container.setVisible(true); +} + +function getServerStatus(container) +{ + server_call_url("/scripting/server/status.esp", 'serverInfo', + function(info) { __load_status_table(info, container); }); +} |