Reworked addScriptCall function

This commit is contained in:
Andreas Stöckel 2010-06-15 14:05:56 +00:00
parent 2181c9ca9e
commit a085ffb24c

View File

@ -11,14 +11,14 @@
*/ */
/** /**
* Class handling JSON requests to the server * Class handling JSON requests to the server
*/ */
class egw_json_request class egw_json_request
{ {
/** /**
* Parses the raw input data supplied with the input_data parameter and calls the menuaction * Parses the raw input data supplied with the input_data parameter and calls the menuaction
* passing all parameters supplied in the request to it. * passing all parameters supplied in the request to it.
* *
* @param string menuaction to call * @param string menuaction to call
* @param string $input_data is the RAW input data as it was received from the client * @param string $input_data is the RAW input data as it was received from the client
* @returns NULL if parsing the request failed, or the result of the callback function if the request has been successfully decoded. * @returns NULL if parsing the request failed, or the result of the callback function if the request has been successfully decoded.
@ -45,7 +45,7 @@ class egw_json_request
if (isset($json['request'])) if (isset($json['request']))
{ {
$request = $json['request']; $request = $json['request'];
//Check whether any parameters were supplied along with the request //Check whether any parameters were supplied along with the request
if (isset($request['parameters'])) if (isset($request['parameters']))
$parameters = $request['parameters']; $parameters = $request['parameters'];
@ -61,7 +61,7 @@ class egw_json_request
/** /**
* Request handler * Request handler
* *
* @param string $menuaction * @param string $menuaction
* @param array $parameters * @param array $parameters
*/ */
@ -121,9 +121,9 @@ class egw_json_request
} }
else else
{ {
$ajaxClass = CreateObject($appName.'.'.$className); $ajaxClass = CreateObject($appName.'.'.$className);
} }
$parameters = translation::convert($parameters, 'utf-8'); $parameters = translation::convert($parameters, 'utf-8');
// error_log(print_r($parameters, true)); // error_log(print_r($parameters, true));
@ -140,31 +140,31 @@ class egw_json_request
class egw_json_response class egw_json_response
{ {
/** /**
* A response can only contain one generic data part. * A response can only contain one generic data part.
* This variable is used to store, whether a data part had already been added to the response. * This variable is used to store, whether a data part had already been added to the response.
* *
* @var boolean * @var boolean
*/ */
private $hasData = false; private $hasData = false;
/** /**
* Holds the actual response data which is then encoded to JSON * Holds the actual response data which is then encoded to JSON
* once the "getJSON" function is called * once the "getJSON" function is called
* *
* @var array * @var array
*/ */
protected $responseArray = array(); protected $responseArray = array();
/** /**
* Holding instance of class for singelton egw_json_response::get() * Holding instance of class for singelton egw_json_response::get()
* *
* @var egw_json_response * @var egw_json_response
*/ */
private static $response = null; private static $response = null;
/** /**
* Singelton for class * Singelton for class
* *
* @return egw_json_response * @return egw_json_response
*/ */
public static function get() public static function get()
@ -191,9 +191,9 @@ class egw_json_response
public function sendResult() public function sendResult()
{ {
$this->sendHeader(); $this->sendHeader();
echo $this->getJSON(); echo($this->getJSON());
} }
/** /**
* xAjax compatibility function * xAjax compatibility function
*/ */
@ -214,10 +214,10 @@ class egw_json_response
} }
/** /**
* Adds a "data" response to the json response. * Adds a "data" response to the json response.
* *
* This function may only be called once for a single JSON response object. * This function may only be called once for a single JSON response object.
* *
* @param object|array|string $data can be of any data type and will be added JSON Encoded to your response. * @param object|array|string $data can be of any data type and will be added JSON Encoded to your response.
*/ */
public function data($data) public function data($data)
@ -235,10 +235,10 @@ class egw_json_response
} }
/** /**
* Adds an "alert" to the response which can be handeled on the client side. * Adds an "alert" to the response which can be handeled on the client side.
* *
* The default implementation simply displays the text supplied here with the JavaScript function "alert". * The default implementation simply displays the text supplied here with the JavaScript function "alert".
* *
* @param string $message contains the actual message being sent to the client. * @param string $message contains the actual message being sent to the client.
* @param string $details (optional) can be used to inform the user on the client side about additional details about the error. This might be information how the error can be resolved/why it was raised or simply some debug data. * @param string $details (optional) can be used to inform the user on the client side about additional details about the error. This might be information how the error can be resolved/why it was raised or simply some debug data.
*/ */
@ -258,10 +258,10 @@ class egw_json_response
/** /**
* Allows to add a generic java script to the response which will be executed upon the request gets received. * Allows to add a generic java script to the response which will be executed upon the request gets received.
* *
* @deprecated * @deprecated
* @param string $script the script code which should be executed upon receiving * @param string $script the script code which should be executed upon receiving
*/ */
public function script($script) public function script($script)
{ {
if (is_string($script)) if (is_string($script))
@ -276,9 +276,9 @@ class egw_json_response
/** /**
* Allows to add a global javascript function with giben parameters * Allows to add a global javascript function with giben parameters
* *
* @param string $script the script code which should be executed upon receiving * @param string $script the script code which should be executed upon receiving
*/ */
public function jquery($selector,$method,array $parameters=array()) public function jquery($selector,$method,array $parameters=array())
{ {
if (is_string($selector) && is_string($method)) if (is_string($selector) && is_string($method))
@ -297,7 +297,7 @@ class egw_json_response
/** /**
* Adds an html assign to the response, which is excecuted upon the request is received. * Adds an html assign to the response, which is excecuted upon the request is received.
* *
* @param string $id id of dom element to modify * @param string $id id of dom element to modify
* @param string $key attribute name of dom element which should be modified * @param string $key attribute name of dom element which should be modified
* @param string $value the value which should be assigned to the given attribute * @param string $value the value which should be assigned to the given attribute
@ -317,10 +317,10 @@ class egw_json_response
throw new Exception("Invalid parameters supplied"); throw new Exception("Invalid parameters supplied");
} }
} }
/** /**
* Redirect to given url * Redirect to given url
* *
* @param string $url * @param string $url
*/ */
public function redirect($url, $global = false) public function redirect($url, $global = false)
@ -337,14 +337,14 @@ class egw_json_response
/** /**
* Returns the actual JSON code generated by calling the above "add" function. * Returns the actual JSON code generated by calling the above "add" function.
* *
* @return string * @return string
*/ */
public function getJSON() public function getJSON()
{ {
/* Wrap the result array into a parent "response" Object */ /* Wrap the result array into a parent "response" Object */
$res = array('response' => $this->responseArray); $res = array('response' => $this->responseArray);
return json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); return json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
} }
@ -387,7 +387,7 @@ class xajaxResponse extends egw_json_response
$args = func_get_args(); $args = func_get_args();
$func = array_shift($args); $func = array_shift($args);
$this->script("$func(".implode(",", $args).");"); $this->script("window['".$func."'].apply(window, ".json_encode($args).");");
} }
public function getXML() public function getXML()