-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
253 lines (225 loc) · 10.4 KB
/
Copy pathindex.html
File metadata and controls
253 lines (225 loc) · 10.4 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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ToDo App</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<style>
.demo-list-control {
width: 600px;
}
.page-content {
padding: 50px 25%;
margin-top: 50px;
}
.mdl-mini-footer {
position: relative;
}
</style>
<script>
// Variable to store the imported data
let importedData = null;
// Function to import data from a JSON file and create the list
function importList(input) {
const file = input.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function (e) {
const jsonContent = e.target.result;
try {
importedData = JSON.parse(jsonContent);
const todoList = document.getElementById('todolist');
// Clear the existing list
todoList.innerHTML = '';
// Iterate through the imported data and create list items
importedData.todoList.forEach((item, index) => {
createListItem(item, index);
});
} catch (error) {
console.error('Error parsing JSON:', error);
}
};
reader.readAsText(file);
}
// Function to create a list item
function createListItem(item, index) {
const todoList = document.getElementById('todolist');
const listItem = document.createElement('li');
listItem.className = 'mdl-list__item';
const primaryContent = document.createElement('span');
primaryContent.className = 'mdl-list__item-primary-content';
const checkboxLabel = document.createElement('label');
checkboxLabel.className = 'mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect';
const checkboxInput = document.createElement('input');
checkboxInput.type = 'checkbox';
checkboxInput.className = 'mdl-checkbox__input';
checkboxInput.checked = item.checked;
checkboxInput.addEventListener('change', function () {
// Update the checked status in the importedData when the checkbox changes
importedData.todoList[index].checked = this.checked;
exportEditedList(); // Export the edited list
});
checkboxLabel.appendChild(checkboxInput);
const itemText = document.createElement('span');
itemText.textContent = item.text;
// Add an edit button to each item
const editButton = document.createElement('button');
editButton.textContent = 'Edit';
editButton.className = 'mdl-button mdl-js-button mdl-button--raised mdl-button--colored';
editButton.onclick = function () {
editItem(index);
};
// Add a remove button to each item
const removeButton = document.createElement('button');
removeButton.textContent = 'Del';
removeButton.className = 'mdl-button mdl-js-button mdl-button--raised mdl-button--colored';
removeButton.onclick = function () {
removeItem(index);
};
primaryContent.appendChild(checkboxLabel);
primaryContent.appendChild(itemText);
primaryContent.appendChild(editButton);
primaryContent.appendChild(removeButton);
listItem.appendChild(primaryContent);
todoList.appendChild(listItem);
componentHandler.upgradeAllRegistered();
}
// Function to edit a list item
function editItem(index) {
const newText = prompt('Edit the item:', importedData.todoList[index].text);
if (newText !== null) {
importedData.todoList[index].text = newText;
exportEditedList();
}
}
// Function to remove a list item
function removeItem(index) {
importedData.todoList.splice(index, 1);
exportEditedList();
}
// Function to update the displayed list with importedData
function updateList() {
const todoList = document.getElementById('todolist');
todoList.innerHTML = ''; // Clear the existing list
importedData.todoList.forEach((item, index) => {
createListItem(item, index);
});
}
// Function to add a new item to the list
function additem() {
const text = todoitem.value.trim(); // Trim any leading/trailing whitespace
if (text) {
// Create a new item object and add it to the importedData
const newItem = {
text: text,
checked: false,
};
importedData.todoList.push(newItem);
// Update the displayed list
createListItem(newItem, importedData.todoList.length - 1);
// Clear the input field
todoitem.value = '';
exportEditedList(); // Export the edited list
}
return false; // Prevent the form from submitting
}
// Function to export the edited ToDo list data to a JSON file
function exportEditedList() {
// Convert the data to a JSON string
const jsonData = JSON.stringify(importedData, null, 2);
// Create a Blob containing the JSON data
const blob = new Blob([jsonData], { type: 'application/json' });
// Create a download link for the JSON file
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'edited_todolist.json';
a.textContent = 'Download Edited JSON';
// Trigger a click event to initiate the download
a.click();
// Clean up resources
URL.revokeObjectURL(url);
}
</script>
</head>
<body>
<div class="mdl-layout mdl-js-layout">
<header class="mdl-layout__header mdl-layout__header--scroll">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">ToDo App</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="mailto:katja33herold@gmail.com">
<div id="tt2" class="icon material-icons">mail</div>
<div class="mdl-tooltip mdl-tooltip--large" for="tt2">contact Author</div>
</a>
</nav>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout-title">Menu</span>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="blank.html" >Create new List</a>
<a class="mdl-navigation__link" href="#" onclick="exportEditedList()">Export List</a>
<input type="file" id="importFile" style="display: none;" accept=".json" onchange="importList(this)">
<label class="mdl-navigation__link" for="importFile">Import List</label>
</nav>
</div>
<main class="mdl-layout__content">
<div class="page-content">
<div id="p2" class="mdl-progress mdl-js-progress mdl-progress__indeterminate"></div>
<div class="mdl-layout__content">
<h4>ToDo List Editor</h4>
<form onsubmit="additem(); return false;" action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="todoitem">
<label class="mdl-textfield__label" for="sample3">ToDo...</label>
</div>
<button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored">
Add
</button>
</form>
<ul class="demo-list-control mdl-list" id="todolist"></ul>
</div>
</div>
</main>
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<div class="mdl-logo">ToDo App</div>
<ul class="mdl-mini-footer__link-list">
<li>
<a id="show-dialog" type="button" class="mdl-button">Version</a>
<dialog class="mdl-dialog">
<h4 class="mdl-dialog__title">ToDo App</h4>
<div class="mdl-dialog__content">
<p><b>Version 1.39</b> - 2023.10</p>
<p>by katja33herold@gmail.com</p>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button close">Okay</button>
</div>
</dialog>
<script>
var dialog = document.querySelector('dialog');
var showDialogButton = document.querySelector('#show-dialog');
if (!dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
showDialogButton.addEventListener('click', function () {
dialog.showModal();
});
dialog.querySelector('.close').addEventListener('click', function () {
dialog.close();
});
</script>
</li>
</ul>
</div>
</footer>
</div>
</body>
</html>