-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
154 lines (118 loc) · 4.36 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
var PROFESSORS = [];
var QSL = [];
var isFilterApplied = false;
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
}
rawFile.send(null);
}
function populateQSL(json) {
let series = Object.keys(json).length;
let table = document.querySelector('table.qsl');
QSL = json;
for (let row_index=0; row_index<series; row_index++)
{
let row = document.createElement('tr');
QSL[row_index].forEach((elem, col_index) => {
let col = document.createElement('td');
col.setAttribute('class', elem.class);
col.setAttribute('colspan', elem.colspan);
if (elem.hours != null) {
col.addEventListener('click', e => { openModalDisciplina(row_index, col_index); });
col.innerHTML = `<b>${elem.name}</b></br>${elem.type}</br>${elem.hours}h`;
}
row.appendChild(col);
});
table.appendChild(row);
}
}
function populateProfessors(json) {
let table = document.querySelector('table.professors');
let datalist = document.querySelector('datalist#searchs');
PROFESSORS = json.all
PROFESSORS.forEach((professor, index) => {
let row = document.createElement('tr');
row.addEventListener('click', e => { openModalProfessors(index); });
let name = document.createElement('td');
let titulacao = document.createElement('td');
let vinculo = document.createElement('td');
name.innerHTML = professor.name;
titulacao.innerHTML = professor.titulacao;
vinculo.innerHTML = professor.vinculo;
row.appendChild(name);
row.appendChild(titulacao);
row.appendChild(vinculo);
table.appendChild(row);
addDatalistElement(datalist, professor.name);
});
}
function openModalDisciplina(row, col) {
document.querySelector('h3#disciplina').innerHTML = QSL[row][col].name_full;
document.querySelector('span#serie').innerHTML = QSL[row][col].serie;
document.querySelector('span#type').innerHTML = QSL[row][col].type;
document.querySelector('span#horas').innerHTML = QSL[row][col].hours;
document.querySelector('p#ementa').innerHTML = QSL[row][col].ementa;
document.querySelector('span#creditos').innerHTML = parseInt(QSL[row][col].hours)/15;
document.querySelector('#modal_disciplinas').classList.remove('hidden');
}
function openModalProfessors(index) {
document.querySelector('p#nome').innerHTML = PROFESSORS[index].name;
document.querySelector('ul#disciplinas').innerHTML = '';
PROFESSORS[index].disciplinas.forEach((disciplina) => {
let disciplina_li = document.createElement('li');
disciplina_li.innerHTML = disciplina;
document.querySelector('ul#disciplinas').appendChild(disciplina_li);
});
document.querySelector('#modal_professores').classList.remove('hidden');
}
function closeModal(modal_id) {
document.querySelector(modal_id).classList.add('hidden');
}
function backdropCloseModal(){
let modal = document.querySelector('.modal-container:not(.hidden)');
if(event.path[0] == modal) { modal.classList.add('hidden'); }
}
function addDatalistElement(datalist, element)
{
let option = document.createElement('option');
option.setAttribute('value', element);
datalist.appendChild(option);
}
function search(table_class)
{
if (isFilterApplied) { removeFilter(table_class, false); }
let value = document.querySelector(`input#search-bar.${table_class}`).value.toLowerCase();
if (value.length <= 1) { return; }
let table = document.querySelector(`table.${table_class}`);
for (var i = 1, row; row = table.rows[i]; i++) {
if (row.cells[0].innerHTML.toLowerCase().includes(value) == false) {
row.style.display = 'none';
}
}
isFilterApplied = true;
document.querySelector(`#remove-filter.${table_class}`).style.display = 'block';
}
function removeFilter(table_class, clean_input = true)
{
let table = document.querySelector(`table.${table_class}`);
for (var i = 1, row; row = table.rows[i]; i++) {
row.style.display = 'table-row';
}
isFilterApplied = false;
document.querySelector(`#remove-filter.${table_class}`).style.display = 'none';
if (clean_input) {
cleanInputSearch(table_class);
}
}
function cleanInputSearch(table_class)
{
let search_bar = document.querySelector(`#search-bar.${table_class}`)
search_bar.value = '';
search_bar.focus();
}