this.changesListModel.update(
pieces.changes,
pieces.fieldset,
- pieces.noResultsDetails === 'NO_RESULTS_TIMEOUT',
+ pieces.noResultsDetails,
true // We're using existing DOM elements
);
}
* Reset to default filters
*/
mw.rcfilters.Controller.prototype.resetToDefaults = function () {
- this.filtersModel.updateStateFromParams( this._getDefaultParams() );
-
- this.updateChangesList();
+ var params = this._getDefaultParams();
+ if ( this.applyParamChange( params ) ) {
+ // Only update the changes list if there was a change to actual filters
+ this.updateChangesList();
+ } else {
+ this.uriProcessor.updateURL( params );
+ }
};
/**
* Empty all selected filters
*/
mw.rcfilters.Controller.prototype.emptyFilters = function () {
- var highlightedFilterNames = this.filtersModel
- .getHighlightedItems()
+ var highlightedFilterNames = this.filtersModel.getHighlightedItems()
.map( function ( filterItem ) { return { name: filterItem.getName() }; } );
- this.filtersModel.updateStateFromParams( {} );
-
- this.updateChangesList();
+ if ( this.applyParamChange( {} ) ) {
+ // Only update the changes list if there was a change to actual filters
+ this.updateChangesList();
+ } else {
+ this.uriProcessor.updateURL();
+ }
if ( highlightedFilterNames ) {
this._trackHighlight( 'clearAll', highlightedFilterNames );
return;
}
- // Apply parameters to model
- this.filtersModel.updateStateFromParams( params );
-
- this.updateChangesList();
+ if ( this.applyParamChange( params ) ) {
+ // Update changes list only if there was a difference in filter selection
+ this.updateChangesList();
+ } else {
+ this.uriProcessor.updateURL( params );
+ }
// Log filter grouping
this.trackFilterGroupings( 'savedfilters' );
* without adding an history entry.
*/
mw.rcfilters.Controller.prototype.replaceUrl = function () {
- this.uriProcessor.replaceUpdatedUri();
+ this.uriProcessor.updateURL();
};
/**
this.changesListModel.update(
$changesListContent,
$fieldset,
- pieces.noResultsDetails === 'NO_RESULTS_TIMEOUT',
+ pieces.noResultsDetails,
false,
// separator between old and new changes
updateMode === this.SHOW_NEW_CHANGES || updateMode === this.LIVE_UPDATE
return this._queryChangesList( 'updateChangesList' )
.then(
function ( data ) {
- var $parsed = $( '<div>' ).append( $( $.parseHTML( data.content ) ) );
+ var $parsed;
+
+ // Status code 0 is not HTTP status code,
+ // but is valid value of XMLHttpRequest status.
+ // It is used for variety of network errors, for example
+ // when an AJAX call was cancelled before getting the response
+ if ( data && data.status === 0 ) {
+ return {
+ changes: 'NO_RESULTS',
+ // We need empty result set, to avoid exceptions because of undefined value
+ fieldset: $( [] ),
+ noResultsDetails: 'NO_RESULTS_NETWORK_ERROR'
+ };
+ }
+
+ $parsed = $( '<div>' ).append( $( $.parseHTML( data.content ) ) );
return this._extractChangesListInfo( $parsed );
}
};
+ /**
+ * Apply a change of parameters to the model state, and check whether
+ * the new state is different than the old state.
+ *
+ * @param {Object} newParamState New parameter state to apply
+ * @return {boolean} New applied model state is different than the previous state
+ */
+ mw.rcfilters.Controller.prototype.applyParamChange = function ( newParamState ) {
+ var after,
+ before = this.filtersModel.getSelectedState();
+
+ this.filtersModel.updateStateFromParams( newParamState );
+
+ after = this.filtersModel.getSelectedState();
+
+ return !OO.compare( before, after );
+ };
+
/**
* Mark all changes as seen on Watchlist
*/