1 | <!-- |
---|
2 | //Variavel de uso do objeto a ser utilizado |
---|
3 | function ObjetoAjax(){ |
---|
4 | this.URL = 'ajx_listas.php'; |
---|
5 | this.Dados = null; |
---|
6 | this.Metodo = 'POST'; |
---|
7 | this.Tratamento = null; |
---|
8 | this.Assincrono = true; |
---|
9 | this.ValorRetorno = ""; |
---|
10 | this.Manipulador = ""; |
---|
11 | this.NumeroListas = 0; |
---|
12 | } |
---|
13 | |
---|
14 | ObjetoAjax.prototype.Action = function(){ |
---|
15 | //window.alert('Em Action com arguments[0] => ' + arguments[0]); |
---|
16 | window.setTimeout("CentralizarDiv(document.getElementById('carregando'))", 10); |
---|
17 | window.setTimeout("Ajax.Executar('" + arguments[0] + "', " + arguments[1] + ")", 300); |
---|
18 | } |
---|
19 | |
---|
20 | ObjetoAjax.prototype.Cancel = function(){ |
---|
21 | if (this.Manipulador.readyState != 4) |
---|
22 | this.Manipulador.abort(); |
---|
23 | } |
---|
24 | |
---|
25 | //Funcao principal: aciona uma URL passada, |
---|
26 | //postando informações para processamento via HTTP Post |
---|
27 | ObjetoAjax.prototype.Executar = function(){ |
---|
28 | this.Dados = arguments[0]; |
---|
29 | this.Tratamento = arguments[1]; |
---|
30 | |
---|
31 | if (window.XMLHttpRequest){ |
---|
32 | try { |
---|
33 | this.Manipulador = new XMLHttpRequest(); |
---|
34 | } catch (e) {} |
---|
35 | } |
---|
36 | else if (window.ActiveXObject){ |
---|
37 | try { |
---|
38 | this.Manipulador = new ActiveXObject("Msxml2.XMLHTTP"); |
---|
39 | } catch (e) { |
---|
40 | try { |
---|
41 | this.Manipulador = new ActiveXObject("Microsoft.XMLHTTP"); |
---|
42 | } catch (e) {} |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | if (!this.Manipulador) { |
---|
47 | window.alert('Erro -> Falha no processo de criação de instância XMLHTTP'); |
---|
48 | return false; |
---|
49 | } |
---|
50 | else { |
---|
51 | document.getElementById('status').innerHTML += 'Inicializando solicitação HTTP ...\n\r'; |
---|
52 | this.Manipulador.onreadystatechange = this.Tratamento; |
---|
53 | this.Manipulador.open(this.Metodo,this.URL,this.Assincrono); |
---|
54 | this.Manipulador.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); |
---|
55 | this.Manipulador.send(this.Dados); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | function CancelarOperacao(){ |
---|
61 | Ajax.Cancel(); |
---|
62 | document.getElementById('status').value += '[ATENÇÃO] -> Requisição HTTP interrompida pelo usuário\n'; |
---|
63 | document.getElementById('carregando').style.display = 'none'; |
---|
64 | } |
---|
65 | |
---|
66 | function CarregarLista(){ |
---|
67 | //Testa se já carregou os dados |
---|
68 | if(Ajax.Manipulador.readyState == 4){ |
---|
69 | //Testa se a resposta da solicitação está OK(200) |
---|
70 | if(Ajax.Manipulador.status == 200){ |
---|
71 | Ajax.ValorRetorno = Ajax.Manipulador.responseText; |
---|
72 | //window.alert('Teste:' + Ajax.ValorRetorno.substr(0,5) + '\n' + typeof(Ajax.ValorRetorno)); |
---|
73 | if (Ajax.ValorRetorno.substr(0,4) == 'ERRO') |
---|
74 | var objJS = null; |
---|
75 | else |
---|
76 | var objJS = eval(Ajax.ValorRetorno); |
---|
77 | |
---|
78 | if ((objJS != null) && (typeof(objJS) == 'object')){ |
---|
79 | document.getElementById('status').value += 'Encontrados ' + eval(Ajax.ValorRetorno).length+ ' registros para "' + Ajax.Dados + '"\n'; |
---|
80 | objJS.sort(); |
---|
81 | //window.alert('Lista caregada: ' + objJS.length + ' registros mapeados'); |
---|
82 | MontarLista(objJS, Ajax.Dados); |
---|
83 | } |
---|
84 | else{ |
---|
85 | if(Ajax.ValorRetorno != "") |
---|
86 | document.getElementById('status').value += Ajax.Manipulador.responseText + "\n"; |
---|
87 | else |
---|
88 | document.getElementById('status').value += "Nenhuma lista RHDS encontrada.\n"; |
---|
89 | } |
---|
90 | } |
---|
91 | else { |
---|
92 | document.getElementById('status').value += 'Problema de comunicação: ' + Ajax.Manipulador.statusText + "\n"; |
---|
93 | } |
---|
94 | // document.getElementById('preloader').style.visibility = 'hidden'; |
---|
95 | } |
---|
96 | // else |
---|
97 | //document.getElementById('preloader').style.visibility = 'visible'; |
---|
98 | } |
---|
99 | |
---|
100 | function MontarLista(){ |
---|
101 | //window.alert('Em montar listas:' + Ajax.Dados); |
---|
102 | if (Ajax.Dados.indexOf('listaid') != -1){ |
---|
103 | var lista = Ajax.Dados.split("&")[1].split("=")[1]; |
---|
104 | var sublista = true; |
---|
105 | if (document.getElementById(lista).style.display == 'block'){ |
---|
106 | if (Ajax.Dados.indexOf('expresso') != -1) |
---|
107 | var listapai = 'l_expresso'; |
---|
108 | else |
---|
109 | var listapai = 'l_notes'; |
---|
110 | var spanlista = document.getElementById(listapai).getElementsByTagName('span'); |
---|
111 | |
---|
112 | var spanlista = document.getElementById(listapai).getElementsByTagName('span'); |
---|
113 | for (var k=0; k<spanlista.length; k++){ |
---|
114 | //document.getElementById('status').value += 'Lista pai = "' + spanlista[k].innerHTML + '" -x- sublista = "' + lista + '"\n'; |
---|
115 | if (spanlista[k].innerHTML == lista){ |
---|
116 | spanlista[k].style.backgroundColor = ''; |
---|
117 | break; |
---|
118 | } |
---|
119 | } |
---|
120 | document.getElementById(lista).style.display = 'none'; |
---|
121 | CancelarOperacao(); |
---|
122 | return; |
---|
123 | } |
---|
124 | if (Ajax.Dados.indexOf('expresso') != -1) |
---|
125 | var listapai = 'l_expresso'; |
---|
126 | else |
---|
127 | var listapai = 'l_notes'; |
---|
128 | var spanlista = document.getElementById(listapai).getElementsByTagName('span'); |
---|
129 | for (var k=0; k<spanlista.length; k++){ |
---|
130 | //document.getElementById('status').value += 'Lista pai = "' + spanlista[k].innerHTML + '" -x- sublista = "' + lista + '"\n'; |
---|
131 | if (spanlista[k].innerHTML == lista){ |
---|
132 | spanlista[k].style.backgroundColor = 'rgb(238,238,0)'; |
---|
133 | break; |
---|
134 | } |
---|
135 | else |
---|
136 | spanlista[k].style.backgroundColor = ''; |
---|
137 | } |
---|
138 | } |
---|
139 | else{ |
---|
140 | if (Ajax.Dados.indexOf('expresso') != -1) |
---|
141 | var lista = 'l_expresso'; |
---|
142 | else |
---|
143 | var lista = 'l_notes'; |
---|
144 | var sublista = false; |
---|
145 | } |
---|
146 | //window.alert('Motar Lista = ' + lista); |
---|
147 | LimparListagem(document.getElementById(lista)); |
---|
148 | |
---|
149 | if (arguments[0].length > 0){ |
---|
150 | //Atribui os valores para os contadores de itens de lista |
---|
151 | if(Ajax.Dados.split("&")[0].split("=")[1] == 'expresso') |
---|
152 | document.getElementById('c_expresso').value = arguments[0].length; |
---|
153 | else |
---|
154 | document.getElementById('c_notes').value = arguments[0].length; |
---|
155 | |
---|
156 | var strHTML = ""; |
---|
157 | for (var k=0; k < arguments[0].length; k++){ |
---|
158 | if (sublista){ |
---|
159 | //Para sublistas do expresso, basta verificar se começa com 'lista*' |
---|
160 | if (arguments[0][k].substr(0,5) == 'lista'){ |
---|
161 | strHTML += "<span onclick=\"Ajax.Action('lista=expresso&listaid=" + arguments[0][k].split("@")[0] + "', CarregarLista);\">" + arguments[0][k] + '</span><br/>\n'; |
---|
162 | strHTML += '<div id="'+ arguments[0][k] +'" style="display: none; margin-left: 20px;"></div>'; |
---|
163 | } |
---|
164 | //Para sublistas do notes, tem outra sintaxe de identificacao (primeiro, confere se há delimitadores underscore a esquerda do nome da lista) |
---|
165 | else if(arguments[0][k].split("@")[0].indexOf("_") != -1){ |
---|
166 | //Verifica se o último digito antes da arroba é numérico |
---|
167 | var ultimo_d = arguments[0][k].split("@")[0].charAt(arguments[0][k].split("@")[0].length -1); |
---|
168 | var er = /[0-9]/; |
---|
169 | if(er.test(ultimo_d)){ |
---|
170 | var sublistaid1 = arguments[0][k].split("@")[0].replace("_"," ","g").replace(" ", " ", "g"); |
---|
171 | var sublistaid2 = sublistaid1.split(" "); |
---|
172 | sublistaid3 = ""; |
---|
173 | for (var x=0; x < sublistaid2.length-1; x++){ |
---|
174 | sublistaid3 += sublistaid2[x] + " "; |
---|
175 | } |
---|
176 | sublistaid3 = sublistaid3.substr(0, sublistaid3.length-1) + "_" + sublistaid2[x]; |
---|
177 | } |
---|
178 | //Se não for numérico, apenas substitui os sublinhados por espaços em branco |
---|
179 | else{ |
---|
180 | var sublistaid1 = arguments[0][k].split("@")[0].replace("_"," ","g").replace(" ", " ", "g"); |
---|
181 | sublistaid3 = sublistaid1; |
---|
182 | document.getElementById('c_notes').value = k + 1; |
---|
183 | } |
---|
184 | strHTML += "<span onclick=\"Ajax.Action('lista=notes&listaid=" + sublistaid3 + "', CarregarLista);\">" + arguments[0][k] + '</span><br/>\n'; |
---|
185 | strHTML += '<div id="'+ arguments[0][k] +'" style="display: none; margin-left: 20px;"></div>'; |
---|
186 | } |
---|
187 | else |
---|
188 | strHTML += '<span style="color: rgb(0,0,128)">' + arguments[0][k] + '</span><br/>\n'; |
---|
189 | |
---|
190 | } |
---|
191 | //Para as listas padrão |
---|
192 | else{ |
---|
193 | if (lista == 'l_notes') |
---|
194 | strHTML += '<input type="checkbox" name="ch_' + arguments[0][k] + '" id="ch_' + arguments[0][k] + '" value="' + arguments[0][k] + '"/>'; |
---|
195 | |
---|
196 | strHTML += "<span onclick=\"Ajax.Action('lista=" + lista.split("_")[1] + "&listaid=" + arguments[0][k] + "', CarregarLista);\">" + arguments[0][k] + '</span><br/>\n'; |
---|
197 | strHTML += '<div id="'+ arguments[0][k] +'" style="display: none; margin-left: 20px;"></div>'; |
---|
198 | } |
---|
199 | } |
---|
200 | document.getElementById(lista).innerHTML = strHTML; |
---|
201 | document.getElementById(lista).style.display = (document.getElementById(lista).style.display == 'none') ? 'block' : ''; |
---|
202 | if (lista == 'l_expresso'){ |
---|
203 | window.setTimeout("CentralizarDiv(document.getElementById('carregando'))", 10); |
---|
204 | Ajax.Executar('lista=notes', CarregarLista); |
---|
205 | } |
---|
206 | } |
---|
207 | else |
---|
208 | document.getElementById(lista).innerHTML += '<span>Não constam dados para a lista</span><br>'; |
---|
209 | document.getElementById('carregando').style.display = 'none'; |
---|
210 | if (Ajax.Dados.indexOf('expresso') != -1) |
---|
211 | CompararListas('expresso',lista); |
---|
212 | else |
---|
213 | CompararListas('notes',lista); |
---|
214 | } |
---|
215 | |
---|
216 | function BuscarIntegrantes(combo){ |
---|
217 | parametros = 'lista=' + combo.id.split("_")[1] + ' &listaid=' + combo.value; |
---|
218 | Ajax.Executar(parametros, ExibirIntegrantesLista); |
---|
219 | } |
---|
220 | |
---|
221 | function ExibirIntegrantesLista(){ |
---|
222 | //Testa se já carregou os dados |
---|
223 | if(Ajax.Manipulador.readyState == 4){ |
---|
224 | //Testa se a resposta da solicitação está OK(200) |
---|
225 | if(Ajax.Manipulador.status == 200){ |
---|
226 | Ajax.ValorRetorno = Ajax.Manipulador.responseText; |
---|
227 | if (Ajax.ValorRetorno.substr(0,4) == 'ERRO') |
---|
228 | var objJS = null; |
---|
229 | else |
---|
230 | var objJS = eval(Ajax.ValorRetorno); |
---|
231 | |
---|
232 | if ((objJS != null) && (typeof(objJS) == 'object')){ |
---|
233 | //document.getElementById('status').innerHTML += '<span style="color: rgb(0,191,255);">Encontradas <b>' + eval(Ajax.ValorRetorno).length+ '</b> listas para o critério "' + Ajax.Dados + '".</span><br>'; |
---|
234 | //window.alert('OK em ExibirIntegrantesLista' + '\n' + objJS.length + ' itens de email localizados para a lista selecionada.' ); |
---|
235 | objJS.sort(); |
---|
236 | MontarListaIntegrantes(objJS, Ajax.Dados); |
---|
237 | } |
---|
238 | else{ |
---|
239 | if(Ajax.ValorRetorno != "") |
---|
240 | document.getElementById('status').innerHTML += Ajax.Manipulador.responseText; |
---|
241 | else |
---|
242 | document.getElementById('status').innerHTML += '<span style="color: red;">Nenhuma lista RHDS encontrada</span><br>'; |
---|
243 | } |
---|
244 | } |
---|
245 | else { |
---|
246 | document.getElementById('status').innerHTML += '<span style="color: red;">Problema de comunicação: ' + Ajax.Manipulador.statusText + '</span><br>'; |
---|
247 | } |
---|
248 | } |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | function CentralizarDiv(object){ |
---|
253 | pagina = getPageSize(); |
---|
254 | obj = findPos(object); |
---|
255 | object.style.left = (parseInt(pagina[0] / 2) -100)+ "px"; |
---|
256 | object.style.top = (parseInt(pagina[1] / 2 ) -45)+ "px"; |
---|
257 | object.style.display = 'block'; |
---|
258 | } |
---|
259 | |
---|
260 | function findPos(obj) { |
---|
261 | var curleft = curtop = 0; |
---|
262 | if (obj.offsetParent) { |
---|
263 | curleft = obj.offsetLeft |
---|
264 | curtop = obj.offsetTop |
---|
265 | while (obj = obj.offsetParent) { |
---|
266 | curleft += obj.offsetLeft |
---|
267 | curtop += obj.offsetTop |
---|
268 | } |
---|
269 | } |
---|
270 | return [curleft,curtop]; |
---|
271 | } |
---|
272 | |
---|
273 | function getPageSize() { |
---|
274 | var myWidth = 0, myHeight = 0; |
---|
275 | if( typeof( window.innerWidth ) == 'number' ) { |
---|
276 | //Non-IE |
---|
277 | myWidth = window.innerWidth; |
---|
278 | myHeight = window.innerHeight; |
---|
279 | } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { |
---|
280 | //IE 6+ in 'standards compliant mode' |
---|
281 | myWidth = document.documentElement.clientWidth; |
---|
282 | myHeight = document.documentElement.clientHeight; |
---|
283 | } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { |
---|
284 | //IE 4 compatible |
---|
285 | myWidth = document.body.clientWidth; |
---|
286 | myHeight = document.body.clientHeight; |
---|
287 | } |
---|
288 | return[myWidth,myHeight]; |
---|
289 | } |
---|
290 | |
---|
291 | function CarregarListas(){ |
---|
292 | Ajax.Action('lista=expresso', CarregarLista); |
---|
293 | } |
---|
294 | |
---|
295 | function LimparListagem(objDiv){ |
---|
296 | objDiv.innerHTML = ""; |
---|
297 | } |
---|
298 | |
---|
299 | function LimparConsole(){ |
---|
300 | document.getElementById('status').value = ''; |
---|
301 | } |
---|
302 | |
---|
303 | function AdicionarListasNotes(){ |
---|
304 | var inputs = document.getElementById('l_notes').getElementsByTagName('input'); |
---|
305 | var vetListas = new Array(); |
---|
306 | |
---|
307 | for (var j=0; j < inputs.length; j++){ |
---|
308 | if (inputs[j].checked){ |
---|
309 | vetListas.push(inputs[j].value); |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | //Se o usuário marcou alguma lista do notes para acionar ao rhds... |
---|
314 | if (vetListas.length > 0){ |
---|
315 | document.getElementById('proclistas').value = ""; |
---|
316 | for (var l=0; l < vetListas.length; l++){ |
---|
317 | document.getElementById('proclistas').value += vetListas[l] + "\n"; |
---|
318 | } |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | function Resetar(){ |
---|
323 | document.getElementById('l_expresso').innerHTML = ""; |
---|
324 | document.getElementById('l_notes').innerHTML = ""; |
---|
325 | document.getElementById('status').value += "------------------------------------------\nConsole Reinicializado\n------------------------------------------\n"; |
---|
326 | } |
---|
327 | |
---|
328 | function CompararListas(){ |
---|
329 | if ((arguments[0] != 'undefined') && (arguments[1] != 'undefined')){ |
---|
330 | if (arguments[0] == 'expresso'){ |
---|
331 | Listas["expresso"] = arguments[1]; |
---|
332 | } |
---|
333 | else if(arguments[0] == 'notes') { |
---|
334 | Listas["notes"] = arguments[1]; |
---|
335 | } |
---|
336 | |
---|
337 | if((Listas['expresso'] != null) && (Listas['notes'] != null)){ |
---|
338 | var oExpresso = document.getElementById(Listas['expresso']).getElementsByTagName('span'); |
---|
339 | var oNotes = document.getElementById(Listas['notes']).getElementsByTagName('span'); |
---|
340 | var nExpresso = document.getElementById(Listas['expresso']).getElementsByTagName('span').length; |
---|
341 | var nNotes = document.getElementById(Listas['notes']).getElementsByTagName('span').length; |
---|
342 | var n_iguais = 0; |
---|
343 | var c_expresso = 0; |
---|
344 | |
---|
345 | for (var i=0; i<nExpresso; i++){ |
---|
346 | if (oExpresso[i].innerHTML.split("@")[0].substr(0,5) != 'lista'){ |
---|
347 | c_expresso++; |
---|
348 | for (var j=0; j<nNotes; j++){ |
---|
349 | if (oExpresso[i].innerHTML.split("@")[0] == oNotes[j].innerHTML.split("@")[0]){ |
---|
350 | n_iguais++; |
---|
351 | break; |
---|
352 | } |
---|
353 | } |
---|
354 | document.getElementById('c_analisador').value = ((n_iguais * 100) / c_expresso); |
---|
355 | } |
---|
356 | else |
---|
357 | document.getElementById('c_analisador').value = ''; |
---|
358 | } |
---|
359 | //window.alert('Iguais:' + n_iguais + '\nListas Ex:' + c_expresso); |
---|
360 | //window.alert('Similaridade de ' + ((n_iguais * 100) / c_expresso) + '% de expresso para notes.'); |
---|
361 | |
---|
362 | } |
---|
363 | } |
---|
364 | } |
---|
365 | |
---|
366 | function ExportarAnalise(){ |
---|
367 | var strvalor = document.getElementById('proclistas').value.split("\n"); |
---|
368 | var novostr= ""; |
---|
369 | for (var i=0; i<strvalor.length-1; i++){ |
---|
370 | novostr += strvalor[i] + '|'; |
---|
371 | } |
---|
372 | var strdados = 'listasproc=' + novostr; |
---|
373 | Ajax.Action(strdados, RetornoAnaliseListas); |
---|
374 | } |
---|
375 | |
---|
376 | function RetornoAnaliseListas(){ |
---|
377 | //Testa se já carregou os dados |
---|
378 | if(Ajax.Manipulador.readyState == 4){ |
---|
379 | //Testa se a resposta da solicitação está OK(200) |
---|
380 | if(Ajax.Manipulador.status == 200){ |
---|
381 | Ajax.ValorRetorno = Ajax.Manipulador.responseText; |
---|
382 | window.alert('Tarefa agendada com êxito!\n' + Ajax.ValorRetorno); |
---|
383 | DesativarListasProcessadas(); |
---|
384 | CancelarOperacao(); |
---|
385 | } |
---|
386 | else { |
---|
387 | window.alert('Problema de comunicação: ' + Ajax.Manipulador.statusText); |
---|
388 | CancelarOperacao(); |
---|
389 | } |
---|
390 | } |
---|
391 | } |
---|
392 | |
---|
393 | function DesativarListasProcessadas(){ |
---|
394 | var strCampos = Ajax.Dados.split("=")[1].split("|"); |
---|
395 | for (var i=0; i<strCampos.length-1; i++){ |
---|
396 | document.getElementById('ch_' + strCampos[i]).readOnly = true; |
---|
397 | document.getElementById('ch_' + strCampos[i]).disabled = true; |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | function ExibeStatus(){ |
---|
402 | document.getElementById('status_painel').style.display = (arguments[0] == 'exibe') ? 'block' : 'none'; |
---|
403 | } |
---|
404 | |
---|
405 | var Ajax = new ObjetoAjax(); |
---|
406 | var Listas = new Array(); |
---|
407 | --> |
---|