diff --git a/new.php b/new.php index 7ce8bcf..b31ac5d 100644 --- a/new.php +++ b/new.php @@ -834,17 +834,47 @@ function handleAjaxFormSubmit(form, redirectTab) { const submit = form.querySelector('button[type="submit"]'); const data = new FormData(form); data.set('ajax', '1'); - if(submit) submit.disabled = true; + + const action = String(data.get('action') || ''); + const verb = action === 'update' ? 'Saving' + : action === 'delete_video' ? 'Deleting' + : action === 'delete_dir' ? 'Deleting' + : action === 'delete_file' ? 'Deleting' + : action === 'create' ? 'Creating' + : 'Working'; + + let timer = 0; + let success = false; + if (submit) { + submit.dataset.label = submit.dataset.label || submit.textContent.trim() || 'Submit'; + submit.disabled = true; + submit.style.opacity = '0.78'; + submit.style.cursor = 'wait'; + let dots = 0; + submit.textContent = verb; + timer = window.setInterval(function(){ + dots = (dots + 1) % 4; + submit.textContent = verb + '.'.repeat(dots); + }, 320); + } + try{ const res = await fetch('new.php', { method: 'POST', body: data, credentials: 'same-origin', headers: { 'Accept': 'application/json' }}); const json = await res.json().catch(() => ({})); if(!res.ok || !json.ok) throw new Error(json.error || 'Operation failed'); + success = true; showToast(json.message || 'Operation successful', true); setTimeout(() => { window.location.href = 'new.php?tab=' + (json.tab || redirectTab); }, 450); } catch(e) { showToast(e.message || 'Operation failed', false); } finally { - if(submit) submit.disabled = false; + if (timer) window.clearInterval(timer); + if(submit && !success) { + submit.disabled = false; + submit.style.opacity = ''; + submit.style.cursor = ''; + submit.textContent = submit.dataset.label || 'Submit'; + } } }); }