From 7c9537015a7361681323e5a5ce2f10d9c0ee42d3 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 27 Dec 2020 02:32:00 +0100 Subject: [PATCH] widget/reply: redirect to created comment Undo initial design of continuous uploads, rather have normal form behaviour of showing feedback/results. --- issue/index.php | 2 +- progress.js | 10 +++++++--- widget/reply.php | 7 +++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/issue/index.php b/issue/index.php index 87b22a3..62182ac 100644 --- a/issue/index.php +++ b/issue/index.php @@ -5,7 +5,7 @@ require_once 'database.inc.php'; if ($id and ctype_digit($id)) { $Page->title = "Issue #$id"; - $Page->path = "/$id"; # minimal reference + $Page->link = $Page->handler . ($Page->path = "/$id"); # minimal reference $Issue = $Db->query( 'SELECT * FROM issues WHERE page = ? AND id = ?', [$Page->handler, $id] )->fetch(); diff --git a/progress.js b/progress.js index e59422d..575b98e 100644 --- a/progress.js +++ b/progress.js @@ -3,6 +3,10 @@ function showsize(bytes) { } function trackupload(input) { + if (!input.value) { + return true; // default form action + } + var progress = document.getElementById('progress'); if (!progress) { progress = document.createElement('DIV'); @@ -26,7 +30,7 @@ function trackupload(input) { if (e.target.status == 200) { progress.textContent = 'voltooid'; progress.innerHTML += ' (' + showsize(input.files[0].size) + ' MB)'; - input.value = ''; + window.location.assign(e.target.response); } else { progress.textContent = 'fout'; @@ -53,14 +57,14 @@ function trackupload(input) { cancel.onclick = function () { ajax.abort() }; cancel.style.float = 'left'; input.parentNode.insertBefore(cancel, progress.parentNode); + return false; } document.addEventListener('DOMContentLoaded', e => { for (let row of document.forms[0].elements) { if (row.type == 'file') { row.form.onsubmit = () => { - trackupload(row); - return false; + return trackupload(row); }; } } diff --git a/widget/reply.php b/widget/reply.php index 1f6d0e2..0935567 100644 --- a/widget/reply.php +++ b/widget/reply.php @@ -61,9 +61,8 @@ if ($_POST) { } } - if ($Page->api) { - abort("/{$Page->link}", '200 reply success'); - } + $target = "/{$Page->link}/$newcomment#$newcomment"; + abort($target, ($Page->api ? 200 : 303) . ' reply success'); $_POST['reply'] = NULL; } catch (Exception $e) { @@ -81,7 +80,7 @@ print '