-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
144 lines (109 loc) · 2.76 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<title>Habit Tracker</title>
<!-- Stylesheets -->
<link rel="stylesheet" href="styles.css">
<script>
// Habit data object
const habitData = {
rows: []
};
// Load data from localStorage
loadData();
// Current date
const today = new Date();
const currentMonth = today.getMonth();
const currentYear = today.getFullYear();
// DOM Elements
const prevButton = document.getElementById('prev');
const nextButton = document.getElementById('next');
const titleElement = document.getElementById('title');
const table = document.getElementById('table');
const rowsElement = document.getElementById('rows');
// Render UI
render();
function render() {
titleElement.textContent = `${getMonthName(currentMonth)} ${currentYear}`;
let html = '';
habitData.rows.forEach(row => {
html += createRowHTML(row);
});
rowsElement.innerHTML = html;
}
function createRowHTML(row) {
let html = `
<tr data-row-id="${row.id}">
<td>${row.name}</td>
`;
for (let i = 1; i <= getDaysInMonth(); i++) {
let checked = '';
if (row.dates.includes(i)) {
checked = 'checked';
}
html += `
<td>
<input type="checkbox" ${checked}
onclick="toggleDate(${row.id}, ${i})">
</td>
`;
}
html += `
<td>
<button onclick="removeRow(${row.id})">
Delete
</button>
</td>
</tr>
`;
return html;
}
// Add row
function addRow() {
habitData.rows.push({
id: Date.now(),
name: '',
dates: []
});
saveData();
render();
}
// Toggle date
function toggleDate(rowId, date) {
const row = habitData.rows.find(r => r.id == rowId);
toggleDateForRow(row, date);
saveData();
render();
}
// Save to localStorage
function saveData() {
localStorage.setItem('habitData', JSON.stringify(habitData));
}
// Load data from localStorage
function loadData() {
const data = localStorage.getItem('habitData');
if (data) {
habitData.rows = JSON.parse(data).rows;
}
}
// Other helper functions
function getDaysInMonth() {
// Return number of days in month
}
function getMonthName(monthIndex) {
// Return name of month
}
function isWeekend(day) {
}
</script>
</head>
<body>
<!-- User interface -->
<div id="title"></div>
<table id="table">
<tbody id="rows"></tbody>
</table>
<button onclick="addRow()">Add Row</button>
<script src="app.js"></script>
</body>
</html>