3 * Controller for the filters in Recent Changes
5 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
7 mw
.rcfilters
.Controller
= function MwRcfiltersController( model
) {
9 // TODO: When we are ready, update the URL when a filter is updated
10 // this.model.connect( this, { itemUpdate: 'updateURL' } );
14 OO
.initClass( mw
.rcfilters
.Controller
);
17 * Initialize the filter and parameter states
19 mw
.rcfilters
.Controller
.prototype.initialize = function () {
20 var uri
= new mw
.Uri();
22 // Give the model a full parameter state from which to
24 this.model
.updateFilters(
25 // Translate the url params to filter select states
26 this.model
.getFiltersFromParameters( uri
.query
)
31 * Reset to default filters
33 mw
.rcfilters
.Controller
.prototype.resetToDefaults = function () {
34 this.model
.setFiltersToDefaults();
38 * Empty all selected filters
40 mw
.rcfilters
.Controller
.prototype.emptyFilters = function () {
41 this.model
.emptyAllFilters();
45 * Update the state of a filter
47 * @param {string} filterName Filter name
48 * @param {boolean} isSelected Filter selected state
50 mw
.rcfilters
.Controller
.prototype.updateFilter = function ( filterName
, isSelected
) {
53 obj
[ filterName
] = isSelected
;
54 this.model
.updateFilters( obj
);
58 * Update the URL of the page to reflect current filters
60 mw
.rcfilters
.Controller
.prototype.updateURL = function () {
61 var uri
= new mw
.Uri();
63 // Add to existing queries in URL
64 // TODO: Clean up the list of filters; perhaps 'falsy' filters
65 // shouldn't appear at all? Or compare to existing query string
66 // and see if current state of a specific filter is needed?
67 uri
.extend( this.model
.getParametersFromFilters() );
69 // Update the URL itself
70 window
.history
.pushState( { tag
: 'rcfilters' }, document
.title
, uri
.toString() );