// ******************************************************************************************************************************* // Classe que gerencia as abas (geral e interna) // ******************************************************************************************************************************* /* parâmetros para o construtor New AbasGeral ou para o construtor New AbasInterna( lista com objetos com os atributos de cada aba: { label: texto que aparece em cada aba acao: funcão que será invocada quando a aba for clicada inicia: quando setado como true, indica que aba será clicada no momento que as abas forem montadas se nenhuma for setada como "inicia", a inicial será a primeira da lista } ) */ // guarda globalmente qual o último objeto carregado pelas abas var objAtualCarregado; // sub-classe abasGeral (baseada na classe Abas e que gerencia as abas no topo da página) function AbasGeral(lista) { Abas.call(this, lista); colocaClasse(obj('main'), 'comAba'); colocaClasse(obj('apoio'), 'comAba'); } AbasGeral.prototype = new Abas; AbasGeral.prototype.constructor = AbasGeral; AbasGeral.prototype.rodaAcao = function() { this.acao.apply(this); }; // sub-classe abasInterna (baseada na classe Abas e que gerencia as abas na área de conteúdo da página) function AbasInterna(lista, item, ehSubAba, consolidado, dialog, labelConsolidado, idPaginaBotao) { Abas.call(this, lista, item, ehSubAba, consolidado, dialog, labelConsolidado, idPaginaBotao) } AbasInterna.prototype = new Abas; AbasInterna.prototype.constructor = AbasInterna; AbasInterna.prototype.rodaAcao = function() { // o this deste método é cada aba var estaAba = this; this.abasInterna = true; if (this.abasPai.listaAbas) this.abasPai.listaAbas.setAttribute("abaSelecionada", this.id); var ulAbas = (this.li) ? this.li.parentNode : false; this.item.pai.abaClick = this.id; // limpar o conteúdo do main quando clicar em uma aba if (ulAbas) limpaConteudo((this.sub == true) ? obj('conteudo') : ulAbas.parentNode, [ulAbas]); if (this.abasPai.ehSubAba) removeObj(obj('cabecalho')); // limpando o conteudo da subAba quando for clicado em uma aba onde a mesma não tenha sub abas. if (this.subAbas) this.montaSubAbas(); // montando o cabeçalho var elementoAlvo = (this.item.pai.elementoAlvoCont) ? this.item.pai.elementoAlvoCont : obj('conteudo'); if (ulAbas) { removeObj(elementoAlvo); if (ulAbas.parentNode) { this.objCabecalho = new Cabecalho(this.item, this); ulAbas.parentNode.appendChild(this.objCabecalho.monta()); } } else if (this.item.pai.abaDialog) { $("div#abaDialog").dialog("close"); var dialog = this.item.pai.abaDialog; this.divDialog = $("
").appendTo(elementoAlvo).dialog({ autoOpen: false, width: (dialog.largura || Math.round(0.8 * tamanhoTela().largura)), height: (dialog.altura || Math.round(0.8 * tamanhoTela().altura)), modal: dialog.modal, title: estaAba.label, show: { effect: "scale", duration: 200 }, hide: { effect: "scale", duration: 200 }, close: function() { $(this).remove(); }, }).dialog("open")[0]; } $(this.divDialog).on( "dialogbeforeclose", function() { temAlteracao.verificaAlterados(estaAba, 'fecha'); return false; } ); // indica se o último objeto carregado pelas abas já foi descarregado (carregado outro) if (objAtualCarregado) objAtualCarregado.descarregado = true; this.acao(); objAtualCarregado = this.item.conteudo; }; // construtor da class Abas function Abas(lista, item, ehSubAba, consolidado, dialog, labelConsolidado, idPaginaBotao) { // console.log(lista); if (consolidado) this.consolidado = consolidado; this.labelConsolidado = labelConsolidado; this.idPaginaBotao = idPaginaBotao; this.item = item; this.lista = lista; this.dialog = (this.item && this.item.pai && this.item.pai.abaDialog); if (ehSubAba) this.ehSubAba = ehSubAba; // console.log(this.ehSubAba); if (this.lista && this.lista.length > 0) { var elementoBase = this.pai || this.item.elementoAlvo; this.listaAbas = this.monta(); if (elementoBase) { if (this.listaAbas) elementoBase.appendChild(this.listaAbas); } } if (this.inicial) this.inicial.carrega.call(this.inicial); } // método que monta uma ul com as abas para ser colocada na tela cria('ul', { className: 'subAbas' }) Abas.prototype.monta = function() { if (!this.dialog) var elem = (this.ehSubAba) ? cria('ul', { id: 'subabas', className: 'abas subAbas' }) : cria('ul', { id: 'abas', className: 'abas' }); this.inicial = false; var primeiraAba; var sub = (this.ehSubAba) ? true : false; // se for um item novo, só mantém na lista de abas as que tiverem o parâmetro "novo" setado como true // por enquanto apenas uma aba pode ser setada como "novo", não uma subAba // (pois se for uma subAba tem que abrir a aba mas selecionar a subAba - se precisar, implementa). // se não for um item novo, tira as abas que tem o parâmetro "sohNovo" (que só aparecem em itens novos) var ehNovo = (this.item && this.item.id && this.item.id.toString().substring(0,4) == 'novo'); var listaAbas = []; if (ehNovo) { for (var i = 0; i < this.lista.length; i++) if (this.lista[i].novo) listaAbas.push(this.lista[i]); } else { for (var i = 0; i < this.lista.length; i++) if (!this.lista[i].sohNovo) listaAbas.push(this.lista[i]); } this.lista = listaAbas; for (var i = 0; i < this.lista.length; i++) { var esta = this.lista[i]; var subAbas = (ehNovo) ? null : esta.subAbas; var objAba = new Aba(esta.label, esta.acao, this.item, this.rodaAcao, esta.id, esta.botoes, this.lista.length, subAbas, sub, this, esta.perm, esta.func, esta.parametros, this.dialog, esta.estilo, esta.camposHab); esta.objAba = objAba; //se a permissao for igual a 0 nao monta a aba //if (esta.objAba.perm > 0) elem.appendChild(objAba.cria()); if (elem) elem.appendChild(objAba.cria()); if (this.item && this.item.pai && this.item.pai.abaClick == esta.id) this.inicial = objAba; if (!this.inicial && esta.inicia) this.inicial = objAba; if (i == 0) primeiraAba = objAba; } // se for subAba não precisa ter uma das abas selecionadas if (!this.inicial && !this.ehSubAba) this.inicial = primeiraAba; var permConsolidado = (typeof(_info) == "undefined" || _info.permConsolidado == undefined || _info.permConsolidado > 0); if (this.consolidado && permConsolidado) { var ini = queryString("ini"); var visu = queryString("visu"); var submenu = queryString("submenu"); var ce = queryString("ce"); var repos = queryString("repos"); var anohist = queryString("anohist"); var txttop = queryString("txttop"); var idPaginaBotao = (this.idPaginaBotao) ? this.idPaginaBotao : "31"; var labelBotao = (this.labelConsolidado) ? this.labelConsolidado : "consolidado"; var urlRelatorio = 'relat.php?pag=' + idPaginaBotao + '&ini=' + ini + '&visu=' + visu + '&submenu=' + submenu + '&ce=' + ce + '&repos=' + repos + '&anohist=' + anohist + '&txttop=' + txttop + '&relatorio=' + this.consolidado; if (elem) elem.appendChild(cria('a', { href: urlRelatorio, className: "botaoSuperior consolidado" }, null, labelBotao)); } return elem; }; // ******************************************************************************************************************************* // ******************************************************************************************************************************* // ******************************************************************************************************************************* // Classe que gerencia cada Aba da lista de Abas // ******************************************************************************************************************************* function Aba(label, acao, item, rodaAcao, id, botoes, qtde, subAbas, sub, abasPai, perm, func, parametros, dialog, estilo, camposHab) { this.label = label; this.acao = acao; this.parametros = parametros; this.item = item; this.rodaAcao = rodaAcao; this.id = id; this.botoes = botoes; this.qtde = qtde; this.classeOrigem = 'Aba'; this.abasPai = abasPai; this.subAbas = subAbas; this.sub = sub; this.perm = perm; this.func = (func) ? ((typeof(func) == 'string') ? jQuery.parseJSON(func) : func) : {}; this.estilo = estilo; this.camposHab = camposHab; } Aba.prototype.cria = function() { this.li = cria('li'); var estaAba = this; if (this.subAbas) colocaClasse(this.li, 'comSubAbas'); var classe = (this.label) ? "" : "dispsome"; const margin = (this.sub) ? (7 - this.qtde) + '%' : (9 - this.qtde) + '%'; const estilo = (typeof(this.estilo) != "undefined") ? this.estilo : { marginLeft: margin }; var link = this.li.appendChild(cria('a', { href: '#', className: classe }, estilo, this.label)); link.appendChild(cria('div', { className: 'divTampa' })); $(link).click(function(e) { e.preventDefault(); this.blur(); var li = sobeDOM(this, 'li'); // só é clicável se não estiver desabilitado e se não estiver selecionada (a não ser que seja com subabas, quando pode ser clicável) if (!temClasse(li, 'desabilitado') && (!temClasse(li, 'selecionada') && !estaAba.desabilitado || temClasse(li, 'comSubAbas'))) temAlteracao.verificaAlterados(estaAba, 'carrega'); }); // if (!_IE6) { // link.appendChild(canto.sup_esq()); // link.appendChild(canto.sup_dir()); // } return this.li; }; Aba.prototype.carrega = function() { if (this.li) { var todasAbas = this.li.parentNode.childNodes; for (var i = 0; i < todasAbas.length; i++) tiraClasse(todasAbas[i], 'selecionada'); colocaClasse(this.li, 'selecionada'); if (this.item && this.item.pai && temClasse(this.item.pai.elementoBase, 'vemDaMatricula' )) { tiraClasse(this.item.pai.elementoBase, 'vemDaMatricula'); if (temClasse(this.item.pai.elementoBase, 'nivel1' )) this.item.pai.botAmplia.click(); } } this.abasPai.aberta = this; this.rodaAcao(); }; Aba.prototype.fecha = function() { // fecha abas dialog $(this.divDialog).unbind("dialogbeforeclose").dialog("close"); }; Aba.prototype.montaSubAbas = function() { new AbasInterna(this.subAbas, this.item, true); }; Aba.prototype.permissao = function(acao) { //log(this.perm, this.func, acao); if (acao && acao.substring(0,5) == 'func:') { const func = acao.substring(5); return (this.func && this.func[func] == 1); } else { var acoes = ["editar|gravar", "incluir", "excluir"]; var pos = -1; for (var i = 0, t = acoes.length; t--; i++) if (acoes[i].indexOf(acao) >= 0) pos = i; // this.perm = 1.consulta, 2.edita, 3.inclui, 4.exclui if (pos < 0) return true; else return (this.perm > (pos + 1)); } }; // ******************************************************************************************************************************* // ******************************************************************************************************************************* // ******************************************************************************************************************************* // Classe que gerencia os cabeçalhos do conteúdo // ******************************************************************************************************************************* function Cabecalho(item, aba, parametros) { if (!item) item = {}; this.item = item; this.aba = aba; this.classeObjeto = 'cabecalho'; this.botoes = aba.botoes; if (!parametros) parametros = {}; this.formato = (item.pai && item.pai.formatoCabecalho) ? item.pai.formatoCabecalho : parametros.formato; this.nome = (item.nome) ? item.nome : parametros.nome; this.id = (item.id) ? this.item.id : parametros.id; this.botaoAdd = (item.pai && item.pai.botaoAdd) ? this.item.pai.botaoAdd : parametros.botaoAdd; } Cabecalho.prototype.monta = function() { // recuperando o objeto DOM do cabeçalho // this.onde = obj('cabecalho'); // console.log(this); // se existir limpa o conteudo if (this.onde) limpaConteudo(this.onde); // senão cria else this.onde = cria('div', { id: 'cabecalho' }); if (this.aba.sub) $(this.onde).addClass("sub"); if (this.item && this.item.id && this.item.id.toString().substring(0,4) != 'novo' && this.item.ativo != 1 && this.item.pai.tipInativo) { $(this.onde).addClass("inativo") .append("") .attr("title", this.item.pai.tipInativo); } // recuperando o conteudo var conteudo = (this.formato) ? this.formato.call(this.item) : cria('label', null, null, this.nome); // se o item for novo troca o cabecalho por um novo var ehNovo = (this.id && this.id.toString().substring(0,4) == 'novo') ? true : false; if (ehNovo && !this.item.formatoPadrao) conteudo = cria('label', { className: 'novo' }, null, this.botaoAdd); // aplicando o conteudo no cabeçalho this.onde.appendChild(conteudo); var title = conteudo.getAttribute("title") || conteudo.getAttribute("tip") || this.nome || this.botaoAdd; conteudo.setAttribute("title", title); this.tituloCont = conteudo; // coloca os botões (só se existirem) this.objBotoes = new clBotoes(this, ehNovo); // caso nao tenha o item coloca a referencia do cabeçalho para a aba. if (this.item) { this.item.objCabecalho = this; this.item.cabecalho = this.onde; } else { this.aba.objCabecalho = this; this.aba.cabecalho = this.onde; } return this.onde; } Cabecalho.prototype.habilitaBotoes = function() { //bot = this.item.objCabecalho.aba.botoes; //if (bot) for (var ibot = 0, totBots = bot.length; totBots--; ibot++) if (bot[ibot].objBotao) botao.habilita(bot[ibot].objBotao); this.objBotoes.habilita(); } // ******************************************************************************************************************************* // ******************************************************************************************************************************* // ******************************************************************************************************************************* // Abas superiores (que mudam todo o conteúdo da página) // ******************************************************************************************************************************* function SobreAbas(parametros) { for (var i in parametros) this[i] = parametros[i]; this.classeObjeto = 'sobreAba'; // exemplo de parâmetros: // abas: [ // { label: "acervo", id: "acervo", tip: "publicações do acervo da biblioteca", acao: bibl.montaLista, inicial: true, abas: [94, 95, 96, 100] }, // { label: "leitores", id: "leitores", tip: "todos que podem emprestar publicações do acervo", acao: leitores.montaLista, abas: [97, 98, 99] } // ] } SobreAbas.prototype.monta = function() { var inicial, temSobreAbas = {}; for (var i = 0, t = _info.abas.length; t--; i++) { var idAba = parseInt(_info.abas[i].id, 10); for (var k = 0; k < this.abas.length; k++) { if (this.abas[k].abas.indexOf(idAba) >= 0) temSobreAbas[this.abas[k].id] = true; } } var chaves = Object.keys(temSobreAbas); if (chaves.length < 1) return; if (chaves.length == 1) { // não mostra a sobreAbas e já abre as abas da única sobreAba for (var i = 0; i < this.abas.length; i++) { if (this.abas[i].id == chaves[0]) { this.abas[i].acao(); break; } } } else { var esteAbas = this; this.ul = $("