Add support for uploads in the acp
authorJoshua Rüsweg <josh@bastelstu.be>
Mon, 28 Jan 2019 17:00:25 +0000 (18:00 +0100)
committerJoshua Rüsweg <josh@bastelstu.be>
Mon, 28 Jan 2019 17:00:25 +0000 (18:00 +0100)
See #2825

syncTemplates.json
wcfsetup/install/files/acp/templates/__uploadFormField.tpl [new file with mode: 0644]
wcfsetup/install/files/acp/templates/uploadFieldComponent.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/acp/action/AJAXFileDeleteAction.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/acp/action/AJAXFileUploadAction.class.php [new file with mode: 0644]

index 1cab808a5516ab9c2947474f8859b253b04c9c1c..a2097268ce724b906fa9dca0a4d21f0aeb76476d 100644 (file)
@@ -34,6 +34,7 @@
     "__tabTabMenuFormContainer",
     "__tagFormField",
     "__textFormField",
+    "__uploadFormField",
     "__userFormField",
     "__usernameFormField",
     "__valueFormFieldDependency",
@@ -62,6 +63,7 @@
     "sitemapEnd",
     "sitemapStart",
     "trophyImage",
+    "uploadFieldComponent",
     "userConditions",
     "userOptionsCondition",
     "worker",
diff --git a/wcfsetup/install/files/acp/templates/__uploadFormField.tpl b/wcfsetup/install/files/acp/templates/__uploadFormField.tpl
new file mode 100644 (file)
index 0000000..83bcc45
--- /dev/null
@@ -0,0 +1,5 @@
+{include file='__formFieldHeader'}
+
+{@$__wcf->getUploadHandler()->renderField($field->getPrefixedId())}
+
+{include file='__formFieldFooter'}
diff --git a/wcfsetup/install/files/acp/templates/uploadFieldComponent.tpl b/wcfsetup/install/files/acp/templates/uploadFieldComponent.tpl
new file mode 100644 (file)
index 0000000..3fa0ea0
--- /dev/null
@@ -0,0 +1,48 @@
+{if !$uploadField->supportMultipleFiles() && $uploadField->isImageOnly()}
+       <div class="selectedImagePreview uploadedFile" id="{$uploadFieldId}uploadFileList" data-internal-id="{$uploadField->getInternalId()}">{*
+               *}{if !$uploadFieldFiles|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>
+                                       </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("{$uploadFieldId}UploadButtonDiv", "{$uploadFieldId}uploadFileList", {
+                       internalId: '{$uploadField->getInternalId()}',
+                       {if $uploadField->getMaxFiles()}maxFiles: {$uploadField->getMaxFiles()},{/if}
+                       imagePreview: {if !$uploadField->supportMultipleFiles() && $uploadField->isImageOnly()}true{else}false{/if}
+               });
+               
+               Language.addObject({
+                       'wcf.upload.error.reachedRemainingLimit': '{lang}wcf.upload.error.reachedRemainingLimit{/lang}',
+                       'wcf.upload.error.noImage': '{lang}wcf.upload.error.noImage{/lang}'
+               });
+       });
+</script>
\ No newline at end of file
diff --git a/wcfsetup/install/files/lib/acp/action/AJAXFileDeleteAction.class.php b/wcfsetup/install/files/lib/acp/action/AJAXFileDeleteAction.class.php
new file mode 100644 (file)
index 0000000..4872966
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+namespace wcf\acp\action;
+
+/**
+ * Action to delete files in the acp.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2018 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\Acp\Action
+ * @since      5.2
+ */
+class AJAXFileDeleteAction extends \wcf\action\AJAXFileDeleteAction { }
diff --git a/wcfsetup/install/files/lib/acp/action/AJAXFileUploadAction.class.php b/wcfsetup/install/files/lib/acp/action/AJAXFileUploadAction.class.php
new file mode 100644 (file)
index 0000000..ad01d02
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+namespace wcf\acp\action;
+
+/**
+ * Action to upload files in the acp.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2018 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\Acp\Action
+ * @since      5.2
+ */
+class AJAXFileUploadAction extends \wcf\action\AJAXFileUploadAction { }