Learning/.checkout/assets/controllers/column_controller.js

27 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-05-05 18:53:21 +00:00
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()
}
}