-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.js
More file actions
95 lines (79 loc) · 2.14 KB
/
table.js
File metadata and controls
95 lines (79 loc) · 2.14 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
class Table {
tbody;
rows = [];
constructor(name, tableBody, removeButton, copyPlanAButton) {
this.name = name;
this.tbody = tableBody;
this.removeButton = removeButton;
this.copyPlanAButton = copyPlanAButton;
}
add() {
let row = new Row(this.tbody, this);
this.rows.push(row);
const checkIncome = document.getElementById("flexSwitchCheckIncome");
if (checkIncome) {
checkIncome.checked = true;
}
const checkConsumption = document.getElementById("flexSwitchCheckConsumption");
if (checkConsumption) {
checkConsumption.checked = true;
}
const checkIncomeB = document.getElementById("flexSwitchCheckIncomeB");
if (checkIncomeB) {
checkIncomeB.checked = true;
}
const checkConsumptionB = document.getElementById("flexSwitchCheckConsumptionB");
if (checkConsumptionB) {
checkConsumptionB.checked = true;
}
}
saveData() {
let data = this.getData();
localStorage.setItem(this.name, JSON.stringify(data));
this.removeButton.disabled = data.length === 0;
}
fillData(data) {
if (!data) {
let store = localStorage.getItem(this.name);
console.log(store);
if (store) {
data = JSON.parse(store);
} else {
return;
}
}
for (let item of data) {
let row = new Row(this.tbody, this);
row.name = item.name;
row.price = item.price;
row.quantity = item.quantity;
row.amount = item.amount;
row.isShowAmountInput = item.isAmount;
row.timeLineName = item.timeline;
row.setInputsState(false);
this.rows.push(row);
}
this.removeButton.disabled = data.length === 0;
}
getData() {
let result = [];
// this.rows.map();
for (let row of this.rows) {
if (row.status === "Active") {
result.push(
{
name: row.name,
isAmount: row.isShowAmountInput,
price: row.price,
quantity: row.quantity,
amount: row.amount,
timeline: row.timeLineName
});
}
}
return result;
}
remove() {
localStorage.setItem(this.name);
}
}