(sourceFolder, sourceId)
| 308 | } |
| 309 | |
| 310 | async function loadMoveFolderTargets(sourceFolder, sourceId) { |
| 311 | const targetSel = document.getElementById('moveFolderTarget'); |
| 312 | if (!targetSel) return; |
| 313 | targetSel.innerHTML = ''; |
| 314 | const activeId = getActiveSourceId(); |
| 315 | const sameSource = (sourceId || activeId) === activeId; |
| 316 | const url = withBase('/api/folder/getFolderList.php') |
| 317 | + '?counts=0' |
| 318 | + (sourceId ? `&sourceId=${encodeURIComponent(sourceId)}` : ''); |
| 319 | try { |
| 320 | let list = await fetch(url, { credentials: 'include' }).then(r => r.json()); |
| 321 | if (Array.isArray(list) && list.length && typeof list[0] === 'object' && list[0].folder) { |
| 322 | list = list.map(it => it.folder); |
| 323 | } |
| 324 | const rootOpt = document.createElement('option'); |
| 325 | rootOpt.value = 'root'; |
| 326 | rootOpt.textContent = getRootLabel(sourceId || activeId); |
| 327 | targetSel.appendChild(rootOpt); |
| 328 | (list || []) |
| 329 | .filter(f => f && f !== 'trash' && (!sameSource || f !== (sourceFolder || ''))) |
| 330 | .forEach(f => { |
| 331 | const o = document.createElement('option'); |
| 332 | o.value = f; |
| 333 | o.textContent = f; |
| 334 | targetSel.appendChild(o); |
| 335 | }); |
| 336 | } catch (e) { |
| 337 | // ignore |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | async function initMoveFolderSourceSelect(sourceFolder) { |
| 342 | const row = document.getElementById('moveFolderSourceRow'); |
no test coverage detected