Search in sources :

Example 6 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject 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 7 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject 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 8 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject 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)

Example 9 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class CreateAttribute method createAttributeDefinition.

/**
	 * Creates attribute definition in DB - make RPC call
	 *
	 * @param friendlyName name of new attribute
	 * @param description description of new attribute
	 * @param namespace namespace of new attribute
	 * @param type type of new attribute (core,def,opt,virt)
	 */
public void createAttributeDefinition(final String displayName, final String friendlyName, final String description, final String namespace, final String type) {
    this.displayName = displayName;
    this.friendlyName = friendlyName;
    this.description = description;
    this.namespace = namespace;
    this.type = type;
    // test arguments
    if (!this.testCreating()) {
        return;
    }
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Creating attribute definition: " + friendlyName + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Attribute definition: " + friendlyName + " successfully created.");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, prepareJSONObject());
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 10 with JavaScriptObject

use of com.google.gwt.core.client.JavaScriptObject in project perun by CESNET.

the class DeleteExecService method deleteExecService.

/**
	 * Deletes Exec Service from DB
	 *
	 * @param serviceId id of exec service to be deleted
	 */
public void deleteExecService(final int serviceId) {
    this.execServiceId = serviceId;
    // test arguments
    if (!this.testArguments()) {
        return;
    }
    // whole JSON query
    JSONObject jsonQuery = new JSONObject();
    jsonQuery.put("execService", new JSONNumber(serviceId));
    // new events
    JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Deleting of ExecService: " + execServiceId + " failed.");
            events.onError(error);
        }

        ;

        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("ExecService: " + execServiceId + " deleted successfully.");
            events.onFinished(jso);
        }

        ;

        public void onLoadingStart() {
            events.onLoadingStart();
        }

        ;
    };
    // sending data
    JsonPostClient jspc = new JsonPostClient(newEvents);
    jspc.sendData(JSON_URL, jsonQuery);
}
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) JSONNumber(com.google.gwt.json.client.JSONNumber) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)436 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)333 PerunError (cz.metacentrum.perun.webgui.model.PerunError)212 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)181 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)110 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)110 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)104 ArrayList (java.util.ArrayList)95 JSONObject (com.google.gwt.json.client.JSONObject)79 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)73 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)58 HashMap (java.util.HashMap)34 JSONNumber (com.google.gwt.json.client.JSONNumber)32 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)31 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)31 Map (java.util.Map)25 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)24 JSONString (com.google.gwt.json.client.JSONString)22 Attribute (cz.metacentrum.perun.webgui.model.Attribute)20 Group (cz.metacentrum.perun.webgui.model.Group)19