| 1 |
const ChangesLimitPopupWidget = require( './ChangesLimitPopupWidget.js' ), |
| 2 |
DatePopupWidget = require( './DatePopupWidget.js' ); |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
const ChangesLimitAndDateButtonWidget = function MwRcfiltersUiChangesLimitWidget( controller, model, config ) { |
| 17 |
config = config || {}; |
| 18 |
|
| 19 |
|
| 20 |
ChangesLimitAndDateButtonWidget.super.call( this, config ); |
| 21 |
|
| 22 |
this.controller = controller; |
| 23 |
this.model = model; |
| 24 |
|
| 25 |
this.$overlay = config.$overlay || this.$element; |
| 26 |
|
| 27 |
this.button = null; |
| 28 |
this.limitGroupModel = null; |
| 29 |
this.groupByPageItemModel = null; |
| 30 |
this.daysGroupModel = null; |
| 31 |
|
| 32 |
this.model.connect( this, { |
| 33 |
initialize: 'onModelInitialize' |
| 34 |
} ); |
| 35 |
|
| 36 |
this.$element |
| 37 |
.addClass( 'mw-rcfilters-ui-changesLimitAndDateButtonWidget' ); |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
OO.inheritClass( ChangesLimitAndDateButtonWidget, OO.ui.Widget ); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
ChangesLimitAndDateButtonWidget.prototype.onModelInitialize = function () { |
| 48 |
const displayGroupModel = this.model.getGroup( 'display' ); |
| 49 |
|
| 50 |
this.limitGroupModel = this.model.getGroup( 'limit' ); |
| 51 |
this.groupByPageItemModel = displayGroupModel.getItemByParamName( 'enhanced' ); |
| 52 |
this.daysGroupModel = this.model.getGroup( 'days' ); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
if ( this.limitGroupModel && this.daysGroupModel ) { |
| 60 |
this.changesLimitPopupWidget = new ChangesLimitPopupWidget( |
| 61 |
this.limitGroupModel, |
| 62 |
this.groupByPageItemModel |
| 63 |
); |
| 64 |
|
| 65 |
const datePopupWidget = new DatePopupWidget( |
| 66 |
this.daysGroupModel, |
| 67 |
{ |
| 68 |
label: mw.msg( 'rcfilters-date-popup-title' ) |
| 69 |
} |
| 70 |
); |
| 71 |
|
| 72 |
const selectedItem = this.limitGroupModel.findSelectedItems()[ 0 ]; |
| 73 |
const currentValue = ( selectedItem && selectedItem.getLabel() ) || |
| 74 |
mw.language.convertNumber( this.limitGroupModel.getDefaultParamValue() ); |
| 75 |
|
| 76 |
this.button = new OO.ui.PopupButtonWidget( { |
| 77 |
icon: 'settings', |
| 78 |
indicator: 'down', |
| 79 |
label: mw.msg( 'rcfilters-limit-and-date-label', currentValue ), |
| 80 |
$overlay: this.$overlay, |
| 81 |
popup: { |
| 82 |
width: 300, |
| 83 |
padded: false, |
| 84 |
anchor: false, |
| 85 |
align: 'backwards', |
| 86 |
$autoCloseIgnore: this.$overlay, |
| 87 |
$content: $( '<div>' ).append( |
| 88 |
|
| 89 |
this.changesLimitPopupWidget.$element, |
| 90 |
datePopupWidget.$element |
| 91 |
) |
| 92 |
} |
| 93 |
} ); |
| 94 |
|
| 95 |
this.button.popup.connect( this, { ready: 'onPopupInitialized' } ); |
| 96 |
this.button.popup.connect( this, { closing: 'onPopupClosing' } ); |
| 97 |
this.button.popup.$element.attr( 'aria-label', |
| 98 |
mw.msg( 'rcfilters-limit-and-date-popup-dialog-aria-label' ) |
| 99 |
); |
| 100 |
this.updateButtonLabel(); |
| 101 |
|
| 102 |
|
| 103 |
this.limitGroupModel.connect( this, { update: 'updateButtonLabel' } ); |
| 104 |
this.daysGroupModel.connect( this, { update: 'updateButtonLabel' } ); |
| 105 |
this.changesLimitPopupWidget.connect( this, { |
| 106 |
limit: 'onPopupLimit', |
| 107 |
groupByPage: 'onPopupGroupByPage', |
| 108 |
groupByPageUserClick: 'onPopupGroupByPageUserClick' |
| 109 |
} ); |
| 110 |
datePopupWidget.connect( this, { days: 'onPopupDays' } ); |
| 111 |
|
| 112 |
this.$element.append( this.button.$element ); |
| 113 |
} |
| 114 |
}; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
ChangesLimitAndDateButtonWidget.prototype.onPopupInitialized = function () { |
| 121 |
this.changesLimitPopupWidget.$element.find( '*[tabindex]' ).first().trigger( 'focus' ); |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
ChangesLimitAndDateButtonWidget.prototype.onPopupClosing = function () { |
| 129 |
this.button.$button.trigger( 'focus' ); |
| 130 |
}; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
ChangesLimitAndDateButtonWidget.prototype.onPopupLimit = function ( filterName ) { |
| 138 |
const item = this.limitGroupModel.getItemByName( filterName ); |
| 139 |
|
| 140 |
this.controller.toggleFilterSelect( filterName, true ); |
| 141 |
this.controller.updateLimitDefault( item.getParamName() ); |
| 142 |
this.button.popup.toggle( false ); |
| 143 |
}; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
ChangesLimitAndDateButtonWidget.prototype.onPopupGroupByPage = function ( isGrouped ) { |
| 151 |
this.controller.toggleFilterSelect( this.groupByPageItemModel.getName(), isGrouped ); |
| 152 |
this.button.popup.toggle( false ); |
| 153 |
}; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
ChangesLimitAndDateButtonWidget.prototype.onPopupGroupByPageUserClick = function ( isSelected ) { |
| 161 |
this.controller.updateGroupByPageDefault( isSelected ); |
| 162 |
}; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
ChangesLimitAndDateButtonWidget.prototype.onPopupDays = function ( filterName ) { |
| 170 |
const item = this.daysGroupModel.getItemByName( filterName ); |
| 171 |
|
| 172 |
this.controller.toggleFilterSelect( filterName, true ); |
| 173 |
this.controller.updateDaysDefault( item.getParamName() ); |
| 174 |
this.button.popup.toggle( false ); |
| 175 |
}; |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
ChangesLimitAndDateButtonWidget.prototype.updateButtonLabel = function () { |
| 181 |
const limit = this.limitGroupModel.findSelectedItems()[ 0 ], |
| 182 |
label = limit && limit.getLabel(), |
| 183 |
days = this.daysGroupModel.findSelectedItems()[ 0 ]; |
| 184 |
|
| 185 |
|
| 186 |
if ( label && days ) { |
| 187 |
const message = mw.msg( 'rcfilters-limit-and-date-label', label, |
| 188 |
mw.msg( |
| 189 |
Number( days.getParamName() ) < 1 ? |
| 190 |
'rcfilters-days-show-hours' : |
| 191 |
'rcfilters-days-show-days', |
| 192 |
days.getLabel() |
| 193 |
) |
| 194 |
); |
| 195 |
this.button.setLabel( message ); |
| 196 |
} |
| 197 |
}; |
| 198 |
|
| 199 |
module.exports = ChangesLimitAndDateButtonWidget; |