diff options
| author | historia <[not public]> | 2026-07-05 19:18:50 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-07-05 19:18:50 -0400 |
| commit | 7b5ed92e003d8a4bf9bdc69d43b7354eb2260dfa (patch) | |
| tree | 04310b22c25e2d9fe86b2c06e78e12d8f4caa61b /internal/admin/static/editor.js | |
| parent | 6bd5365cc22f84c047c1585e3f54571af46f53e5 (diff) | |
| download | thehouseoficarus-7b5ed92e003d8a4bf9bdc69d43b7354eb2260dfa.tar.gz | |
feat: duplicate items/obj/mobs from sidebar. item inputs fields changed to search fields
Diffstat (limited to 'internal/admin/static/editor.js')
| -rw-r--r-- | internal/admin/static/editor.js | 45 |
1 files changed, 45 insertions, 0 deletions
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'); |
