Merge "Add parameter to API modules to apply change tags to log entries"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / mw.rcfilters.Controller.js
1 ( function ( mw ) {
2 /**
3 * Controller for the filters in Recent Changes
4 *
5 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
6 */
7 mw.rcfilters.Controller = function MwRcfiltersController( model ) {
8 this.model = model;
9
10 // TODO: When we are ready, update the URL when a filter is updated
11 // this.model.connect( this, { itemUpdate: 'updateURL' } );
12 };
13
14 /* Initialization */
15 OO.initClass( mw.rcfilters.Controller );
16
17 /**
18 * Initialize the filter and parameter states
19 */
20 mw.rcfilters.Controller.prototype.initialize = function () {
21 var uri = new mw.Uri();
22
23 this.model.updateFilters(
24 // Translate the url params to filter select states
25 this.model.getFiltersFromParameters( uri.query )
26 );
27 };
28
29 /**
30 * Update the state of a filter
31 *
32 * @param {string} filterName Filter name
33 * @param {boolean} isSelected Filter selected state
34 */
35 mw.rcfilters.Controller.prototype.updateFilter = function ( filterName, isSelected ) {
36 var obj = {};
37
38 obj[ filterName ] = isSelected;
39 this.model.updateFilters( obj );
40 };
41
42 /**
43 * Update the URL of the page to reflect current filters
44 */
45 mw.rcfilters.Controller.prototype.updateURL = function () {
46 var uri = new mw.Uri();
47
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() );
53
54 // Update the URL itself
55 window.history.pushState( { tag: 'rcfilters' }, document.title, uri.toString() );
56 };
57 }( mediaWiki ) );