Skip to content

Commit 1d2ac61

Browse files
committed
Remove feature to edit/delete notes
1 parent 14f4422 commit 1d2ac61

File tree

3 files changed

+0
-96
lines changed

3 files changed

+0
-96
lines changed

build-a-rest-api-frontend/source_code_final/static/js/notes.js

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export class Notes {
55
this.allNoteLists = document.querySelectorAll(".note-list");
66
this.allNotes = document.querySelectorAll(".note-card");
77
this.activateAllCreateForms();
8-
this.activateAllControls();
98
}
109

1110
activateAllCreateForms() {
@@ -15,12 +14,6 @@ export class Notes {
1514
new NoteCreateForm(noteList, personID);
1615
});
1716
}
18-
19-
activateAllControls() {
20-
this.allNotes.forEach((noteCard) => {
21-
new NoteControl(noteCard);
22-
});
23-
}
2417
}
2518

2619
export class NoteCreateForm {
@@ -54,80 +47,6 @@ export class NoteCreateForm {
5447
const newNoteCard = document.querySelector(".note-card").cloneNode(true);
5548
newNoteCard.querySelector(".note-content").textContent = data.content;
5649
newNoteCard.setAttribute("data-note-id", data.id);
57-
new NoteControl(newNoteCard);
5850
noteList.insertBefore(newNoteCard, noteList.children[1]);
5951
}
6052
}
61-
62-
class NoteControl {
63-
constructor(noteCard) {
64-
this.noteCard = noteCard;
65-
this.noteElement = this.noteCard.querySelector(".note-content");
66-
this.noteControl = this.noteCard.querySelector(".note-control");
67-
this.noteID = this.noteCard.getAttribute("data-note-id");
68-
this.form = this.noteCard.querySelector("form");
69-
70-
this.editButton = this.noteCard.querySelector(".toggle-control");
71-
this.editButton.addEventListener("click", this.handleEditClick.bind(this));
72-
this.cancel = this.noteCard.querySelector("[data-action='cancel']");
73-
this.cancel.addEventListener("click", this.handleCancelClick.bind(this));
74-
this.delete = this.noteCard.querySelector("[data-action='delete']");
75-
this.delete.addEventListener("click", this.handleDeleteClick.bind(this));
76-
this.update = this.noteCard.querySelector("[data-action='update']");
77-
this.update.addEventListener("click", this.handleUpdateClick.bind(this));
78-
79-
this.fillControlForm();
80-
}
81-
82-
handleEditClick(event) {
83-
event.preventDefault();
84-
this.noteCard.classList.add("editing");
85-
this.noteElement.classList.add("hidden");
86-
this.editButton.classList.add("hidden");
87-
this.noteControl.classList.remove("hidden");
88-
}
89-
90-
handleCancelClick(event) {
91-
event.preventDefault();
92-
this.noteCard.classList.remove("editing");
93-
this.noteElement.classList.remove("hidden");
94-
this.editButton.classList.remove("hidden");
95-
this.noteControl.classList.add("hidden");
96-
}
97-
98-
handleDeleteClick(event) {
99-
event.preventDefault();
100-
const endpoint = "/api/notes/" + this.noteID;
101-
sendForm(this.form, "DELETE", endpoint, this.removeNoteFromList);
102-
}
103-
104-
removeNoteFromList(data, inputForm) {
105-
const noteCard = inputForm.closest(".note-card");
106-
if (window.confirm("Do you really want to remove this note?")) {
107-
noteCard.remove();
108-
}
109-
}
110-
111-
handleUpdateClick(event) {
112-
event.preventDefault();
113-
const endpoint = "/api/notes/" + this.noteID;
114-
sendForm(this.form, "PUT", endpoint, this.updateNoteInList);
115-
this.cancel.click();
116-
}
117-
118-
updateNoteInList(rawData, inputForm) {
119-
const data = JSON.parse(rawData);
120-
const noteContent = inputForm
121-
.closest(".note-card")
122-
.querySelector(".note-content");
123-
noteContent.textContent = data.content;
124-
}
125-
126-
fillControlForm() {
127-
const noteContent = this.noteElement.textContent;
128-
this.form.querySelector("[name='id']").setAttribute("value", this.noteID);
129-
this.form
130-
.querySelector("[name='content']")
131-
.setAttribute("value", noteContent);
132-
}
133-
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
<li class="note-card" data-note-id="{{ note.id }}">
2-
{% include "_note_control.html" %}
32
<div class="note-content">{{ note.content }}</div>
43
</li>

build-a-rest-api-frontend/source_code_final/templates/_note_control.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)