Update page condition
authorMatthias Schmidt <gravatronics@live.com>
Sun, 22 May 2016 14:30:38 +0000 (16:30 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 22 May 2016 14:30:42 +0000 (16:30 +0200)
CHANGELOG.md
wcfsetup/install/files/acp/templates/noticeAdd.tpl
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/js/WoltLab/WCF/Controller/Condition/Page/Dependence.js [new file with mode: 0644]
wcfsetup/install/files/lib/data/page/PageCache.class.php
wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php

index 7740d5b7a93ba787d686ae3c45584fc417ad7605..9e654cb4a24fe68bb1328efad53f126b170a8879 100644 (file)
@@ -46,6 +46,7 @@
 * Overhauled style editor
 * Added replacements for WCF.Like, WCF.User.List and $.ui.wcfPages
 * Added update support for styles
+* `\wcf\system\condition\MultiPageControllerCondition` has been replaced by `wcf\system\condition\page\MultiPageCondition`
 
 #### CMS
 
 * Renamed `.pageNavigation` to `.pagination`
 * Renamed `.navigation`/`.navigationIcons` to `.pageNavigation`/`.pageNavigationIcons`
 
+#### Deprecated Code
+
+* Object type definition `com.woltlab.wcf.user.online.location` deprecated.
+* Object type definition `com.woltlab.wcf.page` deprecated.
+
 #### Removed Code
 
 * `wcf\system\clipboard\action\UserExtendedClipboardAction` removed.
 * Version system removed.
 * Support for query string based sessions in Frontend removed.
 * Language server system removed.
-* Object type definition `com.woltlab.wcf.user.online.location` deprecated.
-* Object type definition `com.woltlab.wcf.page` deprecated.
 * Deprecated methods in `wcf\util\StringUtil` removed.
 * Option `message_sidebar_enable_message_group_starter_icon` removed.
 * Option `module_privacy_policy_page` removed.
index 7b60fe1e509241bb2da4eb96600c993ae30bd444..44b426e65da22fcd1505cb30a2c6a944dbd19521 100644 (file)
@@ -3,8 +3,6 @@
 <script data-relocate="true">
        //<![CDATA[
        $(function() {
-               WCF.TabMenu.init();
-               
                $('input[name=cssClassName]').change(function() {
                        var $val = $('input[name=cssClassName]:checked').val();
                        if (!$val || $val === 'custom') {
                </header>
        
                {include file='userConditions' groupedObjectTypes=$groupedConditionObjectTypes['com.woltlab.wcf.user']}
-       </section>      
-               
+       </section>
+       
        {event name='conditionContainers'}
        
        <div class="formSubmit">
index 5b64b87e32d59b163bb5e55912ebba4caac40948..333ff40498b4af84587458ec8c3f512c80269aec 100755 (executable)
@@ -8046,89 +8046,6 @@ WCF.Category.FlexibleCategoryList = Class.extend({
  */
 WCF.Condition = { };
 
-/**
- * Handles displaying the a form element whose visibility depends on the selected
- * page controllers.
- */
-WCF.Condition.PageControllerDependence = Class.extend({
-       /**
-        * select list with the available page controllers
-        * @var jQuery
-        */
-       _pageControllerSelection: null,
-       
-       /**
-        * ids of page object types that support the form element
-        * @var array<integer>
-        */
-       _supportedPageObjectTypeIDs: [],
-       
-       /**
-        * Initializes a new WCF.Condition.PageControllerDependence object.
-        * 
-        * @param       string                  inputIdentifier
-        * @param       array<integer>          supportedPageObjectTypeIDs
-        */
-       init: function(inputIdentifier, supportedPageObjectTypeIDs) {
-               this._supportedPageObjectTypeIDs = supportedPageObjectTypeIDs;
-               
-               this._pageControllerSelection = $('#pageControllers').change($.proxy(this._checkVisibility, this));
-               this._pageControllerContainer = this._pageControllerSelection.parents('dl:eq(0)');
-               this._fieldset = this._pageControllerContainer.parent('fieldset');
-               this._nextFieldset = this._fieldset.next('fieldset');
-               if (this._nextFieldset) {
-                       this._nextFieldset.data('margin-top', this._nextFieldset.css('margin-top'));
-               }
-               
-               this._input = $('#' + inputIdentifier);
-               this._inputContainer = this._input.parents('dl:eq(0)');
-               
-               this._checkVisibility();
-       },
-       
-       /**
-        * Checks the visibility based on the selected page controllers.
-        */
-       _checkVisibility: function() {
-               var $selectedPageIDs = this._pageControllerSelection.val() || [ ];
-               
-               var $display = true;
-               if ($selectedPageIDs.length) {
-                       for (var $i = 0, $length = $selectedPageIDs.length; $i < $length; $i++) {
-                               if (this._supportedPageObjectTypeIDs.indexOf(parseInt($selectedPageIDs[$i])) == -1) {
-                                       $display = false;
-                                       break;
-                               }
-                       }
-               }
-               else {
-                       $display = false;
-               }
-               
-               if ($display) {
-                       this._inputContainer.show();
-                       this._input.enable();
-                       this._fieldset.show();
-                       
-                       if (this._nextFieldset) {
-                               this._nextFieldset.css('margin-top', this._nextFieldset.data('margin-top'));
-                       }
-               }
-               else {
-                       this._inputContainer.hide();
-                       this._input.disable();
-                       
-                       if (!this._fieldset.children('dl:visible').length) {
-                               this._fieldset.hide();
-                               
-                               if (this._nextFieldset) {
-                                       this._nextFieldset.css('margin-top', 0);
-                               }
-                       }
-               }
-       }
-});
-
 /**
  * Initialize WCF.Notice namespace.
  */
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
new file mode 100644 (file)
index 0000000..8d20e68
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * Shows and hides an element that dependes on certain selected pages when setting up conditions.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module     WoltLab/WCF/Controller/Condition/Page/Dependence
+ */
+define(['Dom/Traverse'], function(DomTraverse) {
+       "use strict";
+       
+       var _pages = elBySelAll('input[name="pageIDs[]"]');
+       
+       /**
+        * @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();
+                       }
+               }.bind(this));
+               
+               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.
+                * 
+                * @private
+                */
+               _checkVisibility: function() {
+                       var page;
+                       for (var i = 0, length = _pages.length; i < length; i++) {
+                               page = _pages[i];
+                               
+                               if (page.checked && this._pageIds.indexOf(~~page.value) !== -1) {
+                                       elShow(this._dependentElement);
+                                       return;
+                               }
+                       }
+                       
+                       elHide(this._dependentElement);
+               }
+       };
+       
+       return ControllerConditionPageDependence;
+});
index 6519363bbd25edad117c2e6252eb028fbe83e860..f7302e83926485e5ed39c328956000b5bb81e09b 100644 (file)
@@ -29,6 +29,15 @@ class PageCache extends SingletonFactory {
                $this->cache = PageCacheBuilder::getInstance()->getData();
        }
        
+       /**
+        * Returns all available pages.
+        * 
+        * @return      Page[]
+        */
+       public function getPages() {
+               return $this->cache['pages'];
+       }
+       
        /**
         * Returns a page by page id or null.
         * 
index e4830d9481bbadabb0c677c72e67039eaa61d9a6..699ce28d0e65f9a32b1375ceeb41de7049d0fc42 100644 (file)
@@ -5,6 +5,7 @@ use wcf\data\page\PageCache;
 use wcf\data\page\PageNode;
 use wcf\data\page\PageNodeTree;
 use wcf\system\condition\AbstractMultiSelectCondition;
+use wcf\system\condition\AbstractSingleFieldCondition;
 use wcf\system\condition\IContentCondition;
 use wcf\system\exception\UserInputException;
 use wcf\system\request\RequestHandler;
@@ -18,14 +19,9 @@ use wcf\system\request\RequestHandler;
  * @package    com.woltlab.wcf
  * @subpackage system.condition.page
  * @category   Community Framework
- * @deprecated since 2.2
+ * @since      2.2
  */
 class MultiPageCondition extends AbstractMultiSelectCondition implements IContentCondition {
-       /**
-        * @inheritDoc
-        */
-       protected $description = 'wcf.global.multiSelect';
-       
        /**
         * @inheritDoc
         */
@@ -42,16 +38,31 @@ class MultiPageCondition extends AbstractMultiSelectCondition implements IConten
        protected function getFieldElement() {
                $pageNodes = (new PageNodeTree())->getNodeList();
                
-               $fieldElement = '<select name="'.$this->fieldName.'[]" id="'.$this->fieldName.'" multiple="multiple" size="10">';
+               $fieldElement = '<ul class="scrollableCheckboxList">';
                /** @var PageNode $pageNode */
                foreach ($pageNodes as $pageNode) {
-                       $fieldElement .= '<option value="'.$pageNode->pageID.'">'.($pageNode->getDepth() > 1 ? str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;", $pageNode->getDepth() - 1) : '').$pageNode->name.'</option>';
+                       $fieldElement .= '<li';
+                       if ($pageNode->getDepth() > 1) {
+                               $fieldElement .= ' style="padding-left: '.($pageNode->getDepth()*20-20).'px"';
+                       }
+                       $fieldElement .= '><label><input type="checkbox" name="'.$this->fieldName.'[]" value="'.$pageNode->pageID.'"';
+                       if (in_array($pageNode->pageID, $this->fieldValue)) {
+                               $fieldElement .= ' checked="checked"';
+                       }
+                       $fieldElement .= ' />'.$pageNode->name.'</label></li>';
                }
-               $fieldElement .= "</select>";
+               $fieldElement .= "</ul>";
                
                return $fieldElement;
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function getHTML() {
+               return AbstractSingleFieldCondition::getHTML();
+       }
+       
        /**
         * @inheritDoc
         */