Author: nathangray
New Revision: 54923
URL: http://svn.stylite.de/viewvc/egroupware?rev=54923&view=rev
Log:
Add support for global json handlers, and register a global handler for storing data entries
Modified:
trunk/phpgwapi/js/jsapi/egw_data.js
trunk/phpgwapi/js/jsapi/egw_json.js
— trunk/phpgwapi/js/jsapi/egw_data.js (original)
+++ trunk/phpgwapi/js/jsapi/egw_data.js Thu Feb 4 20:26:37 2016
@@ -519,6 +519,25 @@
*/
var registeredCallbacks = {};
-
-
- /**
-
- Register the “data” plugin globally for single uids
-
- Multiple UIDs such as nextmatch results are still handled by egw.data
-
- using dataFetch() && parseServerResponse(), above. Both update the
-
- GLOBAL data cache though this one is registered globally, and the above
-
- */
- egw.registerJSONPlugin(function(type, res, req) {
-
if ((typeof res.data.uid != 'undefined') &&
-
(typeof res.data.data != 'undefined'))
-
{
-
// Store it, which will call all registered listeners
-
this.dataStoreUID(res.data.uid, res.data.data);
-
return true;
-
}
- }, egw, ‘data’,true);
- /**
- Uids and timers used for querying data uids, hashed by the first few
- bytes of the _execId, stored as an object of the form
— trunk/phpgwapi/js/jsapi/egw_json.js (original)
+++ trunk/phpgwapi/js/jsapi/egw_json.js Thu Feb 4 20:26:37 2016
@@ -30,6 +30,15 @@
* to it.
*/
var plugins = {};
+
-
/**
-
- Global json handlers are from global modules, not window level
-
*/
-
if(typeof egw._global_json_handlers == ‘undefined’)
-
{
-
egw._global_json_handlers = {}
-
}
-
var global_plugins = egw._global_json_handlers;
/**
-
Internal implementation of the JSON request object.
@@ -165,24 +174,29 @@
if(typeof res.type == ‘string’ && res.type != ‘data’) only_data = false;
// Check whether a plugin for the given type exists
-
if (typeof plugins[res.type] !== 'undefined')
-
{
-
for (var j = 0; j < plugins[res.type].length; j++) {
-
try {
-
// Get a reference to the plugin
-
var plugin = plugins[res.type][j];
-
-
// Call the plugin callback
-
plugin.callback.call(
-
plugin.context ? plugin.context : this.context,
-
res.type, res, this
-
);
-
} catch(e) {
-
var msg = e.message ? e.message : e + '';
-
var stack = e.stack ? "\n-- Stack trace --\n" + e.stack : "";
-
this.egw.debug('error', 'Exception "' + msg + '" while handling JSON response from ' +
-
this.url + ' [' + JSON.stringify(this.parameters) + '] type "' + res.type +
-
'", plugin', plugin, 'response', res, stack);
-
var handlers = [plugins, global_plugins];
-
for(var handler_idx = 0; handler_idx < handlers.length; handler_idx++)
-
{
-
var handler_level = handlers[handler_idx];
-
if (typeof handler_level[res.type] !== 'undefined')
-
{
-
for (var j = 0; j < handler_level[res.type].length; j++) {
-
try {
-
// Get a reference to the plugin
-
var plugin = handler_level[res.type][j];
-
-
// Call the plugin callback
-
plugin.callback.call(
-
plugin.context ? plugin.context : this.context,
-
res.type, res, this
-
);
-
} catch(e) {
-
var msg = e.message ? e.message : e + '';
-
var stack = e.stack ? "\n-- Stack trace --\n" + e.stack : "";
-
this.egw.debug('error', 'Exception "' + msg + '" while handling JSON response from ' +
-
this.url + ' [' + JSON.stringify(this.parameters) + '] type "' + res.type +
-
'", plugin', plugin, 'response', res, stack);
-
}
}
}
}
@@ -229,23 +243,32 @@
* @param _type is an optional parameter defaulting to ‘global’.
* it describes the response type which this plugin should be
* handling.
-
* @param {boolean} [_global=false] Register the handler globally or
-
* locally. Global handlers must stay around, so should be used
-
* for global modules.
*/
-
registerJSONPlugin: function(_callback, _context, _type, _global)
{
// _type defaults to 'global'
if (typeof _type === 'undefined')
{
_type = 'global';
}
-
// _global defaults to false
-
if (typeof _global === 'undefined')
-
{
-
_global = false;
-
}
-
var scoped = _global ? global_plugins : plugins;
// Create an array for the given category inside the plugins object
@@ -261,22 +284,28 @@
* @param _type is an optional parameter defaulting to ‘global’.
* it describes the response type which this plugin should be
* handling.
-
unregisterJSONPlugin: function(_callback, _context, _type, _global)
{
// _type defaults to 'global'
if (typeof _type === 'undefined')
{
_type = 'global';
}
-
-
if (typeof plugins[_type] !== 'undefined') {
-
for (var i = 0; i < plugins[_type].length; i++)
-
{
-
if (plugins[_type][i].callback == _callback &&
-
plugins[_type][i].context == _context)
-
// _global defaults to false
-
if (typeof _global === 'undefined')
-
{
-
_global = false;
-
}
-
var scoped = _global ? global_plugins : plugins;
-
if (typeof scoped[_type] !== 'undefined') {
-
for (var i = 0; i < scoped[_type].length; i++)
-
{
-
if (scoped[_type][i].callback == _callback &&
-
scoped[_type][i].context == _context)
{
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
eGroupWare-cvs mailing list
eGroupWare-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/egroupware-cvs