-{foreach from=$availableOptions item=availableOption}
- <label><input type="checkbox" name="values[{$option->optionName}][]" value="{$availableOption}" {if $availableOption|in_array:$value}checked="checked" {/if}/> {lang}wcf.user.option.{$availableOption}{/lang}</label>
-{/foreach}
+{if $option->issortable}
+ <script data-relocate="true">
+ document.addEventListener('DOMContentLoaded', function() {
+ require(['Dom/Traverse', 'Dom/Util', 'Ui/TabMenu'], function (DomTraverse, DomUtil, UiTabMenu) {
+ var sortableList = elById('{$option->optionName}SortableList');
+ var tabMenu = UiTabMenu.getTabMenu(DomUtil.identify(DomTraverse.parentByClass(sortableList, 'tabMenuContainer')));
+ var activeTab = tabMenu.getActiveTab();
+
+ // select the tab the sortable list is in as jQuery's sortable requires
+ // the sortable list to be visible
+ tabMenu.select(null, DomTraverse.parentByClass(sortableList, 'tabMenuContent'));
+
+ new WCF.Sortable.List('{$option->optionName}SortableList', null, 0, { }, true);
+
+ // re-select the previously selected tab
+ tabMenu.select(null, activeTab);
+ });
+ });
+ </script>
+
+ <div id="{$option->optionName}SortableList" class="sortableListContainer">
+ <ol class="sortableList">
+ {foreach from=$availableOptions item=availableOption}
+ <li class="sortableNode">
+ <span class="sortableNodeLabel">
+ <label><input type="checkbox" name="values[{$option->optionName}][]" value="{$availableOption}" {if $availableOption|in_array:$value}checked="checked" {/if}/> {lang}wcf.user.option.{$availableOption}{/lang}</label>
+ </span>
+ </li>
+ {/foreach}
+ </ol>
+ </div>
+{else}
+ {foreach from=$availableOptions item=availableOption}
+ <label><input type="checkbox" name="values[{$option->optionName}][]" value="{$availableOption}" {if $availableOption|in_array:$value}checked="checked" {/if}/> {lang}wcf.user.option.{$availableOption}{/lang}</label>
+ {/foreach}
+{/if}
\ No newline at end of file
* 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 <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.option
class UseroptionsOptionType extends AbstractOptionType {
/**
* list of available user options
- * @var array<string>
+ * @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) {
}
/**
- * @see \wcf\system\option\IOptionType::getData()
+ * @inheritDoc
*/
public function getData(Option $option, $newValue) {
if (!is_array($newValue)) return '';
}
/**
- * @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;