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.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; 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.PerfilFuncionService;
import com.rjconsultores.ventaboletos.service.PerfilService; import com.rjconsultores.ventaboletos.service.PerfilService;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; 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.MyGenericForwardComposer;
import com.rjconsultores.ventaboletos.web.utilerias.MyListbox; import com.rjconsultores.ventaboletos.web.utilerias.MyListbox;
import com.rjconsultores.ventaboletos.web.utilerias.render.RenderPermiso; 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> lsFuncionSistema;
private List<FuncionSistema> lsAllFuncionPerfil; private List<FuncionSistema> lsAllFuncionPerfil;
private List<PerfilFuncion> lsPermiso; private List<PerfilFuncion> lsPermiso;
private List<PerfilFuncion> lsPermisoRemovidas;
private Combobox cmbFuncionSistema; private Combobox cmbFuncionSistema;
private Button btnApagar; private Button btnApagar;
private Window winEditarPerfil; private Window winEditarPerfil;
@ -75,6 +78,11 @@ public class EditarPerfilController extends MyGenericForwardComposer {
private Radio radReadOnly; private Radio radReadOnly;
private Radio radWrite; private Radio radWrite;
private Textbox txtPalavraPesquisaPermissao;
private MyListbox permissaoSelecionadaList;
private MyListbox permissoListSelList;
public Perfil getPerfil() { public Perfil getPerfil() {
return perfil; return perfil;
} }
@ -111,10 +119,26 @@ public class EditarPerfilController extends MyGenericForwardComposer {
public void doAfterCompose(Component comp) throws Exception { public void doAfterCompose(Component comp) throws Exception {
lsFuncionSistema = funcionSistemaService.obtenerTodos(); lsFuncionSistema = funcionSistemaService.obtenerTodos();
lsAllFuncionPerfil = new ArrayList<FuncionSistema>(); lsAllFuncionPerfil = new ArrayList<FuncionSistema>();
lsPermisoRemovidas = new ArrayList<PerfilFuncion>();
super.doAfterCompose(comp); super.doAfterCompose(comp);
permisoList.setItemRenderer(new RenderPermiso()); 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() { permisoList.addEventListener("onDoubleClick", new EventListener() {
@Override @Override
@ -158,20 +182,6 @@ public class EditarPerfilController extends MyGenericForwardComposer {
if (perfil.getPerfilId() == null) { if (perfil.getPerfilId() == null) {
btnApagar.setVisible(Boolean.FALSE); 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() { winEditarPerfil.addEventListener("onClose", new EventListener() {
@ -256,6 +266,12 @@ public class EditarPerfilController extends MyGenericForwardComposer {
perfilList.updateItem(perfil); perfilList.updateItem(perfil);
} }
if(!lsPermisoRemovidas.isEmpty()) {
for (PerfilFuncion pf : lsPermisoRemovidas) {
perfilFuncionService.borrar(pf);
}
lsPermisoRemovidas.clear();
}
Messagebox.show( Messagebox.show(
Labels.getLabel("editarPerfilController.MSG.suscribirOK"), Labels.getLabel("editarPerfilController.MSG.suscribirOK"),
Labels.getLabel("editarPerfilController.window.title"), Labels.getLabel("editarPerfilController.window.title"),
@ -306,30 +322,20 @@ public class EditarPerfilController extends MyGenericForwardComposer {
} }
public void onClick$btnAdicionarPermiso(Event ev) { public void onClick$btnAdicionarPermiso(Event ev) {
Comboitem comboItem = cmbFuncionSistema.getSelectedItem(); for (Object perfilFuncion : permissoListSelList.getListData()) {
if (comboItem != null && indPermiso.getSelectedItem() != null) { PerfilFuncion pf = (PerfilFuncion) perfilFuncion;
FuncionSistema fs = (FuncionSistema) comboItem.getValue();
PerfilFuncion pf = new PerfilFuncion();
pf.setActivo(Boolean.TRUE); pf.setActivo(Boolean.TRUE);
pf.setFuncionSistema(fs);
pf.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); pf.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
pf.setFecmodif(Calendar.getInstance().getTime()); pf.setFecmodif(Calendar.getInstance().getTime());
pf.setPerfil(perfil); pf.setPerfil(perfil);
if (radReadOnly.isChecked()) {
pf.setIndLectura(Boolean.TRUE);
} else if (radWrite.isChecked()) {
pf.setIndLectura(Boolean.FALSE);
}
lsPermiso.add(pf); lsPermiso.add(pf);
permisoList.setData(lsPermiso); permisoList.setData(lsPermiso);
perfil.setPerfilFuncionList(lsPermiso); perfil.setPerfilFuncionList(lsPermiso);
cmbFuncionSistema.setSelectedItem(null);
cmbFuncionSistema.setValue(null);
comboItem.setVisible(false);
} }
permissoListSelList.getListData().clear();
} }
public void onClick$btnRemoverPermiso(Event ev) { public void onClick$btnRemoverPermiso(Event ev) {
@ -339,8 +345,10 @@ public class EditarPerfilController extends MyGenericForwardComposer {
pf.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); pf.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
pf.setFecmodif(Calendar.getInstance().getTime()); pf.setFecmodif(Calendar.getInstance().getTime());
if (pf.getPerfilfuncionId() != null) { if (pf.getPerfilfuncionId() != null) {
perfilFuncionService.borrar(pf); pf.setActivo(Boolean.FALSE);
lsPermisoRemovidas.add(pf);
} }
int indice = 0; int indice = 0;
@ -357,15 +365,6 @@ public class EditarPerfilController extends MyGenericForwardComposer {
permisoList.setData(lsPermiso); permisoList.setData(lsPermiso);
perfil.setPerfilFuncionList(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" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@ -386,4 +385,143 @@ public class EditarPerfilController extends MyGenericForwardComposer {
Labels.getLabel("copiarPerfilController.window.title"), args, MODAL); 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; 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 * 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(); lc = new Listcell();
boolean indLectura = permiso.getIndLectura() == null ? false : permiso.getIndLectura(); boolean indLectura = permiso.getIndLectura() == null ? true : permiso.getIndLectura();
if (indLectura) { if (indLectura) {
chkRead.setChecked(Boolean.TRUE); chkRead.setChecked(Boolean.TRUE);
} }

View File

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