-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.js
155 lines (136 loc) · 6.75 KB
/
calendar.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
let current = new Date();
let month = current.getMonth()+1;
let cmonth = current.getMonth();
let day = current.getDate();
let cday = current.getDate();
let year = current.getFullYear();
let weekday = current.getDay();
let dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
let monthNames = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
let dates = [];
console.log(dayNames[weekday], day, month, year);
let i = 0;
if(weekday>0){
current.setDate(day-weekday);
day = current.getDate();
} else {
current.setDate(day-7);
day = current.getDate();
}
console.log('----------------');
for(i=0;i<30;i++){
current.setDate(day+1);
dates.push({
year: current.getFullYear(),
month: current.getMonth(), // NOTICE
day: current.getDate(),
weekday: current.getDay(),
date: new Date(current.getFullYear(),current.getMonth(),current.getDate())
});
day = current.getDate();
}
function calendar(nthWeek, userid, mybooked, allbooked) {
let calendarTable = "<table class='table table-bordered calendarr' style='font-size:18px;width:100%'> <tr style='text-align:center'><th colspan='8'>";
if (nthWeek===0){
calendarTable += "<button type='button' disabled class='btn btn-sm btn-secondary'> <span data-feather='plus'> << </span> </button>";
} else{
calendarTable += "<button type='button' onclick='lastWeek()' class='btn btn-sm btn-secondary'> <span data-feather='plus'> << </span> </button>";
}
calendarTable += " "+monthNames[dates[0+nthWeek*7].month]+ " " + dates[0+nthWeek*7].day +" "+ dates[0+nthWeek*7].year + " - " + monthNames[dates[6+nthWeek*7].month]+ " " + dates[6+nthWeek*7].day +" "+ dates[6+nthWeek*7].year+" ";
if (dates.length-nthWeek*7 < 13){
calendarTable += "<button type='button' disabled class='btn btn-sm btn-secondary'> <span data-feather='plus'> >> </span> </button> </th></tr>";
} else{
calendarTable += "<button type='button' onclick='nextWeek()' class='btn btn-sm btn-secondary'> <span data-feather='plus'> >> </span> </button> </th></tr>";
}
//calendarTable += "<tr class='weekdays'> <td></td> <th>June 7<br>Mon</th> <th>June 8<br>Tue</th> <th>June 9<br>Wed</th> <th>June 10<br>Thu</th> <th>June 11<br>Fri</th> <th>June 12<br>Sat</th> <th>June 13<br>Sun</th> </tr>";
calendarTable += "<tr> <td></td>";
for(i=0+nthWeek*7;i<7+nthWeek*7;i++){
if(dates[i].day===cday && dates[i].month===cmonth && dates[i].year===year ){
calendarTable += "<th style='background-color:powderblue'>"+ monthNames[dates[i].month] + " " + dates[i].day + "<br>" + dayNames[dates[i].weekday] + "</th>";
}else{
calendarTable += "<th>"+ monthNames[dates[i].month] + " " + dates[i].day + "<br>" + dayNames[dates[i].weekday] + "</th>";
}
}
calendarTable += "</tr>";
function printSlot(j){
for(i=0+nthWeek*7;i<7+nthWeek*7;i++){
let dt = new Date();
if(j===1){dates[i].date.setHours(9,0,0);}
else if(j===2){dates[i].date.setHours(10,30,0);}
else if(j===3){dates[i].date.setHours(12,0,0);}
else if(j===4){dates[i].date.setHours(13,30,0);}
else if(j===5){dates[i].date.setHours(15,0,0);}
else if(j===6){dates[i].date.setHours(16,30,0);}
console.log(dates[i].date); console.log(dt);
if(dates[i].date<dt){
calendarTable += "<td style='background-color:LightGray'></td>";
} else{
let ibook = false;
let booked = false;
mybooked.forEach( b => {
if(dates[i].day===b.d && dates[i].month+1===b.m && dates[i].year===b.y && j.toString()===b.slot && Number(userid)===b.userid){
calendarTable += "<td style='background-color:lightBlue'>";
calendarTable += b.dogname;
calendarTable += "</button> </td>";
ibook = true;
booked = true;
}
})
if(!ibook){
allbooked.forEach( b => {
if(dates[i].day===b.d && dates[i].month+1===b.m && dates[i].year===b.y && j.toString()===b.slot && userid!==b.userid){
calendarTable += "<td style='background-color:DarkRed'></td>";
booked = true;
}
})
}
if(!booked){
calendarTable += "<td style='padding:0' onMouseOver='this.style.background=\"SeaGreen\"' onMouseOut='this.style.background=\"#FFFFFF\"'>";
calendarTable += "<label class='btn' style='width:100%;height:100%;'><input type='radio' name='slot' value='";
calendarTable += j+","+dates[i].day+","+(dates[i].month+1)+","+dates[i].year+","+userid;
calendarTable += "' required> </label> <div class='invalid-feedback'>More example invalid feedback text</div></td>";
}
}
}
calendarTable += "</tr>";
}
calendarTable +="<div class='btn-group btn-group-toggle' data-toggle='buttons'>";
calendarTable += "<tr style='text-align:center;'> <td>9:00 am - 10:30 am</td>";
printSlot(1);
calendarTable += "<tr style='text-align:center;'> <td>10:30 am - 12:00 pm</td>";
printSlot(2);
calendarTable += "<tr style='text-align:center;'> <td>12:00 am - 1:30 pm</td>";
printSlot(3);
calendarTable += "<tr style='text-align:center;'> <td>1:30 pm - 3:00 pm</td>";
printSlot(4);
calendarTable += "<tr style='text-align:center;'> <td>3:00 pm - 4:30 pm</td>";
printSlot(5);
calendarTable += "<tr style='text-align:center;'> <td>4:30 pm - 6:00 pm</td>";
printSlot(6);
calendarTable += "</div";
calendarTable += "</table>";
/*
document.getElementById("calendarr").innerHTML = calendarTable;
mybooked.forEach( b => {
let idname = "book"+b.id;
document.getElementById(idname).innerHTML = calendarTable;
})
*/
return calendarTable;
}
let j = 0;
function nextWeek(){
j++;
console.log(j);
calendar(j);
}
function lastWeek(){
j--;
console.log(j);
calendar(j);
}
calendar(j);
dates.forEach(date => console.log(dayNames[date.weekday], date.day, date.month, date.year));
module.export = {
calendar: calendar
}