use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class SelfPasswordTabItem method draw.
public Widget draw() {
String actionText = "Change";
if (action.equals(Actions.CREATE)) {
actionText = "Create";
} else if (action.equals(Actions.DELETE)) {
actionText = "Delete";
}
// set tab name
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": " + actionText + " password");
// main panel
final VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
TabMenu menu = new TabMenu();
// widgets
final Label namespaceLabel = new Label();
namespaceLabel.setText(namespace);
final Label loginLabel = new Label();
loginLabel.setText(login);
final ExtendedPasswordBox newPass = new ExtendedPasswordBox();
final ExtendedPasswordBox confPass = new ExtendedPasswordBox();
final ExtendedPasswordBox oldPass = new ExtendedPasswordBox();
final CustomButton changeButton = new CustomButton("Change password", "Changes your password in selected namespace", SmallIcons.INSTANCE.keyIcon());
final CustomButton createButton = new CustomButton("Create password", "Creates your password in selected namespace", SmallIcons.INSTANCE.keyAddIcon());
final CustomButton deleteButton = new CustomButton("Delete password", "Deletes your password in selected namespace", SmallIcons.INSTANCE.keyDeleteIcon());
final TabItem tab = this;
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (newPass.getTextBox().getValue().trim().equals("")) {
newPass.setError("Password can't be empty!");
return false;
} else if (!newPass.getTextBox().getValue().trim().equals(confPass.getTextBox().getValue().trim())) {
newPass.setError("Password in both textboxes must be the same!");
return false;
} else {
newPass.setOk();
confPass.setOk();
return true;
}
}
};
final ExtendedTextBox.TextBoxValidator validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (confPass.getTextBox().getValue().trim().equals("")) {
confPass.setError("Password can't be empty!");
return false;
} else if (!confPass.getTextBox().getValue().trim().equals(newPass.getTextBox().getValue().trim())) {
confPass.setError("Password in both textboxes must be the same!");
return false;
} else {
confPass.setOk();
newPass.setOk();
return true;
}
}
};
final ExtendedTextBox.TextBoxValidator oldValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (oldPass.getTextBox().getValue().trim().equals("")) {
oldPass.setError("Password can't be empty!");
return false;
} else {
oldPass.setOk();
return true;
}
}
};
newPass.setValidator(validator);
confPass.setValidator(validator2);
oldPass.setValidator(oldValidator);
// save changes
changeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if ("mu".equals(namespace) && !JsonUtils.checkParseInt(login)) {
UiElements.generateAlert("Operation not supported", "Password change/reset is not supported for non-numeric logins (UČO).");
}
if (session.isPerunAdmin() || user.isServiceUser()) {
if (!validator.validateTextBox() && !validator2.validateTextBox())
return;
ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab), false);
changepw.changePassword(user, namespace, oldPass.getTextBox().getValue().trim(), newPass.getTextBox().getValue().trim());
} else {
if (!validator.validateTextBox() && !validator2.validateTextBox() && !oldValidator.validateTextBox())
return;
ChangePassword changepw = new ChangePassword(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab), true);
changepw.changePassword(user, namespace, oldPass.getTextBox().getValue().trim(), newPass.getTextBox().getValue().trim());
}
}
});
if (user.isServiceUser()) {
// for service users it's reset since they don't provide old password
changeButton.setText("Reset password…");
}
createButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
if (validator.validateTextBox() && validator2.validateTextBox()) {
if ("mu".equals(namespace)) {
final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
// VALIDATE PASSWORD - SET EXT SOURCES
CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
req.validateAndSetUserExtSources(user.getId(), login, namespace);
}
}));
setLogin.setLogin(user.getId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
User usr = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
generateAccount.generateAccount(namespace, newPass.getTextBox().getValue().trim(), params);
}
}));
get.retrieveData();
} else {
// NORMAL PWD LOGIC
CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
create.createPassword(userId, login, namespace, newPass.getTextBox().getValue().trim());
}
}
}
});
deleteButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
UiElements.generateAlert("Not yet implemented", "Not yet implemented");
}
});
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
// change layout
if (action.equals(Actions.CHANGE)) {
int row = 0;
layout.setHTML(row, 0, "Namespace:");
layout.setWidget(row, 1, namespaceLabel);
row++;
layout.setHTML(row, 0, "Login:");
layout.setWidget(row, 1, loginLabel);
row++;
// mu namespace can change without knowing old
if (!session.isPerunAdmin()) {
if (!user.isServiceUser()) {
layout.setHTML(row, 0, "Old password: ");
layout.setWidget(row, 1, oldPass);
row++;
}
}
layout.setHTML(row, 0, "New password:");
layout.setWidget(row, 1, newPass);
row++;
layout.setHTML(row, 0, "Retype new pass:");
layout.setWidget(row, 1, confPass);
menu.addWidget(changeButton);
vp.add(layout);
} else if (action.equals(Actions.CREATE)) {
layout.setHTML(0, 0, "Namespace:");
layout.setWidget(0, 1, namespaceLabel);
if ("mu".equals(namespace)) {
loginLabel.setText("Will be generated...");
loginLabel.addStyleName("inputFormInlineComment");
}
layout.setHTML(1, 0, "Login:");
layout.setWidget(1, 1, loginLabel);
layout.setHTML(2, 0, "New password:");
layout.setWidget(2, 1, newPass);
layout.setHTML(3, 0, "Retype new pass:");
layout.setWidget(3, 1, confPass);
final CustomButton skip = new CustomButton("Skip", "Will set random/empty password", SmallIcons.INSTANCE.arrowRightIcon());
skip.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if ("mu".equals(namespace)) {
final GenerateAccount generateAccount = new GenerateAccount(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
BasicOverlayType basic = jso.cast();
final String login = basic.getCustomProperty("urn:perun:user:attribute-def:def:login-namespace:mu");
SetLogin setLogin = new SetLogin(JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
UiElements.generateInfo("Assigned login", "You were assigned with login <b>" + login + "</b> in namespace MU.");
// VALIDATE PASSWORD - SET EXT SOURCES
CreatePassword req = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(createButton, tab));
req.validateAndSetUserExtSources(user.getId(), login, namespace);
}
}));
setLogin.setLogin(user.getId(), "mu", login);
}
}));
final Map<String, String> params = new HashMap<String, String>();
GetEntityById get = new GetEntityById(PerunEntity.RICH_USER_WITH_ATTRS, user.getId(), JsonCallbackEvents.disableButtonEvents(createButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
User usr = jso.cast();
params.put("urn:perun:user:attribute-def:core:firstName", usr.getFirstName());
params.put("urn:perun:user:attribute-def:core:lastName", usr.getLastName());
params.put("urn:perun:member:attribute-def:def:mail", usr.getAttribute("urn:perun:user:attribute-def:def:preferredMail").getValue());
generateAccount.generateAccount(namespace, newPass.getTextBox().getValue().trim(), params);
}
}));
get.retrieveData();
} else {
CreatePassword create = new CreatePassword(JsonCallbackEvents.closeTabDisableButtonEvents(skip, tab));
create.createRandomPassword(userId, login, namespace);
}
}
});
menu.addWidget(skip);
menu.addWidget(createButton);
vp.add(layout);
} else if (action.equals(Actions.DELETE)) {
layout.setHTML(0, 0, "Namespace:");
layout.setWidget(0, 1, namespaceLabel);
layout.setHTML(1, 0, "Login:");
layout.setWidget(1, 1, loginLabel);
menu.addWidget(deleteButton);
vp.add(layout);
}
for (int i = 0; i < layout.getRowCount(); i++) {
layout.getFlexCellFormatter().setStyleName(i, 0, "itemName");
}
if (!action.equals(Actions.CREATE)) {
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, false);
}
}));
}
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AddVoManagerGroupTabItem method draw.
public Widget draw() {
titleWidget.setText("Add manager group");
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
final TabMenu tabMenu = new TabMenu();
final ListBoxWithObjects<VirtualOrganization> box = new ListBoxWithObjects<VirtualOrganization>();
// get the table
final ScrollPanel sp = new ScrollPanel();
sp.addStyleName("perun-tableScrollPanel");
box.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
}
});
if (box.getAllObjects().isEmpty()) {
GetVos vos = new GetVos(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
box.clear();
ArrayList<VirtualOrganization> list = new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso));
if (list != null && !list.isEmpty()) {
box.addAllItems(list);
sp.setWidget(fillGroupsContent(new GetAllGroups(box.getSelectedObject().getId()), tabMenu, box));
} else {
box.addItem("No VOs found");
}
}
@Override
public void onError(PerunError error) {
box.clear();
box.addItem("Error while loading");
}
@Override
public void onLoadingStart() {
box.clear();
box.addItem("Loading...");
}
});
vos.retrieveData();
}
// add menu and the table to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(sp);
// pass empty first item to tab menu to ensure rest is added
tabMenu.addWidget(new HTML(""));
final TabItem tab = this;
tabMenu.addWidget(1, TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (refreshEvents != null)
refreshEvents.onFinished(null);
session.getTabManager().closeTab(tab, false);
}
}));
tabMenu.addWidget(2, new HTML("<strong>Select VO:</strong>"));
tabMenu.addWidget(3, box);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AddVoManagerGroupTabItem method fillGroupsContent.
private Widget fillGroupsContent(GetAllGroups groups, TabMenu tabMenu, final ListBoxWithObjects<VirtualOrganization> box) {
getAllGroups = groups;
getAllGroups.setCoreGroupsCheckable(true);
final CellTable<Group> table = getAllGroups.getTable();
getAllGroups.getSelectionModel().addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
private boolean found = false;
@Override
public void onSelectionChange(SelectionChangeEvent event) {
for (Group g : getAllGroups.getTableSelectedList()) {
if (g.isCoreGroup()) {
if (!found) {
// display only once
UiElements.generateInfo("You have selected 'all vo members' group", "If this group will be added as 'manager group', all new members of VO " + box.getSelectedObject().getName() + " will be automatically managers of your VO and all removed members will lose management rights.");
}
found = true;
return;
}
}
found = false;
}
});
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersGroupToVo());
tabMenu.addWidget(0, addButton);
final TabItem tab = this;
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
ArrayList<Group> list = getAllGroups.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
for (int i = 0; i < list.size(); i++) {
if (i == list.size() - 1) {
AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
// close tab and refresh table
if (refreshEvents != null)
refreshEvents.onFinished(null);
session.getTabManager().closeTab(tab, false);
}
}));
request.addVoAdminGroup(vo, list.get(i));
} else {
AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton));
request.addVoAdminGroup(vo, list.get(i));
}
}
}
}
});
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(getAllGroups, table, addButton);
// add a class to the table and wrap it into scroll panel
table.addStyleName("perun-table");
return table;
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class AddUserToBlacklistTabItem method draw.
public Widget draw() {
titleWidget.setText("Add to blacklist");
final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// if found 1 item, select
ArrayList<User> list = JsonUtils.jsoAsList(jso);
if (list != null && list.size() == 1) {
users.getSelectionModel().setSelected(list.get(0), true);
}
}
}));
// MAIN TAB PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
// HORIZONTAL MENU
TabMenu tabMenu = new TabMenu();
// get the table
final CellTable<User> table;
if (session.isPerunAdmin()) {
table = users.getTable(new FieldUpdater<User, String>() {
public void update(int i, User user, String s) {
session.getTabManager().addTab(new UserDetailTabItem(user));
}
});
} else {
table = users.getTable();
}
rebuildAlreadyAddedWidget();
final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedUsersToBlacklist());
final TabItem tab = this;
// search textbox
final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {
@Override
public void searchFor(String text) {
startSearching(text);
searchString = text;
}
}, searchButton);
tabMenu.addWidget(addButton);
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
}
}));
addButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final ArrayList<User> list = users.getTableSelectedList();
if (UiElements.cantSaveEmptyListDialogBox(list)) {
FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
final TextArea textArea = new TextArea();
textArea.setSize("250px", "120px");
layout.getFlexCellFormatter().addStyleName(0, 0, "itemName");
layout.setHTML(0, 0, "Reason:");
layout.setWidget(1, 0, textArea);
layout.setHTML(2, 0, "Please specify why users are blacklisted.");
layout.getFlexCellFormatter().addStyleName(2, 0, "inputFormInlineComment");
Confirm c = new Confirm("Add user(s) to blacklist", layout, new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
for (int i = 0; i < list.size(); i++) {
// FIXME - Should have only one callback to core
final int n = i;
AddUserToBlacklist request = new AddUserToBlacklist(securityTeamId, JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// put names to already added
alreadyAddedList.add(list.get(n));
rebuildAlreadyAddedWidget();
// unselect added person
users.getSelectionModel().setSelected(list.get(n), false);
// clear search
searchBox.getTextBox().setText("");
}
}));
request.addUserToBlacklist(list.get(i).getId(), textArea.getText().trim());
}
}
}, "Add", true);
c.show();
}
}
});
// if some text has been searched before
if (!searchString.equals("")) {
searchBox.getTextBox().setText(searchString);
startSearching(searchString);
}
addButton.setEnabled(false);
JsonUtils.addTableManagedButton(users, table, addButton);
// 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(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
firstTabPanel.add(alreadyAdded);
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
use of cz.metacentrum.perun.webgui.tabs.TabItem in project perun by CESNET.
the class SecurityTeamBlacklistTabItem method draw.
public Widget draw() {
// MAIN PANEL
VerticalPanel firstTabPanel = new VerticalPanel();
firstTabPanel.setSize("100%", "100%");
this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(securityTeam.getName()) + ": " + "blacklist");
// Get vos request
final GetBlacklistWithDescription teams = new GetBlacklistWithDescription(PerunEntity.SECURITY_TEAM, securityTeamId);
// Events for reloading when finished
final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(teams);
TabMenu tabMenu = new TabMenu();
// add menu to the main panel
firstTabPanel.add(tabMenu);
firstTabPanel.setCellHeight(tabMenu, "30px");
tabMenu.addWidget(UiElements.getRefreshButton(this));
// do not display to sec admins only
tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addUsersToBlacklist(), new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().addTabToCurrentTab(new AddUserToBlacklistTabItem(securityTeam), true);
}
}));
final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, buttonTranslation.removeSelectedUsersFromBlacklist());
removeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final ArrayList<Pair<User, String>> itemsToRemove = teams.getTableSelectedList();
UiElements.showDeleteConfirm(itemsToRemove, new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
// TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
for (int i = 0; i < itemsToRemove.size(); i++) {
RemoveUserFromBlacklist request;
if (i == itemsToRemove.size() - 1) {
request = new RemoveUserFromBlacklist(securityTeamId, JsonCallbackEvents.disableButtonEvents(removeButton, events));
} else {
request = new RemoveUserFromBlacklist(securityTeamId, JsonCallbackEvents.disableButtonEvents(removeButton));
}
request.removeUserFromBlacklist(itemsToRemove.get(i).getLeft().getId());
}
}
});
}
});
tabMenu.addWidget(removeButton);
// filter
tabMenu.addFilterWidget(new ExtendedSuggestBox(teams.getOracle()), new PerunSearchEvent() {
@Override
public void searchFor(String text) {
teams.filterTable(text);
}
}, buttonTranslation.filterBlacklist());
final TabItem tab = this;
CellTable<Pair<User, String>> table;
if (session.isPerunAdmin()) {
// get the table with custom onclick
table = teams.getTable(new FieldUpdater<Pair<User, String>, String>() {
@Override
public void update(int i, Pair<User, String> pair, String string) {
session.getTabManager().addTab(new UserDetailTabItem(pair.getLeft()));
session.getTabManager().closeTab(tab, false);
}
});
} else {
table = teams.getTable();
}
// 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 the table to the main panel
firstTabPanel.add(sp);
session.getUiElements().resizePerunTable(sp, 350, 0, this);
this.contentWidget.setWidget(firstTabPanel);
return getWidget();
}
Aggregations