User profile view

This commit is contained in:
Cohee
2024-04-10 02:09:38 +03:00
parent 8f1d2e0163
commit 09b44075ed
5 changed files with 108 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import { getRequestHeaders, renderTemplate } from '../script.js';
import { POPUP_RESULT, POPUP_TYPE, callGenericPopup } from './popup.js';
/**
* @type {import('../../src/users.js').User} Logged in user
* @type {import('../../src/users.js').UserViewModel} Logged in user
*/
export let currentUser = null;
@ -357,6 +357,27 @@ async function deleteUser(handle, callback) {
}
}
async function openUserProfile() {
await getCurrentUser();
const template = $(renderTemplate('userProfile'));
template.find('.userName').text(currentUser.name);
template.find('.userHandle').text(currentUser.handle);
template.find('.avatar img').attr('src', currentUser.avatar);
template.find('.userRole').text(currentUser.admin ? 'Admin' : 'User');
template.find('.userCreated').text(new Date(currentUser.created).toLocaleString());
template.find('.hasPassword').toggle(currentUser.password);
template.find('.noPassword').toggle(!currentUser.password);
template.find('.userChangePasswordButton').on('click', () => changePassword(currentUser.handle, () => { }));
template.find('.userBackupButton').on('click', function () {
$(this).addClass('disabled');
backupUserData(currentUser.handle, () => {
$(this).removeClass('disabled');
});
});
callGenericPopup(template, POPUP_TYPE.TEXT, '', { okButton: 'Close', wide: false, large: false, allowVerticalScrolling: true, allowHorizontalScrolling: false });
}
async function openAdminPanel() {
async function renderUsers() {
const users = await getUsers();
@ -406,7 +427,7 @@ async function openAdminPanel() {
});
});
callGenericPopup(template, POPUP_TYPE.TEXT, '', { okButton: 'Close', wide: true, large: true, allowVerticalScrolling: true, allowHorizontalScrolling: false });
callGenericPopup(template, POPUP_TYPE.TEXT, '', { okButton: 'Close', wide: false, large: false, allowVerticalScrolling: true, allowHorizontalScrolling: false });
renderUsers();
}
@ -430,4 +451,7 @@ jQuery(() => {
$('#admin_button').on('click', () => {
openAdminPanel();
});
$('#account_button').on('click', () => {
openUserProfile();
});
});