-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
113 lines (112 loc) · 3.19 KB
/
Copy pathpopup.js
File metadata and controls
113 lines (112 loc) · 3.19 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
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
function cleanup() {
showPopup("Clean Up", "Enter a range of rows to remove");
}
function showPopup(title, description) {
document.getElementById("popup-title").innerText = title;
document.getElementById("popup-description").innerText = description;
document.getElementById("popup-overlay").style.display = "flex";
document.getElementById("cleanerr").textContent = "";
document.getElementById("popup-input").value =
localStorage.getItem("cin") || "";
}
function hidePopup() {
document.getElementById("popup-overlay").style.display = "none";
}
document.getElementById("popup-ok").addEventListener("click", () => {
const input = document.getElementById("popup-input").value;
let errore = false;
const table = document.getElementById("scheduleTable");
let n = table.rows.length;
try {
const ranges = input.split(",").map((range) => range.trim());
if (!ranges.length || ranges.some((range) => range === "")) {
throwError("Invalid Input");
errore = true;
}
ranges.forEach((range) => {
if (range.includes("-")) {
const [start, end] = range.split("-").map(Number);
if (isNaN(start) || isNaN(end)) {
throwError("Invalid range");
errore = true;
}
if(start <= 0 || end >= n){
throwError("Index out of Bounds");
errore = true;
}
} else {
const num = Number(range);
if (isNaN(num)) {
throwError("Invalid number");
errore = true;
}
if(num <= 0 || num >= n){
throwError("Index out of Bounds");
errore = true;
}
}
});
} catch (error) {
throwError(error);
errore = true;
}
if (!errore) {
perform();
}
});
function perform() {
const input = document.getElementById("popup-input").value;
const ranges = input.split(",").map((range) => range.trim());
ranges.forEach((range) => {
if (range.includes("-")) {
const [start, end] = range.split("-").map(Number);
if (start <= end) {
for (let i = end; i >= start; i--) func(i);
} else {
for (let i = start; i >= end; i--) func(i);
}
} else {
const num = Number(range);
func(num);
}
});
for(let i = 1; i < document.getElementById("scheduleTable").rows.length; i++){
settb(i);
}
hidePopup();
localStorage.setItem("cin", input);
}
function throwError(err) {
document.getElementById("cleanerr").textContent = err;
}
function func(inp) {
if(inp > 0){
try{
const table = document.getElementById("scheduleTable");
table.deleteRow(inp);
}
catch(error){
console.log(error + "Laaaaaaaaaa");
}
}
}
function settb(val) {
var table = document.getElementById("scheduleTable");
if (!table) {
console.error("Table with ID 'table' not found.");
return;
}
var rows = table.getElementsByTagName('tr');
if (val < 0 || val >= rows.length) {
console.error("Invalid row index: " + val);
return;
}
var tr = rows[val];
var tds = tr.getElementsByTagName('td');
if (tds.length === 0) {
console.error("No <td> elements found in row " + val);
return;
}
tds[0].innerHTML = val;
}
document.getElementById("popup-cancel").addEventListener("click", hidePopup);