new JSON response method "message" to call egw.message eg. in a popup, by using the context from the egw.json call

This commit is contained in:
Ralf Becker 2018-06-05 12:29:23 +02:00
parent 6f7050d036
commit 430368eab9
2 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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.
*