Bug #8977: Add prefsEnum()
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 20 Apr 2010 05:19:11 +0000 (23:19 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 20 Apr 2010 05:48:38 +0000 (23:48 -0600)
12 files changed:
ansel/lib/Application.php
fima/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 cbf48d0..2610d24 100644 (file)
@@ -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;
 
index 4d8136c..de4ee48 100644 (file)
@@ -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':
index c513e46..a6ef7c6 100644 (file)
@@ -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');
index c2cf99c..4535d6b 100644 (file)
@@ -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.
index d482d16..2f9218f 100644 (file)
@@ -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.
index 5f4f19e..fef4003 100644 (file)
 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;
index ef42dc0..631c6f2 100644 (file)
@@ -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.
index 915c52c..b527d58 100644 (file)
 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';
index 05af8c4..5b4be45 100644 (file)
@@ -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')) {
index ae3596d..da9e126 100644 (file)
@@ -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'));
index b8e7278..36f154b 100644 (file)
@@ -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;
         }
     }
 
index 4663d2f..da6ddb5 100644 (file)
@@ -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');