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

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-10-30 17:26:41 +00:00
import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../logger/logger';
2021-11-02 04:29:24 +00:00
const LOG = Logger.create(__filename, electronConsole);
2021-10-30 17:26:41 +00:00
import BaseElements from './require/base-elements.js';
import ClientController from '../client-controller.js';
import Q from '../q-module';
import UI from '../ui';
import Controller from '../controller';
2021-10-30 17:26:41 +00:00
export default function createServerContextMenu(document: Document, q: Q, ui: UI, controller: Controller, server: ClientController) {
let element = BaseElements.createContextMenu(document, {
class: 'server-context', content: [
{ class: 'item red leave-server', content: 'Leave Server' }
]
});
2021-10-30 17:26:41 +00:00
q.$$$(element, '.leave-server').addEventListener('click', async () => {
element.removeSelf();
await server.disconnect();
await controller.removeServer(server);
await ui.removeServer(server);
let firstServerElement = q.$_('#server-list .server');
if (firstServerElement) {
firstServerElement.click();
} else {
LOG.warn('no first server element to click on');
}
});
2021-10-30 17:26:41 +00:00
return element;
2021-10-30 17:26:41 +00:00
}