diff --git a/apps/member/static/member/js/trust.js b/apps/member/static/member/js/trust.js index a16bed08..15b5359f 100644 --- a/apps/member/static/member/js/trust.js +++ b/apps/member/static/member/js/trust.js @@ -1,7 +1,7 @@ /** * On form submit, create a new friendship */ -function create_trust (e) { +function form_create_trust (e) { // Do not submit HTML form e.preventDefault() @@ -14,25 +14,35 @@ function create_trust (e) { addMsg(gettext("You can't add yourself as a friend"), "danger") return } - $.post('/api/note/trust/', { - csrfmiddlewaretoken: formData.get('csrfmiddlewaretoken'), - trusting: formData.get('trusting'), - trusted: trusted_alias.note - }).done(function () { - // Reload table - $('#trust_table').load(location.pathname + ' #trust_table') - addMsg(gettext('Friendship successfully added'), 'success') - }).fail(function (xhr, _textStatus, _error) { - errMsg(xhr.responseJSON) - }) + create_trust(formData.get('trusting'), trusted_alias.note) }).fail(function (xhr, _textStatus, _error) { errMsg(xhr.responseJSON) }) } /** - * On click of "delete", delete the alias - * @param button_id:Integer Alias id to remove + * Create a trust between users + * @param trusting:Integer trusting note id + * @param trusted:Integer trusted note id + */ +function create_trust(trusting, trusted) { + $.post('/api/note/trust/', { + trusting: trusting, + trusted: trusted, + csrfmiddlewaretoken: CSRF_TOKEN + }).done(function () { + // Reload tables + $('#trust_table').load(location.pathname + ' #trust_table') + $('#trusted_table').load(location.pathname + ' #trusted_table') + addMsg(gettext('Friendship successfully added'), 'success') + }).fail(function (xhr, _textStatus, _error) { + errMsg(xhr.responseJSON) + }) +} + +/** + * On click of "delete", delete the trust + * @param button_id:Integer Trust id to remove */ function delete_button (button_id) { $.ajax({ @@ -42,6 +52,7 @@ function delete_button (button_id) { }).done(function () { addMsg(gettext('Friendship successfully deleted'), 'success') $('#trust_table').load(location.pathname + ' #trust_table') + $('#trusted_table').load(location.pathname + ' #trusted_table') }).fail(function (xhr, _textStatus, _error) { errMsg(xhr.responseJSON) }) @@ -49,5 +60,5 @@ function delete_button (button_id) { $(document).ready(function () { // Attach event - document.getElementById('form_trust').addEventListener('submit', create_trust) + document.getElementById('form_trust').addEventListener('submit', form_create_trust) }) diff --git a/apps/member/templates/member/profile_trust.html b/apps/member/templates/member/profile_trust.html index bd8d6b50..b89f05f6 100644 --- a/apps/member/templates/member/profile_trust.html +++ b/apps/member/templates/member/profile_trust.html @@ -7,7 +7,7 @@ SPDX-License-Identifier: GPL-3.0-or-later {% block profile_content %}