[dev] [PATCH] Personal Information options screen (bug 1846)

Elliot Kendall ekendall at brandeis.edu
Mon Apr 25 14:13:29 PDT 2005


I understand the issue a little better now than I did when I first filed
the bug. The "None" option is so that you can change just your default
identity without making any preference changes, but it's still a very
confusing interface.

This patch removes the "None" option, adds a button just for changing
the default identity, makes the "which identity to change" select field
have the user's default identity selected, and (the really hard part)
pre-fills all the fields with the appropriate values from the default
identity.

I have no illusions that the patch is suitable to be committed as it
stands. It uses overly generic messages to avoid having to have new
text translated, and the trick I used to get Javascript into the body's
onload attribute is a serious hack. I would welcome any suggestions as
to how to proceed from here.

Elliot
-------------- next part --------------
diff -urN horde.old/config/prefs.php horde/config/prefs.php
--- horde.old/config/prefs.php	2005-02-15 15:58:25.000000000 -0500
+++ horde/config/prefs.php	2005-04-22 11:26:57.000000000 -0400
@@ -64,7 +64,7 @@
     'column' => _("Your Information"),
     'label' => _("Personal Information"),
     'desc' => _("Change the name and address that people see when they read and reply to your emails."),
-    'members' => array('default_identity', 'identityselect', 'deleteidentity',
+    'members' => array('default_identity', 'changedefaultidentity', 'identityselect', 'deleteidentity',
                        'id', 'fullname', 'from_addr')
 );
 
@@ -148,6 +148,12 @@
     'desc' => _("Your default identity:")
 );
 
+// change default identity button
+$_prefs['changedefaultidentity'] = array(
+    'type' => 'special',
+    'shared' => true
+);
+
 // identities array
 // Don't change anything here.
 $_prefs['identities'] = array(
diff -urN horde.old/lib/Horde/Prefs/UI.php horde/lib/Horde/Prefs/UI.php
--- horde.old/lib/Horde/Prefs/UI.php	2005-03-29 06:00:00.000000000 -0500
+++ horde/lib/Horde/Prefs/UI.php	2005-04-25 16:30:24.000000000 -0400
@@ -246,9 +246,12 @@
      */
     function generateHeader($group = null)
     {
-        global $registry, $prefGroups, $app, $perms;
+        global $registry, $prefGroups, $app, $perms, $prefs, $bodyClass;
 
         $title = _("User Options");
+        if ($group == "identities" && ! $prefs->isLocked('default_identity')) {
+            $bodyClass = $bodyClass . "\" onload=\"javascript:newChoice()";
+        }
         require $registry->get('templates', $app) . '/common-header.inc';
         if (is_callable(array($app, 'getMenu'))) {
             $menu = call_user_func(array($app, 'getMenu'));
diff -urN horde.old/services/prefs.php horde/services/prefs.php
--- horde.old/services/prefs.php	2005-01-03 07:25:45.000000000 -0500
+++ horde/services/prefs.php	2005-04-25 12:15:30.000000000 -0400
@@ -87,6 +87,12 @@
         $deleted_identity = $identity->delete(Util::getFormData('id'));
         $notification->push(sprintf(_("The identity \"%s\" has been deleted."), $deleted_identity[0]['id']), 'horde.success');
         break;
+
+    case 'change_default_identity':
+        $default_identity = $identity->setDefault(Util::getFormData('id'));
+        $identity->save();
+	$notification->push(_("Your options have been updated."), 'horde.success');
+        break;
     }
 } elseif (Prefs_UI::handleForm($group, $prefs)) {
     require $appbase . '/config/prefs.php';
diff -urN horde.old/templates/prefs/changedefaultidentity.inc horde/templates/prefs/changedefaultidentity.inc
--- horde.old/templates/prefs/changedefaultidentity.inc	1969-12-31 19:00:00.000000000 -0500
+++ horde/templates/prefs/changedefaultidentity.inc	2005-04-22 11:25:46.000000000 -0400
@@ -0,0 +1,14 @@
+<?php if (!$prefs->isLocked('default_identity')): ?>
+<script language="JavaScript" type="text/javascript">
+<!--
+function changeDefaultIdentity()
+{
+    var index = document.prefs.default_identity.selectedIndex;
+    var id = document.prefs.default_identity.options[index].value;
+    document.location.href = "<?php echo str_replace('&amp;', '&', Util::addParameter(Horde::selfUrl(true), array('actionID' => 'change_default_identity', 'id' => ''))) ?>" + id;
+}
+//-->
+</script>
+<br />
+<input type="button" onclick="changeDefaultIdentity()" class="button" value="<?php echo _("Change") ?>" /><br />
+<?php endif; ?>
diff -urN horde.old/templates/prefs/identityselect.inc horde/templates/prefs/identityselect.inc
--- horde.old/templates/prefs/identityselect.inc	2004-09-18 13:13:46.000000000 -0400
+++ horde/templates/prefs/identityselect.inc	2005-04-22 11:59:57.000000000 -0400
@@ -8,6 +8,7 @@
 <?php
 global $identity;
 $identities = $identity->getAll('id');
+$default_identity = $identity->getDefault();
 $members = $prefGroups['identities']['members'];
 for ($i = 0; $i < count($identities); $i++):
 ?>
@@ -84,11 +85,9 @@
 <br />
 <?php echo Horde::label('identity', _("Select the identity you want to change:")) ?><br />
 <select name="identity" id="identity" onchange="javascript:newChoice()">
-  <option value="-2" selected="selected"
-><?php echo _("None") ?></option>
   <option value="-1"><?php echo _("Create a new one") ?></option>
 <?php for ($i = 0; $i < count($identities); $i++): ?>
-  <option value="<?php echo $i ?>"><?php echo $identities[$i] ?></option>
+  <option value="<?php echo $i ?>" <?php if ($i == $default_identity) echo 'selected="selected"' ?>><?php echo $identities[$i] ?></option>
 <?php endfor; ?>
 </select><br />
 <?php endif; ?>


More information about the dev mailing list