Merge "Change 'editfont' default preference to 'monospace'"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / ui / mw.rcfilters.ui.ChangesLimitButtonWidget.js
index 61ee4a5..c2f20b7 100644 (file)
@@ -2,6 +2,7 @@
        /**
         * Widget defining the button controlling the popup for the number of results
         *
+        * @class
         * @extends OO.ui.Widget
         *
         * @constructor
         * Respond to model initialize event
         */
        mw.rcfilters.ui.ChangesLimitButtonWidget.prototype.onModelInitialize = function () {
-               var changesLimitPopupWidget, selectedItem, currentValue;
+               var changesLimitPopupWidget, selectedItem, currentValue,
+                       displayGroupModel = this.model.getGroup( 'display' );
 
                this.limitGroupModel = this.model.getGroup( 'limit' );
+               this.groupByPageItemModel = displayGroupModel.getItemByParamName( 'enhanced' );
 
                // HACK: We need the model to be ready before we populate the button
                // and the widget, because we require the filter items for the
@@ -51,7 +54,8 @@
                // Note: This will be fixed soon!
                if ( this.limitGroupModel ) {
                        changesLimitPopupWidget = new mw.rcfilters.ui.ChangesLimitPopupWidget(
-                               this.limitGroupModel
+                               this.limitGroupModel,
+                               this.groupByPageItemModel
                        );
 
                        selectedItem = this.limitGroupModel.getSelectedItems()[ 0 ];
@@ -66,7 +70,7 @@
                                        width: 300,
                                        padded: true,
                                        anchor: false,
-                                       align: 'backwards',
+                                       align: 'forwards',
                                        $autoCloseIgnore: this.$overlay,
                                        $content: changesLimitPopupWidget.$element
                                }
 
                        // Events
                        this.limitGroupModel.connect( this, { update: 'onLimitGroupModelUpdate' } );
-                       changesLimitPopupWidget.connect( this, { limit: 'onPopupLimit' } );
+                       changesLimitPopupWidget.connect( this, {
+                               limit: 'onPopupLimit',
+                               groupByPage: 'onPopupGroupByPage'
+                       } );
 
                        this.$element.append( this.button.$element );
                }
         * @param {string} filterName Chosen filter name
         */
        mw.rcfilters.ui.ChangesLimitButtonWidget.prototype.onPopupLimit = function ( filterName ) {
+               var item = this.limitGroupModel.getItemByName( filterName );
+
                this.controller.toggleFilterSelect( filterName, true );
+               this.controller.updateLimitDefault( item.getParamName() );
+               this.button.popup.toggle( false );
+       };
+
+       /**
+        * Respond to popup limit change event
+        *
+        * @param {boolean} isGrouped The result set is grouped by page
+        */
+       mw.rcfilters.ui.ChangesLimitButtonWidget.prototype.onPopupGroupByPage = function ( isGrouped ) {
+               this.controller.toggleFilterSelect( this.groupByPageItemModel.getName(), isGrouped );
+               this.controller.updateGroupByPageDefault( Number( isGrouped ) );
+               this.button.popup.toggle( false );
        };
 
        /**