class UserList extends ResourceList {
static autoInit() {
for (let userListElement of document.querySelectorAll('.user-list:not(.no-autoinit)')) {
new UserList(userListElement);
}
}
constructor(listContainerElement, options = {}) {
super(listContainerElement, options);
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
}
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('user-list-');
}
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
this.listContainerElement.innerHTML = `
search
|
Username |
Full name |
Location |
Organization |
Corpora online |
|
`.trim();
}
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': Object.values(user.corpora).filter((corpus) => corpus.is_public).length
};
};
sort() {
this.listjs.sort('member-since', {order: 'desc'});
}
onClick(event) {
let listItemElement = event.target.closest('.list-item[data-id]');
if (listItemElement === null) {return;}
let itemId = listItemElement.dataset.id;
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
switch (listAction) {
case 'view': {
window.location.href = `/users/${itemId}`;
break;
}
default: {
break;
}
}
}
}