fixes bug#0010358

obs: adicionada funcionalidade de seleção de varias funções para adicionar no perfil. 

dev: Frederico 
qua: Renato

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@80159 d1611594-4594-4d17-8e1d-87c2c4800839
master
bruno.neves 2018-03-22 21:13:03 +00:00
parent a83f231d01
commit fb945ac2d9
4 changed files with 321 additions and 120 deletions

View File

@ -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,6 +70,7 @@ public class EditarPerfilController extends MyGenericForwardComposer {
private List<FuncionSistema> lsFuncionSistema;
private List<FuncionSistema> lsAllFuncionPerfil;
private List<PerfilFuncion> lsPermiso;
private List<PerfilFuncion> lsPermisoRemovidas;
private Combobox cmbFuncionSistema;
private Button btnApagar;
private Window winEditarPerfil;
@ -75,6 +78,11 @@ public class EditarPerfilController extends MyGenericForwardComposer {
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<FuncionSistema>();
lsPermisoRemovidas = new ArrayList<PerfilFuncion>();
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,20 +182,6 @@ 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() {
@ -256,6 +266,12 @@ public class EditarPerfilController extends MyGenericForwardComposer {
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<Component> 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<FuncionSistema> lsFuncionSistemaSemAdicionadas = new ArrayList<FuncionSistema>(lsFuncionSistema) ;
List<PerfilFuncion> todasPermissoesfuncao = new ArrayList<PerfilFuncion>();
for (FuncionSistema funcionSistema : lsFuncionSistemaSemAdicionadas) {
PerfilFuncion pf = new PerfilFuncion();
pf.setFuncionSistema(funcionSistema);
todasPermissoesfuncao.add(pf);
}
for (Iterator<PerfilFuncion> 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<PerfilFuncion> 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<PerfilFuncion> it = todasPermissoesfuncao.iterator(); it.hasNext();) {
PerfilFuncion pf = (PerfilFuncion) it.next();
if(!pf.getFuncionSistema().getNombfuncion().contains(palavraPesquisaRuta.toUpperCase())) {
it.remove();
}
}
// List<PerfilFuncion> lsPermisoSelecionados = new ArrayList<PerfilFuncion>();
// lsFuncionSistemaSemAdicionadas.removeAll(lsAllFuncionPerfil);
// boolean x = lsFuncionSistemaSemAdicionadas.removeAll(permissoListSelList.getListData());
// List<PerfilFuncion> listaAuxTodas = new ArrayList<PerfilFuncion>();
// 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) {
}
}
}
}

View File

@ -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

View File

@ -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);
}

View File

