mirror of
https://github.com/openvk/openvk
synced 2024-12-22 16:42:32 +03:00
add gui 4 dis
This commit is contained in:
parent
813306f38e
commit
94e2f440be
8 changed files with 215 additions and 27 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
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";
|
||||
|
||||
|
|
|
@ -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")},
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -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 @@
|
|||
<div n:attr="id => ($isInterests ? 'activetabs' : 'ki')" class="tab">
|
||||
<a n:attr="id => ($isInterests ? 'act_tab_a' : 'ki')" href="/edit?act=interests">{_interests}</a>
|
||||
</div>
|
||||
<div n:attr="id => ($isAdditional ? 'activetabs' : 'ki')" class="tab">
|
||||
<a n:attr="id => ($isAdditional ? 'act_tab_a' : 'ki')" href="/edit?act=additional">{_additional}</a>
|
||||
</div>
|
||||
<div n:attr="id => ($isAvatar ? 'activetabs' : 'ki')" class="tab">
|
||||
<a n:attr="id => ($isAvatar ? 'act_tab_a' : 'ki')" href="/edit?act=avatar">{_avatar}</a>
|
||||
</div>
|
||||
|
@ -383,7 +387,58 @@
|
|||
</center>
|
||||
</div>
|
||||
</form>
|
||||
{elseif $isAdditional}
|
||||
{var $f_iterator = 0}
|
||||
<h4>{_additional_information}</h4>
|
||||
<p>{tr("additional_fields_description", ovkGetQuirk("users.max-fields"))}</p>
|
||||
<form id="additional_fields_form" method="POST" enctype="multipart/form-data">
|
||||
<div class="edit_field_container_inserts">
|
||||
<table data-iterator="{$f_iterator}" class="outline_table edit_field_container_item" width="80%" border="0" align="center" n:foreach="$thisUser->getAdditionalFields() as $field">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="150">
|
||||
{_additional_field_name}
|
||||
</td>
|
||||
<td>
|
||||
<input name="name_{$f_iterator}" type="text" value="{$field->getName(false)}">
|
||||
</td>
|
||||
<td>
|
||||
<div id="small_remove_button"></div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
{_additional_field_text}
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="text_{$f_iterator}">{$field->getContent()}</textarea>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
{_additional_field_place}
|
||||
</td>
|
||||
<td>
|
||||
<select name="place_{$f_iterator}">
|
||||
<option value="0" n:attr="selected => $field->isContact()">{_additional_field_place_contacts}</option>
|
||||
<option value="1" n:attr="selected => !$field->isContact()">{_additional_field_place_interests}</option>
|
||||
</select>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
{php $f_iterator += 1}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="flex_column_center_gap5px">
|
||||
<input type="button" id="additional_field_append" value="{_add}" class="button" />
|
||||
<input type="hidden" name="hash" value="{$csrfToken}" />
|
||||
<input type="submit" value="{_save}" class="button" />
|
||||
</div>
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(`
|
||||
<table data-iterator="${iterator}" class="outline_table edit_field_container_item" width="80%" border="0" align="center">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="150">${tr("additional_field_name")}</td>
|
||||
<td><input name="name_${iterator}" type="text"></td>
|
||||
<td><div id="small_remove_button"></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">${tr("additional_field_text")}</td>
|
||||
<td><textarea name="text_${iterator}"></textarea></td><td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>${tr("additional_field_place")}</td>
|
||||
<td>
|
||||
<select name="place_${iterator}">
|
||||
<option value="0">${tr("additional_field_place_contacts")}</option>
|
||||
<option value="1" selected>${tr("additional_field_place_interests")}</option>
|
||||
</select>
|
||||
</td><td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
`)
|
||||
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
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue