X-Git-Url: http://git.cyclocoop.org//%22%22.str_replace%28%27%22%27%2C?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fmw.rcfilters.Controller.js;h=98eaa59257e117004d3b254cf268bb670adf8c20;hb=904faf281ae365cf4d1575d7a5ac8617b3323b2e;hp=ec14aa6a76adba7b970fcd97e71b66eb762f6597;hpb=ed6b53179876e373a6016cfe08a10f3553a643bf;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js index ec14aa6a76..98eaa59257 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -62,7 +62,6 @@ // Check all filter interactions this.filtersModel.reassessFilterInteractions(); - this.updateURL(); this.updateChangesList(); }; @@ -75,7 +74,6 @@ // Check all filter interactions this.filtersModel.reassessFilterInteractions(); - this.updateURL(); this.updateChangesList(); }; @@ -95,7 +93,6 @@ obj[ filterName ] = isSelected; this.filtersModel.updateFilters( obj ); - this.updateURL(); this.updateChangesList(); // Check filter interactions @@ -105,9 +102,23 @@ /** * Update the URL of the page to reflect current filters + * + * This should not be called directly from outside the controller. + * If an action requires changing the URL, it should either use the + * highlighting actions below, or call #updateChangesList which does + * the uri corrections already. + * + * @private + * @param {Object} [params] Extra parameters to add to the API call */ - mw.rcfilters.Controller.prototype.updateURL = function () { - var uri = this.getUpdatedUri(); + mw.rcfilters.Controller.prototype.updateURL = function ( params ) { + var uri; + + params = params || {}; + + uri = this.getUpdatedUri(); + uri.extend( params ); + window.history.pushState( { tag: 'rcfilters' }, document.title, uri.toString() ); }; @@ -142,6 +153,7 @@ * Fetch the list of changes from the server for the current filters * * @return {jQuery.Promise} Promise object that will resolve with the changes list + * or with a string denoting no results. */ mw.rcfilters.Controller.prototype.fetchChangesList = function () { var uri = this.getUpdatedUri(), @@ -149,28 +161,63 @@ latestRequest = function () { return requestId === this.requestCounter; }.bind( this ); - uri.extend( this.filtersModel.getParametersFromFilters() ); + return $.ajax( uri.toString(), { contentType: 'html' } ) - .then( function ( html ) { - return latestRequest() ? - $( $.parseHTML( html ) ).find( '.mw-changeslist' ).first().contents() : - null; - } ).then( null, function () { - return latestRequest() ? 'NO_RESULTS' : null; - } ); + .then( + // Success + function ( html ) { + var $parsed; + if ( !latestRequest() ) { + return $.Deferred().reject(); + } + + $parsed = $( $.parseHTML( html ) ); + + return { + // Changes list + changes: $parsed.find( '.mw-changeslist' ).first().contents(), + // Fieldset + fieldset: $parsed.find( 'fieldset.rcoptions' ).first() + }; + }, + // Failure + function ( responseObj ) { + var $parsed; + + if ( !latestRequest() ) { + return $.Deferred().reject(); + } + + $parsed = $( $.parseHTML( responseObj.responseText ) ); + + // Force a resolve state to this promise + return $.Deferred().resolve( { + changes: 'NO_RESULTS', + fieldset: $parsed.find( 'fieldset.rcoptions' ).first() + } ).promise(); + } + ); }; /** * Update the list of changes and notify the model + * + * @param {Object} [params] Extra parameters to add to the API call */ - mw.rcfilters.Controller.prototype.updateChangesList = function () { + mw.rcfilters.Controller.prototype.updateChangesList = function ( params ) { + this.updateURL( params ); this.changesListModel.invalidate(); this.fetchChangesList() - .always( function ( changesListContent ) { - if ( changesListContent ) { - this.changesListModel.update( changesListContent ); - } - }.bind( this ) ); + .then( + // Success + function ( pieces ) { + var $changesListContent = pieces.changes, + $fieldset = pieces.fieldset; + + this.changesListModel.update( $changesListContent, $fieldset ); + }.bind( this ) + // Do nothing for failure + ); }; /**