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',
104 // For enhanced mode, we have to load these modules, which are
105 // not loaded for the 'regular' mode in the backend
106 loaderPromise
= mw
.user
.options
.get( 'usenewrc' ) ?
107 mw
.loader
.using( [ 'mediawiki.special.changeslist.enhanced', 'mediawiki.icon' ] ) :
108 $.Deferred().resolve(),
111 this.$element
.toggleClass( 'mw-changeslist', !isEmpty
);
113 this.$element
.empty();
115 if ( this.filtersViewModel
.hasConflict() ) {
116 conflictItem
= this.filtersViewModel
.getFirstConflictedItem();
121 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-conflict' )
122 .text( mw
.message( 'rcfilters-noresults-conflict' ).text() ),
124 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-message' )
125 .text( mw
.message( conflictItem
.getCurrentConflictResultMessage() ).text() )
131 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-results-noresult' )
132 .text( mw
.message( 'recentchanges-noresult' ).text() )
136 this.$element
.append( $message
);
138 if ( !isInitialDOM
) {
139 this.$element
.empty().append( $changesListContent
);
142 this.emphasizeNewChanges( from );
146 // Set up highlight containers
147 this.setupHighlightContainers( this.$element
);
150 this.applyHighlight();
154 loaderPromise
.done( function () {
155 if ( !isInitialDOM
&& !isEmpty
) {
156 // Make sure enhanced RC re-initializes correctly
157 mw
.hook( 'wikipage.content' ).fire( widget
.$element
);
160 $( '.rcfilters-spinner' ).addClass( 'mw-rcfilters-ui-ready' );
161 widget
.$element
.addClass( 'mw-rcfilters-ui-ready' );
166 * Emphasize the elements (or groups) newer than the 'from' parameter
167 * @param {string} from Anything newer than this is considered 'new'
169 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.emphasizeNewChanges = function ( from ) {
172 $newChanges
= $( [] ),
173 selector
= this.inEnhancedMode() ?
174 'table.mw-enhanced-rc[data-mw-ts]' :
176 set = this.$element
.find( selector
),
179 set.each( function ( index
) {
180 var $this = $( this ),
181 ts
= $this.data( 'mw-ts' );
184 $newChanges
= $newChanges
.add( $this );
187 // guards against putting the marker after the last element
188 if ( index
=== ( length
- 1 ) ) {
195 $indicator
= $( '<div>' )
196 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-previousChangesIndicator' )
197 .text( mw
.message( 'rcfilters-previous-changes-label' ).text() );
199 $indicator
.on( 'click', function () {
203 $lastSeen
.after( $indicator
);
212 * Respond to changes list model newChangesExist
214 * @param {boolean} newChangesExist Whether new changes exist
216 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onNewChangesExist = function ( newChangesExist
) {
217 this.showNewChangesLink
.toggle( newChangesExist
);
221 * Respond to the user clicking the 'show new changes' button
223 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.onShowNewChangesClick = function () {
224 this.controller
.showNewChanges();
228 * Setup the container for the 'new changes' button.
230 * @param {jQuery} $content
232 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.setupNewChangesButtonContainer = function ( $content
) {
233 this.showNewChangesLink
= new OO
.ui
.ButtonWidget( {
235 label
: mw
.message( 'rcfilters-show-new-changes' ).text(),
236 flags
: [ 'progressive' ]
238 this.showNewChangesLink
.connect( this, { click
: 'onShowNewChangesClick' } );
239 this.showNewChangesLink
.toggle( false );
243 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-newChanges' )
244 .append( this.showNewChangesLink
.$element
)
249 * Set up the highlight containers with all color circle indicators.
251 * @param {jQuery|string} $content The content of the updated changes list
253 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.setupHighlightContainers = function ( $content
) {
254 var highlightClass
= 'mw-rcfilters-ui-changesListWrapperWidget-highlights',
255 $highlights
= $( '<div>' )
256 .addClass( highlightClass
)
259 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-none' )
260 .prop( 'data-color', 'none' )
263 if ( $( '.mw-rcfilters-ui-changesListWrapperWidget-highlights' ).length
) {
268 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
271 .addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlights-color-' + color
)
272 .prop( 'data-color', color
)
276 if ( this.inEnhancedMode() ) {
278 $content
.find( 'td.mw-enhanced-rc' )
282 .append( $highlights
.clone() )
286 $content
.find( 'ul.special li' )
287 .prepend( $highlights
.clone() );
292 * @return {boolean} Whether the changes are grouped by page
294 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.inEnhancedMode = function () {
295 var uri
= new mw
.Uri();
296 return ( uri
.query
.enhanced
!== undefined && Number( uri
.query
.enhanced
) ) ||
297 ( uri
.query
.enhanced
=== undefined && Number( mw
.user
.options
.get( 'usenewrc' ) ) );
301 * Apply color classes based on filters highlight configuration
303 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.applyHighlight = function () {
304 if ( !this.filtersViewModel
.isHighlightEnabled() ) {
308 this.filtersViewModel
.getHighlightedItems().forEach( function ( filterItem
) {
309 // Add highlight class to all highlighted list items
310 this.$element
.find( '.' + filterItem
.getCssClass() )
311 .addClass( 'mw-rcfilters-highlight-color-' + filterItem
.getHighlightColor() );
314 // Turn on highlights
315 this.$element
.addClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );
319 * Remove all color classes
321 mw
.rcfilters
.ui
.ChangesListWrapperWidget
.prototype.clearHighlight = function () {
322 // Remove highlight classes
323 mw
.rcfilters
.HighlightColors
.forEach( function ( color
) {
324 this.$element
.find( '.mw-rcfilters-highlight-color-' + color
).removeClass( 'mw-rcfilters-highlight-color-' + color
);
327 // Turn off highlights
328 this.$element
.removeClass( 'mw-rcfilters-ui-changesListWrapperWidget-highlighted' );