summaryrefslogtreecommitdiffstats
path: root/deluge/ui/webui/templates/ajax/static/js/Rpc.js
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/ui/webui/templates/ajax/static/js/Rpc.js')
-rw-r--r--deluge/ui/webui/templates/ajax/static/js/Rpc.js51
1 files changed, 34 insertions, 17 deletions
diff --git a/deluge/ui/webui/templates/ajax/static/js/Rpc.js b/deluge/ui/webui/templates/ajax/static/js/Rpc.js
index daeb288df..c381f9b99 100644
--- a/deluge/ui/webui/templates/ajax/static/js/Rpc.js
+++ b/deluge/ui/webui/templates/ajax/static/js/Rpc.js
@@ -2,12 +2,29 @@
Script: Rpc.js
A JSON-RPC proxy built ontop of mootools.
-Copyright:
- Damien Churchill (c) 2008 <damoxc@gmail.com>
+ *
+ * Copyright (C) Damien Churchill 2008 <damoxc@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, write to:
+ * The Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301, USA.
+ *
Class: JSON.RPC
Class to create a proxy to a json-rpc interface on a server.
-
+
Example:
client = new JSON.RPC('/json/rpc');
client.hello_world({
@@ -21,18 +38,18 @@ Copyright:
alert(result);
}
});
-
+
Returns:
The proxy that can be used to directly call methods on the server.
*/
JSON.RPC = new Class({
Implements: Options,
-
+
options: {
async: true,
methods: []
},
-
+
initialize: function(url, options) {
this.setOptions(options)
this.url = url
@@ -45,23 +62,23 @@ JSON.RPC = new Class({
}, this)
}
},
-
+
/*
Property: _parseargs
Internal method for parsing the arguments given to the method
-
+
Arguments:
args - A list of the methods arguments
-
+
Returns:
An options object with the arguments set as options.params
-
+
*/
_parseargs: function(args) {
var params = $A(args), options = params.getLast()
if ($type(options) == 'object') {
var option_keys = ['async', 'onRequest', 'onComplete',
- 'onSuccess', 'onFailure', 'onException', 'onCancel'], keys =
+ 'onSuccess', 'onFailure', 'onException', 'onCancel'], keys =
new Hash(options).getKeys(), is_option = false
option_keys.each(function(key) {
@@ -69,7 +86,7 @@ JSON.RPC = new Class({
is_option = true
}
})
-
+
if (is_option) {
params.erase(options)
} else {
@@ -79,19 +96,19 @@ JSON.RPC = new Class({
options.params = params
return options
},
-
+
/*
Property: _execute
An internal method to make the call to the rpc page
-
+
Arguements:
method - the name of the method
options - An options dict providing any additional options for the
call.
-
+
Example:
alert(client.hello_world({async: false;}));
-
+
Returns:
If not async returns the json result
*/
@@ -99,7 +116,7 @@ JSON.RPC = new Class({
options = $pick(options, {})
options.params = $pick(options.params, [])
options.async = $pick(options.async, this.options.async)
-
+
data = JSON.encode({
method: method,
params: options.params,