Skip to content

Commit

Permalink
feat(friends): add ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
veselcraft committed Sep 17, 2024
1 parent 4c78617 commit c5644a5
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Web/Presenters/templates/@listView.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
10 changes: 5 additions & 5 deletions Web/Presenters/templates/User/Friends.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,37 +145,37 @@
{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}" />
<input type="submit" class="profile_link" value="{_friends_leave_in_flw}" />
</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}" />
<input type="submit" class="profile_link" value="{_friends_reject}" />
</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}" />
Expand Down
16 changes: 16 additions & 0 deletions Web/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions Web/static/js/openvk.cls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion install/sqls/00046-deny-request.sql
Original file line number Diff line number Diff line change
@@ -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`
3 changes: 3 additions & 0 deletions locales/en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions locales/ru.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "Исходящие";
Expand Down

0 comments on commit c5644a5

Please sign in to comment.