var nomeDialogoAtivo = ""; $(function(){ definirReferenciasAjax(); $().ajaxStart( function() { $("#bloquerBrowser").show(); }); $().ajaxComplete( function() { definirReferenciasAjax(); $("#bloquerBrowser").hide(); }); $().ajaxSuccess( function(evnt, request, settings) { if ( nomeDialogoAtivo != '' && nomeDialogoAtivo != undefined ){ $("#" + nomeDialogoAtivo).dialog("destroy"); $("#" + nomeDialogoAtivo).remove(); $(document.body).append(request.responseText); $("#" + nomeDialogoAtivo).dialog({ autoOpen :false, modal :true, width :750, height :500, resizable :false, zIndex :1000 }); $("#" + nomeDialogoAtivo).dialog("open"); } $("#bloquerBrowser").hide(); }); $().ajaxError( function(request, settings, exception) { $("#bloquerBrowser").hide(); }); $("form").submit(function(eventObject){ $('#area-mensagens').remove(); //POG--Corrigir problema ao fazer download de relatorios, etc. if ($('#isRelatorio') == undefined || $('#isRelatorio').attr('value') == undefined || $('#isRelatorio').attr('value') == 'false') { $("#bloquerBrowser").show(); } else { $('#isRelatorio').attr('value', 'false'); } //} }); $("input[type='submit']").click(function(eventObject){ if(($(this).attr('value').toUpperCase() == 'CONSULTAR') || ($(this).attr('value').toUpperCase() == 'CONSULTA')){ $("input[name='paginaAtual']").attr('value','1'); } }); // Dialog exemplo $('#dialog-exemplo').dialog({ autoOpen :false, modal :true, width :600, height :400, resizable :false }); // Dialog exemplo link $('#dialog-exemplo-link').click(function(){ $('#dialog-exemplo').dialog('open'); return false; }); // Dialog confirm $('#dialog-confirm').dialog({ autoOpen :false, modal :true, resizable :false, buttons: { "N�o": function() { $(this).dialog("close"); }, "Sim": function() { submeter(); $(this).dialog("close"); } } }); // Dialog confirm link $('#dialog-confirm-link').click(function(){ $('#dialog-confirm').dialog('open'); return false; }); // Dialog fun��es gerais $('#dialog-funcoes').dialog({ autoOpen :false, modal :true, width :600, height :400, resizable :false }); // Dialog fiun��es gerais link $('#dialog-funcoes-link').click(function(){ $('#dialog-funcoes').dialog('open'); return false; }); // Dialog fiun��es gerais link $('#dialog-situacao-link').click(function(){ $('#dialog-situacao').dialog('open'); return false; }); // Datepicker $('#campo-data-de').datepicker({ changeMonth :true, changeYear :true, yearRange :'1900:2010' }); $('#campo-data-a').datepicker({ changeMonth :true, changeYear :true, yearRange :'1900:2010' }); }); function bloquearBrowser(){ $("#bloquerBrowser").show(); } function desbloquearBrowser(){ $("#bloquerBrowser").hide(); } function chkBoxChildByName(objectCheck, nameChkChildArquivo){ var isChecked = !$(objectCheck).attr("checked"); $('input[name="'+nameChkChildArquivo+'"]').attr("checked", !isChecked); return true; } function controlCheckAll(objectCheck, nameCheckAll) { var name = $(objectCheck).attr('name'); var totalMarcados = $("input:checkbox[name='"+name+"']:checked").length; var totalChecks = $("input:checkbox[name='"+name+"']").length; var totalDesabilitados = $("input:checkbox[name='"+name+"']:disabled").length if (totalMarcados == (totalChecks - totalDesabilitados)){ $('#'+nameCheckAll).attr('checked', 'checked'); }else{ $('#'+nameCheckAll).removeAttr('checked'); } } /* * Remover a div de mensagens da popup */ function removerBarraMensagens(popup) { $("#" + popup + " > div").remove(); } /** * M�todo exclusivamente utilizando para remover valores de input type text, select e textarea * @return */ function removerValoresInputs(){ $("input[type='text']").attr("value", ""); $("textarea").val(""); $("select").each(function(sel){ $(this).attr("selectedIndex", 0); }); } function abrirManualUsuario(ref) { window.open('paginas/manualusuario/MAPA-SISZARC_Manual_do_Usuario.htm#'+ref,'SISZARC_AJUDA', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=400'); } function desabilitarInputsForm(){ $("input[type='text']").attr("disabled", true); $("input[type='radio']").attr("disabled", true); $("input[type='checkbox']").attr("disabled", true); $("select").attr("disabled", true); $("textarea").attr("disabled", true); } function habilitaInputsForm(){ $("input[type='text']").attr("disabled", false); $("input[type='radio']").attr("disabled", false); $("input[type='checkbox']").attr("disabled", false); $("select").attr("disabled", false); $("textarea").attr("disabled", false); } //Habilita os inputs/object/element de todos os filhos do elemento pai(passando o id do element pai). //IdElement parent, isHabilitar (false or true) function habilitaDesabilitaInputsChildsForm(idElement, isHabilitar){ var pegaTodos = { pega : function(maiorDeTodos){ var filho; // Passo por todos os controles. $(maiorDeTodos).children().each(function(i){ filho = $(this); var nomeTag = $.trim($(filho).attr("tagName")); if($(filho).attr('type') != undefined && $.trim($(filho).attr('type').toLowerCase()) != 'text/javascript' && $.trim($(filho).attr('type').toLowerCase()) != 'hidden' && $.trim(nomeTag.toLowerCase()) != 'script'){ if($(filho).attr("disabled") == !isHabilitar){ $(filho).attr("disabled", isHabilitar); } if( $(filho).css("display") == 'hidden' || $(filho).css("display") == 'none' || $(filho).css("visibility") == 'hidden'){ if(isHabilitar){ $(filho).show(); }else{ $(filho).hide(); } } } if ($(filho).children().length != 0) { pegaTodos.pega($(filho)); } }); }}; pegaTodos.pega($("#"+idElement)); } function removerAreaMensagem(){ $('#area-mensagens').remove(); $('#areaMensagemDownload').html(''); } function selecionarTodosComboMultiple(idCombo){ $("#"+idCombo +" option").each(function(){ $(this).attr('selected', true); }); } function adicionarItemCombo(select, value, text){ if(value != ''){ var naoAchou = true; $("#"+select+" option").each(function() { if($(this).attr("value") == value){ naoAchou = false; } }); if(naoAchou){ $("#"+select).append(""); } } } function preencherListaCombo(idSelect, idSelectDestino){ var select = document.getElementById(idSelect); for ( var i = 0; i < select.length; i++) { if(select[i].selected) { adicionarItemCombo(idSelectDestino, select[i].value, select[i].text); } } $("#"+idSelect+" option:selected").remove(); } function preencherTodosListaCombo(idSelect, idSelectDestino){ var select = document.getElementById(idSelect); for ( var i = 0; i < select.length; i++) { adicionarItemCombo(idSelectDestino, select[i].value, select[i].text); } $("#"+idSelect).attr("value",''); $("#"+idSelect).empty(); } //Funcao Ajax Generica a ser usado por submit popup. function registrarBotaoPopup(objJQuery) { $(objJQuery).unbind('click'); objJQuery.click(function() { var formPai = getElementoPai($(this), "FORM"); var formAcao = $(formPai).attr('action'); var indexSeparador = formAcao.indexOf("."); var nomeBotao = $(this).attr("name"); var botao = $(this); var url = formAcao.substring(0, indexSeparador); url += "!"; url += nomeBotao.substring(nomeBotao.indexOf(":")+1); url += ".action"; $.ajax({ type: "POST", url: url, data: $(formPai).serialize(), success: function(response){ var dialog = getElementoPai($(botao), "DIV", "dialog"); nomeDialogoAtivo = $(dialog).attr("id"); if (botao.attr('fechar')) { onclose = botao.attr('onclose'); if (onclose != null && onclose != '') { eval(onclose); } $("#"+nomeDialogoAtivo).dialog('close'); if (botao.attr('remover')) { $("#"+nomeDialogoAtivo).dialog('destroy').remove(); } nomeDialogoAtivo = ''; } } }); return true; }); objJQuery.each(function(index) { var frm = $(this).closest("form"); var btn = $('#submitPopup', frm); frm.unbind('submit'); frm.submit(function() { btn.click(); return false; }); }); }; function registrarSubmitPopup(objJQuery) { $(objJQuery).unbind('click'); objJQuery.click(function() { var idToId = $("#" + nomeDialogoAtivo + " > form > input[id='idToId']").get(0).value; var value = $("input[id='resultado_hidden']").get(0).value; var formSubmit = $("#" + nomeDialogoAtivo + " > form > input[id='formSubmit']").get(0).value; var metodoSubmit = $("#" + nomeDialogoAtivo + " > form > input[id='metodoSubmit']").get(0).value; $('input[id="'+idToId+'"]').val(value); $(getElementoPai($(this), "DIV", "dialog")).dialog('close'); if ((metodoSubmit.length > 0) && (formSubmit.length > 0)) { var formulario = $('form[id="'+formSubmit+'"]'); var formAcao = $(formulario).attr("action"); var metodoAcao = "!"+metodoSubmit+".action"; //Verifica se a url já está ajustada antes de fazê-lo if(!(new RegExp(metodoAcao).test(formAcao))) { var indexSeparador = formAcao.indexOf("."); var url = formAcao.substring(0, indexSeparador) + metodoAcao; $('form[id="'+formSubmit+'"]').get(0).action = url; } $('form[id="'+formSubmit+'"]').get(0).submit(); } return false; }); } function definirReferenciasAjax() { bloqBrowser = true; //Funcao Ajax Generica a ser usado por submit. registrarBotaoPopup($("button[id='submitPopup']")); registrarSubmitPopup($('#resultado-link')); } /* * Esta função retorna uma referência do elemento pai que contenha a * tagPai e o idPai quando este for informado. */ function getElementoPai(elementFilho, tagPai, idPai) { var elementoPai = $(elementFilho).parents() .map(function () { if ((this.tagName == tagPai) && (($(this).attr('id').indexOf(idPai) > -1) || (typeof(idPai) == "undefined"))) { return this; } }) .get(0); return elementoPai; } function limita(campo, tamanhoMaximo) { var tamanho = campo.value.length; var tex = campo.value; if (tamanho >= tamanhoMaximo) { campo.value = tex.substring(0, tamanhoMaximo); } return true; } function limparFormulario(form,excessao, div) { $(form).find(':input').each(function() { if(this.id!=excessao){ switch(this.type) { case 'password': case 'select-multiple': case 'select-one': case 'text': case 'textarea': $(this).val(''); break; case 'checkbox': case 'radio': this.checked = false; } } if(!isVazio(div)){ $(div).remove(); } }); } function isVazio(sString){ var regEspaco = /\s/g; sString = sString.replace(regEspaco, ""); return (sString == ""); }