3 * Widget defining the button controlling the popup for the number of results
6 * @extends OO.ui.Widget
9 * @param {mw.rcfilters.Controller} controller Controller
10 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
11 * @param {Object} [config] Configuration object
12 * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
14 mw
.rcfilters
.ui
.ChangesLimitButtonWidget
= function MwRcfiltersUiChangesLimitWidget( controller
, model
, config
) {
15 config
= config
|| {};
18 mw
.rcfilters
.ui
.ChangesLimitButtonWidget
.parent
.call( this, config
);
20 this.controller
= controller
;
23 this.$overlay
= config
.$overlay
|| this.$element
;
26 this.limitGroupModel
= null;
28 this.model
.connect( this, {
29 initialize
: 'onModelInitialize'
33 .addClass( 'mw-rcfilters-ui-changesLimitButtonWidget' );
38 OO
.inheritClass( mw
.rcfilters
.ui
.ChangesLimitButtonWidget
, OO
.ui
.Widget
);
41 * Respond to model initialize event
43 mw
.rcfilters
.ui
.ChangesLimitButtonWidget
.prototype.onModelInitialize = function () {
44 var changesLimitPopupWidget
, selectedItem
, currentValue
,
45 displayGroupModel
= this.model
.getGroup( 'display' );
47 this.limitGroupModel
= this.model
.getGroup( 'limit' );
48 this.groupByPageItemModel
= displayGroupModel
.getItemByParamName( 'enhanced' );
50 // HACK: We need the model to be ready before we populate the button
51 // and the widget, because we require the filter items for the
52 // limit and their events. This addition is only done after the
53 // model is initialized.
54 // Note: This will be fixed soon!
55 if ( this.limitGroupModel
) {
56 changesLimitPopupWidget
= new mw
.rcfilters
.ui
.ChangesLimitPopupWidget(
58 this.groupByPageItemModel
61 selectedItem
= this.limitGroupModel
.getSelectedItems()[ 0 ];
62 currentValue
= ( selectedItem
&& selectedItem
.getLabel() ) ||
63 mw
.language
.convertNumber( this.limitGroupModel
.getDefaultParamValue() );
65 this.button
= new OO
.ui
.PopupButtonWidget( {
67 label
: mw
.msg( 'rcfilters-limit-shownum', currentValue
),
68 $overlay
: this.$overlay
,
74 $autoCloseIgnore
: this.$overlay
,
75 $content
: changesLimitPopupWidget
.$element
80 this.limitGroupModel
.connect( this, { update
: 'onLimitGroupModelUpdate' } );
81 changesLimitPopupWidget
.connect( this, {
82 limit
: 'onPopupLimit',
83 groupByPage
: 'onPopupGroupByPage'
86 this.$element
.append( this.button
.$element
);
91 * Respond to popup limit change event
93 * @param {string} filterName Chosen filter name
95 mw
.rcfilters
.ui
.ChangesLimitButtonWidget
.prototype.onPopupLimit = function ( filterName
) {
96 var item
= this.limitGroupModel
.getItemByName( filterName
);
98 this.controller
.toggleFilterSelect( filterName
, true );
99 this.controller
.updateLimitDefault( item
.getParamName() );
100 this.button
.popup
.toggle( false );
104 * Respond to popup limit change event
106 * @param {boolean} isGrouped The result set is grouped by page
108 mw
.rcfilters
.ui
.ChangesLimitButtonWidget
.prototype.onPopupGroupByPage = function ( isGrouped
) {
109 this.controller
.toggleFilterSelect( this.groupByPageItemModel
.getName(), isGrouped
);
110 this.controller
.updateGroupByPageDefault( Number( isGrouped
) );
111 this.button
.popup
.toggle( false );
115 * Respond to limit choose event
117 * @param {string} filterName Filter name
119 mw
.rcfilters
.ui
.ChangesLimitButtonWidget
.prototype.onLimitGroupModelUpdate = function () {
120 var item
= this.limitGroupModel
.getSelectedItems()[ 0 ],
121 label
= item
&& item
.getLabel();
125 this.button
.setLabel( mw
.msg( 'rcfilters-limit-shownum', label
) );