-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
245 lines (210 loc) · 8.08 KB
/
script2.js
File metadata and controls
245 lines (210 loc) · 8.08 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
$(document).ready(() => {
fetchusername();
fetchcourse();
fetchuserrole();
const body = document.querySelector("body");
const darkLight = document.querySelector("#darkLight");
const sidebar = document.querySelector(".sidebar");
const submenuItems = document.querySelectorAll(".submenu_item");
const sidebarOpen = document.querySelector("#sidebarOpen");
const sidebarClose = document.querySelector(".collapse_sidebar");
const sidebarExpand = document.querySelector(".expand_sidebar");
sidebarOpen.addEventListener("click", () => sidebar.classList.toggle("close"));
$('#semesterDropdown').change(function () {
// Get the selected values
const selectedYear = $('#academicYearDropdown').val();
const selectedSemester = $(this).val(); // 'this' refers to the semester dropdown
// Call the fetchSubjects function to fetch subjects and data
fetchSubjects(selectedYear, selectedSemester);
});
$('#setteacherButton').click(function () {
// Get the selected teacher IDs from the checkboxes
const selectedSubject = $('#subjectDropdown').val();
const selectedTeacherIds = $('input[name="coordinatorCheckbox"]:checked').map(function() {
return $(this).val();
}).get();
// Make an AJAX request to update the teachers as coordinators
$.post('/set-teachers', { name: selectedTeacherIds, courseid: selectedSubject }, function (response) {
if (response.success) {
alert('Teachers set as teachers successfully!');
// You can also update the UI or perform any other actions as needed.
} else {
alert('Failed to set teachers.');
}
});
});
// Add a click event handler for the "Set as Coordinators" button
$('#setCoordinatorButton').click(function () {
// Get the selected teacher IDs from the checkboxes
const selectedSubject = $('#subjectDropdown').val();
const selectedTeacherIds = $('input[name="coordinatorCheckbox"]:checked').map(function() {
return $(this).val();
}).get();
// Make an AJAX request to update the teachers as coordinators
$.post('/set-coordinators', { name: selectedTeacherIds, courseid: selectedSubject }, function (response) {
if (response.success) {
alert('Teachers set as coordinators successfully!');
// You can also update the UI or perform any other actions as needed.
} else {
alert('Failed to set teachers as coordinators.');
}
});
});
// Handle button click
$('.get-data-button').click(function () {
// Get the selected values
const selectedYear = $('#academicYearDropdown').val();
const selectedSemester = $('#semesterDropdown').val();
const selectedSubject = $('#subjectDropdown').val();
const department = $('#deptDropdown').val();
// Make an AJAX request to fetch data based on all three selected values
$.get(`/fetch-data?year=${selectedYear}&semester=${selectedSemester}&subject=${selectedSubject}&department=${department}`, function (data) {
// Handle the received data as needed (e.g., update the UI)
const corData = $('#cor-data');
console.log(data);
corData.empty();
let tableHtml = '<table class="table table-bordered table-centered">';
tableHtml += '<thead><tr>';
tableHtml += '<th>Available Teachers</th>';
tableHtml += '<th>Make Coordinator</th></tr></thead>';
tableHtml += '<tbody>';
data.forEach(data => {
tableHtml += '<tr>';
tableHtml += `<td>${data.User}</td>`;
tableHtml += '<td class="text-center">'; // Center-align the content
tableHtml += `<input type="checkbox" class="form-check-input" id="makeCoordinatorCheckbox_${data.User}" name="coordinatorCheckbox" value="${data.User}">`;
tableHtml += '</td>';
tableHtml += '</tr>';
});
tableHtml += '</tbody></table>';
corData.append(tableHtml);
});
});
$('.get-data2-button').click(function () {
// Get the selected values
const selectedYear = $('#academicYearDropdown').val();
const selectedSemester = $('#semesterDropdown').val();
const selectedSubject = $('#subjectDropdown').val();
const department = $('#deptDropdown').val();
// Make an AJAX request to fetch data based on all three selected values
$.get(`/fetch-data?year=${selectedYear}&semester=${selectedSemester}&subject=${selectedSubject}&department=${department}`, function (data) {
// Handle the received data as needed (e.g., update the UI)
const corData = $('#cor-data');
console.log(data);
corData.empty();
let tableHtml = '<table class="table table-bordered table-centered">';
tableHtml += '<thead><tr>';
tableHtml += '<th>Available Teachers</th>';
tableHtml += '<th>Select as Course Teachers</th></tr></thead>';
tableHtml += '<tbody>';
data.forEach(data => {
tableHtml += '<tr>';
tableHtml += `<td>${data.User}</td>`;
tableHtml += '<td class="text-center">'; // Center-align the content
tableHtml += `<input type="checkbox" class="form-check-input" id="makeCoordinatorCheckbox_${data.User}" name="coordinatorCheckbox" value="${data.User}">`;
tableHtml += '</td>';
tableHtml += '</tr>';
});
tableHtml += '</tbody></table>';
corData.append(tableHtml);
});
});
sidebarClose.addEventListener("click", () => {
sidebar.classList.add("close", "hoverable");
});
sidebarExpand.addEventListener("click", () => {
sidebar.classList.remove("close", "hoverable");
});
sidebar.addEventListener("mouseenter", () => {
if (sidebar.classList.contains("hoverable")) {
sidebar.classList.remove("close");
}
});
sidebar.addEventListener("mouseleave", () => {
if (sidebar.classList.contains("hoverable")) {
sidebar.classList.add("close");
}
});
darkLight.addEventListener("click", () => {
body.classList.toggle("dark");
if (body.classList.contains("dark")) {
document.setI
darkLight.classList.replace("bx-sun", "bx-moon");
} else {
darkLight.classList.replace("bx-moon", "bx-sun");
}
});
// Define a function to fetch subjects based on selected year and semester
function fetchSubjects(selectedYear, selectedSemester) {
$.get(`/subjects?year=${selectedYear}&semester=${selectedSemester}`, function (subjectData) {
const subjectDropdown = $('#subjectDropdown');
subjectDropdown.empty(); // Clear existing .
console.log(subjectData);
subjectDropdown.append('<option value="" disabled selected>Select Subject Code</option>');
subjectData.forEach(subject => {
subjectDropdown.append($('<option></option>').attr('value', subject.co_code).text(subject.co_code));
});
});
}
submenuItems.forEach((item, index) => {
item.addEventListener("click", () => {
item.classList.toggle("show_submenu");
submenuItems.forEach((item2, index2) => {
if (index !== index2) {
item2.classList.remove("show_submenu");
}
});
});
});
if (window.innerWidth < 768) {
sidebar.classList.add("close");
} else {
sidebar.classList.remove("close");
}
});
function fetchusername(){
$.ajax({
url: '/api/get-username',
type: 'GET',
dataType: 'json',
success: function (data) {
const username = data.username;
console.log('Username:', username);
$('#username').text(username);
$('#username1').text(username);
},
error: function (error) {
console.error('Error fetching username', error);
}
});
}
function fetchuserrole(){
$.ajax({
url: '/api/get-userrole',
type: 'GET',
dataType: 'json',
success: function (data) {
const userrole = data.userrole;
console.log('Userrole:', userrole);
$('#userrole').text(userrole);
},
error: function (error) {
console.error('Error fetching userrole', error);
}
});
}
function fetchcourse(){
$.ajax({
url: '/api/get-usercourse',
type: 'GET',
dataType: 'json',
success: function (data) {
const usercourse = data.usercourse;
console.log('Userrole:', usercourse);
$('#course_code').text(usercourse);
},
error: function (error) {
console.error('Error fetching usercourse', error);
}
});
}