]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1517429 - Search: Filter out by default Product containing "Graveyard"
authorKohei Yoshino <kohei.yoshino@gmail.com>
Tue, 22 Jan 2019 17:28:42 +0000 (12:28 -0500)
committerGitHub <noreply@github.com>
Tue, 22 Jan 2019 17:28:42 +0000 (12:28 -0500)
extensions/BMO/template/en/default/hook/global/header-start.html.tmpl
extensions/BMO/web/js/advanced-search.js [new file with mode: 0644]

index a9d3146f1139f13cb686f9bd97ada10d8243c57e..d02eff10b71b42ab3a32b8a8020899e743d8aec1 100644 (file)
   [% javascript_urls.push('extensions/BMO/web/js/sorttable.js') %]
 [% END %]
 
+[% IF template.name == 'search/search-advanced.html.tmpl' %]
+  [% javascript_urls.push('extensions/BMO/web/js/advanced-search.js') %]
+[% END %]
+
 [% IF !bodyclasses %]
   [% bodyclasses = [] %]
 [% END %]
diff --git a/extensions/BMO/web/js/advanced-search.js b/extensions/BMO/web/js/advanced-search.js
new file mode 100644 (file)
index 0000000..3e56624
--- /dev/null
@@ -0,0 +1,47 @@
+/* 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/.
+ *
+ * This Source Code Form is "Incompatible With Secondary Licenses", as
+ * defined by the Mozilla Public License, v. 2.0. */
+
+/**
+ * Reference or define the Bugzilla app namespace.
+ * @namespace
+ */
+var Bugzilla = Bugzilla || {}; // eslint-disable-line no-var
+
+/**
+ * Implement Advanced Search page features.
+ */
+Bugzilla.AdvancedSearch = class AdvancedSearch {
+  /**
+   * Initialize a new AdvancedSearch instance.
+   */
+  constructor() {
+    this.params = (new URL(document.location)).searchParams;
+    this.$classifications = document.querySelector('#classification');
+
+    this.hide_graveyard();
+  }
+
+  /**
+   * Hide Graveyard products by selecting classifications other than Graveyard.
+   */
+  hide_graveyard() {
+    // Give up if URL params contain certain fields
+    if (this.params.has('classification') || this.params.has('product') || this.params.has('component')) {
+      return;
+    }
+
+    // Select non-Graveyard classifications
+    for (const $option of this.$classifications.options) {
+      $option.selected = $option.value !== 'Graveyard';
+    }
+
+    // Fire an event to update the Product and Component lists
+    this.$classifications.dispatchEvent(new Event('change'));
+  }
+};
+
+window.addEventListener('DOMContentLoaded', () => new Bugzilla.AdvancedSearch(), { once: true });