Template
fix: site form JS conflict with window.name
This commit is contained in:
@@ -101,8 +101,8 @@ const loginPageHTML = `<!DOCTYPE html>
|
||||
</form><div id="msg" class="msg"></div>
|
||||
</div></div>
|
||||
<script>
|
||||
document.getElementById('form').onsubmit=async e=>{e.preventDefault();const btn=document.getElementById('btn'),msg=document.getElementById('msg');btn.disabled=true;msg.className='msg';
|
||||
const res=await fetch('/api/v1/auth/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username:username.value.trim(),password:password.value})});
|
||||
document.getElementById('form').onsubmit=async e=>{e.preventDefault();const btn=document.getElementById('btn'),msg=document.getElementById('msg');const userEl=document.getElementById('username'),passEl=document.getElementById('password');btn.disabled=true;msg.className='msg';
|
||||
const res=await fetch('/api/v1/auth/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username:userEl.value.trim(),password:passEl.value})});
|
||||
const d=await res.json().catch(()=>({}));if(!res.ok){msg.className='msg error';msg.textContent=d.error||'Неверный логин или пароль';btn.disabled=false;return;}
|
||||
location.reload();};
|
||||
</script></body></html>`
|
||||
@@ -132,10 +132,21 @@ async function loadSites(){const r=await fetch('/api/v1/sites');const d=await r.
|
||||
tr.innerHTML='<td>'+site.name+'</td><td>'+site.primary_domain+'</td><td>'+(site.php_version||'-')+'</td><td><span class="badge">'+site.status+'</span></td><td><code>'+site.document_root+'</code></td>';
|
||||
tb.appendChild(tr);});}
|
||||
document.getElementById('logout').onclick=async()=>{await fetch('/api/v1/auth/logout',{method:'POST'});location.reload();};
|
||||
document.getElementById('siteForm').onsubmit=async e=>{e.preventDefault();const btn=document.getElementById('createBtn'),msg=document.getElementById('formMsg');btn.disabled=true;msg.className='msg';
|
||||
const res=await fetch('/api/v1/sites',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({name:name.value.trim().toLowerCase(),domain:domain.value.trim().toLowerCase(),php_version:php_version.value})});
|
||||
const d=await res.json().catch(()=>({}));if(!res.ok){msg.className='msg error';msg.textContent=d.error||'Ошибка';btn.disabled=false;return;}
|
||||
msg.className='msg ok';msg.textContent='Сайт создан';siteForm.reset();btn.disabled=false;await loadPHP();loadSites();};
|
||||
document.getElementById('siteForm').onsubmit=async e=>{
|
||||
e.preventDefault();
|
||||
const btn=document.getElementById('createBtn'),msg=document.getElementById('formMsg');
|
||||
const siteName=document.getElementById('name'),siteDomain=document.getElementById('domain'),phpSelect=document.getElementById('php_version');
|
||||
btn.disabled=true;msg.className='msg';msg.textContent='';
|
||||
try{
|
||||
const res=await fetch('/api/v1/sites',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({name:siteName.value.trim().toLowerCase(),domain:siteDomain.value.trim().toLowerCase(),php_version:phpSelect.value})});
|
||||
const d=await res.json().catch(()=>({}));
|
||||
if(!res.ok){msg.className='msg error';msg.textContent=d.error||'Ошибка';btn.disabled=false;return;}
|
||||
msg.className='msg ok';msg.textContent='Сайт создан';
|
||||
document.getElementById('siteForm').reset();
|
||||
await loadPHP();loadSites();
|
||||
}catch(err){msg.className='msg error';msg.textContent='Сетевая ошибка';}
|
||||
btn.disabled=false;
|
||||
};
|
||||
loadPHP();loadSites();
|
||||
</script></body></html>`, baseCSS, username)
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (h *SiteHandler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
errors.Is(err, sitesvc.ErrInvalidPHPVersion):
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
default:
|
||||
writeError(w, http.StatusInternalServerError, "failed to create site")
|
||||
writeError(w, http.StatusInternalServerError, "failed to create site: "+err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user