Add EmptyFormFieldDependency
authorMatthias Schmidt <gravatronics@live.com>
Sun, 30 Jun 2019 12:19:35 +0000 (14:19 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 30 Jun 2019 12:19:35 +0000 (14:19 +0200)
See #2509

com.woltlab.wcf/templates/__emptyFormFieldDependency.tpl [new file with mode: 0644]
syncTemplates.json
wcfsetup/install/files/acp/templates/__emptyFormFieldDependency.tpl [new file with mode: 0644]
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js [new file with mode: 0644]
wcfsetup/install/files/lib/system/form/builder/field/dependency/EmptyFormFieldDependency.class.php [new file with mode: 0644]

diff --git a/com.woltlab.wcf/templates/__emptyFormFieldDependency.tpl b/com.woltlab.wcf/templates/__emptyFormFieldDependency.tpl
new file mode 100644 (file)
index 0000000..0975ecb
--- /dev/null
@@ -0,0 +1,7 @@
+require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty'], function(EmptyFieldDependency) {
+       // dependency '{@$dependency->getId()}'
+       new EmptyFieldDependency(
+               '{@$dependency->getDependentNode()->getPrefixedId()}Container',
+               '{@$dependency->getField()->getPrefixedId()}'
+       );
+});
index 75370394fbac9ccdafb5512708352bb4fb56a5a2..b236044664c074c21ba842500e0a03b2e8d150a0 100644 (file)
@@ -8,6 +8,7 @@
     "__booleanFormField",
     "__contentLanguageFormField",
     "__dateFormField",
+    "__emptyFormFieldDependency",
     "__form",
     "__formButton",
     "__formContainer",
diff --git a/wcfsetup/install/files/acp/templates/__emptyFormFieldDependency.tpl b/wcfsetup/install/files/acp/templates/__emptyFormFieldDependency.tpl
new file mode 100644 (file)
index 0000000..0975ecb
--- /dev/null
@@ -0,0 +1,7 @@
+require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty'], function(EmptyFieldDependency) {
+       // dependency '{@$dependency->getId()}'
+       new EmptyFieldDependency(
+               '{@$dependency->getDependentNode()->getPrefixedId()}Container',
+               '{@$dependency->getField()->getPrefixedId()}'
+       );
+});
diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js
new file mode 100644 (file)
index 0000000..d14b1ca
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Form field dependency implementation that requires the value of a field to be empty.
+ *
+ * @author     Matthias Schmidt
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module     WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty
+ * @see        module:WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract
+ * @since      5.2
+ */
+define(['./Abstract', 'Core'], function(Abstract, Core) {
+       "use strict";
+       
+       /**
+        * @constructor
+        */
+       function Empty(dependentElementId, fieldId) {
+               this.init(dependentElementId, fieldId);
+       };
+       Core.inherit(Empty, Abstract, {
+               /**
+                * @see WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract#checkDependency
+                */
+               checkDependency: function() {
+                       switch (this._field.tagName) {
+                               case 'INPUT':
+                                       switch (this._field.type) {
+                                               case 'checkbox':
+                                                       // TODO: check if working
+                                                       return !this._field.checked;
+                                               
+                                               case 'radio':
+                                                       if (this._noField && this._noField.checked) {
+                                                               return true;
+                                                       }
+                                                       
+                                                       return !this._field.checked;
+                                               
+                                               default:
+                                                       return this._field.value.trim().length === 0;
+                                       }
+                               
+                               case 'SELECT':
+                                       // TODO: check if working for multiselect
+                                       return this._field.value.length === 0;
+                               
+                               case 'TEXTAREA':
+                                       // TODO: check if working
+                                       return this._field.value.trim().length === 0;
+                       }
+               }
+       });
+       
+       return Empty;
+});
diff --git a/wcfsetup/install/files/lib/system/form/builder/field/dependency/EmptyFormFieldDependency.class.php b/wcfsetup/install/files/lib/system/form/builder/field/dependency/EmptyFormFieldDependency.class.php
new file mode 100644 (file)
index 0000000..aa10be2
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+namespace wcf\system\form\builder\field\dependency;
+
+/**
+ * Represents a dependency that requires the value of a field is empty.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Form\Builder\Field\Dependency
+ * @since      5.2
+ */
+class EmptyFormFieldDependency extends AbstractFormFieldDependency {
+       /**
+        * @inheritDoc
+        */
+       protected $templateName = '__emptyFormFieldDependency';
+       
+       /**
+        * @inheritDoc
+        */
+       public function checkDependency() {
+               return empty($this->getField()->getValue());
+       }
+}