disable buttons in member tab

This commit is contained in:
Peter Hormanns 2017-08-05 17:09:50 +02:00
parent 2ea4a23132
commit cf6c5e3493
5 changed files with 67 additions and 50 deletions

View File

@ -15,4 +15,6 @@ public interface HSAdminSession {
public I18N getI18N(); public I18N getI18N();
public String getRole() throws RpcException;
} }

View File

@ -7,6 +7,7 @@ import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent; import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.SelectedTabChangeListener; import com.vaadin.ui.TabSheet.SelectedTabChangeListener;
import de.hsadmin.login.Role;
import de.hsadmin.rpc.HSAdminSession; import de.hsadmin.rpc.HSAdminSession;
import de.hsadmin.rpc.RpcException; import de.hsadmin.rpc.RpcException;
@ -30,30 +31,44 @@ public class CustomerPanel extends CustomComponent implements IHSPanel, Selected
public TabSheet createTabs(Object itemId) throws RpcException public TabSheet createTabs(Object itemId) throws RpcException
{ {
final I18N i18n = session.getI18N(); final I18N i18n = session.getI18N();
final String role = session.getRole();
final boolean isHostmasterSession = Role.SYSTEM.name().equals(role);
final TabSheet tabsheet = new TabSheet(); final TabSheet tabsheet = new TabSheet();
tabsheet.setSizeFull(); tabsheet.setSizeFull();
tabsheet.addSelectedTabChangeListener(this); tabsheet.addSelectedTabChangeListener(this);
tabsheet.addSelectedTabChangeListener(this); tabsheet.addSelectedTabChangeListener(this);
tabsheet.addTab(new GenericForm("customer", session, itemId, "name"), i18n.getText("customer")); tabsheet.addTab(new GenericForm("customer", session, itemId, "name"), i18n.getText("customer"));
final HSTab usersTab = new HSTab("contact", session, "customer", itemId, "email"); final HSTab contactsTab = new HSTab("contact", session, "customer", itemId, "email");
usersTab.fillTable(); contactsTab.fillTable();
tabsheet.addTab(usersTab, i18n.getText("contact")); contactsTab.getPanelToolbar().setCreateEnabled(isHostmasterSession);
contactsTab.getPanelToolbar().setUpdateEnabled(false);
contactsTab.getPanelToolbar().setDeleteEnabled(false);
tabsheet.addTab(contactsTab, i18n.getText("contact"));
final HSTab aliasTab = new HSTab("mandat", session, "customer", itemId, "mandatRef"); final HSTab mandatTab = new HSTab("mandat", session, "customer", itemId, "mandatRef");
tabsheet.addTab(aliasTab, i18n.getText("mandat")); mandatTab.getPanelToolbar().setCreateEnabled(isHostmasterSession);
mandatTab.getPanelToolbar().setUpdateEnabled(false);
mandatTab.getPanelToolbar().setDeleteEnabled(false);
tabsheet.addTab(mandatTab, i18n.getText("mandat"));
final HSTab assetsTab = new HSTab("memberShare", session, "customer", itemId, "id"); final HSTab sharesTab = new HSTab("memberShare", session, "customer", itemId, "id");
sharesTab.getPanelToolbar().setCreateEnabled(isHostmasterSession);
sharesTab.getPanelToolbar().setUpdateEnabled(false);
sharesTab.getPanelToolbar().setDeleteEnabled(false);
tabsheet.addTab(sharesTab, i18n.getText("memberShare"));
final HSTab assetsTab = new HSTab("memberAsset", session, "customer", itemId, "id");
assetsTab.getPanelToolbar().setCreateEnabled(isHostmasterSession);
assetsTab.getPanelToolbar().setUpdateEnabled(false); assetsTab.getPanelToolbar().setUpdateEnabled(false);
assetsTab.getPanelToolbar().setDeleteEnabled(false); assetsTab.getPanelToolbar().setDeleteEnabled(false);
tabsheet.addTab(assetsTab, i18n.getText("memberShare")); tabsheet.addTab(assetsTab, i18n.getText("memberAsset"));
final HSTab assetsTab1 = new HSTab("memberAsset", session, "customer", itemId, "id");
assetsTab1.getPanelToolbar().setUpdateEnabled(false);
assetsTab1.getPanelToolbar().setDeleteEnabled(false);
tabsheet.addTab(assetsTab1, i18n.getText("memberAsset"));
final HSTab pacTab = new HSTab("pac", session, "customer", itemId, "name"); final HSTab pacTab = new HSTab("pac", session, "customer", itemId, "name");
pacTab.getPanelToolbar().setCreateEnabled(isHostmasterSession);
pacTab.getPanelToolbar().setUpdateEnabled(false);
pacTab.getPanelToolbar().setDeleteEnabled(false);
tabsheet.addTab(pacTab, i18n.getText("pac")); tabsheet.addTab(pacTab, i18n.getText("pac"));
return tabsheet; return tabsheet;
} }

View File

