-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdailyToDo.js
68 lines (56 loc) · 1.69 KB
/
dailyToDo.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
//resetData();
var input = $("#hoursSlept")
input.change(function() {
var num = parseInt(this.value, 10),
min = 0,
max = 24;
if (isNaN(num)) {
this.value = "";
return;
}
this.value = Math.max(num, min);
this.value = Math.min(num, max);
});
function initDailyToDo(){
var myCheck = $("#mycheck");
var myCheck2 = $("#mycheck2");
var myInput = $("#hoursSlept")
var d = new Date()
var currentDay = d.getDate();
if(days[currentDay].didntLookAtScreen) {
myCheck.prop("checked", true)
} else {
myCheck.prop("checked", false)
}
if(days[currentDay].drunk) {
myCheck2.prop("checked", true);
} else {
myCheck2.prop("checked", false);
}
if(days[currentDay].submitted){
myCheck.prop('disabled', true);
myCheck2.prop('disabled', true);
myInput.prop('disabled', true);
} else {
myCheck.prop('disabled', false);
myCheck2.prop('disabled', false);
myInput.prop('disabled', false);
}
if(days[currentDay].sleepTime) {
myInput.val(days[currentDay].sleepTime);
}
}
function submitDaily() {
var myCheck = $("#mycheck");
var myCheck2 = $("#mycheck2");
var myInput = $("#hoursSlept");
var d = new Date()
var currentDay = d.getDate();
days[currentDay].didntLookAtScreen = myCheck.is(":checked");
days[currentDay].drunk = myCheck2.is(":checked");
days[currentDay].sleepTime = parseInt(myInput.val()) ? parseInt(myInput.val()) : 0;
days[currentDay].submitted = true;
localStorage.days = JSON.stringify(days);
updatePoints();
initDailyToDo();
}