From f572a601c4d2cf7a73ed7a17ca3791c0179fc292 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 16 Jun 2024 20:36:23 +0200 Subject: [PATCH] feat(webui): add option to rename items --- src/controllers/api/nameWeaponController.ts | 8 +++-- static/webui/script.js | 38 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/controllers/api/nameWeaponController.ts b/src/controllers/api/nameWeaponController.ts index 7caf40b5..7543cbc4 100644 --- a/src/controllers/api/nameWeaponController.ts +++ b/src/controllers/api/nameWeaponController.ts @@ -15,9 +15,13 @@ export const nameWeaponController: RequestHandler = async (req, res) => { const item = inventory[req.query.Category as string as TEquipmentKey].find( item => item._id.toString() == (req.query.ItemId as string) )!; - item.ItemName = body.ItemName; + if (body.ItemName != "") { + item.ItemName = body.ItemName; + } else { + item.ItemName = undefined; + } await inventory.save(); res.json({ - InventoryChanges: await updateCurrency(15, true, accountId) + InventoryChanges: await updateCurrency("webui" in req.query ? 0 : 15, true, accountId) }); }; diff --git a/static/webui/script.js b/static/webui/script.js index a4696e14..6a9d525d 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -151,6 +151,18 @@ function updateInventory() { a.innerHTML = ``; td.appendChild(a); } + { + const a = document.createElement("a"); + a.href = "#"; + a.onclick = function (event) { + event.preventDefault(); + const name = prompt("Enter new custom name:"); + renameGear("Suits", item.ItemId.$oid, name); + }; + a.title = "Rename"; + a.innerHTML = ``; + td.appendChild(a); + } { const a = document.createElement("a"); a.href = "#"; @@ -193,6 +205,18 @@ function updateInventory() { a.innerHTML = ``; td.appendChild(a); } + { + const a = document.createElement("a"); + a.href = "#"; + a.onclick = function (event) { + event.preventDefault(); + const name = prompt("Enter new custom name:"); + renameGear(category, item.ItemId.$oid, name); + }; + a.title = "Rename"; + a.innerHTML = ``; + td.appendChild(a); + } { const a = document.createElement("a"); a.href = "#"; @@ -426,6 +450,20 @@ function addGearExp(category, oid, xp) { }); } +function renameGear(category, oid, name) { + revalidateAuthz(() => { + $.post({ + url: "/api/nameWeapon.php?" + window.authz + "&Category=" + category + "&ItemId=" + oid + "&webui=1", + contentType: "text/plain", + data: JSON.stringify({ + ItemName: name + }) + }).done(function () { + updateInventory(); + }); + }); +} + function disposeOfGear(category, oid) { const data = { SellCurrency: "SC_RegularCredits",