-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewerDepartamento.js
266 lines (206 loc) · 8.7 KB
/
ViewerDepartamento.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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import Status from "/Status.js";
import Departamento from "/Departamento.js";
import ViewerError from "/ViewerError.js";
//------------------------------------------------------------------------//
export default class ViewerDepartamento {
#ctrl;
constructor(ctrl) {
this.#ctrl = ctrl;
this.divNavegar = this.obterElemento('divNavegar');
this.divComandos = this.obterElemento('divComandos');
this.divAviso = this.obterElemento('divAviso');
this.divDialogo = this.obterElemento('divDialogo');
this.btPrimeiro = this.obterElemento('btPrimeiro');
this.btAnterior = this.obterElemento('btAnterior');
this.btProximo = this.obterElemento('btProximo');
this.btUltimo = this.obterElemento('btUltimo');
this.btIncluir = this.obterElemento('btIncluir');
this.btExcluir = this.obterElemento('btExcluir');
this.btAlterar = this.obterElemento('btAlterar');
this.btSair = this.obterElemento('btSair');
this.btOk = this.obterElemento('btOk');
this.btCancelar = this.obterElemento('btCancelar');
this.tfSigla = this.obterElemento('tfSigla');
this.tfNome = this.obterElemento('tfNome');
this.tfNumEmpregados = this.obterElemento('tfNumEmpregados');
this.btPrimeiro.onclick = fnBtPrimeiro;
this.btProximo.onclick = fnBtProximo;
this.btAnterior.onclick = fnBtAnterior;
this.btUltimo.onclick = fnBtUltimo;
this.btIncluir.onclick = fnBtIncluir;
this.btAlterar.onclick = fnBtAlterar;
this.btExcluir.onclick = fnBtExcluir;
this.btOk.onclick = fnBtOk;
this.btCancelar.onclick = fnBtCancelar;
}
//------------------------------------------------------------------------//
obterElemento(idElemento) {
let elemento = document.getElementById(idElemento);
if(elemento == null)
throw new ViewerError("Não encontrei um elemento com id '" + idElemento + "'");
// Adicionando o atributo 'viewer' no elemento do Viewer. Isso permitirá
// que o elemento guarde a referência para o objeto Viewer que o contém.
elemento.viewer = this;
return elemento;
}
//------------------------------------------------------------------------//
getCtrl() {
return this.#ctrl;
}
//------------------------------------------------------------------------//
apresentar(pos, qtde, departamento) {
this.configurarNavegacao( pos , qtde );
if(departamento == null) {
this.tfSigla.value = "";
this.tfNome.value = "";
this.tfNumEmpregados.value = "";
this.divAviso.innerHTML = " Número de Departamentos: 0";
} else {
this.tfSigla.value = departamento.getSigla();
this.tfNome.value = departamento.getNome();
this.tfNumEmpregados.value = departamento.getNumEmpregados();
this.divAviso.innerHTML = "Posição: " + pos + " | Número de Departamentos: " + qtde;
}
}
//------------------------------------------------------------------------//
configurarNavegacao(pos, qtde) {
let flagInicio = pos <= 1;
let flagFim = pos == qtde;
this.btPrimeiro.disabled = flagInicio;
this.btUltimo.disabled = flagFim;
this.btProximo.disabled = flagFim;
this.btAnterior.disabled = flagInicio;
this.btIncluir.title = "Inicia a inclusão de um novo departamento";
this.btSair.title = "Encerra a aplicação";
//
// Atribuo um hint aos botões Primeiro e Anterior, caso estejam habilitados
//
if(!flagInicio) {
this.btPrimeiro.title = "Apresenta o primeiro departamento da lista";
this.btAnterior.title = "Apresenta o departamento anterior da lista";
}
else {
this.btPrimeiro.title = "";
this.btAnterior.title = "";
}
//
// Atribuo um hint aos botões Último e Próximo, caso estejam habilitados
//
if(!flagFim) {
this.btUltimo.title = "Apresenta o último departamento da lista";
this.btProximo.title = "Apresenta o próximo departamento da lista";
}
else {
this.btUltimo.title = "";
this.btProximo.title = "";
}
//
// Atribuo um hint aos botões Alterar e Excluir, caso estejam habilitados
//
if(pos != 0) {
this.btAlterar.disabled = false;
this.btExcluir.disabled = false;
this.btAlterar.title = "Habilita a alteração do departamento em questão";
this.btExcluir.title = "Inicia os procedimentos para exclusão do departamento em questão";
}
else {
this.btAlterar.disabled = true;
this.btExcluir.disabled = true;
this.btAlterar.title = "";
this.btExcluir.title = "";
}
}
//------------------------------------------------------------------------//
statusEdicao(operacao) {
this.divNavegar.hidden = true;
this.divComandos.hidden = true;
this.divDialogo.hidden = false;
if(operacao != Status.EXCLUINDO) {
this.tfNome.disabled = false;
this.tfNumEmpregados.disabled = false;
this.divAviso.innerHTML = "";
} else {
this.divAviso.innerHTML = "Deseja excluir este registro?";
}
if(operacao == Status.INCLUINDO) {
this.tfSigla.disabled = false;
this.tfSigla.value = "";
this.tfNome.value = "";
this.tfNumEmpregados.value = "";
}
}
//------------------------------------------------------------------------//
statusApresentacao() {
this.divNavegar.hidden = false;
this.divComandos.hidden = false;
this.divDialogo.hidden = true;
this.tfSigla.disabled = true;
this.tfNome.disabled = true;
this.tfNumEmpregados.disabled = true;
}
}
//------------------------------------------------------------------------//
// CALLBACKs para os Botões
//------------------------------------------------------------------------//
function fnBtPrimeiro() {
// Aqui, o 'this' é o objeto Button. Eu adicionei o atributo 'viewer'
// no botão para poder executar a instrução abaixo.
this.viewer.getCtrl().apresentarPrimeiro();
}
//------------------------------------------------------------------------//
function fnBtProximo() {
// Aqui, o 'this' é o objeto Button. Eu adicionei o atributo 'viewer'
// no botão para poder executar a instrução abaixo.
this.viewer.getCtrl().apresentarProximo();
}
//------------------------------------------------------------------------//
function fnBtAnterior() {
// Aqui, o 'this' é o objeto Button. Eu adicionei o atributo 'viewer'
// no botão para poder executar a instrução abaixo.
this.viewer.getCtrl().apresentarAnterior();
}
//------------------------------------------------------------------------//
function fnBtUltimo() {
// Aqui, o 'this' é o objeto Button. Eu adicionei o atributo 'viewer'
// no botão para poder executar a instrução abaixo.
this.viewer.getCtrl().apresentarUltimo();
}
//------------------------------------------------------------------------//
function fnBtIncluir() {
// Aqui, o 'this' é o objeto Button. Eu adicionei o atributo 'viewer'
// no botão para poder executar a instrução abaixo.
this.viewer.getCtrl().iniciarIncluir();
}
//------------------------------------------------------------------------//
function fnBtAlterar() {
// Aqui, o 'this' é o objeto Button. Eu adicionei o atributo 'viewer'
// no botão para poder executar a instrução abaixo.
this.viewer.getCtrl().iniciarAlterar();
}
//------------------------------------------------------------------------//
function fnBtExcluir() {
// Aqui, o 'this' é o objeto Button. Eu adicionei o atributo 'viewer'
// no botão para poder executar a instrução abaixo.
this.viewer.getCtrl().iniciarExcluir();
}
//------------------------------------------------------------------------//
function fnBtOk() {
const sigla = this.viewer.tfSigla.value;
const nome = this.viewer.tfNome.value;
const numEmpregados = parseInt(this.viewer.tfNumEmpregados.value,10);
// Como defini que o método "efetivar" é um dos métodos incluir, excluir ou alterar
// não estou precisando colocar os ninhos de IF abaixo.
this.viewer.getCtrl().efetivar(sigla, nome, numEmpregados);
// if(this.viewer.getCtrl().getStatus() == Status.INCLUINDO) {
// this.viewer.getCtrl().incluir(matricula, cpf, nome, email, telefone);
//} else if(this.viewer.getCtrl().getStatus() == Status.ALTERANDO) {
// this.viewer.getCtrl().alterar(matricula, cpf, nome, email, telefone);
//} else if(this.viewer.getCtrl().getStatus() == Status.EXCLUINDO) {
// this.viewer.getCtrl().excluir(matricula, cpf, nome, email, telefone);
//}
}
//------------------------------------------------------------------------//
function fnBtCancelar() {
this.viewer.getCtrl().cancelar();
}
//------------------------------------------------------------------------//