- 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);
|
t.textContent=msg;c.appendChild(t);setTimeout(()=>t.remove(),3000);
|
||||||
}
|
}
|
||||||
async function api(action,method='GET',data=null,extra=''){
|
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);}
|
if(data){opts.headers['Content-Type']='application/json';opts.body=JSON.stringify(data);}
|
||||||
const r=await fetch(API+'?action='+action+extra,opts);
|
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');
|
if(!j.ok)throw new Error(j.error||'Erreur');
|
||||||
return j.data;
|
return j.data;
|
||||||
}
|
}
|
||||||
@@ -84,7 +86,6 @@ async function loadTodos(){
|
|||||||
|
|
||||||
const todos=await api('todos','GET',null,extra);
|
const todos=await api('todos','GET',null,extra);
|
||||||
renderTodos(todos);
|
renderTodos(todos);
|
||||||
updateQuickAddList();
|
|
||||||
updateHeader();
|
updateHeader();
|
||||||
}catch(e){toast(e.message,'error');}
|
}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(){
|
function toggleShowDone(){
|
||||||
showDone=!showDone;
|
showDone=!showDone;
|
||||||
const btn=document.getElementById('show-done-btn');
|
const btn=document.getElementById('show-done-btn');
|
||||||
@@ -183,19 +176,6 @@ async function deleteTodo(e,id){
|
|||||||
catch(e){toast(e.message,'error');}
|
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 ───────────────────────────────────────────────────────────────
|
// ─── Todo modal ───────────────────────────────────────────────────────────────
|
||||||
function openAddTodo(){
|
function openAddTodo(){
|
||||||
editTodoId=null;
|
editTodoId=null;
|
||||||
@@ -346,6 +326,5 @@ function closeModal(id){document.getElementById(id)?.classList.remove('show');}
|
|||||||
document.addEventListener('DOMContentLoaded',()=>{
|
document.addEventListener('DOMContentLoaded',()=>{
|
||||||
loadSidebar();
|
loadSidebar();
|
||||||
loadTodos();
|
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');}));
|
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>
|
||||||
</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 -->
|
<!-- Todo list -->
|
||||||
<div class="todo-list" id="todo-list"></div>
|
<div class="todo-list" id="todo-list"></div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user