class Component { constructor(name) { this.name = name; this.start(); } handle(data, ds) { } init() { } getUrl(ds) { return ''; } start() { if (window.routerIsReady) { router.addComponent(this.name || VUtils.tempId(), this); this.init(); } else { window.addEventListener('routerReady', this.start.bind(this)); } } } class RolesComponent extends Component { constructor() { super("/roles"); this.tpl = "rolesList"; this.tpl2 = "roleEdit"; this._url = "/admin/api/roles"; } async handle(data, ds) { let meTpl = ds.id ? this.tpl2 : this.tpl; await tpl.loadTemplate(meTpl); return await tpl.renderOn(meTpl, data.content); } getUrl(ds) { let url = this._url; if (ds.id) { url += '/' + ds.id; } return url; } } (() => { // init all Components ;) new RolesComponent(); if (routerIsReady) { document.body.dispatchEvent(new CustomEvent('triggerRouter')); } else { document.addEventListener('routerReady', e => { document.body.dispatchEvent(new CustomEvent('triggerRouter')); }) } })();