2021-02-11 22:32:55 +01:00
|
|
|
import tpl_chat_head from './templates/chat-head.js';
|
2021-06-15 10:53:53 +02:00
|
|
|
import { ElementView } from '@converse/skeletor/src/element.js';
|
2021-02-11 22:32:55 +01:00
|
|
|
import { __ } from 'i18n';
|
|
|
|
import { _converse, api } from "@converse/headless/core";
|
|
|
|
import { getHeadingDropdownItem, getHeadingStandaloneButton } from 'plugins/chatview/utils.js';
|
2021-06-15 10:53:53 +02:00
|
|
|
import { render } from 'lit';
|
2021-02-11 22:32:55 +01:00
|
|
|
|
|
|
|
|
2021-06-15 10:53:53 +02:00
|
|
|
export default class HeadlinesHeading extends ElementView {
|
2021-02-11 22:32:55 +01:00
|
|
|
|
|
|
|
async connectedCallback () {
|
|
|
|
super.connectedCallback();
|
|
|
|
this.model = _converse.chatboxes.get(this.getAttribute('jid'));
|
|
|
|
await this.model.initialized;
|
|
|
|
this.render();
|
|
|
|
}
|
|
|
|
|
2021-06-15 10:53:53 +02:00
|
|
|
async render () {
|
|
|
|
const tpl = await this.generateHeadingTemplate();
|
|
|
|
render(tpl, this);
|
|
|
|
}
|
|
|
|
|
2021-02-11 22:32:55 +01:00
|
|
|
async generateHeadingTemplate () {
|
|
|
|
const heading_btns = await this.getHeadingButtons();
|
|
|
|
const standalone_btns = heading_btns.filter(b => b.standalone);
|
|
|
|
const dropdown_btns = heading_btns.filter(b => !b.standalone);
|
|
|
|
return tpl_chat_head(
|
|
|
|
Object.assign(this.model.toJSON(), {
|
|
|
|
'display_name': this.model.getDisplayName(),
|
|
|
|
'dropdown_btns': dropdown_btns.map(b => getHeadingDropdownItem(b)),
|
|
|
|
'standalone_btns': standalone_btns.map(b => getHeadingStandaloneButton(b))
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of objects which represent buttons for the headlines header.
|
|
|
|
* @async
|
|
|
|
* @emits _converse#getHeadingButtons
|
|
|
|
* @method HeadlinesHeading#getHeadingButtons
|
|
|
|
*/
|
|
|
|
getHeadingButtons () {
|
|
|
|
const buttons = [];
|
|
|
|
if (!api.settings.get('singleton')) {
|
|
|
|
buttons.push({
|
|
|
|
'a_class': 'close-chatbox-button',
|
|
|
|
'handler': ev => this.close(ev),
|
|
|
|
'i18n_text': __('Close'),
|
|
|
|
'i18n_title': __('Close these announcements'),
|
|
|
|
'icon_class': 'fa-times',
|
|
|
|
'name': 'close',
|
|
|
|
'standalone': api.settings.get('view_mode') === 'overlayed'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return _converse.api.hook('getHeadingButtons', this, buttons);
|
|
|
|
}
|
|
|
|
|
2021-06-15 10:53:53 +02:00
|
|
|
close (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
this.model.close();
|
|
|
|
}
|
2021-02-11 22:32:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
api.elements.define('converse-headlines-heading', HeadlinesHeading);
|