Prefs UI fixes
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Nov 2010 05:26:39 +0000 (22:26 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Nov 2010 05:26:39 +0000 (22:26 -0700)
Remove prefsEnum() call; replace with prefsGroup() call

prefsInit() is designed for tasks that need to run once on the page.
This is where all suppressGroups handling should go.

Next, prefsGroups() is used to determine the list of prefs that need to
be updated.  However, after prefs are updated, suppressed prefs may
change so we need to run prefsGroups() again to get the updated list of
suppressed prefs for display.

prefsEnum() becomes redundant because it can be handled in either
prefsInit() or prefsGroups().

12 files changed:
agora/lib/Application.php
ansel/lib/Application.php
framework/Core/lib/Horde/Core/Prefs/Ui.php
framework/Core/lib/Horde/Registry/Application.php
horde/lib/Application.php
horde/lib/Prefs/Ui.php
imp/lib/Application.php
imp/lib/Prefs/Ui.php
kronolith/lib/Application.php
mnemo/lib/Application.php
nag/lib/Application.php
turba/lib/Application.php

index a32f30a..c021a9c 100644 (file)
@@ -131,8 +131,6 @@ class Agora_Application extends Horde_Registry_Application
                 $GLOBALS['conf']['avatar']['enable_gallery'] &&
                 $vfs->isFolder(Agora::AVATAR_PATH, 'gallery')) {
                 Horde::addScriptFile('popup.js', 'horde', true);
-            } else {
-                $suppress[] = 'avatar_link';
             }
             break;
         }
@@ -144,6 +142,25 @@ class Agora_Application extends Horde_Registry_Application
     }
 
     /**
+     * Determine active prefs when displaying a group.
+     *
+     * @param Horde_Core_Prefs_Ui $ui  The UI object.
+     */
+    public function prefsGroup($ui)
+    {
+        switch ($ui->group) {
+        case 'display_avatar':
+            $vfs = Agora::getVFS();
+            if (($vfs instanceof PEAR_Error) ||
+                !$GLOBALS['conf']['avatar']['enable_gallery'] ||
+                !$vfs->isFolder(Agora::AVATAR_PATH, 'gallery')) {
+                $suppress[] = 'avatar_link';
+            }
+            break;
+        }
+    }
+
+    /**
      * Generate code used to display a special preference.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
index 04ec2e9..e5cd0de 100644 (file)
@@ -162,11 +162,11 @@ class Ansel_Application extends Horde_Registry_Application
     }
 
     /**
-     * Populate dynamically-generated preference values.
+     * Determine active prefs when displaying a group.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsEnum($ui)
+    public function prefsGroup($ui)
     {
         global $conf, $prefs;
 
index d160bc4..acabfeb 100644 (file)
@@ -16,6 +16,7 @@
  * @author   Chuck Hagenbuch <chuck@horde.org>
  * @author   Michael Slusarz <slusarz@horde.org>
  * @category Horde
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @package  Core
  */
 class Horde_Core_Prefs_Ui
@@ -56,13 +57,6 @@ class Horde_Core_Prefs_Ui
     public $suppressGroups = array();
 
     /**
-     * Suppressed preference entries to automatically update.
-     *
-     * @var array
-     */
-    public $suppressUpdate = array();
-
-    /**
      * Current application.
      *
      * @var string
@@ -125,17 +119,15 @@ class Horde_Core_Prefs_Ui
         /* Load preferences. */
         $this->_loadPrefs($this->app);
 
-        /* Populate enums. */
-        if ($this->group &&
-            $registry->hasAppMethod($this->app, 'prefsEnum') &&
-            $this->groupIsEditable($this->group)) {
-            $registry->callAppMethod($this->app, 'prefsEnum', array('args' => array($this)));
-        }
-
         /* Run app-specific init code. */
         if ($registry->hasAppMethod($this->app, 'prefsInit')) {
             $registry->callAppMethod($this->app, 'prefsInit', array('args' => array($this)));
         }
