class PublicUserList extends ResourceList {
static autoInit() {
for (let publicUserListElement of document.querySelectorAll('.public-user-list:not(.no-autoinit)')) {
new PublicUserList(publicUserListElement);
}
}
constructor(listContainerElement, options = {}) {
super(listContainerElement, options);
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
}
// #region Mandatory getters and methods to implement
get item() {
return `
|
|
|
|
|
|
send
|
`.trim();
}
get valueNames() {
return [
{data: ['id']},
{data: ['member-since']},
{name: 'avatar', attr: 'src'},
'username',
'full-name',
'location',
'organization',
'corpora-online'
];
}
initListContainerElement() {
if (!this.listContainerElement.hasAttribute('id')) {
this.listContainerElement.id = Utils.generateElementId('public-user-list-');
}
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
this.listContainerElement.innerHTML = `
search
|
Username |
Full name |
Location |
Organization |
Corpora online |
|
`.trim();
}
// #endregion
// #region Optional methods to implement
mapResourceToValue(user) {
return {
'id': user.id,
'member-since': user.member_since,
'avatar': user.avatar ? `/users/${user.id}/avatar` : '/static/images/user_avatar.png',
'username': user.username,
'full-name': user.full_name ? user.full_name : '',
'location': user.location ? user.location : '',
'organization': user.organization ? user.organization : '',
'corpora-online': '0'
};
};
sort() {
this.listjs.sort('member-since', {order: 'desc'});
}
// #endregion
onClick(event) {
let actionButtonElement = event.target.closest('.action-button');
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
let publicUserElement = event.target.closest('tr');
let publicUserId = publicUserElement.dataset.id;
switch (action) {
case 'view': {
window.location.href = `/users/${publicUserId}`;
break;
}
default: {
break;
}
}
}
}