source: trunk/workflow/inc/report/includes/js/auxiliares.js @ 5307

Revision 5307, 18.8 KB checked in by pereira.jair, 12 years ago (diff)

Ticket #2416 - Inclusao da nova ferramenta de relatorios do workflow.

Line 
1/**
2 * Funᅵᅵo:          $id(nomeCampo)
3 * Autor:       Ricardo Andre Pikussa
4 * Data:                12/12/2008
5 * Descriᅵᅵo:       Funᅵᅵo utilizada para retornar as propriedades de um campo via getElementById(nomeCampo)
6 * Chamada:             $id('nomeCampo'); ou $id('nomeCampo').value;
7 *     
8 */
9function $id(nomeCampo)
10{
11    return document.getElementById(nomeCampo);
12}
13
14function trim(str){
15    return str.replace(/^\s+|\s+$/g,"");
16}
17
18//gerencia o efeito amarelo que aparece nas mensagens ao usuario
19var tempo_fade;
20function fade(percent,container,topercent) {
21        if(!topercent){
22                topercent = 100;
23        }
24       
25    clearTimeout(tempo_fade);
26   
27    if($id(container)){
28   
29            $id(container).style.backgroundColor = "rgb(100%, 100%, "+percent+"%)";
30           
31            percent += 10;
32           
33            if(percent<=topercent){
34                tempo_fade = setTimeout("fade("+percent+",'"+container+"',"+topercent+")", 100/*ms*/);
35            }
36       
37            if(percent > topercent){
38                $id(container).style.backgroundColor = "#FFFFC0";
39                return true;   
40            }
41    }
42   
43}
44
45//gera a mensagem ao usuario
46function cria_msg_html(container,mensagem){
47    $id(container).innerHTML = "";
48    if(mensagem!=""){
49        $id(container).innerHTML = mensagem;
50        fade(0,container);
51    }
52    return;
53}
54
55// funcao para mudar a cor de background de um campos
56function muda_cor(id_campo){
57        document.getElementById(id_campo).style.backgroundColor = "#FFFFC0";
58}
59// funcao para remover a cor de background de um campos
60function remove_cor(id_campo){
61   
62    if(document.getElementById(id_campo).readOnly == true){
63     
64        document.getElementById(id_campo).style.backgroundColor = "#F0F0F0";
65     
66    }else{
67
68           document.getElementById(id_campo).style.backgroundColor = "";
69           
70        }
71}
72
73//limpa todos os backgrounds dos inputs
74function limpaCores(){
75       
76        for(i=0;i<document.forms.length;i++){
77               
78                for (j=0; j<document.forms[i].elements.length ;j++){
79                       
80                        /* limpando os inputs txt */
81                        if(document.forms[i].elements[j].type == 'text'){
82                                if(document.forms[i].elements[j].id){
83                                        remove_cor(document.forms[i].elements[j].id);
84                                }
85                        }
86                        /* limpando os selects */
87                        if(document.forms[i].elements[j].type == 'select-one'){
88                                if(document.forms[i].elements[j].id){
89                                        remove_cor(document.forms[i].elements[j].id);
90                                }
91                        }
92                        /* limpando os textarea */
93                        if(document.forms[i].elements[j].type == 'textarea'){
94                                if(document.forms[i].elements[j].id){
95                                        remove_cor(document.forms[i].elements[j].id);
96                                }
97                        }
98                       
99                }
100               
101                /* limpando os checkboxes e radios*/
102        ckbox_a_div = document.getElementsByTagName('div');
103               
104                for(x=0;x<ckbox_a_div.length;x++){
105               
106                        if(ckbox_a_div[x].id){
107                                remove_cor(ckbox_a_div[x].id);
108                        }
109                }
110        }
111}
112
113// funcao para criar um div dinamico
114function criarDiv(id, html, width, height, left, top, classe) {
115       
116   var newdiv = document.createElement('div');
117   newdiv.setAttribute('id', id);
118   
119   if (width) {
120       newdiv.style.width = width;
121   }
122   
123   if (height) {
124       newdiv.style.height = height;
125   }
126   
127   if ((left || top) || (left && top)) {
128       newdiv.style.position = "absolute";
129       
130       if (left) {
131           newdiv.style.left = left;
132       }
133       
134       if (top) {
135           newdiv.style.top = top;
136       }
137   }
138   
139   newdiv.style.color = "#643E41";
140   newdiv.style.fontFamily = "Verdana";
141   newdiv.style.fontSize = "12px";
142   newdiv.style.fontWeight = "bold";
143   newdiv.style.verticalAlign = "middle";
144   
145   if (classe) {
146                newdiv.setAttribute('class',classe);
147                alert(classe);
148   }
149   
150   
151   if (html) {
152       newdiv.innerHTML = html;
153   } else {
154       //newdiv.innerHTML = "ops...";
155   }
156   
157   document.body.appendChild(newdiv);
158
159}
160
161// Funᅵᅵo para criar o div de mensagem padrᅵo
162function criaAlerta(mensagem){
163   
164    if(!document.getElementById("mess")){
165               
166        criarDiv('mess', '<table height=\"32\" width=\"100%\" valign=\"middle\"><tr onclick=\"removeDiv(\'mess\');\"><td class="\msg\" width=\"96%\" heigth=\"100%\">&nbsp;<font color=\"#CD0000\">' + mensagem + '</font></td><td width=\"4%\"><img width=\"15\" height=\"15\" src=\"images/X.jpg\"></img></td></tr></table>', '100%', '34', '0', '0');
167        alinhaDiv('mess');
168        id_interval = setInterval("alinhaDiv('mess')",500);
169        fade(0,'mess',80);
170               
171    }else{
172   
173        fade(0,'mess',80);
174    }
175}
176// Funᅵᅵo para remover div de alerta
177function removeAlerta(){
178    removeDiv('mess');
179}
180
181// funcao para remover um div dinamico
182function removeDiv(id){
183       
184        tmp = document.getElementById(id);
185        if(tmp){
186                document.body.removeChild(tmp);
187        }
188}
189
190// funcao para alinhar um div ao topo
191var id_interval ;
192
193function alinhaDiv(id){
194        if(document.getElementById(id)){
195                               
196                if(navigator.appName == "Microsoft Internet Explorer"){
197                        var new_top = document.body.scrollTop;
198                }else{
199                        var new_top = window.pageYOffset;
200                }
201                new_top = parseFloat(new_top);
202               
203                b = new_top;
204       
205                document.getElementById(id).style.marginTop = b+'px';
206               
207        }else{
208                clearInterval(id_interval);
209        }
210}
211
212//funcao para alinhar um div a direita
213var id_interval_dir ;
214
215function alinhaDivDir(id){
216       
217        var tamanho_util = getWidth();
218       
219        document.getElementById(id).style.display = '';
220       
221        if(document.getElementById(id).style.display == ''){
222               
223                document.getElementById(id).style.display = 'none';
224                document.getElementById(id).style.marginLeft = '0px';
225                               
226                if(navigator.appName == "Microsoft Internet Explorer"){
227                        var new_dir = document.body.scrollLeft;
228                }else{
229                        var new_dir = window.pageXOffset;
230                }
231                new_dir = parseFloat(new_dir);
232                tamanho_util = parseFloat(tamanho_util);
233               
234                b = new_dir+tamanho_util-360 ;
235               
236                document.getElementById(id).style.marginLeft = b+'px';
237               
238                document.getElementById(id).style.display = '';
239               
240        }
241}
242
243function retiraAspas (evtKeyPress) {
244   
245        var nTecla=0;
246        if (document.all) {
247       
248                nTecla = evtKeyPress.keyCode;
249
250        } else {
251                nTecla = evtKeyPress.which;
252        }
253        if (nTecla == 34 || nTecla == 39) {
254                return false;
255        } else {
256                return true;
257        }
258}
259
260// Funᅵᅵo para alterar o style width de um selectbox
261function expandirSelect(sel,width) {
262   
263    if(width){
264        sel.style.width = width+'px'; 
265    }else{
266        sel.style.width = 'auto';
267    }
268}
269
270//Detect if the browser is IE or not.
271//If it is not IE, we assume that the browser is NS.
272var IE = document.all?true:false;
273
274//If NS -- that is, !IE -- then set up for mouse capture
275if (!IE) document.captureEvents(Event.MOUSEMOVE);
276
277//Set-up to use getMouseXY function onMouseMove
278//document.onmousemove = getMouseXY;
279
280//Temporary variables to hold mouse x-y pos.s
281var tempX = 0;
282var tempY = 0;
283
284// Funᅵᅵo principal para pegar posiᅵᅵo Y do mouse
285function getMouseY(e) {
286       
287        if (IE) { // grab the x-y pos.s if browser is IE
288               
289                tempY = event.clientY + document.body.scrollTop;
290               
291        }else{  // grab the x-y pos.s if browser is NS
292
293                tempY = e.pageY;
294        } 
295        // catch possible negative values in NS4
296
297        if (tempY < 0){tempY = 0;} 
298        // show the position values in the form named Show
299        // in the text fields named MouseX and MouseY
300        //document.frm.MouseX.value = tempX
301        //document.frm.MouseY.value = tempY
302       
303        return tempY;
304}
305
306// Funᅵᅵo principal para pegar posiᅵᅵo X do mouse
307function getMouseX(e) {
308       
309        if (IE) { // grab the x-y pos.s if browser is IE
310               
311                tempX = event.clientX + document.body.scrollLeft;
312
313        }else{  // grab the x-y pos.s if browser is NS
314
315                tempX = e.pageX;
316        } 
317        // catch possible negative values in NS4
318        if (tempX < 0){tempX = 0;}
319        // show the position values in the form named Show
320        // in the text fields named MouseX and MouseY
321        //document.frm.MouseX.value = tempX
322        //document.frm.MouseY.value = tempY
323       
324        return tempX;
325}
326
327function ListagemExibeOcultaColuna(id_listagem, id_campo){
328
329    var i = 0;
330    var continua = true;
331   
332    while(continua == true){
333
334        if(document.getElementById('td_'+id_campo+'_'+i)){
335
336            if(document.getElementById(id_listagem + '_ck_visivel_' + id_campo).checked == true){
337               
338                        document.getElementById('td_'+id_campo+'_'+i).style.display = '';
339                   
340                }else{
341               
342                        document.getElementById('td_'+id_campo+'_'+i).style.display = 'none';
343                }
344
345            i++;
346           
347        }else{
348           
349            continua = false;
350        }
351    }
352
353    if(document.getElementById('td_tit_'+id_campo)){
354
355        if(document.getElementById(id_listagem+'_ck_visivel_'+id_campo).checked == true){
356           
357            document.getElementById('td_tit_'+id_campo).style.display = '';
358               
359        }else{
360           
361            document.getElementById('td_tit_'+id_campo).style.display = 'none';
362        }
363    }
364
365    if(document.getElementById('total_'+id_campo)){
366
367        if(document.getElementById(id_listagem+'_ck_visivel_'+id_campo).checked == true){
368           
369            document.getElementById('total_'+id_campo).style.display = '';
370               
371        }else{
372           
373            document.getElementById('total_'+id_campo).style.display = 'none';
374        }
375    }
376   
377    i = 1;
378    continua = true;
379
380    while(continua == true){
381
382        if(document.getElementById('subtotal_'+id_campo+'_'+i)){
383
384            if(document.getElementById(id_listagem+ '_ck_visivel_'+id_campo).checked == true){
385               
386                document.getElementById('subtotal_'+id_campo+'_'+i).style.display = '';
387                   
388            }else{
389               
390                document.getElementById('subtotal_'+id_campo+'_'+i).style.display = 'none';
391            }
392
393            i++;
394           
395        }else{
396           
397            if (i == 1) {
398                i++;
399            } else {
400              continua = false;
401            }
402        }
403    }
404
405
406    document.getElementById(id_listagem+'_div_visivel').style.display = '';
407    document.getElementById(id_listagem+'_div_visivel_load').style.display = 'none';
408   
409    //setTimeout("alinhaDivDir('"+id_listagem+"_div_visivel')",1000);
410
411}
412
413function getWidth(){
414
415        if(window.innerWidth){
416                //alert('window.width='+window.innerWidth);
417                return window.innerWidth; /* For non-IE */
418        }
419        if(document.documentElement.clientWidth){
420                //alert('document.element='+document.documentElement.clientWidth);
421                return document.documentElement.clientWidth; /* IE 6+ (Standards Compilant Mode) */
422        }
423        if(document.body.clientWidth){
424                //alert('document.body='+document.body.clientWidth);
425                return document.body.clientWidth; /* IE 4 Compatible */
426        }
427        if(window.screen.width){
428                //alert('screen.width='+window.screen.width);
429                return window.screen.width; /* Others (It is not browser window size, but screen size) */
430        }
431       
432        return false;
433
434}
435
436function ListagemShowHide(event,id_listagem,id){
437
438        //alinhaDivDir(id_listagem + '_div_visivel');
439         
440        var y = getMouseY(event);
441        //var x = getMouseX(event);
442       
443    if(document.getElementById(id_listagem+'_div_visivel').style.display == 'none'){
444       
445        id_interval_dir = setInterval("alinhaDivDir('"+id_listagem+"_div_visivel')",100);
446        //id_interval_dir2 = setInterval("alinhaDivDir('"+id_listagem+"_div_visivel_load')",100);
447       
448        document.getElementById(id_listagem+'_div_visivel').style.display = '';
449
450        document.getElementById(id_listagem+'_div_visivel').style.marginTop = parseInt(y) - 200 + 'px';
451        document.getElementById(id_listagem+'_div_visivel_load').style.marginTop = parseInt(y) -200 + 'px';
452       
453        //document.getElementById(id_listagem+'_div_visivel').style.marginLeft = '2%'; //parseInt(x) -260 + 'px';
454        //document.getElementById(id_listagem+'_div_visivel_load').style.marginLeft = '2%'; //parseInt(x) -260 + 'px';
455       
456        //document.getElementById(id).setAttribute("src","./images/icones/menosTransparente.gif");
457       
458    }else{
459       
460        //alert('limpou intervalo');
461        clearInterval(id_interval_dir);
462        //clearInterval(id_interval_dir2);
463       
464        document.getElementById(id_listagem+'_div_visivel').style.display = 'none';
465        //document.getElementById(id).setAttribute("src","./images/icones/maisTransparente.gif");
466       
467    }
468}
469
470function ListagemSelecionachecks(check,qtdtotal,prefixo){
471       
472        for (var i=0;i<qtdtotal;i++)  {
473                if(document.getElementById(prefixo+i)){
474                        document.getElementById(prefixo+i).checked=check;
475                }
476        }
477}
478
479//FUNᅵᅵES DA COMBO ESPECIAL.
480function CE_pesquisar(idcodigo,idnome,funcao) {
481    var nome = document.getElementById(idnome);
482    var codigo = document.getElementById(idcodigo);
483    var botao = document.getElementById("bt_pesquisar_" + idcodigo);
484    var palavra = nome.value;
485    botao.disabled = true;
486    if (botao.value == 'Pesquisar') {
487        if(palavra != ""){
488            if(palavra.length>2){
489                xajax_CE_pesquisar_combo(idcodigo,idnome,funcao,nome.value);
490                document.getElementById('div_img_pesquisa_' +idcodigo).style.display = "inline";
491            }else{
492                criaAlerta("Digite no mï¿œnimo 3 caracteres para procurar.");
493            }
494        }else{
495                criaAlerta("Digite no mï¿œnimo 3 caracteres para procurar.");
496            document.getElementById('result_pesq_' + idcodigo).innerHTML = "";
497        }
498    } else {
499        CE_bloquear(false,idcodigo,idnome);
500    }
501}
502function CE_selecionar(selecao,idcodigo,idnome){
503    var nome = document.getElementById(idnome);
504    var codigo = document.getElementById(idcodigo);
505    var botao = document.getElementById("bt_pesquisar_" + idcodigo);
506    var funcao_selecionar = document.getElementById(idcodigo + "_funcao_selecionar");
507    var funcao_limpar = document.getElementById(idcodigo + "_funcao_limpar");
508    botao.disabled = false;
509    if(selecao !="|"){
510        var valor = selecao.split("|");
511        codigo.value=valor[0];
512        nome.value=valor[1];
513        CE_bloquear(true,idcodigo,idnome);
514        if (funcao_selecionar.value != "") {
515                eval(funcao_selecionar.value);
516        }
517        document.getElementById('result_pesq_' + idcodigo).innerHTML = "";
518    }else{
519        return false;
520    }
521}
522
523function CE_bloquear(bloqueio,idcodigo,idnome) {
524    var nome = document.getElementById(idnome);
525    var codigo = document.getElementById(idcodigo);
526    var botao = document.getElementById("bt_pesquisar_" + idcodigo);
527    var funcao_limpar = document.getElementById(idcodigo + "_funcao_limpar");
528    if (bloqueio) {
529        nome.style.background = "#F0F0F0";
530        nome.readOnly = true;
531        botao.value = 'Limpar';
532        botao.disabled = false;
533    } else {
534        nome.style.background = "#FFFFFF";
535        codigo.value="";
536        nome.value="";
537        nome.readOnly = false;
538        botao.value = 'Pesquisar';
539        botao.disabled = false;
540        if (funcao_limpar.value != "") {
541                eval(funcao_limpar.value);
542        }
543    }
544}
545
546// Funᅵᅵes e variᅵveis utilizadas para criaᅵᅵo do Help Comment
547var help_offsetTop  = 0;
548var help_offsetLeft = 0;
549
550var lastObj     = false;
551var helpCommentDiv = false;
552
553var MSIE = false;
554if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)MSIE=true;
555
556function mostrarHelpComment(inputObj,msg,lado,titulo){
557
558    if(!helpCommentDiv){
559   
560        criarHelpComment(msg,inputObj,lado,titulo);
561
562    }else{
563
564        if(helpCommentDiv.style.display=='block'){
565       
566            fecharHelpComment();
567
568            if(lastObj == inputObj){
569
570                return false;
571               
572            }else{
573               
574                criarHelpComment(msg,inputObj,lado,titulo);
575            }
576        }
577    }
578}
579function escreveConteudo(msg,titulo){
580
581
582    var calTable = document.createElement('TABLE');
583    calTable.width = '100%';
584    calTable.cellSpacing = '0';
585    helpCommentDiv.appendChild(calTable);
586
587    var calTBody = document.createElement('TBODY');
588    calTable.appendChild(calTBody);
589
590    if(titulo){
591
592        var row = calTBody.insertRow(-1);
593       
594       // var cell = row.insertCell(-1);
595        //cell.align = 'right';
596        //cell.width = '15';
597        //cell.className = 'cell-topo-mensagem';
598       
599        var cell = row.insertCell(-1);
600        cell.innerHTML = titulo;
601        cell.className = 'cell-topo-mensagem';
602       
603        //var cell = row.insertCell(-1);
604        //cell.width = '15';
605        //cell.align = 'right';
606        //cell.innerHTML = '<img OnMouseOver="document.body.style.cursor=\'pointer\';" OnMouseOut="document.body.style.cursor=\'default\';" OnClick="fecharHelpComment(); document.body.style.cursor=\'default\';" src="images/fileclose.gif">';
607        //cell.className = 'cell-topo-mensagem';
608    }
609   
610    var row = calTBody.insertRow(-1);
611    var cell = row.insertCell(-1);
612
613    //if(titulo){
614    //  cell.colSpan = '2';
615    //}
616   
617    cell.innerHTML = msg
618    cell.className = 'cell-mensagem';
619
620}
621
622function getTopPos(inputObj){
623
624    var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
625    while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
626    return returnValue + help_offsetTop;
627}
628
629function getleftPos(inputObj){
630
631    var returnValue = inputObj.offsetLeft;
632    while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
633    return returnValue + help_offsetLeft;
634}
635
636function fecharHelpComment(){
637
638        if(document.getElementById('helpComment')){
639
640                document.body.removeChild(helpCommentDiv);
641        helpCommentDiv = false;
642        document.body.removeChild(helpCommentDivSeta);
643    }
644}
645
646function criarHelpComment(msg,inputObj,lado,titulo){
647
648    lastObj = inputObj;
649   
650    // Configuraᅵᅵo do lado que vai ser desenhado
651    if(lado == ''){
652        alert('Erro ao selecionar lado');
653        return false;
654    }
655   
656    if(lado == 'D'){
657       
658        var divLeftPos = 32;
659        var divTopPos  = 21;
660       
661        var divSetaLeftPos = 20;
662        var divSetaTopPos  = 15;
663       
664        if(titulo){
665                var imgSeta = '<img src="images/hbseta_t.gif">';
666        }else{
667                var imgSeta = '<img src="images/hbseta.gif">';
668        }
669    }
670   
671    if(lado == 'E'){
672       
673        if (MSIE == true){
674               
675                var divLeftPos = -314;
676                var divTopPos  = 21 ;
677               
678        }else{
679       
680                var divLeftPos = -318;
681                var divTopPos  = 21 ;
682        }
683       
684        var divSetaLeftPos = -15;
685        var divSetaTopPos  = 15 ;
686       
687        if(titulo){
688                divLeftPos = divLeftPos + 1;
689                var imgSeta = '<img src="images/hbseta2_t.gif">';
690        }else{
691                var imgSeta = '<img src="images/hbseta2.gif">';
692        }
693    }
694   
695    // Div principal
696    helpCommentDiv = document.createElement('DIV');
697    helpCommentDiv.id = 'helpComment';
698    helpCommentDiv.style.zIndex = 1000;
699
700    document.body.appendChild(helpCommentDiv);
701
702    helpCommentDiv.style.visibility = 'visible';   
703    helpCommentDiv.style.display = 'block';
704    helpCommentDiv.style.left = getleftPos(inputObj) + divLeftPos + 'px';
705    helpCommentDiv.style.top = getTopPos(inputObj) - divTopPos + 'px';
706
707    escreveConteudo(msg,titulo);
708
709    // Div da seta
710    helpCommentDivSeta = document.createElement('DIV');
711    helpCommentDivSeta.id = 'helpCommentSeta';
712    helpCommentDivSeta.style.zIndex = 2000;
713    helpCommentDivSeta.innerHTML = imgSeta;
714
715    document.body.appendChild(helpCommentDivSeta);
716
717    helpCommentDivSeta.style.left = getleftPos(inputObj)  + divSetaLeftPos + 'px';
718    helpCommentDivSeta.style.top = getTopPos(inputObj) - divSetaTopPos + 'px';
719   
720}
Note: See TracBrowser for help on using the repository browser.