+
+        if ($this->group &&
+            $registry->hasAppMethod($this->app, 'prefsGroup')) {
+            $registry->callAppMethod($this->app, 'prefsGroup', array('args' => array($this)));
+        }
     }
 
     /**
@@ -218,7 +210,7 @@ class Horde_Core_Prefs_Ui
                 ($this->prefGroups[$this->group]['type'] == 'identities')) {
                 $this->_identitiesUpdate();
             } else {
-                $this->_handleForm(array_diff($this->getChangeablePrefs($this->group), $this->suppressUpdate), $GLOBALS['prefs']);
+                $this->_handleForm($this->getChangeablePrefs($this->group), $GLOBALS['prefs']);
             }
             break;
 
@@ -232,6 +224,11 @@ class Horde_Core_Prefs_Ui
             $this->_handleForm($special, $GLOBALS['prefs']);
             break;
         }
+
+        if ($GLOBALS['registry']->hasAppMethod($this->app, 'prefsGroup')) {
+            $this->suppress = array();
+            $GLOBALS['registry']->callAppMethod($this->app, 'prefsGroup', array('args' => array($this)));
+        }
     }
 
     /*
@@ -869,7 +866,7 @@ class Horde_Core_Prefs_Ui
         $identity->setDefault($id);
 
         try {
-            $this->_handleForm(array_diff($this->_addHordeIdentitiesPrefs($this->getChangeablePrefs($this->group)), $this->suppressUpdate), $identity);
+            $this->_handleForm($this->_addHordeIdentitiesPrefs($this->getChangeablePrefs($this->group)), $identity);
         } catch (Exception $e) {
             $notification->push($e, 'horde.error');
             return;
index 34305bf..d7f7db5 100644 (file)
@@ -217,18 +217,22 @@ class Horde_Registry_Application
     // public function changeLanguage() {}
 
     /**
-     * Populate dynamically-generated preference values.
+     * Run on init when viewing prefs for an application.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    // public function prefsEnum($ui) {}
+    // public function prefsInit($ui) {}
 
     /**
-     * Code to run on init when viewing prefs for this application.
+     * Determine active prefs when displaying a group. This is where all
+     * suppress/overrides should be defined.
+     *
+     * This function may be run multiple times in a single page - once on init
+     * and once after prefs are updated.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    // public function prefsInit($ui) {}
+    // public function prefsGroup($ui) {}
 
     /**
      * Called when preferences are changed.
index 90ce967..08fbd96 100644 (file)
@@ -62,16 +62,6 @@ 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.
index ecd2792..2d5fa65 100644 (file)
 class Horde_Prefs_Ui
 {
     /**
-     * Populate dynamically-generated preference values.
+     * Code to run on init when viewing prefs for this application.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsEnum($ui)
+    public function prefsInit($ui)
     {
-        global $injector, $notification, $prefs, $registry;
+        global $conf, $injector, $prefs, $registry;
 
         switch ($ui->group) {
         case 'display':
@@ -39,11 +39,7 @@ class Horde_Prefs_Ui
             }
 
             if (!$prefs->isLocked('theme')) {
-                try {
-                    $ui->override['theme'] = Horde_Themes::themeList();
-                } catch (UnexpectedValueException $e) {
-                    $notification->push(_("Theme directory can't be opened"), 'horde.error');
-                }
+                $ui->override['theme'] = Horde_Themes::themeList();
             }
             break;
 
@@ -57,21 +53,7 @@ class Horde_Prefs_Ui
                 $ui->override['timezone'] = Horde_Nls::getTimezones();
                 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, $injector, $prefs, $registry;
 
-        switch ($ui->group) {
-        case 'language':
             if (!$prefs->isLocked('sending_charset')) {
                 asort($registry->nlsconfig['encodings']);
             }
index 85cba3e..1bd8eae 100644 (file)
@@ -519,23 +519,23 @@ 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.
+     * Code to run on init when viewing prefs for this application.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsEnum($ui)
+    public function prefsInit($ui)
     {
-        $GLOBALS['injector']->getInstance('IMP_Prefs_Ui')->prefsEnum($ui);
+        $GLOBALS['injector']->getInstance('IMP_Prefs_Ui')->prefsInit($ui);
     }
 
     /**
-     * Code to run on init when viewing prefs for this application.
+     * Determine active prefs when displaying a group.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsInit($ui)
+    public function prefsGroup($ui)
     {
-        $GLOBALS['injector']->getInstance('IMP_Prefs_Ui')->prefsInit($ui);
+        $GLOBALS['injector']->getInstance('IMP_Prefs_Ui')->prefsGroup($ui);
     }
 
     /**
index 6d915d9..fab6e01 100644 (file)
@@ -27,66 +27,179 @@ class IMP_Prefs_Ui
     protected $_cache = null;
 
     /**
-     * Populate dynamically-generated preference values.
+     * Run once on init when viewing prefs for an application.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsEnum($ui)
+    public function prefsInit($ui)
     {
-        global $prefs, $registry;
+        global $conf, $injector, $prefs, $registry, $session;
 
         switch ($ui->group) {
+        case 'accounts':
+            if (!empty($conf['user']['allow_accounts'])) {
+                Horde::addScriptFile('accountsprefs.js', 'imp');
+            }
+            break;
+
+        case 'acl':
+            Horde::addScriptFile('acl.js', 'imp');
+            break;
+
         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';
-                }
+            if (!$prefs->isLocked('sourceselect')) {
+                Horde_Core_Prefs_Ui_Widgets::addressbooksInit();
             }
             break;
 
         case 'delmove':
-            if ($GLOBALS['session']->get('imp', 'protocol') == 'pop') {
+            if ($session->get('imp', 'protocol') == 'pop') {
                 $tmp = $ui->prefs['delete_spam_after_report']['enum'];
                 unset($tmp[2]);
                 $ui->override['delete_spam_after_report'] = $tmp;
             }
             break;
+
+        case 'display':
+            /* Set the timezone on this page so the 'time_format' output uses
+             * the configured time zone's time, not the system's time zone. */
+            $registry->setTimeZone();
+            break;
+
+        case 'flags':
+            if ($prefs->isLocked('msgflags') &&
+                $prefs->isLocked('msgflags_user')) {
+                $ui->nobuttons = true;
+            } else {
+                Horde::addScriptFile('colorpicker.js', 'horde');
+                Horde::addScriptFile('flagprefs.js', 'imp');
+            }
+            break;
+
+        case 'identities':
+            if (!$prefs->isLocked('sent_mail_folder')) {
+                Horde::addScriptFile('folderprefs.js', 'imp');
+            }
+
+            if (!$prefs->isLocked('signature_html') &&
+                $session->get('imp', 'rteavail')) {
+                Horde::addScriptFile('signaturehtml.js', 'imp');
+                IMP_Ui_Editor::init(false, 'signature_html');
+            }
+            break;
+
+        case 'pgp':
+            Horde::addScriptFile('imp.js', 'imp');
+            break;
+
+        case 'searches':
+            Horde::addScriptFile('searchesprefs.js', 'imp');
+            break;
+
+        case 'server':
+            $code = array();
+
+            if (!$prefs->isLocked('drafts_folder')) {
+                $code['drafts'] = _("Enter the name for your new drafts folder.");
+            }
+
+            if (!$prefs->isLocked('spam_folder')) {
+                $code['spam'] = _("Enter the name for your new spam folder.");
+            }
+
+            if (!$prefs->isLocked('trash_folder')) {
+                $code['trash'] = _("Enter the name for your new trash folder.");
+            }
+
+            if (!empty($code)) {
+                Horde::addScriptFile('folderprefs.js', 'imp');
+                Horde::addInlineJsVars(array(
+                    'ImpFolderPrefs.folders' => $code
+                ));
+            }
+            break;
+
+        case 'smime':
+            Horde::addScriptFile('imp.js', 'imp');
+            break;
+
+        case 'stationery':
+            if (!$prefs->isLocked('stationery')) {
+                $ui->nobuttons = true;
+            }
+            break;
+
+        case 'viewing':
+            /* Sort encodings. */
+            if (!$prefs->isLocked('default_msg_charset')) {
+                asort($registry->nlsconfig['encodings']);
+            }
+            break;
+        }
+
+        /* Hide appropriate prefGroups. */
+        if ($session->get('imp', 'protocol') == 'pop') {
+            $ui->suppressGroups[] = 'flags';
+            $ui->suppressGroups[] = 'searches';
+            $ui->suppressGroups[] = 'server';
+        }
+
+        try {
+            $injector->getInstance('IMP_Imap_Acl');
+        } catch (IMP_Exception $e) {
+            $ui->suppressGroups[] = 'acl';
+        }
+
+        if (empty($conf['user']['allow_accounts'])) {
+            $ui->suppressGroups[] = 'accounts';
+        }
+
+        $contacts_app = $registry->hasInterface('contacts');
+        if (!$contacts_app || !$registry->hasPermission($contacts_app)) {
+            $ui->suppressGroups[] = 'addressbooks';
+        }
+
+        if (!isset($conf['gnupg']['path'])) {
+            $ui->suppressGroups[] = 'pgp';
+        }
+
+        if (!Horde_Util::extensionExists('openssl') ||
+            !isset($conf['openssl']['path'])) {
+            $ui->suppressGroups[] = 'smime';
         }
