mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
allow to explicit register callbacks for the broadcasted push messages
egw.registerPush(Function) The callback should have a bound context, if it requires one!
This commit is contained in:
parent
eae9c97caa
commit
5f7bafd030
@ -20,6 +20,13 @@ egw.extend('jsonq', egw.MODULE_GLOBAL, function()
|
||||
{
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Explicit registered push callbacks
|
||||
*
|
||||
* @type {Function[]}
|
||||
*/
|
||||
let push_callbacks = [];
|
||||
|
||||
/**
|
||||
* Queued json requests (objects with attributes menuaction, parameters, context, callback, sender and callbeforesend)
|
||||
*
|
||||
@ -149,6 +156,34 @@ egw.extend('jsonq', egw.MODULE_GLOBAL, function()
|
||||
}, 100);
|
||||
}
|
||||
return uid;
|
||||
},
|
||||
|
||||
/**
|
||||
* Register a callback to receive push broadcasts eg. in a popup or iframe
|
||||
*
|
||||
* It's also used internally by egw_message's push method to dispatch to the registered callbacks.
|
||||
*
|
||||
* @param {Function|PushData} data callback (with bound context) or PushData to dispatch to callbacks
|
||||
*/
|
||||
registerPush: function(data)
|
||||
{
|
||||
if (typeof data === "function")
|
||||
{
|
||||
push_callbacks.push(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (let n in push_callbacks)
|
||||
{
|
||||
try {
|
||||
push_callbacks[n].call(this, data);
|
||||
}
|
||||
// if we get an exception, we assume the callback is no longer available and remove it
|
||||
catch (ex) {
|
||||
push_callbacks.splice(n, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -459,6 +459,9 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
|
||||
app_obj.push(pushData);
|
||||
}
|
||||
}
|
||||
|
||||
// call the global registered push callbacks
|
||||
this.registerPush(pushData);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user