1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/sources/system/controllers/AjaxController.php

66 lines
1.4 KiB
PHP
Raw Normal View History

<?php
/**
* @file AjaxController.php
* This file is part of Movim.
*
* @brief Description
*
* @author Timothée jaussoin
*
* @date 14 November 2013
*/
class AjaxController extends BaseController
{
protected $funclist = array();
protected static $instance;
public function __construct()
{
parent::__construct();
}
public static function getInstance()
{
if(!is_object(self::$instance)) {
self::$instance = new AjaxController();
}
return self::$instance;
}
/**
* Generates the javascript part of the ajax.
*/
public function genJs()
{
if(empty($this->funclist)) {
return '';
}
$buffer = '<script type="text/javascript">';
foreach($this->funclist as $funcdef) {
$parlist = implode(', ', $funcdef['params']);
$buffer .= "function " . $funcdef['object'] . '_'
. $funcdef['funcname'] . "(${parlist}) {";
$buffer .= "MovimWebsocket.send('".$funcdef['object']."', '".$funcdef['funcname']."', [${parlist}]);}\n";
}
return $buffer . "</script>\n";
}
/**
* Defines a new function.
*/
public function defun($widget, $funcname, array $params)
{
$this->funclist[] = array(
'object' => $widget,
'funcname' => $funcname,
'params' => $params,
);
}
}
?>