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, '
\n') template.innerHTML = response const card = template.content.firstChild cards_controller.bindSpecificCardDragAndDropEvents(card) this.outputTarget.appendChild(card) this.valueTarget.value = "" } } xhttp.send() } }