3 * Widget defining the button controlling the popup for the date range for the 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
.DateButtonWidget
= function MwRcfiltersUiDateButtonWidget( 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.daysGroupModel
= null;
28 this.model
.connect( this, {
29 initialize
: 'onModelInitialize'
33 .addClass( 'mw-rcfilters-ui-dateButtonWidget' );
38 OO
.inheritClass( mw
.rcfilters
.ui
.DateButtonWidget
, OO
.ui
.Widget
);
41 * Respond to model initialize event
43 mw
.rcfilters
.ui
.DateButtonWidget
.prototype.onModelInitialize = function () {
46 this.daysGroupModel
= this.model
.getGroup( 'days' );
48 // HACK: We need the model to be ready before we populate the button
49 // and the widget, because we require the filter items for the
50 // limit and their events. This addition is only done after the
51 // model is initialized.
52 // Note: This will be fixed soon!
53 if ( this.daysGroupModel
) {
54 datePopupWidget
= new mw
.rcfilters
.ui
.DatePopupWidget(
58 this.button
= new OO
.ui
.PopupButtonWidget( {
61 $overlay
: this.$overlay
,
67 $autoCloseIgnore
: this.$overlay
,
68 $content
: datePopupWidget
.$element
71 this.updateButtonLabel();
74 this.daysGroupModel
.connect( this, { update
: 'onDaysGroupModelUpdate' } );
75 datePopupWidget
.connect( this, { days
: 'onPopupDays' } );
77 this.$element
.append( this.button
.$element
);
82 * Respond to popup limit change event
84 * @param {string} filterName Chosen filter name
86 mw
.rcfilters
.ui
.DateButtonWidget
.prototype.onPopupDays = function ( filterName
) {
87 var item
= this.daysGroupModel
.getItemByName( filterName
);
89 this.controller
.toggleFilterSelect( filterName
, true );
90 this.controller
.updateDaysDefault( item
.getParamName() );
91 this.button
.popup
.toggle( false );
95 * Respond to limit choose event
97 * @param {string} filterName Filter name
99 mw
.rcfilters
.ui
.DateButtonWidget
.prototype.onDaysGroupModelUpdate = function () {
100 this.updateButtonLabel();
104 * Update the button label
106 mw
.rcfilters
.ui
.DateButtonWidget
.prototype.updateButtonLabel = function () {
107 var item
= this.daysGroupModel
.getSelectedItems()[ 0 ];
111 this.button
.setLabel(
113 Number( item
.getParamName() ) < 1 ?
114 'rcfilters-days-show-hours' : 'rcfilters-days-show-days',