Update behavior of page dependence condition controller
authorMatthias Schmidt <gravatronics@live.com>
Sun, 23 Apr 2017 16:21:00 +0000 (18:21 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 23 Apr 2017 16:21:00 +0000 (18:21 +0200)
The relevant element should only be shown when all selected pages are
accepted as the related condition is only guaranteed to work in these
instances and can cause other selected pages to be ignored.

wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Condition/Page/Dependence.js

index 543c791c09cc564a889ddf7e4fc838dcea57509d..2938d40cab505cf9ffe38f9763b9c4792017400a 100644 (file)
@@ -41,34 +41,47 @@ define(['Dom/ChangeListener', 'Dom/Traverse', 'EventHandler', 'ObjectMap'], func
                },
                
                /**
-                * Checks if any of the relevant pages is selected. If that is the case, the dependent
+                * Checks if only relevant pages are selected. If that is the case, the dependent
                 * element is shown, otherwise it is hidden.
                 * 
                 * @private
                 */
                _checkVisibility: function() {
-                       var dependentElement, page, pageIds;
+                       var dependentElement, page, pageIds, checkedPageIds, irrelevantPageIds;
                        
                        depenentElementLoop: for (var i = 0, length = _dependentElements.length; i < length; i++) {
                                dependentElement = _dependentElements[i];
                                pageIds = _pageIds.get(dependentElement);
                                
+                               checkedPageIds = [];
                                for (var j = 0, length2 = _pages.length; j < length2; j++) {
                                        page = _pages[j];
                                        
-                                       if (page.checked && pageIds.indexOf(~~page.value) !== -1) {
-                                               this._showDependentElement(dependentElement);
-                                               
-                                               continue depenentElementLoop;
+                                       if (page.checked) {
+                                               checkedPageIds.push(~~page.value);
                                        }
                                }
                                
-                               this._hideDependentElement(dependentElement);
+                               irrelevantPageIds = checkedPageIds.filter(function(pageId) {
+                                       return pageIds.indexOf(pageId) === -1;
+                               });
+                               
+                               if (!checkedPageIds.length || irrelevantPageIds.length) {
+                                       this._hideDependentElement(dependentElement);
+                               }
+                               else {
+                                       this._showDependentElement(dependentElement);
+                               }
                        }
                        
                        EventHandler.fire('com.woltlab.wcf.pageConditionDependence', 'checkVisivility');
                },
                
+               /**
+                * Hides all elements that depend on the given element.
+                * 
+                * @param       {HTMLElement}   dependentElement
+                */
                _hideDependentElement: function(dependentElement) {
                        elHide(dependentElement);
                        
@@ -80,6 +93,11 @@ define(['Dom/ChangeListener', 'Dom/Traverse', 'EventHandler', 'ObjectMap'], func
                        _hiddenElements.set(dependentElement, []);
                },
                
+               /**
+                * Shows all elements that depend on the given element.
+                * 
+                * @param       {HTMLElement}   dependentElement
+                */
                _showDependentElement: function(dependentElement) {
                        elShow(dependentElement);