- api() now sends credentials + Accept/X-Requested-With headers so session expiry returns proper JSON 401 instead of HTML redirect - Safer JSON parsing with readable error in console - Remove quick-add bar (use modal only) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
606dcbf3d7
commit
9ec78ba77e
@@ -13,10 +13,12 @@ function toast(msg,type='success'){
|
||||
t.textContent=msg;c.appendChild(t);setTimeout(()=>t.remove(),3000);
|
||||
}
|
||||
async function api(action,method='GET',data=null,extra=''){
|
||||
const opts={method,headers:{}};
|
||||
const opts={method,credentials:'same-origin',headers:{'Accept':'application/json','X-Requested-With':'XMLHttpRequest'}};
|
||||
if(data){opts.headers['Content-Type']='application/json';opts.body=JSON.stringify(data);}
|
||||
const r=await fetch(API+'?action='+action+extra,opts);
|
||||
const j=await r.json();
|
||||
const text=await r.text();
|
||||
let j;
|
||||
try{j=JSON.parse(text);}catch(e){console.error('Bad JSON from API:',text.slice(0,200));throw new Error('Erreur serveur');}
|
||||
if(!j.ok)throw new Error(j.error||'Erreur');
|
||||
return j.data;
|
||||
}
|
||||
@@ -84,7 +86,6 @@ async function loadTodos(){
|
||||
|
||||
const todos=await api('todos','GET',null,extra);
|
||||
renderTodos(todos);
|
||||
updateQuickAddList();
|
||||
updateHeader();
|
||||
}catch(e){toast(e.message,'error');}
|
||||
}
|
||||
@@ -100,14 +101,6 @@ function updateHeader(){
|
||||
}
|
||||
}
|
||||
|
||||
function updateQuickAddList(){
|
||||
const sel=document.getElementById('quick-add-list');
|
||||
if(!sel)return;
|
||||
sel.innerHTML='<option value="">Sans liste</option>'+
|
||||
lists.map(l=>`<option value="${l.id}">${escHtml(l.icon)} ${escHtml(l.name)}</option>`).join('');
|
||||
if(currentFilter.startsWith('list_'))sel.value=currentFilter.slice(5);
|
||||
}
|
||||
|
||||
function toggleShowDone(){
|
||||
showDone=!showDone;
|
||||
const btn=document.getElementById('show-done-btn');
|
||||
@@ -183,19 +176,6 @@ async function deleteTodo(e,id){
|
||||
catch(e){toast(e.message,'error');}
|
||||
}
|
||||
|
||||
// ─── Quick add ────────────────────────────────────────────────────────────────
|
||||
async function quickAdd(e){
|
||||
if(e.key!=='Enter')return;
|
||||
const inp=document.getElementById('quick-add-input');
|
||||
const title=inp.value.trim();
|
||||
if(!title)return;
|
||||
const listSel=document.getElementById('quick-add-list');
|
||||
try{
|
||||
await api('todos','POST',{title,list_id:listSel?.value||null,priority:'none'});
|
||||
inp.value='';toast('Tâche ajoutée ✓');loadTodos();loadSidebar();
|
||||
}catch(e){toast(e.message,'error');}
|
||||
}
|
||||
|
||||
// ─── Todo modal ───────────────────────────────────────────────────────────────
|
||||
function openAddTodo(){
|
||||
editTodoId=null;
|
||||
@@ -346,6 +326,5 @@ function closeModal(id){document.getElementById(id)?.classList.remove('show');}
|
||||
document.addEventListener('DOMContentLoaded',()=>{
|
||||
loadSidebar();
|
||||
loadTodos();
|
||||
document.getElementById('quick-add-input')?.addEventListener('keydown',quickAdd);
|
||||
document.querySelectorAll('.todo-modal-backdrop').forEach(m=>m.addEventListener('click',e=>{if(e.target===m)m.classList.remove('show');}));
|
||||
});
|
||||
|
||||
@@ -40,13 +40,6 @@ require __DIR__ . '/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quick add -->
|
||||
<div class="todo-quick-add">
|
||||
<span style="color:var(--text-muted)">+</span>
|
||||
<input type="text" id="quick-add-input" placeholder="Ajouter une tâche rapide… (Entrée pour valider)">
|
||||
<select id="quick-add-list" class="form-control" style="width:auto;font-size:.8rem;padding:.25rem .5rem;border:none;background:transparent;color:var(--text-muted)"></select>
|
||||
</div>
|
||||
|
||||
<!-- Todo list -->
|
||||
<div class="todo-list" id="todo-list"></div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user