use of cz.metacentrum.perun.webgui.json.membersManager.SetStatus 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>" + listbox.getSelectedObject().getName() + "</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("SUSPENDED")) {
ir = SmallIcons.INSTANCE.stopIcon();
} 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) {
FlexTable widget = new FlexTable();
final ListBox lb = new ListBox(false);
lb.addItem("VALID", "VALID");
lb.addItem("INVALID", "INVALID");
lb.addItem("SUSPENDED", "SUSPENDED");
lb.addItem("EXPIRED", "EXPIRED");
lb.addItem("DISABLED", "DISABLED");
widget.setHTML(0, 0, "<strong>Status: </strong>");
widget.setWidget(0, 1, lb);
// pick which one is already set
for (int i = 0; i < lb.getItemCount(); i++) {
if (lb.getItemText(i).equalsIgnoreCase(member.getStatus())) {
lb.setSelectedIndex(i);
}
}
Confirm conf = new Confirm("Change member's status", widget, true);
conf.setCancelButtonText("Cancel");
conf.setOkButtonText("Change status");
conf.setOkClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SetStatus call = new SetStatus(member.getId(), new JsonCallbackEvents() {
@Override
public void onLoadingStart() {
subContent.setWidget(new AjaxLoaderImage());
}
public void onFinished(JavaScriptObject jso) {
subContent.setWidget(entryPanel);
gmbu.retrieveData();
}
public void onError(PerunError error) {
subContent.setWidget(entryPanel);
gmbu.retrieveData();
}
});
call.setStatus(lb.getValue(lb.getSelectedIndex()));
}
});
conf.show();
}
});
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.membersManager.SetStatus in project perun by CESNET.
the class GetGroupRichMembers method getTable.
/**
* Returns the table with rich members of group
*
* @return table widget
*/
public CellTable<RichMember> getTable() {
// retrieves data
retrieveData();
// Table data provider.
dataProvider = new ListDataProvider<RichMember>(list);
// Cell table
table = new PerunTable<RichMember>(list);
// Connect the table to the data provider.
dataProvider.addDataDisplay(table);
// Sorting
ListHandler<RichMember> columnSortHandler = new ListHandler<RichMember>(dataProvider.getList());
table.addColumnSortHandler(columnSortHandler);
// Table selection
table.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RichMember>createCheckboxManager());
// Set empty content & loader
table.setEmptyTableWidget(loaderImage);
// Checkbox column column
table.addCheckBoxColumn();
// Status column
Column<RichMember, String> statusColumn = new Column<RichMember, String>(new PerunStatusCell()) {
@Override
public String getValue(RichMember object) {
return object.getStatus();
}
};
// own onClick tab for changing member's status
statusColumn.setFieldUpdater(new FieldUpdater<RichMember, String>() {
public void update(int index, final RichMember object, String value) {
FlexTable widget = new FlexTable();
final ListBox lb = new ListBox(false);
lb.addItem("VALID", "VALID");
lb.addItem("INVALID", "INVALID");
lb.addItem("SUSPENDED", "SUSPENDED");
lb.addItem("EXPIRED", "EXPIRED");
lb.addItem("DISABLED", "DISABLED");
widget.setHTML(0, 0, "<strong>Status: </strong>");
widget.setWidget(0, 1, lb);
// pick which one is already set
for (int i = 0; i < lb.getItemCount(); i++) {
if (lb.getItemText(i).equalsIgnoreCase(object.getStatus())) {
lb.setSelectedIndex(i);
}
}
Confirm conf = new Confirm("Change member's status: " + object.getUser().getFullName(), widget, true);
conf.setCancelButtonText("Cancel");
conf.setOkButtonText("Change status");
conf.setOkClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SetStatus call = new SetStatus(object.getId(), new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
clearTable();
retrieveData();
}
public void onError(PerunError error) {
clearTable();
retrieveData();
}
});
call.setStatus(lb.getValue(lb.getSelectedIndex()));
}
});
conf.show();
}
});
// status column sortable
statusColumn.setSortable(true);
columnSortHandler.setComparator(statusColumn, new GeneralComparator<RichMember>(GeneralComparator.Column.STATUS));
table.addColumn(statusColumn, "Status");
table.setColumnWidth(statusColumn, 20, Unit.PX);
// Create member ID column.
Column<RichMember, String> memberIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<RichMember, String>() {
public String getValue(RichMember object) {
return String.valueOf(object.getId());
}
}, this.tableFieldUpdater);
// Create User ID column.
Column<RichMember, String> userIdColumn = JsonUtils.addColumn(new JsonUtils.GetValue<RichMember, String>() {
public String getValue(RichMember object) {
return String.valueOf(object.getUser().getId());
}
}, this.tableFieldUpdater);
columnSortHandler.setComparator(memberIdColumn, new RichMemberComparator(RichMemberComparator.Column.MEMBER_ID));
memberIdColumn.setSortable(true);
userIdColumn.setSortable(true);
columnSortHandler.setComparator(userIdColumn, new RichMemberComparator(RichMemberComparator.Column.USER_ID));
table.setColumnWidth(memberIdColumn, 110.0, Unit.PX);
table.setColumnWidth(userIdColumn, 110.0, Unit.PX);
// headers
if (JsonUtils.isExtendedInfoVisible()) {
table.addColumn(memberIdColumn, "Member ID");
table.addColumn(userIdColumn, "User ID");
}
table.addNameColumn(tableFieldUpdater);
return table;
}
use of cz.metacentrum.perun.webgui.json.membersManager.SetStatus in project perun by CESNET.
the class ChangeStatusTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Change member's status");
VerticalPanel vp = new VerticalPanel();
vp.setSize("300px", "100%");
FlexTable layout = new FlexTable();
layout.setSize("100%", "100%");
layout.setStyleName("inputFormFlexTable");
final HTML text = new HTML("");
final ListBox lb = new ListBox(false);
lb.addItem("VALID", "VALID");
lb.addItem("INVALID", "INVALID");
lb.addItem("SUSPENDED", "SUSPENDED");
lb.addItem("EXPIRED", "EXPIRED");
lb.addItem("DISABLED", "DISABLED");
layout.setHTML(0, 0, "Current status:");
layout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
layout.setHTML(0, 1, member.getStatus());
if (member.getStatus().equalsIgnoreCase("VALID")) {
layout.setHTML(1, 0, "Member is properly configured and have access on provided resources.");
} else if (member.getStatus().equalsIgnoreCase("INVALID")) {
layout.setHTML(1, 0, "Member have configuration error and DON'T have access on provided resources. You can check what is wrong by changing member's status to VALID. If possible, procedure will configure all necessary settings by itself.");
} else if (member.getStatus().equalsIgnoreCase("SUSPENDED")) {
layout.setHTML(1, 0, "Member violated some rules and DON'T have access on provided resources.");
} else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
layout.setHTML(1, 0, "Member didn't extend membership and DON'T have access on provided resources.");
} else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
layout.setHTML(1, 0, "Member didn't extend membership long time ago or was manually disabled and DON'T have access on provided resources.");
}
layout.getFlexCellFormatter().setColSpan(1, 0, 2);
layout.getFlexCellFormatter().setStyleName(1, 0, "inputFormInlineComment");
layout.setHTML(2, 0, "New status:");
layout.getFlexCellFormatter().setStyleName(2, 0, "itemName");
layout.setWidget(2, 1, lb);
layout.setWidget(3, 0, text);
layout.getFlexCellFormatter().setColSpan(3, 0, 2);
layout.getFlexCellFormatter().setStyleName(3, 0, "inputFormInlineComment");
// pick which one is already set
for (int i = 0; i < lb.getItemCount(); i++) {
if (lb.getItemText(i).equalsIgnoreCase(member.getStatus())) {
lb.setSelectedIndex(i);
}
}
TabMenu menu = new TabMenu();
final TabItem tab = this;
final CustomButton changeButton = new CustomButton("Change status", ButtonTranslation.INSTANCE.changeStatus(member.getUser().getFullName()), SmallIcons.INSTANCE.diskIcon());
// by default false
changeButton.setEnabled(false);
changeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
SetStatus request = new SetStatus(memberId, JsonCallbackEvents.disableButtonEvents(changeButton, JsonCallbackEvents.mergeEvents(events, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// close without refresh
session.getTabManager().closeTab(tab, false);
}
})));
request.setStatus(lb.getValue(lb.getSelectedIndex()));
}
});
menu.addWidget(changeButton);
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, ButtonTranslation.INSTANCE.cancelButton(), new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
// listbox change handler
lb.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent changeEvent) {
if (lb.getValue(lb.getSelectedIndex()).equalsIgnoreCase(member.getStatus())) {
changeButton.setEnabled(false);
} else {
changeButton.setEnabled(true);
}
// clear
text.setHTML("");
if (lb.getSelectedIndex() == 0) {
// VALIDATING NOTICE
if (!member.getStatus().equalsIgnoreCase("VALID"))
text.setHTML("Changing status to VALID <strong>will trigger automatic configuration</strong> for provided resources. <br/><strong>If successful</strong>, member will have access on provided resources. <br /><strong>If not</strong>, see displayed error message and do manual configuration on 'settings' tab on members detail.");
} else {
// INVALIDATING NOTICE
if (member.getStatus().equalsIgnoreCase("VALID"))
text.setHTML("Changing status to " + lb.getValue(lb.getSelectedIndex()) + " will <strong>prevent member from access to provided resources (based on provided service's rules)</strong>.<br /><br />");
}
// SET INFO
if (lb.getSelectedIndex() == 1) {
text.setHTML(text.getHTML() + "INVALID status means there is configuration error, which prevents him from access on provided resources.");
} else if (lb.getSelectedIndex() == 2) {
text.setHTML(text.getHTML() + "SUSPENDED status means, that member did something bad (against VO rules).");
} else if (lb.getSelectedIndex() == 3) {
text.setHTML(text.getHTML() + "EXPIRED status means, that member didn't extend his membership in VO, but it's still possible for him to do so.");
} else if (lb.getSelectedIndex() == 4) {
text.setHTML(text.getHTML() + "DISABLED status means, that member didn't extend his membership long ago or was manually disabled by administrator. Member can't enable/extend membership by himself.");
}
}
});
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations