Move form processing for source/addressbook prefs to Widgets class
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Apr 2010 15:05:36 +0000 (09:05 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Apr 2010 15:05:36 +0000 (09:05 -0600)
framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php
imp/lib/Prefs/Ui.php
kronolith/lib/Application.php
turba/lib/Application.php
whups/lib/Application.php

index e05f350..c2a097f 100644 (file)
@@ -27,12 +27,6 @@ class Horde_Core_Prefs_Ui_Widgets
     /**
      * Create code needed for source selection.
      *
-     * Returns data in a form variable named 'sources'. If only one source
-     * was originally given, this variable will contain the list of selected
-     * values (JSON encoded). If multiple sources were given, this variable
-     * will contain a list of arrays; each subarray contains the source name
-     * and the list of selected values (JSON encoded).
-     *
      * @param array $data  Data items:
      * <pre>
      * 'mainlabel' - (string) Main label.
@@ -102,6 +96,28 @@ class Horde_Core_Prefs_Ui_Widgets
         return $t->fetch(HORDE_TEMPLATES . '/prefs/source.html');
     }
 
+    /**
+     * Process form data for source selection.
+     *
+     * @param Horde_Core_Prefs_Ui $ui  The UI object.
+     *
+     * @return array  If only one source was originally given, contains the
+     *                list of selected values (JSON encoded). If multiple
+     *                sources were given, this variable will contain a list of
+     *                arrays; each subarray contains the source name and the
+     *                list of selected values (JSON encoded).
+     */
+    static public function sourceUpdate($ui)
+    {
+        $out = array();
+
+        if (isset($ui->vars->sources)) {
+            $out['sources'] = $ui->vars->sources;
+        }
+
+        return $out;
+    }
+
     /* Addressbook selection widget. Extends the source widget to handle
      * the special case of addressbook selection. */
 
@@ -117,11 +133,6 @@ class Horde_Core_Prefs_Ui_Widgets
     /**
      * Create code needed for addressbook selection.
      *
-     * Returns data in form variables named sources and search_fields.
-     * Sources contains the list of selected addressbooks (JSON encoded).
-     * search_fields contains a hash containing sources as keys and an array
-     * of search fields as the value.
-     *
      * @param array $data  Data items:
      * <pre>
      * 'fields' - (array) Hash containing addressbook sources as keys and an
@@ -220,6 +231,31 @@ class Horde_Core_Prefs_Ui_Widgets
         return $out . $t->fetch(HORDE_TEMPLATES . '/prefs/addressbooks.html');
     }
 
+    /**
+     * Process form data for address book selection.
+     *
+     * @param Horde_Core_Prefs_Ui $ui  The UI object.
+     *
+     * @return array  Array with two possible keys: sources and fields.
+     *                Sources contains the list of selected addressbooks (JSON
+     *                encoded). Fields contains a hash containing sources as
+     *                keys and an array of search fields as the value.
+     */
+    static public function addressbooksUpdate($ui)
+    {
+        $out = self::sourcesUpdate($ui);
+
+        if (isset($ui->vars->sources)) {
+            $out['sources'] = $ui->vars->sources;
+        }
+
+        if (isset($ui->vars->search_fields)) {
+            $out['fields'] = $ui->vars->search_fields;
+        }
+
+        return $out;
+    }
+
     /* Alarms selection widget. */
 
     /**
@@ -332,9 +368,10 @@ class Horde_Core_Prefs_Ui_Widgets
     }
 
     /**
-     * Process form data.
+     * Process form data for alarm selection.
      *
-     * @param array $data  Data items:
+     * @param Horde_Core_Prefs_Ui $ui  The UI object.
+     * @param array $data              Data items:
      * <pre>
      * 'pref' - (string) Preference name.
      * </pre>
index e583faf..d5f3fb7 100644 (file)
@@ -1335,16 +1335,17 @@ class IMP_Prefs_Ui
     {
         global $prefs;
 
+        $data = Horde_Core_Prefs_Ui_Widgets::addressbooksUpdate($ui);
         $updated = false;
 
-        if (isset($ui->vars->sources)) {
-            $prefs->setValue('search_sources', $ui->vars->sources);
+        if (isset($data['sources'])) {
+            $prefs->setValue('search_sources', $data['sources']);
             unset($_SESSION['imp']['cache']['ac_ajax']);
             $updated = true;
         }
 
-        if (isset($ui->vars->search_fields)) {
-            $prefs->setValue('search_fields', $ui->vars->search_fields);
+        if (isset($data['fields'])) {
+            $prefs->setValue('search_fields', $data['fields']);
             $updated = true;
         }
 
index e3b3303..3f81c76 100644 (file)
@@ -391,15 +391,16 @@ class Kronolith_Application extends Horde_Registry_Application
     {
         global $prefs;
 
+        $data = Horde_Core_Prefs_Ui_Widgets::addressbooksUpdate($ui);
         $updated = false;
 
-        if (isset($ui->vars->sources)) {
-            $prefs->setValue('search_sources', $ui->vars->sources);
+        if (isset($data['sources'])) {
+            $prefs->setValue('search_sources', $data['sources']);
             $updated = true;
         }
 
-        if (isset($ui->vars->search_fields)) {
-            $prefs->setValue('search_fields', $ui->vars->search_fields);
+        if (isset($data['fields'])) {
+            $prefs->setValue('search_fields', $data['fields']);
             $updated = true;
         }
 
index c257353..0eee7fc 100644 (file)
@@ -322,8 +322,12 @@ class Turba_Application extends Horde_Registry_Application
     {
         switch ($item) {
         case 'addressbookselect':
-            $ui->setValue('addressbooks', Horde_Serialize::unserialize($ui->vars->sources, Horde_Serialize::JSON));
-            return true;
+            $data = Horde_Core_Prefs_Ui_Widgets::sourceUpdate($ui);
+            if (isset($data['sources'])) {
+                $ui->setValue('addressbooks', Horde_Serialize::unserialize($data['sources'], Horde_Serialize::JSON));
+                return true;
+            }
+            break;
 
         case 'columnselect':
             if (isset($ui->vars->columns)) {
@@ -332,6 +336,8 @@ class Turba_Application extends Horde_Registry_Application
             }
             break;
         }
+
+        return false;
     }
 
     /**
index b6adab6..cb87d8f 100644 (file)
@@ -176,13 +176,15 @@ class Whups_Application extends Horde_Registry_Application
 
         switch ($item) {
         case 'sourceselect':
-            if (isset($ui->vars->sources)) {
-                $prefs->setValue('search_sources', $ui->vars->sources);
+            $data = Horde_Core_Prefs_Ui_Widgets::addressbooksUpdate($ui);
+
+            if (isset($data['sources'])) {
+                $prefs->setValue('search_sources', $data['sources']);
                 $updated = true;
             }
 
-            if (isset($ui->vars->search_fields)) {
-                $prefs->setValue('search_fields', $ui->vars->search_fields);
+            if (isset($data['fields'])) {
+                $prefs->setValue('search_fields', $data['fields']);
                 $updated = true;
             }
             break;