-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedule.html
128 lines (118 loc) · 4.12 KB
/
schedule.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
<!DOCTYPE html>
<html>
<head>
<title>UPS Scheduluing ALPHA</title>
</head>
<body>
<form action="javascript:;" id="onlyform" onsubmit="start(this)">
Starting a new schedule?: <select name="yesno" form="onlyform"><option value="yes">Yes</option><option value="no">No</option></select>
<input type="submit">
</form>
<p id="part2"></p>
<script>
//Setup variables
var num1 = 1;
var names = [];
var max = 0;
var jsonInfo = {};
var testArray = [];
var date1 = new Date();
const months = ["January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var givenMonth = months[date1.getMonth()];
var htmlTest = `Select a month: <select name ="months" form="onlyform">`;
for(var i = 0; i < months.length; i++){
if(months[i] == givenMonth){
htmlTest+=`<option value="${months[i]}" selected>${months[i]}</option>`;
}else{
htmlTest+=`<option value="${months[i]}">${months[i]}</option>`;
}
}
htmlTest+=`</select>`;
document.getElementById("part2").innerHTML=htmlTest;
//Beginning
function start(form){
var x = form.elements;
givenMonth = x["months"].value;
if(x["yesno"].value == "yes"){
var html = '<form action ="javascript:;" onsubmit="people(this)"> How many people are you scheduling?: <input type ="number" min="1" name="amount"><input type="submit"></form>'
//document.getElementById("part1").innerHTML=(html);
document.write(html);
document.close();
}else{
document.getElementById("part1").innerHTML=("Error! Can't select no");
}
}
//Method used to get the names of people
function schedule(){
var html = `<form action ="javascript:;" onsubmit="individual(this)"> What is the name of person #${num1}?: <input type ="text" name="names"><input type="submit"></form>`;
document.write(html);
}
//Event function used when setting amount of players
function people(form){
var x = form.elements;
var amount = parseInt(x["amount"].value);
max = amount;
schedule();
}
//Function called after giving a name.
function individual(form){
var x = form.elements;
var name = x["names"].value
names[num1-1] = name;
num1++;
if(num1-1<max){
schedule();
}else{
document.close();
num1 = 0;
startSchedule();
}
}
//Function used to get the days people can work.
function startSchedule(){
var sched = getDays(months.indexOf(givenMonth),date1.getFullYear());
var html = `<form action ="javascript:;" onsubmit="endSchedule(this)"> When can ${names[num1]} work?:`;
for(var i = 0; i < sched.length; i++){
html+= `<br/><input type="checkbox" name="day${i}" value="${months[sched[i].getMonth()]} ${sched[i].getDate()}"> ${months[sched[i].getMonth()]} ${sched[i].getDate()}`;
}
html+= `<br/><input type="submit">\n</form>`;
document.write(html);
document.close();
}
//Event used when you select dates people can work.
function endSchedule(form){
var x = form.elements;
var days = getDays(date1.getMonth(),date1.getFullYear());
testArray[num1] = [];
for(var i = 0; i < days.length; i++){
if(x[`day${i}`].checked){
testArray[num1][testArray[num1].length] = x[`day${i}`].value;
}
}
num1++;
//Used to tell when people can work
if(num1 < names.length){
startSchedule();
}else{
for(var i = 0; i < testArray.length; i++){
document.writeln(`${names[i]} can work: <br/>`);
for(var g = 0; g < testArray[i].length; g++){
document.writeln(`${testArray[i][g]} <br/>`);
}
}
}
}
//Gets the days of the given month
function getDays(month, year){
var date = new Date(year, month, 1);
var days = [];
while (date.getMonth() === month) {
days.push(new Date(date));
date.setDate(date.getDate() + 1);
}
return days;
}
</script>
<p id="part1"></p>
</body>
</html>