From 7b5ed92e003d8a4bf9bdc69d43b7354eb2260dfa Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Sun, 5 Jul 2026 19:18:50 -0400 Subject: feat: duplicate items/obj/mobs from sidebar. item inputs fields changed to search fields --- internal/admin/static/editor.js | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'internal/admin/static/editor.js') diff --git a/internal/admin/static/editor.js b/internal/admin/static/editor.js index a9c1e1c..50d86f1 100644 --- a/internal/admin/static/editor.js +++ b/internal/admin/static/editor.js @@ -340,12 +340,57 @@ function showItemContextMenu(e, id) { } addBtn('Rename', '', function() { startInlineItemRename(id); }); + addBtn('Duplicate', '', function() { duplicateFromMenu(id); }); addBtn('Delete', 'danger', function() { deleteItem(id); }); document.body.appendChild(overlay); document.body.appendChild(menu); } +function duplicateFromMenu(id) { + API.get('/api/' + editorType + '/' + encodeURIComponent(id)).then(function(data) { + var dir = ''; + if (data._path) { + var parts = data._path.split('/'); + var parentDir = parts[parts.length - 2]; + if (parentDir !== editorType) dir = parentDir; + } + var clean = JSON.parse(JSON.stringify(data)); + delete clean._raw; + delete clean._path; + clean.id = ''; + + var baseID = id + '_copy'; + var newID = baseID; + var counter = 2; + while (true) { + var exists = false; + for (var i = 0; i < allIDs.length; i++) { + if (allIDs[i] === newID) { exists = true; break; } + } + if (!exists) break; + newID = baseID + '_' + counter; + counter++; + } + + clean.id = newID; + API.post('/api/' + editorType, {id: newID}).then(function() { + var putOp = API.put('/api/' + editorType + '/' + encodeURIComponent(newID), clean); + if (dir) { + return putOp.then(function() { + return API.post('/api/' + editorType + '/move', {id: newID, dir: dir}); + }); + } + return putOp; + }).then(function() { + notify('Duplicated as ' + newID, 'success'); + updateUndoBar(); + loadList(); + loadItem(newID); + }).catch(function(e) { notify('Duplicate failed: ' + e.message, 'error'); }); + }).catch(function(e) { notify('Duplicate failed: ' + e.message, 'error'); }); +} + function closeContextMenu() { var o = document.getElementById('_ctxMenuOverlay'); var m = document.getElementById('_ctxMenu'); -- cgit v1.2.3