-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsheetsHandling.js
More file actions
153 lines (131 loc) · 4.83 KB
/
sheetsHandling.js
File metadata and controls
153 lines (131 loc) · 4.83 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
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
let sheetAddBtn = document.querySelector(".icon-add");
let sheetContainer = document.querySelector(".sheet-tab-container");
let leftScroll = document.querySelector(".icon-left-scroll");
let rightScroll = document.querySelector(".icon-right-scroll");
leftScroll.addEventListener("click", () => {
sheetContainer.scrollLeft -= 50;
})
rightScroll.addEventListener("click", () => {
sheetContainer.scrollLeft += 50;
})
sheetAddBtn.addEventListener("click", () =>{
let newSheet = document.createElement("div");
let allSheets = document.querySelectorAll(".sheet-tab");
newSheet.setAttribute("id",allSheets.length);
newSheet.setAttribute("class","sheet-tab");
newSheet.innerText = "Sheet-" + (allSheets.length+1) ;
sheetContainer.appendChild(newSheet);
newSheet.scrollIntoView();
createSheetDB();
handleSheetActiveness(newSheet);
newSheet.click();
handleSheetRemoval(newSheet);
})
function sheetOpenHandler(){
let newSheet = document.createElement("div");
let allSheets = document.querySelectorAll(".sheet-tab");
newSheet.setAttribute("id",allSheets.length);
newSheet.setAttribute("class","sheet-tab");
newSheet.innerText = "Sheet-" + (allSheets.length+1) ;
sheetContainer.appendChild(newSheet);
newSheet.scrollIntoView();
newSheet.click();
handleSheetActiveness(newSheet);
handleSheetRemoval(sheet);
}
function handleSheetRemoval(sheet){
sheet.addEventListener("mousedown", (e) => {
// Right Click
if(e.button !== 2) return;
let allSheetFolders = document.querySelectorAll(".sheet-tab");
if(allSheetFolders.length == 1){
alert("You need to have atleast one sheet");
return;
}
let response = confirm("Your sheet will be deleted permanently, Are you sure ?")
if(response == false) return;
let sheetIdx = Number(sheet.getAttribute("id"));
sheetDB.splice(sheetIdx, 1);
handleSheetUIRemoval(sheet);
db = sheetDB[0];
handleSheetProperties();
})
}
function handleSheetUIRemoval(sheet){
sheet.remove();
let allSheetFolders = document.querySelectorAll(".sheet-tab");
for(let i = 0 ; i < allSheetFolders.length; i++){
allSheetFolders[i].setAttribute("id", i);
allSheetFolders[i].innerText = `Sheet ${i+1}`;
allSheetFolders[i].style.backgroundColor = "transparent";
}
allSheetFolders[0].style.backgroundColor = "lightgray";
}
function createSheetDB(){
let db = []
for(let i = 0; i < 100; i++){
let rowArr = []
for(let j = 0; j < 100 ; j++){
let cellObj = {
color: "black",
backgroundColor: "white",
fontFamily: "Arial",
fontSize: 14,
halign: "left",
italic: false,
underline: false,
bold: false,
value:"",
formula: "",
children: []
}
rowArr.push(cellObj)
}
db.push(rowArr)
}
// console.log(db);
sheetDB.push(db)
// console.log(sheetDB);
}
function handleSheetActiveness(sheet){
sheet.addEventListener("click", (e) => {
let sheetIdx = Number(sheet.getAttribute("id"));
handleSheetDB(sheetIdx);
handleSheetProperties();
handleSheetUI(sheet);
// console.log(db);
})
}
function handleSheetDB(sheetIdx){
db = sheetDB[sheetIdx];
// console.log(db);
}
function handleSheetProperties(){
for(let i = 0 ; i < 100 ; i++){
for(let j = 0 ; j < 100 ; j++){
let cellObject = db[i][j];
let tobeChangedCell = document.querySelector(`.input-cell[rId='${i}'][cId='${j}']`);
// console.log(cellObject.value);
// console.log(tobeChangedCell)
tobeChangedCell.innerText = cellObject.value;
tobeChangedCell.style.color = cellObject.color;
tobeChangedCell.style.fontWeight = cellObject.fontWeight;
tobeChangedCell.style.backgroundColor = cellObject.backgroundColor;
tobeChangedCell.style.fontFamily = cellObject.fontFamily;
tobeChangedCell.style.textAlign = cellObject.halign;
tobeChangedCell.style.textDecoration = cellObject.underline == false ? "none" : "underline";
tobeChangedCell.style.fontStyle = cellObject.italic == false ? "normal" : "italic";
tobeChangedCell.style.fontSize = cellObject.fontSize;
}
}
let firstCell = document.querySelector(".input-cell");
firstCell.click();
firstCell.focus();
}
function handleSheetUI(sheet){
let allSheetFolders = document.querySelectorAll(".sheet-tab");
for (let i = 0; i < allSheetFolders.length; i++) {
allSheetFolders[i].style.backgroundColor = "transparent";
}
sheet.style.backgroundColor = "lightgray";
}