This commit is contained in:
P-A
2026-02-06 23:37:58 +01:00
parent 16393b221f
commit 0f28082e46
2 changed files with 23 additions and 3 deletions

View File

@@ -61,6 +61,7 @@ class HomeworkPage extends HomeworkElement {
this.sourceLanguage.setAttribute("id", sourceLanguageTextId)
this.targetLanguage.setAttribute("id", targetLanguageTextId)
this.content = this.querySelector('#content')
this.content.addEventListener("delete", this.deleteTask.bind(this))
this.newButton = this.querySelector('#new')
this.newButton.addEventListener("click", this.newVocabulary.bind(this))
this.saveButton = this.querySelector('#save')
@@ -72,14 +73,14 @@ class HomeworkPage extends HomeworkElement {
connectedCallback() {
console.log("Page of type " + this.type + " added to session")
if(this.type == HomeworkTypes.VOCABULARY_ENGLISH) {
const row = new HomeworkVocabularyTask()
const row = new HomeworkVocabularyTask(crypto.randomUUID())
this.content.append(row)
}
}
newVocabulary() {
if(this.type == HomeworkTypes.VOCABULARY_ENGLISH) {
const row = new HomeworkVocabularyTask()
const row = new HomeworkVocabularyTask(crypto.randomUUID())
this.content.append(row)
}
}
@@ -91,5 +92,18 @@ class HomeworkPage extends HomeworkElement {
trainVocabulary() {
console.log("Train!!")
}
deleteTask(event) {
const tasks = this.content.querySelectorAll("homework-vocabulary-task")
if(tasks.length > 1) {
tasks.forEach((task) => {
if(event.detail.id == task.getId()) {
alert(task.getId())
task.remove()
}
})
}
}
}
customElements.define('homework-page', HomeworkPage)