From c9648de618fc8aabcce883300e1e5d21c03e063b Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 5 Dec 2020 19:25:30 +0100 Subject: [PATCH] Convert `Acp/Ui/Trophy/Upload` to TypeScript Note: The `input` key in the options was never used anywhere. --- .../install/files/acp/templates/trophyAdd.tpl | 4 +- .../WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js | 72 ++++++++---------- .../WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js | 66 ---------------- .../WoltLabSuite/Core/Acp/Ui/Trophy/Upload.ts | 76 +++++++++++++++++++ 4 files changed, 108 insertions(+), 110 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.ts diff --git a/wcfsetup/install/files/acp/templates/trophyAdd.tpl b/wcfsetup/install/files/acp/templates/trophyAdd.tpl index 2bba55b3ca..d31541f299 100644 --- a/wcfsetup/install/files/acp/templates/trophyAdd.tpl +++ b/wcfsetup/install/files/acp/templates/trophyAdd.tpl @@ -199,9 +199,7 @@ diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js index 2da068953e..5407a8e31b 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js @@ -1,54 +1,44 @@ /** * Handles the trophy image upload. * - * @author Joshua Ruesweg - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Acp/Ui/Trophy/Upload + * @author Joshua Ruesweg + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @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 = ""; - 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 = ``; + 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 index 525dbf7eb8..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.js +++ /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 - * @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 = ""; - - 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 index 0000000000..2889637028 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/Trophy/Upload.ts @@ -0,0 +1,76 @@ +/** + * Handles the trophy image upload. + * + * @author Joshua Ruesweg + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @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) { + 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 = ``; + + 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; -- 2.20.1