5 * @extends OO.ui.Widget
6 * @mixins OO.ui.mixin.PendingElement
9 * @param {mw.rcfilters.dm.FiltersViewModel} filtersViewModel View model
10 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListViewModel View model
11 * @param {jQuery} $changesListRoot Root element of the changes list to attach to
12 * @param {Object} config Configuration object
14 mw
.rcfilters
.ui
.ChangesListWrapperWidget
= function MwRcfiltersUiChangesListWrapperWidget(
20 config
= $.extend( {}, config
, {
21 $element
: $changesListRoot
25 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.parent
.call( this, config
);
27 OO
.ui
.mixin
.PendingElement
.call( this, config
);
29 this.filtersViewModel
= filtersViewModel
;
30 this.changesListViewModel
= changesListViewModel
;
33 this.filtersViewModel
.connect( this, {
34 itemUpdate
: 'onItemUpdate',
35 highlightChange
: 'onHighlightChange'
37 this.changesListViewModel
.connect( this, {
38 invalidate
: 'onModelInvalidate',
39 update
: 'onModelUpdate'
43 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget' )
44 // We handle our own display/hide of the empty results message
45 .removeClass( 'mw-changeslist-empty' );
47 // Set up highlight containers
48 this.setupHighlightContainers( this.$element
);
53 OO
.inheritClass( mw
.rcfilters
.ui
.ChangesListWrapperWidget
, OO
.ui
.Widget
);
54 OO
.mixinClass( mw
.rcfilters
.ui
.ChangesListWrapperWidget
, OO
.ui
.mixin
.PendingElement
);
57 * Respond to the highlight feature being toggled on and off
59 * @param {boolean} highlightEnabled
61 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onHighlightChange = function ( highlightEnabled
) {
62 if ( highlightEnabled
) {
63 this.applyHighlight();
65 this.clearHighlight();
70 * Respond to a filter item model update
72 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onItemUpdate = function () {
73 if ( this.filtersViewModel
.isHighlightEnabled() ) {
74 this.clearHighlight();
75 this.applyHighlight();
80 * Respond to changes list model invalidate
82 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onModelInvalidate = function () {
87 * Respond to changes list model update
89 * @param {jQuery|string} $changesListContent The content of the updated changes list
90 * @param {jQuery} $fieldset The content of the updated fieldset
91 * @param {boolean} isInitialDOM Whether $changesListContent is the existing (already attached) DOM
93 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onModelUpdate = function ( $changesListContent
, $fieldset
, isInitialDOM
) {
95 $message
= $( '<div>' )
96 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results' ),
97 isEmpty
= $changesListContent
=== 'NO_RESULTS';
99 this.$element
.toggleClass( 'mw-changeslist', !isEmpty
);
101 this.$changesListContent
= null;
102 this.$element
.empty();
104 if ( this.filtersViewModel
.hasConflict() ) {
105 conflictItem
= this.filtersViewModel
.getFirstConflictedItem();
110 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-conflict' )
111 .text( mw
.message( 'rcfilters-noresults-conflict' ).text() ),
113 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-message' )
114 .text( mw
.message( conflictItem
.getCurrentConflictResultMessage() ).text() )
120 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-noresult' )
121 .text( mw
.message( 'recentchanges-noresult' ).text() )
125 this.$element
.append( $message
);
127 this.$changesListContent
= $changesListContent
;
128 this.$element
.empty().append( this.$changesListContent
);
129 // Set up highlight containers
130 this.setupHighlightContainers( this.$element
);
133 this.applyHighlight();
135 if ( !isInitialDOM
) {
136 // Make sure enhanced RC re-initializes correctly
137 mw
.hook( 'wikipage.content' ).fire( this.$element
);
144 * Set up the highlight containers with all color circle indicators.
146 * @param {jQuery|string} $content The content of the updated changes list
148 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.setupHighlightContainers = function ( $content
) {
149 var uri
= new mw
.Uri(),
150 $highlights
= $( '<div>' )
151 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights' )
154 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-none' )
155 .prop( 'data-color', 'none' )
158 if ( $( '.mw-rcfilters-ui-changesListWrapperWidget-highlights' ).length
) {
163 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
166 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-' + color
)
167 .prop( 'data-color', color
)
172 ( uri
.query
.enhanced
!== undefined && Number( uri
.query
.enhanced
) ) ||
173 ( uri
.query
.enhanced
=== undefined && Number( mw
.user
.options
.get( 'usenewrc' ) ) )
176 $content
.find( 'td.mw-enhanced-rc' )
180 .append( $highlights
.clone() )
184 $content
.find( 'ul.special li' )
185 .prepend( $highlights
.clone() );
190 * Apply color classes based on filters highlight configuration
192 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.applyHighlight = function () {
193 if ( !this.filtersViewModel
.isHighlightEnabled() ) {
197 this.filtersViewModel
.getHighlightedItems().forEach( function ( filterItem
) {
198 // Add highlight class to all highlighted list items
199 this.$element
.find( '.' + filterItem
.getCssClass() )
200 .addClass( 'mw-rcfilters-highlight-color-' + filterItem
.getHighlightColor() );
203 // Turn on highlights
204 this.$element
.addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );
208 * Remove all color classes
210 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.clearHighlight = function () {
211 // Remove highlight classes
212 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
213 this.$element
.find( '.mw-rcfilters-highlight-color-' + color
).removeClass( 'mw-rcfilters-highlight-color-' + color
);
216 // Turn off highlights
217 this.$element
.removeClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );