From 94e2f440bea4ac929d2048fffe9fe039409e0460 Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:48:35 +0300 Subject: [PATCH] add gui 4 dis --- .../UserInfoEntities/AdditionalField.php | 32 +++++----- Web/Presenters/UserPresenter.php | 34 ++++++++++- Web/Presenters/templates/@layout.xml | 1 + Web/Presenters/templates/User/Edit.xml | 55 ++++++++++++++++++ Web/static/css/main.css | 22 +++++++ Web/static/js/al_wall.js | 58 +++++++++++++++++++ locales/en.strings | 20 +++++-- locales/ru.strings | 20 +++++-- 8 files changed, 215 insertions(+), 27 deletions(-) diff --git a/Web/Models/Entities/UserInfoEntities/AdditionalField.php b/Web/Models/Entities/UserInfoEntities/AdditionalField.php index b2a936df..47c69de3 100644 --- a/Web/Models/Entities/UserInfoEntities/AdditionalField.php +++ b/Web/Models/Entities/UserInfoEntities/AdditionalField.php @@ -16,14 +16,14 @@ class AdditionalField extends RowModel return (int) $this->getRecord()->owner; } - function getName(): string + function getName(bool $tr = true): string { $orig_name = $this->getRecord()->name; $name = $orig_name; - if($name[0] === "_") - $name = tr("custom_fav_" . substr($name, 1)); + if($tr && $name[0] === "_") + $name = tr("custom_field_" . substr($name, 1)); - if(str_contains($name, "custom_fav")) + if(str_contains($name, "custom_field")) return $orig_name; return $name; @@ -46,6 +46,11 @@ class AdditionalField extends RowModel return "contact"; } + function isContact(): bool + { + return $this->getRecord()->place == AdditionalField::PLACE_CONTACTS; + } + function toVkApiStruct(): object { return (object) [ @@ -58,9 +63,7 @@ class AdditionalField extends RowModel static function getById(int $id) { $ctx = DatabaseConnection::i()->getContext(); - $entry = $ctx->table("additional_fields")->where([ - "id" => $id, - ])->fetch(); + $entry = $ctx->table("additional_fields")->where("id", $id)->fetch(); if(!$entry) return NULL; @@ -71,9 +74,7 @@ class AdditionalField extends RowModel static function getByOwner(int $owner): \Traversable { $ctx = DatabaseConnection::i()->getContext(); - $entries = $ctx->table("additional_fields")->where([ - "owner" => $owner, - ]); + $entries = $ctx->table("additional_fields")->where("owner", $owner); foreach($entries as $entry) { yield new AdditionalField($entry); @@ -82,8 +83,13 @@ class AdditionalField extends RowModel static function getCountByOwner(int $owner): \Traversable { - return DatabaseConnection::i()->getContext()->table("additional_fields")->where([ - "owner" => $owner, - ])->count(); + return DatabaseConnection::i()->getContext()->table("additional_fields")->where("owner", $owner)->count(); + } + + static function resetByOwner(int $owner): bool + { + DatabaseConnection::i()->getContext()->table("additional_fields")->where("owner", $owner)->delete(); + + return true; } } diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 3d070b1c..41c2db1e 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -297,10 +297,40 @@ final class UserPresenter extends OpenVKPresenter $this->returnJson([ "success" => true ]); + } elseif($_GET['act'] === "additional") { + $maxAddFields = ovkGetQuirk("users.max-fields"); + $items = []; + + for($i = 0; $i < $maxAddFields; $i++) { + if(!$this->postParam("name_".$i)) { + continue; + } + + $items[] = [ + "name" => $this->postParam("name_".$i), + "text" => $this->postParam("text_".$i), + "place" => $this->postParam("place_".$i), + ]; + } + + \openvk\Web\Models\Entities\UserInfoEntities\AdditionalField::resetByOwner($this->user->id); + foreach($items as $new_field_info) { + $place = (int)($new_field_info["place"]); + + $new_field = new \openvk\Web\Models\Entities\UserInfoEntities\AdditionalField; + $new_field->setOwner($this->user->id); + $new_field->setName(ovk_proc_strtr($new_field_info["name"], 50)); + $new_field->setText(ovk_proc_strtr($new_field_info["text"], 1000)); + $new_field->setPlace([0, 1][$place] ? $place : 0); + + $new_field->save(); + } } try { - $user->save(); + if($_GET['act'] !== "additional") { + $user->save(); + } } catch(\PDOException $ex) { if($ex->getCode() == 23000) $this->flashFail("err", tr("error"), tr("error_shorturl")); @@ -312,7 +342,7 @@ final class UserPresenter extends OpenVKPresenter } $this->template->mode = in_array($this->queryParam("act"), [ - "main", "contacts", "interests", "avatar", "backdrop" + "main", "contacts", "interests", "avatar", "backdrop", "additional" ]) ? $this->queryParam("act") : "main"; diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 811548cd..3990c741 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -452,6 +452,7 @@ "max_filesize_mb": 5, "current_id": {$thisUser ? $thisUser->getId() : 0}, "disable_ajax": {$disable_ajax ? $disable_ajax : 0}, + "max_add_fields": {ovkGetQuirk("users.max-fields")}, } diff --git a/Web/Presenters/templates/User/Edit.xml b/Web/Presenters/templates/User/Edit.xml index b0eea51f..163ea6a2 100644 --- a/Web/Presenters/templates/User/Edit.xml +++ b/Web/Presenters/templates/User/Edit.xml @@ -13,6 +13,7 @@ {var $isMain = $mode === 'main'} {var $isContacts = $mode === 'contacts'} {var $isInterests = $mode === 'interests'} + {var $isAdditional = $mode === 'additional'} {var $isAvatar = $mode === 'avatar'} {var $isBackDrop = $mode === 'backdrop'} @@ -31,6 +32,9 @@
{_interests}
+
+ {_additional} +
{_avatar}
@@ -383,7 +387,58 @@ + {elseif $isAdditional} + {var $f_iterator = 0} +

{_additional_information}

+

{tr("additional_fields_description", ovkGetQuirk("users.max-fields"))}

+
+
+ + + + + + + + + + + + + + + + + + + {php $f_iterator += 1} +
+ {_additional_field_name} + + + +
+
+ {_additional_field_text} + + +
+ {_additional_field_place} + + +
+
+ +
+ + + +
+
{/if} diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 928ef300..677ea4fc 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -506,6 +506,28 @@ table { text-align: left; } +.outline_table td { + text-align: right; + font-weight: normal; + color: gray; +} + +.outline_table { + border-bottom: 1px solid #cbcbcb; + padding: 5px 0px; +} + +.outline_table:last-of-type { + border-bottom: unset; +} + +.flex_column_center_gap5px { + display: flex; + flex-direction: column; + align-items: center; + gap: 5px; +} + .information { padding: 9px; background-color: #c3e4ff; diff --git a/Web/static/js/al_wall.js b/Web/static/js/al_wall.js index 58ba9437..6b1cfb35 100644 --- a/Web/static/js/al_wall.js +++ b/Web/static/js/al_wall.js @@ -2887,3 +2887,61 @@ u(document).on('click', '#_bl_toggler', async (e) => { } } }) + +/* Additional fields */ + +u(document).on("click", "#additional_field_append", (e) => { + let iterator = 0 + if(u(`table[data-iterator]`).last()) { + iterator = Number(u(`table[data-iterator]`).last().dataset.iterator) + 1 + } + + if(iterator >= window.openvk.max_add_fields) { + return + } + + u('.edit_field_container_inserts').append(` + + + + + + + + + + + + + + + + +
${tr("additional_field_name")}
${tr("additional_field_text")}
${tr("additional_field_place")} + +
+ `) + u(`.edit_field_container_item[data-iterator='${iterator}'] input[type="text"]`).nodes[0].focus() +}) + +u(document).on("click", ".edit_field_container_item #small_remove_button", (e) => { + let iterator = 0 + u(e.target).closest('table').remove() + u(".edit_field_container_inserts .edit_field_container_item").nodes.forEach(node => { + node.setAttribute('data-iterator', iterator) + iterator += 1 + }) +}) + +u(document).on("submit", "#additional_fields_form", (e) => { + u(`.edit_field_container_item input, .edit_field_container_item textarea`).nodes.forEach(node => { + if(node.value == "" || node.value == " ") { + e.preventDefault() + node.focus() + return + } + }) +}) diff --git a/locales/en.strings b/locales/en.strings index d82e0794..8bef6d40 100644 --- a/locales/en.strings +++ b/locales/en.strings @@ -147,18 +147,26 @@ "personal_information" = "Personal information"; "interests" = "Interests"; +"additional" = "Additional"; +"additional_fields_description" = "There you can add additional info about you, like another profiles links or your interests. Up to a maximum of $1 such fields can be added."; +"additional_field_name" = "Name"; +"additional_field_text" = "Text"; +"additional_field_place" = "Place"; +"additional_field_place_contacts" = "In \"contacts\""; +"additional_field_place_interests" = "In \"interests\""; + "favorite_music" = "Favorite music"; "favorite_films" = "Favorite flims"; "favorite_shows" = "Favorite TV-shows"; "favorite_books" = "Favorite books"; "favorite_quotes" = "Favorite quotes"; "favorite_games" = "Favorite games"; -"custom_fav_favorite_performers" = "Favourite performers"; -"custom_fav_favorite_content_makers" = "Favourite content-makers"; -"custom_fav_favorite_anime" = "Favourite anime"; -"custom_fav_favorite_manga" = "Favourite manga"; -"custom_fav_favorite_vtubers" = "Favourite vtubers"; -"custom_fav_favorite_albums" = "Favourite music albums"; +"custom_field_favorite_performers" = "Favourite performers"; +"custom_field_favorite_content_makers" = "Favourite content-makers"; +"custom_field_favorite_anime" = "Favourite anime"; +"custom_field_favorite_manga" = "Favourite manga"; +"custom_field_favorite_vtubers" = "Favourite vtubers"; +"custom_field_favorite_albums" = "Favourite music albums"; "information_about" = "About"; diff --git a/locales/ru.strings b/locales/ru.strings index 531b6de8..12eb8801 100644 --- a/locales/ru.strings +++ b/locales/ru.strings @@ -131,18 +131,26 @@ "address" = "Адрес"; "personal_information" = "Личная информация"; "interests" = "Интересы"; +"additional" = "Дополнительно"; +"additional_fields_description" = "Здесь вы можете добавить дополнительную информацию о себе: ссылки на ваши социальные сети, либо же ваши интересы. Максимум можно добавить до $1 таких полей."; +"additional_field_name" = "Название"; +"additional_field_text" = "Текст"; +"additional_field_place" = "Отображение"; +"additional_field_place_contacts" = "В \"контактах\""; +"additional_field_place_interests" = "В \"интересах\""; + "favorite_music" = "Любимая музыка"; "favorite_films" = "Любимые фильмы"; "favorite_shows" = "Любимые ТВ-шоу"; "favorite_books" = "Любимые книги"; "favorite_quotes" = "Любимые цитаты"; "favorite_games" = "Любимые игры"; -"custom_fav_favorite_performers" = "Любимые исполнители"; -"custom_fav_favorite_content_makers" = "Любимые контент-мейкеры"; -"custom_fav_favorite_anime" = "Любимые аниме"; -"custom_fav_favorite_manga" = "Любимая манга"; -"custom_fav_favorite_vtubers" = "Любимые витуберы"; -"custom_fav_favorite_albums" = "Любимые альбомы"; +"custom_field_favorite_performers" = "Любимые исполнители"; +"custom_field_favorite_content_makers" = "Любимые контент-мейкеры"; +"custom_field_favorite_anime" = "Любимые аниме"; +"custom_field_favorite_manga" = "Любимая манга"; +"custom_field_favorite_vtubers" = "Любимые витуберы"; +"custom_field_favorite_albums" = "Любимые альбомы"; "information_about" = "О себе"; "updated_at" = "Обновлено $1";