Merge "Temporary hax to hide cawiki's hacked in search sidebar"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.FilterItem.js
index 63db0ea..5dfb68d 100644 (file)
         * @cfg {string} [group] The group this item belongs to
         * @cfg {string} [label] The label for the filter
         * @cfg {string} [description] The description of the filter
-        * @cfg {boolean} [selected] Filter is selected
+        * @cfg {boolean} [active=true] The filter is active and affecting the result
+        * @cfg {string[]} [excludes=[]] A list of filter names this filter, if
+        *  selected, makes inactive.
+        * @cfg {boolean} [default] The default state of this filter
         */
        mw.rcfilters.dm.FilterItem = function MwRcfiltersDmFilterItem( name, config ) {
                config = config || {};
                this.group = config.group || '';
                this.label = config.label || this.name;
                this.description = config.description;
+               this.default = !!config.default;
 
-               this.selected = !!config.selected;
+               this.active = config.active === undefined ? true : !!config.active;
+               this.excludes = config.excludes || [];
+               this.selected = this.default;
        };
 
        /* Initialization */
                return this.description;
        };
 
+       /**
+        * Get the default value of this filter
+        *
+        * @return {boolean} Filter default
+        */
+       mw.rcfilters.dm.FilterItem.prototype.getDefault = function () {
+               return this.default;
+       };
+
        /**
         * Get the selected state of this filter
         *
                return this.selected;
        };
 
+       /**
+        * Check if this filter is active
+        *
+        * @return {boolean} Filter is active
+        */
+       mw.rcfilters.dm.FilterItem.prototype.isActive = function () {
+               return this.active;
+       };
+
+       /**
+        * Check if this filter has a list of excluded filters
+        *
+        * @return {boolean} Filter has a list of excluded filters
+        */
+       mw.rcfilters.dm.FilterItem.prototype.hasExcludedFilters = function () {
+               return !!this.excludes.length;
+       };
+
+       /**
+        * Get this filter's list of excluded filters
+        *
+        * @return {string[]} Array of excluded filter names
+        */
+       mw.rcfilters.dm.FilterItem.prototype.getExcludedFilters = function () {
+               return this.excludes;
+       };
+
+       /**
+        * Toggle the active state of the item
+        *
+        * @param {boolean} [isActive] Filter is active
+        * @fires update
+        */
+       mw.rcfilters.dm.FilterItem.prototype.toggleActive = function ( isActive ) {
+               isActive = isActive === undefined ? !this.active : isActive;
+
+               if ( this.active !== isActive ) {
+                       this.active = isActive;
+                       this.emit( 'update' );
+               }
+       };
+
        /**
         * Toggle the selected state of the item
         *