var tr_selecionado = ""; //tr_selecionado n�o � �til var psq_url = ""; // linux: n�o � �til var btn_confirm = ""; var win_grid; var a_nos = new Array(); // array de nos; Browser = navigator.appName; function cad_pesquisa(f) { /* Desabilita o form de cadastro e habilita o form de pesquisa */ doc = f.ownerDocument ? f.ownerDocument : window.document; } function psq_carrega_resultado() { form = document.forms[0]; psq_url = carrega_valor_form_psq('psq_resultado'); resultado = exec_ajax_sincrono(psq_url); resultado = resultado.replace(/\+/g, " "); // Resolve o problema dos acentos resultado = unescape(resultado); // Resolve o problema dos acentos document.getElementById('psq_resultado').innerHTML = resultado; // document.getElementById('psq_menu').style.display = "block"; // document.getElementById('psq_resultado').style.display = "block"; // document.getElementById('psq_cadastro').style.display = "none"; resultado = false; } function psq_carrega_cadastro(str_id) { psq_url = '?op=dados_xml'; if (str_id) psq_url = psq_url + '&' + str_id; resultado = exec_ajax_sincrono(psq_url, 'xml'); f = document.getElementById('frm_cadastro'); if (!f) { f = document.getElementById('div_cadastro'); } get_dados_xml(f, resultado); atualiza_botoes(f); win_psq = document.getElementById('win_psq'); if (win_psq) win_psq.close(); else { // Vai para a aba de cadastro //$("#div_aba_cadastro").parents('div').eq(1).triggerTab(2); } } function btn_sair() { /* document.getElementById('psq_menu').style.display = "block"; document.getElementById('psq_resultado').style.display = "block"; document.getElementById('psq_cadastro').style.display = "none"; */ } function cad_salva(f, file) { var doc = f.ownerDocument ? f.ownerDocument : window.document; var pos = doc.getElementById('nav_pos').value; if (pos == "") pos = 0; pos = parseInt(pos); // Verifica se foi passado o arquivo senao assume index.php if (!file) file = 'index.php'; resultado = envia_form(f, file, 'salvar'); // acentos var r = explode(resultado, "&"); btn_confirm = ""; if (r[0] != 'ok') { //document.getElementById("cad_mens_text").innerHTML= resultado; if (r[0] == 'simnao') { Ext.MessageBox.show({ title: r[1], //tem que melhorar o msg msg: r[2], buttons: Ext.MessageBox.YESNO, //quais bottons vai ter fn: cad_salva_confirm, //nome da funcao parametros: {//parametros que ele vai ultilizar OBS:parametros eu q criei form: f, file: file }, icon: Ext.MessageBox.QUESTION //imagem que mostra de informa��o }); // Ext.MessageBox.confirm(r[1], r[2], cad_salva_confirm); } else { toastr.remove(); toastr.error(r[0]); } } else { // Carrega de acordo com o Id passado if (r[1]) { xml = exec_ajax_sincrono(file + '?op=dados_xml&id=' + r[1], 'xml'); //auditoria(f,xml,r[1],""); get_dados_xml(f, xml); } else { nav_carrega_form(f, pos, "", "", file); } // document.getElementById("div_cad_mens").style.display= 'block'; //document.getElementById("cad_mens_btn_ok").focus(); msg = "Salvo com sucesso."; if (r[2]) { msg = r[2]; } toastr.remove(); toastr.success("Salvo com sucesso!"); } atualiza_botoes(f); if (r[0] != 'ok') { return false; } else { setTimeout(atualiza_div_msg, 5000, doc, ''); return true; } } function envia_form(f, file, op) { // Verifica se foi passado o arquivo senao assume index.php if (!file) file = 'index.php'; // Busca todos os campos do f var parameters = carrega_valor_form(f, op); var url = file + '?op=' + op + '&btn_confirm=' + btn_confirm; resultado = exec_ajax_sincrono(url, 'texto', parameters); resultado = resultado.replace(/\+/g, " "); // Resolve o problema resultado = unescape(resultado); // Resolve o problema dos return resultado; } function atualiza_div_msg(form, msg, display) { var cont; if (form) { var div_msg = ""; if (Browser.indexOf('Internet Explorer') > 0) { div_msg = form.ownerDocument.getElementsByName('div_msg'); } else { div_msg = form.getElementsByClassName('div_msg'); } for (cont = 0; cont < div_msg.length; cont++) { if (cont >= 0) { div_msg[cont].innerHTML = msg; div_msg[cont].style.display = display ? display : "block"; } } } } function cad_salva_confirm(btn, text, opt) { btn_confirm = btn; if (btn == 'yes') cad_salva(opt.parametros.form, opt.parametros.file); } function verifica_alteracao(doc) { var tela_atualizada = doc.getElementById('tela_atualizada'); var campos = doc.getElementsByName('anterior'); var i = 0; var valor = ""; var nome_campo = ""; var atualizar = false; var campo = ""; var id = 0; var campo_id_nome = 1;//para ter um valor if (tela_atualizada) { if (tela_atualizada.value == "false") { // if(campos.length>0){ // campo_id_nome=campos[0].className.substring(0,4)+"id"; // // id = doc.getElementById(campo_id_nome).value; // } var f = doc.getElementById('frm_cadastro'); //se nao eh cadastro nao faz nada if (f == "") return true; for (i = 0; i < campos.length; i++) { nome_campo = campos[i].className; if (nome_campo != 'nav_count') { campo = doc.getElementById(nome_campo); if (campo.type == 'checkbox') { //para quando nao tiver nenhu campo checado var checado = false; campo = doc.getElementsByName(nome_campo); for (c in campo) { if (campo[c].checked) { campo = campo[c]; checado = true; break; } } if (!checado) valor = "N"; else valor = campo.value; // S } else if (campo.type == 'radio') { // para quando nao tiver nenhu campo checado checado = false; campo = doc.getElementsByName(nome_campo); for (c in campo) { if (campo[c].checked) { campo = campo[c]; checado = true; break; } } if (!checado) { //se nunca tiver marcado o radio ta null if (campos[i].value == "") { valor = ""; } else { atualizar = true; } } else { valor = campo.value; // S } } else { valor = campo.value; } // if(campos[i].value!="" || id==0){ if (campos[i].value != valor) { atualizar = true; } //} } } } if (atualizar) { tela_atualizada.value = confirm_salvar(f, doc); return tela_atualizada.value; } else { tela_atualizada.value = true; return tela_atualizada.value; } } else { return true; } } function confirm_salvar(f, doc) { var resposta = confirm("Deseja salvar as Altera��es?"); if (resposta) { //nao sei qual tela que ta salvando var file = doc.location.pathname + "index.php"; return cad_salva(f, file); } else { //true pq ele esta ciente que esta saindo sem salvar return true; } } function pega_inputs(obj, elementos) { //var el = ""; //if(obj.nodeName=="FORM" && Browser == "Microsoft Internet Explorer") el = obj.childNodes.length; //else el = (obj.nodeName=="FORM"?obj.elements.length:obj.childNodes.length); //for(var e=0;(e< el);e++){ for (var e = 0; (e < (obj.nodeName == "FORM" ? obj.elements.length : obj.childNodes.length)); e++) { var tipo = (obj.nodeName == "FORM" ? obj.elements[e] : obj.childNodes[e]); if (tipo.nodeName == 'INPUT') { elementos.push(tipo); } else if (tipo.nodeName == 'SELECT') { elementos.push(tipo); } else if (tipo.nodeName == 'TEXTAREA') { elementos.push(tipo); } else { elementos = pega_inputs(tipo, elementos); } } return elementos; } function auditoria(form, xml, id, acao) { var doc = form.ownerDocument ? form.ownerDocument : window.document; var campos = doc.getElementsByName('anterior'); var response = xml.getElementsByTagName('response')[0]; var men_id = doc.getElementById('men_id'); var i = 0; var j = 0; var valor = ""; var valor_ant = ""; var valor_pos = ""; var campo = ""; var url = ""; var valor_campo_nome = ""; var campo_id_nome = ""; var cmp = ""; var elementos = new Array(); elementos = pega_inputs(form, elementos); campo_id_nome = pega_elemento(form, "cmp_id_atual")[0].value; if (!acao) acao = ""; for (i = 0; (i < response.childNodes.length); i++) { cmp = doc.getElementById(response.childNodes[i].tagName); //grid if (!cmp) cmp = doc.getElementById('g_' + response.childNodes[i].tagName); campo = campos.namedItem(response.childNodes[i].tagName + '_ant'); if (response.childNodes[i].hasChildNodes()) { valor = response.childNodes[i].firstChild.data; } else { valor = ""; } valor = valor.replace(/\+/g, " "); valor = unescape(valor); if (!cmp) console.log(response.childNodes[i].tagName); if (cmp.type == 'checkbox') { if (valor != 'S') valor = 'N'; } //quando o grid exclui direto nao tem o "campo"_ant if (!campo && acao == 'E') { campo = cmp; campo.className = cmp.id; } if (campos.length > 0 && campos.length > i && campo != null) { if (campo.className != 'prox' && campo.className != 'ante' && campo.className != 'prim' && campo.className != 'ulti' && campo.className != 'nav_count') { if (campo.value != valor) { valor_ant = campo.value; valor_pos = valor; campo = campo.className; if (valor_campo_nome == "" && acao == "") { if (!campo_id_nome) { campo_id_nome = campo.substring(0, 4) + "id"; } url = url + "&nome_id=" + campo_id_nome; valor_campo_nome = campo_id_nome.value; valor_campo_nome = valor_campo_nome ? valor_campo_nome : id; url = url + "&valor_campo_nome=" + valor_campo_nome; acao = "A"; var id_ant = doc.getElementById(campo_id_nome + "_ant").value; if (id_ant == "") { acao = "I"; } else { acao = "A"; } } // url = url+"&campos["+campo+"]="+campo; url = url + "&campos[" + campo + "][ant]=" + valor_ant; url = url + "&campos[" + campo + "][pos]=" + valor_pos; } } } else { break; } } if (url) { url = url + "&acao=" + acao; url = url + "&men_id=" + men_id.value; //pega a url da pasta url = doc.location.pathname + "../sis_auditoria/index.php?op=auditoria" + url; var resultado = exec_ajax_sincrono(url, 'texto'); resultado = resultado.replace(/\+/g, " "); // Resolve o problema resultado = unescape(resultado); // Resolve o problema dos var r = explode(resultado, "&"); if (r[0] != 'ok') { //document.getElementById("cad_mens_text").innerHTML= resultado; Ext.MessageBox.alert('Erro', r[0]); } } } function cad_grid_salva(form, file) { var doc = form.ownerDocument ? form.ownerDocument : window.document; var pos = parseInt(doc.getElementById('nav_pos').value); atualiza_div_msg(form, '', "block"); var dv = document.defaultView ? document.defaultView : document.parentWindow; // Verifica se foi passado o arquivo senao assume index.php if (!file) file = 'index.php'; // Busca todos os campos do form parameters = carrega_valor_form(form, 'salvar'); url = file + '?op=salvar'; resultado = exec_ajax_sincrono(url, 'texto', parameters); resultado = resultado.replace(/\+/g, " "); // Resolve o problema resultado = unescape(resultado); // Resolve o problema dos // acentos r = explode(resultado, "&"); if (r[0] != 'ok') { //document.getElementById("cad_mens_text").innerHTML= resultado; var win = new Ext.Window({ title: 'Erro', width: 400, height: 300, plain: true, html: resultado, modal: true, buttons: [{ text: 'OK', handler: function () { win.hide(); } }] }); win.show(); //alert(resultado); } else { // se existir a funcao f_after_scroll, entao executa if (typeof dv.f_after_scroll == 'function') { // Depois tirar essa mensagem dv.f_after_scroll(form); } // nav_carrega_form(form, pos); } } function cad_cancela(f, file) { var form_valid = document.getElementById('div_form_pesquisa'); var obj_url = pega_elemento(form_valid, 'url')[0]; var url = ""; if (obj_url) obj_url.value; url = url + carrega_valor_form(form_valid, "executa_relatorio"); var div_rel = document.getElementById('div_rel'); exec_ajax_progresso(div_rel, url, "after_valida_form_html", "extjs"); return; } function cad_cancela1(f) { var elems = frm_cadastro.elements; for (var i = 0; i < elems.length; i++) { if (elems[i].tagName == "INPUT") { var cmp_id = elems[i].id; var cmp_ante = document.getElementById(cmp_id + "_ant"); var tipo = elems[i].type; if (tipo == "text") { if (cmp_ante) elems[i].value = cmp_ante.value; } else if (cmp_ante && tipo == "checkbox") { elems[i].checked = cmp_ante.value == "S" ? true : false; } else if (tipo == "radio") { var cmp = document.getElementsByName(cmp_id); for (var j = 0; j < cmp.length; j++) { if (cmp[j].value == cmp_ante.value) { cmp[j].checked = true; } else cmp[j].checked = false; } } } else if (elems[i].tagName == "SELECT") { cmp_id = elems[i].id; if (cmp_ante) cmp_ante = document.getElementById(cmp_id + "_ant"); if (cmp_ante) elems[i].value = cmp_ante.value; } else if (elems[i].tagName == "TEXTAREA") { cmp_ante = document.getElementById(elems[i].id + "_ant"); if (cmp_ante) elems[i].value = cmp_ante.value; } } } function posiciona_ultimo(f) { // Atualiza o count var document = f.ownerDocument ? f.ownerDocument : window.document; var url = document.location.protocol + '//' + document.location.host + document.location.pathname; url = url + '?op=dados_xml&pos=-1'; resultado = exec_ajax_sincrono(url, 'xml'); a = resultado.getElementsByTagName('nav_count'); for (j = 0; (j < a.length); j++) { document.getElementById('nav_count').value = a[j].firstChild.data; } nav_ulti(f); } // Fun��o para buscar valores do form de pesquisa function carrega_valor_form(obj, op) { var s = ""; if (op) s += "?op=" + op; if (!obj) { obj = document.getElementById('div_cadastro'); } a_nos = new Array(); s = s + gera_url_nos(obj); if (obj.name != 'div_cadastro') { obj = document.getElementById('div_cadastro'); s = s + gera_url_nos(obj); } return s; } function carrega_valor_form_psq(op) { var s = "?op=" + op; div_pesquisa = document.getElementById('div_pesquisa'); s = s + gera_url_nos(div_pesquisa); return s; } // Foi trocado a forma de busca dos elementos para montar a url // Funcao para gerar url com os valores do form de acordo com os 'n�s' function gera_url_nos(param) { var s = ""; var obj = param; var a_nos = new Array(); if (obj) { for (var i = 0; i < (obj.nodeName == "FORM" ? obj.elements.length : obj.childNodes.length); i++) { var tipo = (obj.nodeName == "FORM" ? obj.elements[i] : obj.childNodes[i]); if (tipo.nodeName == 'INPUT') { if (tipo.name != 'op' && tipo.name != '') { if (tipo.type == 'checkbox') { if (!a_nos.hasOwnProperty(tipo.name)) s = s + "&" + tipo.name + "=" + (tipo.checked ? tipo.value : ""); a_nos[tipo.name] = tipo.value; } else { if (tipo.type == 'radio') { if (tipo.checked) { if (!a_nos.hasOwnProperty(tipo.name)) s = s + "&" + tipo.name + "=" + unescape(tipo.value); a_nos[tipo.name] = tipo.value; } } else { if (!a_nos.hasOwnProperty(tipo.name)) s = s + "&" + tipo.name + "=" + escape(tipo.value); a_nos[tipo.name] = tipo.value; } } } } else if (tipo.nodeName == 'SELECT') { if (!a_nos.hasOwnProperty(tipo.name)) s = s + "&" + tipo.name + "=" + unescape(tipo.value); a_nos[tipo.name] = tipo.value; } else if (tipo.nodeName == 'TEXTAREA') { if (!a_nos.hasOwnProperty(tipo.name)) s = s + "&" + tipo.name + "=" + urlencode(tipo.value); a_nos[tipo.name] = tipo.value; } else { s = s + gera_url_nos(tipo); } } } return s; } function urlencode(str) { return escape(str).replace(/\+/g, '%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40'); } function urldecode(str) { return unescape(str.replace('+', ' ')); } // Funcao para buscar url de acordo com o elemento function gera_url_el(params) { var s = ""; var obj = param; if (obj) { for (var i = 0; i < obj.elements.length; i++) { var tipo = obj.elements[i]; if (tipo.nodeName == 'INPUT') { if (tipo.name != 'op' && tipo.name != '') { if (tipo.type == 'checkbox') s = s + "&" + tipo.name + "=" + (tipo.checked ? tipo.value : ""); else { if (tipo.type == 'radio') { if (tipo.checked) { s = s + "&" + tipo.name + "=" + tipo.value; } } else s = s + "&" + tipo.name + "=" + tipo.value; } } } else if (tipo.nodeName == 'SELECT') s = s + "&" + tipo.name + "=" + tipo.value; else if (tipo.nodeName == 'TEXTAREA') s = s + "&" + tipo.name + "=" + unescape(tipo.value); else s = s + gera_url_el(tipo); } } return s; } /* * Fun��o: cad_exclui * Objetivo: excluir registro * Vers�o * 1.01 - 17/11/2010 - Victor * foi adicionada a chamada da fun��o f_after_exclui caso ela exista no .js da tela * 1.02 - 25/11/2010 - Renato * foi feito um else if para quanto estiver pos=-1; */ function cad_exclui(f, nome_id, file) { var document = f.ownerDocument ? f.ownerDocument : window.document; if (nome_id) { var dv = document.defaultView ? document.defaultView : document.parentWindow var id = document.getElementById(nome_id).value; // antes de excluir, executa a fun��o f_after_exclui caso ela exista if (typeof dv.f_after_exclui == 'function') dv.f_after_exclui(); var cont = document.getElementById("nav_count").value; var pos = document.getElementById("nav_pos").value; if (!file) file = 'index.php'; psq_url = file + '?op=exclui&id=' + id; if (confirm('Deseja excluir?')) { resultado = exec_ajax_sincrono(psq_url); resultado = resultado.rtrim(); resultado = resultado.ltrim(); if (resultado == 'ok') { xml = exec_ajax_sincrono(file + '?op=dados_xml&id=' + id, 'xml'); // auditoria(f,xml,id,"E"); alert('Excluido com sucesso.'); if (pos == 0) { (cont > 1) ? nav_prim(f, '', file) : nav_limp(f, file); } else if (pos == -1) { //vai para o 1� nav_prim(f, '', file); } else nav_ante(f, '', file); return true; } else { alert(resultado); return false; } } else { return false; } } else { return false; } } function trocaImgCadeado(o) { if (o.className == 'lock') o.className = 'unlock'; else o.className = 'lock'; } function focoPrimeiroCampo(f) { var foco = false; if (!f) f = document.forms[0]; elementos = new Array(); elem = pega_inputs(f, elementos); for (i = 0; (i < elem.length || !foco); i++) { if (!foco && !elem[i].disabled && !elem[i].readOnly && elem[i].type != 'hidden') { elem[i].focus(); foco = true; } } } function nav_novo(f, file) { var doc = f.ownerDocument ? f.ownerDocument : window.document; doc.getElementById('nav_pos').value = -1; if (verifica_alteracao(doc)) { nav_limp(f, file); var dv = document.defaultView ? document.defaultView : document.parentWindow; if (typeof dv.f_before_scroll == 'function') { dv.f_before_scroll(f, resultado); } else ajax_continua = true; focoPrimeiroCampo(f); // se existir a funcao f_after_scroll, entao executa if (typeof dv.f_after_scroll == 'function') { atualiza_div_msg(f, 'Atualizando campos ...', "block"); dv.f_after_scroll(f); } atualiza_div_msg(f, '', "none"); } } function nav_limp(f, file) { var doc = f.ownerDocument ? f.ownerDocument : window.document; if (verifica_alteracao(doc)) { nav_carrega_form(f, -1, '', '', file); //limpa_form(f); } btn_grid_atualiza(false); } /* * Funcao inativa nav_limp */ function nav_limp1(f) { for (i = 0; (i < f.elements.length); i++) { cmp = f.elements[i]; if (cmp != null) { valor = ""; if (cmp.tagName == 'SELECT') { cmp.value = valor; } else if (cmp.tagName == 'TEXTAREA') { cmp.value = unescape(valor); } else { if (cmp.tagName == 'INPUT') { if (cmp.type == 'checkbox') cmp.checked = (valor == 'S'); else if (cmp.type == 'text') cmp.value = valor; else if (cmp.type == 'hidden') { cmp.value = valor; } else if (cmp.type == 'radio') { // Quando for radio, deve verificar todos os obj cmpradio = doc.getElementsByName(cmp.id); for (j = 0; (j < cmpradio.length); j++) { cmpradio[j].checked = cmpradio[j].value == valor; } } else cmp.innerHTML = valor; } } } else { if (!msg_erro) msg_erro = 'N�o encontrou os seguintes campos: '; msg_erro = msg_erro + "\n" + response.childNodes[i].tagName; } } } function nav_prim(f, uri, file) { // Limpa o form nav_limp(f, file); var doc = f.ownerDocument ? f.ownerDocument : window.document; var pos = doc.getElementById('prim'); if (pos) { pos = pos.value; } if (verifica_alteracao(doc)) { var nav_pos = doc.getElementById('nav_pos'); if (nav_pos) { nav_pos = doc.getElementById('nav_pos').value = pos; } nav_carrega_form(f, pos, uri, '', file); atualiza_botoes(f); var id_ante = doc.getElementById('id_ante'); var cmp_id_atual = doc.getElementById('cmp_id_atual'); var cmp_value = ""; if (cmp_id_atual) { cmp_value = doc.getElementById(cmp_id_atual.value); if (cmp_value) { cmp_value = cmp_value.value; } } if (id_ante) { id_ante.value = cmp_value; } } } function nav_ante(f, uri, file) { var doc = f.ownerDocument ? f.ownerDocument : window.document; var pos = doc.getElementById('ante').value; doc.getElementById('nav_pos').value = pos; if (verifica_alteracao(doc)) { nav_carrega_form(f, pos, uri, '', file); atualiza_botoes(f); var id_ante = doc.getElementById('id_ante'); var c = doc.getElementById('cmp_id_atual'); //garantido tudo var cmp_value = ""; if (c) { var cv = doc.getElementById(c.value); if (cv) { cmp_value = cv.value; } } id_ante.value = cmp_value; } } function nav_prox(f, uri, file) { var doc = f.ownerDocument ? f.ownerDocument : window.document; var pos = doc.getElementById('prox').value; doc.getElementById('nav_pos').value = pos; if (verifica_alteracao(doc)) { nav_carrega_form(f, pos, uri, '', file); atualiza_botoes(f); var id_ante = doc.getElementById('id_ante'); var c = doc.getElementById('cmp_id_atual'); //garantido tudo var cmp_value = ""; if (c) { var cv = doc.getElementById(c.value); if (cv) { cmp_value = cv.value; } } id_ante.value = cmp_value; } } function nav_ulti(f, uri, file) { var doc = f.ownerDocument ? f.ownerDocument : window.document; var pos = doc.getElementById('ulti').value; if (verifica_alteracao(doc)) { doc.getElementById('nav_pos').value = pos; nav_carrega_form(f, pos, uri, '', file); atualiza_botoes(f); var id_ante = doc.getElementById('id_ante'); var c = doc.getElementById('cmp_id_atual'); //garantido tudo var cmp_value = ""; if (c) { var cv = doc.getElementById(c.value); if (cv) { cmp_value = cv.value; } } id_ante.value = cmp_value; } } function atualiza_botoes(f) { if (!(f)) f = window.document.forms[0]; var doc = f.ownerDocument ? f.ownerDocument : window.document; var id_ante = doc.getElementById('id_ante'); var c = doc.getElementById('cmp_id_atual'); //garantido tudo var cmp_value = ""; if (c) { var cv = doc.getElementById(c.value); if (cv) { cmp_value = cv.value; } } var btnpesq = doc.getElementById('btnpesq'); var btnnovo = doc.getElementById('btnnovo'); var btnexcl = doc.getElementById('btnexcl'); var btnsalv = doc.getElementById('btnsalv'); if (!cmp_value) { if (id_ante) { if (btnpesq) btnpesq.disabled = true; if (btnnovo) btnnovo.disabled = true; if (btnsalv) btnsalv.disabled = false; } else { if (btnpesq) btnpesq.disabled = false; if (btnnovo) btnnovo.disabled = false; if (btnsalv) btnsalv.disabled = false; } if (btnexcl) btnexcl.disabled = true; } else { if (btnpesq) btnpesq.disabled = false; if (btnnovo) btnnovo.disabled = false; if (btnexcl) btnexcl.disabled = false; } //redeclarado comentei //var doc = f.ownerDocument ? f.ownerDocument : window.document; var prim = doc.getElementById('prim'); var btnprim = doc.getElementById('btnprim'); var ante = doc.getElementById('ante'); var btnante = doc.getElementById('btnante'); var prox = doc.getElementById('prox'); var btnprox = doc.getElementById('btnprox'); var ulti = doc.getElementById('ulti'); var btnulti = doc.getElementById('btnulti'); if (btnprim) btnprim.disabled = prim.value == ""; if (btnante) btnante.disabled = ante.value == ""; if (btnprox) btnprox.disabled = prox.value == ""; if (btnulti) btnulti.disabled = ulti.value == ""; // Define os botoes de acordo com o acesso desabilita_botoes(f); btn_grid_atualiza(cmp_value > 0); } function desabilita_botoes(f) { var document = f.ownerDocument ? f.ownerDocument : window.document; //evitar erros var campo_id = ""; var dv = document.defaultView ? document.defaultView : document.parentWindow; var cmp_id_atual = document.getElementById('cmp_id_atual'); var campo_id = 0; var cmp_id = ''; if (cmp_id_atual) { campo_id = document.getElementById(cmp_id_atual.value); } if (cmp_id_atual) { if (f.tagName == 'FORM') cmp_id = f.elements[cmp_id_atual.value]; else cmp_id = pega_elemento(f, cmp_id_atual.value)[0]; // if (cmp_id) { campo_id = cmp_id.value; } } //tem 2 form e um document //tira pemi var str_acesso = document.getElementById('str_acesso').value; if (Browser.indexOf('Internet Explorer') > 0) { var btnsalva = f.ownerDocument.getElementsByName('input_nav_salv'); //var btnsalva = f.ownerDocument.getElementsByName(''); var btnnovo = f.ownerDocument.getElementsByName('input_nav_novo'); var btnexcl = f.ownerDocument.getElementsByName('input_nav_excl'); var btnpesq = f.ownerDocument.getElementsByName('input_nav_pesq'); var btnvisu = f.ownerDocument.getElementsByName('input_nav_visu'); var btncanc = f.ownerDocument.getElementsByName('input_nav_canc'); } else { var btnsalva = f.getElementsByClassName('input_nav_salv'); //var btnsalva = document.getElementById('btnsalv'); var btnnovo = f.getElementsByClassName('input_nav_novo'); var btnexcl = f.getElementsByClassName('input_nav_excl'); var btnpesq = f.getElementsByClassName('input_nav_pesq'); var btnvisu = f.getElementsByClassName('input_nav_visu'); var btncanc = f.getElementsByClassName('input_nav_canc'); } /* var btn_novo = document.getElementById('btn_novo'); var btn_visu = document.getElementById('btn_visu'); var btnsalv = document.getElementById('btnsalv'); var btnpesq = document.getElementById('btnpesq'); var btnprim = document.getElementById('btnprim'); var btnante = document.getElementById('btnante'); var btnprox = document.getElementById('btnprox'); var btnulti = document.getElementById('btnulti'); */ var desab_canc = 0; // Verifica inclusao if (str_acesso.substr(0, 1) == '0') { if (!campo_id) { desabilita_botoes_array(btnsalva, true); } else { desabilita_botoes_array(btnsalva, false); } desabilita_botoes_array(btnnovo, true); desab_canc++; // btn_novo.disabled = true; } // Exclusao if (str_acesso.substr(1, 1) == "0") { desabilita_botoes_array(btnexcl, true); } // Alteracao if ((str_acesso.substr(2, 1) == "0")) { if (campo_id > 0) desabilita_botoes_array(btnsalva, true); // btnsalv.disabled = true; desab_canc++; } else // Consulta if ((str_acesso.substr(3, 1) == "0")) { // btn_visu.disabled = true; desabilita_botoes_array(btnvisu, true); } // Desabilita o botao cancelar se nao possui acesso para incluir ou alterar if (desab_canc == 2) { desabilita_botoes_array(btncanc, true); } //valida permiss�o personalizada if (typeof dv.f_after_scroll_permissao == 'function') { // Depois tirar essa mensagem dv.f_after_scroll_permissao(f); } } function desabilita_botoes_array(bt, desabilitar) { for (var i = 0; i < bt.length; i++) { bt[i].disabled = desabilitar; } } function nav_pesq(f, uri) { var document = f.ownerDocument ? f.ownerDocument : window.document; sw = screen.width; sh = screen.height; w = document.width - 20; h = document.height - 20; t = 50; l = 50; win_psq = new Ext.Window({ title: 'Pesquisa', width: w, height: h, plain: false, html: '
' }); win_psq.show(); div_jan_pesquisa = document.getElementById('div_jan_pesquisa'); div_jan_pesquisa.innerHTML = exec_ajax_sincrono('?op=pesquisar'); //cria_grid(); } function nav_carrega_form(f, pos, uri, param, file) { var document = f.ownerDocument ? f.ownerDocument : window.document; atualiza_div_msg(f, 'Aguarde ...'); //planejamento // if(!file) file = 'index.php'; if (!uri) uri = document.location.protocol + '//' + document.location.host + document.location.pathname; var url = uri; url = url + (file ? file : '') + '?op=dados_xml&pos=' + pos; if (param) url += "&" + param; // $.ajax({ method: "GET", url: url }).done(function (resultado) { //resultado = exec_ajax_sincrono(url, 'xml'); get_dados_xml(f, resultado); atualiza_div_msg(f, ''); atualiza_botoes(f); }); } function get_dados_xml(f, resultado) { var document = f.ownerDocument ? f.ownerDocument : window.document; var tela_atualizada = document.getElementById('tela_atualizada') //carrengando.. entao nao foi alterado.... if (tela_atualizada) tela_atualizada.value = false; atualiza_div_msg(f, '', "block"); var dv = document.defaultView ? document.defaultView : document.parentWindow; // se existir a funcao f_before_scroll, entao executa if (typeof dv.f_before_scroll == 'function') { dv.f_before_scroll(f, resultado); } else ajax_continua = true; if (resultado) { // retrieve the document element var response = resultado.getElementsByTagName('response')[0]; var msg_erro = ""; if (response) { if (response.childNodes.length) { var resp_erro = child_value(response, 'erro'); if (resp_erro) alert_ext("Erro: " + unescape(resp_erro)); // while(!ajax_continua) {} // Aguarda resposa do ajax no before_scroll // alert('depois do before = '+doc.getElementById('evc_usu_id_responsavel').value); // Carrega campos atualiza_div_msg(f, 'Atualizando campos ...', "block"); msg_erro = carrega_campo(document, response, f); if (msg_erro) alert(msg_erro); var nav_count = document.getElementById('nav_count'); if (nav_count) nav_count.value = child_value(response, 'nav_count'); } else { alert('Nenhum registro encontrado.'); } } // if(nav_count) desabilita_botoes(f, nav_count.value); atualiza_botoes(f); } // se existir a funcao f_after_scroll, entao executa if (typeof dv.f_after_scroll == 'function') { atualiza_div_msg(f, 'Atualizando campos ...', "block"); dv.f_after_scroll(f); } atualiza_div_msg(f, 'Atualizando campos ...', "none"); } function get_grid_dados_xml(f, resultado) { var doc = f.ownerDocument ? f.ownerDocument : window.document; var dv = doc.defaultView ? doc.defaultView : doc.parentWindow; // se existir a funcao g_before_scroll, entao executa if (typeof dv.g_before_scroll == 'function') { dv.g_before_scroll(f, resultado); } // retrieve the document element response = resultado.getElementsByTagName('response')[0]; var msg_erro = ""; if (response) { if (response.childNodes.length > 0) { // Carrega campos msg_erro = carrega_campo(doc, response, f); if (msg_erro) alert(msg_erro); } else { // alert('Nenhum registro encontrado.'); } } // se existir a funcao g_after_scroll, entao executa if (typeof dv.g_after_scroll == 'function') { // Depois tirar essa mensagem dv.g_after_scroll(f); } g_desabilita_botoes(); } function carrega_campo(doc, response, f) { var frm_cadastro = f; if (!frm_cadastro) frm_cadastro = doc.getElementById('frm_cadastro'); var msg_erro = ""; var i = 0; var cmp_ant = ""; var cmp_atual = ""; var cmpradio = ""; var valor = ""; var atributo = ""; for (i = 0; (i < response.childNodes.length); i++) { var cmp = doc.getElementById(response.childNodes[i].tagName); if (cmp != null) { if (cmp.id != 'prox' && cmp.id != 'ante' && cmp.id != 'prim' && cmp.id != 'ulti' && cmp.id != 'nav_count') { //se for navega�ao nao faz // if(cmp.id!='prox' && // cmp.id!='ante' && // cmp.id!='prim' && // cmp.id!='ulti'){ //se tem remove o hidden; remove_elemento(cmp.id + "_ant", doc); cmp_ant = doc.createElement("input"); cmp_ant.setAttribute("type", "hidden"); cmp_ant.setAttribute("id", cmp.id + "_ant"); cmp_ant.setAttribute("name", "anterior"); cmp_ant.setAttribute("class", cmp.id); frm_cadastro.appendChild(cmp_ant); if (response.childNodes[i].hasChildNodes()) { if (cmp.tagName == 'TEXTAREA') { valor = response.childNodes[i].textContent; } else { valor = response.childNodes[i].firstChild.data; } } else { valor = ""; } // Corrige acentos e espaco em branco valor = valor.replace(/\+/g, " "); // Resolve o problema dos // acentos valor = unescape(valor); // Resolve o problema dos acentos if (cmp.tagName == 'SELECT') { cmp.value = valor; cmp_ant.setAttribute("value", valor); } else if (cmp.tagName == 'TEXTAREA') { cmp.value = unescape(valor); cmp_ant.setAttribute("value", valor); } else { if (cmp.tagName == 'INPUT') { if (cmp.type == 'checkbox') { cmp.checked = (valor == 'S'); cmp_ant.setAttribute("value", (cmp.checked) ? "S" : "N"); cmp_atual = doc.createElement("input"); cmp_atual.setAttribute("type", "hidden"); cmp_atual.setAttribute("id", cmp.id + "_atual"); cmp_atual.setAttribute("value", cmp.checked ? "S" : "N"); frm_cadastro.appendChild(cmp_atual); atributo = "" atributo = cmp.getAttribute("onchange"); if (atributo) { if (atributo.search(/atualiza_campoatual/i) == -1) { cmp.setAttribute("onchange", "atualiza_campoatual(this.value, '" + cmp.id + "', 'checkbox'," + frm_cadastro.id + ")," + atributo); } } else { cmp.setAttribute("onchange", "atualiza_campoatual(this.value, '" + cmp.id + "', 'checkbox'," + frm_cadastro.id + ")"); } } else if (cmp.type == 'text') { cmp.value = valor; cmp_ant.setAttribute("value", valor); } else if (cmp.type == 'hidden') { cmp.value = valor; cmp_ant.setAttribute("value", valor); } else if (cmp.type == 'radio') { // Quando for radio, deve verificar todos os obj cmpradio = doc.getElementsByName(cmp.id); cmp_ant.setAttribute("value", valor); cmp_atual = doc.createElement("input"); cmp_atual.setAttribute("type", "hidden"); cmp_atual.setAttribute("id", cmp.id + "_atual"); cmp_atual.setAttribute("value", valor); frm_cadastro.appendChild(cmp_atual); var j = 0; for (j = 0; (j < cmpradio.length); j++) { cmpradio[j].checked = cmpradio[j].value == valor; atributo = ""; atributo = cmpradio[j].getAttribute("onchange"); if (atributo) { if (atributo.search(/atualiza_campoatual/i) == -1) { cmpradio[j].setAttribute("onchange", "atualiza_campoatual(this.value, '" + cmp.id + "', 'checkbox'," + frm_cadastro.id + ")," + atributo); } } else { cmpradio[j].setAttribute("onchange", "atualiza_campoatual(this.value, '" + cmp.id + "', 'checkbox'," + frm_cadastro.id + ")"); } } } } else { cmp.innerHTML = valor; cmp_ant.innerHTML = valor; } } // } } else if (cmp.id != 'nav_count') { //eh os botoes de navega��o if (response.childNodes[i].hasChildNodes()) { valor = response.childNodes[i].firstChild.data; } else { valor = ""; } // Corrige acentos e espaco em branco valor = valor.replace(/\+/g, " "); // Resolve o problema dos // acentos valor = unescape(valor); // Resolve o problema dos acentos cmp.value = valor; } } // else { // if(!msg_erro) msg_erro = 'N�o encontrou os seguintes campos: '; // msg_erro = msg_erro+ "\n"+ response.childNodes[i].tagName; // } } return msg_erro; } //alterado // FUNCOES PARA GRID function child_value(rg, campo) { var r = ""; var x = rg.getElementsByTagName(campo)[0]; if (x) { if (x.childNodes.length > 0) r = x.firstChild.data; } return r; } /* funcao nao utilizada mais, porem deixada apenas para compatibilidade * substituida pela f_int_grid * */ function f_grid(com, id) { if (com == 'Atualizar') { J('#flex_pesquisa')[0].p.url = '?op=grid_pesquisa'; J('#flex_pesquisa').flexOptions({ newp: 1 }).flexReload(); } else if (com == 'Editar') { if (J('.trSelected').length > 0) { resultado = exec_ajax_sincrono('?op=dados_xml&id=' + id, 'xml'); f = document.getElementById('frm_cadastro'); get_dados_xml(f, resultado); return; } else { alert('Selecione apenas um item para editar.' + id); } } } /* * Funcao para gerenciar os botoes do grid */ function f_int_grid(com, id, cmp_id, file) { var div_rel_html = document.getElementById("div_rel_html_" + cmp_id); var div_form_cadastro_grid = document.getElementById("div_form_cadastro_" + cmp_id); var flgGrid = document.getElementById('flgGrid' + cmp_id); // var form_cadastro = document.getElementById("div_cad_"+cmp_id); // var cli_id = pega_elemento(form_cadastro, cmp_id)[0]; var form_grid = document.getElementById("div_cad_" + cmp_id) // var clf_cli_id = pega_elemento(form_grid, "clf_cli_id")[0]; var div_grid_rel = document.getElementById("div_resultado_pesquisa_" + cmp_id); var btn_salva = document.getElementById("btn_salva_" + cmp_id); if (com == "Atualizar") { if (div_rel_html) div_rel_html.className = ""; if (div_grid_rel) div_grid_rel.className = ""; if (flgGrid && flgGrid.value == "1") flgGrid.value = "0"; if (div_form_cadastro_grid) div_form_cadastro_grid.className = (flgGrid && flgGrid.value == "0" ? 'x-hidden' : ''); if (btn_salva) btn_salva.className = "x-hidden"; } else if (com == "Editar") { if (flgGrid) flgGrid.value = "1"; if (div_form_cadastro_grid) div_form_cadastro_grid.className = (flgGrid && flgGrid.value == "0" ? 'x-hidden' : ''); if (div_grid_rel) div_grid_rel.className = ""; if (btn_salva) btn_salva.className = ""; } else if (com == "Novo") { if (flgGrid) flgGrid.value = "1"; if (div_form_cadastro_grid) div_form_cadastro_grid.className = (flgGrid && flgGrid.value == "0" ? 'x-hidden' : ''); if (div_grid_rel) div_grid_rel.className = ""; if (btn_salva) btn_salva.className = ""; } } function mouse(id, color) { if (tr_selecionado != id) id.style.backgroundColor = color; /* Define a cor de fundo padr�o */ } function explode(texto, separador) { var ind = -1; var c = ""; var t = "" var a = new Array(); for (var i = 0; i < texto.length; i++) { c = texto.substring(i, i + 1); if (c == separador) { ind = ind + 1; a[ind] = t; t = ""; } else { t = t + c; } } ind = ind + 1; a[ind] = t; t = ""; return a; } /* * Fun��o: desabilita_botoes * Objetivo: Haboilitar e desabilitar bot�es do nav de acordo com a permiss�o do usu�rio * Vers�o * 1.00: Victor - 20/09/2010 */ function dateDiff(strInicio, strFim) { //Define os arrays para data var arr_inicio = strInicio.split("/"); var arr_fim = strFim.split("/"); //Define o array com o nome dos meses em ingles var meses = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); //Cria as strings para o Date.parse ex: 30/09/2010 vira September 30 2010 var str_date_inicio = meses[arr_inicio - 1] + " " + arr_inicio[0] + " " + arr_inicio[2]; var str_date_fim = meses[arr_fim - 1] + " " + arr_fim[0] + " " + arr_fim[2]; //Calcula a diferen�a, em dias, entre as duas datas var dif = ((Date.parse(str_date_fim)) - (Date.parse(str_date_inicio))) / (1000 * 60 * 60 * 24); return dif; } function calcula_data_nasc(idade) { //Cria o objeto data data = new Date(); //Calcula a data de nascimento data.setDate(data.getDate() - idade * 365.25); //Traz a data de nascimento calculada, formato aaaa-mm-dd strData = data.toLocaleDateString(); //retorna a strData no formato dd/mm/aaaa return(strData.substr(9, 2) + "/" + strData.substr(6, 2) + "/" + strData.substr(0, 4)); } function atualiza_campoatual(valor, campo_id, tipo, f) { var document = f.ownerDocument ? f.ownerDocument : window.document; campo_atual = document.getElementById(campo_id + "_atual"); campo = document.getElementById(campo_id); if (tipo == "radio") campo_atual.value = valor; else if (tipo == "checkbox") { campo_atual.value = (campo.checked) ? "S" : "N"; } } function remove_elemento(id, doc) { var elemento = doc.getElementById(id); if (elemento) { elemento.parentNode.removeChild(elemento); return true; } else { return false; } } function fechando_navegador(e) { var divs = window.parent.frames; var j = 0; var f = ''; var doc = ''; var fechar_tudo = true; var fechar = true; for (j = 1; j < divs.length; j++) { //pega o form form f = divs[j].f; //pega o document doc = f.ownerDocument ? f.ownerDocument : window.document; if (f.refresh_tela) { // Se for a tela de paciente, apenas atualiza if (f.refresh_tela.value == 'true') { fechar = verifica_alteracao(doc); } else if (f.refresh_tela.value == 'paciente') { fechar = verifica_alteracao(doc); } } if (!fechar) { fechar_tudo = false; } } return fechar_tudo; } function atualizar_grid_json(g_nome, f, nome_id) { var doc = f.ownerDocument ? f.ownerDocument : window.document; atualiza_div_msg(f, 'Carregando...', "block"); var id = ""; if (nome_id) { id = doc.getElementById(nome_id); if (id) { g_nome.getStore().reload({ params: { id: id.value } }); } } if (!id) { g_nome.getStore().reload({ params: { id: 0 } }); } permissao_grid_json(g_nome, doc); atualiza_div_msg(f, '', "none"); } function permissao_grid_json(g_nome, doc) { var str_acesso = doc.getElementById('str_acesso').value; // g_nome.fbar.items.items[0].setDisabled(true); for (var i = 0; i < 2; i++) { if (g_nome.fbar.items.items[i].id == 'novo') { if (str_acesso.substr(0, 1) == '0') { g_nome.fbar.items.items[i].setDisabled(true); } } else if (g_nome.fbar.items.items[i].id == 'excluir') { if (str_acesso.substr(1, 1) == "0") { g_nome.fbar.items.items[i].setDisabled(true); } } } } function desabilita_botao_json(g_nome, doc, btn, disabled) { for (var i in g_nome.fbar.items.items) { el = g_nome.fbar.items.items[i]; if (el.id == btn) el.setDisabled(disabled); } } function desabilita_campos(f, cmp, disabled) { var elem = ""; for (var i = 0; i < cmp.length; i++) { elem = pega_elemento(f, cmp[i])[0]; elem.disabled = disabled; if (disabled) elem.setAttribute("readonly", "readonly"); else elem.removeAttribute("readonly"); } } function cria_wiw_grid(id_w, url, titulo, w, h, x, y) { var cmp = document.getElementById("cmp_id_atual"); var form = document.getElementById("form_" + cmp.value); var dv = document.defaultView ? document.defaultView : document.parentWindow; sw = screen.width; sh = screen.height; w = (w > 0 ? w : form.offsetWidth / 2); h = (h > 0 ? h : form.offsetHeight / 2); t = 50; l = 50; if (!x) x = 50; win_grid = ""; if (!y) y = 50; win_grid = ""; if (titulo == "N") { titulo = "Novo"; } else if (!titulo) { titulo = "Editando"; } win_grid = Ext.getCmp("win_" + id_w); if (!win_grid) { win_grid = new Ext.Window({ id: "win_" + id_w, applyTo: 'div_grid_win_' + id_w, layout: 'fit', closeAction: 'hide', title: titulo, scripts: true, width: w, height: h, x: x, y: y, title: titulo, closeAction:'hide', plain: false, items: new Ext.TabPanel({ applyTo: 'div_grid_form_' + id_w, autoTabs: true, activeTab: 0, deferredRender: false, plain: false, border: false }) }); // a_win_grid.push(win_grid); } if (win_grid.id != "win_" + id_w) { win_grid.close(); //a_win_grid.splice(a_win_grid.indexOf(win_grid,1)); win_grid = ""; cria_wiw_grid(id_w, url, titulo); } else { win_grid.setTitle(titulo); win_grid.show(this); // win_grid.load({ // url: url, // scripts: true // }); } } function fecha_wiw_grid(id_w) { var win = Ext.getCmp("win_" + id_w); if (win) ; win.hide(); } function hidden_input(form, dados, doc) { var cmp; if (!doc) doc = window.document; for (var d in dados) { cmp = doc.getElementById("g_" + d); if (!cmp) { cmp = doc.createElement('input'); cmp.setAttribute('type', 'hidden'); cmp.setAttribute('id', "g_" + d); cmp.setAttribute('name', d); cmp.setAttribute('class', d); form.appendChild(cmp); cmp.setAttribute('value', dados[d]); } else { cmp.value = dados[d]; } } } function _edit_grid_win(d, nome, url, w, h, x, y) { var doc; var dados; var dv = document.defaultView ? document.defaultView : document.parentWindow; doc = window.document; cria_wiw_grid('grid_win_' + nome, url, "", w, h, x, y); var form_jan_grid = doc.getElementById('frm_grid_' + nome); doc = form_jan_grid.ownerDocument ? form_jan_grid.ownerDocument : window.document; var cmp; var cmp_ant; var dv = document.defaultView ? document.defaultView : document.parentWindow; var valor; if (typeof eval("dv.g_tratar_dados_" + nome) == 'function') { dados = eval("dv.g_tratar_dados_" + nome + "(f,d)"); } else { dados = d; } for (var d in dados) { cmp = doc.getElementById(d); if (cmp) { doc.getElementById(d).value = dados[d]; remove_elemento(cmp.id + '_ant', doc); cmp_ant = doc.createElement('input'); cmp_ant.setAttribute('type', 'hidden'); cmp_ant.setAttribute('id', cmp.id + '_ant'); cmp_ant.setAttribute('name', 'anterior'); cmp_ant.setAttribute('class', cmp.id); form_jan_grid.appendChild(cmp_ant); valor = dados[d]; // Corrige acentos e espaco em branco valor = valor.replace(/\+/g, ' '); // Resolve o problema dos // acentos valor = unescape(valor); // Resolve o problema dos acentos if (cmp.tagName == 'SELECT') { cmp.value = valor; cmp_ant.setAttribute('value', valor); } else if (cmp.tagName == 'TEXTAREA') { cmp.value = unescape(valor); cmp_ant.setAttribute('value', valor); } else { if (cmp.tagName == 'INPUT') { if (cmp.type == 'checkbox') { cmp.checked = (valor == 'S'); cmp_ant.setAttribute('value', (cmp.checked) ? 'S' : 'N'); cmp_atual = doc.createElement('input'); cmp_atual.setAttribute('type', 'hidden'); cmp_atual.setAttribute('id', cmp.id + '_atual'); cmp_atual.setAttribute('value', cmp.checked ? 'S' : 'N'); form_jan_grid.appendChild(cmp_atual); atributo = '' atributo = cmp.getAttribute('onchange'); if (atributo) { if (atributo.search(/atualiza_campoatual/i) == -1) { cmp.setAttribute("onchange", "atualiza_campoatual(this.value, '" + cmp.id + "', 'checkbox')," + atributo); } } else { cmp.setAttribute("onchange", "atualiza_campoatual(this.value, '" + cmp.id + "', 'checkbox')"); } } else if (cmp.type == 'text') { cmp.value = valor; cmp_ant.setAttribute('value', valor); } else if (cmp.type == 'hidden') { cmp.value = valor; cmp_ant.setAttribute('value', valor); } else if (cmp.type == 'radio') { // Quando for radio, deve verificar todos os obj cmpradio = doc.getElementsByName(cmp.id); cmp_ant.setAttribute('value', valor); cmp_atual = doc.createElement('input'); cmp_atual.setAttribute('type', 'text'); cmp_atual.setAttribute('id', cmp.id + '_atual'); cmp_atual.setAttribute('value', valor); form_jan_grid.appendChild(cmp_atual); var j = 0; for (j = 0; (j < cmpradio.length); j++) { cmpradio[j].checked = cmpradio[j].value == valor; atributo = ''; atributo = cmpradio[j].getAttribute('onchange'); if (atributo) { if (atributo.search(/atualiza_campoatual/i) == -1) { cmp.setAttribute("onchange", "atualiza_campoatual(this.value, '" + cmp.id + "', 'checkbox', form_jan_grid)," + atributo); } } else { cmp.setAttribute("onchange", "atualiza_campoatual(this.value, '" + cmp.id + "', 'checkbox', form_jan_grid)"); } } } } else { cmp.innerHTML = valor; cmp_ant.innerHTML = valor; } } // } } } desabilita_botoes(form_jan_grid); if (typeof dv.w_after_scroll == "function") dv.w_after_scroll(); } function limpa_form(f) { var doc = f.ownerDocument ? f.ownerDocument : window.document; var inputs = pega_inputs(f, new Array()); for (var i = 0; i < inputs.length; i++) { cmp = inputs[i]; if (cmp.className != "cstatic") { if (cmp.tagName == 'SELECT') { cmp.value = ""; } else if (cmp.tagName == 'TEXTAREA') { cmp.value = unescape(""); } else { if (cmp.tagName == 'INPUT') { if (cmp.type == 'checkbox') { cmp.checked = false; } else if (cmp.type == 'text') { cmp.value = ''; } else if (cmp.type == 'hidden') { cmp.value = ''; } else if (cmp.type == 'radio') { // Quando for radio, deve verificar todos os obj cmpradio = doc.getElementsByName(cmp.id); var j = 0; for (j = 0; (j < cmpradio.length); j++) { cmpradio[j].checked = false; } } } } } } } function btn_novo_click(cmp_id, w, h, x, y, file, f_grid) { var f = document.getElementById('frm_grid_' + cmp_id); if (!file) file = "index.php"; var url = file + "?op=cadastro"; /* $.fancybox({ 'content' : $("#div_form_cadastro"), 'onStart': function() { $("#div_form_cadastro").css("display","block"); }, 'onClosed': function() { $("#div_form_cadastro").css("display","none"); } }); */ nav_novo(f, file); // reseta_tela(); // if (f_grid) eval(f_grid + "('Novo','')"); // cria_wiw_grid('grid_win_'+cmp_id,url,'N',w,h,x,y,f_grid); } function btn_grid_novo_click(cmp_id, w, h, x, y, file, f_grid) { var f = document.getElementById('frm_grid_' + cmp_id); if (!file) file = "index.php"; var url = file + "?op=cadastro"; nav_novo(f, file); f_int_grid('Novo', '', cmp_id); if (f_grid) eval(f_grid + "('Novo','')"); // cria_wiw_grid('grid_win_'+cmp_id,url,'N',w,h,x,y,f_grid); } function btn_grid_salva_click(f, file) { cad_salva(f, file); } function btn_grid_cancela_click(cmp_id, f_grid) { var flgGrid = document.getElementById('flgGrid' + cmp_id); var dv = document.defaultView ? document.defaultView : document.parentWindow; if (!cmp_id) { reseta_tela(); document.getElementById('div_resultado_pesquisa').className = ''; //se existir a funcao f_after_scroll, entao executa if (typeof dv.f_after_scroll == 'function') { dv.f_after_scroll(); } } f_int_grid('Atualizar', '', cmp_id); if (f_grid) eval(f_grid + "('Atualizar','')"); } //nav_novo(f,'grid_local.php'); ///cria_wiw_grid('grid_win_loc_id','','N',400,110,50, 50); function btn_edit_click(cmp_id, w, h, x, y, file, campo, f_grid, tipo_pesq) { var f = document.getElementById("div_form_cadastro"); if (!f || tipo_pesq == "grid") { f = document.getElementById("div_form_cadastro_" + campo); } if (!file) { file = "index.php"; } var url = file + "?op=dados_xml&id=" + cmp_id; // var resultado = exec_ajax_sincrono(url, 'xml'); $.ajax({ method: "GET", url: url }).done(function (resultado) { get_dados_xml(f, resultado); f_int_grid("Editar", cmp_id, campo); if (f_grid != "") { eval(f_grid + "(\"Editar\",cmp_id)"); } }); } function btn_exclui_click(id, file, f_grid, cmp_id) { if (!file) file = "index.php"; Ext.MessageBox.show({ title: "Confirma", msg: "Deseja realmente excluir?", width: 300, height: 200, buttons: Ext.MessageBox.YESNO, //quais bottons vai ter fn: function (btnId) { if (btnId == 'yes') { //File = http://localhost/integracao/est_mov_paciente/ //"" = Verificar se o retorno � um XML ou Texto //op=exclui&id="+id //Parametros utilizado na url var r = exec_ajax_sincrono(file, "", "op=exclui&id=" + id); //r = r.rtrim(); //r = r.ltrim(); if (r != "ok") { alert_ext('Falha ao excluir', r); return false; } if (f_grid != "") { eval(f_grid + "(\"Excluir\", id)"); var dv = document.defaultView ? document.defaultView : document.parentWindow; if (typeof dv.f_after_scroll == 'function') { dv.f_after_scroll(); } } else { validar_form(document.getElementById("div_form_pesquisa")); } } }, //nome da funcao icon: Ext.MessageBox.QUESTION //imagem que mostra de informa��o }); } function edit_grid_win(nome, url, w, h, x, y, f_grid) { var doc; var dados; var dv = document.defaultView ? document.defaultView : document.parentWindow; doc = window.document; cria_wiw_grid('grid_win_' + nome, url, "", w, h, x, y, f_grid); var form_jan_grid = doc.getElementById('frm_grid_' + nome); doc = form_jan_grid.ownerDocument ? form_jan_grid.ownerDocument : window.document; desabilita_botoes(form_jan_grid); if (typeof dv.w_after_scroll == "function") dv.w_after_scroll(); } function reseta_tela() { var div_resultado_pesquisa = document.getElementById('div_resultado_pesquisa'); var div_grf = document.getElementById('div_grf'); //var div_form_cadastro = document.getElementById('div_form_cadastro'); if (div_resultado_pesquisa) div_resultado_pesquisa.className = 'x-hidden'; if (div_grf) div_grf.className = 'x-hidden'; //if (div_form_cadastro) // div_form_cadastro.className = 'x-hidden'; } function pega_elemento(obj, id, elementos) { var e = ""; if (!elementos) elementos = Array(); for (var i = 0; obj.childNodes && i < obj.childNodes.length; i++) { e = obj.childNodes[i]; // && (e.nodeName != "DIV" || (e.nodeName == "DIV" && e.className != "div_form")) if (e.id == id) elementos.push(obj.childNodes[i]) else if (e.nodeName != "INPUT" && e.nodeName != "SELECT" && e.nodeName != "TEXTAREA" && e.nodeName != "FORM") { elementos = pega_elemento(e, id, elementos); } } return elementos; } function gera_grid() { var tbl_grid = document.getElementById('tbl_grid'); separa(tbl_grid); } function separa(obj) { var tblh = document.getElementById('tblh'); var tblb = document.getElementById('tblb'); var html = ""; for (var i = 0; i < obj.childNodes.length; i++) { // Pega todos os nos filhos exemplo como uma tabela ou xml e = obj.childNodes[i]; switch (e.nodeName) { case 'THEAD': obj.removeChild(e); tblh.appendChild(e); break; case 'TBODY': obj.removeChild(e); tblb.appendChild(e); break; default: break; } } // alert(obj.width); return html; } function btn_grid_atualiza(mostra) { } function btn_grid_atualiza1(mostra) { // se nao foi passado parametro, atribui padrao if (!mostra) mostra = false; var objs = getElementsByClassName('art-button', document); var cont; for (cont = 0; cont < objs.length; cont++) { if (cont >= 0) { if (objs[cont].id == 'btn_novo') { objs[cont].style.display = mostra ? "block" : "none"; } } } } function getElementsByClassName(findClass, parent) { //alert(Browser); var matching = ""; if (Browser == "Microsoft Internet Explorer") { parent = parent || document; var elements = parent.getElementsByTagName('*'); var matching = []; for (var i = 0, elementsLength = elements.length; i < elementsLength; i++) { var regex = new RegExp('\b' + findClass + '\b') if (elements[i].className.match(regex)) { matching.push(elements[i]); } } } else { matching = parent.getElementsByClassName(findClass); } return matching; }