[dev] [imp-patch] Hiding multiple address book options

Francois Marier francois at nit.ca
Tue Jul 27 17:52:00 PDT 2004


This is a patch for IMP's option page.  It aims at making the "Address
books" option page simpler by removing some options that are not
useful in the current context.

If there is only one address book configured, the options related to
setting the default address book and such will be hidden and replaced
by an <input type=hidden> tag with the unique source.

It removes the ability to select "None" as the expansion address book,
but I don't see why this should be an option.  After all, if users
don't want to expand from a notebook, they just have to refrain from
clicking on the "Expand" button of the Compose window.

Francois
-------------- next part --------------
diff -rpuN -X ../ignorelist ../build/imp/templates/prefs/sourceselect.inc imp/templates/prefs/sourceselect.inc
--- ../build/imp/templates/prefs/sourceselect.inc	Sat Oct 18 17:19:19 2003
+++ imp/templates/prefs/sourceselect.inc	Fri Jul 23 16:04:40 2004
@@ -5,8 +5,17 @@ if ($registry->hasMethod('contacts/sourc
     $readable = $registry->call('contacts/sources');
     $writeable = $registry->call('contacts/sources', true);
 
+    $nbReadSources = count(array_keys($readable));
+    $nbWriteSources = count(array_keys($writeable));
+
     if (count($selected) == 1 && empty($selected[0]))
         $selected = array();
+    
+    if ($nbReadSources == 1) {
+        // Only one source, no need to display the selection widget
+        $selected = array_keys($readable);
+        $readSelect = '';
+    }
 
     $prefSelect = '';
     foreach ($selected as $source) {
@@ -24,9 +33,11 @@ if ($registry->hasMethod('contacts/sourc
 
     if (!is_a($writeable, 'PEAR_Error') && is_array($writeable)) {
         $writeSelect = '<option value="">' . _("None") . '</option>' . "\n";
+        $writeSource = '';
         foreach ($writeable as $source => $name) {
             $sel = $prefs->getValue('add_source') == $source ? ' selected="selected"' : '';
             $writeSelect .= '<option value="' . $source . '"' . "$sel>" . $name . "</option>\n";
+            $writeSource = $source;
         }
     }
 
@@ -204,19 +215,34 @@ function moveSourceDown()
 
 <?php echo $js ?>
 
+var selectedIndex = false;
+var selectedValue = false;
+var nbSources = <?php echo $nbReadSources ?>;
+<?php if ($nbReadSources == 1): ?>
+selectedIndex = 1;
+selectedValue = "<?php echo $selected[0] ?>";
+<?php endif; ?>
+
 function updateSearchFields()
 {
     var f = document.prefs;
+    <?php if ($nbReadSources > 1): ?>
+    selectedIndex = f.selected_search_sources.selectedIndex;
+    <?php endif; ?>
     var fieldString = '';
 
     while (f.search_fields.length > 0) {
         f.search_fields.options[f.search_fields.length-1] = null;
     }
 
-    if (f.selected_search_sources.selectedIndex < 1) {
+    if (selectedIndex < 1) {
         return;
     }
 
+    <?php if ($nbReadSources > 1): ?>
+    selectedValue = f.selected_search_sources.options[selectedIndex].value;
+    <?php endif; ?>
+
     for (var i = 0; i < searchFields.length; i++) {
         if (i > 0) {
             fieldString += "\n";
@@ -226,7 +252,8 @@ function updateSearchFields()
             if (searchFields[i][j][2]) {
                 fieldString += "\t" + searchFields[i][j][0];
             }
-            if (searchFields[i][0] == f.selected_search_sources.options[f.selected_search_sources.selectedIndex].value) {
+            
+            if (searchFields[i][0] == selectedValue) {
                 f.search_fields.options[f.search_fields.length] = new Option(searchFields[i][j][1], searchFields[i][j][0]);
                 if (searchFields[i][j][2]) {
                     f.search_fields.options[f.search_fields.length - 1].selected = true;
@@ -241,9 +268,13 @@ function updateSearchFields()
 function changeSearchFields()
 {
     var f = document.prefs;
+    <?php if ($nbReadSources > 1): ?>
+    selectedIndex = f.selected_search_sources.selectedIndex;
+    selectedValue = f.selected_search_sources.options[selectedIndex].value;
+    <?php endif; ?>
 
     for (var i = 0; i < searchFields.length; i++) {
-        if (searchFields[i][0] == f.selected_search_sources.options[f.selected_search_sources.selectedIndex].value) {
+        if (searchFields[i][0] == selectedValue) {
             for (var j = 1; j < searchFields[i].length; j++) {
                 searchFields[i][j][2] = f.search_fields.options[j - 1].selected;
             }
@@ -252,12 +283,14 @@ function changeSearchFields()
         }
     }
 }
+
 // -->
 </script>
 
 <br />
-<?php echo _("Choose the order of address books to search when expanding addresses.") ?><br />
 <input type="hidden" name="search_sources" value="<?php echo implode("\t", $selected) ?>" />
+<?php if ($nbReadSources > 1): ?>
+<?php echo _("Choose the order of address books to search when expanding addresses.") ?><br />
 <table>
     <tr>
         <td>
@@ -286,6 +319,10 @@ function changeSearchFields()
 </table>
 
 <?php echo _("Click on one of your selected address books and then select all fields to search.") ?><br />
+<?php else: ?>
+<?php echo _("Select all fields to search when expanding addresses.") ?><br />
+<?php endif; ?>
+
 <?php echo _("To select multiple fields, hold down the Control (PC) or Command (Mac) while clicking.") ?><br />
 <input type="hidden" name="search_fields_string" />
 <table>
@@ -297,11 +334,24 @@ function changeSearchFields()
         </td>
     </tr>
 </table>
+
+<script language="JavaScript" type="text/javascript">
+<!--
+updateSearchFields();
+// -->
+</script>
+
 <?php endif; ?>
 
-<br />
 
-<?php if (!$prefs->isLocked('search_sources') && !empty($writeSelect)): ?>
-<?php echo _("Choose the address book to use when adding addresses.") ?><br />
-<select name="add_source"><?php echo $writeSelect ?></select>
+<?php if (!$prefs->isLocked('add_source') && !empty($writeSelect)): ?>
+
+  <?php if ($nbWriteSources > 1): ?>
+  <?php echo _("Choose the address book to use when adding addresses.") ?><br />
+  <br />
+  <select name="add_source"><?php echo $writeSelect ?></select>
+  <?php else: ?>
+  <input type="hidden" name="add_source" value="<?php print $writeSource ?>" />
+  <?php endif; ?>
+
 <?php endif; ?>


More information about the dev mailing list