Convert mnemo to new preferences UI
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Apr 2010 13:33:58 +0000 (07:33 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Apr 2010 13:33:58 +0000 (07:33 -0600)
mnemo/config/prefs.php.dist
mnemo/lib/Application.php
mnemo/templates/prefs/notepadselect.inc [deleted file]

index ddeb1c2..b1b37c3 100644 (file)
@@ -1,13 +1,10 @@
 <?php
 /**
- * $Horde: mnemo/config/prefs.php.dist,v 1.31 2009/07/08 18:29:42 slusarz Exp $
- *
  * See horde/config/prefs.php for documentation on the structure of this file.
+ *
+ * $Id$
  */
 
-// Make sure that constants are defined.
-require_once dirname(__FILE__) . '/../lib/Mnemo.php';
-
 $prefGroups['display'] = array(
     'column' => _("General Options"),
     'label' => _("Display Options"),
@@ -19,7 +16,7 @@ $prefGroups['share'] = array(
     'column' => _("General Options"),
     'label' => _("Default Notepad"),
     'desc' => _("Choose your default Notepad."),
-    'members' => array('notepadselect')
+    'members' => array('default_notepad')
 );
 
 $prefGroups['deletion'] = array(
@@ -33,8 +30,6 @@ $prefGroups['deletion'] = array(
 // show a notepad column in the list view?
 $_prefs['show_notepad'] = array(
     'value' => 0,
-    'locked' => false,
-    'shared' => false,
     'type' => 'checkbox',
     'desc' => _("Should the Notepad be shown in its own column in the List view?")
 );
@@ -42,76 +37,58 @@ $_prefs['show_notepad'] = array(
 // show the notepad options panel?
 // a value of 0 = no, 1 = yes
 $_prefs['show_panel'] = array(
-    'value' => 1,
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit',
+    'value' => 1
 );
 
 // user preferred sorting column
 $_prefs['sortby'] = array(
     'value' => MNEMO_SORT_DESC,
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array(MNEMO_SORT_DESC => _("Note Text"),
-                    MNEMO_SORT_CATEGORY => _("Note Category"),
-                    MNEMO_SORT_NOTEPAD => _("Notepad")),
+    'enum' => array(
+        MNEMO_SORT_DESC => _("Note Text"),
+        MNEMO_SORT_CATEGORY => _("Note Category"),
+        MNEMO_SORT_NOTEPAD => _("Notepad")
+    ),
     'desc' => _("Default sorting criteria:")
 );
 
 // user preferred sorting direction
 $_prefs['sortdir'] = array(
     'value' => 0,
-    'locked' => false,
-    'shared' => false,
     'type' => 'enum',
-    'enum' => array(MNEMO_SORT_ASCEND => _("Ascending"),
-                    MNEMO_SORT_DESCEND => _("Descending")),
+    'enum' => array(
+        MNEMO_SORT_ASCEND => _("Ascending"),
+        MNEMO_SORT_DESCEND => _("Descending")
+    ),
     'desc' => _("Default sorting direction:")
 );
 
 // user note categories
 $_prefs['memo_categories'] = array(
-    'value' => '',
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit'
+    'value' => ''
 );
 
 // category highlight colors
 $_prefs['memo_colors'] = array(
-    'value' => '',
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit'
+    'value' => ''
 );
 
-// default notepad selection widget
-$_prefs['notepadselect'] = array('type' => 'special');
-
 // default notepad
 // Set locked to true if you don't want users to have multiple notepads.
 $_prefs['default_notepad'] = array(
     'value' => Horde_Auth::getAuth() ? Horde_Auth::getAuth() : 0,
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit'
+    'type' => 'enum',
+    'desc' => _("Your default notepad:")
 );
 
 // store the notepads to diplay
 $_prefs['display_notepads'] = array(
-    'value' => 'a:0:{}',
-    'locked' => false,
-    'shared' => false,
-    'type' => 'implicit'
+    'value' => 'a:0:{}'
 );
 
 // preference for delete confirmation dialog.
 $_prefs['delete_opt'] = array(
     'value' => 1,
-    'locked' => false,
-    'shared' => false,
     'type' => 'checkbox',
     'desc' => _("Do you want to confirm deleting entries?")
 );
index 6378663..3633cbc 100644 (file)
@@ -40,10 +40,10 @@ class Mnemo_Application extends Horde_Registry_Application
      * @var string
      */
     public $version = 'H4 (3.0-git)';
-    
+
     /**
      * Initialization function.
-     * 
+     *
      * Global variables defined:
      *   $mnemo_shares - TODO
      */
@@ -51,13 +51,35 @@ class Mnemo_Application extends Horde_Registry_Application
     {
        // Set the timezone variable.
        Horde_Nls::setTimeZone();
-       
+
        // Create a share instance.
        $GLOBALS['mnemo_shares'] = Horde_Share::singleton($GLOBALS['registry']->getApp());
-       
+
        Mnemo::initialize();
     }
-    
+
+    /**
+     * 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 'share':
+            if (!$prefs->isLocked('default_notepad')) {
+                $notepads = array();
+                foreach (Mnemo::listNotepads() as $key => $val) {
+                    $notepads[htmlspecialchars($key)] = htmlspecialchars($val->get('name'));
+                }
+                $ui->override['default_tasklist'] = $notepads;
+            }
+            break;
+        }
+    }
+
     /**
      * Generate the menu to use on the prefs page.
      *
diff --git a/mnemo/templates/prefs/notepadselect.inc b/mnemo/templates/prefs/notepadselect.inc
deleted file mode 100644 (file)
index 1c6e64b..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-if (!$prefs->isLocked('default_notepad')):
-    $notepads = Mnemo::listNotepads();
-    if (($default_notepad = $prefs->getValue('default_notepad')) == null ||
-        !isset($notepads[$default_notepad])) {
-        $default_notepad = Horde_Auth::getAuth();
-    }
-?>
-
-<?php echo Horde::label('default_notepad', _("Your default notepad:")) ?><br />
-<select id="default_notepad" name="default_notepad">
-<?php foreach (array_keys($notepads) as $id): ?>
-    <option value="<?php echo htmlspecialchars($id) ?>"<?php if ($id == $default_notepad) echo ' selected="selected"' ?>><?php echo htmlspecialchars($notepads[$id]->get('name')) ?></option>
-<?php endforeach; ?>
-</select><br /><br />
-<?php endif; ?>