From 6bd5365cc22f84c047c1585e3f54571af46f53e5 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Sun, 5 Jul 2026 18:52:51 -0400 Subject: feat: renameable directories and files in admin gui --- internal/admin/static/admin.js | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'internal/admin/static/admin.js') diff --git a/internal/admin/static/admin.js b/internal/admin/static/admin.js index f8e9d13..a6bb8b2 100644 --- a/internal/admin/static/admin.js +++ b/internal/admin/static/admin.js @@ -52,4 +52,69 @@ window.saveForm = function(url, data, msg) { }).catch(function(e) { notify('Save failed: '+e.message, 'error'); }); }; +window.entityRename = function(type, oldID, newID) { + return API.post('/api/' + type + '/rename', {id: oldID, new_id: newID}).then(function(r) { + notify('Renamed ' + oldID + ' to ' + newID, 'success'); + updateUndoBar(); + return r; + }); +}; + +window.renderRenameableHeader = function(label, id) { + var h = '
'; + h += '

' + esc(label) + ': ' + esc(id) + '

'; + h += '\u270E'; + h += ''; + h += '
'; + return h; +}; + +window.handleHeaderRename = function(oldID, newID) { + var type = window.editorType || ''; + if (!type) return; + entityRename(type, oldID, newID).then(function() { + window.currentID = newID; + var typeSingular = type.slice(0, -1) + 'ID'; + if (window[typeSingular] !== undefined) window[typeSingular] = newID; + if (window.loadList) window.loadList(); + if (window.loadItem) window.loadItem(newID); + }).catch(function(e) { notify('Rename failed: ' + e.message, 'error'); }); +}; + +window.startHeaderRename = function(pencilEl, oldID) { + var header = pencilEl.parentElement; + var textSpan = header.querySelector('.rename-header-text'); + var editRow = header.querySelector('.rename-edit-row'); + + textSpan.style.display = 'none'; + pencilEl.style.display = 'none'; + editRow.style.display = 'flex'; + editRow.innerHTML = '' + + '' + + ''; + + var input = editRow.querySelector('.rename-input'); + var confirmBtn = editRow.querySelector('.rename-btn-confirm'); + var cancelBtn = editRow.querySelector('.rename-btn-cancel'); + + input.focus(); + input.select(); + + function cancel() { + textSpan.style.display = ''; + pencilEl.style.display = ''; + editRow.style.display = 'none'; + } + + function confirm() { + var newID = input.value.trim(); + if (!newID || newID === oldID) { cancel(); return; } + if (window.handleHeaderRename) handleHeaderRename(oldID, newID); + } + + cancelBtn.onclick = cancel; + input.onkeydown = function(e) { if (e.key === 'Enter') confirm(); else if (e.key === 'Escape') cancel(); }; + confirmBtn.onclick = confirm; +}; + document.addEventListener('DOMContentLoaded', function() { updateUndoBar(); }); -- cgit v1.2.3