diff --git a/com.woltlab.wcf/fileDelete.xml b/com.woltlab.wcf/fileDelete.xml index 154738101c9..3336abf1ebc 100644 --- a/com.woltlab.wcf/fileDelete.xml +++ b/com.woltlab.wcf/fileDelete.xml @@ -26,6 +26,8 @@ acp/images/wcfLogoWhite.svg acp/install.php acp/js/WCF.ACP.User.js + acp/js/WCF.ACP.Language.js + acp/js/WCF.ACP.Language.min.js acp/js/wcombined.min.js acp/post_install.php acp/pre_update_com.woltlab.wcf_2.1.php diff --git a/ts/WoltLabSuite/Core/Acp/Ui/Language/ItemList.ts b/ts/WoltLabSuite/Core/Acp/Ui/Language/ItemList.ts new file mode 100644 index 00000000000..4e8072ad828 --- /dev/null +++ b/ts/WoltLabSuite/Core/Acp/Ui/Language/ItemList.ts @@ -0,0 +1,80 @@ +/** + * Handles language item list. + * + * @author Olaf Braun + * @copyright 2001-2024 WoltLab GmbH + * @license GNU Lesser General Public License + */ + +import { dboAction } from "WoltLabSuite/Core/Ajax"; +import { dialogFactory } from "WoltLabSuite/Core/Component/Dialog"; +import { getPhrase } from "WoltLabSuite/Core/Language"; +import { confirmationFactory } from "WoltLabSuite/Core/Component/Confirmation"; +import { show as showNotification } from "WoltLabSuite/Core/Ui/Notification"; + +interface BeginEditResponse { + languageItem: string; + isCustomLanguageItem: boolean; + template: string; +} + +export function init() { + document.querySelectorAll(".jsLanguageItem").forEach((button) => { + button.addEventListener("click", () => { + void beginEdit(parseInt(button.dataset.languageItemId!, 10)); + }); + }); +} + +async function beginEdit(languageItemID: number) { + const result = (await dboAction("prepareEdit", "wcf\\data\\language\\item\\LanguageItemAction") + .objectIds([languageItemID]) + .dispatch()) as BeginEditResponse; + + const dialog = dialogFactory() + .fromHtml(result.template) + .asPrompt( + result.isCustomLanguageItem + ? { + extra: getPhrase("wcf.global.button.delete"), + } + : undefined, + ); + + dialog.addEventListener("extra", () => { + void confirmationFactory() + .custom(getPhrase("wcf.global.confirmation.title")) + .message(getPhrase("wcf.acp.language.item.delete.confirmMessage")) + .then((result) => { + if (result) { + void dboAction("deleteCustomLanguageItems", "wcf\\data\\language\\item\\LanguageItemAction") + .objectIds([languageItemID]) + .dispatch(); + + dialog.close(); + + window.location.reload(); + } + }); + }); + + dialog.addEventListener("primary", () => { + const languageItemValue = dialog.querySelector('[name="languageItemValue"]')?.value; + const languageCustomItemValue = dialog.querySelector('[name="languageCustomItemValue"]')?.value; + const languageUseCustomValue = dialog.querySelector('[name="languageUseCustomValue"]')?.checked; + + void dboAction("edit", "wcf\\data\\language\\item\\LanguageItemAction") + .objectIds([languageItemID]) + .payload({ + languageItemValue: languageItemValue ?? null, + languageCustomItemValue: languageCustomItemValue ?? null, + languageUseCustomValue: languageUseCustomValue ?? null, + }) + .dispatch() + .then(() => { + showNotification(); + }); + }); + + dialog.show(result.languageItem); +} diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.Language.js b/wcfsetup/install/files/acp/js/WCF.ACP.Language.js deleted file mode 100644 index 4a46e47f316..00000000000 --- a/wcfsetup/install/files/acp/js/WCF.ACP.Language.js +++ /dev/null @@ -1,155 +0,0 @@ -/** - * ACP Language related classes. - * - * @author Marcel Werk - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - */ -WCF.ACP.Language = { }; - -/** - * Handles language item list management. - * - * @param integer count - * @param integer pageNo - */ -WCF.ACP.Language.ItemList = Class.extend({ - /** - * action proxy - * @var WCF.Action.Proxy - */ - _proxy: null, - - /** - * dialog overlay - * @var jQuery - */ - _dialog: null, - - /** - * notification object - * @var WCF.System.Notification - */ - _notification: null, - - /** - * Initializes the WCF.ACP.Style.List class. - */ - init: function() { - this._proxy = new WCF.Action.Proxy({ - success: $.proxy(this._success, this) - }); - - $('.jsLanguageItem').each($.proxy(function(index, button) { - var $button = $(button); - var $languageItemID = $button.data('languageItemID'); - - var self = this; - $button.click(function() { self._click($languageItemID); }); - }, this)); - }, - - /** - * Executes actions. - * - * @param integer languageItemID - */ - _click: function(languageItemID) { - this._proxy.setOption('data', { - actionName: 'prepareEdit', - className: 'wcf\\data\\language\\item\\LanguageItemAction', - objectIDs: [ languageItemID ] - }); - this._proxy.sendRequest(); - }, - - /** - * Handles clicking on the delete language item button. - */ - _delete: function() { - WCF.System.Confirmation.show(WCF.Language.get('wcf.acp.language.item.delete.confirmMessage'), function (action) { - if (action !== 'cancel') { - this._proxy.setOption('data', { - actionName: 'deleteCustomLanguageItems', - className: 'wcf\\data\\language\\item\\LanguageItemAction', - objectIDs: [ $('#overlayLanguageItemID').val() ] - }); - this._proxy.sendRequest(); - } - }.bind(this)); - }, - - /** - * Handles successful AJAX requests. - * - * @param object data - * @param string textStatus - * @param jQuery jqXHR - */ - _success: function(data, textStatus, jqXHR) { - if (data.returnValues) { - // display template - this._showDialog(data.returnValues.template, data.returnValues.languageItem); - - // bind event listener - this._dialog.find('.jsSubmitLanguageItem').click($.proxy(this._submit, this)); - this._dialog.find('.jsDeleteLanguageItem').click($.proxy(this._delete, this)); - } - else { - if (this._notification === null) { - this._notification = new WCF.System.Notification(WCF.Language.get('wcf.global.success.edit')); - } - - // show success and close dialog - this._dialog.wcfDialog('close'); - - if (data.actionName === 'deleteCustomLanguageItems') { - this._notification.show(window.location.reload.bind(window.location)); - } - else { - this._notification.show(); - } - } - }, - - /** - * Displays the dialog overlay. - * - * @param string template - * @param string itemName - */ - _showDialog: function(template, itemName) { - if (this._dialog === null) { - this._dialog = $('#languageItemEdit'); - if (!this._dialog.length) { - this._dialog = $('
').hide().appendTo(document.body); - } - } - - this._dialog.html(template).wcfDialog({ - title: itemName - }).wcfDialog('render'); - }, - - /** - * Submits the form. - */ - _submit: function() { - var $languageItemValue = $('#overlayLanguageItemValue').val(); - var $languageCustomItemValue = $('#overlayLanguageCustomItemValue').val(); - var $languageUseCustomValue = ($('#overlayLanguageUseCustomValue').is(':checked') ? 1 : 0); - var $languageItemID = $('#overlayLanguageItemID').val(); - - this._proxy.setOption('data', { - actionName: 'edit', - className: 'wcf\\data\\language\\item\\LanguageItemAction', - objectIDs: [ $languageItemID ], - parameters: { - languageItemValue: $languageItemValue, - languageCustomItemValue: $languageCustomItemValue, - languageUseCustomValue: $languageUseCustomValue - } - }); - this._proxy.sendRequest(); - } -}); diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.Language.min.js b/wcfsetup/install/files/acp/js/WCF.ACP.Language.min.js deleted file mode 100644 index 9bc2a798eae..00000000000 --- a/wcfsetup/install/files/acp/js/WCF.ACP.Language.min.js +++ /dev/null @@ -1 +0,0 @@ -WCF.ACP.Language={},WCF.ACP.Language.ItemList=Class.extend({_proxy:null,_dialog:null,_notification:null,init:function(){this._proxy=new WCF.Action.Proxy({success:$.proxy(this._success,this)}),$(".jsLanguageItem").each($.proxy((function(e,t){var a=$(t),i=a.data("languageItemID"),n=this;a.click((function(){n._click(i)}))}),this))},_click:function(e){this._proxy.setOption("data",{actionName:"prepareEdit",className:"wcf\\data\\language\\item\\LanguageItemAction",objectIDs:[e]}),this._proxy.sendRequest()},_delete:function(){WCF.System.Confirmation.show(WCF.Language.get("wcf.acp.language.item.delete.confirmMessage"),function(e){"cancel"!==e&&(this._proxy.setOption("data",{actionName:"deleteCustomLanguageItems",className:"wcf\\data\\language\\item\\LanguageItemAction",objectIDs:[$("#overlayLanguageItemID").val()]}),this._proxy.sendRequest())}.bind(this))},_success:function(e,t,a){e.returnValues?(this._showDialog(e.returnValues.template,e.returnValues.languageItem),this._dialog.find(".jsSubmitLanguageItem").click($.proxy(this._submit,this)),this._dialog.find(".jsDeleteLanguageItem").click($.proxy(this._delete,this))):(null===this._notification&&(this._notification=new WCF.System.Notification(WCF.Language.get("wcf.global.success.edit"))),this._dialog.wcfDialog("close"),"deleteCustomLanguageItems"===e.actionName?this._notification.show(window.location.reload.bind(window.location)):this._notification.show())},_showDialog:function(e,t){null===this._dialog&&(this._dialog=$("#languageItemEdit"),this._dialog.length||(this._dialog=$('
').hide().appendTo(document.body))),this._dialog.html(e).wcfDialog({title:t}).wcfDialog("render")},_submit:function(){var e=$("#overlayLanguageItemValue").val(),t=$("#overlayLanguageCustomItemValue").val(),a=$("#overlayLanguageUseCustomValue").is(":checked")?1:0,i=$("#overlayLanguageItemID").val();this._proxy.setOption("data",{actionName:"edit",className:"wcf\\data\\language\\item\\LanguageItemAction",objectIDs:[i],parameters:{languageItemValue:e,languageCustomItemValue:t,languageUseCustomValue:a}}),this._proxy.sendRequest()}}); \ No newline at end of file diff --git a/wcfsetup/install/files/acp/templates/languageItemEditDialog.tpl b/wcfsetup/install/files/acp/templates/languageItemEditDialog.tpl index 3b3b327098f..5b2d8e563f0 100644 --- a/wcfsetup/install/files/acp/templates/languageItemEditDialog.tpl +++ b/wcfsetup/install/files/acp/templates/languageItemEditDialog.tpl @@ -4,7 +4,7 @@
- +
@@ -32,23 +32,13 @@
- +
-
+
{/if} - - - -
- - - {if $item->isCustomLanguageItem} - - {/if} -
diff --git a/wcfsetup/install/files/acp/templates/languageItemList.tpl b/wcfsetup/install/files/acp/templates/languageItemList.tpl index 9b2103c89c6..07d91a1276b 100644 --- a/wcfsetup/install/files/acp/templates/languageItemList.tpl +++ b/wcfsetup/install/files/acp/templates/languageItemList.tpl @@ -1,11 +1,10 @@ {include file='header' pageTitle="wcf.acp.language.item.list"} - diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Language/ItemList.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Language/ItemList.js new file mode 100644 index 00000000000..95ce1a8c903 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Language/ItemList.js @@ -0,0 +1,62 @@ +/** + * Handles language item list. + * + * @author Olaf Braun + * @copyright 2001-2024 WoltLab GmbH + * @license GNU Lesser General Public License + */ +define(["require", "exports", "WoltLabSuite/Core/Ajax", "WoltLabSuite/Core/Component/Dialog", "WoltLabSuite/Core/Language", "WoltLabSuite/Core/Component/Confirmation", "WoltLabSuite/Core/Ui/Notification"], function (require, exports, Ajax_1, Dialog_1, Language_1, Confirmation_1, Notification_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.init = init; + function init() { + document.querySelectorAll(".jsLanguageItem").forEach((button) => { + button.addEventListener("click", () => { + void beginEdit(parseInt(button.dataset.languageItemId, 10)); + }); + }); + } + async function beginEdit(languageItemID) { + const result = (await (0, Ajax_1.dboAction)("prepareEdit", "wcf\\data\\language\\item\\LanguageItemAction") + .objectIds([languageItemID]) + .dispatch()); + const dialog = (0, Dialog_1.dialogFactory)() + .fromHtml(result.template) + .asPrompt(result.isCustomLanguageItem + ? { + extra: (0, Language_1.getPhrase)("wcf.global.button.delete"), + } + : undefined); + dialog.addEventListener("extra", () => { + void (0, Confirmation_1.confirmationFactory)() + .custom((0, Language_1.getPhrase)("wcf.global.confirmation.title")) + .message((0, Language_1.getPhrase)("wcf.acp.language.item.delete.confirmMessage")) + .then((result) => { + if (result) { + void (0, Ajax_1.dboAction)("deleteCustomLanguageItems", "wcf\\data\\language\\item\\LanguageItemAction") + .objectIds([languageItemID]) + .dispatch(); + dialog.close(); + window.location.reload(); + } + }); + }); + dialog.addEventListener("primary", () => { + const languageItemValue = dialog.querySelector('[name="languageItemValue"]')?.value; + const languageCustomItemValue = dialog.querySelector('[name="languageCustomItemValue"]')?.value; + const languageUseCustomValue = dialog.querySelector('[name="languageUseCustomValue"]')?.checked; + void (0, Ajax_1.dboAction)("edit", "wcf\\data\\language\\item\\LanguageItemAction") + .objectIds([languageItemID]) + .payload({ + languageItemValue: languageItemValue ?? null, + languageCustomItemValue: languageCustomItemValue ?? null, + languageUseCustomValue: languageUseCustomValue ?? null, + }) + .dispatch() + .then(() => { + (0, Notification_1.show)(); + }); + }); + dialog.show(result.languageItem); + } +}); diff --git a/wcfsetup/install/files/lib/data/language/item/LanguageItemAction.class.php b/wcfsetup/install/files/lib/data/language/item/LanguageItemAction.class.php index 2775156b1ab..8fd77193153 100644 --- a/wcfsetup/install/files/lib/data/language/item/LanguageItemAction.class.php +++ b/wcfsetup/install/files/lib/data/language/item/LanguageItemAction.class.php @@ -112,6 +112,7 @@ public function prepareEdit() return [ 'languageItem' => $item->languageItem, + 'isCustomLanguageItem' => $item->isCustomLanguageItem, 'template' => WCF::getTPL()->fetch('languageItemEditDialog'), ]; }