Skip to content

Commit 5bca1ea

Browse files
author
Mike Taylor
committed
Issue #340 - Check for filter params on page load.
1 parent 495d2ef commit 5bca1ea

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

webcompat/static/js/lib/issue-list.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ issueList.FilterView = Backbone.View.extend({
5353
initialize: function() {
5454
//TODO: move this model out into its own file once we have
5555
//actual data for issues count
56+
57+
issueList.events.on('filter:activate', _.bind(this.toggleFilter, this));
58+
5659
var options = [
5760
{title: "View all open issues", params: ""},
5861
{title: "View all issues", params: "filter=all"}
@@ -90,7 +93,15 @@ issueList.FilterView = Backbone.View.extend({
9093
return this;
9194
},
9295
toggleFilter: function(e) {
93-
var btn = $(e.target);
96+
var btn;
97+
// Stringy e comes from triggered filter:activate event
98+
if (typeof e === "string") {
99+
btn = $('[data-filter=' + e + ']');
100+
} else {
101+
// We get a regular event object from click events.
102+
btn = $(e.target);
103+
}
104+
94105
btn.toggleClass('is-active')
95106
.siblings().removeClass('is-active');
96107

@@ -229,14 +240,32 @@ issueList.IssueView = Backbone.View.extend({
229240
},
230241
initialize: function() {
231242
this.issues = new issueList.IssueCollection();
232-
this.fetchAndRenderIssues();
243+
// check to see if we should pre-filter results
244+
this.checkParams();
233245

234246
// set up event listeners.
235247
issueList.events.on('issues:update', _.bind(this.updateIssues, this));
236248
issueList.events.on('paginate:next', _.bind(this.requestNextPage, this));
237249
issueList.events.on('paginate:previous', _.bind(this.requestPreviousPage, this));
238250
},
239251
template: _.template($('#issuelist-issue-tmpl').html()),
252+
checkParams: function() {
253+
// Assumes a URI like: /?untriaged=1 and activates the untriaged filter,
254+
// for example.
255+
var category;
256+
var filterRegex = /\?(untriaged|needsdiagnosis|contactready|sitewait|closed)=1/;
257+
if (category = window.location.search.match(filterRegex)) {
258+
// If there was a match, load the relevant results and fire an event
259+
// to notify the button to activate.
260+
this.updateIssues(category[1]);
261+
_.delay(function() {
262+
issueList.events.trigger('filter:activate', category[1]);
263+
}, 0);
264+
} else {
265+
// Otherwise, load default issues.
266+
this.fetchAndRenderIssues();
267+
}
268+
},
240269
fetchAndRenderIssues: function() {
241270
var headers = {headers: {'Accept': 'application/json'}};
242271
this.issues.fetch(headers).success(_.bind(function() {

0 commit comments

Comments
 (0)