diff options
Diffstat (limited to 'internal/admin/static/moduleeditor.js')
| -rw-r--r-- | internal/admin/static/moduleeditor.js | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/internal/admin/static/moduleeditor.js b/internal/admin/static/moduleeditor.js index 5bcb7bc..ac632e8 100644 --- a/internal/admin/static/moduleeditor.js +++ b/internal/admin/static/moduleeditor.js @@ -8,13 +8,13 @@ var MODULE_SECTIONS = [ { id: 'core', label: 'Core', always: true, fields: [ - ['name', 'Name', 'text'], - ['level', 'Level', 'number', '', 'narrow'], - ['max_hit', 'Max Hit', 'number', '', 'narrow'], - ['base_xp', 'Base XP', 'number', '', 'narrow'], + ['name', 'Name', 'text', 'Fire Blast'], + ['level', 'Level', 'number', '20', 'narrow'], + ['max_hit', 'Max Hit', 'number', '10', 'narrow'], + ['base_xp', 'Base XP', 'number', '50', 'narrow'], ['category', 'Category', 'select', 'combat|utility|enchant|processing|transport'], - ['element', 'Element', 'text'], - ['destination', 'Destination', 'number', '', 'narrow'], + ['element', 'Element', 'text', 'e.g. fire'], + ['destination', 'Destination', 'number', '5', 'narrow'], ], inline: [ {label:'Junk Cost', key:'junk_cost', type:'kv', valType:'number'}, @@ -100,6 +100,7 @@ function renderModuleEditor(id, data) { html += '<div class="btn-row">'; html += '<button class="btn btn-primary" onclick="saveModule()">Save</button>'; + html += '<button class="btn" onclick="duplicateModule()">Duplicate</button>'; html += '<button class="btn btn-danger" onclick="deleteModule()">Delete</button>'; html += '<button class="btn btn-sm" style="margin-left:auto" onclick="createNewDir()">New Directory</button>'; html += '</div>'; @@ -321,3 +322,45 @@ function deleteModule() { loadList(); }).catch(function(e) { notify('Delete failed: ' + e.message, 'error'); }); } + +function duplicateModule() { + var baseID = moduleID + '_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(moduleData)); + delete copy._raw; + delete copy._path; + copy.id = newID; + + var dir = ''; + if (moduleData._path) { + var parts = moduleData._path.split('/'); + var parentDir = parts[parts.length - 2]; + if (parentDir !== 'modules') dir = parentDir; + } + + API.post('/api/modules', {id: newID}).then(function() { + var putOp = API.put('/api/modules/' + encodeURIComponent(newID), copy); + if (dir) { + return putOp.then(function() { + return API.post('/api/modules/move', {id: newID, dir: dir}); + }); + } + return putOp; + }).then(function() { + notify('Duplicated as ' + newID, 'success'); + updateUndoBar(); + loadList(); + loadModuleEditor(newID); + }).catch(function(e) { notify('Duplicate failed: ' + e.message, 'error'); }); +} |
