From 5c2a59e72909db1c5083e8f0a329c9904778e8d4 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Tue, 9 Feb 2016 20:09:44 +0100 Subject: [PATCH] Make message_sidebar_user_options sortable --- CHANGELOG.md | 2 + com.woltlab.wcf/option.xml | 1 + .../acp/templates/useroptionsOptionType.tpl | 39 +++++++++++++++++-- .../files/js/WoltLab/WCF/Ui/TabMenu/Simple.js | 11 +++++- .../option/UseroptionsOptionType.class.php | 39 ++++++++++++------- 5 files changed, 73 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2046f3c4fd..de8656e303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ * Ported the PHP-BBCode parser, massively improves accuracy and ensures validity * Show error message if poll options are given but not question instead of discarding poll options. * `parentObjectID` column added to `modification_log` and `wcf\system\log\modification\AbstractModificationLogHandler` introduced as a replacement for `wcf\system\log\modification\ModificationLogHandler`. +* Add sort support for `useroptions` option type. +* Make user options shown in sidebar sortable. #### New Traits diff --git a/com.woltlab.wcf/option.xml b/com.woltlab.wcf/option.xml index 053be465ce..5e535db096 100644 --- a/com.woltlab.wcf/option.xml +++ b/com.woltlab.wcf/option.xml @@ -1429,6 +1429,7 @@ DESC:wcf.global.sortOrder.descending]]> message.sidebar useroptions + 1 diff --git a/wcfsetup/install/files/acp/templates/useroptionsOptionType.tpl b/wcfsetup/install/files/acp/templates/useroptionsOptionType.tpl index 9b500ceacc..2bf3f5d843 100644 --- a/wcfsetup/install/files/acp/templates/useroptionsOptionType.tpl +++ b/wcfsetup/install/files/acp/templates/useroptionsOptionType.tpl @@ -1,3 +1,36 @@ -{foreach from=$availableOptions item=availableOption} - -{/foreach} +{if $option->issortable} + + +
+
    + {foreach from=$availableOptions item=availableOption} +
  1. + + + +
  2. + {/foreach} +
+
+{else} + {foreach from=$availableOptions item=availableOption} + + {/foreach} +{/if} \ No newline at end of file diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ui/TabMenu/Simple.js b/wcfsetup/install/files/js/WoltLab/WCF/Ui/TabMenu/Simple.js index 50d3952686..e35b09a547 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/Ui/TabMenu/Simple.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/Ui/TabMenu/Simple.js @@ -199,7 +199,7 @@ define(['Dictionary', 'Dom/Traverse', 'Dom/Util', 'EventHandler'], function(Dict name = name || elAttr(tab, 'data-name'); // unmark active tab - var oldTab = elBySel('#' + this._container.id + ' > nav > ul > li.active'); + var oldTab = this.getActiveTab(); var oldContent = null; if (oldTab) { oldTab.classList.remove('active'); @@ -305,6 +305,15 @@ define(['Dictionary', 'Dom/Traverse', 'Dom/Util', 'EventHandler'], function(Dict return name; }, + /** + * Returns the currently active tab. + * + * @return {Element} active tab + */ + getActiveTab: function() { + return elBySel('#' + this._container.id + ' > nav > ul > li.active'); + }, + /** * Returns the list of registered content containers. * diff --git a/wcfsetup/install/files/lib/system/option/UseroptionsOptionType.class.php b/wcfsetup/install/files/lib/system/option/UseroptionsOptionType.class.php index 0ccaa1ab94..6e4a0b1cea 100644 --- a/wcfsetup/install/files/lib/system/option/UseroptionsOptionType.class.php +++ b/wcfsetup/install/files/lib/system/option/UseroptionsOptionType.class.php @@ -8,7 +8,7 @@ use wcf\system\WCF; * Option type implementation for user option selection. * * @author Marcel Werk - * @copyright 2001-2015 WoltLab GmbH + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.option @@ -17,16 +17,16 @@ use wcf\system\WCF; class UseroptionsOptionType extends AbstractOptionType { /** * list of available user options - * @var array + * @var string[] */ protected static $userOptions = null; /** - * @see \wcf\system\option\IOptionType::validate() + * @inheritDoc */ public function validate(Option $option, $newValue) { if (!is_array($newValue)) { - $newValue = array(); + $newValue = []; } foreach ($newValue as $optionName) { @@ -37,7 +37,7 @@ class UseroptionsOptionType extends AbstractOptionType { } /** - * @see \wcf\system\option\IOptionType::getData() + * @inheritDoc */ public function getData(Option $option, $newValue) { if (!is_array($newValue)) return ''; @@ -45,38 +45,47 @@ class UseroptionsOptionType extends AbstractOptionType { } /** - * @see \wcf\system\option\IOptionType::getFormElement() + * @inheritDoc */ public function getFormElement(Option $option, $value) { - WCF::getTPL()->assign(array( + $userOptions = self::getUserOptions(); + if ($option->issortable && $value) { + $sortedOptions = explode(',', $value); + + // remove old options + $sortedOptions = array_intersect($sortedOptions, $userOptions); + + // append the non-checked options after the checked and sorted options + $userOptions = array_merge($sortedOptions, array_diff($userOptions, $sortedOptions)); + } + + WCF::getTPL()->assign([ 'option' => $option, 'value' => explode(',', $value), - 'availableOptions' => self::getUserOptions() - )); + 'availableOptions' => $userOptions + ]); return WCF::getTPL()->fetch('useroptionsOptionType'); } /** * Returns the list of available user options. * - * @return string + * @return string[] */ protected static function getUserOptions() { if (self::$userOptions === null) { - self::$userOptions = array(); + self::$userOptions = []; $sql = "SELECT optionName FROM wcf".WCF_N."_user_option WHERE categoryName IN ( SELECT categoryName FROM wcf".WCF_N."_user_option_category - WHERE parentCategoryName = 'profile' + WHERE parentCategoryName = 'profile' ) AND optionType <> 'boolean'"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(); - while ($row = $statement->fetchArray()) { - self::$userOptions[] = $row['optionName']; - } + self::$userOptions = $statement->fetchAll(\PDO::FETCH_COLUMN); } return self::$userOptions; -- 2.20.1