cleanup better when switching between AND/OR modes of fulltext search gloda-facet
authorAndrew Sutherland <asutherland@asutherland.org>
Tue, 08 Sep 2009 23:05:47 -0700
branchgloda-facet
changeset 3715 62adfc2a96cc5f9db6bb15bb33c41891231ac64c
parent 3714 be1696d2729ba85e760122f04a1d4acdfc5a15f9
child 3716 3686cc368374a3c346777a74defc677b78810a0f
child 3718 0abb2352aa0c200d95bff9eab65be2b407a5af46
push idunknown
push userunknown
push dateunknown
cleanup better when switching between AND/OR modes of fulltext search
mail/base/content/glodaFacetView.js
--- a/mail/base/content/glodaFacetView.js
+++ b/mail/base/content/glodaFacetView.js
@@ -374,16 +374,17 @@ var FacetContext = {
     if (this.searcher)
       queryExplanation.setFulltext(this.searcher);
     else
       queryExplanation.setQuery(this.collection.query);
     // we like to sort them so should clone the list
     this.faceters = this.facetDriver.faceters.concat();
 
     this.everFaceted = false;
+    this._activeConstraints = {};
     try {
       if (this.searcher) {
         this._sortBy = '-dascore';
         this._relevantSortedItems = this._collection.items.concat();
         this._dateSortedItems = this._relevantSortedItems.concat().sort(function(a,b) b.date-a.date);
         this._activeSet = this._relevantSortedItems;
       } else {
         this._sortBy = '-date';
@@ -416,16 +417,28 @@ var FacetContext = {
    *  impacted by layout concerns (since we want to avoid scrolling).
    */
   planLayout: function() {
     // XXX arbitrary!
     this.maxDisplayRows = 8;
     this.maxMessagesToShow = 10;
   },
 
+  /**
+   * Clean up the UI in preparation for a new query to come in.
+   */
+  _resetUI: function() {
+    for each (let [, faceter] in Iterator(this.faceters)) {
+      if (faceter.xblNode && !faceter.xblNode.explicit)
+        faceter.xblNode.parentNode.removeChild(faceter.xblNode);
+      faceter.xblNode = null;
+      faceter.constraint = null;
+    }
+  },
+
   _groupCountComparator: function(a, b) {
     return b.groupCount - a.groupCount;
   },
   /**
    * Tells the UI about all the facets when notified by the |facetDriver| when
    *  it is done faceting everything.
    */
   facetingCompleted: function() {
@@ -443,17 +456,17 @@ var FacetContext = {
         if (explicitBinding) {
           explicitBinding.explicit = true;
           explicitBinding.faceter = faceter;
           explicitBinding.attrDef = faceter.attrDef;
           explicitBinding.nounDef = faceter.attrDef.objectNounDef;
           explicitBinding.orderedGroups = faceter.orderedGroups;
           // explicit booleans should always be displayed for consistency
           if (faceter.groupCount >= 1 ||
-              faceter.type == "boolean") {
+              (explicitBinding.getAttribute("type").indexOf("boolean") != -1)) {
             explicitBinding.build(true);
             explicitBinding.removeAttribute("uninitialized");
           }
           faceter.xblNode = explicitBinding;
           continue;
         }
 
         // ignore facets that do not vary!
@@ -553,17 +566,17 @@ var FacetContext = {
     // reuse hover facet to null everyone out
     this.hoverFacet(null, null, null, null);
   },
 
   /**
    * Maps attribute names to their corresponding |ActiveConstraint|, if they
    *  have one.
    */
-  _activeConstraints: {},
+  _activeConstraints: null,
   /**
    * Called by facet bindings when the user does some clicking and wants to
    *  impose a new constraint.
    *
    * @param aFaceter
    * @param aAttrDef
    * @param {Boolean} aInclusive
    * @param aGroupValues
@@ -661,16 +674,17 @@ var FacetContext = {
       items = constraint.sieve(items);
     }
 
     return items;
   },
 
   toggleFulltextCriteria: function() {
     this.tab.searcher.andTerms = !this.tab.searcher.andTerms;
+    this._resetUI();
     this.collection = this.tab.searcher.getCollection(this);
   },
 
   /**
    * Show the active message set in a glodaList tab, closing the current tab.
    */
   showActiveSetInTab: function() {
     let tabmail = this.rootWin.document.getElementById("tabmail");