Fixed handling of json requests using etemplate.process_exec and fixes in the json encoding of hierarchical values

This commit is contained in:
Andreas Stöckel 2010-06-10 10:48:59 +00:00
parent b2d782dcd9
commit de3ee335a9
2 changed files with 132 additions and 27 deletions

View File

@ -51,7 +51,6 @@ class egw_json_request
$parameters = $request['parameters'];
/*$parameters = array_stripslashes($request['parameters']);*/
}
//Call the supplied callback function along with the menuaction and the passed parameters
$this->handleRequest($menuaction, $parameters);
}
@ -82,15 +81,15 @@ class egw_json_request
switch($handler)
{
case '/etemplate/process_exec':
$menuaction = $appName.'.'.$className.'.'.$functionName;
$_GET['menuaction'] = $appName.'.'.$className.'.'.$functionName;
$appName = $className = 'etemplate';
$functionName = 'process_exec';
$menuaction = 'etemplate.etemplate.process_exec';
$parameters = array(
$argList[0]['etemplate_exec_id'],
$argList[0]['submit_button'],
$argList[0],
$parameters[0]['etemplate_exec_id'],
$parameters[0]['submit_button'],
$parameters[0],
'xajaxResponse',
);
//error_log("xajax_doXMLHTTP() /etemplate/process_exec handler: arg0='$menuaction', menuaction='$_GET[menuaction]'");
@ -127,6 +126,10 @@ class egw_json_request
$parameters = translation::convert($parameters, 'utf-8');
// error_log(print_r($parameters, true));
// _debug_array($parameters);
call_user_func_array(array($ajaxClass, $functionName), $parameters);
}
}
@ -351,8 +354,7 @@ class egw_json_response
/**
* Deprecated legacy xajax wrapper functions for the new egw_json interface
*/
/*
class xajaxResponse extends egw_json_response
/*class xajaxResponse extends egw_json_response
{
public function addScript($script)
{

View File

@ -117,6 +117,27 @@ egw_json_request.prototype.sendRequest = function(_async, _callback, _sender)
success: this.handleResponse});
}
egw_json_request.prototype.getFormValues = function(_form)
{
var elem = null;
if (typeof _form == 'object')
{
elem = _form;
}
else
{
elem = document.getElementsByName(_form)[0];
}
var serialized = new Object;
if (typeof elem != "undefined" && elem && elem.childNodes)
{
_egw_json_getFormValues(serialized, elem.childNodes)
}
return serialized;
}
egw_json_request.prototype.alertFunc = function(_message, _details)
{
alert(_message);
@ -222,30 +243,28 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
}
/**
* Deprecated legacy xajax wrapper functions for the new egw_json interface
*/
/*
_xajax_doXMLHTTP = function(_async, _menuaction, _arguments)
{
/* Assemble the parameter array *//*
/* Assemble the parameter array */
var paramarray = new Array();
for (var i = 1; i < _arguments.length; i++)
{
paramarray[paramarray.length] = _arguments[i];
}
/* Create a new request, passing the menuaction and the parameter array *//*
/* Create a new request, passing the menuaction and the parameter array */
var request = new egw_json_request(_menuaction, paramarray);
/* Send the request *//*
/* Send the request */
request.sendRequest(_async);
return request;
}
xajax_doXMLHTTP = function(_menuaction)
/*xajax_doXMLHTTP = function(_menuaction)
{
return _xajax_doXMLHTTP(true, _menuaction, arguments);
}
@ -258,18 +277,102 @@ xajax_doXMLHTTPsync = function(_menuaction)
window.xajax = {
"getFormValues": function(_form)
{
var elem = null;
if (typeof _form == 'object')
return egw_json_request.prototype.getFormValues(_form);
}
};*/
/*
The following code is adapted from the xajax project which is licensed under
the following license
@copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
@copyright Copyright (c) 2008-2009 by Joseph Woolley, Steffen Konerow, Jared White & J. Max Wilson
@license http://www.xajaxproject.org/bsd_license.txt BSD License
*/
/**
* used internally by the legacy "egw_json_response.getFormValues" to recursively
* run over all form elements
* @param serialized is the object which will contain the form data
* @param children is the children node of the form we're runing over
*/
function _egw_json_getFormValues(serialized, children)
{
for (var i = 0; i < children.length; ++i) {
var child = children[i];
if (typeof child.childNodes != "undefined")
_egw_json_getFormValues(serialized, child.childNodes);
_egw_json_getFormValue(serialized, child);
}
}
/**
* used internally to serialize
*/
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
if ((typeof child.name == "undefined") || (child.disabled && child.disabled == true) ||
(child.type && (child.type == 'radio' || child.type == 'checkbox') && (!child.checked)))
{
elem = _form;
return;
}
var name = child.name;
var values = null;
if ('select-multiple' == child.type)
{
values = new Array;
for (var j = 0; j < child.length; ++j)
{
var option = child.options[j];
if (option.selected == true)
values.push(option.value);
}
}
else
{
elem = document.getElementsByName(_form)[0];
values = child.value;
}
var serialized = $(_form).serializeArray();
alert("\nSerialized:\n" + serialized);
return serialized;
//Special treatment if the name of the child contains a [] - then all theese
//values are added to an array.
var keyBegin = name.indexOf('[');
if (0 <= keyBegin) {
var n = name;
var k = n.substr(0, n.indexOf('['));
var a = n.substr(n.indexOf('['));
if (typeof serialized[k] == 'undefined')
serialized[k] = new Object;
var p = serialized; // pointer reset
while (a.length != 0) {
var sa = a.substr(0, a.indexOf(']')+1);
var lk = k; //save last key
var lp = p; //save last pointer
a = a.substr(a.indexOf(']')+1);
p = p[k];
k = sa.substr(1, sa.length-2);
if (k == '') {
if ('select-multiple' == child.type) {
k = lk; //restore last key
p = lp;
} else {
k = p.length;
}
};*/
}
if (typeof p[k] == 'undefined')
p[k] = new Object;
}
p[k] = values;
} else {
//Add the value to the result object with the given name
if (typeof values != "undefined")
{
serialized[name] = values;
}
}
}