Merge "Don't remove border for floatright and floatleft"
[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 // TODO: When we are ready, update the URL when a filter is updated
10 // this.model.connect( this, { itemUpdate: 'updateURL' } );
11 };
12
13 /* Initialization */
14 OO.initClass( mw.rcfilters.Controller );
15
16 /**
17 * Initialize the filter and parameter states
18 */
19 mw.rcfilters.Controller.prototype.initialize = function () {
20 var uri = new mw.Uri();
21
22 // Give the model a full parameter state from which to
23 // update the filters
24 this.model.updateFilters(
25 // Translate the url params to filter select states
26 this.model.getFiltersFromParameters( uri.query )
27 );
28 };
29
30 /**
31 * Reset to default filters
32 */
33 mw.rcfilters.Controller.prototype.resetToDefaults = function () {
34 this.model.setFiltersToDefaults();
35 };
36
37 /**
38 * Empty all selected filters
39 */
40 mw.rcfilters.Controller.prototype.emptyFilters = function () {
41 this.model.emptyAllFilters();
42 };
43
44 /**
45 * Update the state of a filter
46 *
47 * @param {string} filterName Filter name
48 * @param {boolean} isSelected Filter selected state
49 */
50 mw.rcfilters.Controller.prototype.updateFilter = function ( filterName, isSelected ) {
51 var obj = {};
52
53 obj[ filterName ] = isSelected;
54 this.model.updateFilters( obj );
55 };
56
57 /**
58 * Update the URL of the page to reflect current filters
59 */
60 mw.rcfilters.Controller.prototype.updateURL = function () {
61 var uri = new mw.Uri();
62
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() );
68
69 // Update the URL itself
70 window.history.pushState( { tag: 'rcfilters' }, document.title, uri.toString() );
71 };
72 }( mediaWiki ) );