Search in sources :

Example 1 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class ApplicationFormPage method tryToFindUserByName.

/**
	 * Try to find user by name
	 *
	 * If user found, message box shown
	 *
	 * @param jso returned data
	 */
private void tryToFindUserByName(JavaScriptObject jso) {
    // try to find
    JsonPostClient jspc = new JsonPostClient(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<Identity> users = JsonUtils.<Identity>jsoAsList(jso);
            if (users != null && !users.isEmpty())
                similarUsersFound(users);
        }
    });
    JSONObject query = new JSONObject();
    if (jso == null) {
        // before app submission
        jspc.sendData("registrarManager/checkForSimilarUsers", query);
    } else {
        // after app submission
        query.put("voId", new JSONNumber(vo.getId()));
        if (group != null) {
            query.put("groupId", new JSONNumber(group.getId()));
        } else {
            query.put("groupId", new JSONNumber(0));
        }
        query.put("type", new JSONString(type));
        jspc.sendData("registrarManager/checkForSimilarUsers", query);
    }
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) ArrayList(java.util.ArrayList) JSONNumber(com.google.gwt.json.client.JSONNumber) JSONString(com.google.gwt.json.client.JSONString)

Example 2 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class ApplicationFormPage method sendForm.

/**
	 * Send form
	 */
protected void sendForm(final CustomButton button) {
    PerunPrincipal pp = session.getPerunPrincipal();
    // fed info
    String fedInfo = "";
    fedInfo += "{";
    fedInfo += " displayName=\"" + pp.getAdditionInformations("displayName") + "\"";
    fedInfo += " commonName=\"" + pp.getAdditionInformations("cn") + "\"";
    fedInfo += " givenName=\"" + pp.getAdditionInformations("givenName") + "\"";
    fedInfo += " sureName=\"" + pp.getAdditionInformations("sn") + "\"";
    fedInfo += " loa=\"" + pp.getAdditionInformations("loa") + "\"";
    fedInfo += " mail=\"" + pp.getAdditionInformations("mail") + "\"";
    fedInfo += " organization=\"" + pp.getAdditionInformations("o") + "\"";
    fedInfo += " }";
    Application app = Application.construct(vo, group, type, fedInfo, pp.getActor(), pp.getExtSource(), pp.getExtSourceType(), pp.getExtSourceLoa());
    if (session.getUser() != null) {
        // set user association if known from perun
        app.setUser(session.getUser());
    }
    // loading
    final PopupPanel loadingBox = session.getUiElements().perunLoadingBox(ApplicationMessages.INSTANCE.processing());
    // Create application request
    CreateApplication ca = new CreateApplication(JsonCallbackEvents.disableButtonEvents(button, new JsonCallbackEvents() {

        @Override
        public void onLoadingStart() {
            // show loading box
            loadingBox.show();
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            loadingBox.hide();
            formOk(jso);
        }

        @Override
        public void onError(PerunError err) {
            loadingBox.hide();
            formError(err);
        }
    }));
    // Send the request
    ca.createApplication(app, data);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) CreateApplication(cz.metacentrum.perun.webgui.json.registrarManager.CreateApplication) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JSONString(com.google.gwt.json.client.JSONString) CreateApplication(cz.metacentrum.perun.webgui.json.registrarManager.CreateApplication)

Example 3 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class UsersApplicationsPage method refresh.

/**
	 * Refresh the page
	 */
