1 const ValuePickerWidget = require( './ValuePickerWidget.js' );
4 * Widget defining the popup to choose number of results.
6 * @class mw.rcfilters.ui.ChangesLimitPopupWidget
8 * @extends OO.ui.Widget
10 * @param {mw.rcfilters.dm.FilterGroup} limitModel Group model for 'limit'
11 * @param {mw.rcfilters.dm.FilterItem} groupByPageItemModel Group model for 'limit'
12 * @param {Object} [config] Configuration object
14 const ChangesLimitPopupWidget = function MwRcfiltersUiChangesLimitPopupWidget( limitModel, groupByPageItemModel, config ) {
15 config = config || {};
18 ChangesLimitPopupWidget.super.call( this, config );
20 this.limitModel = limitModel;
21 this.groupByPageItemModel = groupByPageItemModel;
23 this.valuePicker = new ValuePickerWidget(
26 label: mw.msg( 'rcfilters-limit-title' )
30 this.groupByPageCheckbox = new OO.ui.CheckboxInputWidget( {
31 selected: this.groupByPageItemModel.isSelected()
35 this.valuePicker.connect( this, { choose: [ 'emit', 'limit' ] } );
36 this.groupByPageCheckbox.connect( this, { change: [ 'emit', 'groupByPage' ] } );
37 this.groupByPageItemModel.connect( this, { update: 'onGroupByPageModelUpdate' } );
38 // HACK: Directly connect to the checkbox click event so that we can save the preference
39 // when the user explicitly interacts with the checkbox rather than when the checkbox changes
40 // state. This is to make sure that we only save preference when the user explicitly interacts
42 this.groupByPageCheckbox.$element.on( 'click', this.onGroupByPageUserClick.bind( this ) );
46 .addClass( 'mw-rcfilters-ui-changesLimitPopupWidget' )
48 this.valuePicker.$element,
49 OO.ui.isMobile() ? undefined :
50 new OO.ui.FieldLayout(
51 this.groupByPageCheckbox,
54 label: mw.msg( 'rcfilters-group-results-by-page' )
59 this.valuePicker.selectWidget.$element.attr( 'aria-label', mw.msg( 'rcfilters-limit-title' ) );
64 OO.inheritClass( ChangesLimitPopupWidget, OO.ui.Widget );
69 * A limit item was chosen.
72 * @param {string} name Item name
77 * Results are grouped by page
80 * @param {boolean} isGrouped The results are grouped by page
85 * Respond to group by page model update
87 ChangesLimitPopupWidget.prototype.onGroupByPageModelUpdate = function () {
88 this.groupByPageCheckbox.setSelected( this.groupByPageItemModel.isSelected() );
92 * Respond to user explicitly clicking the Group by page checkbox
94 ChangesLimitPopupWidget.prototype.onGroupByPageUserClick = function () {
95 this.emit( 'groupByPageUserClick', this.groupByPageCheckbox.isSelected() );
98 module.exports = ChangesLimitPopupWidget;