Rewrite template to fit the FormBuilder system
authorJoshua Rüsweg <josh@bastelstu.be>
Mon, 14 Jan 2019 19:47:56 +0000 (20:47 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Mon, 14 Jan 2019 19:47:56 +0000 (20:47 +0100)
See #2825

com.woltlab.wcf/templates/uploadFieldComponent.tpl
wcfsetup/install/files/lib/system/file/upload/UploadField.class.php
wcfsetup/install/files/lib/system/file/upload/UploadHandler.class.php

index 2362d74cb7073e4cd87f57d21bfb72d452e15f1e..1045b2878adab620e02044bff1bbfce2d1836de0 100644 (file)
@@ -1,62 +1,47 @@
-<dl{if $errorField == $fieldId} class="formError"{/if}>
-       <dt><label for="{$fieldId}">{$field->getName()}</label></dt>
-       <dd>
-               {if !$field->supportMultipleFiles() && $field->isImageOnly()}
-                       <div class="selectedImagePreview uploadedFile" id="{$fieldId}uploadFileList" data-internal-id="{$field->getInternalId()}">{*
-                               *}{if !$files|empty}{*
-                                       *}{assign var="file" value=$files|reset}{*
-                                       *}<img src="{$file->getImage()}" alt="" class="previewImage" id="{$fieldId}Image" style="max-width: 100%" data-unique-file-id="{$file->getUniqueFileId()}">{*
-                               *}
-                                       <ul class="buttonGroup"></ul>
-                               {/if}{*
-                       *}</div>
-               {else}
-                       <div class="formUploadHandlerContent">
-                               <ul class="formUploadHandlerList" id="{$fieldId}uploadFileList" data-internal-id="{$field->getInternalId()}">
-                                       {foreach from=$files item=file}
-                                               <li class="box64 uploadedFile" data-unique-file-id="{$file->getUniqueFileId()}">
-                                                       <span class="icon icon64 fa-{$file->getIconName()}"></span>
-                                                       
-                                                       <div>
-                                                               <div>
-                                                                       <p>{$file->getFilename()}</p>
-                                                                       <small>{@$file->filesize|filesize}</small>
-                                                               </div>
-                                                               
-                                                               <ul class="buttonGroup"></ul>
-                                                               
-                                                               {if $errorField == $file->getUniqueFileId()}
-                                                                       <small class="innerError innerFileError">{lang __optional="true"}{$errorType}{/lang}</small>
-                                                               {/if}
-                                                       </div>
-                                               </li>
-                                       {/foreach}
-                               </ul>
-                       </div>
-               {/if}
-               
-               <div id="{$fieldId}UploadButtonDiv" class="uploadButtonDiv"></div>
-               
-               {if $errorField == $fieldId}
-                       <small class="innerError">
-                               {if $errorType == 'empty'}
-                                       {lang}wcf.global.form.error.empty{/lang}
-                               {else}
-                                       {lang}{$errorType}{/lang}
-                               {/if}
-                       </small>
-               {/if}
-               
-               <input type="hidden" name="{$fieldId}" value="{$field->getInternalId()}">
-       </dd>
-</dl>
+{if !$uploadField->supportMultipleFiles() && $uploadField->isImageOnly()}
+       <div class="selectedImagePreview uploadedFile" id="{$uploadFieldId}uploadFileList" data-internal-id="{$uploadField->getInternalId()}">{*
+               *}{if !$files|empty}{*
+                       *}{assign var="file" value=$uploadFieldFiles|reset}{*
+                       *}<img src="{$file->getImage()}" alt="" class="previewImage" id="{$uploadFieldId}Image" style="max-width: 100%" data-unique-file-id="{$file->getUniqueFileId()}">{*
+               *}
+                       <ul class="buttonGroup"></ul>
+               {/if}{*
+       *}</div>
+{else}
+       <div class="formUploadHandlerContent">
+               <ul class="formUploadHandlerList" id="{$uploadFieldId}uploadFileList" data-internal-id="{$uploadField->getInternalId()}">
+                       {foreach from=$uploadFieldFiles item=file}
+                               <li class="box64 uploadedFile" data-unique-file-id="{$file->getUniqueFileId()}">
+                                       <span class="icon icon64 fa-{$file->getIconName()}"></span>
+                                       
+                                       <div>
+                                               <div>
+                                                       <p>{$file->getFilename()}</p>
+                                                       <small>{@$file->filesize|filesize}</small>
+                                               </div>
+                                               
+                                               <ul class="buttonGroup"></ul>
+                                               
+                                               {if $errorField == $file->getUniqueFileId()}
+                                                       <small class="innerError innerFileError">{lang __optional="true"}{$errorType}{/lang}</small>
+                                               {/if}
+                                       </div>
+                               </li>
+                       {/foreach}
+               </ul>
+       </div>
+{/if}
+
+<div id="{$uploadFieldId}UploadButtonDiv" class="uploadButtonDiv"></div>
+
+<input type="hidden" name="{$uploadFieldId}" value="{$uploadField->getInternalId()}">
 
 <script data-relocate="true">
        require(['WoltLabSuite/Core/Ui/File/Upload', 'Language'], function(Upload, Language) {
-               new Upload("{$fieldId}UploadButtonDiv", "{$fieldId}uploadFileList", {
-                       internalId: '{$field->getInternalId()}',
-                       maxFiles: {$field->getMaxFiles()},
-                       imagePreview: {if !$field->supportMultipleFiles() && $field->isImageOnly()}true{else}false{/if}
+               new Upload("{$uploadFieldId}UploadButtonDiv", "{$uploadFieldId}uploadFileList", {
+                       internalId: '{$uploadField->getInternalId()}',
+                       maxFiles: {$uploadField->getMaxFiles()},
+                       imagePreview: {if !$uploadField->supportMultipleFiles() && $uploadField->isImageOnly()}true{else}false{/if}
                });
                
                Language.addObject({
index 8dc5c0d82dc38ffad43519436bf152f8ce1ccb7b..1efbe748b356964ad22df6c24d8cf94908a09e53 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\file\upload;
-use wcf\system\WCF;
 
 /**
  * An specific upload field.
@@ -30,17 +29,6 @@ class UploadField {
         */
        public $internalId = null;
        
-       /**
-        * The name of the field.
-        * @var string 
-        */
-       public $name;
-       /**
-        * The description of the field.
-        * @var string 
-        */
-       public $description;
-       
        /**
         * Indicates whether the field is image only.
         * @var boolean
@@ -51,13 +39,9 @@ class UploadField {
         * UploadField constructor.
         *
         * @param       string          $fieldId
-        * @param       string          $fieldName
-        * @param       string          $fieldDescription
         */
-       public function __construct($fieldId, $fieldName = 'Upload', $fieldDescription = null) {
+       public function __construct($fieldId) {
                $this->fieldId = $fieldId;
-               $this->name = $fieldName;
-               $this->description = $fieldDescription;
        }
        
        /**
@@ -114,24 +98,6 @@ class UploadField {
                return $this->internalId;
        }
        
-       /**
-        * Returns the name of the field. 
-        * 
-        * @return string
-        */
-       public function getName() {
-               return WCF::getLanguage()->get($this->name);
-       }
-       
-       /**
-        * Returns the description of the field.
-        *
-        * @return string
-        */
-       public function getDescription() {
-               return WCF::getLanguage()->get($this->description);
-       }
-       
        /**
         * Set the image only flag. 
         * 
index b53570a5ed569db27170c90c1f2b0c92dda9aba2..8352ad1abafc605df1157873aee4c5810368f2c5 100644 (file)
@@ -168,9 +168,9 @@ class UploadHandler extends SingletonFactory {
                }
                
                return WCF::getTPL()->fetch('uploadFieldComponent', 'wcf', [
-                       'field' => $this->fields[$fieldId], 
-                       'fieldId' => $fieldId,
-                       'files' => $this->getFilesForFieldId($fieldId)
+                       'uploadField' => $this->fields[$fieldId], 
+                       'uploadFieldId' => $fieldId,
+                       'uploadFieldFiles' => $this->getFilesForFieldId($fieldId)
                ]);
        }