From: Michael M Slusarz Date: Wed, 7 Apr 2010 15:05:36 +0000 (-0600) Subject: Move form processing for source/addressbook prefs to Widgets class X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=12e46699f32eb3bf7b8639ad11d56fe85278323b;p=horde.git Move form processing for source/addressbook prefs to Widgets class --- diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php index e05f35084..c2a097fd1 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php @@ -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: *
      * '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:
      * 
      * '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:
      * 
      * 'pref' - (string) Preference name.
      * 
diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index e583faf1a..d5f3fb700 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -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; } diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index e3b3303cb..3f81c7612 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -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; } diff --git a/turba/lib/Application.php b/turba/lib/Application.php index c257353f8..0eee7fc94 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -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; } /** diff --git a/whups/lib/Application.php b/whups/lib/Application.php index b6adab63d..cb87d8f38 100644 --- a/whups/lib/Application.php +++ b/whups/lib/Application.php @@ -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;