From fb945ac2d9115c2c74b2c1ad36b49b4e8d4923ce Mon Sep 17 00:00:00 2001 From: "bruno.neves" Date: Thu, 22 Mar 2018 21:13:03 +0000 Subject: [PATCH] =?UTF-8?q?fixes=20bug#0010358=20obs:=20adicionada=20funci?= =?UTF-8?q?onalidade=20de=20sele=C3=A7=C3=A3o=20de=20varias=20fun=C3=A7?= =?UTF-8?q?=C3=B5es=20para=20adicionar=20no=20perfil.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dev: Frederico qua: Renato git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@80159 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../seguridad/EditarPerfilController.java | 224 ++++++++++++++---- .../ventaboletos/web/utilerias/MyListbox.java | 10 + .../web/utilerias/render/RenderPermiso.java | 2 +- web/gui/seguridad/editarPerfil.zul | 205 ++++++++++------ 4 files changed, 321 insertions(+), 120 deletions(-) diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/seguridad/EditarPerfilController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/seguridad/EditarPerfilController.java index 6cddde73f..2bdd61d0f 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/seguridad/EditarPerfilController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/seguridad/EditarPerfilController.java @@ -9,6 +9,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -39,10 +40,11 @@ import com.rjconsultores.ventaboletos.service.FuncionSistemaService; import com.rjconsultores.ventaboletos.service.PerfilFuncionService; import com.rjconsultores.ventaboletos.service.PerfilService; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; -import com.rjconsultores.ventaboletos.vo.segurida.PerfilJerarquia; import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; import com.rjconsultores.ventaboletos.web.utilerias.MyListbox; import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPermiso; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPermisoSelecao; +import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPermisoSelecionados; /** * @@ -68,12 +70,18 @@ public class EditarPerfilController extends MyGenericForwardComposer { private List lsFuncionSistema; private List lsAllFuncionPerfil; private List lsPermiso; + private List lsPermisoRemovidas; private Combobox cmbFuncionSistema; private Button btnApagar; private Window winEditarPerfil; private Radiogroup indPermiso; private Radio radReadOnly; private Radio radWrite; + + private Textbox txtPalavraPesquisaPermissao; + private MyListbox permissaoSelecionadaList; + private MyListbox permissoListSelList; + public Perfil getPerfil() { return perfil; @@ -111,10 +119,26 @@ public class EditarPerfilController extends MyGenericForwardComposer { public void doAfterCompose(Component comp) throws Exception { lsFuncionSistema = funcionSistemaService.obtenerTodos(); lsAllFuncionPerfil = new ArrayList(); - + lsPermisoRemovidas = new ArrayList(); + super.doAfterCompose(comp); permisoList.setItemRenderer(new RenderPermiso()); + permissoListSelList.setItemRenderer(new RenderPermisoSelecionados(new EventListener() { + + @Override + public void onEvent(Event arg0) throws Exception { + + PerfilFuncion pf = (PerfilFuncion) arg0.getTarget().getAttribute("data"); + for (Object perfilFuncion : permissoListSelList.getListData()) { + if(((PerfilFuncion)perfilFuncion).equals(pf)){ + permissoListSelList.removeItem(pf); + executarPesquisaPermissao(); + break; + } + } + } + })); permisoList.addEventListener("onDoubleClick", new EventListener() { @Override @@ -158,21 +182,7 @@ public class EditarPerfilController extends MyGenericForwardComposer { if (perfil.getPerfilId() == null) { btnApagar.setVisible(Boolean.FALSE); } - cmbFuncionSistema.setItemRenderer(new ComboitemRenderer() { - - @Override - public void render(Comboitem cmbtm, Object o) throws Exception { - FuncionSistema fsItem = (FuncionSistema) o; - for (FuncionSistema fs : lsAllFuncionPerfil) { - if (fsItem.getFuncionsistemaId().equals(fs.getFuncionsistemaId())) { - cmbtm.setVisible(false); - } - } - cmbtm.setLabel(fsItem.getNombfuncion()); - cmbtm.setValue(fsItem); - } - }); - + winEditarPerfil.addEventListener("onClose", new EventListener() { @Override @@ -255,7 +265,13 @@ public class EditarPerfilController extends MyGenericForwardComposer { perfilService.actualizacion(perfil); perfilList.updateItem(perfil); } - + + if(!lsPermisoRemovidas.isEmpty()) { + for (PerfilFuncion pf : lsPermisoRemovidas) { + perfilFuncionService.borrar(pf); + } + lsPermisoRemovidas.clear(); + } Messagebox.show( Labels.getLabel("editarPerfilController.MSG.suscribirOK"), Labels.getLabel("editarPerfilController.window.title"), @@ -306,30 +322,20 @@ public class EditarPerfilController extends MyGenericForwardComposer { } public void onClick$btnAdicionarPermiso(Event ev) { - Comboitem comboItem = cmbFuncionSistema.getSelectedItem(); - if (comboItem != null && indPermiso.getSelectedItem() != null) { - FuncionSistema fs = (FuncionSistema) comboItem.getValue(); - PerfilFuncion pf = new PerfilFuncion(); + for (Object perfilFuncion : permissoListSelList.getListData()) { + PerfilFuncion pf = (PerfilFuncion) perfilFuncion; + pf.setActivo(Boolean.TRUE); - pf.setFuncionSistema(fs); pf.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); pf.setFecmodif(Calendar.getInstance().getTime()); pf.setPerfil(perfil); - if (radReadOnly.isChecked()) { - pf.setIndLectura(Boolean.TRUE); - } else if (radWrite.isChecked()) { - pf.setIndLectura(Boolean.FALSE); - } - lsPermiso.add(pf); permisoList.setData(lsPermiso); perfil.setPerfilFuncionList(lsPermiso); - - cmbFuncionSistema.setSelectedItem(null); - cmbFuncionSistema.setValue(null); - comboItem.setVisible(false); + } + permissoListSelList.getListData().clear(); } public void onClick$btnRemoverPermiso(Event ev) { @@ -339,8 +345,10 @@ public class EditarPerfilController extends MyGenericForwardComposer { pf.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); pf.setFecmodif(Calendar.getInstance().getTime()); + if (pf.getPerfilfuncionId() != null) { - perfilFuncionService.borrar(pf); + pf.setActivo(Boolean.FALSE); + lsPermisoRemovidas.add(pf); } int indice = 0; @@ -357,15 +365,6 @@ public class EditarPerfilController extends MyGenericForwardComposer { permisoList.setData(lsPermiso); perfil.setPerfilFuncionList(lsPermiso); - List children = cmbFuncionSistema.getChildren(); - for (Component c : children) { - if (c instanceof Comboitem) { - Comboitem ci = (Comboitem) c; - if ((!ci.isVisible()) && ((FuncionSistema) ci.getValue()).getFuncionsistemaId().equals(pf.getFuncionSistema().getFuncionsistemaId())) { - ci.setVisible(true); - } - } - } } } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -386,4 +385,143 @@ public class EditarPerfilController extends MyGenericForwardComposer { Labels.getLabel("copiarPerfilController.window.title"), args, MODAL); } + public void onClick$btnPesquisaPermissao(Event ev) { + executarPesquisaPermissao(); + } + + private void executarPesquisaPermissao() { + + permissaoSelecionadaList.setItemRenderer(new RenderPermisoSelecao(new EventListener() { + + @Override + public void onEvent(Event arg0) throws Exception { + PerfilFuncion pf = (PerfilFuncion) arg0.getTarget().getAttribute("data"); + if(arg0.getTarget().getAttribute("tipo").equals(RenderPermisoSelecao.BOTAO_ADICIONAR_PERMISSAO)) { + + + if(permissoListSelList.getListData().isEmpty()) { + permissoListSelList.addItemNovo(pf); + }else { + for (Object perfilFuncion : permissoListSelList.getListData()) { + if(!((PerfilFuncion)perfilFuncion).equals(pf)){ + permissoListSelList.addItemNovo(pf); + break; + } + } + + } + + permissaoSelecionadaList.removeItem(pf); + }else { + if(arg0.getTarget().getAttribute("tipo").equals(RenderPermisoSelecao.RADIO_READ_ONLY)) { + Integer posicao = permissaoSelecionadaList.getListData().indexOf(pf); + pf.setIndLectura(((Radio)arg0.getTarget()).isChecked()); + + permissaoSelecionadaList.removeItem(pf); + permissaoSelecionadaList.addItemNovo(posicao, pf); + }else if(arg0.getTarget().getAttribute("tipo").equals(RenderPermisoSelecao.RADIO_WRITE)) { + Integer posicao = permissaoSelecionadaList.getListData().indexOf(pf); + pf.setIndLectura(!((Radio)arg0.getTarget()).isChecked()); + + permissaoSelecionadaList.removeItem(pf); + permissaoSelecionadaList.addItemNovo(posicao, pf); + } + } + } + })); + + String palavraPesquisaRuta = txtPalavraPesquisaPermissao.getText(); + List lsFuncionSistemaSemAdicionadas = new ArrayList(lsFuncionSistema) ; + + List todasPermissoesfuncao = new ArrayList(); + + for (FuncionSistema funcionSistema : lsFuncionSistemaSemAdicionadas) { + PerfilFuncion pf = new PerfilFuncion(); + pf.setFuncionSistema(funcionSistema); + todasPermissoesfuncao.add(pf); + } + + + for (Iterator it = todasPermissoesfuncao.iterator(); it.hasNext();) { + PerfilFuncion pf = (PerfilFuncion) it.next(); + for (PerfilFuncion perfilFuncion : perfil.getPerfilFuncionList()) { + if(pf.getFuncionSistema().equals(perfilFuncion.getFuncionSistema())) { + it.remove(); + } + } + + } + for (Iterator it = todasPermissoesfuncao.iterator(); it.hasNext();) { + PerfilFuncion pf = (PerfilFuncion) it.next(); + for (Object perfilFuncion : permissoListSelList.getListData()) { + if(pf.getFuncionSistema().equals(((PerfilFuncion)perfilFuncion).getFuncionSistema())) { + it.remove(); + } + } + + } + + for (Iterator it = todasPermissoesfuncao.iterator(); it.hasNext();) { + PerfilFuncion pf = (PerfilFuncion) it.next(); + if(!pf.getFuncionSistema().getNombfuncion().contains(palavraPesquisaRuta.toUpperCase())) { + it.remove(); + } + } + + +// List lsPermisoSelecionados = new ArrayList(); +// lsFuncionSistemaSemAdicionadas.removeAll(lsAllFuncionPerfil); +// boolean x = lsFuncionSistemaSemAdicionadas.removeAll(permissoListSelList.getListData()); +// List listaAuxTodas = new ArrayList(); +// listaAuxTodas.addAll(perfil.getPerfilFuncionList()); +// listaAuxTodas.addAll(permissoListSelList.getListData()); + + + + + + + + + + + + +// for (PerfilFuncion perfilFuncion : listaAuxTodas) { +// for (FuncionSistema fs : lsFuncionSistemaSemAdicionadas) { +// if(fs.getNombfuncion().contains(palavraPesquisaRuta.toUpperCase())) { +// //if(!perfilFuncion.getFuncionSistema().getNombfuncion().equals(fs.getNombfuncion())) { +// if(!lsPermisoSelecionados.contains(perfilFuncion) && !permissoListSelList.getListData().contains(perfilFuncion)) { +// PerfilFuncion novo = new PerfilFuncion(); +// novo.setFuncionSistema(fs); +// lsPermisoSelecionados.add(novo); +// break; +// } +// //} +// } +// } +// } +// +// for (PerfilFuncion pf : perfil.getPerfilFuncionList()) { +// if(pf.getFuncionSistema().getNombfuncion().contains(palavraPesquisaRuta.toUpperCase())) { +// if(!lsPermiso.contains(pf)) { +// lsPermisoSelecionados.add(pf); +// } +// +// +// } +// } +// + permissaoSelecionadaList.setData(todasPermissoesfuncao); + + if (permissaoSelecionadaList.getData().length == 0) { + try { + Messagebox.show(Labels.getLabel("MSG.ningunRegistro"), + Labels.getLabel("relatorioLinhasHorarioController.window.title"), + Messagebox.OK, Messagebox.INFORMATION); + } catch (InterruptedException ex) { + } + } + } + } diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/MyListbox.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/MyListbox.java index e5b2c234f..1f3a97fcd 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/utilerias/MyListbox.java +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/MyListbox.java @@ -44,6 +44,16 @@ public class MyListbox extends Listbox { return Boolean.FALSE; } } + public boolean addItemNovo(Integer posicao , Object item) { + try { + this.modelList.add(posicao,item); + super.setModel(modelList); + + return Boolean.TRUE; + } catch (Exception e) { + return Boolean.FALSE; + } + } /** * Adiciona um item na lista caso ele não esteja presente na lista diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderPermiso.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderPermiso.java index 9f57f5c70..e2fdeb6bd 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderPermiso.java +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/render/RenderPermiso.java @@ -30,7 +30,7 @@ public class RenderPermiso implements ListitemRenderer { lc = new Listcell(); - boolean indLectura = permiso.getIndLectura() == null ? false : permiso.getIndLectura(); + boolean indLectura = permiso.getIndLectura() == null ? true : permiso.getIndLectura(); if (indLectura) { chkRead.setChecked(Boolean.TRUE); } diff --git a/web/gui/seguridad/editarPerfil.zul b/web/gui/seguridad/editarPerfil.zul index 71b0e6907..15436fcd1 100644 --- a/web/gui/seguridad/editarPerfil.zul +++ b/web/gui/seguridad/editarPerfil.zul @@ -5,84 +5,137 @@ - - - -