3 * Controller for the filters in Recent Changes
5 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
7 mw.rcfilters.Controller = function MwRcfiltersController( model ) {
10 // TODO: When we are ready, update the URL when a filter is updated
11 // this.model.connect( this, { itemUpdate: 'updateURL' } );
15 OO.initClass( mw.rcfilters.Controller );
18 * Initialize the filter and parameter states
20 mw.rcfilters.Controller.prototype.initialize = function () {
21 var uri = new mw.Uri();
23 this.model.updateFilters(
24 // Translate the url params to filter select states
25 this.model.getFiltersFromParameters( uri.query )
30 * Update the state of a filter
32 * @param {string} filterName Filter name
33 * @param {boolean} isSelected Filter selected state
35 mw.rcfilters.Controller.prototype.updateFilter = function ( filterName, isSelected ) {
38 obj[ filterName ] = isSelected;
39 this.model.updateFilters( obj );
43 * Update the URL of the page to reflect current filters
45 mw.rcfilters.Controller.prototype.updateURL = function () {
46 var uri = new mw.Uri();
48 // Add to existing queries in URL
49 // TODO: Clean up the list of filters; perhaps 'falsy' filters
50 // shouldn't appear at all? Or compare to existing query string
51 // and see if current state of a specific filter is needed?
52 uri.extend( this.model.getParametersFromFilters() );
54 // Update the URL itself
55 window.history.pushState( { tag: 'rcfilters' }, document.title, uri.toString() );