- dynamical (synchronious) loading preferences (other then "common") from server via egw.preference(_name, _app)

- setting preferences on server via egw.set_preference(_app, _name, _value)
- enable calling of active framework / template class via using egw_framework instead of not known used framework class of user, eg. "home.egw_framework.ajax_func.template" instead of "home.idots_framework.ajax_func.template"
This commit is contained in:
Ralf Becker 2011-08-26 09:34:18 +00:00
parent 4effb9931e
commit a925764fc4
3 changed files with 69 additions and 6 deletions

View File

@ -1233,6 +1233,40 @@ abstract class egw_framework
$response->includeScript($GLOBALS['egw_info']['server']['webserver_url'].$path);
}
}
/**
* Set a preference via ajax
*
* User either need run rights for preference app, or setting of preference will be silently ignored!
*
* @param string $app
* @param string $name
* @param string $value
*/
public static function ajax_set_preference($app, $name, $value)
{
//error_log(__METHOD__."('$app', '$name', '$value')");
if ($GLOBALS['egw_info']['user']['apps']['preferences'])
{
$GLOBALS['egw']->preferences->read_repository();
$GLOBALS['egw']->preferences->change($app, $name, $value);
$GLOBALS['egw']->preferences->save_repository(True);
}
}
/**
* Get preferences of a certain application via ajax
*
* @param string $app
*/
public static function ajax_get_preference($app)
{
if (preg_match('/^[a-z0-9_]+$/i', $app))
{
$response = egw_json_response::get();
$response->script('window.egw.set_preferences('.json_encode($GLOBALS['egw_info']['user']['preferences'][$app]).', "'.$app.'");');
}
}
}
// Init all static variables

View File

@ -17,7 +17,7 @@ class egw_json_request
{
private static $_hadJSONRequest = false;
public static function isJSONRequest()
{
return self::$_hadJSONRequest;
@ -34,7 +34,7 @@ class egw_json_request
{
// Remember that we currently are in a JSON request - e.g. used in the redirect code
self::$_hadJSONRequest = true;
if (empty($input_data))
{
$this->handleRequest($menuaction, array());
@ -109,6 +109,13 @@ class egw_json_request
case 'template':
$menuaction = $appName.'.'.$className.'.'.$functionName;
list($template) = explode('_', $className);
if ($className == 'egw_framework') // allow to use egw_framework to call framework / template used by user
{
$template = $GLOBALS['egw_info']['user']['preferences']['common']['template_set'];
if (empty($template)) $template = 'idots';
$className = $template.'_framework';
//error_log(__METHOD__."('$menuaction', ".array($parameters).") --> template='$template', className='$className'");
}
break;
}
@ -133,7 +140,7 @@ class egw_json_request
$ajaxClass = CreateObject($appName.'.'.$className);
}
// for Ajax: no need to load the "standard" javascript files,
// for Ajax: no need to load the "standard" javascript files,
// they are already loaded, in fact jquery has a problem if loaded twice
egw_framework::js_files(array());
@ -189,7 +196,7 @@ class egw_json_response
}
return self::$response;
}
public static function isJSONResponse()
{
return isset(self::$response);
@ -449,7 +456,7 @@ class egw_json_response
'params' => $params
);
}
/**
* Destructor
*/

View File

@ -72,9 +72,12 @@ else
/**
* Query an EGroupware user preference
*
* If a prefernce is not already loaded (only done for "common" by default), it is synchroniosly queryed from the server!
*
* @param string _name name of the preference, eg. 'dateformat'
* @param string _app='common'
* @return string preference value
* @todo add a callback to query it asynchron
*/
preference: function(_name, _app)
{
@ -82,11 +85,30 @@ else
if (typeof this.prefs[_app] == 'undefined')
{
throw 'Prefs for application "'+_app+'" are NOT loaded!';
xajax_doXMLHTTPsync('home.egw_framework.ajax_get_preference.template', _app);
if (typeof this.prefs[_app] == 'undefined') this.prefs[_app] = {};
}
return this.prefs[_app][_name];
},
/**
* Set a preference and sends it to the server
*
* Server will silently ignore setting preferences, if user has no right to do so!
*
* @param string _app application name or "common"
* @param string _name name of the pref
* @param string _val value of the pref
*/
set_preference: function(_app, _name, _val)
{
xajax_doXMLHTTP('home.egw_framework.ajax_set_preference.template', _app, _name, _val);
// update own preference cache, if _app prefs are loaded (dont update otherwise, as it would block loading of other _app prefs!)
if (typeof this.prefs[_app] != 'undefined') this.prefs[_app][_name] = _val;
},
/**
* Translations
*