... |
... |
@@ -328,39 +328,77 @@ |
328 |
328 |
|
329 |
329 |
// Wire up per-card search boxes |
330 |
330 |
let timer=null; |
331 |
|
- document.querySelectorAll('.move-box .move-input').forEach(inp=>{ |
|
331 |
+ |
|
332 |
+ // Debug: Log how many move inputs we find |
|
333 |
+ const moveInputs = document.querySelectorAll('.move-box .move-input'); |
|
334 |
+ console.log('Found', moveInputs.length, 'move input boxes'); |
|
335 |
+ |
|
336 |
+ moveInputs.forEach(function(inp, index){ |
|
337 |
+ console.log('Setting up move input', index, 'with filename:', inp.getAttribute('data-filename')); |
|
338 |
+ |
332 |
332 |
const resultsBox = inp.parentElement.querySelector('.move-results'); |
333 |
|
- inp.addEventListener('input', ()=>{ |
|
340 |
+ if (!resultsBox) { |
|
341 |
+ console.error('No results box found for input', index); |
|
342 |
+ return; |
|
343 |
+ } |
|
344 |
+ |
|
345 |
+ inp.addEventListener('input', function(){ |
334 |
334 |
clearTimeout(timer); |
335 |
335 |
const q = inp.value.trim(); |
336 |
|
- if(!q){ resultsBox.textContent=''; return; } |
337 |
|
- timer = setTimeout(async ()=>{ |
338 |
|
- const res = await searchPages(q); |
339 |
|
- renderResults(resultsBox, res, async (full)=>{ |
340 |
|
- inp.value = full; |
341 |
|
- // Kick the move |
342 |
|
- const filename = inp.getAttribute('data-filename'); |
343 |
|
- const notice = document.createElement('div'); |
344 |
|
- notice.style.fontSize='12px'; notice.style.color='#666'; notice.textContent='Moving…'; |
345 |
|
- inp.parentElement.appendChild(notice); |
346 |
|
- try{ |
347 |
|
- await moveAttachment({ |
348 |
|
- srcSpace: window.SOURCE_SPACE, |
349 |
|
- srcPage: window.SOURCE_PAGE, |
350 |
|
- filename: filename, |
351 |
|
- dstFull: full |
352 |
|
- }); |
353 |
|
- notice.textContent = 'Moved ✔ — reloading…'; |
354 |
|
- setTimeout(()=>location.reload(), 600); |
355 |
|
- }catch(e){ |
356 |
|
- notice.style.color = '#b00020'; |
357 |
|
- notice.textContent = 'Move failed: ' + (e && e.message ? e.message : e); |
358 |
|
- } |
359 |
|
- }); |
|
348 |
+ console.log('Search input changed:', q); |
|
349 |
+ |
|
350 |
+ if(!q){ |
|
351 |
+ resultsBox.textContent=''; |
|
352 |
+ return; |
|
353 |
+ } |
|
354 |
+ |
|
355 |
+ timer = setTimeout(async function(){ |
|
356 |
+ console.log('Searching for:', q); |
|
357 |
+ try { |
|
358 |
+ const res = await searchPages(q); |
|
359 |
+ console.log('Search results:', res); |
|
360 |
+ |
|
361 |
+ renderResults(resultsBox, res, async function(full){ |
|
362 |
+ console.log('Moving file to:', full); |
|
363 |
+ inp.value = full; |
|
364 |
+ |
|
365 |
+ // Kick the move |
|
366 |
+ const filename = inp.getAttribute('data-filename'); |
|
367 |
+ const notice = document.createElement('div'); |
|
368 |
+ notice.style.fontSize='12px'; |
|
369 |
+ notice.style.color='#666'; |
|
370 |
+ notice.style.marginTop='4px'; |
|
371 |
+ notice.textContent='Moving…'; |
|
372 |
+ inp.parentElement.appendChild(notice); |
|
373 |
+ |
|
374 |
+ try{ |
|
375 |
+ await moveAttachment({ |
|
376 |
+ srcSpace: window.SOURCE_SPACE, |
|
377 |
+ srcPage: window.SOURCE_PAGE, |
|
378 |
+ filename: filename, |
|
379 |
+ dstFull: full |
|
380 |
+ }); |
|
381 |
+ notice.textContent = 'Moved ✔ — reloading…'; |
|
382 |
+ notice.style.color = '#28a745'; |
|
383 |
+ setTimeout(function(){ location.reload(); }, 600); |
|
384 |
+ }catch(e){ |
|
385 |
+ console.error('Move failed:', e); |
|
386 |
+ notice.style.color = '#dc3545'; |
|
387 |
+ notice.textContent = 'Move failed: ' + (e && e.message ? e.message : e); |
|
388 |
+ } |
|
389 |
+ }); |
|
390 |
+ } catch(e) { |
|
391 |
+ console.error('Search failed:', e); |
|
392 |
+ } |
360 |
360 |
}, 220); |
361 |
361 |
}); |
|
395 |
+ |
362 |
362 |
// Close suggestions when clicking out |
363 |
|
- document.addEventListener('click', (e)=>{ if(!inp.parentElement.contains(e.target)) resultsBox.textContent=''; }); |
|
397 |
+ document.addEventListener('click', function(e){ |
|
398 |
+ if(!inp.parentElement.contains(e.target)) { |
|
399 |
+ resultsBox.textContent=''; |
|
400 |
+ } |
|
401 |
+ }); |
364 |
364 |
}); |
365 |
365 |
})(); |
366 |
366 |
</script> |