Add Tree Selector

This commit is contained in:
2026-04-23 14:02:41 +02:00
parent c6a292754f
commit 8b13938290
8 changed files with 567 additions and 23 deletions
+49 -22
View File
@@ -1,45 +1,72 @@
function newPage() {
function encodePickedPath(p) {
if (p === '/' || p === '') return '/';
return '/' + p.replace(/^\/+/, '').split('/').map(encodeURIComponent).join('/');
}
function promptPageName(title, initial, confirmLabel, onName) {
var input = document.createElement('input');
input.type = 'text';
input.className = 'modal-input';
input.placeholder = 'New page name';
input.placeholder = 'Page name';
if (initial) input.value = initial;
openModal({
title: 'New page',
title: title,
body: input,
confirm: {
label: 'CREATE',
label: confirmLabel,
onConfirm: function () {
var name = input.value.trim();
if (!name) return;
window.location.href = window.location.pathname +
encodeURIComponent(name) + '/?edit';
onName(name);
}
}
});
}
function movePage() {
var input = document.createElement('input');
input.type = 'text';
input.className = 'modal-input';
input.value = decodeURIComponent(window.location.pathname);
function newPage() {
var current = decodeURIComponent(window.location.pathname).replace(/\/+$/, '') || '/';
openTreePicker({
title: 'New page — where?',
mode: 'folder',
initialPath: current,
preselect: current,
hideFiles: true,
confirmLabel: 'NEXT',
onSelect: function (parentPath) {
promptPageName('New page — name?', '', 'CREATE', function (name) {
var base = parentPath === '/' ? '/' : encodePickedPath(parentPath) + '/';
window.location.href = base + encodeURIComponent(name) + '/?edit';
});
}
});
}
openModal({
title: 'Move page',
body: input,
confirm: {
label: 'MOVE',
onConfirm: function () {
var target = input.value.trim();
if (!target || !target.startsWith('/')) return;
function movePage() {
var current = decodeURIComponent(window.location.pathname).replace(/\/+$/, '');
if (!current) return;
var segs = current.split('/').filter(Boolean);
var currentName = segs[segs.length - 1] || '';
var parent = '/' + segs.slice(0, -1).join('/');
if (parent === '/') parent = '/';
openTreePicker({
title: 'Move — new parent?',
mode: 'folder',
initialPath: parent,
preselect: parent,
hideFiles: true,
confirmLabel: 'NEXT',
allowRoot: false,
onSelect: function (newParent) {
promptPageName('Move — new name?', currentName, 'MOVE', function (name) {
var dest = (newParent === '/' ? '' : newParent) + '/' + name;
var form = document.createElement('form');
form.method = 'POST';
form.action = window.location.pathname + '?move=' +
encodeURIComponent(target);
encodeURIComponent(dest);
document.body.appendChild(form);
form.submit();
}
});
}
});
}