@ -1,11 +1,5 @@
package de.hsadmin.web; package de.hsadmin.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.xmlrpc.XmlRpcException;
import com.vaadin.event.ItemClickEvent; import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener; import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.ui.Accordion; import com.vaadin.ui.Accordion;
@ -16,9 +10,6 @@ import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.SelectedTabChangeListener; import com.vaadin.ui.TabSheet.SelectedTabChangeListener;
import com.vaadin.ui.Table; import com.vaadin.ui.Table;
import de.hsadmin.login.Role;
import de.hsadmin.model.IRemote;
import de.hsadmin.model.TicketService;
import de.hsadmin.rpc.RpcException; import de.hsadmin.rpc.RpcException;
public class EntryPointsSelector extends CustomComponent implements ItemClickListener, SelectedTabChangeListener { public class EntryPointsSelector extends CustomComponent implements ItemClickListener, SelectedTabChangeListener {
@ -42,7 +33,7 @@ public class EntryPointsSelector extends CustomComponent implements ItemClickLis
} }
private void createTabs() throws RpcException { private void createTabs() throws RpcException {
final String role = getRole(); final String role = mainWindow.getRole();
final AbstractEntryPointsFactory entryPointsFactory = FactoryProducer.getEntryPointsFactory(mainWindow, "default"); final AbstractEntryPointsFactory entryPointsFactory = FactoryProducer.getEntryPointsFactory(mainWindow, "default");
int tabCount = 0; int tabCount = 0;
for(String tabName : entryPointsFactory.getEntryPointNames(role)) { for(String tabName : entryPointsFactory.getEntryPointNames(role)) {
@ -58,34 +49,6 @@ public class EntryPointsSelector extends CustomComponent implements ItemClickLis
} }
} }
public String getRole() throws RpcException {
final IRemote rolesProxy = mainWindow.getModulesManager().proxy("role");
final String user = mainWindow.getUser();
final TicketService ticketService = mainWindow.getTicketService();
final String grantingTicket = mainWindow.getGrantingTicket();
final String serviceTicket = ticketService.getServiceTicket(grantingTicket);
try {
final List<Map<String,Object>> list = rolesProxy.search(user, serviceTicket, new HashMap<String, String>());
final String remoteRole = (String) list.get(0).get("role");
return fixRole(remoteRole);
} catch (XmlRpcException e) {
throw new RpcException(e);
}
}
private String fixRole(String remoteRole) {
if ("HOSTMASTER".equals(remoteRole)) {
return Role.SYSTEM.name();
}
if ("PAC_ADMIN_DW".equals(remoteRole)) {
return Role.PACKET.name();
}
if ("DOM_ADMIN".equals(remoteRole)) {
return Role.DOMAIN.name();
}
return remoteRole;
}
@Override @Override
public void itemClick(ItemClickEvent event) { public void itemClick(ItemClickEvent event) {
Table table = (Table) event.getSource(); Table table = (Table) event.getSource();

View File

@ -17,6 +17,8 @@ import com.vaadin.ui.VerticalLayout;
import de.hsadmin.common.config.Config; import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException; import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.login.Role;
import de.hsadmin.model.IRemote;
import de.hsadmin.model.TicketService; import de.hsadmin.model.TicketService;
import de.hsadmin.rpc.HSAdminSession; import de.hsadmin.rpc.HSAdminSession;
import de.hsadmin.rpc.ModulesManager; import de.hsadmin.rpc.ModulesManager;
@ -134,4 +136,35 @@ public class MainWindow extends CustomComponent implements HSAdminSession {
public I18N getI18N() { public I18N getI18N() {
return i18n; return i18n;
} }
@Override
public String getRole() throws RpcException {
final IRemote rolesProxy = getModulesManager().proxy("role");
final String user = getUser();
final TicketService ticketService = getTicketService();
final String grantingTicket = getGrantingTicket();
final String serviceTicket = ticketService.getServiceTicket(grantingTicket);
try {
final List<Map<String,Object>> list = rolesProxy.search(user, serviceTicket, new HashMap<String, String>());
final String remoteRole = (String) list.get(0).get("role");
return fixRole(remoteRole);
} catch (XmlRpcException e) {
throw new RpcException(e);
}
}
private String fixRole(String remoteRole) {
if ("HOSTMASTER".equals(remoteRole)) {
return Role.SYSTEM.name();
}
if ("PAC_ADMIN_DW".equals(remoteRole)) {
return Role.PACKET.name();
}
if ("DOM_ADMIN".equals(remoteRole)) {
return Role.DOMAIN.name();
}
return remoteRole;
}
} }

View File

@ -126,6 +126,10 @@ public class PanelToolbar extends HorizontalLayout implements ClickListener {
} }
} }
public void setCreateEnabled(boolean createEnabled) {
newBtn.setEnabled(createEnabled);
}
public void setUpdateEnabled(boolean updateEnabled) { public void setUpdateEnabled(boolean updateEnabled) {
editBtn.setEnabled(updateEnabled); editBtn.setEnabled(updateEnabled);
} }