From 94d91f3ac8afbcc7e36ce3202fd84ad06e4501e4 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 8 Jan 2015 13:13:02 +0000 Subject: [PATCH] allow to unset a preference by calling egw.set_preference(app,name) --- phpgwapi/inc/class.egw_framework.inc.php | 9 ++++++++- phpgwapi/js/jsapi/egw_preferences.js | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index 78e73f9e28..6d25dfb586 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -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); } diff --git a/phpgwapi/js/jsapi/egw_preferences.js b/phpgwapi/js/jsapi/egw_preferences.js index 2f31573f2b..47cebecb11 100644 --- a/phpgwapi/js/jsapi/egw_preferences.js +++ b/phpgwapi/js/jsapi/egw_preferences.js @@ -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; + } + } }, /**