Convert `Acp/Ui/Trophy/Upload` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Sat, 5 Dec 2020 18:25:30 +0000 (19:25 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 5 Dec 2020 18:25:30 +0000 (19:25 +0100)
Note: The `input` key in the options was never used anywhere.

wcfsetup/install/files/acp/templates/trophyAdd.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.ts [new file with mode: 0644]

index 2bba55b3ca17d74e474b721f12e65108fe87f777..d31541f299837fd5303393eaa93ccb9e063a1fe0 100644 (file)
        
                                        <script data-relocate="true">
                                                require(['WoltLabSuite/Core/Acp/Ui/Trophy/Upload'], function(IconUpload) {
-                                                       new IconUpload({if $action == 'add'}0{else}{$trophy->trophyID}{/if}, '{$tmpHash}', {
-                                                               input: 'uploadIconFile'
-                                                       });
+                                                       new IconUpload({if $action == 'add'}0{else}{$trophy->trophyID}{/if}, '{$tmpHash}');
                                                });
                                        </script>
                                </dd>
index 2da068953edab6a0d8b385260dea4cebeac341c3..5407a8e31b0ab68000fd492af9861bef330ec1dd 100644 (file)
@@ -1,54 +1,44 @@
 /**
  * Handles the trophy image upload.
  *
- * @author     Joshua Ruesweg
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Acp/Ui/Trophy/Upload
+ * @author  Joshua Ruesweg
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Acp/Ui/Trophy/Upload
  */
-define(['Core', 'Dom/Traverse', 'Language', 'Upload', 'Ui/Notification'], function (Core, DomTraverse, Language, Upload, UINotification) {
+define(["require", "exports", "tslib", "../../../Core", "../../../Dom/Util", "../../../Language", "../../../Ui/Notification", "../../../Upload"], function (require, exports, tslib_1, Core, Util_1, Language, UiNotification, Upload_1) {
     "use strict";
-    /**
-     * @constructor
-     */
-    function TrophyUpload(trophyID, tmpHash, options) {
-        options = options || {};
-        this._trophyID = ~~trophyID;
-        this._tmpHash = tmpHash;
-        if (options.input === undefined) {
-            throw new TypeError("invalid input given");
+    Core = tslib_1.__importStar(Core);
+    Util_1 = tslib_1.__importDefault(Util_1);
+    Language = tslib_1.__importStar(Language);
+    UiNotification = tslib_1.__importStar(UiNotification);
+    Upload_1 = tslib_1.__importDefault(Upload_1);
+    class TrophyUpload extends Upload_1.default {
+        constructor(trophyId, tmpHash, options) {
+            super("uploadIconFileButton", "uploadIconFileContent", Core.extend({
+                className: "wcf\\data\\trophy\\TrophyAction",
+            }, options));
+            this.trophyId = ~~trophyId;
+            this.tmpHash = tmpHash;
         }
-        Upload.call(this, 'uploadIconFileButton', 'uploadIconFileContent', Core.extend({
-            className: 'wcf\\data\\trophy\\TrophyAction'
-        }, options));
-    }
-    Core.inherit(TrophyUpload, Upload, {
-        /**
-         * @see        WoltLabSuite/Core/Upload#_getParameters
-         */
-        _getParameters: function () {
+        _getParameters() {
             return {
-                trophyID: this._trophyID,
-                tmpHash: this._tmpHash
+                trophyID: this.trophyId,
+                tmpHash: this.tmpHash,
             };
-        },
-        /**
-         * @see        WoltLabSuite/Core/Upload#_success
-         */
-        _success: function (uploadId, data) {
-            elInnerError(this._button, false);
-            this._target.innerHTML = "<img src=\"" + data.returnValues.url + "?timestamp=" + Date.now() + "\" />";
-            UINotification.show();
-        },
-        /**
-         * @see        WoltLabSuite/Core/Upload#_failure
-         */
-        _failure: function (uploadId, data, responseText, xhr, requestOptions) {
-            elInnerError(this._button, Language.get('wcf.acp.trophy.imageUpload.error.' + data.returnValues.errorType));
-            // remove previous images 
+        }
+        _success(uploadId, data) {
+            Util_1.default.innerError(this._button, false);
+            this._target.innerHTML = `<img src="${data.returnValues.url}?timestamp=${Date.now()}" alt="">`;
+            UiNotification.show();
+        }
+        _failure(uploadId, data) {
+            Util_1.default.innerError(this._button, Language.get(`wcf.acp.trophy.imageUpload.error.${data.returnValues.errorType}`));
+            // remove previous images
             this._target.innerHTML = "";
             return false;
         }
-    });
+    }
+    Core.enableLegacyInheritance(TrophyUpload);
     return TrophyUpload;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js
deleted file mode 100644 (file)
index 525dbf7..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Handles the trophy image upload.
- *
- * @author     Joshua Ruesweg
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Acp/Ui/Trophy/Upload
- */
-define(['Core', 'Dom/Traverse', 'Language', 'Upload', 'Ui/Notification'], function(Core, DomTraverse, Language, Upload, UINotification) {
-       "use strict";
-       
-       /**
-        * @constructor
-        */
-       function TrophyUpload(trophyID, tmpHash, options) {
-               options = options || {};
-               
-               this._trophyID = ~~trophyID;
-               this._tmpHash = tmpHash;
-               
-               if (options.input === undefined) {
-                       throw new TypeError("invalid input given");
-               }
-               
-               Upload.call(this, 'uploadIconFileButton', 'uploadIconFileContent', Core.extend({
-                       className: 'wcf\\data\\trophy\\TrophyAction'
-               }, options));
-       }
-       
-       Core.inherit(TrophyUpload, Upload, {
-               /**
-                * @see WoltLabSuite/Core/Upload#_getParameters
-                */
-               _getParameters: function() {
-                       return {
-                               trophyID: this._trophyID,
-                               tmpHash: this._tmpHash
-                       };
-               },
-               
-               /**
-                * @see WoltLabSuite/Core/Upload#_success
-                */
-               _success: function(uploadId, data) {
-                       elInnerError(this._button, false);
-                       
-                       this._target.innerHTML = "<img src=\"" + data.returnValues.url + "?timestamp=" + Date.now() + "\" />";
-                       
-                       UINotification.show();
-               },
-               
-               /**
-                * @see WoltLabSuite/Core/Upload#_failure
-                */
-               _failure: function(uploadId, data, responseText, xhr, requestOptions) {
-                       elInnerError(this._button, Language.get('wcf.acp.trophy.imageUpload.error.' + data.returnValues.errorType));
-                       
-                       // remove previous images 
-                       this._target.innerHTML = "";
-                       
-                       return false; 
-               }
-       });
-       
-       return TrophyUpload;
-});
\ No newline at end of file
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.ts
new file mode 100644 (file)
index 0000000..2889637
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * Handles the trophy image upload.
+ *
+ * @author  Joshua Ruesweg
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Acp/Ui/Trophy/Upload
+ */
+
+import * as Core from "../../../Core";
+import DomUtil from "../../../Dom/Util";
+import * as Language from "../../../Language";
+import * as UiNotification from "../../../Ui/Notification";
+import Upload from "../../../Upload";
+import { UploadOptions } from "../../../Upload/Data";
+
+interface AjaxResponse {
+  returnValues: {
+    url: string;
+  };
+}
+
+interface AjaxResponseError {
+  returnValues: {
+    errorType: string;
+  };
+}
+
+class TrophyUpload extends Upload {
+  private readonly trophyId: number;
+  private readonly tmpHash: string;
+
+  constructor(trophyId: number, tmpHash: string, options: Partial<UploadOptions>) {
+    super(
+      "uploadIconFileButton",
+      "uploadIconFileContent",
+      Core.extend(
+        {
+          className: "wcf\\data\\trophy\\TrophyAction",
+        },
+        options,
+      ),
+    );
+
+    this.trophyId = ~~trophyId;
+    this.tmpHash = tmpHash;
+  }
+
+  protected _getParameters(): ArbitraryObject {
+    return {
+      trophyID: this.trophyId,
+      tmpHash: this.tmpHash,
+    };
+  }
+
+  protected _success(uploadId: number, data: AjaxResponse): void {
+    DomUtil.innerError(this._button, false);
+
+    this._target.innerHTML = `<img src="${data.returnValues.url}?timestamp=${Date.now()}" alt="">`;
+
+    UiNotification.show();
+  }
+
+  protected _failure(uploadId: number, data: AjaxResponseError): boolean {
+    DomUtil.innerError(this._button, Language.get(`wcf.acp.trophy.imageUpload.error.${data.returnValues.errorType}`));
+
+    // remove previous images
+    this._target.innerHTML = "";
+
+    return false;
+  }
+}
+
+Core.enableLegacyInheritance(TrophyUpload);
+
+export = TrophyUpload;