private void refresh() {
    bodyContents.clear();
    String user = "";
    if (session.getUser() != null) {
        user = this.session.getUser().getFullNameWithTitles().trim();
    } else {
        PerunPrincipal pp = session.getPerunPrincipal();
        if (!pp.getAdditionInformations("displayName").equals("")) {
            user = pp.getAdditionInformations("displayName");
        } else if (!pp.getAdditionInformations("cn").equals("")) {
            user = pp.getAdditionInformations("cn");
        } else {
            if (pp.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
                user = Utils.convertCertCN(pp.getActor());
            } else {
                user = pp.getActor();
            }
        }
    }
    bodyContents.add(new HTML("<h1>" + ApplicationMessages.INSTANCE.applicationsForUser(user) + "</h1>"));
    // callback
    int userId = 0;
    if (session.getUser() != null) {
        userId = session.getUser().getId();
    }
    final GetApplicationsForUserForAppFormGui req = new GetApplicationsForUserForAppFormGui(userId);
    final ListBox listBox = new ListBox();
    req.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<Application> appls = JsonUtils.jsoAsList(jso);
            ArrayList<String> vos = new ArrayList<String>();
            for (Application app : appls) {
                if (!vos.contains(app.getVo().getName())) {
                    vos.add(app.getVo().getName());
                }
            }
            Collections.sort(vos);
            for (String s : vos) {
                listBox.addItem(s);
            }
            if (listBox.getItemCount() > 0) {
                listBox.insertItem(WidgetTranslation.INSTANCE.listboxAll(), 0);
            }
            for (int i = 0; i < listBox.getItemCount(); i++) {
                if (listBox.getItemText(i).equals(ApplicationFormGui.getVo().getName())) {
                    listBox.setSelectedIndex(i);
                    req.filterTable(ApplicationFormGui.getVo().getName());
                    break;
                }
            }
        }

        @Override
        public void onError(PerunError error) {
        }

        @Override
        public void onLoadingStart() {
            listBox.clear();
        }
    });
    req.setCheckable(false);
    listBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (listBox.getSelectedIndex() > 0) {
                req.filterTable(listBox.getItemText(listBox.getSelectedIndex()));
            } else {
                // show all
                req.filterTable("");
            }
        }
    });
    final TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(new HTML("<strong>" + ApplicationMessages.INSTANCE.filterByVo() + ":</strong>"));
    tabMenu.addWidget(listBox);
    tabMenu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
    tabMenu.addWidget(new HTML("<strong>" + ApplicationMessages.INSTANCE.clickOnApplicationToSee() + "</strong>"));
    tabMenu.addStyleName("tabMenu");
    final VerticalPanel applicationsWrapper = new VerticalPanel();
    applicationsWrapper.setSize("100%", "100%");
    applicationsWrapper.add(tabMenu);
    final CellTable<Application> appsTable = req.getTable(new FieldUpdater<Application, String>() {

        public void update(int index, Application object, String value) {
            applicationsWrapper.clear();
            applicationsWrapper.add(backButton);
            applicationsWrapper.add(getApplicationDetailWidget(object));
        }
    });
    appsTable.addStyleName("perun-table");
    applicationsWrapper.add(appsTable);
    backButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            applicationsWrapper.clear();
            applicationsWrapper.add(tabMenu);
            applicationsWrapper.add(appsTable);
        }
    });
    bodyContents.add(applicationsWrapper);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) PerunPrincipal(cz.metacentrum.perun.webgui.model.PerunPrincipal) GetApplicationsForUserForAppFormGui(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationsForUserForAppFormGui) PerunError(cz.metacentrum.perun.webgui.model.PerunError) Application(cz.metacentrum.perun.webgui.model.Application)

Example 4 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class ApplicationFormLeftMenu method addLogoutItem.

public void addLogoutItem() {
    // if not anonymous identity
    if (!PerunWebSession.getInstance().getRpcUrl().startsWith("/non/rpc")) {
        int i = menuContents.getRowCount();
        menuContents.setWidget(i, 0, new Image(SmallIcons.INSTANCE.doorOutIcon()));
        Anchor a = new Anchor(ApplicationMessages.INSTANCE.logout());
        a.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                Logout call = new Logout(new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        Utils.clearFederationCookies();
                        History.newItem("logout");
                        RootLayoutPanel.get().clear();
                        RootLayoutPanel.get().add(new LogoutWidget());
                    }
                });
                call.retrieveData();
            }
        });
        menuContents.setWidget(i, 1, a);
    }
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Logout(cz.metacentrum.perun.webgui.json.authzResolver.Logout) LogoutWidget(cz.metacentrum.perun.webgui.widgets.LogoutWidget)

Example 5 with JsonCallbackEvents

use of cz.metacentrum.perun.webgui.json.JsonCallbackEvents in project perun by CESNET.

the class PasswordResetFormPage method getContent.

/**
	 * Returns page content
	 *
	 * @return page content
	 */
