From 1cbcde7fb71aaee91121fd9e8d2d0ef08f8e682b Mon Sep 17 00:00:00 2001 From: Etenil Date: Wed, 23 Feb 2011 20:27:56 +0000 Subject: [PATCH] Adapted widgets to the new js rpc. --- js/movimrpc.js | 41 ++++++++++++++++++++------------- lib/Ajaxer.php | 9 ++------ lib/Widget.php | 21 +++++++++-------- lib/widgets/Chat/Chat.php | 4 ++-- lib/widgets/Config/Config.php | 2 +- lib/widgets/Friends/Friends.php | 6 ++--- lib/widgets/Logout/Logout.php | 2 +- 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/js/movimrpc.js b/js/movimrpc.js index 6a2453595..5f5519bba 100644 --- a/js/movimrpc.js +++ b/js/movimrpc.js @@ -50,6 +50,8 @@ function movim_drop(params) // log('movim_drop called.'); } +var movim_xmlhttp; + /*********************************************************************** * MOVIM RPC class. * @@ -60,13 +62,7 @@ function movim_drop(params) */ function MovimRPC() { - /* Properties */ - this.widget = ''; - this.func = ''; - this.params = []; - /* Methods */ - this.xmlhttp = this.make_xmlhttp(); this.make_xmlhttp = MovimRPC_make_xmlhttp; this.commit = MovimRPC_commit; @@ -79,6 +75,11 @@ function MovimRPC() this.handle_rpc = MovimRPC_handle_rpc; this.generate_xml = MovimRPC_generate_xml; + + /* Properties */ + this.widget = ''; + this.func = ''; + this.params = []; } /** @@ -90,7 +91,7 @@ function MovimRPC_set_call(widget, func, params) this.set_func(func); this.params = params; } -n + /** * What widget do we call? */ @@ -185,15 +186,20 @@ function MovimRPC_generate_xml() + "\n"; } } + else { + params += this.params[i]; + } - params +=''; + params +="\n"; } var request = '' - + '' + "\n" + + '' + "\n" + params + "\n" + '' + "\n"; + + return request; } /** @@ -206,18 +212,21 @@ function MovimRPC_generate_xml() */ function MovimRPC_commit() { - movimAjax.open('POST', 'jajax.php', true); + movim_xmlhttp = this.make_xmlhttp(); + + movim_xmlhttp.open('POST', 'jajax.php', true); - movimAjax.onreadystatechange = function() + movim_xmlhttp.onreadystatechange = function() { - if(movimAjax.readyState == 4 && movimAjax.status == 200) { - log("Received data " + movimAjax.responseText); - this.handle_rpc(movimAjax.responseXML); + if(movim_xmlhttp.readyState == 4 && movim_xmlhttp.status == 200) { + log("Received data " + movim_xmlhttp.responseText); + MovimRPC_handle_rpc(movim_xmlhttp.responseXML); } }; - movimAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - movimAjax.send(request); + movim_xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + var data = this.generate_xml(); + movim_xmlhttp.send(data); } /** diff --git a/lib/Ajaxer.php b/lib/Ajaxer.php index ecb9850d5..afd45f02e 100644 --- a/lib/Ajaxer.php +++ b/lib/Ajaxer.php @@ -47,14 +47,9 @@ class Ajaxer extends Controller foreach($this->funclist as $funcdef) { $parlist = implode(', ', $funcdef['params']); - $pardef = $parlist; - if($pardef != "") { - $pardef = ", ".$parlist; - } - $buffer .= "function " . $funcdef['object'] . '_' - . $funcdef['funcname'] . "(${pardef}) {"; - $buffer .= "movim_ajaxSend('".$funcdef['object']."', '".$funcdef['funcname']."', options);}\n"; + . $funcdef['funcname'] . "(${parlist}) {"; + $buffer .= "movim_ajaxSend('".$funcdef['object']."', '".$funcdef['funcname']."', [${parlist}]);}\n"; } return $buffer . "\n"; diff --git a/lib/Widget.php b/lib/Widget.php index 943546bf3..f07ca5802 100644 --- a/lib/Widget.php +++ b/lib/Widget.php @@ -89,21 +89,24 @@ class Widget return $path; } - protected function callAjax($funcname, $callback, $target) + protected function callAjax($funcname) { - echo $this->genCallAjax($funcname, $callback, $target); + echo $this->makeCallAjax(func_get_args()); } - protected function genCallAjax($funcname, $callback, $target) + protected function genCallAjax($funcname) { - $args = implode(', ', array_slice(func_get_args(), 3)); - if($args != "") { - $args = ', ' . $args; - } - - return get_class($this) . '_' . $funcname . "($callback, $target" . $args . ");"; + return $this->makeCallAjax(func_get_args()); } + protected function makeCallAjax($params) + { + $funcname = array_shift($params); + $args = implode(', ', $params); + + return get_class($this) . '_' . $funcname . "(" . $args . ");"; + } + /** * Adds a javascript file to this widget. */ diff --git a/lib/widgets/Chat/Chat.php b/lib/widgets/Chat/Chat.php index 87b22c32f..50e42652e 100644 --- a/lib/widgets/Chat/Chat.php +++ b/lib/widgets/Chat/Chat.php @@ -85,9 +85,9 @@ class Chat extends Widget
- }"/> + }"/> - " value=""/> + " value=""/> getLogin()); - $submit = $this->genCallAjax('ajaxSubmit', "'movim_drop'", "'drop'", "movim_parse_form(document.forms['general'])"); + $submit = $this->genCallAjax('ajaxSubmit', "movim_parse_form(document.forms['general'])"); $form = new Form(); $form->startForm(basename($_SERVER['PHP_SELF']), false, false, 'post', 'general'); diff --git a/lib/widgets/Friends/Friends.php b/lib/widgets/Friends/Friends.php index b0294c2b7..d0943872c 100644 --- a/lib/widgets/Friends/Friends.php +++ b/lib/widgets/Friends/Friends.php @@ -107,13 +107,13 @@ class Friends extends Widget { ?>
-
"> +
" + onclick="callAjax('ajaxRefreshVcard');?>" value="Refresh vcard" />

@@ -126,7 +126,7 @@ class Friends extends Widget
  • Do Not Disturb
  • - " +
    diff --git a/lib/widgets/Logout/Logout.php b/lib/widgets/Logout/Logout.php index 0c3ea91f5..a37a184ec 100644 --- a/lib/widgets/Logout/Logout.php +++ b/lib/widgets/Logout/Logout.php @@ -43,7 +43,7 @@ class Logout extends Widget function build() { ?> -
    ">
    +