@ -6,30 +6,28 @@
<zk>
<window id="winEditarPerfil" border="normal"
apply="${editarPerfilController}"
width="700px" height="500px" contentStyle="overflow:auto"
apply="${editarPerfilController}" width="800px" height="500px"
contentStyle="overflow:auto"
title="${c:l('editarPerfilController.window.title')}">
<toolbar>
<hbox spacing="5px" style="padding:1px" align="right">
<button id="btnApagar" height="20"
image="/gui/img/remove.png" width="35px"
tooltiptext="${c:l('editarPerfilController.btnApagar.tooltiptext')}"/>
tooltiptext="${c:l('editarPerfilController.btnApagar.tooltiptext')}" />
<button id="btnSalvar" height="20"
image="/gui/img/save.png" width="35px"
tooltiptext="${c:l('editarPerfilController.btnSalvar.tooltiptext')}"/>
tooltiptext="${c:l('editarPerfilController.btnSalvar.tooltiptext')}" />
<button id="btnFechar" height="20"
image="/gui/img/exit.png" width="35px"
onClick="winEditarPerfil.detach()"
tooltiptext="${c:l('editarPerfilController.btnFechar.tooltiptext')}"/>
tooltiptext="${c:l('editarPerfilController.btnFechar.tooltiptext')}" />
<separator orient="vertical" />
<button id="btnCopiar" height="20"
image="/gui/img/copiar.png" width="35px"
tooltiptext="${c:l('editarPerfilController.btnCopiar.tooltiptext')}" />
</hbox>
</toolbar>
<grid>
<columns>
<column width="20%" />
@ -37,52 +35,107 @@
</columns>
<rows>
<row>
<label id="lbNome" value="${c:l('editarPerfilController.lbNome.value')}"/>
<textbox id="txtDescPerfil" constraint="no empty" width="99%" maxlength="20"
<label id="lbNome"
value="${c:l('editarPerfilController.lbNome.value')}" />
<textbox id="txtDescPerfil" constraint="no empty"
width="99%" maxlength="20"
value="@{winEditarPerfil$composer.perfil.descperfil}"
use="com.rjconsultores.ventaboletos.web.utilerias.MyTextbox"/>
use="com.rjconsultores.ventaboletos.web.utilerias.MyTextbox" />
</row>
<row>
<label value="${c:l('editarPerfilController.lhPermiso.label')}"/>
<label
value="${c:l('editarPerfilController.lhPermiso.label')}" />
<bandbox id="bbPesquisaLinha" width="100%"
mold="rounded" readonly="true">
<bandpopup>
<vbox>
<hbox>
<combobox id="cmbFuncionSistema" mold="rounded" model="@{winEditarPerfil$composer.lsFuncionSistema}" width="535px"
use="com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar"/>
<textbox
id="txtPalavraPesquisaPermissao" />
<button id="btnPesquisaPermissao"
image="/gui/img/find.png"
label="${c:l('relatorioLinhasHorarioController.btnPesquisa.label')}" />
<button id="btnLimparLinha"
image="/gui/img/eraser.png"
label="${c:l('relatorioLinhasHorarioController.btnLimpar.label')}" />
</hbox>
</row>
<listbox id="permissaoSelecionadaList"
mold="paging"
use="com.rjconsultores.ventaboletos.web.utilerias.MyListbox"
vflex="true" multiple="false" height="60%" width="710px">
<listhead>
<listheader
label="${c:l('editarPerfilController.lhPermiso.label')}"
width="65%" />
<listheader
label="Permissao"
width="29%" />
<listheader align="center" label=" "
width="6%" />
</listhead>
</listbox>
<paging id="pagingLinha" pageSize="10" />
</vbox>
</bandpopup>
</bandbox>
</row>
<row>
<label value="${c:l('indexController.mniPermisos.label')}"/>
<radiogroup Id="indPermiso">
<radio id="radReadOnly" label="${c:l('editarPerfilController.lhSoloEscritura.label')}" />
<radio id="radWrite" checked="true" label="${c:l('editarPerfilController.lhGrabacion.label')}" />
</radiogroup>
<cell colspan="4">
<borderlayout height="140px" width="100%">
<center border="0">
<listbox id="permissoListSelList"
mold="paging"
use="com.rjconsultores.ventaboletos.web.utilerias.MyListbox"
vflex="true" multiple="true" height="50%" width="100%">
<listhead>
<listheader id="lhPermisoAux"
image="/gui/img/create_doc.gif"
label="${c:l('editarPerfilController.lhPermiso.label')}"
sort="auto(funcionSistema.nombfuncion)" width="60%" />
<listheader align="center"
image="/gui/img/create_doc.gif"
label="${c:l('editarPerfilController.lhLectura.label')}"
width="17%" />
<listheader align="center"
image="/gui/img/create_doc.gif"
label="${c:l('editarPerfilController.lhEscritura.label')}"
width="17%" />
<listheader align="center" width="10%" />
</listhead>
</listbox>
</center>
</borderlayout>
</cell>
</row>
</rows>
</grid>
<toolbar>
<button id="btnAdicionarPermiso" height="20" image="/gui/img/add.png" width="35px"
tooltiptext="${c:l('editarPerfilController.btnAddPermiso.tooltiptext')}"/>
<button id="btnRemoverPermiso" height="20" image="/gui/img/remove.png" width="35px"
tooltiptext="${c:l('editarPerfilController.btnBorrarPermiso.tooltiptext')}"/>
<button id="btnAdicionarPermiso" height="20"
image="/gui/img/add.png" width="35px"
tooltiptext="${c:l('editarPerfilController.btnAddPermiso.tooltiptext')}" />
<button id="btnRemoverPermiso" height="20"
image="/gui/img/remove.png" width="35px"
tooltiptext="${c:l('editarPerfilController.btnBorrarPermiso.tooltiptext')}" />
</toolbar>
<paging id="pagingPermiso" use="com.rjconsultores.ventaboletos.web.utilerias.MyPaging"/>
<listbox id="permisoList" use="com.rjconsultores.ventaboletos.web.utilerias.MyListbox"
<paging id="pagingPermiso"
use="com.rjconsultores.ventaboletos.web.utilerias.MyPaging" />
<listbox id="permisoList"
use="com.rjconsultores.ventaboletos.web.utilerias.MyListbox"
multiple="false">
<listhead sizable="true">
<listheader id="lhPermiso" image="/gui/img/create_doc.gif"
<listheader id="lhPermiso"
image="/gui/img/create_doc.gif"
label="${c:l('editarPerfilController.lhPermiso.label')}"
sort="auto(funcionSistema.nombfuncion)" width="500px"/>
<listheader image="/gui/img/create_doc.gif"
sort="auto(funcionSistema.nombfuncion)" width="70%" />
<listheader align="center" image="/gui/img/create_doc.gif"
label="${c:l('editarPerfilController.lhLectura.label')}"
width="80px"/>
<listheader image="/gui/img/create_doc.gif"
width="15%" />
<listheader align="center" image="/gui/img/create_doc.gif"
label="${c:l('editarPerfilController.lhEscritura.label')}"
width="80px"/>
width="15%" />
</listhead>
</listbox>
</window>
</zk>