aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates/pages
diff options
context:
space:
mode:
authorwinter2025-03-22 19:41:55 +0000
committerwinter2025-03-22 19:41:55 +0000
commit39fcc5d52ac4c6e76ff87d95ef5b4b63300fe071 (patch)
tree75b83a228906064e80160359a76fa3820a9449eb /templates/pages
parentb535baf69b9a2525bc8a33b9c96460b84af8e6e2 (diff)
implement editing pages
Diffstat (limited to 'templates/pages')
-rw-r--r--templates/pages/editable.php39
-rw-r--r--templates/pages/page.php23
-rw-r--r--templates/pages/page_item.php55
3 files changed, 95 insertions, 22 deletions
diff --git a/templates/pages/editable.php b/templates/pages/editable.php
new file mode 100644
index 0000000..67c97ca
--- /dev/null
+++ b/templates/pages/editable.php
@@ -0,0 +1,39 @@
+<article>
+ <form class="pageEditForm nobackground" hx-post="/fragment/page/<?= $note->id ?>/edit" hx-target="closest article"
+ hx-swap="outerHTML">
+ <div class="row">
+ <label for="pageTitle"><?= __('note.page.new.title.label') ?></label>
+ <input type="text" id="pageTitle" name="title" value="<?= htmlspecialchars($page->title) ?>" required>
+ </div>
+
+ <div class="row">
+ <a class="pageAuthor" href="/@/<?= htmlspecialchars($note->author->getFullHandle()) ?>">
+ <?php call_template('actor/avatar', ['actor' => $note->author]); ?>
+ <span><?= __f(
+ 'note.page.author',
+ '<span class="displayName">' . htmlspecialchars($note->author->displayName) . '</span>'
+ ) ?></span>
+ </a>
+ <div class="created">
+ <?= __f('note.page.created', format_datetime($note->created)) ?>
+ </div>
+ <?php if (isset($note->modified) && $note->modified != $note->created): ?>
+ <div class="modified">
+ <?= __f('note.page.modified', format_datetime($note->modified)) ?>
+ </div>
+ <?php endif; ?>
+ <hr>
+ </div>
+
+ <div class="row">
+ <label for="pageBody"><?= __('note.page.new.body.label') ?></label>
+ <textarea id="pageBody" name="body" required><?= $page->content['text/markdown'] ?></textarea>
+ </div>
+
+ <div class="row actionButtons">
+ <button type="button" class="secondary" hx-get="/fragment/page/<?= $note->id ?>" hx-target="closest article"
+ hx-swap="outerHTML"><?= __('form.discardChanges') ?></button>
+ <button type="submit" class="primary"><?= __('form.saveChanges') ?></button>
+ </div>
+ </form>
+</article> \ No newline at end of file
diff --git a/templates/pages/page.php b/templates/pages/page.php
index 97cea6d..4babb9d 100644
--- a/templates/pages/page.php
+++ b/templates/pages/page.php
@@ -13,27 +13,6 @@ call_template('skeleton', [
'ogHandle' => '@' . $note->author->getFullHandle(true)
], function () use ($note, $page) { ?>
<div class="notePage">
- <article lang="<?= htmlspecialchars($note->language) ?>">
- <h1><?= htmlspecialchars($page->title) ?></h1>
- <a class="pageAuthor" href="/@/<?= htmlspecialchars($note->author->getFullHandle()) ?>">
- <?php call_template('actor/avatar', ['actor' => $note->author]); ?>
- <span><?= __f(
- 'note.page.author',
- '<span class="displayName">' . htmlspecialchars($note->author->displayName) . '</span>'
- ) ?></span>
- </a>
- <div class="created">
- <?= __f('note.page.created', format_datetime($note->created)) ?>
- </div>
- <?php if (isset($note->modified) && $note->modified != $note->created): ?>
- <div class="modified">
- <?= __f('note.page.modified', format_datetime($note->modified)) ?>
- </div>
- <?php endif; ?>
- <hr>
- <div class="pageContent">
- <?= $page->getBestContentAsHtml() ?>
- </div>
- </article>
+ <?php call_template('pages/page_item', ['note' => $note, 'page' => $page]); ?>
</div>
<?php }); \ No newline at end of file
diff --git a/templates/pages/page_item.php b/templates/pages/page_item.php
new file mode 100644
index 0000000..201a2f9
--- /dev/null
+++ b/templates/pages/page_item.php
@@ -0,0 +1,55 @@
+<?php
+
+use Digitigrade\Model\UserAccount;
+
+/** @var \Digitigrade\Model\Note $note */
+/** @var \Digitigrade\Page $page */
+
+?>
+<article lang="<?= htmlspecialchars($note->language) ?>">
+ <div class="pageHeader">
+ <div>
+ <h1><?= htmlspecialchars($page->title) ?></h1>
+ <a class="pageAuthor" href="/@/<?= htmlspecialchars($note->author->getFullHandle()) ?>">
+ <?php call_template('actor/avatar', ['actor' => $note->author]); ?>
+ <span><?= __f(
+ 'note.page.author',
+ '<span class="displayName">' . htmlspecialchars($note->author->displayName) . '</span>'
+ ) ?></span>
+ </a>
+ <div class="created">
+ <?= __f('note.page.created', format_datetime($note->created)) ?>
+ </div>
+ <?php if (isset($note->modified) && $note->modified != $note->created): ?>
+ <div class="modified">
+ <?= __f('note.page.modified', format_datetime($note->modified)) ?>
+ </div>
+ <?php endif; ?>
+ </div>
+ <div class="pageActions">
+ <?php call_template('menu_button', [], function () use ($note, $page) {
+ $user = UserAccount::findByCurrentSession();
+ if ($note->author->isLocal && ($note->author == $user?->actor || $user?->isAdmin)) { ?>
+ <li>
+ <button hx-get="/fragment/page/<?= $note->id ?>/edit" hx-target="closest article" hx-swap="outerHTML">
+ <span class="material-symbols edit-outline"></span>
+ <span><?= __('note.action.edit') ?></span>
+ </button>
+ </li>
+ <li>
+ <button hx-delete="/fragment/note/<?= $note->id ?>"
+ hx-confirm="<?= __('note.action.delete.confirmation') ?>" hx-target="closest article"
+ hx-swap="delete" _="on htmx:afterOnLoad go back">
+ <span class="material-symbols delete-outline"></span>
+ <span><?= __('note.action.delete') ?></span>
+ </button>
+ </li>
+ <?php }
+ }); ?>
+ </div>
+ </div>
+ <hr>
+ <div class="pageContent">
+ <?= $page->getBestContentAsHtml() ?>
+ </div>
+</article> \ No newline at end of file