Bug 1636500 - update glodaFacet.js to use sIStringBundle methods. r=khushil
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Sat, 09 May 2020 13:54:24 +0300
changeset 39102 029c3accdb5d2d143b33ee5ce8a0b5ceaa331261
parent 39101 fed192723bc2c0762edc482a62936bc5b8f16dbf
child 39103 844fa53f6c01096df843206443bff07dae12ec05
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewerskhushil
bugs1636500
Bug 1636500 - update glodaFacet.js to use sIStringBundle methods. r=khushil
mail/base/content/glodaFacet.js
--- a/mail/base/content/glodaFacet.js
+++ b/mail/base/content/glodaFacet.js
@@ -1,21 +1,37 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* global HTMLElement, DateFacetVis, FacetContext, glodaFacetStrings, FacetUtils, PluralForm */
-/* global logException, Gloda */
+/* global DateFacetVis, FacetContext */
 
 // Wrap in a block to prevent leaking to window scope.
 {
+  const { Services } = ChromeUtils.import(
+    "resource://gre/modules/Services.jsm"
+  );
   const { MailServices } = ChromeUtils.import(
     "resource:///modules/MailServices.jsm"
   );
   const { TagUtils } = ChromeUtils.import("resource:///modules/TagUtils.jsm");
+  const { FacetUtils } = ChromeUtils.import(
+    "resource:///modules/gloda/Facet.jsm"
+  );
+  const { PluralForm } = ChromeUtils.import(
+    "resource://gre/modules/PluralForm.jsm"
+  );
+  const { Gloda } = ChromeUtils.import("resource:///modules/gloda/Gloda.jsm");
+  const { logException } = ChromeUtils.import(
+    "resource:///modules/ErrUtils.jsm"
+  );
+
+  var glodaFacetStrings = Services.strings.createBundle(
+    "chrome://messenger/locale/glodaFacetView.properties"
+  );
 
   class MozFacetDate extends HTMLElement {
     get build() {
       return this.buildFunc;
     }
 
     get brushItems() {
       return items => this.vis.hoverItems(items);
@@ -107,25 +123,25 @@
       this.toggleTimeline.appendChild(this.toggleText);
 
       const sortDiv = document.createElement("div");
       sortDiv.classList.add("results-message-sort-bar");
 
       this.sortSelect = document.createElement("select");
 
       let revelanceItem = document.createElement("option");
-      revelanceItem.textContent = glodaFacetStrings.get(
+      revelanceItem.textContent = glodaFacetStrings.GetStringFromName(
         "glodaFacetView.results.message.sort.relevance2"
       );
       revelanceItem.setAttribute("value", "-dascore");
       revelanceItem.setAttribute("selected", true);
       this.sortSelect.appendChild(revelanceItem);
 
       let dateItem = document.createElement("option");
-      dateItem.textContent = glodaFacetStrings.get(
+      dateItem.textContent = glodaFacetStrings.GetStringFromName(
         "glodaFacetView.results.message.sort.date2"
       );
       dateItem.setAttribute("value", "-date");
       this.sortSelect.appendChild(dateItem);
 
       this.messagesNode = document.createElement("div");
       this.messagesNode.classList.add("messages");
 
@@ -135,23 +151,23 @@
 
       sortDiv.appendChild(this.sortSelect);
 
       this.appendChild(header);
       this.appendChild(this.messagesNode);
     }
 
     setMessages(messages) {
-      let topMessagesPluralFormat = glodaFacetStrings.get(
+      let topMessagesPluralFormat = glodaFacetStrings.GetStringFromName(
         "glodaFacetView.results.header.countLabel.NMessages"
       );
-      let outOfPluralFormat = glodaFacetStrings.get(
+      let outOfPluralFormat = glodaFacetStrings.GetStringFromName(
         "glodaFacetView.results.header.countLabel.ofN"
       );
-      let groupingFormat = glodaFacetStrings.get(
+      let groupingFormat = glodaFacetStrings.GetStringFromName(
         "glodaFacetView.results.header.countLabel.grouping"
       );
 
       let displayCount = messages.length;
       let totalCount = FacetContext.activeSet.length;
 
       // set the count so CSS selectors can know what the results look like
       this.setAttribute("state", totalCount <= 0 ? "empty" : "some");
@@ -164,17 +180,17 @@
         "#1",
         totalCount.toLocaleString()
       );
 
       this.countNode.textContent = groupingFormat
         .replace("#1", topMessagesStr)
         .replace("#2", outOfStr);
 
-      this.toggleText.textContent = glodaFacetStrings.get(
+      this.toggleText.textContent = glodaFacetStrings.GetStringFromName(
         "glodaFacetView.results.message.timeline.label"
       );
 
       this.sortSelect.addEventListener("change", () => {
         FacetContext.sortBy = this.sortSelect.value;
       });
 
       while (this.messagesNode.hasChildNodes()) {
@@ -446,17 +462,17 @@
         return;
       }
 
       while (this.filterNode.hasChildNodes()) {
         this.filterNode.lastChild.remove();
       }
 
       let allNode = document.createElement("option");
-      allNode.textContent = glodaFacetStrings.get(
+      allNode.textContent = glodaFacetStrings.GetStringFromName(
         "glodaFacetView.facets.filter." +
           this.attrDef.attributeName +
           ".allLabel"
       );
       allNode.setAttribute("value", "all");
       if (this.selectedValue == "all") {
         allNode.setAttribute("selected", "selected");
       }
@@ -638,39 +654,39 @@
       // -- Header Building
       this.nameNode.textContent = this.facetDef.strings.facetNameLabel;
 
       // - include
       // setup the include label
       if ("includeLabel" in this.facetDef.strings) {
         this.includeLabel.textContent = this.facetDef.strings.includeLabel;
       } else {
-        this.includeLabel.textContent = glodaFacetStrings.get(
+        this.includeLabel.textContent = glodaFacetStrings.GetStringFromName(
           "glodaFacetView.facets.included.fallbackLabel"
         );
       }
       this.includeLabel.setAttribute("state", "empty");
 
       // - exclude
       // setup the exclude label
       if ("excludeLabel" in this.facetDef.strings) {
         this.excludeLabel.textContent = this.facetDef.strings.excludeLabel;
       } else {
-        this.excludeLabel.textContent = glodaFacetStrings.get(
+        this.excludeLabel.textContent = glodaFacetStrings.GetStringFromName(
           "glodaFacetView.facets.excluded.fallbackLabel"
         );
       }
       this.excludeLabel.setAttribute("state", "empty");
 
       // - remainder
       // setup the remainder label
       if ("remainderLabel" in this.facetDef.strings) {
         this.remainderLabel.textContent = this.facetDef.strings.remainderLabel;
       } else {
-        this.remainderLabel.textContent = glodaFacetStrings.get(
+        this.remainderLabel.textContent = glodaFacetStrings.GetStringFromName(
           "glodaFacetView.facets.remainder.fallbackLabel"
         );
       }
 
       // -- House-cleaning
       // -- All/Top mode decision
       this.modes = ["all"];
       if (this.maxDisplayRows >= this.orderedGroups.length) {
@@ -683,17 +699,19 @@
           this.attrDef,
           this.orderedGroups,
           this.maxDisplayRows
         );
         // setup the more button string
         let groupCount = this.orderedGroups.length;
         this.moreButton.textContent = PluralForm.get(
           groupCount,
-          glodaFacetStrings.get("glodaFacetView.facets.mode.top.listAllLabel")
+          glodaFacetStrings.GetStringFromName(
+            "glodaFacetView.facets.mode.top.listAllLabel"
+          )
         ).replace("#1", groupCount);
       }
 
       // -- Row Building
       this.buildRows();
     }
 
     changeMode(newMode) {
@@ -787,17 +805,17 @@
         countSpan.textContent = groupItems.length.toLocaleString();
         li.appendChild(countSpan);
 
         let label = document.createElement("span");
         label.setAttribute("class", "bar-link");
 
         // The null value is a special indicator for 'none'
         if (groupValue == null) {
-          label.textContent = glodaFacetStrings.get(
+          label.textContent = glodaFacetStrings.GetStringFromName(
             "glodaFacetView.facets.noneLabel"
           );
         } else {
           // Otherwise stringify the group object
           let labelStr;
           if (ambiguousKeyValues) {
             labelStr = nounDef.userVisibleString(groupValue, false);
             if (ambiguousKeyValues[labelStr]) {
@@ -1233,17 +1251,17 @@
       this.appendChild(parentDiv);
     }
 
     _getLabel(facetDef, facetValue, groupValue, stringName) {
       let labelFormat;
       if (stringName in facetDef.strings) {
         labelFormat = facetDef.strings[stringName];
       } else {
-        labelFormat = glodaFacetStrings.get(
+        labelFormat = glodaFacetStrings.GetStringFromName(
           `glodaFacetView.facets.${stringName}.fallbackLabel`
         );
       }
 
       if (!labelFormat.includes("#1")) {
         return labelFormat;
       }
 
@@ -1525,44 +1543,44 @@
       subject.onkeypress = event => {
         if (Event.keyCode == event.DOM_VK_RETURN) {
           FacetContext.showConversationInTab(this, event.shiftKey);
         }
       };
 
       // -- Content Poking
       if (message.subject.trim() == "") {
-        subject.textContent = glodaFacetStrings.get(
+        subject.textContent = glodaFacetStrings.GetStringFromName(
           "glodaFacetView.result.message.noSubject"
         );
       } else {
         subject.textContent = message.subject;
       }
       let authorNode = this.author;
       authorNode.setAttribute("title", message.from.value);
       authorNode.textContent = message.from.contact.name;
       let toNode = this.to;
-      toNode.textContent = glodaFacetStrings.get(
+      toNode.textContent = glodaFacetStrings.GetStringFromName(
         "glodaFacetView.result.message.toLabel"
       );
 
       // this.author.textContent = ;
       let { makeFriendlyDateAgo } = ChromeUtils.import(
         "resource:///modules/TemplateUtils.jsm"
       );
       this.date.textContent = makeFriendlyDateAgo(message.date);
 
       // - Recipients
       try {
         let recipientsNode = this.recipients;
         if (message.recipients) {
           let recipientCount = 0;
           const MAX_RECIPIENTS = 3;
           let totalRecipientCount = message.recipients.length;
-          let recipientSeparator = glodaFacetStrings.get(
+          let recipientSeparator = glodaFacetStrings.GetStringFromName(
             "glodaFacetView.results.message.recipientSeparator"
           );
           for (let index in message.recipients) {
             let recipNode = document.createElement("span");
             recipNode.setAttribute("class", "message-recipient");
             recipNode.textContent = message.recipients[index].contact.name;
             recipientsNode.appendChild(recipNode);
             recipientCount++;
@@ -1579,17 +1597,19 @@
           }
           if (totalRecipientCount > MAX_RECIPIENTS) {
             let nOthers = totalRecipientCount - recipientCount;
             let andNOthers = document.createElement("span");
             andNOthers.setAttribute("class", "message-recipients-andothers");
 
             let andOthersLabel = PluralForm.get(
               nOthers,
-              glodaFacetStrings.get("glodaFacetView.results.message.andOthers")
+              glodaFacetStrings.GetStringFromName(
+                "glodaFacetView.results.message.andOthers"
+              )
             ).replace("#1", nOthers);
 
             andNOthers.textContent = andOthersLabel;
             recipientsNode.appendChild(andNOthers);
           }
         }
       } catch (e) {
         logException(e);