@@ -35,8 +35,12 @@ issueList.DropdownView = Backbone.View.extend({
35
35
var option = $ ( e . target ) ;
36
36
option . addClass ( 'is-active' )
37
37
. siblings ( ) . removeClass ( 'is-active' ) ;
38
+
38
39
// TODO: persist in localStorage for page refreshes?
39
40
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' ) } ) ;
40
44
e . preventDefault ( ) ;
41
45
} ,
42
46
updateDropdownTitle : function ( optionElm ) {
@@ -247,6 +251,7 @@ issueList.IssueView = Backbone.View.extend({
247
251
issueList . events . on ( 'issues:update' , _ . bind ( this . updateIssues , this ) ) ;
248
252
issueList . events . on ( 'paginate:next' , _ . bind ( this . requestNextPage , this ) ) ;
249
253
issueList . events . on ( 'paginate:previous' , _ . bind ( this . requestPreviousPage , this ) ) ;
254
+ wcEvents . on ( 'dropdown:change' , _ . bind ( this . updateModelParams , this ) ) ;
250
255
} ,
251
256
template : _ . template ( $ ( '#issuelist-issue-tmpl' ) . html ( ) ) ,
252
257
checkParams : function ( ) {
@@ -368,6 +373,18 @@ issueList.IssueView = Backbone.View.extend({
368
373
this . issues . url = '/api/issues?page=1' ;
369
374
}
370
375
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 ( ) ;
371
388
}
372
389
} ) ;
373
390
0 commit comments