+
+        if (empty($conf['user']['allow_folders'])) {
+            $ui->suppressGroups[] = 'searches';
+        }
+
+        // TODO: For now, disable this group since accounts code has not
+        // yet been fully written.
+        $ui->suppressGroups[] = 'accounts';
     }
 
     /**
-     * Code to run on init when viewing prefs for this application.
+     * Determine active prefs when displaying a group.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsInit($ui)
+    public function prefsGroup($ui)
     {
-        global $conf, $prefs, $registry, $session;
-
-        $pop3 = ($session->get('imp', 'protocol') == 'pop');
+        global $conf, $injector, $prefs, $registry, $session;
 
         switch ($ui->group) {
         case 'accounts':
             if (empty($conf['user']['allow_accounts'])) {
                 $ui->suppress[] = 'accountsmanagement';
-            } else {
-                Horde::addScriptFile('accountsprefs.js', 'imp');
             }
             break;
 
-        case 'acl':
-            Horde::addScriptFile('acl.js', 'imp');
-            break;
-
         case 'addressbooks':
-            if (!$prefs->isLocked('sourceselect')) {
-                Horde_Core_Prefs_Ui_Widgets::addressbooksInit();
+            if (!$prefs->isLocked('add_source')) {
+                try {
+                    $ui->override['add_source'] = $registry->call('contacts/sources', array(true));
+                } catch (Horde_Exception $e) {
+                    $ui->suppress[] = 'add_source';
+                }
             }
             break;
 
@@ -105,7 +218,7 @@ class IMP_Prefs_Ui
             break;
 
         case 'delmove':
-            if ($pop3) {
+            if ($session->get('imp', 'protocol') == 'pop') {
                 $ui->suppress[] = 'move_ham_after_report';
                 $ui->suppress[] = 'empty_spam_menu';
                 $ui->suppress[] = 'use_trash';
@@ -125,10 +238,7 @@ class IMP_Prefs_Ui
             break;
 
         case 'display':
-            /* Set the timezone on this page so the 'time_format' output uses
-             * the configured time zone's time, not the system's time zone. */
-            $registry->setTimeZone();
-            if ($pop3) {
+            if ($session->get('imp', 'protocol') == 'pop') {
                 $ui->suppress[] = 'nav_expanded';
                 $ui->suppress[] = 'tree_view';
             }
@@ -151,29 +261,14 @@ class IMP_Prefs_Ui
             }
             break;
 
