2020-12-06 20:42:12 +01:00
|
|
|
import log from "@converse/headless/log";
|
2021-02-24 09:51:37 +01:00
|
|
|
import tpl_muc_config_form from "./templates/muc-config-form.js";
|
2021-03-24 11:59:09 +01:00
|
|
|
import { CustomElement } from 'shared/components/element';
|
2020-12-06 20:42:12 +01:00
|
|
|
import { __ } from 'i18n';
|
2021-03-13 11:37:07 +01:00
|
|
|
import { _converse, api, converse } from "@converse/headless/core";
|
2020-12-06 20:42:12 +01:00
|
|
|
|
|
|
|
const { sizzle } = converse.env;
|
|
|
|
const u = converse.env.utils;
|
|
|
|
|
|
|
|
|
2021-03-13 11:37:07 +01:00
|
|
|
class MUCConfigForm extends CustomElement {
|
2020-12-06 20:42:12 +01:00
|
|
|
|
2021-03-13 11:37:07 +01:00
|
|
|
static get properties () {
|
|
|
|
return {
|
|
|
|
'jid': { type: String }
|
2020-12-06 20:42:12 +01:00
|
|
|
}
|
2021-03-13 11:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
connectedCallback () {
|
|
|
|
super.connectedCallback();
|
|
|
|
this.model = _converse.chatboxes.get(this.jid);
|
|
|
|
this.listenTo(this.model.features, 'change:passwordprotected', this.requestUpdate);
|
|
|
|
this.listenTo(this.model.session, 'change:config_stanza', this.requestUpdate);
|
|
|
|
this.getConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2020-12-06 20:42:12 +01:00
|
|
|
return tpl_muc_config_form({
|
2021-03-13 11:37:07 +01:00
|
|
|
'model': this.model,
|
|
|
|
'closeConfigForm': ev => this.closeForm(ev),
|
2020-12-06 20:42:12 +01:00
|
|
|
'submitConfigForm': ev => this.submitConfigForm(ev),
|
|
|
|
});
|
2021-03-13 11:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async getConfig () {
|
|
|
|
const iq = await this.model.fetchRoomConfiguration();
|
|
|
|
this.model.session.set('config_stanza', iq.outerHTML);
|
|
|
|
}
|
2020-12-06 20:42:12 +01:00
|
|
|
|
|
|
|
async submitConfigForm (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
const inputs = sizzle(':input:not([type=button]):not([type=submit])', ev.target);
|
|
|
|
const config_array = inputs.map(u.webForm2xForm).filter(f => f);
|
|
|
|
try {
|
|
|
|
await this.model.sendConfiguration(config_array);
|
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
const message =
|
|
|
|
__("Sorry, an error occurred while trying to submit the config form.") + " " +
|
|
|
|
__("Check your browser's developer console for details.");
|
|
|
|
api.alert('error', __('Error'), message);
|
|
|
|
}
|
|
|
|
await this.model.refreshDiscoInfo();
|
2021-03-13 11:37:07 +01:00
|
|
|
this.closeForm();
|
|
|
|
}
|
2020-12-06 20:42:12 +01:00
|
|
|
|
2021-03-13 11:37:07 +01:00
|
|
|
closeForm (ev) {
|
|
|
|
ev?.preventDefault?.();
|
|
|
|
this.model.session.set('view', null);
|
2020-12-06 20:42:12 +01:00
|
|
|
}
|
2021-03-13 11:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
api.elements.define('converse-muc-config-form', MUCConfigForm);
|
2020-12-06 20:42:12 +01:00
|
|
|
|
|
|
|
export default MUCConfigForm
|