X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fui%2FChangesLimitAndDateButtonWidget.js;h=ac5bbae78ef5e3cd9d2022d9f142c8cfa10187b5;hb=fa261ed50f3a8c6e845754f4f75c7b03073bef0f;hp=23b05e812be5d581f7cf87a9561f479ee315684f;hpb=12a9cf3110c9ea840b20f74b3d4a968c92d8b446;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.rcfilters/ui/ChangesLimitAndDateButtonWidget.js b/resources/src/mediawiki.rcfilters/ui/ChangesLimitAndDateButtonWidget.js index 23b05e812b..ac5bbae78e 100644 --- a/resources/src/mediawiki.rcfilters/ui/ChangesLimitAndDateButtonWidget.js +++ b/resources/src/mediawiki.rcfilters/ui/ChangesLimitAndDateButtonWidget.js @@ -1,174 +1,169 @@ -( function () { - var ChangesLimitPopupWidget = require( './ChangesLimitPopupWidget.js' ), - DatePopupWidget = require( './DatePopupWidget.js' ), - ChangesLimitAndDateButtonWidget; - - /** - * Widget defining the button controlling the popup for the number of results - * - * @class mw.rcfilters.ui.ChangesLimitAndDateButtonWidget - * @extends OO.ui.Widget - * - * @constructor - * @param {mw.rcfilters.Controller} controller Controller - * @param {mw.rcfilters.dm.FiltersViewModel} model View model - * @param {Object} [config] Configuration object - * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups - */ - ChangesLimitAndDateButtonWidget = function MwRcfiltersUiChangesLimitWidget( controller, model, config ) { - config = config || {}; - - // Parent - ChangesLimitAndDateButtonWidget.parent.call( this, config ); - - this.controller = controller; - this.model = model; - - this.$overlay = config.$overlay || this.$element; - - this.button = null; - this.limitGroupModel = null; - this.groupByPageItemModel = null; - this.daysGroupModel = null; - - this.model.connect( this, { - initialize: 'onModelInitialize' +var ChangesLimitPopupWidget = require( './ChangesLimitPopupWidget.js' ), + DatePopupWidget = require( './DatePopupWidget.js' ), + ChangesLimitAndDateButtonWidget; + +/** + * Widget defining the button controlling the popup for the number of results + * + * @class mw.rcfilters.ui.ChangesLimitAndDateButtonWidget + * @extends OO.ui.Widget + * + * @constructor + * @param {mw.rcfilters.Controller} controller Controller + * @param {mw.rcfilters.dm.FiltersViewModel} model View model + * @param {Object} [config] Configuration object + * @cfg {jQuery} [$overlay] A jQuery object serving as overlay for popups + */ +ChangesLimitAndDateButtonWidget = function MwRcfiltersUiChangesLimitWidget( controller, model, config ) { + config = config || {}; + + // Parent + ChangesLimitAndDateButtonWidget.parent.call( this, config ); + + this.controller = controller; + this.model = model; + + this.$overlay = config.$overlay || this.$element; + + this.button = null; + this.limitGroupModel = null; + this.groupByPageItemModel = null; + this.daysGroupModel = null; + + this.model.connect( this, { + initialize: 'onModelInitialize' + } ); + + this.$element + .addClass( 'mw-rcfilters-ui-changesLimitAndDateButtonWidget' ); +}; + +/* Initialization */ + +OO.inheritClass( ChangesLimitAndDateButtonWidget, OO.ui.Widget ); + +/** + * Respond to model initialize event + */ +ChangesLimitAndDateButtonWidget.prototype.onModelInitialize = function () { + var changesLimitPopupWidget, selectedItem, currentValue, datePopupWidget, + displayGroupModel = this.model.getGroup( 'display' ); + + this.limitGroupModel = this.model.getGroup( 'limit' ); + this.groupByPageItemModel = displayGroupModel.getItemByParamName( 'enhanced' ); + this.daysGroupModel = this.model.getGroup( 'days' ); + + // HACK: We need the model to be ready before we populate the button + // and the widget, because we require the filter items for the + // limit and their events. This addition is only done after the + // model is initialized. + // Note: This will be fixed soon! + if ( this.limitGroupModel && this.daysGroupModel ) { + changesLimitPopupWidget = new ChangesLimitPopupWidget( + this.limitGroupModel, + this.groupByPageItemModel + ); + + datePopupWidget = new DatePopupWidget( + this.daysGroupModel, + { + label: mw.msg( 'rcfilters-date-popup-title' ) + } + ); + + selectedItem = this.limitGroupModel.findSelectedItems()[ 0 ]; + currentValue = ( selectedItem && selectedItem.getLabel() ) || + mw.language.convertNumber( this.limitGroupModel.getDefaultParamValue() ); + + this.button = new OO.ui.PopupButtonWidget( { + icon: 'settings', + indicator: 'down', + label: mw.msg( 'rcfilters-limit-and-date-label', currentValue ), + $overlay: this.$overlay, + popup: { + width: 300, + padded: false, + anchor: false, + align: 'backwards', + $autoCloseIgnore: this.$overlay, + $content: $( '
' ).append( + // TODO: Merge ChangesLimitPopupWidget with DatePopupWidget into one common widget + changesLimitPopupWidget.$element, + datePopupWidget.$element + ) + } } ); - - this.$element - .addClass( 'mw-rcfilters-ui-changesLimitAndDateButtonWidget' ); - }; - - /* Initialization */ - - OO.inheritClass( ChangesLimitAndDateButtonWidget, OO.ui.Widget ); - - /** - * Respond to model initialize event - */ - ChangesLimitAndDateButtonWidget.prototype.onModelInitialize = function () { - var changesLimitPopupWidget, selectedItem, currentValue, datePopupWidget, - displayGroupModel = this.model.getGroup( 'display' ); - - this.limitGroupModel = this.model.getGroup( 'limit' ); - this.groupByPageItemModel = displayGroupModel.getItemByParamName( 'enhanced' ); - this.daysGroupModel = this.model.getGroup( 'days' ); - - // HACK: We need the model to be ready before we populate the button - // and the widget, because we require the filter items for the - // limit and their events. This addition is only done after the - // model is initialized. - // Note: This will be fixed soon! - if ( this.limitGroupModel && this.daysGroupModel ) { - changesLimitPopupWidget = new ChangesLimitPopupWidget( - this.limitGroupModel, - this.groupByPageItemModel - ); - - datePopupWidget = new DatePopupWidget( - this.daysGroupModel, - { - label: mw.msg( 'rcfilters-date-popup-title' ) - } - ); - - selectedItem = this.limitGroupModel.findSelectedItems()[ 0 ]; - currentValue = ( selectedItem && selectedItem.getLabel() ) || - mw.language.convertNumber( this.limitGroupModel.getDefaultParamValue() ); - - this.button = new OO.ui.PopupButtonWidget( { - icon: 'settings', - indicator: 'down', - label: mw.msg( 'rcfilters-limit-and-date-label', currentValue ), - $overlay: this.$overlay, - popup: { - width: 300, - padded: false, - anchor: false, - align: 'backwards', - $autoCloseIgnore: this.$overlay, - $content: $( '
' ).append( - // TODO: Merge ChangesLimitPopupWidget with DatePopupWidget into one common widget - changesLimitPopupWidget.$element, - datePopupWidget.$element - ) - } - } ); - this.updateButtonLabel(); - - // Events - this.limitGroupModel.connect( this, { update: 'updateButtonLabel' } ); - this.daysGroupModel.connect( this, { update: 'updateButtonLabel' } ); - changesLimitPopupWidget.connect( this, { - limit: 'onPopupLimit', - groupByPage: 'onPopupGroupByPage' - } ); - datePopupWidget.connect( this, { days: 'onPopupDays' } ); - - this.$element.append( this.button.$element ); - } - }; - - /** - * Respond to popup limit change event - * - * @param {string} filterName Chosen filter name - */ - ChangesLimitAndDateButtonWidget.prototype.onPopupLimit = function ( filterName ) { - var item = this.limitGroupModel.getItemByName( filterName ); - - this.controller.toggleFilterSelect( filterName, true ); - this.controller.updateLimitDefault( item.getParamName() ); - this.button.popup.toggle( false ); - }; - - /** - * Respond to popup limit change event - * - * @param {boolean} isGrouped The result set is grouped by page - */ - ChangesLimitAndDateButtonWidget.prototype.onPopupGroupByPage = function ( isGrouped ) { - this.controller.toggleFilterSelect( this.groupByPageItemModel.getName(), isGrouped ); - this.controller.updateGroupByPageDefault( isGrouped ); - this.button.popup.toggle( false ); - }; - - /** - * Respond to popup limit change event - * - * @param {string} filterName Chosen filter name - */ - ChangesLimitAndDateButtonWidget.prototype.onPopupDays = function ( filterName ) { - var item = this.daysGroupModel.getItemByName( filterName ); - - this.controller.toggleFilterSelect( filterName, true ); - this.controller.updateDaysDefault( item.getParamName() ); - this.button.popup.toggle( false ); - }; - - /** - * Respond to limit choose event - * - * @param {string} filterName Filter name - */ - ChangesLimitAndDateButtonWidget.prototype.updateButtonLabel = function () { - var message, - limit = this.limitGroupModel.findSelectedItems()[ 0 ], - label = limit && limit.getLabel(), - days = this.daysGroupModel.findSelectedItems()[ 0 ], - daysParamName = Number( days.getParamName() ) < 1 ? - 'rcfilters-days-show-hours' : - 'rcfilters-days-show-days'; - - // Update the label - if ( label && days ) { - message = mw.msg( 'rcfilters-limit-and-date-label', label, - mw.msg( daysParamName, days.getLabel() ) - ); - this.button.setLabel( message ); - } - }; - - module.exports = ChangesLimitAndDateButtonWidget; - -}() ); + this.updateButtonLabel(); + + // Events + this.limitGroupModel.connect( this, { update: 'updateButtonLabel' } ); + this.daysGroupModel.connect( this, { update: 'updateButtonLabel' } ); + changesLimitPopupWidget.connect( this, { + limit: 'onPopupLimit', + groupByPage: 'onPopupGroupByPage' + } ); + datePopupWidget.connect( this, { days: 'onPopupDays' } ); + + this.$element.append( this.button.$element ); + } +}; + +/** + * Respond to popup limit change event + * + * @param {string} filterName Chosen filter name + */ +ChangesLimitAndDateButtonWidget.prototype.onPopupLimit = function ( filterName ) { + var item = this.limitGroupModel.getItemByName( filterName ); + + this.controller.toggleFilterSelect( filterName, true ); + this.controller.updateLimitDefault( item.getParamName() ); + this.button.popup.toggle( false ); +}; + +/** + * Respond to popup limit change event + * + * @param {boolean} isGrouped The result set is grouped by page + */ +ChangesLimitAndDateButtonWidget.prototype.onPopupGroupByPage = function ( isGrouped ) { + this.controller.toggleFilterSelect( this.groupByPageItemModel.getName(), isGrouped ); + this.controller.updateGroupByPageDefault( isGrouped ); + this.button.popup.toggle( false ); +}; + +/** + * Respond to popup limit change event + * + * @param {string} filterName Chosen filter name + */ +ChangesLimitAndDateButtonWidget.prototype.onPopupDays = function ( filterName ) { + var item = this.daysGroupModel.getItemByName( filterName ); + + this.controller.toggleFilterSelect( filterName, true ); + this.controller.updateDaysDefault( item.getParamName() ); + this.button.popup.toggle( false ); +}; + +/** + * Respond to limit choose event + */ +ChangesLimitAndDateButtonWidget.prototype.updateButtonLabel = function () { + var message, + limit = this.limitGroupModel.findSelectedItems()[ 0 ], + label = limit && limit.getLabel(), + days = this.daysGroupModel.findSelectedItems()[ 0 ], + daysParamName = Number( days.getParamName() ) < 1 ? + 'rcfilters-days-show-hours' : + 'rcfilters-days-show-days'; + + // Update the label + if ( label && days ) { + message = mw.msg( 'rcfilters-limit-and-date-label', label, + mw.msg( daysParamName, days.getLabel() ) + ); + this.button.setLabel( message ); + } +}; + +module.exports = ChangesLimitAndDateButtonWidget;