5 * @extends OO.ui.Widget
8 * @param {mw.rcfilters.dm.FiltersViewModel} filtersViewModel View model
9 * @param {mw.rcfilters.dm.ChangesListViewModel} changesListViewModel View model
10 * @param {mw.rcfilters.Controller} controller
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(
21 config
= $.extend( {}, config
, {
22 $element
: $changesListRoot
26 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.parent
.call( this, config
);
28 this.filtersViewModel
= filtersViewModel
;
29 this.changesListViewModel
= changesListViewModel
;
30 this.controller
= controller
;
33 this.filtersViewModel
.connect( this, {
34 itemUpdate
: 'onItemUpdate',
35 highlightChange
: 'onHighlightChange'
37 this.changesListViewModel
.connect( this, {
38 invalidate
: 'onModelInvalidate',
39 update
: 'onModelUpdate',
40 newChangesExist
: 'onNewChangesExist'
44 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget' )
45 // We handle our own display/hide of the empty results message
46 .removeClass( 'mw-changeslist-empty' );
48 // Set up highlight containers
49 this.setupHighlightContainers( this.$element
);
51 this.setupNewChangesButtonContainer( this.$element
);
56 OO
.inheritClass( mw
.rcfilters
.ui
.ChangesListWrapperWidget
, OO
.ui
.Widget
);
59 * Respond to the highlight feature being toggled on and off
61 * @param {boolean} highlightEnabled
63 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onHighlightChange = function ( highlightEnabled
) {
64 if ( highlightEnabled
) {
65 this.applyHighlight();
67 this.clearHighlight();
72 * Respond to a filter item model update
74 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onItemUpdate = function () {
75 if ( this.filtersViewModel
.isHighlightEnabled() ) {
76 this.clearHighlight();
77 this.applyHighlight();
82 * Respond to changes list model invalidate
84 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onModelInvalidate = function () {
85 $( '.rcfilters-spinner' ).removeClass( 'mw-rcfilters-ui-ready' );
86 this.$element
.removeClass( 'mw-rcfilters-ui-ready' );
90 * Respond to changes list model update
92 * @param {jQuery|string} $changesListContent The content of the updated changes list
93 * @param {jQuery} $fieldset The content of the updated fieldset
94 * @param {boolean} isInitialDOM Whether $changesListContent is the existing (already attached) DOM
95 * @param {boolean} from Timestamp of the new changes
97 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onModelUpdate = function (
98 $changesListContent
, $fieldset
, isInitialDOM
, from
101 $message
= $( '<div>' )
102 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results' ),
103 isEmpty
= $changesListContent
=== 'NO_RESULTS',
106 $newChanges
= $( [] );
108 this.$element
.toggleClass( 'mw-changeslist', !isEmpty
);
110 this.$element
.empty();
112 if ( this.filtersViewModel
.hasConflict() ) {
113 conflictItem
= this.filtersViewModel
.getFirstConflictedItem();
118 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-conflict' )
119 .text( mw
.message( 'rcfilters-noresults-conflict' ).text() ),
121 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-message' )
122 .text( mw
.message( conflictItem
.getCurrentConflictResultMessage() ).text() )
128 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-noresult' )
129 .text( mw
.message( 'recentchanges-noresult' ).text() )
133 this.$element
.append( $message
);
135 if ( !isInitialDOM
) {
136 this.$element
.empty().append( $changesListContent
);
140 this.$element
.find( 'li[data-mw-ts]' ).each( function () {
142 ts
= $li
.data( 'mw-ts' );
145 $newChanges
= $newChanges
.add( $li
);
146 } else if ( $lastSeen
=== null ) {
153 $indicator
= $( '<div>' )
154 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-previousChangesIndicator' )
155 .text( mw
.message( 'rcfilters-previous-changes-label' ).text() );
157 $indicator
.on( 'click', function () {
161 $lastSeen
.before( $indicator
);
170 // Set up highlight containers
171 this.setupHighlightContainers( this.$element
);
174 this.applyHighlight();
176 if ( !isInitialDOM
) {
177 // Make sure enhanced RC re-initializes correctly
178 mw
.hook( 'wikipage.content' ).fire( this.$element
);
182 $( '.rcfilters-spinner' ).addClass( 'mw-rcfilters-ui-ready' );
183 this.$element
.addClass( 'mw-rcfilters-ui-ready' );
187 * Respond to changes list model newChangesExist
189 * @param {boolean} newChangesExist Whether new changes exist
191 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onNewChangesExist = function ( newChangesExist
) {
192 this.showNewChangesLink
.toggle( newChangesExist
);
196 * Respond to the user clicking the 'show new changes' button
198 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onShowNewChangesClick = function () {
199 this.controller
.showNewChanges();
203 * Setup the container for the 'new changes' button.
205 * @param {jQuery} $content
207 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.setupNewChangesButtonContainer = function ( $content
) {
208 this.showNewChangesLink
= new OO
.ui
.ButtonWidget( {
210 label
: mw
.message( 'rcfilters-show-new-changes' ).text(),
211 flags
: [ 'progressive' ]
213 this.showNewChangesLink
.connect( this, { click
: 'onShowNewChangesClick' } );
214 this.showNewChangesLink
.toggle( false );
218 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-newChanges' )
219 .append( this.showNewChangesLink
.$element
)
224 * Set up the highlight containers with all color circle indicators.
226 * @param {jQuery|string} $content The content of the updated changes list
228 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.setupHighlightContainers = function ( $content
) {
229 var uri
= new mw
.Uri(),
230 highlightClass
= 'mw-rcfilters-ui-changesListWrapperWidget-highlights',
231 $highlights
= $( '<div>' )
232 .addClass( highlightClass
)
235 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-none' )
236 .prop( 'data-color', 'none' )
239 if ( $( '.mw-rcfilters-ui-changesListWrapperWidget-highlights' ).length
) {
244 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
247 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-' + color
)
248 .prop( 'data-color', color
)
253 ( uri
.query
.enhanced
!== undefined && Number( uri
.query
.enhanced
) ) ||
254 ( uri
.query
.enhanced
=== undefined && Number( mw
.user
.options
.get( 'usenewrc' ) ) )
257 $content
.find( 'td.mw-enhanced-rc' )
261 .append( $highlights
.clone() )
265 $content
.find( 'ul.special li' )
266 .prepend( $highlights
.clone() );
271 * Apply color classes based on filters highlight configuration
273 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.applyHighlight = function () {
274 if ( !this.filtersViewModel
.isHighlightEnabled() ) {
278 this.filtersViewModel
.getHighlightedItems().forEach( function ( filterItem
) {
279 // Add highlight class to all highlighted list items
280 this.$element
.find( '.' + filterItem
.getCssClass() )
281 .addClass( 'mw-rcfilters-highlight-color-' + filterItem
.getHighlightColor() );
284 // Turn on highlights
285 this.$element
.addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );
289 * Remove all color classes
291 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.clearHighlight = function () {
292 // Remove highlight classes
293 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
294 this.$element
.find( '.mw-rcfilters-highlight-color-' + color
).removeClass( 'mw-rcfilters-highlight-color-' + color
);
297 // Turn off highlights
298 this.$element
.removeClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );