| 1 |
const FilterTagMultiselectWidget = require( './FilterTagMultiselectWidget.js' ), |
| 2 |
LiveUpdateButtonWidget = require( './LiveUpdateButtonWidget.js' ), |
| 3 |
ChangesLimitAndDateButtonWidget = require( './ChangesLimitAndDateButtonWidget.js' ); |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
const FilterWrapperWidget = function MwRcfiltersUiFilterWrapperWidget( |
| 25 |
controller, model, savedQueriesModel, changesListModel, config |
| 26 |
) { |
| 27 |
config = config || {}; |
| 28 |
|
| 29 |
|
| 30 |
FilterWrapperWidget.super.call( this, config ); |
| 31 |
|
| 32 |
OO.ui.mixin.PendingElement.call( this, config ); |
| 33 |
|
| 34 |
this.controller = controller; |
| 35 |
this.model = model; |
| 36 |
this.queriesModel = savedQueriesModel; |
| 37 |
this.changesListModel = changesListModel; |
| 38 |
this.$overlay = config.$overlay || this.$element; |
| 39 |
this.$wrapper = config.$wrapper || this.$element; |
| 40 |
|
| 41 |
this.filterTagWidget = new FilterTagMultiselectWidget( |
| 42 |
this.controller, |
| 43 |
this.model, |
| 44 |
this.queriesModel, |
| 45 |
{ |
| 46 |
$overlay: this.$overlay, |
| 47 |
collapsed: config.collapsed, |
| 48 |
$wrapper: this.$wrapper, |
| 49 |
isMobile: OO.ui.isMobile() |
| 50 |
} |
| 51 |
); |
| 52 |
|
| 53 |
this.liveUpdateButton = new LiveUpdateButtonWidget( |
| 54 |
this.controller, |
| 55 |
this.changesListModel |
| 56 |
); |
| 57 |
|
| 58 |
this.numChangesAndDateWidget = new ChangesLimitAndDateButtonWidget( |
| 59 |
this.controller, |
| 60 |
this.model, |
| 61 |
{ |
| 62 |
$overlay: this.$overlay |
| 63 |
} |
| 64 |
); |
| 65 |
|
| 66 |
this.showNewChangesLink = new OO.ui.ButtonWidget( { |
| 67 |
icon: 'reload', |
| 68 |
framed: false, |
| 69 |
flags: [ 'progressive' ], |
| 70 |
classes: [ 'mw-rcfilters-ui-filterWrapperWidget-showNewChanges' ] |
| 71 |
} ); |
| 72 |
|
| 73 |
|
| 74 |
this.filterTagWidget.menu.connect( this, { toggle: [ 'emit', 'menuToggle' ] } ); |
| 75 |
this.changesListModel.connect( this, { newChangesExist: 'onNewChangesExist' } ); |
| 76 |
this.showNewChangesLink.connect( this, { click: 'onShowNewChangesClick' } ); |
| 77 |
this.showNewChangesLink.toggle( false ); |
| 78 |
|
| 79 |
|
| 80 |
this.$top = $( '<div>' ) |
| 81 |
.addClass( 'mw-rcfilters-ui-filterWrapperWidget-top' ); |
| 82 |
|
| 83 |
const $bottom = $( '<div>' ) |
| 84 |
.addClass( 'mw-rcfilters-ui-filterWrapperWidget-bottom' ) |
| 85 |
.addClass( OO.ui.isMobile() ? 'mw-rcfilters-ui-filterWrapperWidget-bottom-mobile' : '' ) |
| 86 |
.append( |
| 87 |
this.showNewChangesLink.$element, |
| 88 |
this.numChangesAndDateWidget.$element |
| 89 |
); |
| 90 |
|
| 91 |
if ( this.controller.pollingRate ) { |
| 92 |
$bottom.prepend( this.liveUpdateButton.$element ); |
| 93 |
} |
| 94 |
|
| 95 |
this.$element |
| 96 |
.addClass( 'mw-rcfilters-ui-filterWrapperWidget' ) |
| 97 |
.append( |
| 98 |
this.$top, |
| 99 |
this.filterTagWidget.$element, |
| 100 |
$bottom |
| 101 |
); |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
OO.inheritClass( FilterWrapperWidget, OO.ui.Widget ); |
| 107 |
OO.mixinClass( FilterWrapperWidget, OO.ui.mixin.PendingElement ); |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
FilterWrapperWidget.prototype.setTopSection = function ( $topSectionElement ) { |
| 117 |
this.$top.append( $topSectionElement ); |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
FilterWrapperWidget.prototype.onShowNewChangesClick = function () { |
| 124 |
this.controller.showNewChanges(); |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
FilterWrapperWidget.prototype.onNewChangesExist = function ( newChangesExist ) { |
| 133 |
if ( newChangesExist ) { |
| 134 |
this.showNewChangesLink.setLabel( |
| 135 |
mw.msg( |
| 136 |
'rcfilters-show-new-changes', |
| 137 |
this.changesListModel.getNextFromFormatted() |
| 138 |
) |
| 139 |
); |
| 140 |
} |
| 141 |
this.showNewChangesLink.toggle( newChangesExist ); |
| 142 |
}; |
| 143 |
|
| 144 |
module.exports = FilterWrapperWidget; |