From a085ffb24cace7489cc26942c42b005683100345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Tue, 15 Jun 2010 14:05:56 +0000 Subject: [PATCH] Reworked addScriptCall function --- phpgwapi/inc/class.egw_json.inc.php | 62 ++++++++++++++--------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/phpgwapi/inc/class.egw_json.inc.php b/phpgwapi/inc/class.egw_json.inc.php index 445f38ee1b..b62f0a67dd 100644 --- a/phpgwapi/inc/class.egw_json.inc.php +++ b/phpgwapi/inc/class.egw_json.inc.php @@ -11,14 +11,14 @@ */ /** - * Class handling JSON requests to the server + * Class handling JSON requests to the server */ class egw_json_request { /** * Parses the raw input data supplied with the input_data parameter and calls the menuaction * passing all parameters supplied in the request to it. - * + * * @param string menuaction to call * @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. @@ -45,7 +45,7 @@ class egw_json_request if (isset($json['request'])) { $request = $json['request']; - + //Check whether any parameters were supplied along with the request if (isset($request['parameters'])) $parameters = $request['parameters']; @@ -61,7 +61,7 @@ class egw_json_request /** * Request handler - * + * * @param string $menuaction * @param array $parameters */ @@ -121,9 +121,9 @@ class egw_json_request } else { - $ajaxClass = CreateObject($appName.'.'.$className); + $ajaxClass = CreateObject($appName.'.'.$className); } - + $parameters = translation::convert($parameters, 'utf-8'); // error_log(print_r($parameters, true)); @@ -140,31 +140,31 @@ class egw_json_request 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. - * + * * @var boolean */ 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 - * + * * @var array */ protected $responseArray = array(); /** * Holding instance of class for singelton egw_json_response::get() - * + * * @var egw_json_response */ private static $response = null; /** * Singelton for class - * + * * @return egw_json_response */ public static function get() @@ -191,9 +191,9 @@ class egw_json_response public function sendResult() { $this->sendHeader(); - echo $this->getJSON(); + echo($this->getJSON()); } - + /** * 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. - * + * * @param object|array|string $data can be of any data type and will be added JSON Encoded to your response. */ 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". - * + * * @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. */ @@ -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. - * + * * @deprecated * @param string $script the script code which should be executed upon receiving - */ + */ public function script($script) { if (is_string($script)) @@ -276,9 +276,9 @@ class egw_json_response /** * Allows to add a global javascript function with giben parameters - * + * * @param string $script the script code which should be executed upon receiving - */ + */ public function jquery($selector,$method,array $parameters=array()) { 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. - * + * * @param string $id id of dom element to modify * @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 @@ -317,10 +317,10 @@ class egw_json_response throw new Exception("Invalid parameters supplied"); } } - + /** * Redirect to given url - * + * * @param string $url */ 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. - * + * * @return string - */ + */ public function getJSON() { /* Wrap the result array into a parent "response" Object */ $res = array('response' => $this->responseArray); - + 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(); $func = array_shift($args); - $this->script("$func(".implode(",", $args).");"); + $this->script("window['".$func."'].apply(window, ".json_encode($args).");"); } public function getXML()