use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.
the class UserDetailTabItem method loadMemberSubContent.
private void loadMemberSubContent(final SimplePanel subContent, final Hyperlink voLabel, final ListBoxWithObjects<VirtualOrganization> listbox) {
subContent.setWidget(new AjaxLoaderImage());
final GetMemberByUser gmbu = new GetMemberByUser(listbox.getSelectedObject().getId(), user.getId());
JsonCallbackEvents loadEvent = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// get member
final Member member = jso.cast();
// create content panel and put it on page
final VerticalPanel entryPanel = new VerticalPanel();
entryPanel.setStyleName("perun-table");
entryPanel.setSize("100%", "100%");
subContent.setWidget(entryPanel);
voLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + SafeHtmlUtils.fromString((listbox.getSelectedObject().getName() != null) ? listbox.getSelectedObject().getName() : "").asString() + "</h2>"));
voLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new VoDetailTabItem(listbox.getSelectedObject())));
// detail header
Widget memberHeader = new HTML("<h2>" + "Member details" + "</h2>");
entryPanel.add(memberHeader);
entryPanel.setCellHeight(memberHeader, "30px");
// detail content
FlexTable layout = new FlexTable();
layout.setCellSpacing(6);
// Add some standard form options
layout.setHTML(0, 0, "<strong>Member ID:</strong>");
layout.setHTML(0, 1, String.valueOf(member.getId()));
ImageResource ir = null;
// member status
if (member.getStatus().equalsIgnoreCase("VALID")) {
ir = SmallIcons.INSTANCE.acceptIcon();
} else if (member.getStatus().equalsIgnoreCase("INVALID")) {
ir = SmallIcons.INSTANCE.flagRedIcon();
} else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
ir = SmallIcons.INSTANCE.flagYellowIcon();
} else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
ir = SmallIcons.INSTANCE.binClosedIcon();
}
HTML status = new HTML("<a>" + member.getStatus() + " " + new Image(ir) + "</a>");
layout.setHTML(1, 0, "<strong>Member status: </strong>");
layout.setWidget(1, 1, status);
// member status - on click action
status.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
PerunWebSession.getInstance().getTabManager().addTabToCurrentTab(new ChangeStatusTabItem(member, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
loadMemberSubContent(subContent, voLabel, listbox);
}
}));
}
});
final ListBoxWithObjects<Resource> resList = new ListBoxWithObjects<Resource>();
GetAssignedResources res = new GetAssignedResources(member.getId(), PerunEntity.MEMBER, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
resList.clear();
ArrayList<Resource> list = JsonUtils.jsoAsList(jso);
if (list == null || list.isEmpty()) {
resList.addItem("No resources found");
} else {
list = new TableSorter<Resource>().sortByName(list);
resList.addNotSelectedOption();
resList.addAllItems(list);
}
}
@Override
public void onError(PerunError error) {
resList.clear();
resList.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
resList.clear();
resList.addItem("Loading...");
}
});
res.retrieveData();
// link to member's detail
Hyperlink link = new Hyperlink();
link.setText("View detail");
layout.setHTML(2, 0, "<strong>Member's detail page:</strong>");
layout.setWidget(2, 1, link);
link.setTargetHistoryToken(session.getTabManager().getLinkForTab(new MemberDetailTabItem(member.getId(), 0)));
// wrap the content in a DecoratorPanel
DecoratorPanel decPanel = new DecoratorPanel();
decPanel.setWidget(layout);
entryPanel.add(decPanel);
entryPanel.setCellHeight(decPanel, "50px");
// tables
// detail header
Widget groupHeader = new HTML("<h2>" + "Member groups" + "</h2>");
entryPanel.add(groupHeader);
entryPanel.setCellHeight(groupHeader, "30px");
final GetMemberGroups groups = new GetMemberGroups(member.getId());
groups.setCheckable(false);
groups.setEditable(false);
CellTable<Group> table = groups.getTable();
table.addStyleName("perun-table");
table.setWidth("100%");
entryPanel.add(table);
// detail header
Widget attrHeader = new HTML("<h2>" + "Member / Member-resource attributes" + "</h2>");
entryPanel.add(attrHeader);
entryPanel.setCellHeight(attrHeader, "30px");
final GetAttributesV2 attributes = new GetAttributesV2();
attributes.getMemberAttributes(member.getId());
resList.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (resList.getSelectedIndex() == 0) {
attributes.getMemberAttributes(member.getId());
attributes.retrieveData();
} else {
attributes.getMemberResourceAttributes(member.getId(), resList.getSelectedObject().getId());
attributes.retrieveData();
}
}
});
TabMenu menu = new TabMenu();
final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for member");
saveAttrButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attributes.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.getSelectedObject().getId());
}
SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
request.setAttributes(ids, list);
}
}
});
menu.addWidget(saveAttrButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Set new attributes for member", new ClickHandler() {
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.getSelectedObject().getId());
}
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
}
}));
final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes from member");
removeAttrButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attributes.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("member", member.getId());
if (resList.getSelectedIndex() > 0) {
ids.put("resource", resList.getSelectedObject().getId());
}
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(removeAttrButton);
menu.addWidget(new HTML("<strong>Resource:</strong>"));
menu.addWidget(resList);
entryPanel.add(menu);
CellTable<Attribute> attrTable = attributes.getTable();
attrTable.addStyleName("perun-table");
attrTable.setWidth("100%");
entryPanel.add(attrTable);
}
@Override
public void onError(PerunError error) {
subContent.setWidget(new AjaxLoaderImage().loadingError(error));
}
};
// set events & load data
gmbu.setEvents(loadEvent);
gmbu.retrieveData();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.
the class UserExtSourceSettingsTabItem method draw.
public Widget draw() {
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(userExtSource.getLogin().trim()));
// MAIN TAB PANEL
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
// MENU
TabMenu menu = new TabMenu();
vp.add(menu);
vp.setCellHeight(menu, "30px");
final GetAttributesV2 callback = new GetAttributesV2(true);
callback.getUserExtSourceAttributes(userExtSource.getId());
final CellTable<Attribute> table = callback.getEmptyTable();
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
session.getUiElements().resizePerunTable(sp, 350, this);
menu.addWidget(UiElements.getRefreshButton(this));
// save changes in attributes
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
callback.getUserExtSourceAttributes(userExtSourceId);
callback.retrieveData();
}
}));
final Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("userExtSource", userExtSourceId);
request.setAttributes(ids, callback.getTableSelectedList());
}
}
});
menu.addWidget(saveChangesButton);
// buttons
CustomButton setNewMemberAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("userExtSource", userExtSource.getId());
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids), true);
}
});
menu.addWidget(setNewMemberAttributeButton);
// REMOVE ATTRIBUTES BUTTON
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// if selected
if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("userExtSource", userExtSource.getId());
RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
callback.clearTable();
callback.getUserExtSourceAttributes(userExtSource.getId());
callback.retrieveData();
}
}));
// make removeAttributes call
request.removeAttributes(ids, callback.getTableSelectedList());
}
}
});
removeButton.setEnabled(false);
JsonUtils.addTableManagedButton(callback, table, removeButton);
menu.addWidget(removeButton);
callback.retrieveData();
// ATTRIBUTES TABLE
vp.add(sp);
vp.setCellHeight(sp, "100%");
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.
the class SelfResourcesSettingsTabItem method loadSettings.
/**
* Load settings for each resource (loaded only once onClick on header)
*
* @return settings content for each resource
*/
private void loadSettings(final DisclosurePanel settings, final Resource resource) {
// create content table
final FlexTable layoutx = new FlexTable();
layoutx.setCellSpacing(5);
GetAttributesV2 resourceAttrsCall = new GetAttributesV2();
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("resource", resource.getId());
resourceAttrsCall.setIds(ids);
resourceAttrsCall.setEvents(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
boolean disableOptOut = false;
ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
for (Attribute a : attrs) {
if ("urn:perun:resource:attribute-def:def:disableMailingListOptOut".equals(a.getName())) {
disableOptOut = true;
break;
}
}
loadContent(layoutx, resource, disableOptOut);
}
public void onLoadingStart() {
AjaxLoaderImage loader = new AjaxLoaderImage(true);
layoutx.setWidget(0, 0, loader.loadingStart());
}
public void onError(PerunError error) {
AjaxLoaderImage loader = new AjaxLoaderImage(true);
layoutx.setWidget(0, 0, loader.loadingError(error));
}
});
// load content on open
settings.addOpenHandler(new OpenHandler<DisclosurePanel>() {
public void onOpen(OpenEvent<DisclosurePanel> event) {
if (settings.getContent() == null) {
resourceAttrsCall.retrieveData();
// set content
settings.setContent(layoutx);
}
}
});
}
use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.
the class FacilityHostsSettingsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()) + ": Hosts settings");
// main panel
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
final GetAttributesV2 attrs = new GetAttributesV2();
final ListBoxWithObjects<Host> listbox = new ListBoxWithObjects<Host>();
// refresh attributes for hosts
listbox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
if (listbox.getSelectedObject() != null) {
lastSelectedHostId = listbox.getSelectedObject().getId();
attrs.getHostAttributes(lastSelectedHostId);
attrs.retrieveData();
} else {
lastSelectedHostId = 0;
}
}
});
// retrieve hosts
final GetHosts hosts = new GetHosts(facilityId, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
listbox.clear();
ArrayList<Host> result = JsonUtils.jsoAsList(jso);
if (result != null && !result.isEmpty()) {
for (Host h : result) {
listbox.addItem(h);
if (h.getId() == lastSelectedHostId) {
listbox.setSelected(h, true);
}
}
if (lastSelectedHostId == 0) {
lastSelectedHostId = listbox.getSelectedObject().getId();
}
attrs.getHostAttributes(lastSelectedHostId);
attrs.retrieveData();
}
}
@Override
public void onError(PerunError error) {
listbox.clear();
listbox.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
listbox.clear();
listbox.addItem("Loading...");
}
});
hosts.retrieveData();
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(attrs);
// menu
TabMenu menu = new TabMenu();
// Save changes button
final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
final JsonCallbackEvents saveChangesButtonEvent = JsonCallbackEvents.disableButtonEvents(saveChangesButton, events);
saveChangesButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
SetAttributes request = new SetAttributes(saveChangesButtonEvent);
request.setAttributes(ids, list);
}
}
});
// Remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
removeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = attrs.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
request.removeAttributes(ids, list);
}
}
});
menu.addWidget(UiElements.getRefreshButton(this));
menu.addWidget(saveChangesButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("host", lastSelectedHostId);
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attrs.getList()), true);
}
}));
menu.addWidget(removeButton);
menu.addWidget(new HTML("<strong>Select host:</strong>"));
menu.addWidget(listbox);
// attrs table
CellTable<Attribute> table = attrs.getEmptyTable();
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
// add menu and the table to the main panel
firstTabPanel.add(menu);
firstTabPanel.setCellHeight(menu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2 in project perun by CESNET.
the class VoSettingsTabItem method draw.
public Widget draw() {
titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": settings");
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu menu = new TabMenu();
// refresh
menu.addWidget(UiElements.getRefreshButton(this));
// Get Attributes
final GetAttributesV2 jsonCallback = new GetAttributesV2();
// We want VO attributes
jsonCallback.getVoAttributes(voId);
// get the table
CellTable<Attribute> table = jsonCallback.getTable();
if (!session.isVoAdmin(voId))
jsonCallback.setCheckable(false);
final CustomButton setButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
menu.addWidget(setButton);
if (!session.isVoAdmin(voId))
setButton.setEnabled(false);
// refresh table
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(jsonCallback);
// set button event with button disable
final JsonCallbackEvents setButtonEvent = JsonCallbackEvents.disableButtonEvents(setButton, events);
setButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("vo", voId);
SetAttributes request = new SetAttributes(setButtonEvent);
request.setAttributes(ids, list);
}
}
});
CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("vo", voId);
session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, jsonCallback.getList()), true);
}
});
menu.addWidget(addButton);
if (!session.isVoAdmin(voId))
addButton.setEnabled(false);
// remove attr button
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
menu.addWidget(removeButton);
if (!session.isVoAdmin(voId))
removeButton.setEnabled(false);
// remove button event
final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
Map<String, Integer> ids = new HashMap<String, Integer>();
ids.put("vo", voId);
RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
request.removeAttributes(ids, list);
}
}
});
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
ScrollPanel sp = new ScrollPanel(table);
sp.addStyleName("perun-tableScrollPanel");
if (session.isVoAdmin(voId))
JsonUtils.addTableManagedButton(jsonCallback, table, removeButton);
// add menu and the table to the main panel
firstTabPanel.add(menu);
firstTabPanel.setCellHeight(menu, "30px");
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations