3373ee00ca6136fc363de5c0a0068c721a104c00
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.FilterWrapperWidget.js
1 ( function ( mw ) {
2 /**
3 * List displaying all filter groups
4 *
5 * @extends OO.ui.Widget
6 * @mixins OO.ui.mixin.PendingElement
7 *
8 * @constructor
9 * @param {mw.rcfilters.Controller} controller Controller
10 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
11 * @param {mw.rcfilters.dm.SavedQueriesModel} savedQueriesModel Saved queries model
12 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListModel
13 * @param {Object} [config] Configuration object
14 * @cfg {Object} [filters] A definition of the filter groups in this list
15 * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
16 */
17 mw.rcfilters.ui.FilterWrapperWidget = function MwRcfiltersUiFilterWrapperWidget(
18 controller, model, savedQueriesModel, changesListModel, config
19 ) {
20 var $bottom;
21 config = config || {};
22
23 // Parent
24 mw.rcfilters.ui.FilterWrapperWidget.parent.call( this, config );
25 // Mixin constructors
26 OO.ui.mixin.PendingElement.call( this, config );
27
28 this.controller = controller;
29 this.model = model;
30 this.queriesModel = savedQueriesModel;
31 this.changesListModel = changesListModel;
32 this.$overlay = config.$overlay || this.$element;
33
34 this.filterTagWidget = new mw.rcfilters.ui.FilterTagMultiselectWidget(
35 this.controller,
36 this.model,
37 this.queriesModel,
38 { $overlay: this.$overlay }
39 );
40
41 this.liveUpdateButton = new mw.rcfilters.ui.LiveUpdateButtonWidget(
42 this.controller,
43 this.changesListModel
44 );
45
46 this.numChangesWidget = new mw.rcfilters.ui.ChangesLimitAndDateButtonWidget(
47 this.controller,
48 this.model,
49 {
50 $overlay: this.$overlay
51 }
52 );
53
54 this.showNewChangesLink = new OO.ui.ButtonWidget( {
55 icon: 'reload',
56 framed: false,
57 label: mw.msg( 'rcfilters-show-new-changes' ),
58 flags: [ 'progressive' ]
59 } );
60
61 // Initialize
62 this.$top = $( '<div>' )
63 .addClass( 'mw-rcfilters-ui-filterWrapperWidget-top' );
64
65 $bottom = $( '<div>' )
66 .addClass( 'mw-rcfilters-ui-filterWrapperWidget-bottom' )
67 .append(
68 this.showNewChangesLink.$element,
69 this.numChangesWidget.$element
70 );
71
72 if ( mw.rcfilters.featureFlags.liveUpdate ) {
73 $bottom.prepend( this.liveUpdateButton.$element );
74 }
75
76 // Events
77 this.filterTagWidget.menu.connect( this, { toggle: [ 'emit', 'menuToggle' ] } );
78 this.changesListModel.connect( this, { newChangesExist: 'onNewChangesExist' } );
79 this.showNewChangesLink.connect( this, { click: 'onShowNewChangesClick' } );
80 this.showNewChangesLink.toggle( false );
81
82 this.$element
83 .addClass( 'mw-rcfilters-ui-filterWrapperWidget' )
84 .append(
85 this.$top,
86 this.filterTagWidget.$element,
87 $bottom
88 );
89 };
90
91 /* Initialization */
92
93 OO.inheritClass( mw.rcfilters.ui.FilterWrapperWidget, OO.ui.Widget );
94 OO.mixinClass( mw.rcfilters.ui.FilterWrapperWidget, OO.ui.mixin.PendingElement );
95
96 /* Methods */
97
98 /**
99 * Set the content of the top section
100 *
101 * @param {jQuery} $topSectionElement
102 */
103 mw.rcfilters.ui.FilterWrapperWidget.prototype.setTopSection = function ( $topSectionElement ) {
104 this.$top.append( $topSectionElement );
105 };
106
107 /**
108 * Respond to the user clicking the 'show new changes' button
109 */
110 mw.rcfilters.ui.FilterWrapperWidget.prototype.onShowNewChangesClick = function () {
111 this.controller.showNewChanges();
112 };
113
114 /**
115 * Respond to changes list model newChangesExist
116 *
117 * @param {boolean} newChangesExist Whether new changes exist
118 */
119 mw.rcfilters.ui.FilterWrapperWidget.prototype.onNewChangesExist = function ( newChangesExist ) {
120 this.showNewChangesLink.toggle( newChangesExist );
121 };
122 }( mediaWiki ) );