/** * Kanbante β€” Focus of the day (issue #5): pin/unpin from /today and, * via a delegated handler, the πŸ“Œ button on board cards. */ (function () { var csrf = (document.querySelector('meta[name="csrf-token"]') || {}).content || ''; function post(url, repo, number) { var data = new FormData(); data.append('repo_full_name', repo); data.append('issue_number', number); data.append('csrf_token', csrf); return fetch(url, { method: 'POST', body: data }).then(function (r) { return r.json().catch(function () { return {}; }).then(function (body) { if (!r.ok || body.ok === false) throw new Error(body.error || ('HTTP ' + r.status)); return body; }); }); } // Capture phase: a πŸ“Œ click on a board card must be swallowed // before board.js sees it (it would open the detail drawer). document.addEventListener('click', function (e) { var pinBtn = e.target.closest('[data-pin]'); var unpinBtn = e.target.closest('[data-unpin]'); var cardPin = e.target.closest('.pin-btn'); if (pinBtn) { post('/api/today/pin', pinBtn.getAttribute('data-repo'), pinBtn.getAttribute('data-number')) .then(function () { location.reload(); }) .catch(function (err) { alert(err.message); }); } else if (unpinBtn) { post('/api/today/unpin', unpinBtn.getAttribute('data-repo'), unpinBtn.getAttribute('data-number')) .then(function () { location.reload(); }) .catch(function (err) { alert(err.message); }); } else if (cardPin) { // Board card πŸ“Œ: never open the detail drawer for this click. e.stopPropagation(); e.preventDefault(); var card = cardPin.closest('.kanban-card'); post('/api/today/pin', card.getAttribute('data-repo'), card.getAttribute('data-issue')) .then(function () { cardPin.textContent = 'πŸ“Œβœ“'; cardPin.title = 'Γ‰pinglΓ©e au Focus du jour (/today)'; }) .catch(function (err) { alert(err.message); }); } }, true); })();