Fixed problem with IE, adapted egw_data.js to specification changes

This commit is contained in:
Andreas Stöckel 2012-03-23 12:06:52 +00:00
parent 8bd0e2865d
commit 23f221456f
2 changed files with 58 additions and 52 deletions

View File

@ -137,10 +137,18 @@
// Add an eventlistener for the "onunload" event -- if "onunload" gets // Add an eventlistener for the "onunload" event -- if "onunload" gets
// called, we have to delete the module slot created above // called, we have to delete the module slot created above
_window.addEventListener('beforeunload', function() { var fnct = function() {
cleanupEgwInstances(_instances, _moduleInstances, function(_w) { cleanupEgwInstances(_instances, _moduleInstances, function(_w) {
return _w.window === _window}); return _w.window === _window});
}, false); };
if (_window.attachEvent)
{
_window.attachEvent('onbeforeunload', fnct);
}
else
{
_window.addEventListener('beforeunload', fnct, false);
}
// Otherwise create the window specific instances // Otherwise create the window specific instances
for (var key in _modules) for (var key in _modules)

View File

@ -28,8 +28,7 @@ egw.extend("data", egw.MODULE_APP_LOCAL, function (_app, _wnd) {
return _app + "::" + _uid; return _app + "::" + _uid;
} }
function parseServerResponse(_result, _execId, _queriedRange, _filters, function parseServerResponse(_result, _callback, _context)
_lastModification, _callback, _context)
{ {
// Check whether the result is valid -- so "result" has to be an object // Check whether the result is valid -- so "result" has to be an object
// consting of "order" and "data" // consting of "order" and "data"
@ -44,28 +43,23 @@ egw.extend("data", egw.MODULE_APP_LOCAL, function (_app, _wnd) {
if (_result.order && _result.data) if (_result.order && _result.data)
{ {
var order = []; // Assemble the correct order uids
for (var i = 0; i < _result.order.length; i++)
{
_result.order[i] = UID(_result.order[i]);
}
// Load all data entries that have been sent // Load all data entries that have been sent or delete them
for (var key in _result.data) for (var key in _result.data)
{ {
var uid = UID(key); var uid = UID(key);
egw.dataStoreUID(uid, _result.data[key]); if (_result.data[key] === null)
{
egw.dataDeleteUID(uid);
} }
else
// Iterate over the order entries and check whether all uids are
// available
for (var i = 0; i < _result.order.length; i++)
{ {
// Calculate the actual uid and store it egw.dataStoreUID(uid, _result.data[key]);
var uid = UID(_result.order[i]);
order.push(uid);
// Check whether the data for that row is loaded, if no, update
// the "uidsMissing" variable
if (!egw.dataHasUID(uid))
{
uidsMissing.push(_result.order[i]);
} }
} }
@ -74,21 +68,13 @@ egw.extend("data", egw.MODULE_APP_LOCAL, function (_app, _wnd) {
if (_callback) if (_callback)
{ {
_callback.call(_context, { _callback.call(_context, {
"order": order, "order": _result.order,
"lastModification": "lastModification": _result.lastModification,
typeof _result.lastModification === "undefined" "total": parseInt(_result.total),
? _lastModification : _result.lastModification, "readonlys": _result.readonlys,
"total": _result.total, "rows": _result.rows
"readonlys": _result.readonlys
}); });
} }
// Fetch the missing uids
if (uidsMissing.length > 0)
{
this.dataFetch(_execId, _queriedRange, _filters, null, null,
uidsMissing, null, null);
}
} }
} }
@ -110,11 +96,11 @@ egw.extend("data", egw.MODULE_APP_LOCAL, function (_app, _wnd) {
* readonlys: <READONLYS> * readonlys: <READONLYS>
* } * }
* If a uid got deleted on the server above data is null. * If a uid got deleted on the server above data is null.
* If a uid is obmitted from data, is has not changed since lastModification. * If a uid is omitted from data, is has not changed since lastModification.
* *
* If order/data is null, this means that nothing has changed for the * If order/data is null, this means that nothing has changed for the
* given range. * given range.
* The fetchRows function stores new data for the uid's inside the * The dataFetch function stores new data for the uid's inside the
* local data storage, the grid views are then capable of querying the * local data storage, the grid views are then capable of querying the
* data for those uids from the local storage using the * data for those uids from the local storage using the
* "dataRegisterUID" function. * "dataRegisterUID" function.
@ -154,7 +140,7 @@ egw.extend("data", egw.MODULE_APP_LOCAL, function (_app, _wnd) {
* @param context is the context in which the callback function will get * @param context is the context in which the callback function will get
* called. * called.
*/ */
dataFetch: function (_execId, _queriedRange, _filters, _widgetId, _knownUids, dataFetch: function (_execId, _queriedRange, _filters, _widgetId,
_lastModification, _callback, _context) _lastModification, _callback, _context)
{ {
var request = egw.json( var request = egw.json(
@ -164,23 +150,15 @@ egw.extend("data", egw.MODULE_APP_LOCAL, function (_app, _wnd) {
_queriedRange, _queriedRange,
_filters, _filters,
_widgetId, _widgetId,
_knownUids, egw.dataKnownUIDs(_app),
_lastModification _lastModification
], ],
function(result) { function(result) {
parseServerResponse.call( parseServerResponse(result, _callback, _context);
this,
result,
_execId,
_queriedRange,
_filters,
_lastModification,
_callback,
_context
);
}, },
this this
); );
request.sendRequest();
} }
}; };
@ -302,7 +280,7 @@ egw.extend("data_storage", egw.MODULE_GLOBAL, function (_app, _wnd) {
if ((!_callback || registeredCallbacks[_uid][i].callback === _callback) if ((!_callback || registeredCallbacks[_uid][i].callback === _callback)
&& (!_context || registeredCallbacks[_uid][i].context === _context)) && (!_context || registeredCallbacks[_uid][i].context === _context))
{ {
registeredCallbacks.splice(i, 1); registeredCallbacks[_uid].splice(i, 1);
} }
} }
@ -324,6 +302,26 @@ egw.extend("data_storage", egw.MODULE_GLOBAL, function (_app, _wnd) {
return typeof this.localStorage[_uid] !== "undefined"; return typeof this.localStorage[_uid] !== "undefined";
}, },
/**
* Returns all uids that have the given prefix
* TODO: Improve this
*/
dataKnownUIDs: function (_prefix) {
var result = [];
for (var key in this.localStorage)
{
var parts = key.split("::");
if (parts[0] === _prefix)
{
result.push(parts[1]);
}
}
return result;
},
/** /**
* Stores data for the uid and calls all callback functions registered * Stores data for the uid and calls all callback functions registered
* for that uid. * for that uid.
@ -345,10 +343,10 @@ egw.extend("data_storage", egw.MODULE_GLOBAL, function (_app, _wnd) {
// those. // those.
if (typeof registeredCallbacks[_uid] != "undefined") if (typeof registeredCallbacks[_uid] != "undefined")
{ {
for (var i = 0; i < this.registeredCallbacks.length; i++) for (var i = 0; i < registeredCallbacks[_uid].length; i++)
{ {
this.registeredCallbacks[i].callback.call( registeredCallbacks[_uid][i].callback.call(
this.registeredCallbacks[i].context, registeredCallbacks[_uid][i].context,
_data _data
); );
} }