feat(friends): add ajax

This commit is contained in:
veselcraft 2024-09-18 01:02:56 +03:00
parent 4c78617a9c
commit c5644a51d6
No known key found for this signature in database
GPG key ID: 9CF0B42766CCF7BA
7 changed files with 67 additions and 7 deletions

View file

@ -49,7 +49,7 @@
{include description, x => $dat}
{/ifset}
</td>
<td n:ifset="actions" valign="top" class="action_links" style="width: 150px;">
<td n:ifset="actions" valign="top" class="action_links" style="min-width: 150px;">
{include actions, x => $dat}
</td>
</tr>

View file

@ -145,21 +145,21 @@
{if ($x->getId() !== $thisUser->getId()) && ($thisUser->getId() === $user->getId())}
{var $subStatus = $x->getSubscriptionStatus($thisUser)}
{if $subStatus === 0}
<form action="/setSub/user" method="post" class="profile_link_form">
<form action="/setSub/user" method="post" class="profile_link_form" id="_submitUserSubscriptionAction">
<input type="hidden" name="act" value="add" />
<input type="hidden" name="id" value="{$x->getId()}" />
<input type="hidden" name="hash" value="{$csrfToken}" />
<input type="submit" class="profile_link" value="{_friends_add}" />
</form>
{elseif $subStatus === 1}
<form action="/setSub/user" method="post" class="profile_link_form">
<form action="/setSub/user" method="post" class="profile_link_form" id="_submitUserSubscriptionAction">
<input type="hidden" name="act" value="add" />
<input type="hidden" name="id" value="{$x->getId()}" />
<input type="hidden" name="hash" value="{$csrfToken}" />
<input type="submit" class="profile_link" value="{_friends_accept}" />
</form>
{if $act !== 'followers'}
<form action="/setSub/user" method="post" class="profile_link_form">
<form action="/setSub/user" method="post" class="profile_link_form" id="_submitUserSubscriptionAction">
<input type="hidden" name="act" value="rej" />
<input type="hidden" name="id" value="{$x->getId()}" />
<input type="hidden" name="hash" value="{$csrfToken}" />
@ -167,7 +167,7 @@
</form>
{/if}
{elseif $subStatus === 2}
<form action="/setSub/user" method="post" class="profile_link_form">
<form action="/setSub/user" method="post" class="profile_link_form" id="_submitUserSubscriptionAction">
<input type="hidden" name="act" value="rem" />
<input type="hidden" name="id" value="{$x->getId()}" />
<input type="hidden" name="hash" value="{$csrfToken}" />
@ -175,7 +175,7 @@
</form>
{elseif $subStatus === 3}
<a href="/im?sel={$x->getId()}" class="profile_link">{_send_message}</a>
<form action="/setSub/user" method="post" class="profile_link_form">
<form action="/setSub/user" method="post" class="profile_link_form" id="_submitUserSubscriptionAction">
<input type="hidden" name="act" value="rem" />
<input type="hidden" name="id" value="{$x->getId()}" />
<input type="hidden" name="hash" value="{$csrfToken}" />

View file

@ -427,6 +427,22 @@ h1 {
text-transform: lowercase;
}
.action_links.disable>a,
.action_links.disable>form>input,
.action_links.disable {
cursor: not-allowed;
color: grey;
}
.action_links.loading::after {
content: "";
display: inline-block;
background-image: url('/assets/packages/static/openvk/img/loading_mini.gif');
width: 30px;
height: 7px;
margin-left: 5px;
}
.profile_link.disable>a,
.profile_link.disable {
cursor: not-allowed;

View file

@ -167,6 +167,44 @@ document.addEventListener("DOMContentLoaded", function() { //BEGIN
return false;
});
u("#_submitUserSubscriptionAction").handle("submit", async function(e) {
u(this).nodes[0].parentElement.classList.add('loading');
u(this).nodes[0].parentElement.classList.add('disable');
console.log(e.target);
const data = await fetch(u(this).attr('action'), { method: 'POST', body: new FormData(e.target) });
if (data.ok) {
u(this).nodes[0].parentElement.classList.remove('loading');
u(this).nodes[0].parentElement.classList.remove('disable');
if (e.target[0].value == "add") {
u(this).nodes[0].parentElement.innerHTML = tr("friends_add_msg");
} else if (e.target[0].value == "rej") {
u(this).nodes[0].parentElement.innerHTML = tr("friends_rej_msg");
} else if (e.target[0].value == "rem") {
u(this).nodes[0].parentElement.innerHTML = tr("friends_rem_msg");
}
}
})
/*
<script>
$("form").on("submit", function (e) {
var dataString = $(this).serialize();
$.ajax({
type: "POST",
url: "/setSub/user",
data: dataString,
success: function () {
console.log("penis");
}
});
e.preventDefault();
});
</script>
*/
}); //END ONREADY DECLS
async function repostPost(id, hash) {

View file

@ -1 +1 @@
ALTER TABLE `subscriptions` ADD `flags` tinyint(3) unsigned NOT NULL;
ALTER TABLE `subscriptions` ADD `flags` tinyint(3) unsigned NOT NULL DEFAULT '0' AFTER `target`

View file

@ -260,6 +260,9 @@
"friends_reject" = "Reject request";
"friends_accept" = "Accept request";
"friends_leave_in_flw" = "Leave in followers";
"friends_add_msg" = "Now you're friends.";
"friends_rej_msg" = "You left this user as subscriber.";
"friends_rem_msg" = "You deleted this user from your friend list.";
"send_message" = "Send a message";
"incoming_req" = "Pending";
"outcoming_req" = "Outgoing";

View file

@ -240,6 +240,9 @@
"friends_reject" = "Отменить заявку";
"friends_accept" = "Принять заявку";
"friends_leave_in_flw" = "Оставить в подписчиках";
"friends_add_msg" = "Теперь вы друзья.";
"friends_rej_msg" = "Вы оставили пользователя в подписчиках.";
"friends_rem_msg" = "Вы удалили пользователя из списка своих друзей.";
"send_message" = "Отправить сообщение";
"incoming_req" = "Входящие";
"outcoming_req" = "Исходящие";