Skip to content

Commit 4acb8a3

Browse files
author
Mike Taylor
committed
Issue #372 - Add method to update model params from dropdown change.
1 parent ec354a9 commit 4acb8a3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

+17
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ issueList.DropdownView = Backbone.View.extend({
3535
var option = $(e.target);
3636
option.addClass('is-active')
3737
.siblings().removeClass('is-active');
38+
3839
// TODO: persist in localStorage for page refreshes?
3940
this.updateDropdownTitle(option);
41+
42+
// fire an event so other views can react to dropdown changes
43+
wcEvents.trigger('dropdown:change', {params: option.data('params')});
4044
e.preventDefault();
4145
},
4246
updateDropdownTitle: function(optionElm) {
@@ -247,6 +251,7 @@ issueList.IssueView = Backbone.View.extend({
247251
issueList.events.on('issues:update', _.bind(this.updateIssues, this));
248252
issueList.events.on('paginate:next', _.bind(this.requestNextPage, this));
249253
issueList.events.on('paginate:previous', _.bind(this.requestPreviousPage, this));
254+
wcEvents.on('dropdown:change', _.bind(this.updateModelParams, this));
250255
},
251256
template: _.template($('#issuelist-issue-tmpl').html()),
252257
checkParams: function() {
@@ -368,6 +373,18 @@ issueList.IssueView = Backbone.View.extend({
368373
this.issues.url = '/api/issues?page=1';
369374
}
370375
this.fetchAndRenderIssues();
376+
},
377+
updateModelParams: function(data) {
378+
var modelUrl = this.issues.url.split('?');
379+
var modelPath = modelUrl[0];
380+
var modelParams = modelUrl[1];
381+
// merge old params with passed in param data
382+
// $.extend will update existing object keys, and add new ones
383+
var newParams = $.extend($.deparam(modelParams), $.deparam(data.params));
384+
385+
// construct new model URL and re-request issues
386+
this.issues.url = modelPath + '?' + $.param(newParams);
387+
this.fetchAndRenderIssues();
371388
}
372389
});
373390

0 commit comments

Comments
 (0)