From: Matthias Schmidt Date: Fri, 29 Jul 2016 19:23:54 +0000 (+0200) Subject: Update WCF.ACP.Ad.LocationHandler X-Git-Tag: 3.0.0_Beta_1~897 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0360f61bf192a2e3dfb9c9d20a1fd8937e069ae5;p=GitHub%2FWoltLab%2FWCF.git Update WCF.ACP.Ad.LocationHandler --- diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 949c0e28e9..c1a8b12697 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -2518,35 +2518,46 @@ WCF.ACP.Ad.LocationHandler = Class.extend({ /** * select element for the page controller condition - * @var jQuery + * @var jQuery[] */ - _pageControllers: null, + _pageInputs: [], /** * Initializes a new WCF.ACP.Ad.LocationHandler object. */ init: function() { this._pageConditions = $('#pageConditions'); - this._pageControllers = $('#pageControllers'); + this._pageInputs = $('input[name="pageIDs[]"]'); - var $dl = this._pageControllers.parents('dl:eq(0)'); + var dl = $(this._pageInputs[0]).parents('dl:eq(0)'); // hide the page controller element - $dl.hide(); + dl.hide(); - var $fieldset = $dl.parent('fieldset'); - if (!$fieldset.children('dl:visible').length) { - $fieldset.hide(); + var section = dl.parent('section'); + if (!section.children('dl:visible').length) { + section.hide(); } - var $nextFieldset = $fieldset.next('fieldset'); - if ($nextFieldset) { - $nextFieldset.data('margin-top', $nextFieldset.css('margin-top')); - $nextFieldset.css('margin-top', 0); + var nextSection = section.next('section'); + if (nextSection) { + var marginTop = nextSection.css('margin-top'); + nextSection.css('margin-top', 0); + + require(['EventHandler'], function(EventHandler) { + EventHandler.add('com.woltlab.wcf.pageConditionDependence', 'checkVisivility', function() { + if (section.is(':visible')) { + nextSection.css('margin-top', marginTop); + } + else { + nextSection.css('margin-top', 0); + } + }); + }); } // fix the margin of a potentially next page condition element - $dl.next('dl').css('margin-top', 0); + dl.next('dl').css('margin-top', 0); $('#objectTypeID').on('change', $.proxy(this._setPageController, this)); @@ -2559,16 +2570,30 @@ WCF.ACP.Ad.LocationHandler = Class.extend({ * Sets the page controller based on the selected ad location. */ _setPageController: function() { - var $option = $('#objectTypeID').find('option:checked'); + var option = $('#objectTypeID').find('option:checked'); - // check if the selected ad location is bound to a specific page - if ($option.data('page')) { + require(['Core'], function(Core) { + var input, triggerEvent; + // select the related page - this._pageControllers.val([this._pageControllers.find('option[data-object-type="' + $option.data('page') + '"]').val()]).change(); - } - else { - this._pageControllers.val([]).change(); - } + for (var i = 0, length = this._pageInputs.length; i < length; i++) { + input = this._pageInputs[i]; + triggerEvent = false; + + if (option.data('page') && elData(input, 'identifier') === option.data('page')) { + if (!input.checked) triggerEvent = true; + + input.checked = true; + } + else { + if (input.checked) triggerEvent = true; + + input.checked = false; + } + + if (triggerEvent) Core.triggerEvent(this._pageInputs[i], 'change'); + } + }.bind(this)); }, /** @@ -2583,7 +2608,9 @@ WCF.ACP.Ad.LocationHandler = Class.extend({ else { // reset page controller conditions to avoid creation of // unnecessary conditions - this._pageControllers.val([]); + for (var i = 0, length = this._pageInputs.length; i < length; i++) { + this._pageInputs[i].checked = false; + } } } }); diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Controller/Condition/Page/Dependence.js b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Condition/Page/Dependence.js index 8836888252..7576f85c23 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Controller/Condition/Page/Dependence.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Controller/Condition/Page/Dependence.js @@ -6,32 +6,40 @@ * @license GNU Lesser General Public License * @module WoltLab/WCF/Controller/Condition/Page/Dependence */ -define(['Dom/Traverse'], function(DomTraverse) { +define(['Dom/ChangeListener', 'Dom/Traverse', 'EventHandler', 'ObjectMap'], function(DomChangeListener, DomTraverse, EventHandler, ObjectMap) { "use strict"; var _pages = elBySelAll('input[name="pageIDs[]"]'); + var _dependentElements = []; + var _pageIds = new ObjectMap(); + var _hiddenElements = new ObjectMap(); - /** - * @constructor - */ - function ControllerConditionPageDependence(dependentElement, pageIds) { - this._dependentElement = dependentElement; - this._pageIds = pageIds; - - for (var i = 0, length = _pages.length; i < length; i++) { - _pages[i].addEventListener('change', this._checkVisibility.bind(this)); - } - - // remove the dependent element before submit if it is hidden - DomTraverse.parentByTag(this._dependentElement, 'FORM').addEventListener('submit', function() { - if (this._dependentElement.style.getPropertyValue('display') === 'none') { - this._dependentElement.remove(); + var _didInit = false; + + return { + register: function(dependentElement, pageIds) { + _dependentElements.push(dependentElement); + _pageIds.set(dependentElement, pageIds); + _hiddenElements.set(dependentElement, []); + + if (!_didInit) { + for (var i = 0, length = _pages.length; i < length; i++) { + _pages[i].addEventListener('change', this._checkVisibility.bind(this)); + } + + _didInit = true; } - }.bind(this)); + + // remove the dependent element before submit if it is hidden + DomTraverse.parentByTag(dependentElement, 'FORM').addEventListener('submit', function() { + if (dependentElement.style.getPropertyValue('display') === 'none') { + dependentElement.remove(); + } + }); + + this._checkVisibility(); + }, - this._checkVisibility(); - }; - ControllerConditionPageDependence.prototype = { /** * Checks if any of the relevant pages is selected. If that is the case, the dependent * element is shown, otherwise it is hidden. @@ -39,17 +47,51 @@ define(['Dom/Traverse'], function(DomTraverse) { * @private */ _checkVisibility: function() { - var page; - for (var i = 0, length = _pages.length; i < length; i++) { - page = _pages[i]; + var dependentElement, page, pageIds; + + depenentElementLoop: for (var i = 0, length = _dependentElements.length; i < length; i++) { + dependentElement = _dependentElements[i]; + pageIds = _pageIds.get(dependentElement); - if (page.checked && this._pageIds.indexOf(~~page.value) !== -1) { - elShow(this._dependentElement); - return; + 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; + } } + + this._hideDependentElement(dependentElement); + } + + EventHandler.fire('com.woltlab.wcf.pageConditionDependence', 'checkVisivility'); + }, + + _hideDependentElement: function(dependentElement) { + elHide(dependentElement); + + var hiddenElements = _hiddenElements.get(dependentElement); + for (var i = 0, length = hiddenElements.length; i < length; i++) { + elHide(hiddenElements[i]); } - elHide(this._dependentElement); + _hiddenElements.set(dependentElement, []) + }, + + _showDependentElement: function(dependentElement) { + elShow(dependentElement); + + // make sure that all parent elements are also visible + var parentNode = dependentElement; + while ((parentNode = parentNode.parentNode) && parentNode instanceof Element) { + if (parentNode.style.getPropertyValue('display') === 'none') { + _hiddenElements.get(dependentElement).push(parentNode); + } + + elShow(parentNode); + } } }; diff --git a/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php b/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php index 7a9e35a19a..6795cc3aae 100644 --- a/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php @@ -43,7 +43,7 @@ class MultiPageCondition extends AbstractMultiSelectCondition implements IConten if ($pageNode->getDepth() > 1) { $fieldElement .= ' style="padding-left: '.($pageNode->getDepth()*20-20).'px"'; } - $fieldElement .= '>