-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
208 lines (181 loc) · 6.93 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
let index = 0;
ref_event();
// updatelite();
function updatelite() {
let tableBody = document.getElementById("tableBody");
itemJsonArraystr = localStorage.getItem('itemsJson');
itemJsonArray = JSON.parse(itemJsonArraystr);
let str = "";
// console.log(itemJsonArray);
itemJsonArray.forEach((element) => {
str += `<tr>
<td class="dt" data-lable="index">${element['index']}</td>
<td class="dt" data-lable="time">${element['time']}</td>
<td class="dt" data-lable="mon">${element['mon']}</td>
<td class="dt" data-lable="tue"> ${element['tue']}</td>
<td class="dt" data-lable="wed"> ${element['wed']}</td>
<td class="dt" data-lable="thu"> ${element['thu']}</td>
<td class="dt" data-lable="fri"> ${element['fri']}</td>
<td class="dt" data-lable="sat"> ${element['sat']}</td>
<td class="dt" data-lable="sun"> ${element['sun']}</td>
<td class="dt dlt" data-lable="delete"><a onclick="deleted(${element['index']});" class="btntp">delete</a></td>
</tr>`
});
tableBody.innerHTML = str;
}
function updatelite_view() {
let tableBody = document.getElementById("tableBody");
itemJsonArraystr = localStorage.getItem('itemsJson');
itemJsonArray = JSON.parse(itemJsonArraystr);
let str = "";
// console.log(itemJsonArray);
itemJsonArray.forEach((element) => {
str += `<tr>
<td class="dt" data-lable="index">${element['index']}</td>
<td class="dt" data-lable="time">${element['time']}</td>
<td class="dt" data-lable="mon">${element['mon']}</td>
<td class="dt" data-lable="tue"> ${element['tue']}</td>
<td class="dt" data-lable="wed"> ${element['wed']}</td>
<td class="dt" data-lable="thu"> ${element['thu']}</td>
<td class="dt" data-lable="fri"> ${element['fri']}</td>
<td class="dt" data-lable="sat"> ${element['sat']}</td>
<td class="dt" data-lable="sun"> ${element['sun']}</td>
</tr>`
});
tableBody.innerHTML = str;
}
function update()
{
index = index + 1;
let start_time_hour = document.getElementById('time_box_start_hour').value;
let start_time_min = document.getElementById('time_box_start_min').value;
let start_am_pm = document.getElementById('am_pm_start').value;
let end_am_pm = document.getElementById('am_pm_end').value;
let end_time_hour = document.getElementById('time_box_end_hour').value;
let end_time_min = document.getElementById('time_box_end_min').value;
let time = start_time_hour + ":" + start_time_min + " " + start_am_pm + " to " + end_time_hour + ":" + end_time_min + " " + end_am_pm;
// let time = document.getElementById('time').value;
let sub = document.getElementById('sub').value;
let mon = document.getElementById('mon').checked;
let tue = document.getElementById('tue').checked;
let wed = document.getElementById('wed').checked;
let thu = document.getElementById('thu').checked;
let fri = document.getElementById('fri').checked;
let sat = document.getElementById('sat').checked;
let sun = document.getElementById('sun').checked;
let tps_array = [mon, tue, wed, thu, fri, sat, sun];
let tps_name = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
console.log(tps_array)
// console.log(mon)
if (localStorage.getItem('itemsJson') == null) {
itemJsonArray = [];
tps = { 'index': '', 'time': '', 'mon': '', 'tue': '', 'wed': '', 'thu': '', 'fri': '', 'sat': '', 'sun': '' }
// console.log(tps);
tps.index = index;
tps.time = time;
for (i = 0; i < 7; i++) {
if (tps_array[i]) {
tps[tps_name[i]] = sub;
}
}
// tps[day] = sub;
itemJsonArray.push(tps);
console.log(tps);
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray));
}
else {
let kk = 0
itemJsonArraystr = localStorage.getItem('itemsJson');
itemJsonArray = JSON.parse(itemJsonArraystr);
console.log("update", itemJsonArray);
tps = { 'index': '', 'time': '', 'mon': '', 'tue': '', 'wed': '', 'thu': '', 'fri': '', 'sat': '', 'sun': '' };
itemJsonArray.forEach(value => {
if (value.time == time) {
kk = kk + 1;
index = index - 1;
for (i = 0; i < 7; i++) {
if (tps_array[i]) {
value[tps_name[i]] = sub;
}
}
}
})
if (kk == 0) {
for (i = 0; i < 7; i++) {
if (tps_array[i]) {
tps[tps_name[i]] = sub;
}
}
tps.time = time;
tps.index = index;
itemJsonArray.push(tps);
}
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray));
}
let tableBody = document.getElementById("tableBody");
itemJsonArraystr = localStorage.getItem('itemsJson');
itemJsonArray = JSON.parse(itemJsonArraystr);
let str = "";
itemJsonArray.forEach((element) => {
str += `<tr>
<td class="dt" data-lable="index">${element['index']}</td>
<td class="dt" data-lable="time">${element['time']}</td>
<td class="dt" data-lable="mon">${element['mon']}</td>
<td class="dt" data-lable="tue"> ${element['tue']}</td>
<td class="dt" data-lable="wed"> ${element['wed']}</td>
<td class="dt" data-lable="thu"> ${element['thu']}</td>
<td class="dt" data-lable="fri"> ${element['fri']}</td>
<td class="dt" data-lable="sat"> ${element['sat']}</td>
<td class="dt" data-lable="sun"> ${element['sun']}</td>
<td class="dt dlt" data-lable="delete"><a onclick="deleted(${element['index']});" class="btntp">delete</a></td>
</tr>`
})
tableBody.innerHTML = str;
};
function ref_event() {
var i = 1;
itemJsonArraystr = localStorage.getItem('itemsJson');
itemJsonArray = JSON.parse(itemJsonArraystr);
// console.log(itemJsonArray==null)
if (itemJsonArray == null) {
index = 0;
}
else {
itemJsonArray.forEach((element) => {
element['index'] = i;
i += 1;
})
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray));
index = i - 1;
}
// console.log(itemJsonArray);
}
function cleared() {
localStorage.removeItem('itemsJson');
index = 0;
updatelite();
}
function sort_index() {
var i = 1;
itemJsonArraystr = localStorage.getItem('itemsJson');
itemJsonArray = JSON.parse(itemJsonArraystr);
itemJsonArray.forEach((element) => {
element['index'] = i;
i += 1;
})
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray));
// console.log(itemJsonArray);
index--;
updatelite();
}
function deleted(ind) {
console.log(ind + "del req");
itemJsonArraystr = localStorage.getItem('itemsJson');
itemJsonArray = JSON.parse(itemJsonArraystr);
itemJsonArray.splice(ind - 1, 1);
// console.log(itemJsonArray);
localStorage.setItem('itemsJson', JSON.stringify(itemJsonArray));
sort_index();
}
// add = document.getElementById("add");
// add.addEventListener("click", update);