aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/static/dropeditor.js
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/static/dropeditor.js')
-rw-r--r--internal/admin/static/dropeditor.js55
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'); });
+}