2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-05-12 16:45:51 +00:00
|
|
|
import BaseModal from 'plugins/modal/modal.js'
|
|
|
|
import tplPickTaskList from './templates/pick-task-list.js'
|
2024-07-11 15:53:50 +00:00
|
|
|
import { api } from '@converse/headless'
|
2024-05-12 16:45:51 +00:00
|
|
|
import { __ } from 'i18n'
|
|
|
|
|
|
|
|
export default class PickTaskListModal extends BaseModal {
|
|
|
|
constructor (options) {
|
|
|
|
super(options)
|
|
|
|
this.muc = options.muc
|
|
|
|
this.message = options.message
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize () {
|
|
|
|
super.initialize(...arguments)
|
|
|
|
this.addEventListener('shown.bs.modal', () => {
|
|
|
|
this.querySelector('select[name="tasklist"]').focus()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
getModalTitle () {
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
return __(LOC_task_list_pick_title)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderModal () {
|
|
|
|
return tplPickTaskList(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
onPick (ev) {
|
|
|
|
ev.preventDefault()
|
|
|
|
const tlId = ev.target?.tasklist?.value
|
|
|
|
if (!tlId) { return }
|
|
|
|
|
|
|
|
const tasklists = this.muc.tasklists
|
|
|
|
if (!tasklists) { return }
|
|
|
|
|
|
|
|
const tasklist = tasklists.get(tlId)
|
|
|
|
if (!tasklist) { return }
|
|
|
|
|
|
|
|
const message = this.message
|
|
|
|
tasklist.createTask({
|
|
|
|
name: message.get('nick'),
|
|
|
|
description: message.get('body')
|
|
|
|
}).then(
|
|
|
|
() => this.modal.hide(),
|
|
|
|
console.error
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
api.elements.define('livechat-converse-pick-task-list-modal', PickTaskListModal)
|