Add change-password modal and desktop context menu
@@ -91,6 +91,21 @@ const DEFAULT_FOLDER_VIEW_PREFS = {
91
91
foldersFirst: true,
92
92
ascending: true,
93
93
};
94
const FOLDER_SORT_OPTIONS = [
95
{ value: 'alphabetical', label: 'Alphabetically' },
96
{ value: 'fileType', label: 'File type' },
97
{ value: 'lastChanged', label: 'Last changed' },
98
{ value: 'timeUploaded', label: 'Time uploaded' },
99
{ value: 'size', label: 'Size' },
100
];
101
const FOLDER_GROUP_OPTIONS = [
102
{ value: 'none', label: 'None' },
103
{ value: 'alphabetical', label: 'Alphabetically' },
104
{ value: 'fileType', label: 'File type' },
105
{ value: 'lastChangedDate', label: 'Last changed date' },
106
{ value: 'timeUploadedDate', label: 'Upload date' },
107
{ value: 'size', label: 'Size' },
108
];
94
109
const VIDEO_FORWARD_BUFFER_SECONDS = 60 * 60;
95
110
const VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED = false;
96
111
let videoJsLoaderPromise = null;
@@ -1789,6 +1804,67 @@ function logout ()
1789
1804
void performLogout();
1790
1805
}
1791
1806
1807
function openChangePasswordModal ()
1808
{
1809
const modal = document.getElementById('change-password-modal');
1810
const form = document.getElementById('change-password-form');
1811
const currentInput = document.getElementById('change-password-current');
1812
const nextInput = document.getElementById('change-password-next');
1813
const confirmInput = document.getElementById('change-password-confirm');
1814
const errorEl = document.getElementById('change-password-error');
1815
1816
function hide ()
1817
{
1818
modal.classList.add('hidden');
1819
form.onsubmit = null;
1820
}
1821
1822
currentInput.value = '';
1823
nextInput.value = '';
1824
confirmInput.value = '';
1825
errorEl.textContent = '';
1826
errorEl.classList.add('hidden');
1827
modal.classList.remove('hidden');
1828
currentInput.focus();
1829
1830
form.onsubmit = async (e) =>
1831
{
1832
e.preventDefault();
1833
const currentPassword = currentInput.value;
1834
const newPassword = nextInput.value;
1835
const confirmPassword = confirmInput.value;
1836
1837
if (newPassword !== confirmPassword)
1838
{
1839
errorEl.textContent = 'New passwords do not match.';
1840
errorEl.classList.remove('hidden');
1841
return;
1842
}
1843
1844
if (newPassword.length < 8)
1845
{
1846
errorEl.textContent = 'New password must be at least 8 characters.';
1847
errorEl.classList.remove('hidden');
1848
return;
1849
}
1850
1851
try
1852
{
1853
await api('POST', '/auth/change-password', {
1854
currentPassword,
1855
newPassword,
1856
});
1857
hide();
1858
toast('Password changed.', 'ok');
1859
}
1860
catch (err)
1861
{
1862
errorEl.textContent = err.message || 'Failed to change password.';
1863
errorEl.classList.remove('hidden');
1864
}
1865
};
1866
}
1867
1792
1868
async function performLogout ()
1793
1869
{
1794
1870
const tokenAtStart = STATE.token;
@@ -2445,9 +2521,16 @@ function makeFileItem (item)
2445
2521
2446
2522
el.addEventListener('contextmenu', (e) =>
2447
2523
{
2448
if (!isMobileViewport()) return;
2449
2524
e.preventDefault();
2450
2525
e.stopPropagation();
2526
2527
if (isMobileViewport()) return;
2528
if (el.classList.contains('file-item--preview')) return;
2529
2530
document.querySelectorAll('.file-item.selected').forEach(node => node.classList.remove('selected'));
2531
el.classList.add('selected');
2532
STATE.selectedItem = item;
2533
openItemContextMenu(item, e.clientX, e.clientY);
2451
2534
});
2452
2535
2453
2536
// Single-click: open sidebar
@@ -2679,6 +2762,277 @@ async function navigateToDuplicate (dup)
2679
2762
selectItem(tile, dupItem);
2680
2763
}
2681
2764
}
2765
2766
function renderItemActionButtons (actions, item)
2767
{
2768
if (!actions || !item) return;
2769
actions.innerHTML = '';
2770
2771
if (!item.isDir)
2772
{
2773
const btnDl = document.createElement('button');
2774
btnDl.textContent = 'View / Download';
2775
btnDl.addEventListener('click', () =>
2776
{
2777
const tile = Array.from(document.querySelectorAll('.file-item')).find(node => node.dataset.path === item.path);
2778
const source = (tile ? tile.querySelector('.icon svg') : null) || document.querySelector('#sidebar-icon svg');
2779
downloadOrView(item, source);
2780
});
2781
actions.appendChild(btnDl);
2782
2783
const btnShareFile = document.createElement('button');
2784
btnShareFile.textContent = 'Share';
2785
btnShareFile.addEventListener('click', () => openShareModal(item));
2786
actions.appendChild(btnShareFile);
2787
}
2788
else
2789
{
2790
const btnOpen = document.createElement('button');
2791
btnOpen.textContent = 'Open folder';
2792
btnOpen.addEventListener('click', () => navigateTo(item.path, item._root || STATE.currentRoot));
2793
actions.appendChild(btnOpen);
2794
2795
const btnZip = document.createElement('button');
2796
btnZip.textContent = 'Download as zip';
2797
btnZip.addEventListener('click', () =>
2798
{
2799
btnZip.disabled = true;
2800
btnZip.textContent = 'Working...';
2801
const url = `/api/files/download-zip?dir=${encodeURIComponent(item.path)}`;
2802
const headers = {
2803
Authorization: 'Bearer ' + STATE.token,
2804
'X-Fp': getFingerprint(),
2805
};
2806
fetch(url, { headers })
2807
.then(res =>
2808
{
2809
if (!res.ok) throw new Error('Download mislukt');
2810
return res.blob();
2811
})
2812
.then(blob =>
2813
{
2814
const blobUrl = URL.createObjectURL(blob);
2815
const a = document.createElement('a');
2816
a.href = blobUrl;
2817
a.download = item.name + '.zip';
2818
a.click();
2819
setTimeout(() => URL.revokeObjectURL(blobUrl), 10000);
2820
})
2821
.catch((err) => toast(err.message || 'Download mislukt', 'err'))
2822
.finally(() =>
2823
{
2824
btnZip.disabled = false;
2825
btnZip.textContent = 'Download as zip';
2826
});
2827
});
2828
actions.appendChild(btnZip);
2829
2830
const btnShareFolder = document.createElement('button');
2831
btnShareFolder.textContent = 'Share';
2832
btnShareFolder.addEventListener('click', () => openShareModal(item));
2833
actions.appendChild(btnShareFolder);
2834
}
2835
2836
if (!canWrite(item)) return;
2837
2838
if (item.isDir)
2839
{
2840
const btnSetIcon = document.createElement('button');
2841
btnSetIcon.textContent = 'Set icon';
2842
btnSetIcon.addEventListener('click', () => openFolderIconPicker(item));
2843
actions.appendChild(btnSetIcon);
2844
}
2845
2846
if (!item._root)
2847
{
2848
const btnMove = document.createElement('button');
2849
btnMove.textContent = 'Move to';
2850
btnMove.addEventListener('click', () => openMovePicker(item));
2851
actions.appendChild(btnMove);
2852
2853
if (!item.isDir)
2854
{
2855
const btnCopy = document.createElement('button');
2856
btnCopy.textContent = 'Copy to';
2857
btnCopy.addEventListener('click', () => openCopyPicker(item));
2858
actions.appendChild(btnCopy);
2859
}
2860
}
2861
2862
const btnRen = document.createElement('button');
2863
btnRen.textContent = 'Rename';
2864
btnRen.addEventListener('click', () => openRenameModal(item));
2865
actions.appendChild(btnRen);
2866
2867
if (!item._root)
2868
{
2869
const btnDel = document.createElement('button');
2870
btnDel.textContent = 'Delete';
2871
btnDel.className = 'danger';
2872
btnDel.addEventListener('click', () => deleteItem(item));
2873
actions.appendChild(btnDel);
2874
}
2875
}
2876
2877
function closeCustomContextMenu ()
2878
{
2879
const menu = document.getElementById('custom-context-menu');
2880
if (!menu) return;
2881
menu.classList.add('hidden');
2882
menu.innerHTML = '';
2883
}
2884
2885
function ensureCustomContextMenu ()
2886
{
2887
let menu = document.getElementById('custom-context-menu');
2888
if (menu) return menu;
2889
2890
menu = document.createElement('div');
2891
menu.id = 'custom-context-menu';
2892
menu.className = 'custom-context-menu hidden';
2893
menu.setAttribute('role', 'menu');
2894
menu.setAttribute('aria-label', 'Context menu');
2895
menu.addEventListener('click', (e) => e.stopPropagation());
2896
document.body.appendChild(menu);
2897
return menu;
2898
}
2899
2900
function openCustomContextMenuAt (x, y, build)
2901
{
2902
const menu = ensureCustomContextMenu();
2903
menu.innerHTML = '';
2904
build(menu);
2905
if (!menu.childElementCount)
2906
{
2907
closeCustomContextMenu();
2908
return;
2909
}
2910
2911
menu.classList.remove('hidden');
2912
menu.style.left = '0px';
2913
menu.style.top = '0px';
2914
2915
const maxLeft = Math.max(6, window.innerWidth - menu.offsetWidth - 6);
2916
const maxTop = Math.max(6, window.innerHeight - menu.offsetHeight - 6);
2917
menu.style.left = `${Math.min(Math.max(6, x), maxLeft)}px`;
2918
menu.style.top = `${Math.min(Math.max(6, y), maxTop)}px`;
2919
}
2920
2921
function addContextMenuButton (menu, label, onClick, { danger = false, checked = null, hasSubmenu = false } = {})
2922
{
2923
const btn = document.createElement('button');
2924
btn.type = 'button';
2925
btn.className = 'custom-context-menu-item';
2926
if (danger) btn.classList.add('danger');
2927
if (checked !== null) btn.classList.add('custom-context-menu-item--check');
2928
if (hasSubmenu) btn.classList.add('custom-context-menu-item--submenu');
2929
2930
const labelEl = document.createElement('span');
2931
if (checked === true) labelEl.textContent = '✓ ' + label;
2932
else if (checked === false) labelEl.textContent = '□ ' + label;
2933
else labelEl.textContent = label;
2934
btn.appendChild(labelEl);
2935
2936
if (hasSubmenu)
2937
{
2938
const arrow = document.createElement('span');
2939
arrow.textContent = '›';
2940
btn.appendChild(arrow);
2941
}
2942
2943
btn.addEventListener('click', async (e) =>
2944
{
2945
e.stopPropagation();
2946
await onClick();
2947
closeCustomContextMenu();
2948
});
2949
menu.appendChild(btn);
2950
return btn;
2951
}
2952
2953
function addContextMenuSeparator (menu)
2954
{
2955
const sep = document.createElement('div');
2956
sep.className = 'custom-context-menu-separator';
2957
menu.appendChild(sep);
2958
}
2959
2960
function addContextMenuSubmenu (menu, label, options)
2961
{
2962
const row = document.createElement('div');
2963
row.className = 'custom-context-menu-row';
2964
const trigger = addContextMenuButton(row, label, () => {}, { hasSubmenu: true });
2965
trigger.addEventListener('click', (e) => e.preventDefault());
2966
2967
const panel = document.createElement('div');
2968
panel.className = 'custom-context-submenu';
2969
for (const option of options)
2970
{
2971
addContextMenuButton(panel, option.label, option.onClick, {
2972
checked: option.checked,
2973
});
2974
}
2975
row.appendChild(panel);
2976
menu.appendChild(row);
2977
}
2978
2979
function openItemContextMenu (item, x, y)
2980
{
2981
openCustomContextMenuAt(x, y, (menu) =>
2982
{
2983
renderItemActionButtons(menu, item);
2984
menu.querySelectorAll('button').forEach((btn) =>
2985
{
2986
if (btn.classList.contains('danger')) btn.classList.add('danger');
2987
btn.addEventListener('click', () => closeCustomContextMenu(), { once: true });
2988
});
2989
});
2990
}
2991
2992
function openFolderContextMenu (x, y)
2993
{
2994
if (!STATE.currentDir)
2995
{
2996
closeCustomContextMenu();
2997
return;
2998
}
2999
3000
const prefs = folderViewPrefsForDir(STATE.currentDir);
3001
const makeOptionHandler = (patch) => async () =>
3002
{
3003
saveFolderViewPrefsForDir(STATE.currentDir, patch);
3004
renderFileGrid();
3005
};
3006
3007
openCustomContextMenuAt(x, y, (menu) =>
3008
{
3009
if (canWrite())
3010
{
3011
addContextMenuButton(menu, 'Create Folder', createFolderInCurrentDir);
3012
addContextMenuSeparator(menu);
3013
}
3014
3015
addContextMenuSubmenu(menu, 'Sort by', FOLDER_SORT_OPTIONS.map((option) => ({
3016
label: option.label,
3017
checked: prefs.sortBy === option.value,
3018
onClick: makeOptionHandler({ sortBy: option.value }),
3019
})));
3020
3021
addContextMenuSubmenu(menu, 'Group by', FOLDER_GROUP_OPTIONS.map((option) => ({
3022
label: option.label,
3023
checked: prefs.groupBy === option.value,
3024
onClick: makeOptionHandler({ groupBy: option.value }),
3025
})));
3026
3027
addContextMenuSeparator(menu);
3028
addContextMenuButton(menu, 'Always keep folders at the top', makeOptionHandler({ foldersFirst: !prefs.foldersFirst }), {
3029
checked: !!prefs.foldersFirst,
3030
});
3031
addContextMenuButton(menu, prefs.ascending ? 'Ascending' : 'Descending', makeOptionHandler({ ascending: !prefs.ascending }), {
3032
checked: !!prefs.ascending,
3033
});
3034
});
3035
}
2682
3036
// ───────────────────────────────────────────────────────────────────────────
2683
3037
2684
3038
async function openSidebar (item)
@@ -2753,22 +3107,6 @@ async function openSidebar (item)
2753
3107
renderSidebarDuplicates(item, []);
2754
3108
});
2755
3109
2756
// View / download button
2757
const btnDl = document.createElement('button');
2758
btnDl.textContent = 'View / Download';
2759
btnDl.addEventListener('click', () =>
2760
{
2761
const tile = Array.from(document.querySelectorAll('.file-item')).find(node => node.dataset.path === item.path);
2762
const source = (tile ? tile.querySelector('.icon svg') : null) || document.querySelector('#sidebar-icon svg');
2763
downloadOrView(item, source);
2764
});
2765
actions.appendChild(btnDl);
2766
2767
// Share button (file)
2768
const btnShareFile = document.createElement('button');
2769
btnShareFile.textContent = 'Share';
2770
btnShareFile.addEventListener('click', () => openShareModal(item));
2771
actions.appendChild(btnShareFile);
2772
3110
} else
2773
3111
{
2774
3112
dl.innerHTML = `<dt>Type</dt><dd>${item._root ? 'Root folder' : 'Folder'}</dd>`;
@@ -2817,99 +3155,15 @@ async function openSidebar (item)
2817
3155
}
2818
3156
}
2819
3157
}
3158
}
2820
3159
2821
const btnOpen = document.createElement('button');
2822
btnOpen.textContent = 'Open folder';
2823
btnOpen.addEventListener('click', () => navigateTo(item.path, item._root || STATE.currentRoot));
2824
actions.appendChild(btnOpen);
2825
2826
// Download as zip button (folder)
2827
const btnZip = document.createElement('button');
2828
btnZip.textContent = 'Download as zip';
2829
btnZip.addEventListener('click', () =>
2830
{
2831
btnZip.disabled = true;
2832
btnZip.textContent = 'Working...';
2833
const url = `/api/files/download-zip?dir=${encodeURIComponent(item.path)}`;
2834
const headers = {
2835
Authorization: 'Bearer ' + STATE.token,
2836
'X-Fp': getFingerprint(),
2837
};
2838
fetch(url, { headers })
2839
.then(res =>
2840
{
2841
if (!res.ok) throw new Error('Download mislukt');
2842
return res.blob();
2843
})
2844
.then(blob =>
2845
{
2846
const blobUrl = URL.createObjectURL(blob);
2847
const a = document.createElement('a');
2848
a.href = blobUrl;
2849
a.download = item.name + '.zip';
2850
a.click();
2851
setTimeout(() => URL.revokeObjectURL(blobUrl), 10000);
2852
})
2853
.catch((err) => toast(err.message || 'Download mislukt', 'err'))
2854
.finally(() =>
2855
{
2856
btnZip.disabled = false;
2857
btnZip.textContent = 'Download as zip';
2858
});
2859
});
2860
actions.appendChild(btnZip);
2861
2862
// Share button (folder)
2863
const btnShareFolder = document.createElement('button');
2864
btnShareFolder.textContent = 'Share';
2865
btnShareFolder.addEventListener('click', () => openShareModal(item));
2866
actions.appendChild(btnShareFolder);
3160
renderItemActionButtons(actions, item);
2867
3161
3162
if (item.isDir)
3163
{
2868
3164
// Load folder icon thumbnail into the sidebar icon element.
2869
3165
void loadOneFolderIcon(document.getElementById('sidebar-icon'));
2870
3166
}
2871
2872
// Rename button (write access required)
2873
if (canWrite(item))
2874
{
2875
if (item.isDir)
2876
{
2877
const btnSetIcon = document.createElement('button');
2878
btnSetIcon.textContent = 'Set icon';
2879
btnSetIcon.addEventListener('click', () => openFolderIconPicker(item));
2880
actions.appendChild(btnSetIcon);
2881
}
2882
2883
if (!item._root)
2884
{
2885
const btnMove = document.createElement('button');
2886
btnMove.textContent = 'Move to';
2887
btnMove.addEventListener('click', () => openMovePicker(item));
2888
actions.appendChild(btnMove);
2889
2890
if (!item.isDir)
2891
{
2892
const btnCopy = document.createElement('button');
2893
btnCopy.textContent = 'Copy to';
2894
btnCopy.addEventListener('click', () => openCopyPicker(item));
2895
actions.appendChild(btnCopy);
2896
}
2897
}
2898
2899
const btnRen = document.createElement('button');
2900
btnRen.textContent = 'Rename';
2901
btnRen.addEventListener('click', () => openRenameModal(item));
2902
actions.appendChild(btnRen);
2903
2904
if (!item._root)
2905
{
2906
const btnDel = document.createElement('button');
2907
btnDel.textContent = 'Delete';
2908
btnDel.className = 'danger';
2909
btnDel.addEventListener('click', () => deleteItem(item));
2910
actions.appendChild(btnDel);
2911
}
2912
}
2913
3167
}
2914
3168
2915
3169
function openFolderSidebar ()
@@ -2994,14 +3248,7 @@ function renderFolderViewControls (actions, dirPath)
2994
3248
const sortSelect = document.createElement('select');
2995
3249
sortSelect.className = 'sidebar-view-option-control';
2996
3250
sortSelect.dataset.viewOption = 'sort';
2997
const sortOptions = [
2998
{ value: 'alphabetical', label: 'Alphabetically' },
2999
{ value: 'fileType', label: 'File type' },
3000
{ value: 'lastChanged', label: 'Last changed' },
3001
{ value: 'timeUploaded', label: 'Time uploaded' },
3002
{ value: 'size', label: 'Size' },
3003
];
3004
for (const option of sortOptions)
3251
for (const option of FOLDER_SORT_OPTIONS)
3005
3252
{
3006
3253
const optEl = document.createElement('option');
3007
3254
optEl.value = option.value;
@@ -3023,15 +3270,7 @@ function renderFolderViewControls (actions, dirPath)
3023
3270
const groupSelect = document.createElement('select');
3024
3271
groupSelect.className = 'sidebar-view-option-control';
3025
3272
groupSelect.dataset.viewOption = 'group';
3026
const groupOptions = [
3027
{ value: 'none', label: 'None' },
3028
{ value: 'alphabetical', label: 'Alphabetically' },
3029
{ value: 'fileType', label: 'File type' },
3030
{ value: 'lastChangedDate', label: 'Last changed date' },
3031
{ value: 'timeUploadedDate', label: 'Upload date' },
3032
{ value: 'size', label: 'Size' },
3033
];
3034
for (const option of groupOptions)
3273
for (const option of FOLDER_GROUP_OPTIONS)
3035
3274
{
3036
3275
const optEl = document.createElement('option');
3037
3276
optEl.value = option.value;
@@ -5090,6 +5329,31 @@ async function downloadOrView (item, sourceSvgEl = null)
5090
5329
// UPLOAD
5091
5330
// ───────────────────────────────────────────────────────────────────────────
5092
5331
5332
async function createFolderInCurrentDir ()
5333
{
5334
if (!STATE.currentDir) { toast('Open a folder first.', 'err'); return; }
5335
if (!canWrite()) { toast('No write access.', 'err'); return; }
5336
5337
const name = await showPrompt('New Folder', 'Enter a name for the new folder:');
5338
if (name == null) return;
5339
const folderName = name.trim();
5340
if (!folderName)
5341
{
5342
toast('Folder name is required.', 'err');
5343
return;
5344
}
5345
5346
try
5347
{
5348
await api('POST', '/files/mkdir', { dir: STATE.currentDir, name: folderName });
5349
toast('Folder created.', 'ok');
5350
await navigateTo(STATE.currentDir, STATE.currentRoot);
5351
} catch (err)
5352
{
5353
toast(err.message, 'err');
5354
}
5355
}
5356
5093
5357
function canWrite (item = null)
5094
5358
{
5095
5359
if (STATE.isAdmin) return true;
@@ -6669,27 +6933,13 @@ function wireEvents ()
6669
6933
6670
6934
document.getElementById('btn-new-folder').addEventListener('click', async () =>
6671
6935
{
6672
if (!STATE.currentDir) { toast('Open a folder first.', 'err'); return; }
6673
if (!canWrite()) { toast('No write access.', 'err'); return; }
6674
6675
const name = await showPrompt('New Folder', 'Enter a name for the new folder:');
6676
if (name == null) return;
6677
const folderName = name.trim();
6678
if (!folderName)
6679
{
6680
toast('Folder name is required.', 'err');
6681
return;
6682
}
6936
await createFolderInCurrentDir();
6937
});
6683
6938
6684
try
6685
{
6686
await api('POST', '/files/mkdir', { dir: STATE.currentDir, name: folderName });
6687
toast('Folder created.', 'ok');
6688
await navigateTo(STATE.currentDir, STATE.currentRoot);
6689
} catch (err)
6690
{
6691
toast(err.message, 'err');
6692
}
6939
document.getElementById('btn-change-password').addEventListener('click', openChangePasswordModal);
6940
document.getElementById('change-password-modal-close').addEventListener('click', () =>
6941
{
6942
document.getElementById('change-password-modal').classList.add('hidden');
6693
6943
});
6694
6944
6695
6945
document.getElementById('sidebar-close').addEventListener('click', (e) =>
@@ -6721,9 +6971,27 @@ function wireEvents ()
6721
6971
// Click outside grid clears selection and returns to folder sidebar info.
6722
6972
document.getElementById('main-content').addEventListener('click', (e) =>
6723
6973
{
6974
closeCustomContextMenu();
6724
6975
if (!e.target.closest('.file-item')) closeSidebar();
6725
6976
});
6726
6977
6978
document.getElementById('main-content').addEventListener('contextmenu', (e) =>
6979
{
6980
if (isMobileViewport()) return;
6981
if (e.target && e.target.closest && e.target.closest('.file-item')) return;
6982
e.preventDefault();
6983
closeSidebar();
6984
openFolderContextMenu(e.clientX, e.clientY);
6985
});
6986
6987
window.addEventListener('resize', closeCustomContextMenu);
6988
window.addEventListener('scroll', closeCustomContextMenu, true);
6989
document.addEventListener('click', closeCustomContextMenu);
6990
document.addEventListener('keydown', (e) =>
6991
{
6992
if (e.key === 'Escape') closeCustomContextMenu();
6993
});
6994
6727
6995
// Admin panel
6728
6996
document.getElementById('btn-admin').addEventListener('click', openAdminModal);
6729
6997
document.getElementById('btn-admin-favicon').addEventListener('click', () =>
@@ -91,6 +91,21 @@ const DEFAULT_FOLDER_VIEW_PREFS = {91
foldersFirst: true,91
foldersFirst: true,92
ascending: true,92
ascending: true,93
};93
};94
const FOLDER_SORT_OPTIONS = [95
{ value: 'alphabetical', label: 'Alphabetically' },96
{ value: 'fileType', label: 'File type' },97
{ value: 'lastChanged', label: 'Last changed' },98
{ value: 'timeUploaded', label: 'Time uploaded' },99
{ value: 'size', label: 'Size' },100
];101
const FOLDER_GROUP_OPTIONS = [102
{ value: 'none', label: 'None' },103
{ value: 'alphabetical', label: 'Alphabetically' },104
{ value: 'fileType', label: 'File type' },105
{ value: 'lastChangedDate', label: 'Last changed date' },106
{ value: 'timeUploadedDate', label: 'Upload date' },107
{ value: 'size', label: 'Size' },108
];94
const VIDEO_FORWARD_BUFFER_SECONDS = 60 * 60;109
const VIDEO_FORWARD_BUFFER_SECONDS = 60 * 60;95
const VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED = false;110
const VIDEO_FORWARD_BUFFER_OVERRIDE_ENABLED = false;96
let videoJsLoaderPromise = null;111
let videoJsLoaderPromise = null;@@ -1789,6 +1804,67 @@ function logout ()1789
void performLogout();1804
void performLogout();1790
}1805
}1791
1806
1807
function openChangePasswordModal ()1808
{1809
const modal = document.getElementById('change-password-modal');1810
const form = document.getElementById('change-password-form');1811
const currentInput = document.getElementById('change-password-current');1812
const nextInput = document.getElementById('change-password-next');1813
const confirmInput = document.getElementById('change-password-confirm');1814
const errorEl = document.getElementById('change-password-error');1815
1816
function hide ()1817
{1818
modal.classList.add('hidden');1819
form.onsubmit = null;1820
}1821
1822
currentInput.value = '';1823
nextInput.value = '';1824
confirmInput.value = '';1825
errorEl.textContent = '';1826
errorEl.classList.add('hidden');1827
modal.classList.remove('hidden');1828
currentInput.focus();1829
1830
form.onsubmit = async (e) =>1831
{1832
e.preventDefault();1833
const currentPassword = currentInput.value;1834
const newPassword = nextInput.value;1835
const confirmPassword = confirmInput.value;1836
1837
if (newPassword !== confirmPassword)1838
{1839
errorEl.textContent = 'New passwords do not match.';1840
errorEl.classList.remove('hidden');1841
return;1842
}1843
1844
if (newPassword.length < 8)1845
{1846
errorEl.textContent = 'New password must be at least 8 characters.';1847
errorEl.classList.remove('hidden');1848
return;1849
}1850
1851
try1852
{1853
await api('POST', '/auth/change-password', {1854
currentPassword,1855
newPassword,1856
});1857
hide();1858
toast('Password changed.', 'ok');1859
}1860
catch (err)1861
{1862
errorEl.textContent = err.message || 'Failed to change password.';1863
errorEl.classList.remove('hidden');1864
}1865
};1866
}1867
1792
async function performLogout ()1868
async function performLogout ()1793
{1869
{1794
const tokenAtStart = STATE.token;1870
const tokenAtStart = STATE.token;@@ -2445,9 +2521,16 @@ function makeFileItem (item)2445
2521
2446
el.addEventListener('contextmenu', (e) =>2522
el.addEventListener('contextmenu', (e) =>2447
{2523
{2448
if (!isMobileViewport()) return;2449
e.preventDefault();2524
e.preventDefault();2450
e.stopPropagation();2525
e.stopPropagation();2526
2527
if (isMobileViewport()) return;2528
if (el.classList.contains('file-item--preview')) return;2529
2530
document.querySelectorAll('.file-item.selected').forEach(node => node.classList.remove('selected'));2531
el.classList.add('selected');2532
STATE.selectedItem = item;2533
openItemContextMenu(item, e.clientX, e.clientY);2451
});2534
});2452
2535
2453
// Single-click: open sidebar2536
// Single-click: open sidebar@@ -2679,6 +2762,277 @@ async function navigateToDuplicate (dup)2679
selectItem(tile, dupItem);2762
selectItem(tile, dupItem);2680
}2763
}2681
}2764
}2765
2766
function renderItemActionButtons (actions, item)2767
{2768
if (!actions || !item) return;2769
actions.innerHTML = '';2770
2771
if (!item.isDir)2772
{2773
const btnDl = document.createElement('button');2774
btnDl.textContent = 'View / Download';2775
btnDl.addEventListener('click', () =>2776
{2777
const tile = Array.from(document.querySelectorAll('.file-item')).find(node => node.dataset.path === item.path);2778
const source = (tile ? tile.querySelector('.icon svg') : null) || document.querySelector('#sidebar-icon svg');2779
downloadOrView(item, source);2780
});2781
actions.appendChild(btnDl);2782
2783
const btnShareFile = document.createElement('button');2784
btnShareFile.textContent = 'Share';2785
btnShareFile.addEventListener('click', () => openShareModal(item));2786
actions.appendChild(btnShareFile);2787
}2788
else2789
{2790
const btnOpen = document.createElement('button');2791
btnOpen.textContent = 'Open folder';2792
btnOpen.addEventListener('click', () => navigateTo(item.path, item._root || STATE.currentRoot));2793
actions.appendChild(btnOpen);2794
2795
const btnZip = document.createElement('button');2796
btnZip.textContent = 'Download as zip';2797
btnZip.addEventListener('click', () =>2798
{2799
btnZip.disabled = true;2800
btnZip.textContent = 'Working...';2801
const url = `/api/files/download-zip?dir=${encodeURIComponent(item.path)}`;2802
const headers = {2803
Authorization: 'Bearer ' + STATE.token,2804
'X-Fp': getFingerprint(),2805
};2806
fetch(url, { headers })2807
.then(res =>2808
{2809
if (!res.ok) throw new Error('Download mislukt');2810
return res.blob();2811
})2812
.then(blob =>2813
{2814
const blobUrl = URL.createObjectURL(blob);2815
const a = document.createElement('a');2816
a.href = blobUrl;2817
a.download = item.name + '.zip';2818
a.click();2819
setTimeout(() => URL.revokeObjectURL(blobUrl), 10000);2820
})2821
.catch((err) => toast(err.message || 'Download mislukt', 'err'))2822
.finally(() =>2823
{2824
btnZip.disabled = false;2825
btnZip.textContent = 'Download as zip';2826
});2827
});2828
actions.appendChild(btnZip);2829
2830
const btnShareFolder = document.createElement('button');2831
btnShareFolder.textContent = 'Share';2832
btnShareFolder.addEventListener('click', () => openShareModal(item));2833
actions.appendChild(btnShareFolder);2834
}2835
2836
if (!canWrite(item)) return;2837
2838
if (item.isDir)2839
{2840
const btnSetIcon = document.createElement('button');2841
btnSetIcon.textContent = 'Set icon';2842
btnSetIcon.addEventListener('click', () => openFolderIconPicker(item));2843
actions.appendChild(btnSetIcon);2844
}2845
2846
if (!item._root)2847
{2848
const btnMove = document.createElement('button');2849
btnMove.textContent = 'Move to';2850
btnMove.addEventListener('click', () => openMovePicker(item));2851
actions.appendChild(btnMove);2852
2853
if (!item.isDir)2854
{2855
const btnCopy = document.createElement('button');2856
btnCopy.textContent = 'Copy to';2857
btnCopy.addEventListener('click', () => openCopyPicker(item));2858
actions.appendChild(btnCopy);2859
}2860
}2861
2862
const btnRen = document.createElement('button');2863
btnRen.textContent = 'Rename';2864
btnRen.addEventListener('click', () => openRenameModal(item));2865
actions.appendChild(btnRen);2866
2867
if (!item._root)2868
{2869
const btnDel = document.createElement('button');2870
btnDel.textContent = 'Delete';2871
btnDel.className = 'danger';2872
btnDel.addEventListener('click', () => deleteItem(item));2873
actions.appendChild(btnDel);2874
}2875
}2876
2877
function closeCustomContextMenu ()2878
{2879
const menu = document.getElementById('custom-context-menu');2880
if (!menu) return;2881
menu.classList.add('hidden');2882
menu.innerHTML = '';2883
}2884
2885
function ensureCustomContextMenu ()2886
{2887
let menu = document.getElementById('custom-context-menu');2888
if (menu) return menu;2889
2890
menu = document.createElement('div');2891
menu.id = 'custom-context-menu';2892
menu.className = 'custom-context-menu hidden';2893
menu.setAttribute('role', 'menu');2894
menu.setAttribute('aria-label', 'Context menu');2895
menu.addEventListener('click', (e) => e.stopPropagation());2896
document.body.appendChild(menu);2897
return menu;2898
}2899
2900
function openCustomContextMenuAt (x, y, build)2901
{2902
const menu = ensureCustomContextMenu();2903
menu.innerHTML = '';2904
build(menu);2905
if (!menu.childElementCount)2906
{2907
closeCustomContextMenu();2908
return;2909
}2910
2911
menu.classList.remove('hidden');2912
menu.style.left = '0px';2913
menu.style.top = '0px';2914
2915
const maxLeft = Math.max(6, window.innerWidth - menu.offsetWidth - 6);2916
const maxTop = Math.max(6, window.innerHeight - menu.offsetHeight - 6);2917
menu.style.left = `${Math.min(Math.max(6, x), maxLeft)}px`;2918
menu.style.top = `${Math.min(Math.max(6, y), maxTop)}px`;2919
}2920
2921
function addContextMenuButton (menu, label, onClick, { danger = false, checked = null, hasSubmenu = false } = {})2922
{2923
const btn = document.createElement('button');2924
btn.type = 'button';2925
btn.className = 'custom-context-menu-item';2926
if (danger) btn.classList.add('danger');2927
if (checked !== null) btn.classList.add('custom-context-menu-item--check');2928
if (hasSubmenu) btn.classList.add('custom-context-menu-item--submenu');2929
2930
const labelEl = document.createElement('span');2931
if (checked === true) labelEl.textContent = '✓ ' + label;2932
else if (checked === false) labelEl.textContent = '□ ' + label;2933
else labelEl.textContent = label;2934
btn.appendChild(labelEl);2935
2936
if (hasSubmenu)2937
{2938
const arrow = document.createElement('span');2939
arrow.textContent = '›';2940
btn.appendChild(arrow);2941
}2942
2943
btn.addEventListener('click', async (e) =>2944
{2945
e.stopPropagation();2946
await onClick();2947
closeCustomContextMenu();2948
});2949
menu.appendChild(btn);2950
return btn;2951
}2952
2953
function addContextMenuSeparator (menu)2954
{2955
const sep = document.createElement('div');2956
sep.className = 'custom-context-menu-separator';2957
menu.appendChild(sep);2958
}2959
2960
function addContextMenuSubmenu (menu, label, options)2961
{2962
const row = document.createElement('div');2963
row.className = 'custom-context-menu-row';2964
const trigger = addContextMenuButton(row, label, () => {}, { hasSubmenu: true });2965
trigger.addEventListener('click', (e) => e.preventDefault());2966
2967
const panel = document.createElement('div');2968
panel.className = 'custom-context-submenu';2969
for (const option of options)2970
{2971
addContextMenuButton(panel, option.label, option.onClick, {2972
checked: option.checked,2973
});2974
}2975
row.appendChild(panel);2976
menu.appendChild(row);2977
}2978
2979
function openItemContextMenu (item, x, y)2980
{2981
openCustomContextMenuAt(x, y, (menu) =>2982
{2983
renderItemActionButtons(menu, item);2984
menu.querySelectorAll('button').forEach((btn) =>2985
{2986
if (btn.classList.contains('danger')) btn.classList.add('danger');2987
btn.addEventListener('click', () => closeCustomContextMenu(), { once: true });2988
});2989
});2990
}2991
2992
function openFolderContextMenu (x, y)2993
{2994
if (!STATE.currentDir)2995
{2996
closeCustomContextMenu();2997
return;2998
}2999
3000
const prefs = folderViewPrefsForDir(STATE.currentDir);3001
const makeOptionHandler = (patch) => async () =>3002
{3003
saveFolderViewPrefsForDir(STATE.currentDir, patch);3004
renderFileGrid();3005
};3006
3007
openCustomContextMenuAt(x, y, (menu) =>3008
{3009
if (canWrite())3010
{3011
addContextMenuButton(menu, 'Create Folder', createFolderInCurrentDir);3012
addContextMenuSeparator(menu);3013
}3014
3015
addContextMenuSubmenu(menu, 'Sort by', FOLDER_SORT_OPTIONS.map((option) => ({3016
label: option.label,3017
checked: prefs.sortBy === option.value,3018
onClick: makeOptionHandler({ sortBy: option.value }),3019
})));3020
3021
addContextMenuSubmenu(menu, 'Group by', FOLDER_GROUP_OPTIONS.map((option) => ({3022
label: option.label,3023
checked: prefs.groupBy === option.value,3024
onClick: makeOptionHandler({ groupBy: option.value }),3025
})));3026
3027
addContextMenuSeparator(menu);3028
addContextMenuButton(menu, 'Always keep folders at the top', makeOptionHandler({ foldersFirst: !prefs.foldersFirst }), {3029
checked: !!prefs.foldersFirst,3030
});3031
addContextMenuButton(menu, prefs.ascending ? 'Ascending' : 'Descending', makeOptionHandler({ ascending: !prefs.ascending }), {3032
checked: !!prefs.ascending,3033
});3034
});3035
}2682
// ───────────────────────────────────────────────────────────────────────────3036
// ───────────────────────────────────────────────────────────────────────────2683
3037
2684
async function openSidebar (item)3038
async function openSidebar (item)@@ -2753,22 +3107,6 @@ async function openSidebar (item)2753
renderSidebarDuplicates(item, []);3107
renderSidebarDuplicates(item, []);2754
});3108
});2755
3109
2756
// View / download button2757
const btnDl = document.createElement('button');2758
btnDl.textContent = 'View / Download';2759
btnDl.addEventListener('click', () =>2760
{2761
const tile = Array.from(document.querySelectorAll('.file-item')).find(node => node.dataset.path === item.path);2762
const source = (tile ? tile.querySelector('.icon svg') : null) || document.querySelector('#sidebar-icon svg');2763
downloadOrView(item, source);2764
});2765
actions.appendChild(btnDl);2766
2767
// Share button (file)2768
const btnShareFile = document.createElement('button');2769
btnShareFile.textContent = 'Share';2770
btnShareFile.addEventListener('click', () => openShareModal(item));2771
actions.appendChild(btnShareFile);2772
} else3110
} else2773
{3111
{2774
dl.innerHTML = `<dt>Type</dt><dd>${item._root ? 'Root folder' : 'Folder'}</dd>`;3112
dl.innerHTML = `<dt>Type</dt><dd>${item._root ? 'Root folder' : 'Folder'}</dd>`;@@ -2817,99 +3155,15 @@ async function openSidebar (item)2817
}3155
}2818
}3156
}2819
}3157
}3158
}2820
3159
2821
const btnOpen = document.createElement('button');3160
renderItemActionButtons(actions, item);2822
btnOpen.textContent = 'Open folder';2823
btnOpen.addEventListener('click', () => navigateTo(item.path, item._root || STATE.currentRoot));2824
actions.appendChild(btnOpen);2825
2826
// Download as zip button (folder)2827
const btnZip = document.createElement('button');2828
btnZip.textContent = 'Download as zip';2829
btnZip.addEventListener('click', () =>2830
{2831
btnZip.disabled = true;2832
btnZip.textContent = 'Working...';2833
const url = `/api/files/download-zip?dir=${encodeURIComponent(item.path)}`;2834
const headers = {2835
Authorization: 'Bearer ' + STATE.token,2836
'X-Fp': getFingerprint(),2837
};2838
fetch(url, { headers })2839
.then(res =>2840
{2841
if (!res.ok) throw new Error('Download mislukt');2842
return res.blob();2843
})2844
.then(blob =>2845
{2846
const blobUrl = URL.createObjectURL(blob);2847
const a = document.createElement('a');2848
a.href = blobUrl;2849
a.download = item.name + '.zip';2850
a.click();2851
setTimeout(() => URL.revokeObjectURL(blobUrl), 10000);2852
})2853
.catch((err) => toast(err.message || 'Download mislukt', 'err'))2854
.finally(() =>2855
{2856
btnZip.disabled = false;2857
btnZip.textContent = 'Download as zip';2858
});2859
});2860
actions.appendChild(btnZip);2861
2862
// Share button (folder)2863
const btnShareFolder = document.createElement('button');2864
btnShareFolder.textContent = 'Share';2865
btnShareFolder.addEventListener('click', () => openShareModal(item));2866
actions.appendChild(btnShareFolder);2867
3161
3162
if (item.isDir)3163
{2868
// Load folder icon thumbnail into the sidebar icon element.3164
// Load folder icon thumbnail into the sidebar icon element.2869
void loadOneFolderIcon(document.getElementById('sidebar-icon'));3165
void loadOneFolderIcon(document.getElementById('sidebar-icon'));2870
}3166
}2871
2872
// Rename button (write access required)2873
if (canWrite(item))2874
{2875
if (item.isDir)2876
{2877
const btnSetIcon = document.createElement('button');2878
btnSetIcon.textContent = 'Set icon';2879
btnSetIcon.addEventListener('click', () => openFolderIconPicker(item));2880
actions.appendChild(btnSetIcon);2881
}2882
2883
if (!item._root)2884
{2885
const btnMove = document.createElement('button');2886
btnMove.textContent = 'Move to';2887
btnMove.addEventListener('click', () => openMovePicker(item));2888
actions.appendChild(btnMove);2889
2890
if (!item.isDir)2891
{2892
const btnCopy = document.createElement('button');2893
btnCopy.textContent = 'Copy to';2894
btnCopy.addEventListener('click', () => openCopyPicker(item));2895
actions.appendChild(btnCopy);2896
}2897
}2898
2899
const btnRen = document.createElement('button');2900
btnRen.textContent = 'Rename';2901
btnRen.addEventListener('click', () => openRenameModal(item));2902
actions.appendChild(btnRen);2903
2904
if (!item._root)2905
{2906
const btnDel = document.createElement('button');2907
btnDel.textContent = 'Delete';2908
btnDel.className = 'danger';2909
btnDel.addEventListener('click', () => deleteItem(item));2910
actions.appendChild(btnDel);2911
}2912
}2913
}3167
}2914
3168
2915
function openFolderSidebar ()3169
function openFolderSidebar ()@@ -2994,14 +3248,7 @@ function renderFolderViewControls (actions, dirPath)2994
const sortSelect = document.createElement('select');3248
const sortSelect = document.createElement('select');2995
sortSelect.className = 'sidebar-view-option-control';3249
sortSelect.className = 'sidebar-view-option-control';2996
sortSelect.dataset.viewOption = 'sort';3250
sortSelect.dataset.viewOption = 'sort';2997
const sortOptions = [3251
for (const option of FOLDER_SORT_OPTIONS)2998
{ value: 'alphabetical', label: 'Alphabetically' },2999
{ value: 'fileType', label: 'File type' },3000
{ value: 'lastChanged', label: 'Last changed' },3001
{ value: 'timeUploaded', label: 'Time uploaded' },3002
{ value: 'size', label: 'Size' },3003
];3004
for (const option of sortOptions)3005
{3252
{3006
const optEl = document.createElement('option');3253
const optEl = document.createElement('option');3007
optEl.value = option.value;3254
optEl.value = option.value;@@ -3023,15 +3270,7 @@ function renderFolderViewControls (actions, dirPath)3023
const groupSelect = document.createElement('select');3270
const groupSelect = document.createElement('select');3024
groupSelect.className = 'sidebar-view-option-control';3271
groupSelect.className = 'sidebar-view-option-control';3025
groupSelect.dataset.viewOption = 'group';3272
groupSelect.dataset.viewOption = 'group';3026
const groupOptions = [3273
for (const option of FOLDER_GROUP_OPTIONS)3027
{ value: 'none', label: 'None' },3028
{ value: 'alphabetical', label: 'Alphabetically' },3029
{ value: 'fileType', label: 'File type' },3030
{ value: 'lastChangedDate', label: 'Last changed date' },3031
{ value: 'timeUploadedDate', label: 'Upload date' },3032
{ value: 'size', label: 'Size' },3033
];3034
for (const option of groupOptions)3035
{3274
{3036
const optEl = document.createElement('option');3275
const optEl = document.createElement('option');3037
optEl.value = option.value;3276
optEl.value = option.value;@@ -5090,6 +5329,31 @@ async function downloadOrView (item, sourceSvgEl = null)5090
// UPLOAD5329
// UPLOAD5091
// ───────────────────────────────────────────────────────────────────────────5330
// ───────────────────────────────────────────────────────────────────────────5092
5331
5332
async function createFolderInCurrentDir ()5333
{5334
if (!STATE.currentDir) { toast('Open a folder first.', 'err'); return; }5335
if (!canWrite()) { toast('No write access.', 'err'); return; }5336
5337
const name = await showPrompt('New Folder', 'Enter a name for the new folder:');5338
if (name == null) return;5339
const folderName = name.trim();5340
if (!folderName)5341
{5342
toast('Folder name is required.', 'err');5343
return;5344
}5345
5346
try5347
{5348
await api('POST', '/files/mkdir', { dir: STATE.currentDir, name: folderName });5349
toast('Folder created.', 'ok');5350
await navigateTo(STATE.currentDir, STATE.currentRoot);5351
} catch (err)5352
{5353
toast(err.message, 'err');5354
}5355
}5356
5093
function canWrite (item = null)5357
function canWrite (item = null)5094
{5358
{5095
if (STATE.isAdmin) return true;5359
if (STATE.isAdmin) return true;@@ -6669,27 +6933,13 @@ function wireEvents ()6669
6933
6670
document.getElementById('btn-new-folder').addEventListener('click', async () =>6934
document.getElementById('btn-new-folder').addEventListener('click', async () =>6671
{6935
{6672
if (!STATE.currentDir) { toast('Open a folder first.', 'err'); return; }6936
await createFolderInCurrentDir();6673
if (!canWrite()) { toast('No write access.', 'err'); return; }6937
});6674
6675
const name = await showPrompt('New Folder', 'Enter a name for the new folder:');6676
if (name == null) return;6677
const folderName = name.trim();6678
if (!folderName)6679
{6680
toast('Folder name is required.', 'err');6681
return;6682
}6683
6938
6684
try6939
document.getElementById('btn-change-password').addEventListener('click', openChangePasswordModal);6685
{6940
document.getElementById('change-password-modal-close').addEventListener('click', () =>6686
await api('POST', '/files/mkdir', { dir: STATE.currentDir, name: folderName });6941
{6687
toast('Folder created.', 'ok');6942
document.getElementById('change-password-modal').classList.add('hidden');6688
await navigateTo(STATE.currentDir, STATE.currentRoot);6689
} catch (err)6690
{6691
toast(err.message, 'err');6692
}6693
});6943
});6694
6944
6695
document.getElementById('sidebar-close').addEventListener('click', (e) =>6945
document.getElementById('sidebar-close').addEventListener('click', (e) =>@@ -6721,9 +6971,27 @@ function wireEvents ()6721
// Click outside grid clears selection and returns to folder sidebar info.6971
// Click outside grid clears selection and returns to folder sidebar info.6722
document.getElementById('main-content').addEventListener('click', (e) =>6972
document.getElementById('main-content').addEventListener('click', (e) =>6723
{6973
{6974
closeCustomContextMenu();6724
if (!e.target.closest('.file-item')) closeSidebar();6975
if (!e.target.closest('.file-item')) closeSidebar();6725
});6976
});6726
6977
6978
document.getElementById('main-content').addEventListener('contextmenu', (e) =>6979
{6980
if (isMobileViewport()) return;6981
if (e.target && e.target.closest && e.target.closest('.file-item')) return;6982
e.preventDefault();6983
closeSidebar();6984
openFolderContextMenu(e.clientX, e.clientY);6985
});6986
6987
window.addEventListener('resize', closeCustomContextMenu);6988
window.addEventListener('scroll', closeCustomContextMenu, true);6989
document.addEventListener('click', closeCustomContextMenu);6990
document.addEventListener('keydown', (e) =>6991
{6992
if (e.key === 'Escape') closeCustomContextMenu();6993
});6994
6727
// Admin panel6995
// Admin panel6728
document.getElementById('btn-admin').addEventListener('click', openAdminModal);6996
document.getElementById('btn-admin').addEventListener('click', openAdminModal);6729
document.getElementById('btn-admin-favicon').addEventListener('click', () =>6997
document.getElementById('btn-admin-favicon').addEventListener('click', () =>@@ -106,6 +106,16 @@
106
106
</svg>
107
107
Admin
108
108
</button>
109
<button id="btn-change-password" class="topbar-menu-item" type="button" role="menuitem" title="Change Password"
110
aria-label="Change Password">
111
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
112
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
113
<rect x="3" y="11" width="18" height="10" rx="2" ry="2" />
114
<path d="M7 11V7a5 5 0 0 1 10 0v4" />
115
<circle cx="12" cy="16" r="1" />
116
</svg>
117
Change Password
118
</button>
109
119
<button id="btn-logout" class="topbar-menu-item" type="button" role="menuitem" title="Sign out"
110
120
aria-label="Sign out">
111
121
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
@@ -245,6 +255,27 @@
245
255
</div>
246
256
</div>
247
257
258
<!-- CHANGE PASSWORD MODAL -->
259
<div id="change-password-modal" class="modal-overlay hidden">
260
<div class="modal small">
261
<button class="modal-close" id="change-password-modal-close" aria-label="Close">✕</button>
262
<h2>Change Password</h2>
263
<form id="change-password-form" autocomplete="off">
264
<label>Current password
265
<input id="change-password-current" type="password" autocomplete="current-password" required />
266
</label>
267
<label>New password
268
<input id="change-password-next" type="password" autocomplete="new-password" required />
269
</label>
270
<label>Confirm new password
271
<input id="change-password-confirm" type="password" autocomplete="new-password" required />
272
</label>
273
<p id="change-password-error" class="error hidden"></p>
274
<button type="submit" class="primary">Change password</button>
275
</form>
276
</div>
277
</div>
278
248
279
<!-- CONFIRM MODAL -->
249
280
<div id="confirm-modal" class="modal-overlay hidden" role="dialog" aria-modal="true"
250
281
aria-labelledby="confirm-modal-title">
@@ -106,6 +106,16 @@106
</svg>106
</svg>107
Admin107
Admin108
</button>108
</button>109
<button id="btn-change-password" class="topbar-menu-item" type="button" role="menuitem" title="Change Password"110
aria-label="Change Password">111
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"112
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">113
<rect x="3" y="11" width="18" height="10" rx="2" ry="2" />114
<path d="M7 11V7a5 5 0 0 1 10 0v4" />115
<circle cx="12" cy="16" r="1" />116
</svg>117
Change Password118
</button>109
<button id="btn-logout" class="topbar-menu-item" type="button" role="menuitem" title="Sign out"119
<button id="btn-logout" class="topbar-menu-item" type="button" role="menuitem" title="Sign out"110
aria-label="Sign out">120
aria-label="Sign out">111
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"121
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"@@ -245,6 +255,27 @@245
</div>255
</div>246
</div>256
</div>247
257
258
<!-- CHANGE PASSWORD MODAL -->259
<div id="change-password-modal" class="modal-overlay hidden">260
<div class="modal small">261
<button class="modal-close" id="change-password-modal-close" aria-label="Close">✕</button>262
<h2>Change Password</h2>263
<form id="change-password-form" autocomplete="off">264
<label>Current password265
<input id="change-password-current" type="password" autocomplete="current-password" required />266
</label>267
<label>New password268
<input id="change-password-next" type="password" autocomplete="new-password" required />269
</label>270
<label>Confirm new password271
<input id="change-password-confirm" type="password" autocomplete="new-password" required />272
</label>273
<p id="change-password-error" class="error hidden"></p>274
<button type="submit" class="primary">Change password</button>275
</form>276
</div>277
</div>278
248
<!-- CONFIRM MODAL -->279
<!-- CONFIRM MODAL -->249
<div id="confirm-modal" class="modal-overlay hidden" role="dialog" aria-modal="true"280
<div id="confirm-modal" class="modal-overlay hidden" role="dialog" aria-modal="true"250
aria-labelledby="confirm-modal-title">281
aria-labelledby="confirm-modal-title">@@ -719,6 +719,69 @@ button.danger.admin-update-highlight {
719
719
color: var(--text);
720
720
}
721
721
722
.custom-context-menu {
723
position: fixed;
724
min-width: 220px;
725
max-width: min(320px, calc(100vw - 12px));
726
background: var(--surface);
727
border: 1px solid var(--border);
728
border-radius: var(--radius);
729
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
730
padding: 0.35rem;
731
z-index: 12000;
732
}
733
734
.custom-context-menu button,
735
.custom-context-menu .custom-context-menu-item {
736
display: flex;
737
align-items: center;
738
justify-content: space-between;
739
width: 100%;
740
background: transparent;
741
color: var(--text);
742
padding: 0.45rem 0.55rem;
743
text-align: left;
744
border-radius: 6px;
745
}
746
747
.custom-context-menu button:hover,
748
.custom-context-menu .custom-context-menu-item:hover {
749
background: var(--surface2);
750
}
751
752
.custom-context-menu button.danger,
753
.custom-context-menu .custom-context-menu-item.danger {
754
color: var(--danger);
755
}
756
757
.custom-context-menu-separator {
758
height: 1px;
759
background: var(--border);
760
margin: 0.32rem 0;
761
}
762
763
.custom-context-menu-row {
764
position: relative;
765
}
766
767
.custom-context-submenu {
768
position: absolute;
769
top: 0;
770
left: calc(100% + 0.3rem);
771
min-width: 210px;
772
background: var(--surface);
773
border: 1px solid var(--border);
774
border-radius: var(--radius);
775
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
776
padding: 0.35rem;
777
display: none;
778
}
779
780
.custom-context-menu-row:hover > .custom-context-submenu,
781
.custom-context-menu-row:focus-within > .custom-context-submenu {
782
display: block;
783
}
784
722
785
/* ─── Duplicates panel ─────────────────────────────────── */
723
786
#sidebar-duplicates {
724
787
margin-top: 1rem;
@@ -719,6 +719,69 @@ button.danger.admin-update-highlight {719
color: var(--text);
719
color: var(--text);
720
}
720
}
721
721
722
.custom-context-menu {
723
position: fixed;
724
min-width: 220px;
725
max-width: min(320px, calc(100vw - 12px));
726
background: var(--surface);
727
border: 1px solid var(--border);
728
border-radius: var(--radius);
729
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
730
padding: 0.35rem;
731
z-index: 12000;
732
}
733
734
.custom-context-menu button,
735
.custom-context-menu .custom-context-menu-item {
736
display: flex;
737
align-items: center;
738
justify-content: space-between;
739
width: 100%;
740
background: transparent;
741
color: var(--text);
742
padding: 0.45rem 0.55rem;
743
text-align: left;
744
border-radius: 6px;
745
}
746
747
.custom-context-menu button:hover,
748
.custom-context-menu .custom-context-menu-item:hover {
749
background: var(--surface2);
750
}
751
752
.custom-context-menu button.danger,
753
.custom-context-menu .custom-context-menu-item.danger {
754
color: var(--danger);
755
}
756
757
.custom-context-menu-separator {
758
height: 1px;
759
background: var(--border);
760
margin: 0.32rem 0;
761
}
762
763
.custom-context-menu-row {
764
position: relative;
765
}
766
767
.custom-context-submenu {
768
position: absolute;
769
top: 0;
770
left: calc(100% + 0.3rem);
771
min-width: 210px;
772
background: var(--surface);
773
border: 1px solid var(--border);
774
border-radius: var(--radius);
775
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
776
padding: 0.35rem;
777
display: none;
778
}
779
780
.custom-context-menu-row:hover > .custom-context-submenu,
781
.custom-context-menu-row:focus-within > .custom-context-submenu {
782
display: block;
783
}
784
722
/* ─── Duplicates panel ─────────────────────────────────── */
785
/* ─── Duplicates panel ─────────────────────────────────── */
723
#sidebar-duplicates {
786
#sidebar-duplicates {
724
margin-top: 1rem;
787
margin-top: 1rem;
@@ -498,6 +498,69 @@ describe('page load smoke test', () =>
498
498
dom.window.close();
499
499
});
500
500
501
test('desktop right-click uses custom context menu for files and folder background', async () =>
502
{
503
meFixture = {
504
username: 'tester',
505
isAdmin: false,
506
permissions: {
507
Root: { read: true, write: true },
508
},
509
};
510
511
const { dom, runtimeErrors } = await bootClient();
512
expect(runtimeErrors).toEqual([]);
513
514
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]'));
515
516
const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]');
517
const fileMenuEvent = new dom.window.MouseEvent('contextmenu', {
518
bubbles: true,
519
cancelable: true,
520
clientX: 80,
521
clientY: 80,
522
});
523
const fileDispatchResult = fileTile.dispatchEvent(fileMenuEvent);
524
expect(fileDispatchResult).toBe(false);
525
expect(fileMenuEvent.defaultPrevented).toBe(true);
526
527
await waitFor(dom, () =>
528
{
529
const menu = dom.window.document.getElementById('custom-context-menu');
530
return !!(menu && !menu.classList.contains('hidden') && menu.textContent.includes('Rename'));
531
});
532
533
const fileMenu = dom.window.document.getElementById('custom-context-menu');
534
expect(fileMenu.textContent).toContain('View / Download');
535
expect(fileMenu.textContent).toContain('Share');
536
expect(fileMenu.textContent).toContain('Rename');
537
expect(fileMenu.textContent).toContain('Delete');
538
539
const main = dom.window.document.getElementById('main-content');
540
const folderMenuEvent = new dom.window.MouseEvent('contextmenu', {
541
bubbles: true,
542
cancelable: true,
543
clientX: 120,
544
clientY: 120,
545
});
546
const folderDispatchResult = main.dispatchEvent(folderMenuEvent);
547
expect(folderDispatchResult).toBe(false);
548
expect(folderMenuEvent.defaultPrevented).toBe(true);
549
550
await waitFor(dom, () =>
551
{
552
const menu = dom.window.document.getElementById('custom-context-menu');
553
return !!(menu && !menu.classList.contains('hidden') && menu.textContent.includes('Create Folder'));
554
});
555
556
const folderMenu = dom.window.document.getElementById('custom-context-menu');
557
expect(folderMenu.textContent).toContain('Create Folder');
558
expect(folderMenu.textContent).toContain('Sort by');
559
expect(folderMenu.textContent).toContain('Group by');
560
561
dom.window.close();
562
});
563
501
564
test('in Home, root tiles single-click focus and double-click open', async () =>
502
565
{
503
566
rootsFixture = [
@@ -498,6 +498,69 @@ describe('page load smoke test', () =>498
dom.window.close();
498
dom.window.close();
499
});
499
});
500
500
501
test('desktop right-click uses custom context menu for files and folder background', async () =>
502
{
503
meFixture = {
504
username: 'tester',
505
isAdmin: false,
506
permissions: {
507
Root: { read: true, write: true },
508
},
509
};
510
511
const { dom, runtimeErrors } = await bootClient();
512
expect(runtimeErrors).toEqual([]);
513
514
await waitFor(dom, () => !!dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]'));
515
516
const fileTile = dom.window.document.querySelector('.file-item[data-path="/data/readme.txt"]');
517
const fileMenuEvent = new dom.window.MouseEvent('contextmenu', {
518
bubbles: true,
519
cancelable: true,
520
clientX: 80,
521
clientY: 80,
522
});
523
const fileDispatchResult = fileTile.dispatchEvent(fileMenuEvent);
524
expect(fileDispatchResult).toBe(false);
525
expect(fileMenuEvent.defaultPrevented).toBe(true);
526
527
await waitFor(dom, () =>
528
{
529
const menu = dom.window.document.getElementById('custom-context-menu');
530
return !!(menu && !menu.classList.contains('hidden') && menu.textContent.includes('Rename'));
531
});
532
533
const fileMenu = dom.window.document.getElementById('custom-context-menu');
534
expect(fileMenu.textContent).toContain('View / Download');
535
expect(fileMenu.textContent).toContain('Share');
536
expect(fileMenu.textContent).toContain('Rename');
537
expect(fileMenu.textContent).toContain('Delete');
538
539
const main = dom.window.document.getElementById('main-content');
540
const folderMenuEvent = new dom.window.MouseEvent('contextmenu', {
541
bubbles: true,
542
cancelable: true,
543
clientX: 120,
544
clientY: 120,
545
});
546
const folderDispatchResult = main.dispatchEvent(folderMenuEvent);
547
expect(folderDispatchResult).toBe(false);
548
expect(folderMenuEvent.defaultPrevented).toBe(true);
549
550
await waitFor(dom, () =>
551
{
552
const menu = dom.window.document.getElementById('custom-context-menu');
553
return !!(menu && !menu.classList.contains('hidden') && menu.textContent.includes('Create Folder'));
554
});
555
556
const folderMenu = dom.window.document.getElementById('custom-context-menu');
557
expect(folderMenu.textContent).toContain('Create Folder');
558
expect(folderMenu.textContent).toContain('Sort by');
559
expect(folderMenu.textContent).toContain('Group by');
560
561
dom.window.close();
562
});
563
501
test('in Home, root tiles single-click focus and double-click open', async () =>
564
test('in Home, root tiles single-click focus and double-click open', async () =>
502
{
565
{
503
rootsFixture = [
566
rootsFixture = [