Merge "Replace deprecated Context::getStats() with MWServices::getStatsdDataFactory()"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.FiltersViewModel.js
index cf51424..f04cc85 100644 (file)
                } );
        };
 
+       /**
+        * Get whether the model has any conflict in its items
+        *
+        * @return {boolean} There is a conflict
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.hasConflict = function () {
+               return this.getItems().some( function ( filterItem ) {
+                       return filterItem.isSelected() && filterItem.isConflicted();
+               } );
+       };
+
+       /**
+        * Get the first item with a current conflict
+        *
+        * @return {mw.rcfilters.dm.FilterItem} Conflicted item
+        */
+       mw.rcfilters.dm.FiltersViewModel.prototype.getFirstConflictedItem = function () {
+               var conflictedItem;
+
+               $.each( this.getItems(), function ( index, filterItem ) {
+                       if ( filterItem.isSelected() && filterItem.isConflicted() ) {
+                               conflictedItem = filterItem;
+                               return false;
+                       }
+               } );
+
+               return conflictedItem;
+       };
+
        /**
         * Set filters and preserve a group relationship based on
         * the definition given by an object
                                                adjustedConflicts = {};
 
                                        conflicts.forEach( function ( conflict ) {
+                                               var filter;
+
                                                if ( conflict.filter ) {
                                                        filterName = model.groups[ conflict.group ].getNamePrefix() + conflict.filter;
+                                                       filter = model.getItemByName( filterName );
 
                                                        // Rename
                                                        adjustedConflicts[ filterName ] = $.extend(
                                                                {},
                                                                conflict,
-                                                               { filter: filterName }
+                                                               {
+                                                                       filter: filterName,
+                                                                       item: filter
+                                                               }
                                                        );
                                                } else {
                                                        // This conflict is for an entire group. Split it up to
                                                                adjustedConflicts[ groupItem.getName() ] = $.extend(
                                                                        {},
                                                                        conflict,
-                                                                       { filter: groupItem.getName() }
+                                                                       {
+                                                                               filter: groupItem.getName(),
+                                                                               item: groupItem
+                                                                       }
                                                                );
                                                        } );
                                                }
                                        type: data.type,
                                        title: mw.msg( data.title ),
                                        separator: data.separator,
-                                       fullCoverage: !!data.fullCoverage
+                                       fullCoverage: !!data.fullCoverage,
+                                       whatsThis: {
+                                               body: data.whatsThisBody,
+                                               header: data.whatsThisHeader,
+                                               linkText: data.whatsThisLinkText,
+                                               url: data.whatsThisUrl
+                                       }
                                } );
                        }
 
                        }
                } );
 
+               // Add items to the model
+               this.addItems( items );
+
                // Expand conflicts
                groupConflictResult = expandConflictDefinitions( groupConflictMap );
                filterConflictResult = expandConflictDefinitions( filterConflictMap );
                        }
                } );
 
-               // Add items to the model
-               this.addItems( items );
-
                this.emit( 'initialize' );
        };