()
| 1758 | const getSourceId = () => normalizePortalSourceId(sourceSelect ? sourceSelect.value : '') || getPortalSourceFallbackId(); |
| 1759 | |
| 1760 | const openPicker = async () => { |
| 1761 | const sourceId = getSourceId(); |
| 1762 | if (useNativePicker) { |
| 1763 | try { |
| 1764 | const folder = await window.FileRiseFolderPicker({ |
| 1765 | current: input.value || '', |
| 1766 | mode: 'select-folder', |
| 1767 | source: 'client-portals', |
| 1768 | sourceId |
| 1769 | }); |
| 1770 | if (folder) input.value = folder; |
| 1771 | return; |
| 1772 | } catch (e) { |
| 1773 | console.error('Folder picker error', e); |
| 1774 | showToast(t('admin_portal_open_folder_picker_failed')); |
| 1775 | return; |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | // Fallback: datalist built from /api/folder/getFolderList.php |
| 1780 | try { |
| 1781 | const safeSourceId = (sourceId || 'local').replace(/[^A-Za-z0-9_-]/g, '') || 'local'; |
| 1782 | const datalistId = 'portalFolderList-' + safeSourceId; |
| 1783 | let datalist = document.getElementById(datalistId); |
| 1784 | if (!datalist) { |
| 1785 | datalist = document.createElement('datalist'); |
| 1786 | datalist.id = datalistId; |
| 1787 | document.body.appendChild(datalist); |
| 1788 | |
| 1789 | const folders = await loadPortalFolderList(sourceId); |
| 1790 | datalist.innerHTML = ''; |
| 1791 | folders.forEach(f => { |
| 1792 | const opt = document.createElement('option'); |
| 1793 | opt.value = f; |
| 1794 | datalist.appendChild(opt); |
| 1795 | }); |
| 1796 | } |
| 1797 | |
| 1798 | input.setAttribute('list', datalistId); |
| 1799 | input.focus(); |
| 1800 | input.select(); |
| 1801 | } catch (e) { |
| 1802 | console.error('Error preparing folder list', e); |
| 1803 | input.focus(); |
| 1804 | input.select(); |
| 1805 | } |
| 1806 | }; |
| 1807 | |
| 1808 | if (sourceSelect && !sourceSelect.__frPortalSourceBound) { |
| 1809 | sourceSelect.__frPortalSourceBound = true; |
no test coverage detected