Merge "Revert "Log the reason why revision->getContent() returns null""
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.FilterGroup.js
index 1950b93..a62acc5 100644 (file)
@@ -34,6 +34,7 @@
         * @cfg {string} [whatsThis.body] The body of the whatsThis popup message
         * @cfg {string} [whatsThis.url] The url for the link in the whatsThis popup message
         * @cfg {string} [whatsThis.linkMessage] The text for the link in the whatsThis popup message
+        * @cfg {boolean} [visible=true] The visibility of the group
         */
        mw.rcfilters.dm.FilterGroup = function MwRcfiltersDmFilterGroup( name, config ) {
                config = config || {};
@@ -52,6 +53,7 @@
                this.numericRange = config.range;
                this.separator = config.separator || '|';
                this.labelPrefixKey = config.labelPrefixKey;
+               this.visible = config.visible === undefined ? true : !!config.visible;
 
                this.currSelected = null;
                this.active = !!config.active;
                // Verify that single_option group has at least one item selected
                if (
                        this.getType() === 'single_option' &&
-                       this.getSelectedItems().length === 0
+                       this.findSelectedItems().length === 0
                ) {
                        defaultParam = groupDefault !== undefined ?
                                groupDefault : this.getItems()[ 0 ].getParamName();
                if ( this.getType() === 'single_option' ) {
                        // This group must have one item selected always
                        // and must never have more than one item selected at a time
-                       if ( this.getSelectedItems().length === 0 ) {
+                       if ( this.findSelectedItems().length === 0 ) {
                                // Nothing is selected anymore
                                // Select the default or the first item
                                this.currSelected = this.getItemByParamName( this.defaultParams[ this.getName() ] ) ||
                                        this.getItems()[ 0 ];
                                this.currSelected.toggleSelected( true );
                                changed = true;
-                       } else if ( this.getSelectedItems().length > 1 ) {
+                       } else if ( this.findSelectedItems().length > 1 ) {
                                // There is more than one item selected
                                // This should only happen if the item given
                                // is the one that is selected, so unselect
                                // all items that is not it
-                               this.getSelectedItems().forEach( function ( itemModel ) {
+                               this.findSelectedItems().forEach( function ( itemModel ) {
                                        // Note that in case the given item is actually
                                        // not selected, this loop will end up unselecting
                                        // all items, which would trigger the case above
                        }
                }
 
+               if ( this.isSticky() ) {
+                       // If this group is sticky, then change the default according to the
+                       // current selection.
+                       this.defaultParams = this.getParamRepresentation( this.getSelectedState() );
+               }
+
                if (
                        changed ||
                        this.active !== active ||
                        this.currSelected !== item
                ) {
-                       if ( this.isSticky() ) {
-                               // If this group is sticky, then change the default according to the
-                               // current selection.
-                               this.defaultParams = this.getParamRepresentation( this.getSelectedState() );
-                       }
-
                        this.active = active;
                        this.currSelected = item;
 
         * @param {mw.rcfilters.dm.FilterItem} [excludeItem] Item to exclude from the list
         * @return {mw.rcfilters.dm.FilterItem[]} Selected items
         */
-       mw.rcfilters.dm.FilterGroup.prototype.getSelectedItems = function ( excludeItem ) {
+       mw.rcfilters.dm.FilterGroup.prototype.findSelectedItems = function ( excludeItem ) {
                var excludeName = ( excludeItem && excludeItem.getName() ) || '';
 
                return this.getItems().filter( function ( item ) {
         * @return {boolean} All selected items are in conflict with this item
         */
        mw.rcfilters.dm.FilterGroup.prototype.areAllSelectedInConflictWith = function ( filterItem ) {
-               var selectedItems = this.getSelectedItems( filterItem );
+               var selectedItems = this.findSelectedItems( filterItem );
 
                return selectedItems.length > 0 &&
                        (
         * @return {boolean} Any of the selected items are in conflict with this item
         */
        mw.rcfilters.dm.FilterGroup.prototype.areAnySelectedInConflictWith = function ( filterItem ) {
-               var selectedItems = this.getSelectedItems( filterItem );
+               var selectedItems = this.findSelectedItems( filterItem );
 
                return selectedItems.length > 0 && (
                        // The group as a whole is in conflict with this item
                var state = {};
 
                this.getItems().forEach( function ( filterItem ) {
-                       state[ filterItem.getName() ] = filterItem.isSelected();
+                       state[ filterItem.getName() ] = filterItem.getValue();
                } );
 
                return state;
 
                return value;
        };
+
+       /**
+        * Toggle the visibility of this group
+        *
+        * @param {boolean} [isVisible] Item is visible
+        */
+       mw.rcfilters.dm.FilterGroup.prototype.toggleVisible = function ( isVisible ) {
+               isVisible = isVisible === undefined ? !this.visible : isVisible;
+
+               if ( this.visible !== isVisible ) {
+                       this.visible = isVisible;
+                       this.emit( 'update' );
+               }
+       };
+
+       /**
+        * Check whether the group is visible
+        *
+        * @return {boolean} Group is visible
+        */
+       mw.rcfilters.dm.FilterGroup.prototype.isVisible = function () {
+               return this.visible;
+       };
+
+       /**
+        * Set the visibility of the items under this group by the given items array
+        *
+        * @param {mw.rcfilters.dm.ItemModel[]} visibleItems An array of visible items
+        */
+       mw.rcfilters.dm.FilterGroup.prototype.setVisibleItems = function ( visibleItems ) {
+               this.getItems().forEach( function ( itemModel ) {
+                       itemModel.toggleVisible( visibleItems.indexOf( itemModel ) !== -1 );
+               } );
+       };
 }( mediaWiki ) );