-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
70 lines (61 loc) · 2.1 KB
/
app.js
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
var modal = document.querySelector(".modal");
var closeButton = document.querySelector(".close-button");
let currentModalItem = '';
function toggleModal(item) {
currentModalItem ? currentModalItem = '' : currentModalItem = item;
modal.classList.toggle("show-modal");
}
function windowOnClick(event) {
if (event.target === modal) {
toggleModal();
}
}
function hideForm() {
document.getElementById("duty-form").style.display = 'none';
}
function showForm() {
document.getElementById("duty-form").style.display = 'block';
}
function saveDuty() {
let duty;
document.getElementsByName('duty-radio').forEach(el => {
if(el.checked) {
duty = el.id;
}
})
if (duty !== "day-off") {
const form = document.forms.namedItem('duty-form');
const data = new FormData(form);
const start = `${data.get('start-hours')}:${data.get('start-minutes')}`;
const finish = `${data.get('finish-hours')}:${data.get('finish-minutes')}`;
addDuty(currentModalItem, {duty, start, finish});
} else {
addDuty(currentModalItem, {duty});
}
toggleModal();
}
function addDuty(dayId, data) {
const day = document.getElementById(dayId);
const timeHtml = `<p>${data.start}-${data.finish}</p>`;
const sufix = '-empty';
let htmlString = '';
const onClickAttr = 'onclick="removeDuty(event)"';
if (data.duty === 'day'){
htmlString = `<i class="far fa-sun"></i>${timeHtml}<i class="fas fa-times"${onClickAttr}></i>`;
} else if (data.duty === 'night') {
htmlString = `<i class="far fa-moon"></i>${timeHtml}<i class="fas fa-times"${onClickAttr}></i>`;
} else {
htmlString = `<i class="far fa-grin-beam"></i>Have fun!<i class="fas fa-times"${onClickAttr}></i>`;
}
const div = document.createElement("div");
const emptyMessage = document.getElementById(dayId + sufix);
const dutyClass = data.duty !== 'day-off' ? `${data.duty}-duty`: 'day-off';
div.classList.add(dutyClass);
div.innerHTML = htmlString.trim();
emptyMessage && emptyMessage.remove();
day.insertAdjacentElement('afterbegin', div);
}
function removeDuty(event) {
const nodes = event.path;
nodes[1].remove();
}