nopaque/app/static/js/RessourceLists/PublicUserList.js

95 lines
2.9 KiB
JavaScript
Raw Normal View History

2022-12-19 11:46:18 +00:00
class PublicUserList extends RessourceList {
static autoInit() {
for (let publicUserListElement of document.querySelectorAll('.public-user-list:not(.no-autoinit)')) {
new PublicUserList(publicUserListElement);
}
}
static options = {
initialHtmlGenerator: (id) => {
return `
<div class="input-field">
<i class="material-icons prefix">search</i>
<input id="${id}-search" class="search" type="search"></input>
<label for="${id}-search">Search user</label>
</div>
<table>
<thead>
<tr>
<th style="width:15%;"></th>
<th>Username</th>
2022-12-19 14:02:43 +00:00
<th>Full name</th>
<th>Location</th>
<th>Organization</th>
<th>Corpora online</th>
2022-12-19 11:46:18 +00:00
<th></th>
</tr>
</thead>
<tbody class="list"></tbody>
</table>
<ul class="pagination"></ul>
`.trim();
},
item: `
<tr class="clickable hoverable">
2022-12-19 14:02:43 +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>
2022-12-19 11:46:18 +00:00
<td class="right-align">
<a class="action-button btn-floating waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim(),
ressourceMapper: (user) => {
return {
'id': user.id,
'member-since': user.member_since,
2022-12-19 14:02:43 +00:00
'avatar': user.avatar ? `/profile/${user.id}/avatars/${user.avatar.id}` : '/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'
2022-12-19 11:46:18 +00:00
};
},
sortArgs: ['member-since', {order: 'desc'}],
valueNames: [
{data: ['id']},
{data: ['member-since']},
{name: 'avatar', attr: 'src'},
2022-12-19 14:02:43 +00:00
'username',
'full-name',
'location',
'organization',
'corpora-online'
2022-12-19 11:46:18 +00:00
]
};
constructor(listElement, options = {}) {
super(listElement, {...PublicUserList.options, ...options});
}
init(users) {
super._init(Object.values(users));
}
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 = `/profile/${publicUserId}`;
break;
}
default: {
break;
}
}
}
}