public Widget getContent() {
    bodyContents.clear();
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("50%", "50%");
    vp.getElement().setAttribute("style", "margin: auto; position: relative; top: 50px;");
    bodyContents.setWidget(vp);
    // if using backup pwd-reset option, draw different content
    if (Location.getParameterMap().keySet().contains("m") && Location.getParameterMap().keySet().contains("i") && session.getRpcUrl().startsWith("/non/rpc")) {
        return drawNonAuthzPasswordReset(vp);
    }
    if (Location.getParameter("login-namespace") != null && !Location.getParameter("login-namespace").isEmpty()) {
        namespace = Location.getParameter("login-namespace");
    } else {
        namespace = "";
    }
    final Label headerLabel = new Label();
    final ExtendedPasswordBox passBox = new ExtendedPasswordBox();
    final ExtendedPasswordBox secondPassBox = new ExtendedPasswordBox();
    final ExtendedTextBox.TextBoxValidator validator;
    final ExtendedTextBox.TextBoxValidator validator2;
    final CustomButton resetPass = new CustomButton("Reset password", "Reset password in namespace: " + namespace, SmallIcons.INSTANCE.keyIcon());
    validator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (passBox.getTextBox().getValue().trim().isEmpty()) {
                passBox.setError("Password can't be empty !");
                return false;
            } else if (!passBox.getTextBox().getValue().trim().equals(secondPassBox.getTextBox().getValue().trim())) {
                passBox.setError("Password in both textboxes must be the same !");
                return false;
            } else {
                passBox.setOk();
                secondPassBox.setOk();
                return true;
            }
        }
    };
    validator2 = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (secondPassBox.getTextBox().getValue().trim().isEmpty()) {
                secondPassBox.setError("Password can't be empty !");
                return false;
            } else if (!secondPassBox.getTextBox().getValue().trim().equals(passBox.getTextBox().getValue().trim())) {
                secondPassBox.setError("Password in both textboxes must be the same !");
                return false;
            } else {
                secondPassBox.setOk();
                passBox.setOk();
                return true;
            }
        }
    };
    passBox.setValidator(validator);
    secondPassBox.setValidator(validator2);
    FlexTable ft = new FlexTable();
    ft.setSize("300px", "100px");
    ft.addStyleName("inputFormFlexTable");
    ft.getElement().setAttribute("style", "margin: auto;");
    ft.setHTML(1, 0, "New password:");
    ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
    ft.setWidget(1, 1, passBox);
    ft.setHTML(2, 0, "Retype new password:");
    ft.getFlexCellFormatter().setStyleName(2, 0, "itemName");
    ft.setWidget(2, 1, secondPassBox);
    final FlexTable header = new FlexTable();
    header.setWidget(0, 0, new AjaxLoaderImage());
    header.setWidget(0, 1, headerLabel);
    GetLogins loginsCall = new GetLogins(session.getUser().getId(), new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            bodyContents.clear();
            FlexTable ft = new FlexTable();
            ft.setSize("100%", "300px");
            ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Error occurred when getting your login from Perun. Please, reload page to retry.</h2><p>" + error.getErrorId() + ": " + error.getErrorInfo() + "</p>");
            ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
            ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
            bodyContents.setWidget(ft);
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.keyIcon()));
            logins = JsonUtils.jsoAsList(jso);
            if (logins != null && !logins.isEmpty()) {
                for (Attribute a : logins) {
                    // if have login in namespace
                    if (a.getFriendlyNameParameter().equals(namespace)) {
                        boolean found = false;
                        for (String name : Utils.getSupportedPasswordNamespaces()) {
                            if (a.getFriendlyNameParameter().equalsIgnoreCase(name)) {
                                found = true;
                            }
                        }
                        if (found) {
                            // HAVE LOGIN AND SUPPORTED
                            headerLabel.setText("Password reset for " + a.getValue() + "@" + namespace);
                            return;
                        } else {
                            // NOT SUPPORTED
                            bodyContents.clear();
                            FlexTable ft = new FlexTable();
                            ft.setSize("100%", "300px");
                            ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Password reset in selected namespace is not supported !</h2>");
                            ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                            ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                            bodyContents.setWidget(ft);
                            return;
                        }
                    }
                }
            }
            // DO NOT HAVE LOGIN IN NAMESPACE
            bodyContents.clear();
            FlexTable ft = new FlexTable();
            ft.setSize("100%", "300px");
            if (namespace != null && !namespace.isEmpty()) {
                ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>You don't have login in selected namespace !</h2>");
            } else {
                ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>You must specify login-namespace in URL !</h2>");
            }
            ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
            ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
            bodyContents.setWidget(ft);
        }
    });
    loginsCall.retrieveData();
    resetPass.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ChangePassword changepw = new ChangePassword(JsonCallbackEvents.disableButtonEvents(resetPass, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    bodyContents.clear();
                    FlexTable ft = new FlexTable();
                    ft.setSize("100%", "300px");
                    ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.acceptIcon()) + "<h2>Password successfully changed!</h2>");
                    ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                    ft.setHTML(1, 0, "<h2>New password will work on all resources in approx. 15 minutes after reset.</h2>");
                    ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                    bodyContents.setWidget(ft);
                }
            }), false);
            if (validator.validateTextBox() && validator2.validateTextBox()) {
                changepw.changePassword(session.getUser(), namespace, "", passBox.getTextBox().getText().trim());
            }
        }
    });
    headerLabel.setText("Password reset for ");
    headerLabel.setStyleName("now-managing");
    vp.add(header);
    vp.add(ft);
    TabMenu menu = new TabMenu();
    menu.addWidget(resetPass);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    return bodyContents;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ChangePassword(cz.metacentrum.perun.webgui.json.usersManager.ChangePassword) GetLogins(cz.metacentrum.perun.webgui.json.attributesManager.GetLogins) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)380 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)333 PerunError (cz.metacentrum.perun.webgui.model.PerunError)206 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)181 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)143 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)143 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)142 ArrayList (java.util.ArrayList)125 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)108 JSONObject (com.google.gwt.json.client.JSONObject)69 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)60 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)41 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)34 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)34 HashMap (java.util.HashMap)33 JSONNumber (com.google.gwt.json.client.JSONNumber)30 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)24 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)24 Group (cz.metacentrum.perun.webgui.model.Group)23 Map (java.util.Map)23