Search in sources :

Example 81 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class SelfAuthenticationsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Authentication");
    final String notSet = "<i>N/A</i>";
    // content
    ScrollPanel vp = new ScrollPanel();
    vp.setSize("100%", "100%");
    final VerticalPanel innerVp = new VerticalPanel();
    innerVp.setSize("100%", "100%");
    final TabMenu menu = new TabMenu();
    innerVp.add(menu);
    innerVp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final FlexTable layout = new FlexTable();
    layout.setSize("100%", "100%");
    vp.add(innerVp);
    innerVp.add(layout);
    layout.setStyleName("perun-table");
    vp.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(vp, 350, this);
    FlexTable loginsHeader = new FlexTable();
    loginsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.keyIcon()));
    loginsHeader.setHTML(0, 1, "<p>Logins");
    loginsHeader.getFlexCellFormatter().setStyleName(0, 1, "subsection-heading");
    layout.setWidget(0, 0, loginsHeader);
    FlexTable certHeader = new FlexTable();
    certHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.sslCertificatesIcon()));
    certHeader.setHTML(0, 1, "<p>Certificates");
    certHeader.getFlexCellFormatter().setStyleName(0, 1, "subsection-heading");
    layout.setWidget(3, 0, certHeader);
    layout.setHTML(4, 0, "To <strong>add certificate</strong> please visit <a href=\"" + Utils.getIdentityConsolidatorLink(false) + "\" target=\"_blank\">identity consolidator &gt;&gt;</a> and select \"Using personal certificate\" option.<br />&nbsp;");
    FlexTable sshHeader = new FlexTable();
    sshHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.serverKeyIcon()));
    sshHeader.setHTML(0, 1, "<p>Kerberos & SSH keys");
    sshHeader.getFlexCellFormatter().setStyleName(0, 1, "subsection-heading");
    layout.setWidget(6, 0, sshHeader);
    // login table
    final FlexTable loginsTable = new FlexTable();
    loginsTable.setStyleName("inputFormFlexTableDark");
    final GetLogins logins = new GetLogins(userId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            final ArrayList<Attribute> list = JsonUtils.jsoAsList(jso);
            layout.setWidget(1, 0, loginsTable);
            int row = 0;
            if (user.isServiceUser() || user.isSponsoredUser()) {
                CustomButton addLogin = TabMenu.getPredefinedButton(ButtonType.ADD, "Add new login (only for supported namespaces)");
                addLogin.addClickHandler(new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        session.getTabManager().addTabToCurrentTab(new AddLoginTabItem(user, list));
                    }
                });
                loginsTable.setWidget(row, 0, addLogin);
                row++;
            }
            if (list != null && !list.isEmpty()) {
                for (final Attribute a : list) {
                    loginsTable.setHTML(row, 0, "Login in " + a.getFriendlyNameParameter().toUpperCase() + ":");
                    loginsTable.getFlexCellFormatter().setWidth(row, 0, "150px");
                    loginsTable.getFlexCellFormatter().addStyleName(row, 0, "itemName");
                    loginsTable.setHTML(row, 1, a.getValue());
                    loginsTable.getFlexCellFormatter().setWidth(row, 1, "150px");
                    // change password if possible
                    if (Utils.getSupportedPasswordNamespaces().contains(a.getFriendlyNameParameter())) {
                        FlexTable fw = new FlexTable();
                        fw.addStyleName("padding-vertical");
                        CustomButton cb = new CustomButton("Change password…", SmallIcons.INSTANCE.keyIcon(), new ClickHandler() {

                            public void onClick(ClickEvent event) {
                                session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, a.getFriendlyNameParameter(), a.getValue(), SelfPasswordTabItem.Actions.CHANGE));
                            }
                        });
                        CustomButton cb2 = new CustomButton("Reset password…", SmallIcons.INSTANCE.keyIcon(), new ClickHandler() {

                            public void onClick(ClickEvent event) {
                                // OPEN PASSWORD RESET APPLICATION ON SAME SERVER
                                Window.open("" + Utils.getPasswordResetLink(a.getFriendlyNameParameter()), "_blank", "");
                            }
                        });
                        fw.setWidget(0, 0, cb);
                        if (!user.isServiceUser()) {
                            fw.setWidget(0, 1, cb2);
                        } else {
                            cb.setText("Reset password…");
                        }
                        loginsTable.setWidget(row, 2, fw);
                    }
                    row++;
                }
            } else {
                loginsTable.setHTML(row, 0, "You don't have any login in supported namespaces.");
                loginsTable.getFlexCellFormatter().setStyleName(0, 0, "inputFormInlineComment");
            }
        }

        @Override
        public void onLoadingStart() {
            layout.setWidget(1, 0, new AjaxLoaderImage().loadingStart());
        }

        @Override
        public void onError(PerunError error) {
            layout.setHTML(1, 0, "Error while loading logins.");
            layout.getFlexCellFormatter().setStyleName(1, 0, "serverResponseLabelError");
        }
    });
    logins.retrieveData();
    // certificates table
    final FlexTable certTable = new FlexTable();
    certTable.addStyleName("inputFormFlexTableDark");
    certTable.setHTML(0, 0, "Certificates: ");
    certTable.getFlexCellFormatter().addStyleName(0, 0, "itemName");
    certTable.getFlexCellFormatter().setWidth(0, 0, "150px");
    layout.setWidget(5, 0, certTable);
    final GetUserExtSources ueses = new GetUserExtSources(userId);
    ueses.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<UserExtSource> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                boolean found = false;
                FlexTable tab = new FlexTable();
                // rowcounter
                int i = 0;
                for (final UserExtSource a : list) {
                    if (a.getExtSource().getType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
                        found = true;
                        tab.setHTML(i++, 0, "<strong>" + a.getLogin() + "</strong>");
                        tab.setHTML(i++, 0, "Issuer: " + a.getExtSource().getName());
                        if (!a.isPersistent()) {
                            CustomButton removeButton = new CustomButton("Remove", SmallIcons.INSTANCE.deleteIcon(), new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent event) {
                                    RemoveUserExtSource remove = new RemoveUserExtSource(new JsonCallbackEvents() {

                                        @Override
                                        public void onFinished(JavaScriptObject jso) {
                                            // reload whole tab
                                            ueses.retrieveData();
                                        }
                                    });
                                    remove.removeUserExtSource(userId, a.getId());
                                }
                            });
                            // add button to table
                            tab.getFlexCellFormatter().setRowSpan(i - 2, 1, 2);
                            tab.setWidget(i - 2, 1, removeButton);
                        }
                    }
                }
                if (found) {
                    certTable.setWidget(0, 1, tab);
                } else {
                    certTable.setHTML(0, 1, notSet);
                }
            } else {
                certTable.setHTML(0, 1, notSet);
            }
        }

        @Override
        public void onError(PerunError error) {
            certTable.setHTML(0, 1, "Error while loading certificates. Refresh page to retry.");
            certTable.getFlexCellFormatter().setStyleName(0, 1, "serverResponseLabelError");
        }

        @Override
        public void onLoadingStart() {
            certTable.setWidget(0, 1, new Image(AjaxLoaderImage.SMALL_IMAGE_URL));
        }
    });
    ueses.retrieveData();
    // Kerberos and SSH table
    Map<String, Integer> ids = new HashMap<>();
    ids.put("user", userId);
    final PerunAttributeTableWidget table = new PerunAttributeTableWidget(ids);
    table.setDark(true);
    table.setDescriptionShown(true);
    final GetListOfAttributes attrs2 = new GetListOfAttributes(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            table.add(JsonUtils.<Attribute>jsoAsList(jso));
            layout.setWidget(7, 0, table);
        }

        @Override
        public void onError(PerunError error) {
            layout.setHTML(7, 0, "Error while loading Kerberos and SSH settings. Refresh page to retry.");
            layout.getFlexCellFormatter().setStyleName(7, 0, "serverResponseLabelError");
        }

        @Override
        public void onLoadingStart() {
            layout.setWidget(7, 0, new AjaxLoaderImage().loadingStart());
        }
    });
    ArrayList<String> list2 = new ArrayList<String>();
    list2.add("urn:perun:user:attribute-def:def:kerberosAdminPrincipal");
    list2.add("urn:perun:user:attribute-def:def:sshPublicAdminKey");
    list2.add("urn:perun:user:attribute-def:def:sshPublicKey");
    attrs2.getListOfAttributes(ids, list2);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) Attribute(cz.metacentrum.perun.webgui.model.Attribute) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) PerunAttributeTableWidget(cz.metacentrum.perun.webgui.widgets.PerunAttributeTableWidget) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) RemoveUserExtSource(cz.metacentrum.perun.webgui.json.usersManager.RemoveUserExtSource) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetLogins(cz.metacentrum.perun.webgui.json.attributesManager.GetLogins) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) UserExtSource(cz.metacentrum.perun.webgui.model.UserExtSource) RemoveUserExtSource(cz.metacentrum.perun.webgui.json.usersManager.RemoveUserExtSource) GetUserExtSources(cz.metacentrum.perun.webgui.json.usersManager.GetUserExtSources) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 82 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class AddDependencyTabItem method draw.

