allow to unset a preference by calling egw.set_preference(app,name)

This commit is contained in:
Ralf Becker 2015-01-08 13:13:02 +00:00
parent 0eaa3e0896
commit 94d91f3ac8
2 changed files with 23 additions and 3 deletions

View File

@ -2206,7 +2206,14 @@ abstract class egw_framework
public static function ajax_set_preference($app, $name, $value)
{
$GLOBALS['egw']->preferences->read_repository();
$GLOBALS['egw']->preferences->add($app, $name, $value);
if ((string)$value === '')
{
$GLOBALS['egw']->preferences->delete($app, $name);
}
else
{
$GLOBALS['egw']->preferences->add($app, $name, $value);
}
$GLOBALS['egw']->preferences->save_repository(True);
}

View File

@ -78,15 +78,28 @@ egw.extend('preferences', egw.MODULE_GLOBAL, function() {
*
* @param {string} _app application name or "common"
* @param {string} _name name of the pref
* @param {string} _val value of the pref
* @param {string} _val value of the pref, null, undefined or "" to unset it
* @param {function} _callback Function passed along to the queue, called after preference is set server-side
*/
set_preference: function(_app, _name, _val, _callback)
{
// if there is no change, no need to submit it to server
if (typeof prefs[_app] != 'undefined' && prefs[_app][_name] === _val) return;
this.jsonq('home.egw_framework.ajax_set_preference.template',[_app, _name, _val], _callback);
// update own preference cache, if _app prefs are loaded (dont update otherwise, as it would block loading of other _app prefs!)
if (typeof prefs[_app] != 'undefined') prefs[_app][_name] = _val;
if (typeof prefs[_app] != 'undefined')
{
if (_val === undefined || _val === "" || _val === null)
{
delete prefs[_app][_name];
}
else
{
prefs[_app][_name] = _val;
}
}
},
/**