Update form builder's dialog form document implementation
authorMatthias Schmidt <gravatronics@live.com>
Sun, 17 Mar 2019 07:55:40 +0000 (08:55 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 17 Mar 2019 07:55:40 +0000 (08:55 +0100)
See #2509

com.woltlab.wcf/templates/__dialogForm.tpl [deleted file]
syncTemplates.json
wcfsetup/install/files/acp/templates/__dialogForm.tpl [deleted file]
wcfsetup/install/files/lib/system/form/builder/DialogFormDocument.class.php

diff --git a/com.woltlab.wcf/templates/__dialogForm.tpl b/com.woltlab.wcf/templates/__dialogForm.tpl
deleted file mode 100644 (file)
index d42513b..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<script data-relocate="true">
-       {* register form with dependency manager before any form field-related JavaScript code is executed below *}
-       require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Manager'], function(FormBuilderFieldDependencyManager) {
-               FormBuilderFieldDependencyManager.register('{@$form->getId()}');
-       });
-</script>
-
-{if $form->getAction()}
-       {capture assign='__formStart'}<form method="{@$form->getMethod()}" action="{@$form->getAction()}"{/capture}
-       {assign var='__formEnd' value='</form>'}
-{else}
-       {assign var='__formStart' value='<section'}
-       {assign var='__formEnd' value='</section>'}
-{/if}
-
-{@$__formStart} id="{@$form->getId()}"{if !$form->getClasses()|empty} class="{implode from=$form->getClasses() item='class' glue=' '}{$class}{/implode}"{/if}{foreach from=$form->getAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}>
-       {foreach from=$form item='child'}
-               {if $child->isAvailable()}
-                       {@$child->getHtml()}
-               {/if}
-       {/foreach}
-       
-       <div class="formSubmit">
-               <button class="buttonPrimary">{lang}wcf.global.button.submit{/lang}</button>
-               {if $form->isCancelable()}
-                       <button data-type="cancel">{lang}wcf.global.button.cancel{/lang}</button>
-               {/if}
-       </div>
-{@$__formEnd}
-
-<script data-relocate="true">
-       {* after all dependencies have been added, check them *}
-       require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Manager'], function(FormBuilderFieldDependencyManager) {
-               FormBuilderFieldDependencyManager.checkDependencies();
-       });
-</script>
index f98b8e2307a420dcf73905fc8bd38c13807b8746..62a00302cd876ee69a6ff14eb4639c262bee3ab6 100644 (file)
@@ -8,7 +8,6 @@
     "__booleanFormField",
     "__dateFormField",
     "__devtoolsLanguageChooser",
-    "__dialogForm",
     "__form",
     "__formButton",
     "__formContainer",
diff --git a/wcfsetup/install/files/acp/templates/__dialogForm.tpl b/wcfsetup/install/files/acp/templates/__dialogForm.tpl
deleted file mode 100644 (file)
index d42513b..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<script data-relocate="true">
-       {* register form with dependency manager before any form field-related JavaScript code is executed below *}
-       require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Manager'], function(FormBuilderFieldDependencyManager) {
-               FormBuilderFieldDependencyManager.register('{@$form->getId()}');
-       });
-</script>
-
-{if $form->getAction()}
-       {capture assign='__formStart'}<form method="{@$form->getMethod()}" action="{@$form->getAction()}"{/capture}
-       {assign var='__formEnd' value='</form>'}
-{else}
-       {assign var='__formStart' value='<section'}
-       {assign var='__formEnd' value='</section>'}
-{/if}
-
-{@$__formStart} id="{@$form->getId()}"{if !$form->getClasses()|empty} class="{implode from=$form->getClasses() item='class' glue=' '}{$class}{/implode}"{/if}{foreach from=$form->getAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}>
-       {foreach from=$form item='child'}
-               {if $child->isAvailable()}
-                       {@$child->getHtml()}
-               {/if}
-       {/foreach}
-       
-       <div class="formSubmit">
-               <button class="buttonPrimary">{lang}wcf.global.button.submit{/lang}</button>
-               {if $form->isCancelable()}
-                       <button data-type="cancel">{lang}wcf.global.button.cancel{/lang}</button>
-               {/if}
-       </div>
-{@$__formEnd}
-
-<script data-relocate="true">
-       {* after all dependencies have been added, check them *}
-       require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Manager'], function(FormBuilderFieldDependencyManager) {
-               FormBuilderFieldDependencyManager.checkDependencies();
-       });
-</script>
index 960db3b86d402dc9fea133c75e8b94a8ebcf933c..781a0876f509cbc683d7ab677b5e81c452e25159 100644 (file)
@@ -1,10 +1,13 @@
 <?php
 namespace wcf\system\form\builder;
-use wcf\system\WCF;
+use wcf\system\form\builder\button\FormButton;
 
 /**
  * Represents a form (document) in a dialog.
  * 
+ * By default, the global form error message is now shown for dialog forms and it is assumed that
+ * the form is requested via an AJAX request.
+ * 
  * @author     Matthias Schmidt
  * @copyright  2001-2019 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
@@ -12,15 +15,27 @@ use wcf\system\WCF;
  * @since      5.2
  */
 class DialogFormDocument extends FormDocument {
+       /**
+        * @inheritDoc
+        */
+       protected $ajax = true;
+       
        /**
         * is `true` if dialog from can be canceled and is `false` otherwise
         * @var bool
         */
        protected $isCancelable = true;
        
+       /**
+        * @inheritDoc
+        */
+       protected $showErrorMessage = false;
+       
        /**
         * Sets whether the dialog from can be canceled and return this document.
         * 
+        * For cancelable dialog forms, a cancel button is added.
+        * 
         * @param       bool    $cancelable     determines if dialog from can be canceled
         * @return      static                  this document
         */
@@ -33,12 +48,16 @@ class DialogFormDocument extends FormDocument {
        /**
         * @inheritDoc
         */
-       public function getHtml() {
-               return WCF::getTPL()->fetch(
-                       '__dialogForm',
-                       'wcf',
-                       array_merge($this->getHtmlVariables(), ['form' => $this])
-               );
+       protected function createDefaultButton() {
+               parent::createDefaultButton();
+               
+               if ($this->isCancelable()) {
+                       $this->addButton(
+                               FormButton::create('cancelButton')
+                                       ->attribute('data-type', 'cancel')
+                                       ->label('wcf.global.button.cancel')
+                       );
+               }
        }
        
        /**