X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.rcfilters%2Fmw.rcfilters.Controller.js;h=e9981bdacc5b48be4b9ee6b5bd12f5e4b7132398;hb=f6e0d15a85104ec75de15a11b0e6cc9bc54cffeb;hp=f3ea248b4d9740728cb41f9de323c49ef0922275;hpb=c9eadaecf265472309eaff3a98bbb424a4d8a812;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 f3ea248b4d..e9981bdacc 100644 --- a/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js +++ b/resources/src/mediawiki.rcfilters/mw.rcfilters.Controller.js @@ -19,6 +19,10 @@ this.initializing = false; this.prevLoggedItems = []; + + this.FILTER_CHANGE = 'filterChange'; + this.SHOW_NEW_CHANGES = 'showNewChanges'; + this.LIVE_UPDATE = 'liveUpdate'; }; /* Initialization */ @@ -105,7 +109,7 @@ allowArbitrary: true, validate: $.isNumeric, range: { - min: 1, + min: 0, // The server normalizes negative numbers to 0 results max: 1000 }, sortFunc: function ( a, b ) { return Number( a.name ) - Number( b.name ); }, @@ -115,7 +119,7 @@ // we should remove all sticky behavior methods completely // See T172156 // isSticky: true, - filters: displayConfig.arrayLimit.map( function ( num ) { + filters: displayConfig.limitArray.map( function ( num ) { return controller._createFilterDataFromNumber( num, num ); } ) }, @@ -128,7 +132,7 @@ validate: $.isNumeric, range: { min: 0, - max: displayConfig.maxLimit + max: displayConfig.maxDays }, sortFunc: function ( a, b ) { return Number( a.name ) - Number( b.name ); }, numToLabelFunc: function ( i ) { @@ -143,7 +147,7 @@ // Hours (1, 2, 6, 12) 0.04166, 0.0833, 0.25, 0.5 // Days - ].concat( displayConfig.arrayDays ) + ].concat( displayConfig.daysArray ) .map( function ( num ) { return controller._createFilterDataFromNumber( num, @@ -489,7 +493,7 @@ mw.rcfilters.Controller.prototype.toggleLiveUpdate = function ( enable ) { this.changesListModel.toggleLiveUpdate( enable ); if ( this.changesListModel.getLiveUpdate() && this.changesListModel.getNewChangesExist() ) { - this.showNewChanges(); + this.updateChangesList( null, this.LIVE_UPDATE ); } }; @@ -522,7 +526,7 @@ if ( data.changes !== 'NO_RESULTS' ) { if ( this.changesListModel.getLiveUpdate() ) { - return this.updateChangesList( false, null, true, false ); + return this.updateChangesList( null, this.LIVE_UPDATE ); } else { this.changesListModel.setNewChangesExist( true ); } @@ -571,7 +575,7 @@ * fetching and showing the new changes */ mw.rcfilters.Controller.prototype.showNewChanges = function () { - return this.updateChangesList( false, null, true, true ); + return this.updateChangesList( null, this.SHOW_NEW_CHANGES ); }; /** @@ -987,19 +991,17 @@ /** * Update the list of changes and notify the model * - * @param {boolean} [updateUrl=true] Whether the URL should be updated with the current state of the filters * @param {Object} [params] Extra parameters to add to the API call - * @param {boolean} [isLiveUpdate=false] The purpose of this update is to show new results for the same filters - * @param {boolean} [invalidateCurrentChanges=true] Invalidate current changes by default (show spinner) + * @param {string} [updateMode='filterChange'] One of 'filterChange', 'liveUpdate', 'showNewChanges' * @return {jQuery.Promise} Promise that is resolved when the update is complete */ - mw.rcfilters.Controller.prototype.updateChangesList = function ( updateUrl, params, isLiveUpdate, invalidateCurrentChanges ) { - updateUrl = updateUrl === undefined ? true : updateUrl; - invalidateCurrentChanges = invalidateCurrentChanges === undefined ? true : invalidateCurrentChanges; - if ( updateUrl ) { + mw.rcfilters.Controller.prototype.updateChangesList = function ( params, updateMode ) { + updateMode = updateMode === undefined ? this.FILTER_CHANGE : updateMode; + + if ( updateMode === this.FILTER_CHANGE ) { this._updateURL( params ); } - if ( invalidateCurrentChanges ) { + if ( updateMode === this.FILTER_CHANGE || updateMode === this.SHOW_NEW_CHANGES ) { this.changesListModel.invalidate(); } this.changesListModel.setNewChangesExist( false ); @@ -1010,7 +1012,12 @@ function ( pieces ) { var $changesListContent = pieces.changes, $fieldset = pieces.fieldset; - this.changesListModel.update( $changesListContent, $fieldset, false, isLiveUpdate ); + this.changesListModel.update( + $changesListContent, + $fieldset, + false, + updateMode === this.SHOW_NEW_CHANGES + ); }.bind( this ) // Do nothing for failure )