diff options
| author | Syndamia <kamen@syndamia.com> | 2025-01-26 22:19:25 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2025-01-26 22:24:48 +0200 |
| commit | cc16ebc3927fa19c86d970067bcb9a16be94e40a (patch) | |
| tree | 04740380dd81fe2a0ccb6bacef00c972563eaa4c | |
| parent | 32f3eadcc72a2c6ef3e732cecbc0706e7cbb267c (diff) | |
| download | nowayforward_human-cc16ebc3927fa19c86d970067bcb9a16be94e40a.tar nowayforward_human-cc16ebc3927fa19c86d970067bcb9a16be94e40a.tar.gz nowayforward_human-cc16ebc3927fa19c86d970067bcb9a16be94e40a.zip | |
feat(views): Implement adding a list item
| -rw-r--r-- | controllers/list.php | 29 | ||||
| -rw-r--r-- | views/archive/index.php | 21 | ||||
| -rw-r--r-- | views/global/router.php | 1 | ||||
| -rw-r--r-- | views/list/meta.php | 1 | ||||
| -rw-r--r-- | views/list/update/index.php | 32 | ||||
| -rw-r--r-- | views/list/update/meta.php | 3 |
6 files changed, 81 insertions, 6 deletions
diff --git a/controllers/list.php b/controllers/list.php index 2dea9ec..7bbb739 100644 --- a/controllers/list.php +++ b/controllers/list.php @@ -16,3 +16,32 @@ function on_post() { $list_status = $e; } } + +function on_patch() { + global $TOKEN; + global $METHOD; + + try { + $user = Database\Cookie::fromDB($TOKEN); + } + catch(Exception $e) { + return; + } + + $list = null; + try { + $list = Database\ArchiveList::fromDB($METHOD['lid']); + } + catch(Exception $e) { + return; + } + + switch ($METHOD['type']) { + case 'add': $list->addItem($METHOD['wid']); break; + + default: throw new Exception('Unknown type ' . $METHOD['type']); + } + + header('Location: /list/' . $list->LID); + exit(); +} diff --git a/views/archive/index.php b/views/archive/index.php index 7de2dff..085a033 100644 --- a/views/archive/index.php +++ b/views/archive/index.php @@ -37,14 +37,23 @@ <span class="float-right"><?= Database\User::fromDBuid($page->RequesterUID)->Username ?></span> </div> </section> - <?php if (false): # If user logged-in ?> - <section> - <span><!-- Add to list button --></span> - <span><!-- Delete (when admin) button --></span> - <section> - <?php endif; ?> + <section name="itemButton" hidden> + <form action="/list/update" method="GET"> + <input type="hidden" name="wid" value="<?= $page->WID ?>"> + <input type="submit" value="+"> + </form> + <span><!-- Delete (when admin) button --></span> + </section> </section> <?php endforeach; ?> + <script type="text/javascript"> + function showButtons() { + for (buttonset of document.getElementsByName('itemButton')) { + buttonset.hidden = false; + } + } + authenticated(showButtons); + </script> <?php elseif(!$exists): ?> <h2>"<?= $url ?>" Does not exist!</h2> diff --git a/views/global/router.php b/views/global/router.php index a783531..41e0b48 100644 --- a/views/global/router.php +++ b/views/global/router.php @@ -20,6 +20,7 @@ function route_view() { } switch ($root . $subroot) { + case '/list/update': return '/list/update'; } switch ($root) { diff --git a/views/list/meta.php b/views/list/meta.php index 137794e..5e5e52e 100644 --- a/views/list/meta.php +++ b/views/list/meta.php @@ -2,3 +2,4 @@ $lid = explode('/', $uri, 4)[2]; $title = 'List'; +$controller = 'list'; diff --git a/views/list/update/index.php b/views/list/update/index.php new file mode 100644 index 0000000..6fa91e1 --- /dev/null +++ b/views/list/update/index.php @@ -0,0 +1,32 @@ + +<!-- TODO: Redirect when no user --> + +<?php + $user = null; + $webpage = null; + $lists = null; + + try { + $user = Database\Cookie::fromDB($TOKEN); + $webpage = Database\Webpage::fromDBwid($_GET['wid']); + $lists = Database\ArchiveList::allListsByUser($user->UID); + } + catch (Exception $e) {} +?> + +<!-- TODO: Redirect when no webpage --> +<!-- TODO: Redirect when lists is empty --> + +<h2>To which list do you want to add "<?= $webpage->URL ?>"?</h2> + +<form action="/list" method="GET"> + <input type="hidden" name="method" value="PATCH"> + <select name="lid"> + <?php foreach ($lists as $list): ?> + <option value="<?= $list->LID ?>"><?= $list->Name ?></option> + <?php endforeach; ?> + </select> + <input type="hidden" name="type" value="add"> + <input type="hidden" name="wid" value="<?= $_GET['wid'] ?>"> + <input type="submit" value="Select"> +</form> diff --git a/views/list/update/meta.php b/views/list/update/meta.php new file mode 100644 index 0000000..96fd169 --- /dev/null +++ b/views/list/update/meta.php @@ -0,0 +1,3 @@ +<?php + +$title = 'Add to list'; |
