Browse Source

Adapted widgets to the new js rpc.

pull/5/head
Etenil 15 years ago
parent
commit
1cbcde7fb7
  1. 41
      js/movimrpc.js
  2. 9
      lib/Ajaxer.php
  3. 21
      lib/Widget.php
  4. 4
      lib/widgets/Chat/Chat.php
  5. 2
      lib/widgets/Config/Config.php
  6. 6
      lib/widgets/Friends/Friends.php
  7. 2
      lib/widgets/Logout/Logout.php

41
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()
+ "</arrayelt>\n";
}
}
else {
params += this.params[i];
}
params +='</param>';
params +="</param>\n";
}
var request =
'<?xml version="1.0" encoding="UTF-8" ?>'
+ '<funcall widget="'+ widget + '" name="' + func + '">' + "\n"
+ '<funcall widget="'+ this.widget + '" name="' + this.func + '">' + "\n"
+ params + "\n"
+ '</funcall>' + "\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);
}
/**

9
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 . "</script>\n";

21
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.
*/

4
lib/widgets/Chat/Chat.php

@ -85,9 +85,9 @@ class Chat extends Widget
</div>
<div id="chatMessages">
</div>
<input type="text" id="chatInput" value="Message" onfocus="myFocus(this);" onblur="myBlur(this);" onkeypress="if(event.keyCode == 13) {<?php $this->callAjax('ajaxSendMessage', 'movim_drop', "'test'", "getDest()", "getMessageText()");?>}"/>
<input type="text" id="chatInput" value="Message" onfocus="myFocus(this);" onblur="myBlur(this);" onkeypress="if(event.keyCode == 13) {<?php $this->callAjax('ajaxSendMessage', "getDest()", "getMessageText()");?>}"/>
<input type="text" id="chatTo" value="To" onfocus="myFocus(this);" onblur="myBlur(this);" />
<input type="button" id="chatSend" onclick="<?php $this->callAjax('ajaxSendMessage', 'movim_drop', "'test'", "getDest()", "getMessageText()");?>" value="<?php echo t('Send');?>"/>
<input type="button" id="chatSend" onclick="<?php $this->callAjax('ajaxSendMessage', "getDest()", "getMessageText()");?>" value="<?php echo t('Send');?>"/>
</div>
<?php

2
lib/widgets/Config/Config.php

@ -33,7 +33,7 @@ class Config extends Widget
$usr = new User();
$conf = GetConf::getUserConf($usr->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');

6
lib/widgets/Friends/Friends.php

@ -107,13 +107,13 @@ class Friends extends Widget
{
?>
<div id="friends">
<div class="config_button" onclick="<?php $this->callAjax('ajaxConfig', "'movim_drop'", "'drop'");?>">
<div class="config_button" onclick="<?php $this->callAjax('ajaxConfig');?>">
</div>
<div id="drop" style="display: none;"></div>
<div id="avatar"></div>
<input type="button"
onclick="<?php $this->callAjax('ajaxRefreshVcard', "'movim_drop'", "'drop'");?>"
onclick="<?php $this->callAjax('ajaxRefreshVcard');?>"
value="Refresh vcard" />
<h3><?php echo t('Contacts');?></h3>
@ -126,7 +126,7 @@ class Friends extends Widget
<li class="dnd">Do Not Disturb</li>
</ul>
</div>
<input type="button" onclick="<?php $this->callAjax('ajaxRefreshRoster', "'movim_drop'", "'drop'");?>"
<input type="button" onclick="<?php $this->callAjax('ajaxRefreshRoster');?>"
value="Refresh Roster" />
<div id="testzone"></div>
</div>

2
lib/widgets/Logout/Logout.php

@ -43,7 +43,7 @@ class Logout extends Widget
function build()
{
?>
<div id="logout" onclick="<?php $this->callAjax('ajaxLogout', "'movim_drop'", "'drop'");?>"></div>
<div id="logout" onclick="<?php $this->callAjax('ajaxLogout');?>"></div>
<?php
}
}

Loading…
Cancel
Save