diff --git a/api/js/jsapi/egw_json.js b/api/js/jsapi/egw_json.js index d3f05e77fc..2b173c363c 100644 --- a/api/js/jsapi/egw_json.js +++ b/api/js/jsapi/egw_json.js @@ -368,6 +368,17 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) throw 'Invalid parameters'; }, null, 'alert'); + // Regisert the "message" plugin + json.registerJSONPlugin(function(type, res, req) { + //Check whether all needed parameters have been passed and call the alertHandler function + if ((typeof res.data.message != 'undefined')) + { + req.egw.message(res.data.message, res.data.type); + return true; + } + throw 'Invalid parameters'; + }, null, 'message'); + // Register the "assign" plugin json.registerJSONPlugin(function(type, res, req) { //Check whether all needed parameters have been passed and call the alertHandler function diff --git a/api/src/Json/Msg.php b/api/src/Json/Msg.php index 4d0b9d2d75..aa55bd5e60 100644 --- a/api/src/Json/Msg.php +++ b/api/src/Json/Msg.php @@ -40,6 +40,29 @@ abstract class Msg } } + /** + * 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 $type =null (optional) "success", "error" or "info", + * null: check for "error" in message and use "error" in that case, otherwise "success" + */ + public function message($message, $type = null) + { + if (is_string($message) && (is_string($type) || is_null($type))) + { + $this->addGeneric('message', array( + "message" => $message, + "type" => $type)); + } + else + { + throw new Exception("Invalid parameters supplied."); + } + } + /** * Allows to add a generic java script to the response which will be executed upon the request gets received. *