From 0adad6275792268520d1ca013474e36912e590df Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 11 Jun 2014 20:10:56 +0200 Subject: [PATCH] Added proper support for 'enableoptions' in user profile --- .../templates/userProfileAboutEditable.tpl | 7 +- wcfsetup/install/files/acp/js/WCF.ACP.js | 145 ---------------- .../install/files/acp/templates/option.tpl | 2 +- wcfsetup/install/files/js/WCF.js | 159 ++++++++++++++++++ 4 files changed, 166 insertions(+), 147 deletions(-) diff --git a/com.woltlab.wcf/templates/userProfileAboutEditable.tpl b/com.woltlab.wcf/templates/userProfileAboutEditable.tpl index 93de8ee5ce..0c301086b1 100644 --- a/com.woltlab.wcf/templates/userProfileAboutEditable.tpl +++ b/com.woltlab.wcf/templates/userProfileAboutEditable.tpl @@ -28,4 +28,9 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index 54e2696019..845c5b5c96 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -1687,151 +1687,6 @@ WCF.ACP.PluginStore.PurchasedItems.Search = Class.extend({ } }); -/** - * Handles option selection. - */ -WCF.ACP.Options = Class.extend({ - /** - * Initializes options. - */ - init: function() { - $('.jsEnablesOptions').each($.proxy(this._initOption, this)); - }, - - /** - * Initializes an option. - * - * @param integer index - * @param object option - */ - _initOption: function(index, option) { - // execute action on init - this._change(option); - - // bind event listener - $(option).change($.proxy(this._handleChange, this)); - }, - - /** - * Applies whenever an option is changed. - * - * @param object event - */ - _handleChange: function(event) { - this._change($(event.target)); - }, - - /** - * Enables or disables options on option value change. - * - * @param object option - */ - _change: function(option) { - option = $(option); - - var $disableOptions = eval(option.data('disableOptions')); - var $enableOptions = eval(option.data('enableOptions')); - - // determine action by type - switch(option.getTagName()) { - case 'input': - switch(option.attr('type')) { - case 'checkbox': - this._execute(option.prop('checked'), $disableOptions, $enableOptions); - break; - - case 'radio': - if (option.prop('checked')) { - this._execute(true, $disableOptions, $enableOptions); - } - break; - } - break; - - case 'select': - var $value = option.val(); - var $disableOptions = $enableOptions = []; - - if (option.data('disableOptions').length > 0) { - for (var $index in option.data('disableOptions')) { - var $item = option.data('disableOptions')[$index]; - - if ($item.value == $value) { - $disableOptions.push($item.option); - } - } - } - - if (option.data('enableOptions').length > 0) { - for (var $index in option.data('enableOptions')) { - var $item = option.data('enableOptions')[$index]; - - if ($item.value == $value) { - $enableOptions.push($item.option); - } - } - } - - this._execute(true, $disableOptions, $enableOptions); - break; - } - }, - - /** - * Enables or disables options. - * - * @param boolean isActive - * @param array disableOptions - * @param array enableOptions - */ - _execute: function(isActive, disableOptions, enableOptions) { - if (disableOptions.length > 0) { - for (var $i = 0, $size = disableOptions.length; $i < $size; $i++) { - var $target = disableOptions[$i]; - if ($.wcfIsset($target)) { - this._enableOption($target, !isActive); - } - } - } - - if (enableOptions.length > 0) { - for (var $i = 0, $size = enableOptions.length; $i < $size; $i++) { - var $target = enableOptions[$i]; - if ($.wcfIsset($target)) { - this._enableOption($target, isActive); - } - } - } - }, - - /** - * Enables an option. - * - * @param string target - * @param boolean enable - */ - _enableOption: function(target, enable) { - var $targetElement = $('#' + $.wcfEscapeID(target)); - var $tagName = $targetElement.getTagName(); - - if ($tagName == 'select' || ($tagName == 'input' && ($targetElement.attr('type') == 'checkbox' || $targetElement.attr('type') == 'radio'))) { - if (enable) $targetElement.enable(); - else $targetElement.disable(); - } - else { - if (enable) $targetElement.removeAttr('readonly'); - else $targetElement.attr('readonly', true); - } - - if (enable) { - $targetElement.closest('dl').removeClass('disabled'); - } - else { - $targetElement.closest('dl').addClass('disabled'); - } - } -}); - /** * Worker support for ACP. * diff --git a/wcfsetup/install/files/acp/templates/option.tpl b/wcfsetup/install/files/acp/templates/option.tpl index 4d82259f6b..93e48eb100 100644 --- a/wcfsetup/install/files/acp/templates/option.tpl +++ b/wcfsetup/install/files/acp/templates/option.tpl @@ -6,7 +6,7 @@ // 0) { + for (var $index in option.data('disableOptions')) { + var $item = option.data('disableOptions')[$index]; + + if ($item.value == $value) { + $disableOptions.push($item.option); + } + } + } + + if (option.data('enableOptions').length > 0) { + for (var $index in option.data('enableOptions')) { + var $item = option.data('enableOptions')[$index]; + + if ($item.value == $value) { + $enableOptions.push($item.option); + } + } + } + + this._execute(true, $disableOptions, $enableOptions); + break; + } + }, + + /** + * Enables or disables options. + * + * @param boolean isActive + * @param array disableOptions + * @param array enableOptions + */ + _execute: function(isActive, disableOptions, enableOptions) { + if (disableOptions.length > 0) { + for (var $i = 0, $size = disableOptions.length; $i < $size; $i++) { + var $target = disableOptions[$i]; + if ($.wcfIsset($target)) { + this._enableOption($target, !isActive); + } + } + } + + if (enableOptions.length > 0) { + for (var $i = 0, $size = enableOptions.length; $i < $size; $i++) { + var $target = enableOptions[$i]; + if ($.wcfIsset($target)) { + this._enableOption($target, isActive); + } + } + } + }, + + /** + * Enables an option. + * + * @param string target + * @param boolean enable + */ + _enableOption: function(target, enable) { + var $targetElement = $('#' + $.wcfEscapeID(target)); + var $tagName = $targetElement.getTagName(); + + if ($tagName == 'select' || ($tagName == 'input' && ($targetElement.attr('type') == 'checkbox' || $targetElement.attr('type') == 'radio'))) { + if (enable) $targetElement.enable(); + else $targetElement.disable(); + } + else { + if (enable) $targetElement.removeAttr('readonly'); + else $targetElement.attr('readonly', true); + } + + if (enable) { + $targetElement.closest('dl').removeClass('disabled'); + } + else { + $targetElement.closest('dl').addClass('disabled'); + } + } +}); + WCF.PageVisibilityHandler = { /** * list of callbacks -- 2.20.1