peertube-plugin-livechat/conversejs/custom/plugins/tasks/muc-task-lists-view.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-04-30 07:21:18 +00:00
import { CustomElement } from 'shared/components/element.js'
2024-04-30 16:30:44 +00:00
import { api } from '@converse/headless/core'
2024-04-30 15:11:10 +00:00
import tplMucTaskLists from './templates/muc-task-lists'
import { __ } from 'i18n'
2024-04-30 07:21:18 +00:00
import './styles/muc-task-lists.scss'
2024-04-30 07:21:18 +00:00
export default class MUCTaskListsView extends CustomElement {
static get properties () {
return {
model: { type: Object, attribute: true },
create_tasklist_error_message: { type: String, attribute: false }
2024-04-30 07:21:18 +00:00
}
}
async initialize () {
2024-05-03 13:03:24 +00:00
this.create_tasklist_error_message = ''
2024-04-30 15:11:10 +00:00
if (!this.model) {
return
}
2024-04-30 16:30:44 +00:00
// Adding or removing a new task list: we must update.
2024-04-30 15:11:10 +00:00
this.listenTo(this.model, 'add', () => this.requestUpdate())
2024-04-30 16:30:44 +00:00
this.listenTo(this.model, 'remove', () => this.requestUpdate())
2024-04-30 07:21:18 +00:00
}
render () {
return tplMucTaskLists(this, this.model)
}
async submitCreateTaskList (ev) {
ev.preventDefault()
2024-05-03 13:03:24 +00:00
const name = ev.target.name.value.trim()
if (this.create_tasklist_error_message) {
this.create_tasklist_error_message = ''
}
if ((name ?? '') === '') { return }
try {
2024-05-03 13:03:24 +00:00
this.querySelectorAll('input[type=submit]').forEach(el => {
el.setAttribute('disabled', true)
el.classList.add('disabled')
})
await this.model.createTaskList({
name
})
2024-05-03 13:03:24 +00:00
this.querySelector('input[name=name]').value = ''
} catch (err) {
console.error(err)
// eslint-disable-next-line no-undef
this.create_tasklist_error_message = __(LOC_task_list_create_error)
2024-05-03 13:03:24 +00:00
} finally {
this.querySelectorAll('input[type=submit]').forEach(el => {
el.removeAttribute('disabled')
el.classList.remove('disabled')
})
}
2024-04-30 07:21:18 +00:00
}
}
api.elements.define('livechat-converse-muc-task-lists', MUCTaskListsView)