Search in sources :

Example 1 with SendPasswordResetLinkEmail

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();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) GetLogins(cz.metacentrum.perun.webgui.json.attributesManager.GetLogins) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SendPasswordResetLinkEmail(cz.metacentrum.perun.webgui.json.membersManager.SendPasswordResetLinkEmail)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetLogins (cz.metacentrum.perun.webgui.json.attributesManager.GetLogins)1 SendPasswordResetLinkEmail (cz.metacentrum.perun.webgui.json.membersManager.SendPasswordResetLinkEmail)1 Attribute (cz.metacentrum.perun.webgui.model.Attribute)1 PerunError (cz.metacentrum.perun.webgui.model.PerunError)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1 ArrayList (java.util.ArrayList)1