fixed old "'%1' is NOT allowed ('%2')!" error:

the ajax search now opens the pending eTemplate request and stores the
new allowed id's from this search
This commit is contained in:
Ralf Becker 2008-08-30 11:17:04 +00:00
parent ea295a1165
commit 0f0b5c9639
3 changed files with 52 additions and 19 deletions

View File

@ -30,6 +30,8 @@
* *
* Ajax request can use this object to open the original request by using the id, they have to transmitt back, * Ajax request can use this object to open the original request by using the id, they have to transmitt back,
* and register further variables, modify the registered ones or delete them. * and register further variables, modify the registered ones or delete them.
*
* For an example look in link_widget::ajax_search()
*/ */
class etemplate_request class etemplate_request
{ {
@ -60,7 +62,7 @@ class etemplate_request
*/ */
function __construct($id=null) function __construct($id=null)
{ {
if (!$id) $id = $this->request_id(); if (!$id) $id = self::request_id();
$this->id = $id; $this->id = $id;
} }
@ -79,7 +81,7 @@ class etemplate_request
* Read the request via it's id, returns a request_object or false * Read the request via it's id, returns a request_object or false
* *
* @param string $id * @param string $id
* @return etempalte_request/boolean the object or false if $id is not found * @return etempalte_request|boolean the object or false if $id is not found
*/ */
static function read($id) static function read($id)
{ {
@ -174,7 +176,7 @@ class etemplate_request
* *
* @return string * @return string
*/ */
function _request_id() static function request_id()
{ {
list($msec,$sec) = explode(' ',microtime()); list($msec,$sec) = explode(' ',microtime());
$time = 100 * $sec + (int)(100 * $msec); // gives precision of 1/100 sec $time = 100 * $sec + (int)(100 * $msec); // gives precision of 1/100 sec

View File

@ -58,7 +58,6 @@ class link_widget
var $public_functions = array( var $public_functions = array(
'pre_process' => True, 'pre_process' => True,
'post_process' => True, 'post_process' => True,
'ajax_search' => True,
); );
/** /**
* @var array availible extensions and there names for the editor * @var array availible extensions and there names for the editor
@ -106,7 +105,7 @@ class link_widget
$extension_data['needed'] = $cell['needed']; $extension_data['needed'] = $cell['needed'];
$help = $cell['help'] ? ($value['help'] ? $value['help'] : $cell['help']) : lang('view this linked entry in its application'); $help = $cell['help'] ? ($value['help'] ? $value['help'] : $cell['help']) : lang('view this linked entry in its application');
if (($type == 'link-to' || $type == 'link-add' || $type == 'link-entry' && !$value) && ($cell['readonly'] || $readonlys)) if ((in_array($type,array('link-to','link-add','link-entry')) && !$value) && ($cell['readonly'] || $readonlys))
{ {
//echo "<p>link-to is readonly, cell=".print_r($cell,true).", readonlys=".print_r($readonlys).", value='$value'</p>\n"; //echo "<p>link-to is readonly, cell=".print_r($cell,true).", readonlys=".print_r($readonlys).", value='$value'</p>\n";
// readonly ==> omit the whole widget // readonly ==> omit the whole widget
@ -575,7 +574,9 @@ class link_widget
} }
/** /**
* ajax callback to search in $app for $pattern, result is displayed in $id * Ajax callback to search in $app for $pattern, result is displayed in $id
*
* Called via onClick from etemplate.link_widget.(to|entry)'s search button
* *
* @param string $app app-name to search * @param string $app app-name to search
* @param string $pattern search-pattern * @param string $pattern search-pattern
@ -583,11 +584,14 @@ class link_widget
* @param string $id_hide id(s) of the search-box/-line to hide after a successful search * @param string $id_hide id(s) of the search-box/-line to hide after a successful search
* @param string $id_show id(s) of the select-box/-line to show after a successful search * @param string $id_show id(s) of the select-box/-line to show after a successful search
* @param string $id_input id of the search input-field * @param string $id_input id of the search input-field
* @param string $etemplate_exec_id of the calling etemplate, to upate the allowed ids
* @return string xajax xml response
*/ */
function ajax_search($app,$pattern,$id_res,$id_hide,$id_show,$id_input) static function ajax_search($app,$pattern,$id_res,$id_hide,$id_show,$id_input,$etemplate_exec_id)
{ {
$response = new xajaxResponse(); $response = new xajaxResponse();
//$args = func_get_args(); $response->addAlert("link_widget::ajax_search('".implode("','",$args)."')"); //$args = func_get_args(); $response->addAlert("link_widget::ajax_search('".implode("','",$args)."')");
//$args = func_get_args(); error_log(__METHOD__."('".implode("','",$args)."')");
if (!($found = egw_link::query($app,$pattern == lang('Search') ? '' : $pattern))) // ignore the blur-text if (!($found = egw_link::query($app,$pattern == lang('Search') ? '' : $pattern))) // ignore the blur-text
{ {
@ -622,6 +626,14 @@ class link_widget
//$response->addAlert($script); //$response->addAlert($script);
$response->addScript($script); $response->addScript($script);
} }
// store new allowed id's in the eT request
if ($etemplate_exec_id && ($et_request = etemplate_request::read($etemplate_exec_id)))
{
$data = $et_request->get_to_process($id_res);
//error_log($id_res.'='.array2string($data));
$data['allowed'] = $found ? array_keys($found) : array();
$et_request->set_to_process($id_res,$data);
}
return $response->getXML(); return $response->getXML();
} }
} }

File diff suppressed because one or more lines are too long