cordis/client/webapp/elements/context-menu-conn.ts

47 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-10-30 17:26:41 +00:00
import ElementsUtil from './require/elements-util.js';
import BaseElements from './require/base-elements.js';
import createPersonalizeOverlay from './overlay-personalize.js';
import Q from '../q-module.js';
import UI from '../ui.js';
2021-11-22 02:47:29 +00:00
import CombinedGuild from '../guild-combined.js';
2021-11-21 18:29:42 +00:00
export default function createConnectionContextMenu(document: Document, q: Q, ui: UI, guild: CombinedGuild) {
let statuses = [ 'online', 'away', 'busy', 'invisible' ];
let content: any[] = [
{ class: 'item personalize', content: [
{ class: 'icon', content: { tag: 'img', src: './img/pencil-icon.png' } },
{ content: 'Personalize' }
] },
{ class: 'item-spacer' }
];
content = content.concat(statuses.map(status => {
return { class: 'item ' + status, content: [
{ class: 'status-circle' },
{ class: 'status-text', content: status }
] };
}));
let element = BaseElements.createContextMenu(document, { class: 'member-context', content: content });
q.$$$(element, '.personalize').addEventListener('click', async () => {
element.removeSelf();
if (ui.activeConnection === null) return;
2021-11-22 02:47:29 +00:00
let overlayElement = createPersonalizeOverlay(document, q, guild, ui.activeConnection);
document.body.appendChild(overlayElement);
q.$$$(overlayElement, '.text-input').focus();
ElementsUtil.setCursorToEnd(q.$$$(overlayElement, '.text-input'));
});
for (let status of statuses) {
q.$$$(element, '.' + status).addEventListener('click', async () => {
element.removeSelf();
2021-11-22 02:47:29 +00:00
let currentConnection = await guild.fetchConnectionInfo();
if (status != currentConnection.status) {
2021-11-22 02:47:29 +00:00
await guild.requestSetStatus(status);
}
});
}
return element;
2021-10-30 17:26:41 +00:00
}