Add proper enableOptions support for select option type
authorMatthias Schmidt <gravatronics@live.com>
Fri, 26 Aug 2016 07:51:37 +0000 (09:51 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 26 Aug 2016 07:53:38 +0000 (09:53 +0200)
com.woltlab.wcf/templates/booleanOptionType.tpl
com.woltlab.wcf/templates/selectOptionType.tpl
wcfsetup/install/files/acp/templates/booleanOptionType.tpl
wcfsetup/install/files/acp/templates/selectOptionType.tpl
wcfsetup/install/files/js/WCF.js

index 92fd14be1e6423f1811f9a384bde211a3156d96b..4729f86a47bc72665ec578f3df1b5fa1109450ed 100644 (file)
@@ -1,4 +1,4 @@
-<ol class="flexibleButtonGroup">
+<ol class="flexibleButtonGroup optionTypeBoolean">
        <li>
                <input type="radio" id="{$option->optionName}"{if $value == 1} checked{/if} name="values[{$option->optionName}]" value="1"{if $disableOptions || $enableOptions} class="jsEnablesOptions" data-is-boolean="true" data-disable-options="[ {@$disableOptions}]" data-enable-options="[ {@$enableOptions}]"{/if}>
                <label for="{$option->optionName}" class="green"><span class="icon icon16 fa-check"></span> {lang}wcf.acp.option.type.boolean.yes{/lang}</label>
index ddfb5f9b3cbb19c6e8538eb33f6e1c2f7d42dd6c..9d325fa1b1b9b61e3173e17cfbe2a9af60f97509 100644 (file)
@@ -1,4 +1,4 @@
-<select id="{$option->optionName}" name="values[{$option->optionName}]"{if $option->required} required{/if}>
+<select id="{$option->optionName}" name="values[{$option->optionName}]"{if $option->required} required{/if}{if $disableOptions || $enableOptions} class="jsEnablesOptions" data-is-boolean="true" data-disable-options="[ {@$disableOptions}]" data-enable-options="[ {@$enableOptions}]"{/if}>
        {if !$allowEmptyValue|empty}<option value="">{lang}wcf.global.noSelection{/lang}</option>{/if}
        {foreach from=$selectOptions key=key item=selectOption}
                <option value="{$key}"{if $value == $key} selected{/if}>{lang}{@$selectOption}{/lang}</option>
index 92fd14be1e6423f1811f9a384bde211a3156d96b..4729f86a47bc72665ec578f3df1b5fa1109450ed 100644 (file)
@@ -1,4 +1,4 @@
-<ol class="flexibleButtonGroup">
+<ol class="flexibleButtonGroup optionTypeBoolean">
        <li>
                <input type="radio" id="{$option->optionName}"{if $value == 1} checked{/if} name="values[{$option->optionName}]" value="1"{if $disableOptions || $enableOptions} class="jsEnablesOptions" data-is-boolean="true" data-disable-options="[ {@$disableOptions}]" data-enable-options="[ {@$enableOptions}]"{/if}>
                <label for="{$option->optionName}" class="green"><span class="icon icon16 fa-check"></span> {lang}wcf.acp.option.type.boolean.yes{/lang}</label>
index d05e0ffd09fb821c93241d6831dd7734333728ac..9343d83c47423e01f8ec9e34296c1ef106afe3fc 100644 (file)
@@ -1,4 +1,4 @@
-<select id="{$option->optionName}" name="values[{$option->optionName}]">
+<select id="{$option->optionName}" name="values[{$option->optionName}]"{if $disableOptions || $enableOptions} class="jsEnablesOptions" data-is-boolean="true" data-disable-options="[ {@$disableOptions}]" data-enable-options="[ {@$enableOptions}]"{/if}>
        {if !$allowEmptyValue|empty}<option value="">{lang}wcf.global.noSelection{/lang}</option>{/if}
        {foreach from=$selectOptions key=key item=selectOption}
                <option value="{$key}"{if $value == $key} selected{/if}>{lang}{@$selectOption}{/lang}</option>
index 6d83b88fd2b5142d23cba46c9f7fc3dd4f8dd4b5..d0ec456fc528dec1b662b39acf91f20e17ff9745 100755 (executable)
@@ -3819,15 +3819,15 @@ WCF.Option.Handler = Class.extend({
        _change: function(option) {
                option = $(option);
                
-               var $disableOptions = eval(option.data('disableOptions'));
-               var $enableOptions = eval(option.data('enableOptions'));
+               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);
+                                               this._execute(option.prop('checked'), disableOptions, enableOptions);
                                        break;
                                        
                                        case 'radio':
@@ -3837,7 +3837,7 @@ WCF.Option.Handler = Class.extend({
                                                                isActive = false;
                                                        }
                                                        
-                                                       this._execute(isActive, $disableOptions, $enableOptions);
+                                                       this._execute(isActive, disableOptions, enableOptions);
                                                }
                                        break;
                                }
@@ -3845,29 +3845,36 @@ WCF.Option.Handler = Class.extend({
                        
                        case 'select':
                                var $value = option.val();
-                               var $disableOptions = $enableOptions = [];
+                               var relevantDisableOptions = [];
+                               var relevantEnableOptions = [];
                                
-                               if (option.data('disableOptions').length > 0) {
-                                       for (var $index in option.data('disableOptions')) {
-                                               var $item = option.data('disableOptions')[$index];
+                               if (disableOptions.length > 0) {
+                                       for (var $index in disableOptions) {
+                                               var $item = disableOptions[$index];
                                                
                                                if ($item.value == $value) {
-                                                       $disableOptions.push($item.option);
+                                                       relevantDisableOptions.push($item.option);
+                                               }
+                                               else {
+                                                       relevantEnableOptions.push($item.option);
                                                }
                                        }
                                }
                                
-                               if (option.data('enableOptions').length > 0) {
-                                       for (var $index in option.data('enableOptions')) {
-                                               var $item = option.data('enableOptions')[$index];
+                               if (enableOptions.length > 0) {
+                                       for (var $index in enableOptions) {
+                                               var $item = enableOptions[$index];
                                                
                                                if ($item.value == $value) {
-                                                       $enableOptions.push($item.option);
+                                                       relevantEnableOptions.push($item.option);
+                                               }
+                                               else {
+                                                       relevantDisableOptions.push($item.option);
                                                }
                                        }
                                }
                                
-                               this._execute(true, $disableOptions, $enableOptions);
+                               this._execute(true, relevantDisableOptions, relevantEnableOptions);
                        break;
                }
        },
@@ -3934,6 +3941,12 @@ WCF.Option.Handler = Class.extend({
                if ($tagName == 'select' || ($tagName == 'input' && (element.attr('type') == 'checkbox' || element.attr('type') == 'file' || element.attr('type') == 'radio'))) {
                        if (enable) element.enable();
                        else element.disable();
+                       
+                       if (element.parents('.optionTypeBoolean:eq(0)')) {
+                               var noElement = $('#' + element.wcfIdentify() + '_no');
+                               if (enable) noElement.enable();
+                               else noElement.disable();
+                       }
                }
                else {
                        if (enable) element.removeAttr('readonly');