From: Mischa POSLAWSKY Date: Mon, 17 Sep 2018 15:12:17 +0000 (+0200) Subject: nieuws: apply tag changes to article links in edit mode X-Git-Tag: v3.7~2 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/bd29158976da14f04451d58a8713674934c78379 nieuws: apply tag changes to article links in edit mode --- diff --git a/edit/nieuws/tag/index.php b/edit/nieuws/tag/index.php new file mode 100644 index 0000000..d4edb71 --- /dev/null +++ b/edit/nieuws/tag/index.php @@ -0,0 +1,38 @@ + { }; overview.appendChild(editlink); } + + var editlink = document.querySelector('a[href="#edit"]'); + if (!editlink) return; + editlink.addEventListener('click', () => { + document.querySelectorAll('.tags input').forEach(tagoption => { + tagoption.removeAttribute('disabled'); + tagoption.addEventListener('change', () => { + let editpost = '/edit/nieuws/tag' + window.location.pathname; + let params = new URLSearchParams; + params.append('tag', tagoption.value); + params.append('value', tagoption.checked ? 1 : 0); + fetch(editpost, { + method: 'POST', + body: params, + credentials: 'same-origin', + }) + .then(res => { + if (res.status != 200) { + return res.text().then(body => { + throw `foutcode ${res.status}: ${body}`; + }); + } + }) + .catch(error => { + alert(`Tag aanpassen mislukt: ${error}`); + }); + }); + }); + }); }); diff --git a/nieuws/index.php b/nieuws/index.php index 1a52011..ad85011 100644 --- a/nieuws/index.php +++ b/nieuws/index.php @@ -24,14 +24,14 @@ if ($page and !is_numeric($page)) { $tagtarget = is_writable($tagpath); $taglist[] = sprintf( '' . - '', + '', "tags[$tagname]", $tagname, "tag-$tagname", $tagvalue ? ' checked' : '', - ' onclick="return false"', + ' disabled', ucfirst($tagname) ); } - printf("

Tags: %s

\n", + printf('

Tags: %s

'."\n", implode("\n\t", $taglist) ); }