-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
380 lines (356 loc) · 11.2 KB
/
index.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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<!DOCTYPE html>
<html>
<head>
<title>todo</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<link rel="stylesheet" type="text/css" href="assets/css/animate.min.css">
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css">
<link rel="stylesheet" href="assets/css/bootstrap-datepicker.css">
<link rel="stylesheet" href="assets/css/sweet-alert.css">
<link rel="stylesheet" href="assets/fonts/css/fontawesome.css">
<style>
.actions {
padding-right: 0.6em;
padding-left: 0.6em;
border-radius: 10rem;
}
</style>
</head>
<body>
<div class="container maincontianer animated bounce">
My Todo
</div>
<div class="container animated bounce">
<div class="row">
<div class="col-md-5 mypages">
<h2 id="h2Create">Create Todo</h2>
<!-- <h2 id="h2Edit">Editing Todo...</h2> -->
<hr>
<!-- <span style="font-size: 2em; color: danger;">
<i class= "fas fa-trash "></i>
<i class="fas fa-stroopwafel"></i>
</span>
-->
<div class="form-group">
<label>Name : </label>
<input type="text" class="form-control" id="name" placeholder="Todo name">
<label>Description : </label>
<textarea class="form-control" rows="5" id="description" placeholder="Todo description"></textarea>
<label>Date</label>
<input type="text" name="date" id="date" class="form-control">
<label>Time</label>
<input type="time" name="time" id="time" class="form-control">
<br>
<button onclick="saveTodo();" class="btn btn-info" id="myTodo" >Create</button>
<!-- <button onclick="getUsers();" class="btn btn-info" id="Todo" >Call</button> -->
</div>
</div>
<div class="col-md-7 mypages" id="resultHere">
<h2>Your Todo's</h2>
<hr>
<!-- <table class="table table-hover table-bordered" id="todoTable">
<thead id="tableHead">
<tr>
<th>Todo Name</th>
<th>Description</th>
<th>Date</th>
<th>Properties</th>
</tr>
</thead>
<tbody id="tableBody">
</tbody>
</table> -->
<ul class="list-group todos-parent">
<!-- todo will be displayed -->
</ul>
<!-- <div class="xvalue"></div> -->
</div>
</div>
</div>
<script src="dist/bundle.js"></script>
<script src="assets/js/jquery.js" type="text/javascript"></script>
<script src="assets/js/popper.js" type="text/javascript"></script>
<script src="assets/js/bootstrap.js" type="text/javascript"></script>
<script src="assets/js/bootstrap-datepicker.js" type="text/javascript"></script>
<script src="assets/js/moment.js" type="text/javascript"></script>
<script src="assets/js/swal.min.js" type="text/javascript" ></script>
<script src="assets/fonts/js/fontawesome-all.js" type="text/javascript" ></script>
<script type="text/javascript">
let todos = [];
let databaseTodo = [];
$(window).on('load',function(){
getTodos();
swal(
'Are you Sure to Refresh?',
'Your todos\' will be lost',
'question'
)
$.get('http://localhost:9000/api/todos/test')
});
function getUsers() {
// $.ajax('http://localhost:8000/api/users/create', {
// method: 'post',
// data: {
// name: 'Test api',
// email: 'apitest2@mail.com',
// password: 'secret'
// },
// cache: false,
// type: 'json',
// success: (response) => {
// console.log(response);
// },
// error: (error, status, a) => {
// console.log(error, status, a)
// }
// });
//
// let b = ''
};
function saveTodo() {
// todo.createTodo(this);
let b =''
name = $('#name').val();
description = $('#description').val();
date = $('#date').val();
time = $('#time').val();
done = 0;
realdate = moment(date).format('YYYY-MM-DD');
//realTime = moment(time).format('HH:mm')
primaryindex = todos.push({name, description, realdate, time, done});
console.log(todos)
$.ajax({
url: 'http://localhost:9000/api/todos/create',
method: 'POST',
data: {index:primaryindex, name:name, description:description, date:realdate, time:time},
dataType: 'json',
success: function(result,status,xhr){
console.log(status)
console.log(result)
console.log(xhr)
// console.log(todos)
}
})
getTodos();
}
function getTodos(force) {
if (force) {
let parent = $('.todos-parent').html('');
let todo = null;
for (let todo in databaseTodo) {
//console.log(todo)
todo = generateTodo(databaseTodo[todo].id, todo, databaseTodo[todo].name, databaseTodo[todo]['description'], databaseTodo[todo].date, databaseTodo[todo].time, databaseTodo[todo].done);
$(parent).append(todo);
}
} else {
$.ajax({
url:'http://localhost:9000/api/todos',
method: 'GET',
dataType: 'json',
success: function(data){
databaseTodo = data
// console.log(typeof todos)
// console.log(typeof databaseTodo)
// console.log(todos[0])
let parent = $('.todos-parent').html('');
let todo = null;
for (let todo in databaseTodo) {
console.log(todo)
todo = generateTodo(databaseTodo[todo].id, todo, databaseTodo[todo].name, databaseTodo[todo]['description'], databaseTodo[todo].date, databaseTodo[todo].time, databaseTodo[todo].done);
$(parent).append(todo);
}
}
})
}
initLibraries();
}
function generateTodo (id, index, name, desc, date, time, done) {
return `
${done == 1?`
<li class="doneTodo list-group-item d-flex justify-content-between align-items-center ">
`:`
<li class="list-group-item d-flex justify-content-between align-items-center">`}
${name.substring(0, 12) + (name.length > 13? ' ...':'')} <span class="badge badge-primary">Due: ${moment(date).format('ddd MMM Do, YYYY')}</span>
<span class="actions">
<div class="btn-group" role="group" aria-label="Basic example">
<button class="btn btn-success btn-sm" index="${index}" onclick="doneTodo(this)"><i class= "fas fa-check "></i></button>
<button type="button" class="btn btn-sm btn-info" data-toggle="popover" title="${name}" data-content="${desc}"><i class= "fas fa-eye "></i></button>
<button class="btn btn-warning btn-sm" index="${index}" data-id="${id}" onclick="editTodo(this)"><i class= "fas fa-edit "></i></button>
<button class="btn btn-danger btn-sm" index="${index}" onclick='deleteTodo(this)'><i class= "fas fa-trash "></i></button>
</div>
</span>
</li>
`;
}
function initLibraries() {
$('[data-toggle="popover"]').popover()
$('button[data-toggle="popover"]').click(function() {
$(this).on('mouseleave', function (evt) {
$(this).click();
$(this).unbind('mouseleave');
})
})
}
$(function () {
$('[data-toggle="popover"]').popover();
$('input[name="date"]').datepicker({
startDate: '1d',
format: 'DD M dd yyyy',
});
});
$("#myTodo").click(
function(){
console.log('itsss')
let ele = $("#resultHere");
ele.addClass('animated flipInY')
});
function doneTodo(nn){
let position = parseInt(nn.attributes['index'].value);
positionInDb = position+1;
$.ajax({
url: 'http://localhost:9000/api/todos/done',
method: 'POST',
data: {locate:positionInDb},
success: function(result,status,xhr){
console.log(status)
console.log(result)
console.log(xhr)
todos[position].done = 1;
}
});
ff =nn.parentElement;
fff = ff.parentElement;
// console.log(fff);
fff.className = "doneTodo";
};
function deleteTodo(nn){
let position = parseInt(nn.attributes['index'].value);
positionInDb = position+1;
//console.log(positionInDb)
// var conf = confirm('Do you want to delete \n This Todo?')
// if (conf == true) {
//
swal({
title: 'Are you sure?',
text: "The Todo will be completly deleted!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
todos.splice(position, 1);
$.ajax({
url: 'http://localhost:9000/api/todos/delete',
method: 'POST',
data: {locate:positionInDb},
success: function(result,status,xhr){
console.log(status)
console.log(result)
console.log(xhr)
}
})
swal(
'Deleted!',
'Todo was succesfully deleted.',
'success'
)
}
getTodos()
})
// }
}
function editTodo(nn){
// console.log($('myTodo'))
let position = parseInt(nn.attributes['index'].value);
document.querySelector('#h2Create').innerHTML = "Editing Todo..."
let updateButton = document.getElementById("myTodo")
updateButton.innerHTML = "Update"
updateButton.attributes['onclick'].value = 'afterEdit(this)';
// updateButton.className = 'btn btn-primary'
updateButton.setAttribute('index', position);
updateButton.setAttribute('data-id', $(nn).data('id'));
// let todoItem = databaseTodo.find(item => item.id == $(nn).data('id'))
currentTodo = databaseTodo.splice($(nn).attr('index'), 1)[0];
getTodos(true);
/*$.ajax({
url:'http://localhost:9000/api/todos',
method: 'GET',
dataType: 'json',
success: function(data){ssssssssssssss
let Todos = data*/
// currentTodo = Todos[position];
// console.log(currentTodo)
$('#name').val(currentTodo.name)
$('#description').val(currentTodo.description)
$('#date').val(currentTodo.date)
$('#time').val(currentTodo.time)
//afterEdit(position);
/*}
});*/
}
function afterEdit(nn){
let id = $(nn).data('id');
let position = parseInt(nn.attributes['index'].value);
located = position
name = $('#name').val();
description = $('#description').val();
date = $('#date').val();
time = $('#time').val();
// done = 0;
primaryindex = located;
realdate = moment(date).format('YYYY-MM-DD');
// positionInDb = located+1;
let data = {
index: primaryindex,
name: name,
description: description,
date: realdate,
time: time
};
//console.log(data);
$.ajax(`http://localhost:9000/api/todos/update/${id}`, {
method: 'post',
data,
error: (err) => {console.log(err)},
success: function(data){
databaseTodo.splice(located, 0, data.todo);
getTodos(true);
// let position = parseInt(nn.attributes['index'].value);
document.querySelector('#h2Create').innerHTML = "Create Todo"
let updateButton = document.getElementById("myTodo")
updateButton.innerHTML = "Create"
updateButton.attributes['onclick'].value = 'saveTodo()';
name = $('#name').val('');
description = $('#description').val('');
date = $('#date').val('');
time = $('#time').val('');
}
});
// $.ajax(`http://localhost:9000/api/todos/update/${id}`, {
// method: 'POST',
// data: {
// index:primaryindex,
// name:name,
// description:description,
// date:realdate,
// time:time
// },
// // dataType: 'json',
// success: function(result,status,xhr) {
// console.log(status)
// console.log(result)
// console.log(xhr)
// // console.log(todos)
// }
// })
//realTime = moment(time).format('HH:mm')
// primaryindex = todos.push({name, description, realdate, time, done});
// console.log(todos)
// $.ajax({
// getTodos();
}
</script>
</body>
</html>