Hiding boxes did not work properly
authorMarcel Werk <burntime@woltlab.com>
Mon, 13 Jun 2022 15:47:58 +0000 (17:47 +0200)
committerMarcel Werk <burntime@woltlab.com>
Mon, 13 Jun 2022 15:47:58 +0000 (17:47 +0200)
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/acp/templates/boxAdd.tpl
wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php

index 64489461c9b05ad0543abacfc2bdc0d526afeb2f..84fc009e08302fbcae7bcf78f92dfea829786d87 100644 (file)
                        <conditiongroup>general</conditiongroup>
                </type>
                <!-- /notice conditions -->
-               <!-- box conditions -->
-               <type>
-                       <name>com.woltlab.wcf.page</name>
-                       <definitionname>com.woltlab.wcf.condition.box</definitionname>
-                       <classname>wcf\system\condition\page\MultiPageCondition</classname>
-                       <conditionobject>com.woltlab.wcf.page</conditionobject>
-               </type>
-               <!-- /box conditions -->
                <!-- ad locations -->
                <type>
                        <name>com.woltlab.wcf.logo</name>
                <type name="com.woltlab.wcf.searchEngineConvertInnoDb">
                        <definitionname>com.woltlab.wcf.rebuildData</definitionname>
                </type>
+               <type name="com.woltlab.wcf.page">
+                       <definitionname>com.woltlab.wcf.condition.box</definitionname>
+               </type>
        </delete>
 </data>
index fde8d0882223664e88c0c6c133f1bf99eefab01e..bcab786de6126721001aab43656b7a7bf31ac83d 100644 (file)
                                        <h2 class="sectionTitle">{lang}wcf.acp.box.conditions.page{/lang}</h2>
                                </header>
 
+                               <dl>
+                                       <dt></dt>
+                                       <dd>
+                                               <label><input type="checkbox" id="visibleEverywhere" name="visibleEverywhere" value="1"{if $visibleEverywhere} checked{/if}> {lang}wcf.acp.box.visibleEverywhere{/lang}</label>
+                                               <script data-relocate="true">
+                                                       require([], function() {
+                                                               // visibility toggle
+                                                               var visibilityExceptionHidden = elById('visibilityExceptionHidden');
+                                                               var visibilityExceptionVisible = elById('visibilityExceptionVisible');
+                                                               elById('visibleEverywhere').addEventListener('change', function() {
+                                                                       window[this.checked ? 'elShow' : 'elHide'](visibilityExceptionHidden);
+                                                                       window[this.checked ? 'elHide' : 'elShow'](visibilityExceptionVisible);
+                                                               });
+                                                       });
+                                               </script>
+                                       </dd>
+                               </dl>
+
+                               <dl>
+                                       <dt>
+                                               <span id="visibilityExceptionVisible"{if $visibleEverywhere} style="display: none"{/if}>{lang}wcf.acp.box.visibilityException.visible{/lang}</span>
+                                               <span id="visibilityExceptionHidden"{if !$visibleEverywhere} style="display: none"{/if}>{lang}wcf.acp.box.visibilityException.hidden{/lang}</span>
+                                       </dt>
+                                       <dd>
+                                               {include file='scrollablePageCheckboxList' pageCheckboxListContainerID='boxVisibilitySettings' pageCheckboxID='pageIDs'}
+                                       </dd>
+                               </dl>
+
                                {foreach from=$groupedConditionObjectTypes['com.woltlab.wcf.page'] item='pageConditionObjectType'}
                                        {@$pageConditionObjectType->getProcessor()->getHtml()}
                                {/foreach}
index 5b0f3ed884757b95934c11f1aa7a279b29a5a6ff..3ba48d10671094cd81b43126192bdc52e540d7fa 100644 (file)
@@ -17,7 +17,6 @@ use wcf\system\acl\simple\SimpleAclHandler;
 use wcf\system\box\IBoxController;
 use wcf\system\box\IConditionBoxController;
 use wcf\system\condition\ConditionHandler;
-use wcf\system\condition\page\MultiPageCondition;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\UserInputException;
@@ -339,6 +338,9 @@ class BoxAddForm extends AbstractForm
         if (isset($_POST['showOrder'])) {
             $this->showOrder = \intval($_POST['showOrder']);
         }
+        if (isset($_POST['visibleEverywhere'])) {
+            $this->visibleEverywhere = \intval($_POST['visibleEverywhere']);
+        }
         if (isset($_POST['cssClassName'])) {
             $this->cssClassName = StringUtil::trim($_POST['cssClassName']);
         }
@@ -348,6 +350,9 @@ class BoxAddForm extends AbstractForm
         if (isset($_POST['isDisabled'])) {
             $this->isDisabled = 1;
         }
+        if (isset($_POST['pageIDs']) && \is_array($_POST['pageIDs'])) {
+            $this->pageIDs = ArrayUtil::toIntegerArray($_POST['pageIDs']);
+        }
         if (isset($_POST['linkType'])) {
             $this->linkType = $_POST['linkType'];
         }
@@ -399,36 +404,8 @@ class BoxAddForm extends AbstractForm
 
     private function readConditions(): void
     {
-        $pageConditionObjectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
-            Box::VISIBILITY_CONDITIONS_OBJECT_TYPE_NAME,
-            'com.woltlab.wcf.page'
-        );
-
-        $this->pageIDs = $this->visibleEverywhere = null;
         foreach ($this->toFlatList($this->groupedConditionObjectTypes) as $objectType) {
             $objectType->getProcessor()->readFormParameters();
-            if ($objectType->objectTypeID == $pageConditionObjectTypeID) {
-                \assert($objectType->getProcessor() instanceof MultiPageCondition);
-
-                $data = $objectType->getProcessor()->getData();
-                if ($data !== null) {
-                    $this->pageIDs = $data['pageIDs'];
-                    $this->visibleEverywhere = $data['pageIDs_reverseLogic'] ? 1 : 0;
-                } else {
-                    $this->pageIDs = [];
-                    $this->visibleEverywhere = 1;
-                }
-            }
-        }
-
-        if ($this->pageIDs === null || $this->visibleEverywhere === null) {
-            throw new \LogicException(
-                \sprintf(
-                    "The '%s' condition for the definition '%s' is missing.",
-                    'com.woltlab.wcf.page',
-                    Box::VISIBILITY_CONDITIONS_OBJECT_TYPE_NAME
-                )
-            );
         }
     }