-        case 'flags':
-            if ($prefs->isLocked('msgflags') &&
-                $prefs->isLocked('msgflags_user')) {
-                $ui->nobuttons = true;
-            } else {
-                Horde::addScriptFile('colorpicker.js', 'horde');
-                Horde::addScriptFile('flagprefs.js', 'imp');
-            }
-            break;
-
         case 'identities':
             if ($prefs->isLocked('sent_mail_folder')) {
                 $ui->suppress[] = 'sentmailselect';
-            } else {
-                Horde::addScriptFile('folderprefs.js', 'imp');
             }
 
             if ($prefs->isLocked('signature_html') ||
                 !$session->get('imp', 'rteavail')) {
                 $ui->suppress[] = 'signature_html_select';
-            } else {
-                Horde::addScriptFile('signaturehtml.js', 'imp');
-                IMP_Ui_Editor::init(false, 'signature_html');
             }
             break;
 
@@ -181,7 +276,7 @@ class IMP_Prefs_Ui
             if ($prefs->isLocked('initial_page')) {
                 $ui->suppress[] = 'initialpageselect';
             }
-            if ($pop3) {
+            if ($session->get('imp', 'protocol') == 'pop') {
                 $ui->suppress[] = 'initialpageselect';
                 $ui->suppress[] = 'rename_sentmail_monthly';
                 $ui->suppress[] = 'delete_sentmail_monthly';
@@ -202,15 +297,13 @@ class IMP_Prefs_Ui
             if ($prefs->isLocked('nav_audio')) {
                 $ui->suppress[] = 'soundselect';
             }
-            if ($pop3) {
+            if ($session->get('imp', 'protocol') == 'pop') {
                 $ui->suppress[] = 'nav_poll_all';
             }
             break;
 
         case 'pgp':
-            if ($prefs->getValue('use_pgp')) {
-                Horde::addScriptFile('imp.js', 'imp');
-            } else {
+            if (!$prefs->getValue('use_pgp')) {
                 $ui->suppress[] = 'use_pgp_text';
                 $ui->suppress[] = 'pgp_attach_pubkey';
                 $ui->suppress[] = 'pgp_scan_body';
@@ -221,51 +314,21 @@ class IMP_Prefs_Ui
             }
             break;
 
-        case 'searches':
-            Horde::addScriptFile('searchesprefs.js', 'imp');
-            break;
-
         case 'server':
-            $code = array();
-
             if ($prefs->isLocked('drafts_folder')) {
                 $ui->suppress[] = 'draftsselect';
-            } else {
-                $code['drafts'] = _("Enter the name for your new drafts folder.");
             }
-
             if ($prefs->isLocked('spam_folder')) {
                 $ui->suppress[] = 'spamselect';
-            } else {
-                $code['spam'] = _("Enter the name for your new spam folder.");
             }
 
-            if (!$prefs->isLocked('trash_folder')) {
-                $code['trash'] = _("Enter the name for your new trash folder.");
-            } else {
+            if ($prefs->isLocked('trash_folder')) {
                 $ui->suppress[] = 'trashselect';
             }
-
-            if (!empty($code)) {
-                Horde::addScriptFile('folderprefs.js', 'imp');
-                Horde::addInlineJsVars(array(
-                    'ImpFolderPrefs.folders' => $code
-                ));
-            }
             break;
 
         case 'smime':
-            $use_smime = false;
-            if ($prefs->getValue('use_smime')) {
-                try {
-                    $GLOBALS['injector']->getInstance('IMP_Crypt_Smime')->checkForOpenSSL();
-                    $use_smime = true;
-                } catch (Horde_Exception $e) {}
-            }
-
-            if ($use_smime) {
-                Horde::addScriptFile('imp.js', 'imp');
-            } else {
+            if (!$prefs->getValue('use_smime')) {
                 $ui->suppress[] = 'use_smime_text';
                 $ui->suppress[] = 'smime_verify';
                 $ui->suppress[] = 'smimepublickey';
@@ -276,8 +339,6 @@ class IMP_Prefs_Ui
         case 'stationery':
             if ($prefs->isLocked('stationery')) {
                 $ui->suppress[]  = 'stationerymanagement';
-            } else {
-                $ui->nobuttons = true;
             }
             break;
 
@@ -297,57 +358,13 @@ class IMP_Prefs_Ui
 
             $mock_part = new Horde_Mime_Part();
             $mock_part->setType('text/html');
-            $v = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MimeViewer')->create($mock_part);
+            $v = $injector->getInstance('IMP_Injector_Factory_MimeViewer')->create($mock_part);
 
             if (!$v->canRender('inline')) {
                 $ui->suppress[] = 'alternative_display';
             }
-
-            /* Sort encodings. */
-            if (!$prefs->isLocked('default_msg_charset')) {
-                asort($registry->nlsconfig['encodings']);
-            }
             break;
         }
-
-        /* Hide appropriate prefGroups. */
-        if ($pop3) {
-            $ui->suppressGroups[] = 'flags';
-            $ui->suppressGroups[] = 'searches';
-            $ui->suppressGroups[] = 'server';
-        }
-
-        try {
-            $GLOBALS['injector']->getInstance('IMP_Imap_Acl');
-        } catch (IMP_Exception $e) {
-            $ui->suppressGroups[] = 'acl';
-        }
-
-        if (empty($conf['user']['allow_accounts'])) {
-            $ui->suppressGroups[] = 'accounts';
-        }
-
-        $contacts_app = $registry->hasInterface('contacts');
-        if (!$contacts_app || !$registry->hasPermission($contacts_app)) {
-            $ui->suppressGroups[] = 'addressbooks';
-        }
-
-        if (!isset($GLOBALS['conf']['gnupg']['path'])) {
-            $ui->suppressGroups[] = 'pgp';
-        }
-
-        if (!Horde_Util::extensionExists('openssl') ||
-            !isset($conf['openssl']['path'])) {
-            $ui->suppressGroups[] = 'smime';
-        }
-
-        if (empty($conf['user']['allow_folders'])) {
-            $ui->suppressGroups[] = 'searches';
-        }
-
-        // TODO: For now, disable this group since accounts code has not
-        // yet been fully written.
-        $ui->suppressGroups[] = 'accounts';
     }
 
     /**
@@ -533,12 +550,6 @@ class IMP_Prefs_Ui
             }
             break;
 
-        case 'delmove':
-            if ($prefs->isDirty('use_trash')) {
-                $ui->suppress = array_diff($ui->suppress, array('trashselect', 'empty_trash_menu'));
-            }
-            break;
-
         case 'dimp':
             if ($prefs->isDirty('dynamic_view')) {
                 $session->set(
index f06ddce..f881fd0 100644 (file)
@@ -162,15 +162,21 @@ class Kronolith_Application extends Horde_Registry_Application
     }
 
     /**
-     * Populate dynamically-generated preference values.
+     * Code to run on init when viewing prefs for this application.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsEnum($ui)
+    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 'freebusy':
             if (!$prefs->isLocked('fb_cals')) {
                 $fb_list = array();
@@ -181,81 +187,46 @@ class Kronolith_Application extends Horde_Registry_Application
             }
             break;
 
-       case 'share':
-            if (!$prefs->isLocked('default_share')) {
-                $all_shares = Kronolith::listInternalCalendars();
-                $sharelist = array();
-
-                foreach ($all_shares as $id => $share) {
-                    if (!empty($conf['share']['hidden']) &&
-                        ($share->get('owner') != $GLOBALS['registry']->getAuth()) &&
-                        !in_array($share->getName(), $GLOBALS['display_calendars'])) {
-                        continue;
-                    }
-                    $sharelist[$id] = $share;
-                }
-
-                $vals = array();
-                foreach ($sharelist as $id => $share) {
-                    $vals[htmlspecialchars($id)] = htmlspecialchars($share->get('name'));
-                }
-                $ui->override['default_share'] = $vals;
+        case 'notification':
+            if (!empty($conf['alarms']['driver']) &&
+                !$prefs->isLocked('event_alarms') &&
+                !$prefs->isLocked('event_alarms_select')) {
+                Horde_Core_Prefs_Ui_Widgets::alarminit();
             }
             break;
+        }
 
-        case 'view':
-            if (!$prefs->isLocked('day_hour_start') ||
-                !$prefs->isLocked('day_hour_end')) {
-                $out = array();
-                $tf = $GLOBALS['prefs']->getValue('twentyFour') ? 'G:i' : 'g:ia';
-                for ($i = 0; $i <= 48; ++$i) {
-                    $out[$i] = date($tf, mktime(0, $i * 30, 0));
-                }
-                $ui->override['day_hour_end'] = $out;
-                $ui->override['day_hour_start'] = $out;
-            }
-            break;
+        /* Suppress prefGroups display. */
+        if (!$registry->hasMethod('contacts/sources')) {
+            $ui->suppressGroups[] = 'addressbooks';
+        }
+
+        if ($prefs->isLocked('default_alarm')) {
+            $ui->suppressGroups[] = 'event_options';
         }
     }
 
     /**
-     * Code to run on init when viewing prefs for this application.
+     * Determine active prefs when displaying a group.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsInit($ui)
+    public function prefsGroup($ui)
     {
-        global $conf, $prefs, $registry;
+        global $conf, $prefs;
 
         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();
+                $ui->suppress[] = 'event_alarms';
             }
             break;
         }
-
-        /* Suppress prefGroups display. */
-        if (!$registry->hasMethod('contacts/sources')) {
-            $ui->suppressGroups[] = 'addressbooks';
-        }
-
-        if ($prefs->isLocked('default_alarm')) {
-            $ui->suppressGroups[] = 'event_options';
-        }
     }
 
-   /**
+    /**
      * Generate code used to display a special preference.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
index 3f7e6bc..e9c554c 100644 (file)
@@ -119,11 +119,11 @@ class Mnemo_Application extends Horde_Registry_Application
     }
 
     /**
-     * Populate dynamically-generated preference values.
+     * Run once on init when viewing prefs for an application.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsEnum($ui)
+    public function prefsInit($ui)
     {
         switch ($ui->group) {
         case 'share':
index 3996e3b..a12afbf 100644 (file)
@@ -129,13 +129,13 @@ class Nag_Application extends Horde_Registry_Application
     }
 
     /**
-     * Populate dynamically-generated preference values.
+     * Code to run on init when viewing prefs for this application.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsEnum($ui)
+    public function prefsInit($ui)
     {
-        global $prefs, $registry;
+        global $conf, $prefs, $registry;
 
         switch ($ui->group) {
         case 'share':
@@ -145,7 +145,7 @@ class Nag_Application extends Horde_Registry_Application
 
                 foreach ($all_tasklists as $id => $tasklist) {
                     if (!empty($conf['share']['hidden']) &&
-                        ($tasklist->get('owner') != $GLOBALS['registry']->getAuth()) &&
+                        ($tasklist->get('owner') != $registry->getAuth()) &&
                         !in_array($tasklist->getName(), $GLOBALS['display_tasklists'])) {
                         continue;
                     }
@@ -176,26 +176,21 @@ class Nag_Application extends Horde_Registry_Application
             break;
         }
 
-        $show_external = array();
         if ($registry->hasMethod('getListTypes', 'whups')) {
-            $show_external['whups'] = $registry->get('name', 'whups');
-        }
-        if (count($show_external)) {
-            $ui->override['show_external'] = $show_external;
-        } else {
-            $ui->suppress[] = 'show_external';
-            $ui->suppressGroups[] = 'external';
+            $ui->override['show_external'] = array(
+                'whups' => $registry->get('name', 'whups')
+            );
         }
     }
 
     /**
-     * Code to run on init when viewing prefs for this application.
+     * Determine active prefs when displaying a group.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsInit($ui)
+    public function prefsGroup($ui)
     {
-        global $conf, $prefs;
+        global $conf, $prefs, $registry;
 
         switch ($ui->group) {
         case 'notification':
@@ -206,6 +201,10 @@ class Nag_Application extends Horde_Registry_Application
             }
             break;
         }
+
+        if (!$registry->hasMethod('getListTypes', 'whups')) {
+            $ui->suppress[] = 'show_external';
+        }
     }
 
     /**
index 54a0aee..39dda94 100644 (file)
@@ -197,11 +197,11 @@ class Turba_Application extends Horde_Registry_Application
     }
 
     /**
-     * Populate dynamically-generated preference values.
+     * Code to run on init when viewing prefs for this application.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
      */
-    public function prefsEnum($ui)
+    public function prefsInit($ui)
     {
         global $prefs;
 
@@ -229,21 +229,7 @@ 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;