-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathui_horario.js
201 lines (186 loc) · 6.12 KB
/
ui_horario.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
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
/**
* @constructor
*/
function UI_horario(id)
{
var self = this;
var dias = [ "Segunda", "Ter\u00e7a", "Quarta", "Quinta", "Sexta", "S\u00e1bado" ];
var horas = [ "07:30", "08:20", "09:10", "10:10", "11:00",
"13:30", "14:20", "15:10", "16:20", "17:10",
"18:30", "19:20", "20:20", "21:10"];
var horas_fim = [ "08:20", "09:10", "10:00", "11:00", "11:50",
"14:20", "15:10", "16:00", "17:10", "18:00",
"19:20", "20:10", "21:10", "22:00"];
var horas_fim_div = [];
var mostrar_sala = false;
var horario = document.getElementById(id);
horario.className = "ui_horario";
array = new Array();
for (var i = 0; i < 6; i++) {
array[i] = new Array();
}
var table = document.createElement("table");
var thead = document.createElement("thead");
var row = document.createElement("tr");
var head = document.createElement("th");
var input = document.createElement("input");
input.title = "mostrar salas";
input.type = "checkbox";
input.onchange = function() {
mostrar_sala = this.checked;
self.show_fim();
self.cb_select();
};
head.appendChild(input);
row.appendChild(head);
for (var i = 0; i < dias.length; i++) {
var head = document.createElement("th");
head.innerHTML = dias[i];
row.appendChild(head);
}
thead.appendChild(row);
table.appendChild(thead);
self.show_fim = function() {
horas_fim_div.forEach(function(div) {
if (mostrar_sala) {
div.style.display = "block";
} else {
div.style.display = "none";
}
});
}
var tbody = document.createElement("tbody");
for (var j = 0; j < horas.length; j++) {
if (j == 5 || j == 10) {
var row = document.createElement("tr");
row.style.height = "4px";
tbody.appendChild(row);
}
var row = document.createElement("tr");
var hora = document.createElement("td");
hora.style.fontSize = "11px";
var div = document.createElement("div");
div.innerHTML = horas[j];
hora.appendChild(div);
var div = document.createElement("div");
div.innerHTML = horas_fim[j];
hora.appendChild(div);
horas_fim_div.push(div);
row.appendChild(hora);
for (var i = 0; i < dias.length; i++) {
var data = document.createElement("td");
data.className = "ui_horario_celula";
data.innerHTML = " ";
if (mostrar_sala) {
var div = document.createElement("div");
div.style.fontSize = "10px";
div.innerHTML = " ";
data.appendChild(div);
}
array[i][j] = data;
row.appendChild(data);
}
tbody.appendChild(row);
}
table.appendChild(tbody);
horario.appendChild(table);
self.show_fim();
var reset = function() {
for (var dia = 0; dia < 6; dia++)
for (var hora = 0; hora < 14; hora++)
clear_cell(dia, hora);
}
var clear_cell = function(dia, hora) {
var cell = array[dia][hora];
cell.innerHTML = " ";
if (mostrar_sala) {
var div = document.createElement("div");
div.style.fontSize = "10px";
div.innerHTML = " ";
cell.appendChild(div);
}
cell.style.backgroundColor = "white";
cell.style.border = "1px solid black";
cell.style.color = "black";
}
var display_cell = function(dia, hora, data) {
var cell = array[dia][hora];
cell.innerHTML = data.text;
if (mostrar_sala) {
var div = document.createElement("div");
div.style.fontSize = "10px";
if (data.sala) {
div.innerHTML = data.sala;
} else {
div.innerHTML = " ";
}
cell.appendChild(div);
}
if (data.fixed)
cell.style.fontWeight = "";
else
cell.style.fontWeight = "bold";
cell.style.backgroundColor = data.bgcolor;
cell.style.color = data.color;
}
function set_toggle(func, onover, onout) {
for (var dia = 0; dia < 6; dia++) {
for (var hora = 0; hora < 14; hora++) {
if (func) {
array[dia][hora].style.cursor = "pointer";
array[dia][hora].onclick = function() { func(this.dia, this.hora); };
array[dia][hora].onmouseover = function() { onover(this.dia, this.hora); };
array[dia][hora].onmouseout = function() { onout(this.dia, this.hora); };
} else {
array[dia][hora].style.cursor = "";
array[dia][hora].onclick = null;
array[dia][hora].onmouseover = null;
array[dia][hora].onmouseout = null;
}
array[dia][hora].dia = dia;
array[dia][hora].hora = hora;
}
}
if (func) {
horario.style.zIndex = "2000";
} else {
horario.style.zIndex = "0";
}
}
/* procedures */
self.set_toggle = set_toggle;
self.display_cell = display_cell;
self.clear_cell = clear_cell;
self.reset = reset;
/* functions */
self.height = function() { return horario.offsetHeight; };
/* callbacks */
self.cb_select = null;
}
var Cell = {
normal: function(d) {
return {
fixed: d.fixed,
text: d.horario.materia.codigo,
sala: d.sala,
bgcolor: d.horario.materia.cor,
color: "black",
};
},
red: function(materia) {
return {
fixed: true,
text: materia,
bgcolor: "red",
color: "black",
};
},
grey: function(materia) {
return {
fixed: false,
text: materia,
bgcolor: "grey",
color: "white",
};
}
};