-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditTask.js
More file actions
83 lines (67 loc) · 2.44 KB
/
Copy patheditTask.js
File metadata and controls
83 lines (67 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const updateTitleForm = document.getElementById("update-title-form");
const titleInput = document.getElementById("title");
const updateTitleButton = document.getElementById("update-title-button");
const updateTitleLoader = document.querySelector(".update-title-loader");
const updateDescriptionForm = document.getElementById("update-description-form");
const descriptionInput = document.getElementById("description");
const updateDescriptionButton = document.getElementById("update-description-button");
const updateDescriptionLoader = document.querySelector(".update-description-loader");
const user = JSON.parse(loggedJSON);
updateTitleForm.addEventListener("submit", (e) => {
e.preventDefault();
const title = titleInput.value;
const initTitle = {
method: "PUT",
body: JSON.stringify({ taskId, title }),
headers: {
"Authorization": `Bearer ${user.token}`,
"Content-Type": "application/json",
},
};
updateTitleButton.style.display = "none";
updateTitleLoader.classList.add("show");
fetch("/update-task-title", initTitle)
.then((res) => {
if (res.ok) {
window.location.href = `/tasks/${user.userId}`;
updateTitleLoader.classList.remove("show");
updateTitleButton.style.display = "block";
} else {
return Promise.reject(res);
}
})
.catch((err) => {
updateTitleLoader.classList.remove("show");
updateTitleButton.style.display = "block";
err.json().then((data) => alert(data.message));
});
});
updateDescriptionForm.addEventListener("submit", (e) => {
e.preventDefault();
const description = descriptionInput.value;
const initDescription = {
method: "PUT",
body: JSON.stringify({ taskId, description }),
headers: {
"Authorization": `Bearer ${user.token}`,
"Content-Type": "application/json",
},
};
updateDescriptionButton.style.display = "none";
updateDescriptionLoader.classList.add("show");
fetch("/update-task-description", initDescription)
.then((res) => {
if (res.ok) {
window.location.href = `/tasks/${user.userId}`;
updateDescriptionLoader.classList.remove("show");
updateDescriptionButton.style.display = "block";
} else {
return Promise.reject(res);
}
})
.catch((err) => {
updateDescriptionLoader.classList.remove("show");
updateDescriptionButton.style.display = "block";
err.json().then((data) => alert(data.message));
});
});