Learning/.checkout/assets/controllers/column_controller.js
2023-05-05 20:53:21 +02:00

27 lines
No EOL
1.1 KiB
JavaScript

import { Controller } from '@hotwired/stimulus';
import cards_controller from './cards_controller';
export default class extends Controller {
static targets = ['value', 'output']
create_card(){
var value = this.valueTarget.value.replace(/(?:\r\n|\r|\n)/g, '%5Cr%5Cn')
if(value.length == 0){
return
}
const xhttp = new XMLHttpRequest()
xhttp.open("GET", location.origin + `/kanban/api/card/create/${this.element.id}/${value}`, true)
xhttp.onreadystatechange = (ev) => {
if (xhttp.readyState === XMLHttpRequest.DONE) {
var template = document.createElement('template')
var response = xhttp.responseText.trim();
response = response.replace(/(?:\\r\\n|\\r|\\n)/g, '<br>\n')
template.innerHTML = response
const card = template.content.firstChild
cards_controller.bindSpecificCardDragAndDropEvents(card)
this.outputTarget.appendChild(card)
this.valueTarget.value = ""
}
}
xhttp.send()
}
}