1569f38662fbd029582e0e11a541553a9ecbd81b
3 * Widget defining the button controlling the popup for the date range for the results
5 * @extends OO.ui.Widget
8 * @param {mw.rcfilters.Controller} controller Controller
9 * @param {mw.rcfilters.dm.FiltersViewModel} model View model
10 * @param {Object} [config] Configuration object
11 * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups
13 mw
.rcfilters
.ui
.DateButtonWidget
= function MwRcfiltersUiDateButtonWidget( controller
, model
, config
) {
14 config
= config
|| {};
17 mw
.rcfilters
.ui
.ChangesLimitButtonWidget
.parent
.call( this, config
);
19 this.controller
= controller
;
22 this.$overlay
= config
.$overlay
|| this.$element
;
25 this.daysGroupModel
= null;
27 this.model
.connect( this, {
28 initialize
: 'onModelInitialize'
32 .addClass( 'mw-rcfilters-ui-dateButtonWidget' );
37 OO
.inheritClass( mw
.rcfilters
.ui
.DateButtonWidget
, OO
.ui
.Widget
);
40 * Respond to model initialize event
42 mw
.rcfilters
.ui
.DateButtonWidget
.prototype.onModelInitialize = function () {
45 this.daysGroupModel
= this.model
.getGroup( 'days' );
47 // HACK: We need the model to be ready before we populate the button
48 // and the widget, because we require the filter items for the
49 // limit and their events. This addition is only done after the
50 // model is initialized.
51 // Note: This will be fixed soon!
52 if ( this.daysGroupModel
) {
53 datePopupWidget
= new mw
.rcfilters
.ui
.DatePopupWidget(
57 this.button
= new OO
.ui
.PopupButtonWidget( {
60 $overlay
: this.$overlay
,
66 $autoCloseIgnore
: this.$overlay
,
67 $content
: datePopupWidget
.$element
70 this.updateButtonLabel();
73 this.daysGroupModel
.connect( this, { update
: 'onDaysGroupModelUpdate' } );
74 datePopupWidget
.connect( this, { days
: 'onPopupDays' } );
76 this.$element
.append( this.button
.$element
);
81 * Respond to popup limit change event
83 * @param {string} filterName Chosen filter name
85 mw
.rcfilters
.ui
.DateButtonWidget
.prototype.onPopupDays = function ( filterName
) {
86 this.controller
.toggleFilterSelect( filterName
, true );
90 * Respond to limit choose event
92 * @param {string} filterName Filter name
94 mw
.rcfilters
.ui
.DateButtonWidget
.prototype.onDaysGroupModelUpdate = function () {
95 this.updateButtonLabel();
99 * Update the button label
101 mw
.rcfilters
.ui
.DateButtonWidget
.prototype.updateButtonLabel = function () {
102 var item
= this.daysGroupModel
.getSelectedItems()[ 0 ];
106 this.button
.setLabel(
108 Number( item
.getParamName() ) < 1 ?
109 'rcfilters-days-show-hours' : 'rcfilters-days-show-days',