@@ -53,6 +53,9 @@ issueList.FilterView = Backbone.View.extend({
53
53
initialize : function ( ) {
54
54
//TODO: move this model out into its own file once we have
55
55
//actual data for issues count
56
+
57
+ issueList . events . on ( 'filter:activate' , _ . bind ( this . toggleFilter , this ) ) ;
58
+
56
59
var options = [
57
60
{ title : "View all open issues" , params : "" } ,
58
61
{ title : "View all issues" , params : "filter=all" }
@@ -90,7 +93,15 @@ issueList.FilterView = Backbone.View.extend({
90
93
return this ;
91
94
} ,
92
95
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
+
94
105
btn . toggleClass ( 'is-active' )
95
106
. siblings ( ) . removeClass ( 'is-active' ) ;
96
107
@@ -229,14 +240,32 @@ issueList.IssueView = Backbone.View.extend({
229
240
} ,
230
241
initialize : function ( ) {
231
242
this . issues = new issueList . IssueCollection ( ) ;
232
- this . fetchAndRenderIssues ( ) ;
243
+ // check to see if we should pre-filter results
244
+ this . checkParams ( ) ;
233
245
234
246
// set up event listeners.
235
247
issueList . events . on ( 'issues:update' , _ . bind ( this . updateIssues , this ) ) ;
236
248
issueList . events . on ( 'paginate:next' , _ . bind ( this . requestNextPage , this ) ) ;
237
249
issueList . events . on ( 'paginate:previous' , _ . bind ( this . requestPreviousPage , this ) ) ;
238
250
} ,
239
251
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 = / \? ( u n t r i a g e d | n e e d s d i a g n o s i s | c o n t a c t r e a d y | s i t e w a i t | c l o s e d ) = 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
+ } ,
240
269
fetchAndRenderIssues : function ( ) {
241
270
var headers = { headers : { 'Accept' : 'application/json' } } ;
242
271
this . issues . fetch ( headers ) . success ( _ . bind ( function ( ) {
0 commit comments