2023-01-04 19:00:37 +00:00
|
|
|
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)});
|
|
|
|
}
|
|
|
|
|
|
|
|
get item() {
|
|
|
|
return `
|
2023-01-05 14:03:59 +00:00
|
|
|
<tr class="list-item clickable hoverable">
|
2023-01-04 19:00:37 +00:00
|
|
|
<td><img alt="user-image" class="circle responsive-img avatar" style="width:50%"></td>
|
|
|
|
<td><b><span class="username"></span><b></td>
|
|
|
|
<td><span class="full-name"></span></td>
|
|
|
|
<td><span class="location"></span></td>
|
|
|
|
<td><span class="organization"></span></td>
|
|
|
|
<td><span class="corpora-online"></span></td>
|
|
|
|
<td class="right-align">
|
2023-01-05 14:03:59 +00:00
|
|
|
<a class="list-action-trigger btn-floating waves-effect waves-light" data-list-action="view"><i class="material-icons">send</i></a>
|
2023-01-04 19:00:37 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`.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 = `
|
|
|
|
<div class="input-field">
|
|
|
|
<i class="material-icons prefix">search</i>
|
|
|
|
<input id="${listSearchElementId}" class="search" type="text"></input>
|
|
|
|
<label for="${listSearchElementId}">Search public user</label>
|
|
|
|
</div>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th style="width:15%;"></th>
|
|
|
|
<th>Username</th>
|
|
|
|
<th>Full name</th>
|
|
|
|
<th>Location</th>
|
|
|
|
<th>Organization</th>
|
|
|
|
<th>Corpora online</th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="list"></tbody>
|
|
|
|
</table>
|
|
|
|
<ul class="pagination"></ul>
|
|
|
|
`.trim();
|
|
|
|
}
|
2023-01-05 07:11:27 +00:00
|
|
|
|
2023-01-04 19:00:37 +00:00
|
|
|
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'});
|
|
|
|
}
|
|
|
|
|
|
|
|
onClick(event) {
|
2023-01-10 09:03:27 +00:00
|
|
|
let listItemElement = event.target.closest('.list-item[data-id]');
|
2023-01-05 14:03:59 +00:00
|
|
|
if (listItemElement === null) {return;}
|
|
|
|
let itemId = listItemElement.dataset.id;
|
2023-01-10 09:03:27 +00:00
|
|
|
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
|
|
|
|
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
|
2023-01-05 14:03:59 +00:00
|
|
|
switch (listAction) {
|
2023-01-04 19:00:37 +00:00
|
|
|
case 'view': {
|
2023-01-05 14:03:59 +00:00
|
|
|
window.location.href = `/users/${itemId}`;
|
2023-01-04 19:00:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|