public Widget draw() {
    // TITLE
    titleWidget.setText("Add dependency");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // prepares layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    // close tab events
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    final ListBoxWithObjects<ExecService> listBox = new ListBoxWithObjects<ExecService>();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addDependantExecService());
    // fill listbox after callback finishes
    final JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            listBox.clear();
            ArrayList<ExecService> execs = JsonUtils.jsoAsList(jso);
            if (execs != null && !execs.isEmpty()) {
                execs = new TableSorter<ExecService>().sortByService(execs);
                for (int i = 0; i < execs.size(); i++) {
                    listBox.addItem(execs.get(i));
                    if (execService.getService().getName().equals(execs.get(i).getService().getName()) && !execService.getType().equals(execs.get(i).getType())) {
                        // preselect different type of exec service from same service
                        listBox.setSelected(execs.get(i), true);
                    }
                }
                addButton.setEnabled(true);
            } else {
                listBox.addItem("No exec service available");
            }
        }

        @Override
        public void onLoadingStart() {
            listBox.clear();
            listBox.addItem("Loading...");
            addButton.setEnabled(false);
        }

        @Override
        public void onError(PerunError error) {
            listBox.addItem("Error while loading");
            addButton.setEnabled(false);
        }
    };
    // callback for all services
    ListExecServices callback = new ListExecServices(0, localEvents);
    callback.retrieveData();
    // layout
    layout.setHTML(0, 0, "ExecService:");
    layout.setHTML(1, 0, "Depend On:");
    layout.setHTML(0, 1, execService.getService().getName() + " " + execService.getType());
    layout.setWidget(1, 1, listBox);
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab);
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            CreateDependency request = new CreateDependency(closeTabEvents);
            request.createDependancy(execServiceId, listBox.getSelectedObject().getId());
        }
    });
    final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
    cancelButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    });
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.addStyleName(i, 0, "itemName");
    }
    menu.addWidget(addButton);
    menu.addWidget(cancelButton);
    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) ExecService(cz.metacentrum.perun.webgui.model.ExecService) CreateDependency(cz.metacentrum.perun.webgui.json.generalServiceManager.CreateDependency) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ListExecServices(cz.metacentrum.perun.webgui.json.generalServiceManager.ListExecServices) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) 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 83 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class ServiceDestinationsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Service destinations");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));
    // Adds menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // buttons
    final CustomButton addDestButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addDestination());
    final CustomButton removeDestButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeSelectedDestinations());
    menu.addWidget(addDestButton);
    menu.addWidget(removeDestButton);
    menu.addWidget(new HTML("<strong>Selected facility:</strong>"));
    // listbox with facilities
    final ListBoxWithObjects<Facility> ls = new ListBoxWithObjects<Facility>();
    menu.addWidget(ls);
    // get empty table used for destinations
    final GetAllRichDestinations callback = new GetAllRichDestinations(null, service);
    callback.showFacilityColumn(true);
    callback.showServiceColumn(false);
    // do not make callback yet
    final CellTable<Destination> table = callback.getEmptyTable();
    if (lastSelectedFacilityId == 0) {
        callback.retrieveData();
    }
    // refresh events called when selection changes or callback ends
    final JsonCallbackEvents refreshEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            if (ls.getSelectedIndex() == 0) {
                // fills table with destinations of all facilities
                callback.clearTable();
                callback.retrieveData();
            } else {
                callback.clearTable();
                ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
                // fills table with destinations of selected facility
                JsonCallbackEvents localEvents = new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        JsArray<Destination> dst = JsonUtils.jsoAsArray(jso);
                        for (int i = 0; i < dst.length(); i++) {
                            callback.addToTable(dst.get(i));
                        }
                        ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                    }

                    public void onError(PerunError error) {
                        ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingError(error);
                    }
                };
                final GetDestinations callback = new GetDestinations(ls.getSelectedObject(), service, localEvents);
                callback.retrieveData();
            }
        }
    };
    // fills listbox and table with dest. for all service facilities
    JsonCallbackEvents events = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            ls.clear();
            ArrayList<Facility> facs = JsonUtils.jsoAsList(jso);
            facs = new TableSorter<Facility>().sortByName(facs);
            // if no facility
            if (facs.size() == 0) {
                ls.addItem("No facility available");
                return;
            }
            for (int i = 0; i < facs.size(); i++) {
                ls.addItem(facs.get(i));
                if (facs.get(i).getId() == lastSelectedFacilityId) {
                    ls.setSelected(facs.get(i), true);
                }
            }
            ls.addAllOption();
            if (lastSelectedFacilityId == 0) {
                // select all
                ls.setItemSelected(0, true);
            } else {
                // was selected
                addDestButton.setEnabled(true);
                refreshEvents.onFinished(null);
            }
        }

        public void onError(PerunError error) {
            ls.addItem("Error while loading");
            addDestButton.setEnabled(false);
        }

        public void onLoadingStart() {
            ls.clear();
            ls.addItem("Loading...");
            addDestButton.setEnabled(false);
        }
    };
    final GetAssignedFacilities assignedFacilities = new GetAssignedFacilities(PerunEntity.SERVICE, serviceId, events);
    assignedFacilities.retrieveData();
    ls.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            if (ls.getSelectedIndex() > 0) {
                // store last selected facility id
                addDestButton.setEnabled(true);
                lastSelectedFacilityId = ls.getSelectedObject().getId();
            } else {
                addDestButton.setEnabled(false);
                lastSelectedFacilityId = 0;
            }
            refreshEvents.onFinished(null);
        }
    });
    // CLICK HANDLERS FOR BUTTONS
    addDestButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AddFacilityDestinationTabItem(ls.getSelectedObject()));
        }
    });
    removeDestButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // get
            final ArrayList<Destination> destsToRemove = callback.getTableSelectedList();
            UiElements.showDeleteConfirm(destsToRemove, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < destsToRemove.size(); i++) {
                        if (i == destsToRemove.size() - 1) {
                            RemoveDestination request = new RemoveDestination(destsToRemove.get(i).getFacility().getId(), service.getId(), JsonCallbackEvents.disableButtonEvents(removeDestButton, refreshEvents));
                            request.removeDestination(destsToRemove.get(i).getDestination(), destsToRemove.get(i).getType());
                        } else {
                            RemoveDestination request = new RemoveDestination(destsToRemove.get(i).getFacility().getId(), service.getId(), JsonCallbackEvents.disableButtonEvents(removeDestButton));
                            request.removeDestination(destsToRemove.get(i).getDestination(), destsToRemove.get(i).getType());
                        }
                    }
                }
            });
        }
    });
    // filter box
    menu.addFilterWidget(new ExtendedSuggestBox(callback.getOracle()), new PerunSearchEvent() {

        public void searchFor(String text) {
            callback.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterDestinationByFacility());
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    removeDestButton.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, removeDestButton);
    // add tabs to the main panel
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) RemoveDestination(cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination) Destination(cz.metacentrum.perun.webgui.model.Destination) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetAllRichDestinations(cz.metacentrum.perun.webgui.json.servicesManager.GetAllRichDestinations) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetAssignedFacilities(cz.metacentrum.perun.webgui.json.facilitiesManager.GetAssignedFacilities) AddFacilityDestinationTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.AddFacilityDestinationTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Facility(cz.metacentrum.perun.webgui.model.Facility) PerunError(cz.metacentrum.perun.webgui.model.PerunError) GetDestinations(cz.metacentrum.perun.webgui.json.servicesManager.GetDestinations) RemoveDestination(cz.metacentrum.perun.webgui.json.servicesManager.RemoveDestination)

