widget/reply: load file upload progress indicator
[minimedit.git] / widget / reply.php
index 7e0ec1e83aea3c4c0819df20d9315f491db8ab8b..1f6d0e2ff0352f709ff0223fdd455c1d3962eded 100644 (file)
@@ -21,7 +21,7 @@ if ($_POST) {
                        }
                }
                $query = $Db->set('comments', [
-                       'page'    => $Page,
+                       'page'    => $Page->link,
                        'message' => $html,
                        'author'  => $User->login,
                ]);
@@ -60,15 +60,22 @@ if ($_POST) {
                                $Issue = $updated;
                        }
                }
+
+               if ($Page->api) {
+                       abort("/{$Page->link}", '200 reply success');
+               }
                $_POST['reply'] = NULL;
        }
        catch (Exception $e) {
+               if ($Page->api) {
+                       abort(ucfirst($e->getMessage()), '500 reply error');
+               }
                print "<p class=warn>Antwoord niet opgeslagen: {$e->getMessage()}.</p>\n\n";
        }
 }
 
 $cols = '*, (SELECT json_agg(journal.*) FROM journal WHERE comment_id = comments.id) AS journal';
-$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page]);
+$query = $Db->query("SELECT $cols FROM comments WHERE page = ? ORDER BY created", [$Page->link]);
 
 print '<ul class="replies">';
 
@@ -90,7 +97,7 @@ while ($row = $query->fetch()) {
                                printf("<em>%s</em> %s",
                                        $journalcol[$change->col], sprintf(
                                                !isset($change->old_value) ? 'gewijzigd naar <q>%2$s</q>' :
-                                               (!isset($change->value) ? 'verwijderd (<strike>%s</strike>)' :
+                                               (!isset($change->value) ? 'verwijderd (<s>%s</s>)' :
                                                'gewijzigd van <q>%s</q> naar <q>%s</q>'),
                                                $change->old_value, $change->value
                                        )
@@ -103,10 +110,10 @@ while ($row = $query->fetch()) {
        print "</li>\n";
 }
 
-if ($User) {
+if ($User->login) {
        print '<li>';
        print '<form method="post" action="" enctype="multipart/form-data">';
-       if (isset($Issue) and $User->admin("edit $Page")) {
+       if (isset($Issue) and $User->admin("edit {$Page->link}")) {
                print '<p>';
                printf(
                        '<label for="%s">%s:</label> '
@@ -139,7 +146,9 @@ if ($User) {
                ''
        );
        print '<input type="submit" value="Plaatsen" />'."\n";
-       print "</form></li>\n";
+       print "</form>";
+       print '<script src="/upload/progress.js"></script>';
+       print "</li>\n";
 }
 
 print "</ul>\n\n";