-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·82 lines (64 loc) · 1.91 KB
/
app.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
$(document).ready(function () {
let baseURL = 'https://cors-anywhere.herokuapp.com/https://ecncw5rb2h.execute-api.us-east-1.amazonaws.com/dev/todos'
const getDate = () => {
let date = moment().format("MMM Do YY");
$('.date').append(date)
}
getDate()
const getWeather = () => {
$.ajax({
url: 'https://cors-anywhere.herokuapp.com/https://api.darksky.net/forecast/0a465756c7389af01575f8393da25091/39.7392,-104.9903',
type: 'GET',
success: function(result) {
addWeather(result)
}
})
}
const addWeather = (result) => {
$('.current-weather').append(result.currently.temperature + ascii(176) + " F")
}
function ascii (a) { return String.fromCharCode(a); }
getWeather()
$('#current-time').append(moment().format('LT'))
$.get(baseURL)
.then(getToDoList)
function getToDoList(data) {
$('#full-to-do-list').empty();
let source = $("#to-do-list-item").html();
let template = Handlebars.compile(source);
let context = {data: data};
let html = template(context)
$('#full-to-do-list').append(html);
};
$('#full-to-do-list').on('click', '#delete-item', function() {
let value = $(this).attr('data-id')
$.ajax({
url: baseURL + '/' + value,
type: 'DELETE'
})
.then(()=> $.get(baseURL)
.then(getToDoList))
alert('To-do item deleted! Refreshing now!')
})
$('#add-item').on('click', function(info) {
info.preventDefault()
let value = $('#add-field').val()
var settings = {
"async": true,
"crossDomain": true,
"url": "https://cors-anywhere.herokuapp.com/https://ecncw5rb2h.execute-api.us-east-1.amazonaws.com/dev/todos",
"method": "POST",
"headers": {
"cache-control": "no-cache",
},
"data": '{\n\t\"text\": \"'+value+'\"\n}'
}
$.ajax(settings).done(function (response) {
console.log(response);
})
.then(()=> $.get(baseURL)
.then(getToDoList))
alert('Item added! Refreshing now!')
$('.clearafter').val('')
})
})