check if json apply needs a not yet instanciated app.js object and instanciate it in that case

This commit is contained in:
Ralf Becker 2014-01-23 09:03:30 +00:00
parent 653f013975
commit a788827c1e
2 changed files with 38 additions and 24 deletions

View File

@ -225,7 +225,7 @@ function _egw_json_plugin_handle(_type, _response, _context) {
* which handles the actual request. If the menuaction is a full featured * which handles the actual request. If the menuaction is a full featured
* url, this one will be used instead. * url, this one will be used instead.
* @param array _parameters which should be passed to the menuaction function. * @param array _parameters which should be passed to the menuaction function.
* @param object _context is the context which will be used for the callbacks (not callback of sendRequest!) * @param object _context is the context which will be used for the callbacks (not callback of sendRequest!)
*/ */
function egw_json_request(_menuaction, _parameters, _context) function egw_json_request(_menuaction, _parameters, _context)
{ {
@ -306,12 +306,12 @@ egw_json_request.prototype.sendRequest = function(_async, _callback, _sender)
{ {
egw.debug("warn", "egw_json_request is deprecated\n\ egw.debug("warn", "egw_json_request is deprecated\n\
Use egw.json(menuaction, parameters [,callback, context, async, sender]).sendRequest() instead."); Use egw.json(menuaction, parameters [,callback, context, async, sender]).sendRequest() instead.");
//Store the sender and callback parameter inside this class //Store the sender and callback parameter inside this class
this.sender = _sender; this.sender = _sender;
if (typeof _callback != "undefined") if (typeof _callback != "undefined")
this.callback = _callback; this.callback = _callback;
//Copy the async parameter which defaults to "true" //Copy the async parameter which defaults to "true"
var is_async = true; var is_async = true;
if (typeof _async != "undefined") if (typeof _async != "undefined")
is_async = _async; is_async = _async;
@ -332,10 +332,10 @@ Use egw.json(menuaction, parameters [,callback, context, async, sender]).sendReq
context: this, context: this,
data: request_obj, data: request_obj,
dataType: 'json', dataType: 'json',
type: 'POST', type: 'POST',
success: this.handleResponse, success: this.handleResponse,
error: function(_xmlhttp,_err) { error: function(_xmlhttp,_err) {
window.console.error('Ajax request to ' + this.url + ' failed: ' + _err); window.console.error('Ajax request to ' + this.url + ' failed: ' + _err);
} }
}); });
} }
@ -406,15 +406,15 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
{ {
try try
{ {
var res = data.response[i]; var res = data.response[i];
switch (data.response[i].type) switch (data.response[i].type)
{ {
case 'alert': case 'alert':
//Check whether all needed parameters have been passed and call the alertHandler function //Check whether all needed parameters have been passed and call the alertHandler function
if ((typeof res.data.message != 'undefined') && if ((typeof res.data.message != 'undefined') &&
(typeof res.data.details != 'undefined')) (typeof res.data.details != 'undefined'))
{ {
this.alertHandler( this.alertHandler(
res.data.message, res.data.message,
res.data.details) res.data.details)
@ -424,10 +424,10 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
break; break;
case 'assign': case 'assign':
//Check whether all needed parameters have been passed and call the alertHandler function //Check whether all needed parameters have been passed and call the alertHandler function
if ((typeof res.data.id != 'undefined') && if ((typeof res.data.id != 'undefined') &&
(typeof res.data.key != 'undefined') && (typeof res.data.key != 'undefined') &&
(typeof res.data.value != 'undefined')) (typeof res.data.value != 'undefined'))
{ {
var obj = document.getElementById(res.data.id); var obj = document.getElementById(res.data.id);
if (obj) if (obj)
{ {
@ -485,7 +485,13 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
{ {
var parts = res.data.func.split("."); var parts = res.data.func.split(".");
if(parts.length == 3 && typeof window.app[parts[1]] == "object" && // check if we need a not yet instanciated app.js object --> instanciate it now
if (parts.length == 3 && typeof window.app[parts[1]] == 'undefined' &&
typeof window.app.classes[parts[1]] == 'function')
{
window.app[parts[1]] = new window.app.classes[parts[1]]();
}
if(parts.length == 3 && typeof window.app[parts[1]] == "object" &&
typeof window.app[parts[1]][parts[2]] == "function") typeof window.app[parts[1]][parts[2]] == "function")
{ {
try try
@ -641,8 +647,8 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
/* If no explicit response has been specified, call the callback (if one was set) */ /* If no explicit response has been specified, call the callback (if one was set) */
if (!hasResponse && this.callback && data.response[i]) if (!hasResponse && this.callback && data.response[i])
{ {
this.callback.call(this.sender, data.response[i].data); this.callback.call(this.sender, data.response[i].data);
} }
this.handleResponseDone = true; this.handleResponseDone = true;
@ -745,7 +751,7 @@ window.xajax = {
* run over all form elements * run over all form elements
* @param serialized is the object which will contain the form data * @param serialized is the object which will contain the form data
* @param children is the children node of the form we're runing over * @param children is the children node of the form we're runing over
* @param string _filterClass if given only return * @param string _filterClass if given only return
*/ */
function _egw_json_getFormValues(serialized, children, _filterClass) function _egw_json_getFormValues(serialized, children, _filterClass)
{ {
@ -777,19 +783,19 @@ function _egw_json_getObjectLength(_obj)
} }
/** /**
* used internally to serialize * used internally to serialize
*/ */
function _egw_json_getFormValue(serialized, child) function _egw_json_getFormValue(serialized, child)
{ {
//Return if the child doesn't have a name, is disabled, or is a radio-/checkbox and not checked //Return if the child doesn't have a name, is disabled, or is a radio-/checkbox and not checked
if ((typeof child.name == "undefined") || (child.disabled && child.disabled == true) || if ((typeof child.name == "undefined") || (child.disabled && child.disabled == true) ||
(child.type && (child.type == 'radio' || child.type == 'checkbox' || child.type == 'button' || child.type == 'submit') && (!child.checked))) (child.type && (child.type == 'radio' || child.type == 'checkbox' || child.type == 'button' || child.type == 'submit') && (!child.checked)))
{ {
return; return;
} }
var name = child.name; var name = child.name;
var values = null; var values = null;
if ('select-multiple' == child.type) if ('select-multiple' == child.type)
{ {
@ -819,10 +825,10 @@ function _egw_json_getFormValue(serialized, child)
var p = serialized; // pointer reset var p = serialized; // pointer reset
while (a.length != 0) { while (a.length != 0) {
var sa = a.substr(0, a.indexOf(']')+1); var sa = a.substr(0, a.indexOf(']')+1);
var lk = k; //save last key var lk = k; //save last key
var lp = p; //save last pointer var lp = p; //save last pointer
a = a.substr(a.indexOf(']')+1); a = a.substr(a.indexOf(']')+1);
p = p[k]; p = p[k];
k = sa.substr(1, sa.length-2); k = sa.substr(1, sa.length-2);
@ -836,7 +842,7 @@ function _egw_json_getFormValue(serialized, child)
} }
if (typeof p[k] == 'undefined') if (typeof p[k] == 'undefined')
{ {
p[k] = new Object; p[k] = new Object;
} }
} }
p[k] = values; p[k] = values;

View File

@ -332,9 +332,17 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
var parts = res.data.func.split('.'); var parts = res.data.func.split('.');
var func = parts.pop(); var func = parts.pop();
var parent = req.egw.window; var parent = req.egw.window;
for(var i=0; i < parts.length && typeof parent[parts[i]] != 'undefined'; ++i) for(var i=0; i < parts.length; ++i)
{ {
parent = parent[parts[i]]; if (typeof parent[parts[i]] != 'undefined')
{
parent = parent[parts[i]];
}
// check if we need a not yet instanciated app.js object --> instanciate it now
else if (i == 1 && parts[0] == 'app' && typeof req.egw.window.app.classes[parts[1]] == 'function')
{
parent = parent[parts[1]] = new req.egw.window.app.classes[parts[1]]();
}
} }
if (typeof parent[func] == 'function') if (typeof parent[func] == 'function')
{ {