2021-01-06 17:06:01 +01:00
|
|
|
import tpl_headline_panel from './templates/panel.js';
|
2020-12-08 12:54:14 +01:00
|
|
|
import { ElementView } from '@converse/skeletor/src/element.js';
|
2020-12-08 09:43:09 +01:00
|
|
|
import { __ } from 'i18n';
|
2021-01-06 17:09:47 +01:00
|
|
|
import { _converse, api } from '@converse/headless/core';
|
2020-12-08 09:43:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* View which renders headlines section of the control box.
|
|
|
|
* @class
|
|
|
|
* @namespace _converse.HeadlinesPanel
|
|
|
|
* @memberOf _converse
|
|
|
|
*/
|
2020-12-08 12:54:14 +01:00
|
|
|
export class HeadlinesPanel extends ElementView {
|
|
|
|
events = {
|
2020-12-08 09:43:09 +01:00
|
|
|
'click .open-headline': 'openHeadline'
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2020-12-08 09:43:09 +01:00
|
|
|
|
|
|
|
initialize () {
|
2021-01-06 17:09:47 +01:00
|
|
|
this.model = _converse.chatboxes;
|
2020-12-08 09:43:09 +01:00
|
|
|
this.listenTo(this.model, 'add', this.renderIfHeadline);
|
|
|
|
this.listenTo(this.model, 'remove', this.renderIfHeadline);
|
|
|
|
this.listenTo(this.model, 'destroy', this.renderIfHeadline);
|
|
|
|
this.render();
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2020-12-08 09:43:09 +01:00
|
|
|
|
|
|
|
toHTML () {
|
|
|
|
return tpl_headline_panel({
|
|
|
|
'heading_headline': __('Announcements'),
|
|
|
|
'headlineboxes': this.model.filter(m => m.get('type') === _converse.HEADLINES_TYPE),
|
|
|
|
'open_title': __('Click to open this server message')
|
|
|
|
});
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2020-12-08 09:43:09 +01:00
|
|
|
|
|
|
|
renderIfHeadline (model) {
|
|
|
|
return model && model.get('type') === _converse.HEADLINES_TYPE && this.render();
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
2020-12-08 09:43:09 +01:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
openHeadline (ev) { // eslint-disable-line class-methods-use-this
|
2020-12-08 09:43:09 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
const jid = ev.target.getAttribute('data-headline-jid');
|
|
|
|
const chat = _converse.chatboxes.get(jid);
|
|
|
|
chat.maybeShow(true);
|
|
|
|
}
|
2020-12-08 12:54:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
api.elements.define('converse-headlines-panel', HeadlinesPanel);
|