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