-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
161 lines (146 loc) · 3.55 KB
/
script.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
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
// Hours variable to store and loop through scheduler
var workDay = [
{
id: "0",
hour: "09",
time: "09",
meridiem: " am",
reminder: ""
},
{
id: "1",
hour: "10",
time: "10",
meridiem: " am",
reminder: ""
},
{
id: "2",
hour: "11",
time: "11",
meridiem: " am",
reminder: ""
},
{
id: "3",
hour: "12",
time: "12",
meridiem: " pm",
reminder: ""
},
{
id: "4",
hour: "01",
time: "13",
meridiem: " pm",
reminder: ""
},
{
id: "5",
hour: "02",
time: "14",
meridiem: " pm",
reminder: ""
},
{
id: "6",
hour: "03",
time: "15",
meridiem: " pm",
reminder: ""
},
{
id: "7",
hour: "04",
time: "16",
meridiem: " pm",
reminder: ""
},
{
id: "8",
hour: "05",
time: "17",
meridiem: " pm",
reminder: ""
},
]
// save hours var to localStorage
function saveReminders() {
localStorage.setItem("workDay", JSON.stringify(workDay));
}
// sets any data in localStorage to be displayed
function displayReminders() {
workDay.forEach(function (_thisHour) {
$(`#${_thisHour.id}`).val(_thisHour.reminder);
})
}
// sets any existing localStorage data to the view if it exists
function init() {
var storedDay = JSON.parse(localStorage.getItem("workDay"));
if (storedDay) {
workDay = storedDay;
}
saveReminders();
displayReminders();
}
// Display header date
$(document).ready(function() {
var currentDate = moment().format('dddd MMMM Do YYYY');
var $headerDate = $('#currentDay');
$headerDate.text(currentDate);
});
// creating Timeblocks
workDay.forEach(function(thisHour) {
// timeblocks rows
var hourRow = $("<form>").attr({
"class": "row"
});
$(".container").append(hourRow);
// time holder Boxes
var hourBox = $("<div>")
.text(`${thisHour.hour}${thisHour.meridiem}`)
.attr({
"class": "col-md-2 hour"
});
// Textarea Boxes
var hourPlan = $("<div>")
.attr({
"class": "col-md-9 description p-0"
});
var planData = $("<textarea>");
hourPlan.append(planData);
planData.attr("id", thisHour.id);
if (thisHour.time < moment().format("HH")) {
planData.attr ({
"class": "col-md-12 description p-4 past",
})
} else if (thisHour.time === moment().format("HH")) {
planData.attr({
"class": "col-md-12 description p-4 present"
})
} else if (thisHour.time > moment().format("HH")) {
planData.attr({
"class": "col-md-12 description p-4 future"
})
}
// save button
var saveButton = $("<i class='far fa-save fa-lg'></i>")
var savePlan = $("<button>")
.attr({
"class": "col-md-1 saveBtn"
});
savePlan.append(saveButton);
hourRow.append(hourBox, hourPlan, savePlan);
})
// loads any existing localstorage
init();
// saves data in localStorage on click of save button
$(".saveBtn").on("click", function(event) {
event.preventDefault();
var saveIndex = $(this).siblings(".description").children(".col-md-12").attr("id");
workDay[saveIndex].reminder = $(this).siblings(".description").children(".col-md-12").val();
//display saved message
alert("Saved!");
saveReminders();
displayReminders();
})