use of cz.metacentrum.perun.webgui.json.membersManager.SendPasswordResetLinkEmail in project perun by CESNET.
the class SendPasswordResetRequestTabItem method draw.
public Widget draw() {
this.titleWidget.setText("Send password reset request");
VerticalPanel vp = new VerticalPanel();
vp.setSize("300px", "100%");
final FlexTable layout = new FlexTable();
layout.setSize("100%", "100%");
layout.setStyleName("inputFormFlexTable");
layout.setHTML(0, 0, "Select namespace:");
layout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
layout.setHTML(1, 0, "Login:");
layout.getFlexCellFormatter().setStyleName(1, 0, "itemName");
final ListBox namespaces = new ListBox();
layout.setWidget(0, 1, namespaces);
final CustomButton changeButton = new CustomButton("Send", "Send email with reset password link", SmallIcons.INSTANCE.emailIcon());
GetLogins logins = new GetLogins(member.getUserId(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
namespaces.clear();
ArrayList<Attribute> logins = JsonUtils.jsoAsList(jso);
if (logins != null && !logins.isEmpty()) {
changeButton.setEnabled(true);
for (Attribute a : logins) {
if (Utils.getSupportedPasswordNamespaces().contains(a.getFriendlyNameParameter())) {
namespaces.addItem(a.getFriendlyNameParameter().toUpperCase(), a.getValue());
layout.setHTML(1, 1, a.getValue());
}
}
}
}
public void onLoadingStart() {
changeButton.setEnabled(false);
namespaces.clear();
namespaces.addItem("Loading...");
}
public void onError(PerunError error) {
namespaces.clear();
namespaces.addItem("Error while loading");
}
});
logins.retrieveData();
namespaces.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
layout.setHTML(1, 1, namespaces.getValue(namespaces.getSelectedIndex()));
}
});
TabMenu menu = new TabMenu();
final TabItem tab = this;
// by default false
changeButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
SendPasswordResetLinkEmail request = new SendPasswordResetLinkEmail(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
request.sendEmail(member, namespaces.getItemText(namespaces.getSelectedIndex()).toLowerCase());
}
});
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);
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
Aggregations