-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
214 lines (198 loc) · 6.92 KB
/
script.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// VARIABLES
// ADD TASK
const addTaskButton = window.document.getElementById("addTaskButtonId");
const inputTaskTitle = window.document.getElementById("inputFieldId");
// TASKS EVENTELISTENER
addTaskButton.addEventListener("click", startTaskAddition);
addTaskButton.addEventListener("click", ajaxRequest);
// KEYBOARD ENTER - ADD TASK
inputTaskTitle.addEventListener("keyup", (e) => {
if (e.keyCode === 13) {
startTaskAddition();
}
});
// TASKS FIELDS
const toDoTasks = document.getElementById("divToDoId");
const doingTasks = document.getElementById("divDoingId");
const doneTasks = document.getElementById("divDoneId");
//TASKS ARRAY
var tasksArray = [];
//FUNCTIONS
//ONLOAD REMOVER TODAS PROPRIEDADES DO ARRAY
window.onload = function () {
tasksArray = [];
};
function startTaskAddition() {
let varTaskStringRight = inputTaskTitle.value
.trim()
.normalize("NFD")
.replace(/([\u0300-\u036f]|[^0-9a-zA-Z])/g, "");
criteriaToAdd(varTaskStringRight);
}
// criteria to add
function criteriaToAdd(varTaskStringRight) {
if (inputTaskTitle.value == "") {
alert("ESCREVA UM TÍTULO");
} else if (verifyCharacteres(inputTaskTitle.value) == false) {
alert("INSIRA APENAS NÚMEROS OU LETRAS");
} else if (tasksArray.indexOf(varTaskStringRight) > -1) {
alert("TÍTULO JÁ EXISTE, ESCOLHA OUTRO");
} else if (tasksArray.indexOf(varTaskStringRight) === -1) {
addTask(varTaskStringRight);
}
}
// APENAS NUMEROS E LETRAS , LETRAS ACENTUADAS
function verifyCharacteres(taskString) {
var letters = /^[0-9a-záàâãéèêíïóôõöúçñ ]+$/i;
if (taskString.match(letters)) {
return true;
} else {
return false;
}
}
// ADD A TASK
function addTask(varTaskStringRight) {
tasksArray.push(varTaskStringRight);
createTask(inputTaskTitle.value, varTaskStringRight);
inputTaskTitle.value = "";
}
// Ajax Request
function ajaxRequest() {
console.log("AJAXRequest");
}
// CREATE AN ELEMENT -FUNCTION
function createTask(taskString, varTaskStringRight) {
let div = document.createElement("div");
let h4 = document.createElement("h4");
let spanDots = document.createElement("span");
let spanMore = document.createElement("span");
let textarea = document.createElement("textarea");
let img = document.createElement("img");
let imgCloseButton = document.createElement("img");
let imgCheckButton = document.createElement("img");
let divNextStepButton = document.createElement("div");
let divDeleteButton = document.createElement("div");
let divDeleteButtonClose = document.createElement("div");
let divNextStepButtonClose = document.createElement("div");
toDoTasks.appendChild(div);
div.appendChild(h4);
div.appendChild(spanDots);
spanDots.appendChild(divDeleteButtonClose);
divDeleteButtonClose.appendChild(imgCloseButton);
spanDots.appendChild(divNextStepButtonClose);
divNextStepButtonClose.appendChild(imgCheckButton);
div.appendChild(spanMore);
spanMore.appendChild(textarea);
spanMore.appendChild(divNextStepButton);
spanMore.appendChild(divDeleteButton);
div.appendChild(img);
h4.innerText = taskString;
divDeleteButton.innerText = "DELETE";
divNextStepButton.innerText = "NEXT STEP";
div.setAttribute("class", "field-Criteria taskDiv");
div.setAttribute("name", "task");
div.setAttribute("id", `taskDivId${varTaskStringRight}`);
div.setAttribute("draggable", "true");
div.setAttribute("ondragstart", "drag(event)");
h4.setAttribute("id", `${varTaskStringRight}`);
spanDots.setAttribute("id", `dots${varTaskStringRight}`);
spanDots.setAttribute("class", "dotsClass");
divDeleteButtonClose.setAttribute(
"class",
"field-Criteria deleteButtonCloseClass"
);
divDeleteButtonClose.setAttribute(
"onclick",
`deleteTask(taskDivId${varTaskStringRight}, ${varTaskStringRight})`
);
imgCloseButton.setAttribute("src", "images/close.png");
imgCloseButton.setAttribute("class", "imgCloseButtonClass");
imgCloseButton.setAttribute("draggable", "false");
divNextStepButtonClose.setAttribute(
"class",
"field-Criteria nextStepButtonCheckClass"
);
divNextStepButtonClose.setAttribute(
"onclick",
`nextStepTask(taskDivId${varTaskStringRight}, ${varTaskStringRight})`
);
imgCheckButton.setAttribute("src", "images/check.png");
imgCheckButton.setAttribute("class", "imgCheckButtonClass");
imgCheckButton.setAttribute("draggable", "false");
spanMore.setAttribute("id", `more${varTaskStringRight}`);
spanMore.setAttribute("class", "moreClass");
textarea.setAttribute("name", "taskDetailsName");
textarea.setAttribute("id", "taskDetailsId");
textarea.setAttribute("cols", "30");
textarea.setAttribute("rows", "10");
textarea.setAttribute("maxlength", "500");
textarea.setAttribute("placeholder", "ADD TASKS DETAILS");
textarea.setAttribute("wrap", "on");
divDeleteButton.setAttribute("class", "field-Criteria deleteButtonClass");
divDeleteButton.setAttribute("id", `deleteId${varTaskStringRight}`);
divDeleteButton.setAttribute(
"onclick",
`deleteTask(taskDivId${varTaskStringRight}, ${varTaskStringRight})`
);
divNextStepButton.setAttribute("class", "field-Criteria nextStepButtonClass");
divNextStepButton.setAttribute("id", `nextStepId${varTaskStringRight}`);
divNextStepButton.setAttribute(
"onclick",
`nextStepTask(taskDivId${varTaskStringRight}, ${varTaskStringRight})`
);
img.setAttribute("class", "arrowDown");
img.setAttribute("id", `arrowDownId${varTaskStringRight}`);
img.setAttribute("src", "images/arrow-down.png");
img.setAttribute("alt", "Arrow Down");
img.setAttribute("draggable", "false");
img.setAttribute(
"onclick",
`details(dots${varTaskStringRight}, more${varTaskStringRight}, arrowDownId${varTaskStringRight})`
);
}
// SHOWMORE DETAILS
function details(dotsId, moreId, imgId) {
if (dotsId.style.display === "none") {
dotsId.style.display = "inline";
imgId.className = "arrowDown";
moreId.style.display = "none";
} else {
dotsId.style.display = "none";
imgId.className = "arrowUp";
moreId.style.display = "inline";
}
}
// NEXT STEP BUTTON
function nextStepTask(taskDivId, taskTitle) {
if (taskDivId.parentNode.id == "divToDoId") {
doingTasks.appendChild(taskDivId);
} else if (taskDivId.parentNode.id == "divDoingId") {
doneTasks.appendChild(taskDivId);
} else {
deleteTask(taskDivId, taskTitle);
}
}
// DELETE BUTTON
function deleteTask(taskDivId, taskTitle) {
taskDivId.remove();
removeArrayItem(taskTitle);
}
function removeArrayItem(taskTitle) {
if (typeof(taskTitle) == "number") {
tasksArray.splice(tasksArray.indexOf(taskTitle), 1);
} else if(typeof(taskTitle.textContent) == "string") {
tasksArray.splice(tasksArray.indexOf(taskTitle.textContent), 1);
}
}
// DRAG AND DROP
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev, el) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
el.appendChild(document.getElementById(data));
}