Add checkboxes option type
authorMatthias Schmidt <gravatronics@live.com>
Sun, 14 Dec 2014 10:28:52 +0000 (11:28 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 14 Dec 2014 10:28:52 +0000 (11:28 +0100)
wcfsetup/install/files/acp/templates/checkboxesOptionType.tpl [new file with mode: 0644]
wcfsetup/install/files/acp/templates/checkboxesSearchableOptionType.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/system/option/CheckboxesOptionType.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/option/MultiSelectOptionType.class.php

diff --git a/wcfsetup/install/files/acp/templates/checkboxesOptionType.tpl b/wcfsetup/install/files/acp/templates/checkboxesOptionType.tpl
new file mode 100644 (file)
index 0000000..62f6c3f
--- /dev/null
@@ -0,0 +1,3 @@
+{foreach from=$selectOptions key=key item=selectOption}
+       <label><input type="checkbox" name="values[{$option->optionName}][]" value="{$key}" {if $key|in_array:$value} checked="checked"{/if} {if $disableOptions[$key]|isset || $enableOptions[$key]|isset}class="jsEnablesOptions" data-disable-options="[ {@$disableOptions[$key]}]" data-enable-options="[ {@$enableOptions[$key]}]"{/if} /> {lang}{@$selectOption}{/lang}</label>
+{/foreach}
diff --git a/wcfsetup/install/files/acp/templates/checkboxesSearchableOptionType.tpl b/wcfsetup/install/files/acp/templates/checkboxesSearchableOptionType.tpl
new file mode 100644 (file)
index 0000000..3c88d94
--- /dev/null
@@ -0,0 +1,19 @@
+<label><input type="checkbox" id="search_{$option->optionName}" name="searchOptions[{$option->optionName}]"{if $searchOption} checked="checked"{/if} /> {lang}wcf.user.option.searchRadioButtonOption{/lang}</label>
+{foreach from=$selectOptions key=key item=selectOption}
+       <label><input type="checkbox" name="values[{$option->optionName}][]" value="{$key}" {if $key|in_array:$value} checked="checked"{/if}{if !$searchOption} disabled="disabled"{/if} /> {lang}{@$selectOption}{/lang}</label>
+{/foreach}
+
+<script data-relocate="true">
+       //<![CDATA[
+       $(function() {
+               $('#search_{$option->optionName}').change(function(event) {
+                       if ($(event.currentTarget).prop('checked')) {
+                               $('input[name="values[{$option->optionName}][]"]').enable();
+                       }
+                       else {
+                               $('input[name="values[{$option->optionName}][]"]').disable();
+                       }
+               });
+       });
+       //]]>
+</script>
diff --git a/wcfsetup/install/files/lib/system/option/CheckboxesOptionType.class.php b/wcfsetup/install/files/lib/system/option/CheckboxesOptionType.class.php
new file mode 100644 (file)
index 0000000..026720c
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+namespace wcf\system\option;
+
+/**
+ * Option type implementation for checkboxes.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2014 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.option
+ * @category   Community Framework
+ */
+class CheckboxesOptionType extends MultiSelectOptionType {
+       /**
+        * @see \wcf\wcf\system\option\MultiSelectOptionType::$formElementTemplate
+        */
+       protected $formElementTemplate = 'checkboxesOptionType';
+       
+       /**
+        * @see \wcf\wcf\system\option\MultiSelectOptionType::$formElementTemplate
+        */
+       protected $searchableFormElementTemplate = 'checkboxesSearchableOptionType';
+}
index 65231a4f8547e07b041bef03b8e813c984061f12..7e9efe2b93e08920c9e6739cde863db76d9942f6 100644 (file)
@@ -19,6 +19,18 @@ use wcf\util\ArrayUtil;
  * @category   Community Framework
  */
 class MultiSelectOptionType extends SelectOptionType {
+       /**
+        * name of the form element template
+        * @var string
+        */
+       protected $formElementTemplate = 'multiSelectOptionType';
+       
+       /**
+        * name of the searchable form element template
+        * @var string
+        */
+       protected $searchableFormElementTemplate = 'multiSelectSearchableOptionType';
+       
        /**
         * @see \wcf\system\option\IOptionType::getFormElement()
         */
@@ -28,7 +40,7 @@ class MultiSelectOptionType extends SelectOptionType {
                        'selectOptions' => $this->getSelectOptions($option),
                        'value' => (!is_array($value) ? explode("\n", $value) : $value)
                ));
-               return WCF::getTPL()->fetch('multiSelectOptionType');
+               return WCF::getTPL()->fetch($this->formElementTemplate);
        }
        
        /**
@@ -41,7 +53,7 @@ class MultiSelectOptionType extends SelectOptionType {
                        'selectOptions' => $this->getSelectOptions($option),
                        'value' => (!is_array($value) ? explode("\n", $value) : $value)
                ));
-               return WCF::getTPL()->fetch('multiSelectSearchableOptionType');
+               return WCF::getTPL()->fetch($this->searchableFormElementTemplate);
        }
        
        /**