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/dropeditor.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/dropeditor.js')
| -rw-r--r-- | internal/admin/static/dropeditor.js | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/internal/admin/static/dropeditor.js b/internal/admin/static/dropeditor.js index c5da314..a6537e9 100644 --- a/internal/admin/static/dropeditor.js +++ b/internal/admin/static/dropeditor.js @@ -7,14 +7,14 @@ var DROP_SECTIONS = [ { id: 'drops', label: 'Drops', always: true, path: 'drops', isArray: true, fields: [ - ['item_id', 'Item ID', 'search', '', '', null, 'items'], - ['table', 'Table', 'search', '', '', null, 'drops'], - ['weight', 'Weight', 'number', '', 'narrow'], + ['item_id', 'Item ID', 'search', 'e.g. copper_ore', '', null, 'items'], + ['table', 'Table', 'search', 'e.g. gem_table', '', null, 'drops'], + ['weight', 'Weight', 'number', '10', 'narrow'], ['quantity', 'Quantity', 'number', '1', 'narrow'], - ['level', 'Level', 'number', '', 'narrow'], - ['xp', 'XP', 'number', '', 'narrow'], + ['level', 'Level', 'number', '1', 'narrow'], + ['xp', 'XP', 'number', '5', 'narrow'], ['depletes', 'Depletes', 'checkbox'], - ['success_message', 'Success Message', 'text', '', 'wide'], + ['success_message', 'Success Message', 'text', 'You get some %n.', 'wide'], ] } ]; @@ -75,6 +75,7 @@ function renderDropEditor(id, data) { html += '<div class="btn-row">'; html += '<button class="btn btn-primary" onclick="saveDrop()">Save</button>'; + html += '<button class="btn" onclick="duplicateDrop()">Duplicate</button>'; html += '<button class="btn btn-danger" onclick="deleteDrop()">Delete</button>'; html += '<button class="btn btn-sm" style="margin-left:auto" onclick="createNewDir()">New Directory</button>'; html += '</div>'; @@ -226,3 +227,45 @@ function deleteDrop() { loadList(); }).catch(function(e) { notify('Delete failed: ' + e.message, 'error'); }); } + +function duplicateDrop() { + var baseID = dropID + '_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++; + } + + var copy = JSON.parse(JSON.stringify(dropData)); + delete copy._raw; + delete copy._path; + copy.id = newID; + + var dir = ''; + if (dropData._path) { + var parts = dropData._path.split('/'); + var parentDir = parts[parts.length - 2]; + if (parentDir !== 'drops') dir = parentDir; + } + + API.post('/api/drops', {id: newID}).then(function() { + var putOp = API.put('/api/drops/' + encodeURIComponent(newID), copy); + if (dir) { + return putOp.then(function() { + return API.post('/api/drops/move', {id: newID, dir: dir}); + }); + } + return putOp; + }).then(function() { + notify('Duplicated as ' + newID, 'success'); + updateUndoBar(); + loadList(); + loadDropEditor(newID); + }).catch(function(e) { notify('Duplicate failed: ' + e.message, 'error'); }); +} |