Example 84 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class AddLoginTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add login");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final ExtendedTextBox userLogin = new ExtendedTextBox();
    final ListBox namespace = new ListBox();
    final CustomButton createLogin = TabMenu.getPredefinedButton(ButtonType.ADD, "Add login in selected namespace");
    final Label notice = new Label("Your login will be automatically generated.");
    notice.setVisible(false);
    // offer only available namespaces.
    ArrayList<String> logins = new ArrayList<String>();
    for (Attribute a : usersLogins) {
        logins.add(a.getFriendlyNameParameter());
    }
    for (String s : Utils.getSupportedPasswordNamespaces()) {
        if (!logins.contains(s)) {
            namespace.addItem(s.toUpperCase(), s);
        }
    }
    final ExtendedTextBox.TextBoxValidator loginValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (userLogin.getTextBox().getValue().trim().isEmpty()) {
                userLogin.setError("Login can't be empty!");
                return false;
            }
            RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
            boolean match = regExp.test(userLogin.getTextBox().getValue().trim());
            if (!match) {
                userLogin.setError("Invalid format!");
                return false;
            }
            if (userLogin.isProcessing() || userLogin.isHardError()) {
                return false;
            }
            userLogin.setOk();
            return true;
        }
    };
    userLogin.setValidator(loginValidator);
    final FlexTable layout = new FlexTable();
    layout.addStyleName("inputFormFlexTable");
    layout.setHTML(0, 0, "Namespace:");
    layout.setHTML(1, 0, "Login:");
    for (int i = 0; i < layout.getRowCount(); i++) {
        layout.getFlexCellFormatter().addStyleName(i, 0, "itemName");
    }
    layout.setWidget(0, 1, namespace);
    layout.setWidget(1, 1, userLogin);
    layout.getFlexCellFormatter().setColSpan(2, 0, 2);
    layout.setWidget(2, 0, notice);
    layout.getFlexCellFormatter().addStyleName(2, 0, "inputFormInlineComment");
    TabMenu menu = new TabMenu();
    menu.addWidget(createLogin);
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    // user can't add new login
    if (namespace.getItemCount() == 0) {
        vp.add(new HTML("<p><strong>You already have login in all supported namespaces!</strong></p>"));
        createLogin.setEnabled(false);
    } else {
        // user can add new login
        vp.add(layout);
        // check login availability
        userLogin.getTextBox().addKeyUpHandler(new KeyUpHandler() {

            @Override
            public void onKeyUp(KeyUpEvent keyUpEvent) {
                if (keyUpEvent.isDownArrow() || keyUpEvent.isUpArrow() || keyUpEvent.isLeftArrow() || keyUpEvent.isRightArrow()) {
                    // do not trigger when no text input
                    return;
                }
                final String value = userLogin.getTextBox().getValue().trim();
                // trigger new validation on checked input or if previously was hard error
                if ((!value.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(value)) || userLogin.isHardError()) {
                    new IsLoginAvailable(namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            if (value.equals(userLogin.getTextBox().getValue().trim())) {
                                BasicOverlayType bo = jso.cast();
                                userLogin.setProcessing(false);
                                if (!bo.getBoolean()) {
                                    userLogin.setHardError("Login is already in use!");
                                } else {
                                    userLogin.removeHardError();
                                    loginValidator.validateTextBox();
                                }
                            }
                        }

                        @Override
                        public void onLoadingStart() {
                            if (value.equals(userLogin.getTextBox().getValue().trim())) {
                                userLogin.removeHardError();
                                userLogin.setProcessing(true);
                            }
                        }

                        @Override
                        public void onError(PerunError error) {
                            if (value.equals(userLogin.getTextBox().getValue().trim())) {
                                userLogin.setProcessing(false);
                                userLogin.setHardError("Unable to check if login is available!");
                            }
                        }
                    }).retrieveData();
                }
            }
        });
        namespace.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent changeEvent) {
                if (namespace.getSelectedValue().equals("mu")) {
                    userLogin.getTextBox().setValue("");
                    userLogin.removeHardError();
                    userLogin.setOk();
                    userLogin.getTextBox().setEnabled(false);
                    notice.setVisible(true);
                } else {
                    userLogin.getTextBox().setEnabled(true);
                    notice.setVisible(false);
                    final String value = userLogin.getTextBox().getValue().trim();
                    // trigger new validation on checked input or if previously was hard error
                    if ((!value.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(value)) || userLogin.isHardError()) {
                        new IsLoginAvailable(namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                if (value.equals(userLogin.getTextBox().getValue().trim())) {
                                    BasicOverlayType bo = jso.cast();
                                    userLogin.setProcessing(false);
                                    if (!bo.getBoolean()) {
                                        userLogin.setError("Login is already in use!");
                                    } else {
                                        userLogin.removeHardError();
                                        loginValidator.validateTextBox();
                                    }
                                }
                            }

                            @Override
                            public void onLoadingStart() {
                                if (value.equals(userLogin.getTextBox().getValue().trim())) {
                                    userLogin.removeHardError();
                                    userLogin.setProcessing(true);
                                }
                            }

                            @Override
                            public void onError(PerunError error) {
                                if (value.equals(userLogin.getTextBox().getValue().trim())) {
                                    userLogin.setProcessing(false);
                                    userLogin.setHardError("Error while loading.");
                                }
                            }
                        }).retrieveData();
                    }
                }
            }
        });
        createLogin.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                if (namespace.getSelectedValue().equals("mu")) {
                    session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), SelfPasswordTabItem.Actions.CREATE));
                } else {
                    if (!loginValidator.validateTextBox())
                        return;
                    SetLogin request = new SetLogin(JsonCallbackEvents.disableButtonEvents(createLogin, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), SelfPasswordTabItem.Actions.CREATE));
                        }
                    }));
                    request.setLogin(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim());
                }
            }
        });
    }
    if (namespace.getSelectedValue().equals("mu")) {
        userLogin.getTextBox().setValue("");
        userLogin.removeHardError();
        userLogin.setOk();
        userLogin.getTextBox().setEnabled(false);
        notice.setVisible(true);
    }
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) BasicOverlayType(cz.metacentrum.perun.webgui.model.BasicOverlayType) ArrayList(java.util.ArrayList) IsLoginAvailable(cz.metacentrum.perun.webgui.json.usersManager.IsLoginAvailable) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) RegExp(com.google.gwt.regexp.shared.RegExp) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) SetLogin(cz.metacentrum.perun.webgui.json.usersManager.SetLogin) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 85 with PerunError

