From: Michael M Slusarz Date: Tue, 20 Apr 2010 05:19:11 +0000 (-0600) Subject: Bug #8977: Add prefsEnum() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a861b23f6c641b45228b9a8a2a8cf90e5013be5e;p=horde.git Bug #8977: Add prefsEnum() --- diff --git a/ansel/lib/Application.php b/ansel/lib/Application.php index cbf48d09f..2610d243e 100644 --- a/ansel/lib/Application.php +++ b/ansel/lib/Application.php @@ -95,11 +95,11 @@ class Ansel_Application extends Horde_Registry_Application } /** - * Code to run on init when viewing prefs for this application. + * Populate dynamically-generated preference values. * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - public function prefsInit($ui) + public function prefsEnum($ui) { global $conf, $prefs; diff --git a/fima/lib/Application.php b/fima/lib/Application.php index 4d8136c98..de4ee4846 100644 --- a/fima/lib/Application.php +++ b/fima/lib/Application.php @@ -4,11 +4,11 @@ class Fima_Application extends Horde_Regsitry_Application public $version = '1.0.1'; /** - * Code to run on init when viewing prefs for this application. + * Populate dynamically-generated preference values. * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - public function prefsInit($ui) + public function prefsEnum($ui) { switch ($ui->group) { case 'share': diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui.php b/framework/Core/lib/Horde/Core/Prefs/Ui.php index c513e462e..a6ef7c63b 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui.php @@ -109,6 +109,13 @@ class Horde_Core_Prefs_Ui /* Load preferences. */ $this->_loadPrefs($this->app); + + /* Populate enums. */ + if ($this->group && + $GLOBALS['registry']->hasAppMethod($this->app, 'prefsEnum') && + $this->groupIsEditable($this->group)) { + $GLOBALS['registry']->callAppMethod($this->app, 'prefsEnum', array('args' => array($this))); + } } /** @@ -229,7 +236,10 @@ class Horde_Core_Prefs_Ui break; case 'enum': - if (isset($this->prefs[$pref]['enum'][$this->vars->$pref])) { + $enum = isset($this->override[$pref]) + ? $this->override[$pref] + : $this->prefs[$pref]['enum']; + if (isset($enum[$this->vars->$pref])) { $updated |= $save->setValue($pref, $this->vars->$pref); } else { $notification->push(_("An illegal value was specified."), 'horde.error'); @@ -240,8 +250,12 @@ class Horde_Core_Prefs_Ui $set = array(); if (is_array($this->vars->$pref)) { + $enum = isset($this->override[$pref]) + ? $this->override[$pref] + : $this->prefs[$pref]['enum']; + foreach ($this->vars->$pref as $val) { - if (isset($this->prefs[$pref]['enum'][$val])) { + if (isset($enum[$val])) { $set[] = $val; } else { $notification->push(_("An illegal value was specified."), 'horde.error'); diff --git a/framework/Core/lib/Horde/Registry/Application.php b/framework/Core/lib/Horde/Registry/Application.php index c2cf99ccb..4535d6b48 100644 --- a/framework/Core/lib/Horde/Registry/Application.php +++ b/framework/Core/lib/Horde/Registry/Application.php @@ -104,6 +104,13 @@ class Horde_Registry_Application // public function changeLanguage() {} /** + * Populate dynamically-generated preference values. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + */ + // public function prefsEnum($ui) {} + + /** * Code to run on init when viewing prefs for this application. * * @param Horde_Core_Prefs_Ui $ui The UI object. diff --git a/horde/lib/Application.php b/horde/lib/Application.php index d482d168a..2f9218f91 100644 --- a/horde/lib/Application.php +++ b/horde/lib/Application.php @@ -43,6 +43,16 @@ class Horde_Application extends Horde_Registry_Application } /** + * Populate dynamically-generated preference values. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + */ + public function prefsEnum($ui) + { + $GLOBALS['injector']->getInstance('Horde_Prefs_Ui')->prefsEnum($ui); + } + + /** * Code to run on init when viewing prefs for this application. * * @param Horde_Core_Prefs_Ui $ui The UI object. diff --git a/horde/lib/Prefs/Ui.php b/horde/lib/Prefs/Ui.php index 5f4f19eea..fef40035f 100644 --- a/horde/lib/Prefs/Ui.php +++ b/horde/lib/Prefs/Ui.php @@ -13,13 +13,13 @@ class Horde_Prefs_Ui { /** - * Code to run on init when viewing prefs for this application. + * Populate dynamically-generated preference values. * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - public function prefsInit($ui) + public function prefsEnum($ui) { - global $conf, $prefs, $registry; + global $prefs, $registry; switch ($ui->group) { case 'display': @@ -74,7 +74,19 @@ class Horde_Prefs_Ui array_unshift($ui->override['timezone'], _("Default")); } break; + } + } + + /** + * Code to run on init when viewing prefs for this application. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + */ + public function prefsInit($ui) + { + global $conf; + switch ($ui->group) { case 'remote': Horde::addScriptFile('rpcprefs.js', 'horde'); $ui->nobuttons = true; diff --git a/imp/lib/Application.php b/imp/lib/Application.php index ef42dc078..631c6f20f 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -415,6 +415,16 @@ class IMP_Application extends Horde_Registry_Application * IMP_Prefs_Ui so it doesn't have to be loaded on every page load. */ /** + * Populate dynamically-generated preference values. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + */ + public function prefsEnum($ui) + { + $GLOBALS['injector']->getInstance('IMP_Prefs_Ui')->prefsEnum($ui); + } + + /** * Code to run on init when viewing prefs for this application. * * @param Horde_Core_Prefs_Ui $ui The UI object. diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index 915c52ced..b527d58c9 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -13,6 +13,41 @@ class IMP_Prefs_Ui { /** + * Populate dynamically-generated preference values. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + */ + public function prefsEnum($ui) + { + global $prefs, $registry; + + switch ($ui->group) { + case 'addressbooks': + if (!$prefs->isLocked('add_source')) { + try { + $sources = array(); + foreach ($registry->call('contacts/sources', array(true)) as $source => $name) { + $sources[$source] = $name; + } + $ui->override['add_source'] = $sources; + } catch (Horde_Exception $e) { + $ui->suppress[] = 'add_source'; + } + } + break; + + case 'delmove': + if (isset($_SESSION['imp']['protocol']) && + ($_SESSION['imp']['protocol'] == 'pop')) { + $tmp = $ui->prefs['delete_spam_after_report']['enum']; + unset($tmp[2]); + $ui->override['delete_spam_after_report'] = $tmp; + } + break; + } + } + + /** * Code to run on init when viewing prefs for this application. * * @param Horde_Core_Prefs_Ui $ui The UI object. @@ -40,18 +75,6 @@ class IMP_Prefs_Ui if (!$prefs->isLocked('sourceselect')) { Horde_Core_Prefs_Ui_Widgets::addressbooksInit(); } - - if (!$prefs->isLocked('add_source')) { - try { - $sources = array(); - foreach ($registry->call('contacts/sources', array(true)) as $source => $name) { - $sources[$source] = $name; - } - $ui->override['add_source'] = $sources; - } catch (Horde_Exception $e) { - $ui->suppress[] = 'add_source'; - } - } break; case 'compose': @@ -70,10 +93,6 @@ class IMP_Prefs_Ui $ui->suppress[] = 'use_trash'; $ui->suppress[] = 'trashselect'; $ui->suppress[] = 'empty_trash_menu'; - - $tmp = $ui->prefs['delete_spam_after_report']['enum']; - unset($tmp[2]); - $ui->override['delete_spam_after_report'] = $tmp; } elseif ($prefs->isLocked('use_trash') || !$prefs->getValue('use_trash')) { $ui->suppress[] = 'trashselect'; diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index 05af8c4bb..5b4be45b6 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -109,21 +109,15 @@ class Kronolith_Application extends Horde_Registry_Application } /** - * Code to run on init when viewing prefs for this application. + * Populate dynamically-generated preference values. * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - public function prefsInit($ui) + public function prefsEnum($ui) { global $conf, $prefs, $registry; switch ($ui->group) { - case 'addressbooks': - if (!$prefs->isLocked('sourceselect')) { - Horde_Core_Prefs_Ui_Widgets::addressbooksInit(); - } - break; - case 'freebusy': if (!$prefs->isLocked('fb_cals')) { $fb_cals = Kronolith::ListCalendars(); @@ -135,16 +129,6 @@ class Kronolith_Application extends Horde_Registry_Application } break; - case 'notification': - if (empty($conf['alarms']['driver']) || - $prefs->isLocked('event_alarms') || - $prefs->isLocked('event_alarms_select')) { - $ui->suppress[]= 'event_alarms'; - } else { - Horde_Core_Prefs_Ui_Widgets::alarminit(); - } - break; - case 'share': if (!$prefs->isLocked('default_share')) { $all_shares = Kronolith::listCalendars(); @@ -180,6 +164,34 @@ class Kronolith_Application extends Horde_Registry_Application } break; } + } + + /** + * Code to run on init when viewing prefs for this application. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + */ + public function prefsInit($ui) + { + global $conf, $prefs, $registry; + + switch ($ui->group) { + case 'addressbooks': + if (!$prefs->isLocked('sourceselect')) { + Horde_Core_Prefs_Ui_Widgets::addressbooksInit(); + } + break; + + case 'notification': + if (empty($conf['alarms']['driver']) || + $prefs->isLocked('event_alarms') || + $prefs->isLocked('event_alarms_select')) { + $ui->suppress[]= 'event_alarms'; + } else { + Horde_Core_Prefs_Ui_Widgets::alarminit(); + } + break; + } /* Suppress prefGroups display. */ if (!$registry->hasMethod('contacts/sources')) { diff --git a/mnemo/lib/Application.php b/mnemo/lib/Application.php index ae3596d34..da9e126c1 100644 --- a/mnemo/lib/Application.php +++ b/mnemo/lib/Application.php @@ -49,27 +49,25 @@ class Mnemo_Application extends Horde_Registry_Application */ protected function _init() { - // Set the timezone variable. - Horde_Nls::setTimeZone(); + // Set the timezone variable. + Horde_Nls::setTimeZone(); - // Create a share instance. - $GLOBALS['mnemo_shares'] = Horde_Share::singleton($GLOBALS['registry']->getApp()); + // Create a share instance. + $GLOBALS['mnemo_shares'] = Horde_Share::singleton($GLOBALS['registry']->getApp()); - Mnemo::initialize(); + Mnemo::initialize(); } /** - * Code to run on init when viewing prefs for this application. + * Populate dynamically-generated preference values. * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - public function prefsInit($ui) + public function prefsEnum($ui) { - global $conf, $prefs, $registry; - switch ($ui->group) { case 'share': - if (!$prefs->isLocked('default_notepad')) { + if (!$GLOBALS['prefs']->isLocked('default_notepad')) { $notepads = array(); foreach (Mnemo::listNotepads() as $key => $val) { $notepads[htmlspecialchars($key)] = htmlspecialchars($val->get('name')); diff --git a/nag/lib/Application.php b/nag/lib/Application.php index b8e72789f..36f154b98 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -92,23 +92,15 @@ class Nag_Application extends Horde_Registry_Application } /** - * Code to run on init when viewing prefs for this application. + * Populate dynamically-generated preference values. * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - public function prefsInit($ui) + public function prefsEnum($ui) { - global $conf, $prefs, $registry; + global $prefs, $registry; switch ($ui->group) { - case 'notification': - if (empty($conf['alarms']['driver']) || - $prefs->isLocked('task_alarms') || - $prefs->isLocked('task_alarms_select')) { - $ui->suppress[] = 'task_alarms'; - } - break; - case 'share': if (!$prefs->isLocked('default_tasklist')) { $all_tasklists = Nag::listTasklists(); @@ -147,7 +139,6 @@ class Nag_Application extends Horde_Registry_Application break; } - /* Hide appropriate prefGroups. */ $show_external = array(); if ($registry->hasMethod('getListTypes', 'whups')) { $show_external['whups'] = $registry->get('name', 'whups'); @@ -156,7 +147,27 @@ class Nag_Application extends Horde_Registry_Application $ui->override['show_external'] = $show_external; } else { $ui->suppress[] = 'show_external'; - $ui->suppresGroups[] = 'external'; + $ui->suppressGroups[] = 'external'; + } + } + + /** + * Code to run on init when viewing prefs for this application. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + */ + public function prefsInit($ui) + { + global $conf, $prefs; + + switch ($ui->group) { + case 'notification': + if (empty($conf['alarms']['driver']) || + $prefs->isLocked('task_alarms') || + $prefs->isLocked('task_alarms_select')) { + $ui->suppress[] = 'task_alarms'; + } + break; } } diff --git a/turba/lib/Application.php b/turba/lib/Application.php index 4663d2f4d..da6ddb575 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -158,18 +158,16 @@ class Turba_Application extends Horde_Registry_Application } /** - * Code to run on init when viewing prefs for this application. + * Populate dynamically-generated preference values. * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - public function prefsInit($ui) + public function prefsEnum($ui) { global $prefs; switch ($ui->group) { case 'addressbooks': - Horde_Core_Prefs_Ui_Widgets::sourceInit(); - if (!$prefs->isLocked('default_dir')) { $out = array(); foreach ($GLOBALS['cfgSources'] as $key => $info) { @@ -193,6 +191,22 @@ class Turba_Application extends Horde_Registry_Application } $ui->override['sync_books'] = $out; break; + } + } + + /** + * Code to run on init when viewing prefs for this application. + * + * @param Horde_Core_Prefs_Ui $ui The UI object. + */ + public function prefsInit($ui) + { + global $prefs; + + switch ($ui->group) { + case 'addressbooks': + Horde_Core_Prefs_Ui_Widgets::sourceInit(); + break; case 'columns': Horde::addScriptFile('effects.js', 'horde');