-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstudent.js
175 lines (156 loc) · 6.08 KB
/
student.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const apply=document.getElementById("applyod")
document.getElementById("applyodbtn").addEventListener("click",(event)=>{
event.preventDefault();
apply.classList.toggle("view")
document.getElementById("rollno").value=username;
document.getElementById("rollno").disabled=true;
if(username.includes("CS")){
department="cse"
}else if(username.includes("IT")){
department="it"
}else if(username.includes("AI")){
department="aids"
}
else if(username.includes("EC")){
department="ece"
}
else if(username.includes("ME")){
department="mech"
}
else if(username.includes("CB")){
department="csbs"
}
document.getElementById("studentDept").value=department;
document.getElementById("studentDept").disabled=true;
let curyear=new Date().getFullYear().toString().slice(-2)
let month = new Date().getMonth()+1
let joinyear = username.slice(0,2)
let years=curyear-joinyear;
if(month>=7 && years < 1 || month<7 && years<2){
pursuing="1st"
}else if(month>=7 && years<2 || month<7 && years<3){
pursuing="2nd"
}else if(month>=7 && years<3 || month<7 && years<4){
pursuing="3rd"
}
else if(month>=7 && years<4 || month<7 && years<5){
pursuing="4th"
}
document.getElementById("studentYear").value=pursuing;
document.getElementById("studentYear").disabled=true;
})
//view status bbar
const statusbar=document.getElementById("statusbar")
document.getElementById("statusbtn").addEventListener("click",(event)=>{
event.preventDefault();
statusbar.classList.toggle("view")
})
//view history
const history=document.getElementById("history")
document.getElementById("historybtn").addEventListener("click",(event)=>{
event.preventDefault();
history.classList.toggle("view")
})
const profile=document.getElementById("profilebtn")
profile.addEventListener("click",(event)=>{
event.preventDefault()
const userDetails = getUserDetails()
console.log(userDetails)
document.querySelector(".text-body-emphasis.h4").innerText=userDetails.userName
})
//submit od
// const submitod=document.getElementById("applyod")
// document.getElementById("odsubmit").addEventListener("click",(event)=>{
// event.preventDefault();
// let studentName=document.getElementById("studentname").value
// let mentorName=document.getElementById("mentor").value
// let reason=document.getElementById("reasonforod").value
// let formdate=document.getElementById("formdate").value
// let todate=document.getElementById("todate").value
// let year=document.getElementById("inputGroupSelect01").value
// let department=document.getElementById("inputGroupSelect02").value
// console.log(studentName,mentorName,reason,formdate,todate,year,department)
// submitod.classList.remove("view")
// })
// document
// .getElementById("historybtn")
// .addEventListener("click", async (event) => {
// event.preventDefault();
// try {
// data.forEach(async (info) => {
// let dataset = info.data();
// let login = document.cookie.split(",");
// const docRef = doc(db, "users", info.id);
// if (dataset.username == login[0]) {
// let odlist = dataset.odlist;
// for (const odRequest of odlist) {
// // Access the "mentor" property within the current OD request object
// if(odRequest.mentor!="pending" && odRequest.hod!="pending" && odRequest.principal!="pending"){
// const reason = odRequest.Reason;
// const date = odRequest.OdFrom;
// const todate = odRequest.To;
// const principalstatus = odRequest.principal;
// var table=document.getElementById("odHistory");
// let temp=`
// <tr>
// <td id="mencho">${reason}</td>
// <td id="hodcho">${date}</td>
// <td id="hodcho">${todate}</td>
// <td id="princho">${principalstatus}</td>
// </tr>`
// table.innerHTML+=temp;
// console.log("Mentor Status:", reason);
// }
// }
// }})
// }catch (error) {
// console.log("Upload error:", error);
// }
// },{once:true});
function getUserDetails()
{
var cookies = document.cookie.split(";"); // Split the cookies string into an array
var myCookieValue = null;
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.startsWith("myCookie=")) {
myCookieValue = cookie.substring("myCookie=".length);
break; // Exit the loop once we find the myCookie
}
}
return JSON.parse(myCookieValue)
}
let username = getUserDetails().userName.toUpperCase();
function getTodayDate() {
const now = new Date();
const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0');
const day = now.getDate().toString().padStart(2, '0');
return `${year}-${month}-${day}`;
}
// Calculate the maximum "to" date based on the "from" date
function getMaxToDate(fromDate) {
const maxDate = new Date(fromDate);
maxDate.setDate(maxDate.getDate() + 35);
const year = maxDate.getFullYear();
const month = (maxDate.getMonth() + 1).toString().padStart(2, '0');
const day = maxDate.getDate().toString().padStart(2, '0');
return `${year}-${month}-${day}`;
}
const fromDateInput = document.getElementById('fromdate');
const toDateInput = document.getElementById('todate');
// Set the default value of the "from" date input to today's date
fromDateInput.value = getTodayDate();
fromDateInput.min = getTodayDate();
// Initialize the "to" date input's attributes based on the "from" date
toDateInput.value = getTodayDate();
toDateInput.min = getTodayDate();
toDateInput.max = getMaxToDate(fromDateInput.value);
// Update the "to" date input's attributes when the "from" date changes
fromDateInput.addEventListener('change', function() {
toDateInput.min = fromDateInput.value;
toDateInput.max = getMaxToDate(fromDateInput.value);
if (toDateInput.value < fromDateInput.value) {
toDateInput.value = fromDateInput.value;
}
});