use of cz.metacentrum.perun.webgui.model.PerunError in project perun by CESNET.

the class AddUserExtSourceTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add ext. identity");
    VerticalPanel vp = new VerticalPanel();
    // get available ext sources
    final ListBoxWithObjects<ExtSource> extSourcesDropDown = new ListBoxWithObjects<ExtSource>();
    final TextBox externalLogin = new TextBox();
    final TextBox loaTextBox = new TextBox();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add external identity to user");
    // fill listbox
    JsonCallbackEvents fillEvent = new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            extSourcesDropDown.clear();
            extSourcesDropDown.addItem("Error while loading");
            callDone = false;
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            extSourcesDropDown.clear();
            ArrayList<ExtSource> list = JsonUtils.jsoAsList(jso);
            list = new TableSorter<ExtSource>().sortByName(list);
            if (list == null || list.isEmpty()) {
                extSourcesDropDown.addItem("No external sources available");
                return;
            }
            for (ExtSource ex : list) {
                extSourcesDropDown.addItem(ex);
            }
            callDone = true;
            if (!externalLogin.getText().isEmpty() && !extSourcesDropDown.isEmpty() && JsonUtils.checkParseInt(loaTextBox.getText()) && callDone) {
                addButton.setEnabled(true);
            }
        }

        @Override
        public void onLoadingStart() {
            extSourcesDropDown.clear();
            extSourcesDropDown.addItem("Loading...");
            callDone = false;
        }
    };
    // callback
    final GetExtSources extSources = new GetExtSources(fillEvent);
    extSources.retrieveData();
    // create layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    layout.setHTML(0, 0, "External login:");
    layout.setWidget(0, 1, externalLogin);
    layout.setHTML(1, 0, "External source:");
    layout.setWidget(1, 1, extSourcesDropDown);
    layout.setHTML(2, 0, "Level of Assurance:");
    layout.setWidget(2, 1, loaTextBox);
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
    for (int i = 0; i < layout.getRowCount(); i++) {
        cellFormatter.setStyleName(i, 0, "itemName");
    }
    cellFormatter.setStyleName(3, 1, "inputFormInlineComment");
    layout.setHTML(3, 1, "0 - not verified = default</br>1 - verified email</br>2 - verified identity</br>3 - verified identity, strict password strength");
    TabMenu menu = new TabMenu();
    // close tab events
    final JsonCallbackEvents addExtSrcEvents = JsonCallbackEvents.closeTabDisableButtonEvents(addButton, this);
    addButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ExtSource selected = extSourcesDropDown.getObjectAt(extSourcesDropDown.getSelectedIndex());
            String login = externalLogin.getText();
            AddUserExtSource request = new AddUserExtSource(addExtSrcEvents);
            int loa = 0;
            if (JsonUtils.checkParseInt(loaTextBox.getText())) {
                loa = Integer.parseInt(loaTextBox.getText());
            } else {
                JsonUtils.cantParseIntConfirm("Level of Assurance", loaTextBox.getText());
                return;
            }
            request.addUserExtSource(userId, login.trim(), selected, loa);
        }
    });
    addButton.setEnabled(false);
    menu.addWidget(addButton);
    final TabItem tab = this;
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().closeTab(tab);
        }
    }));
    KeyUpHandler handler = new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (!externalLogin.getText().isEmpty() && !extSourcesDropDown.isEmpty() && JsonUtils.checkParseInt(loaTextBox.getText()) && callDone) {
                addButton.setEnabled(true);
            } else {
                addButton.setEnabled(false);
            }
        }
    };
    externalLogin.addKeyUpHandler(handler);
    loaTextBox.addKeyUpHandler(handler);
    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) GetExtSources(cz.metacentrum.perun.webgui.json.extSourcesManager.GetExtSources) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) AddUserExtSource(cz.metacentrum.perun.webgui.json.usersManager.AddUserExtSource) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AddUserExtSource(cz.metacentrum.perun.webgui.json.usersManager.AddUserExtSource) ExtSource(cz.metacentrum.perun.webgui.model.ExtSource) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Aggregations

PerunError (cz.metacentrum.perun.webgui.model.PerunError)177 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)173 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)167 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)126 JSONObject (com.google.gwt.json.client.JSONObject)55 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)36 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)36 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)30 ArrayList (java.util.ArrayList)30 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)27 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)21 JSONNumber (com.google.gwt.json.client.JSONNumber)17 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)16 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)16 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)15 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)11 Attribute (cz.metacentrum.perun.webgui.model.Attribute)10 HashMap (java.util.HashMap)10 JSONString (com.google.gwt.json.client.JSONString)8 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)8