methods to set or get all body tags or javascript files, replacing direct access to variables of old javascript class

This commit is contained in:
Ralf Becker 2010-06-15 16:08:10 +00:00
parent 631c19a83e
commit 88ebb437c2
3 changed files with 87 additions and 34 deletions

View File

@ -438,7 +438,7 @@ class addressbook_ui extends addressbook_bo
$response = new xajaxResponse();
if ($success) $response->addScript($GLOBALS['egw']->js->body['onLoad']);
if ($success) $response->addScript(egw_framework::set_onload(''));
// close window only if no errors AND something added
if ($failed || !$success)
@ -589,7 +589,7 @@ class addressbook_ui extends addressbook_bo
case 'infolog_add':
if ($use_all) // !$use_all is handled purely in javascript
{
$GLOBALS['egw']->js->set_onload(
egw_framework::set_onload(
"win=window.open('".egw::link('/index.php','menuaction=infolog.infolog_ui.edit&type=task&action=addressbook&action_id=').implode(',',$checked)."','_blank','width=750,height=550,left=100,top=200'); win.focus();");
}
$msg = lang('New window opened to edit Infolog for your selection ');
@ -694,7 +694,7 @@ class addressbook_ui extends addressbook_bo
if($email)
{
$contact['n_fn'] = str_replace(',',' ',$contact['n_fn']);
$GLOBALS['egw']->js->set_onload("addEmail('".addslashes(
egw_framework::set_onload("addEmail('".addslashes(
$contact['n_fn'] ? $contact['n_fn'].' <'.$email.'>' : $email)."');");
$Ok = true;
}
@ -798,9 +798,9 @@ class addressbook_ui extends addressbook_bo
{
$query['advanced_search'] = $old_state['advanced_search'];
}
if ($do_email && etemplate::$loop && is_object($GLOBALS['egw']->js))
if ($do_email && etemplate::$loop)
{ // remove previous addEmail() calls, otherwise they will be run again
$GLOBALS['egw']->js->body['onLoad'] = preg_replace('/addEmail\([^)]+\);/','',$GLOBALS['egw']->js->body['onLoad']);
egw_framework::set_onload(preg_replace('/addEmail\([^)]+\);/','',egw_framework::set_onload()),true);
}
//echo "<p>uicontacts::get_rows(".print_r($query,true).")</p>\n";
if (!$id_only)

View File

@ -260,15 +260,19 @@ class etemplate extends boetemplate
self::$request->java_script = self::$java_script;
self::$request->java_script_from_flags = $GLOBALS['egw_info']['flags']['java_script'];
self::$request->java_script_body_tags = $GLOBALS['egw']->js->body;
self::$request->java_script_files = $GLOBALS['egw']->js->files;
self::$request->java_script_body_tags = array(
'onload' => egw_framework::set_onload(),
'onunload' => egw_framework::set_onunload(),
'onresize' => egw_framework::set_onresize(),
);
self::$request->java_script_files = egw_framework::js_files();
self::$request->include_xajax = $GLOBALS['egw_info']['flags']['include_xajax'];
// check if application of template has a app.js file --> load it
list($app) = explode('.',$this->name);
if (file_exists(EGW_SERVER_ROOT.'/'.$app.'/js/app.js'))
{
$GLOBALS['egw']->js->validate_file('.','app',$app,false);
egw_framework::validate_file('.','app',$app,false);
}
if (!$this->sitemgr)
@ -515,14 +519,21 @@ class etemplate extends boetemplate
{
foreach (self::$request->java_script_body_tags as $tag => $code)
{
//error_log($GLOBALS['egw']->js->body[$tag]);
$GLOBALS['egw']->js->body[$tag] .= $code;
call_user_func('egw_framework::set_'.$tag,$code);
}
}
if (is_array(self::$request->java_script_files))
{
$GLOBALS['egw']->js->files = !is_array($GLOBALS['egw']->js->files) ? self::$request->java_script_files :
self::complete_array_merge($GLOBALS['egw']->js->files,self::$request->java_script_files);
$files = egw_framework::js_files();
if (is_array($files))
{
$files = array_unique(array_merge($files,self::$request->java_script_files));
}
else
{
$files = self::$request->java_script_files;
}
egw_framework::js_files($files);
}
//echo "<p>process_exec($this->name): <font color=red>loop is set</font>, content=</p>\n"; _debug_array(self::complete_array_merge(self::$request->content,$content));

View File

@ -925,43 +925,70 @@ abstract class egw_framework
protected static $body_tags = array();
/**
* Sets an onLoad action for a page
*
* @param string javascript to be used
* @return string content of onXXX tag after adding code
*/
static function set_onload($code)
* Sets an onLoad action for a page
*
* @param string $code='' javascript to be used
* @param boolean $replace=false false: append to existing, true: replace existing tag
* @return string content of onXXX tag after adding code
*/
static function set_onload($code='',$replace=false)
{
return self::$body_tags['onLoad'] .= $code;
if ($replace)
{
self::$body_tags['onLoad'] = $code;
}
else
{
self::$body_tags['onLoad'] .= $code;
}
return self::$body_tags['onLoad'];
}
/**
* Sets an onUnload action for a page
*
* @param string javascript to be used
* @return string content of onXXX tag after adding code
*/
static function set_onunload($code)
* Sets an onUnload action for a page
*
* @param string $code='' javascript to be used
* @param boolean $replace=false false: append to existing, true: replace existing tag
* @return string content of onXXX tag after adding code
*/
static function set_onunload($code='',$replace=false)
{
return self::$body_tags['onUnload'] .= $code;
if ($replace)
{
self::$body_tags['onUnload'] = $code;
}
else
{
self::$body_tags['onUnload'] .= $code;
}
return self::$body_tags['onUnload'];
}
/**
* Sets an onResize action for a page
*
* @param string javascript to be used
* @param string $code='' javascript to be used
* @param boolean $replace=false false: append to existing, true: replace existing tag
* @return string content of onXXX tag after adding code
*/
static function set_onresize($code)
static function set_onresize($code='',$replace=false)
{
return self::$body_tags['onResize'] .= $code;
if ($replace)
{
self::$body_tags['onResize'] = $code;
}
else
{
self::$body_tags['onResize'] .= $code;
}
return self::$body_tags['onResize'];
}
/**
* Adds on(Un)Load= attributes to the body tag of a page
*
* @returns string the attributes to be used
*/
* Adds on(Un)Load= attributes to the body tag of a page
*
* @returns string the attributes to be used
*/
static protected function _get_body_attribs()
{
$js = '';
@ -1016,6 +1043,21 @@ abstract class egw_framework
return False;
}
/**
* Set or return all javascript files set via validate_file
*
* @param array $files=null array with pathes relative to EGW_SERVER_ROOT, eg. /phpgwapi/js/jquery/jquery.js
* @return array with pathes relative to EGW_SERVER_ROOT
*/
static function js_files(array $files=null)
{
if (isset($files) && is_array($files))
{
self::$js_include_files = $files;
}
return self::$js_include_files;
}
/**
* Used for generating the list of external js files to be included in the head of a page
*