From 76605b9eeda1eb9e63064fc3cfe5ab9923b6aba9 Mon Sep 17 00:00:00 2001 From: Maxim Leshchenko Date: Thu, 25 Nov 2021 22:10:53 +0200 Subject: [PATCH] Users: Add a popup to change the status Now, when you click on the status, a popup window opens in which you can do this (just like in the original VK and OpenVK Classic). So far, changing the status requires a page reload. Closes #227 --- Web/Presenters/UserPresenter.php | 12 +++++++++++ Web/Presenters/templates/User/View.xml | 29 +++++++++++++++++++++++--- Web/static/css/style.css | 23 ++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index bff4de2f..4115d178 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -173,6 +173,18 @@ final class UserPresenter extends OpenVKPresenter $user->setFav_Books(empty($this->postParam("fav_books")) ? NULL : ovk_proc_strtr($this->postParam("fav_books"), 300)); $user->setFav_Quote(empty($this->postParam("fav_quote")) ? NULL : ovk_proc_strtr($this->postParam("fav_quote"), 300)); $user->setAbout(empty($this->postParam("about")) ? NULL : ovk_proc_strtr($this->postParam("about"), 300)); + } elseif($_GET['act'] === "status") { + if(mb_strlen($this->postParam("status")) > 255) { + $statusLength = (string) mb_strlen($this->postParam("status")); + $this->flashFail("err", "Ошибка", "Статус слишком длинный ($statusLength символов вместо 255 символов)"); + } + + $user->setStatus(empty($this->postParam("status")) ? NULL : $this->postParam("status")); + $user->save(); + + header("HTTP/1.1 302 Found"); + header("Location: /id" . $user->getId()); + exit; } try { diff --git a/Web/Presenters/templates/User/View.xml b/Web/Presenters/templates/User/View.xml index 2687c42b..9d40d5c9 100644 --- a/Web/Presenters/templates/User/View.xml +++ b/Web/Presenters/templates/User/View.xml @@ -353,14 +353,24 @@
{$alert}
+ {var thatIsThisUser = isset($thisUser) && $user->getId() == $thisUser->getId()} +

{$user->getFullName()}

{if !is_null($user->getStatus())} -
{$user->getStatus()}
- {elseif isset($thisUser) && $user->getId() == $thisUser->getId()} +
{$user->getStatus()}
+ {elseif $thatIsThisUser}
- [ {_"change_status"} ] +
[ {_"change_status"} ]
{/if}
@@ -542,6 +552,19 @@ Function.noop ]); } + + {if isset($thisUser) && $user->getId() == $thisUser->getId()} + function setStatusEditorShown(shown) { + document.getElementById("status_editor").style.display = shown ? "block" : "none"; + } + + document.addEventListener("click", event => { + if(!event.target.closest("#status_editor") && !event.target.closest("#page_status_text")) + setStatusEditorShown(false); + }); + + document.getElementById("page_status_text").onclick = setStatusEditorShown.bind(this, true); + {/if}
diff --git a/Web/static/css/style.css b/Web/static/css/style.css index 3f9cfa1c..443b8cc4 100644 --- a/Web/static/css/style.css +++ b/Web/static/css/style.css @@ -340,6 +340,29 @@ table { overflow: hidden; } +.page_status_edit_button { + cursor: pointer; +} + +.page_status_edit_button:hover { + text-decoration: underline; +} + +.page_status_popup { + position: absolute; + border: 1px solid #CCC; + background-color: #f7f7f7; + box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);; + padding: 10px; + float: right; + margin-top: 6px; + margin-left: -6px; +} + +.page_status_popup form { + margin: 0; +} + .button { border-radius: 2px; border: #595959;