Request #9159: Automatically determine view
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 6 Aug 2010 18:02:58 +0000 (12:02 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 6 Aug 2010 18:10:01 +0000 (12:10 -0600)
imp/config/conf.xml
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/lib/Application.php
imp/lib/Auth.php

index 2e84132..00b2475 100644 (file)
    will be a 'Message Source' link in the parts list of every message, allowing
    the user to view the entire raw message, or to download it and save it to
    disk.">true</configboolean>
-   <configswitch name="select_view" desc="If either DIMP or MIMP is available,
-   allow user to select the application view on login?">true
+   <configswitch name="select_view" desc="Allow user to select the application
+   view mode on login?">false
     <case name="true" desc="Yes"/>
     <case name="false" desc="No">
-     <configenum name="force_view" desc="Which application view should be used
-     for all users?">imp
+     <configenum name="force_view" desc="Force an application view to be used
+     for all users?">
       <values>
+       <value desc="None (use user's browser and 'dynamic_view' preference)"></value>
        <value desc="IMP">imp</value>
        <value desc="DIMP">dimp</value>
        <value desc="MIMP">mimp</value>
index 6f4f328..25a6f2b 100644 (file)
@@ -1713,7 +1713,14 @@ $prefGroups['dimp'] = array(
     'column' => _("Other Options"),
     'label' => _("Dynamic View Options"),
     'desc' => _("Configure options for the dynamic view."),
-    'members' => array('dimp_login_view')
+    'members' => array('dynamic_view', 'dimp_login_view')
+);
+
+// Show dynamic view?
+$_prefs['dynamic_view'] = array(
+    'value' => 1,
+    'type' => 'checkbox',
+    'desc' => _("Show the dynamic view by default, if the browser supports it?")
 );
 
 // Login preferences (dimp)
index 532f176..93d4fd0 100644 (file)
@@ -2,6 +2,8 @@
 v5.0-git
 --------
 
+[mms] Automatically determine view based on browser and 'dynamic_view'
+      preference (Request #9159).
 [mms] Add preference to define default font family/size for the HTML compose
       editor.
 [mms] Honor nav_expanded preference (DIMP).
index a09c7eb..64b52cc 100644 (file)
@@ -235,18 +235,18 @@ class IMP_Application extends Horde_Registry_Application
         }
 
         /* Show selection of alternate views. */
-        if (empty($GLOBALS['conf']['user']['select_view'])) {
-            $view_cookie = empty($conf['user']['force_view'])
-                ? 'imp'
-                : $conf['user']['force_view'];
-        } else {
-            $views = array();
+        $js_code = array(
+            'ImpLogin.server_key_error=' . Horde_Serialize::serialize(_("Please choose a mail server."), Horde_Serialize::JSON)
+        );
+        if (!empty($GLOBALS['conf']['user']['select_view'])) {
             if (!($view_cookie = Horde_Util::getFormData('imp_select_view'))) {
                 $view_cookie = isset($_COOKIE['default_imp_view'])
                     ? $_COOKIE['default_imp_view']
                     : ($GLOBALS['browser']->isMobile() ? 'mimp' : 'imp');
             }
 
+            $js_code[] = 'ImpLogin.dimp_sel=' . intval($view_cookie == 'dimp');
+
             $params['imp_select_view'] = array(
                 'label' => _("Mode"),
                 'type' => 'select',
@@ -269,10 +269,7 @@ class IMP_Application extends Horde_Registry_Application
         }
 
         return array(
-            'js_code' => array(
-                'ImpLogin.dimp_sel=' . intval($view_cookie == 'dimp'),
-                'ImpLogin.server_key_error=' . Horde_Serialize::serialize(_("Please choose a mail server."), Horde_Serialize::JSON)
-            ),
+            'js_code' => $js_code,
             'js_files' => array(
                 array('login.js', 'imp')
             ),
index f680708..1838a42 100644 (file)
@@ -460,24 +460,33 @@ class IMP_Auth
         $editor = $GLOBALS['injector']->getInstance('Horde_Editor')->getEditor('Ckeditor', array('no_notify' => true));
         $sess['rteavail'] = $editor->supportedByBrowser();
 
-        /* Set view in session/cookie. */
-        $sess['view'] = empty($conf['user']['select_view'])
-            ? (empty($conf['user']['force_view']) ? 'imp' : $conf['user']['force_view'])
-            : (empty($sess['cache']['select_view']) ? 'imp' : $sess['cache']['select_view']);
+        /* Determine view. */
+        $setcookie = false;
+        if (empty($conf['user']['force_view'])) {
+            if (empty($conf['user']['select_view']) ||
+                empty($sess['cache']['select_view'])) {
+                $sess['view'] = $GLOBALS['browser']->isMobile()
+                    ? 'mimp'
+                    : ($GLOBALS['prefs']->getValue('dynamic_view') ? 'dimp' : 'imp');
+            } else {
+                $setcookie = true;
+                $sess['view'] = $sess['cache']['select_view'];
+            }
+        } else {
+            $sess['view'] = $conf['user']['force_view'];
+        }
 
-        /* Enforce minimum browser standards for DIMP.
-         * No IE < 7; Safari < 3 */
+        /* Enforce minimum browser standards for DIMP. */
         if (($sess['view'] == 'dimp') && !Horde::ajaxAvailable()) {
             $sess['view'] = 'imp';
             $GLOBALS['notification']->push(_("Your browser is too old to display the dynamic mode. Using traditional mode instead."), 'horde.warning');
         }
 
-        setcookie('default_imp_view', $sess['view'], time() + 30 * 86400,
-                  $conf['cookie']['path'],
-                  $conf['cookie']['domain']);
+        if ($setcookie) {
+            setcookie('default_imp_view', $sess['view'], time() + 30 * 86400, $conf['cookie']['path'], $conf['cookie']['domain']);
+        }
 
-        /* Suppress menus in options screen and indicate that notifications
-         * should use the ajax mode. */
+        /* Indicate that notifications should use AJAX mode. */
         if ($sess['view'] == 'dimp') {
             $_SESSION['horde_notification']['override'] = array(
                 IMP_BASE . '/lib/Notification/Listener/AjaxStatus.php',