Bug 1574590 - Change MozMenulistAddrbooks CE to fix LDAP auto-complete and LDAP server pref. r=mkmelin a=jorgk
authorAlessandro Castellani <alessandro@thunderbird.net>
Wed, 21 Aug 2019 21:11:04 +0200
changeset 36175 1e92fa2aab3f6481a1e2f28a4cce11370328a2a6
parent 36174 ea35b787e55b464c5617f4f412a57dd78d801660
child 36176 979207319f7a0eed4b9615cb5d56fb3c354b3df2
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersmkmelin, jorgk
bugs1574590
Bug 1574590 - Change MozMenulistAddrbooks CE to fix LDAP auto-complete and LDAP server pref. r=mkmelin a=jorgk
mail/components/addrbook/content/menulist-addrbooks.js
mail/components/preferences/compose.inc.xul
mailnews/base/prefs/content/am-addressing.inc.xul
--- a/mail/components/addrbook/content/menulist-addrbooks.js
+++ b/mail/components/addrbook/content/menulist-addrbooks.js
@@ -23,17 +23,16 @@ customElements.whenDefined("menulist").t
         return;
       }
 
       if (this.menupopup) {
         return;
       }
 
       this._directories = [];
-      this._value = this.getAttribute("value") || "URI";
 
       this._rebuild();
 
       // @implements {nsIAbListener}
       this.addressBookListener = {
         onItemAdded: (aParentDir, aItem) => {
           // Are we interested in this new directory?
           if (aItem instanceof Ci.nsIAbDirectory && this._matches(aItem)) {
@@ -84,20 +83,32 @@ customElements.whenDefined("menulist").t
       };
 
       MailServices.ab.addAddressBookListener(this.addressBookListener, Ci.nsIAbListener.all);
       window.addEventListener("unload", () => {
         MailServices.ab.removeAddressBookListener(this.addressBookListener);
       }, { once: true });
     }
 
+    /**
+     * Returns the address book type based on the remoteonly attribute
+     * of the menulist.
+     *
+     * "URI"         Local Address Book
+     * "dirPrefId"   Remote LDAP Directory
+     */
+    get _type() {
+      return this.getAttribute("remoteonly") ? "dirPrefId" : "URI";
+    }
+
     disconnectedCallback() {
       super.disconnectedCallback();
 
       MailServices.ab.removeAddressBookListener(this.addressBookListener);
+      this._teardown();
     }
 
     _rebuild() {
       // Init the address book cache.
       this._directories.length = 0;
       let directories = MailServices.ab.directories;
 
       while (directories && directories.hasMoreElements()) {
@@ -138,23 +149,24 @@ customElements.whenDefined("menulist").t
         this._directories.unshift(null);
         let listItem = this.appendItem(allABLabel, "moz-abdirectory://?");
         listItem.setAttribute("class", "menuitem-iconic abMenuItem");
         listItem.setAttribute("AddrBook", "true");
         listItem.setAttribute("IsAllAB", "true");
       }
 
       // Now create menuitems for all displayed directories.
+      let type = this._type;
       for (let ab of this._directories) {
         if (!ab) {
           // Skip the empty members added above.
           continue;
         }
 
-        let listItem = this.appendItem(ab.dirName, ab.URI);
+        let listItem = this.appendItem(ab.dirName, ab[type]);
         listItem.setAttribute("class", "menuitem-iconic abMenuItem");
 
         // Style the items by type.
         if (ab.isMailList) {
           listItem.setAttribute("MailList", "true");
         } else {
           listItem.setAttribute("AddrBook", "true");
         }
@@ -164,18 +176,22 @@ customElements.whenDefined("menulist").t
         }
         if (ab.isSecure) {
           listItem.setAttribute("IsSecure", "true");
         }
       }
 
       // Attempt to select the persisted or otherwise first directory.
       this.selectedIndex = this._directories.findIndex((d) => {
-        return d && d.URI == this._value;
+        return d && d[type] == this.value;
       });
+
+      if (!this.selectedItem && this.menupopup.hasChildNodes()) {
+        this.selectedIndex = 0;
+      }
     }
 
     _teardown() {
       // Empty out anything in the list.
       while (this.menupopup && this.menupopup.hasChildNodes()) {
         this.menupopup.lastChild.remove();
       }
     }
--- a/mail/components/preferences/compose.inc.xul
+++ b/mail/components/preferences/compose.inc.xul
@@ -156,17 +156,16 @@
               <checkbox id="autocompleteLDAP" label="&directories.label;"
                         preference="ldap_2.autoComplete.useDirectory"
                         accesskey="&directories.accesskey;"/>
               <menulist is="menulist-addrbooks" id="directoriesList"
                         aria-labelledby="autocompleteLDAP"
                         preference="ldap_2.autoComplete.directoryServer"
                         none="&directoriesNone.label;"
                         remoteonly="true"
-                        value="dirPrefId"
                         flex="1"/>
               <button id="editButton" label="&editDirectories.label;"
                       oncommand="gComposePane.editDirectories();"
                       preference="pref.ldap.disable_button.edit_directories"
                       accesskey="&editDirectories.accesskey;"/>
             </hbox>
           </groupbox>
 
--- a/mailnews/base/prefs/content/am-addressing.inc.xul
+++ b/mailnews/base/prefs/content/am-addressing.inc.xul
@@ -93,17 +93,16 @@
           <radio value="false" label="&useGlobal.label;"
                  accesskey="&useGlobal.accesskey;"/>
           <radio value="true" id="directories" label="&directories.label;"
                  accesskey="&directories.accesskey;"/>
           <hbox class="indent">
             <menulist is="menulist-addrbooks" id="identity.directoryServer"
                       none="&directoriesNone.label;"
                       remoteonly="true"
-                      value="dirPrefId"
                       wsm_persist="true"
                       preftype="string"
                       prefstring="mail.identity.%identitykey%.directoryServer"
                       style="min-width: 16em;"
                       aria-labelledby="directories"
                       flex="1"/>
             <button id="editButton" label="&editDirectories.label;"
                     accesskey="&editDirectories.accesskey;"