Search in sources :

Example 71 with CustomButton

use of cz.metacentrum.perun.webgui.widgets.CustomButton 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 72 with CustomButton

use of cz.metacentrum.perun.webgui.widgets.CustomButton 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)

Example 73 with CustomButton

use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.

the class ConnectServiceIdentityTabItem method draw.

public Widget draw() {
    titleWidget.setText("Connect identity");
    VerticalPanel content = new VerticalPanel();
    content.setSize("100%", "100%");
    final TabItem tab = this;
    // add button
    final CustomButton addButton;
    if (user.isServiceUser() || user.isSponsoredUser()) {
        addButton = new CustomButton("Connect", "Add selected users to this identity", SmallIcons.INSTANCE.addIcon());
    } else {
        addButton = new CustomButton("Connect", "Add selected identities to user", SmallIcons.INSTANCE.addIcon());
    }
    TabMenu menu = new TabMenu();
    menu.addWidget(addButton);
    content.add(menu);
    content.setCellHeight(menu, "30px");
    final FindCompleteRichUsers call = new FindCompleteRichUsers("", null);
    if (user.isServiceUser()) {
        call.hideService(true);
    }
    if (user.isSponsoredUser()) {
        call.hideSponsored(true);
        call.hideService(true);
    }
    if (!user.isSpecificUser()) {
        call.hidePerson(true);
    }
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            // close tab and refresh
            session.getTabManager().closeTab(tab, true);
        }
    }));
    // search textbox
    ExtendedTextBox searchBox = menu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            call.searchFor(text);
        }
    }, "");
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            ArrayList<User> list = call.getTableSelectedList();
            for (int i = 0; i < list.size(); i++) {
                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                AddSpecificUserOwner req;
                if (i == list.size() - 1) {
                    req = new AddSpecificUserOwner(JsonCallbackEvents.closeTabDisableButtonEvents(addButton, tab));
                } else {
                    req = new AddSpecificUserOwner(JsonCallbackEvents.disableButtonEvents(addButton));
                }
                if (user.isServiceUser() || user.isSponsoredUser()) {
                    // service user adds user
                    req.addSpecificUser(list.get(i), user);
                } else {
                    // user adds service users
                    req.addSpecificUser(user, list.get(i));
                }
            }
        }
    });
    FieldUpdater<User, String> fieldUpdater = null;
    if (session.isPerunAdmin()) {
        fieldUpdater = new FieldUpdater<User, String>() {

            public void update(int i, User user, String s) {
                session.getTabManager().addTab(new UserDetailTabItem(user));
            }
        };
    }
    CellTable<User> table = call.getTable(fieldUpdater);
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(call, table, addButton);
    content.add(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(new SimplePanel(content));
    return getWidget();
}
Also used : User(cz.metacentrum.perun.webgui.model.User) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FindCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers) ArrayList(java.util.ArrayList) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) AddSpecificUserOwner(cz.metacentrum.perun.webgui.json.usersManager.AddSpecificUserOwner) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 74 with CustomButton

use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.

the class InviteUserTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    final FlexTable ft = new FlexTable();
    ft.setWidth("350px");
    ft.setStyleName("inputFormFlexTable");
    if (groupId == 0) {
        ft.setHTML(0, 0, "Person you are inviting will receive an email with link to VOs application form. You can set up an email template in: Vo manager (advanced) -> Application form -> Notifications.");
    } else {
        ft.setHTML(0, 0, "Person you are inviting will receive an email with link to groups application form. You can set up an email template in: Group manager (advanced) -> Application form -> Notifications.");
    }
    ft.getFlexCellFormatter().setColSpan(0, 0, 2);
    ft.getFlexCellFormatter().addStyleName(0, 0, "inputFormInlineComment");
    ft.setHTML(1, 0, "Name:");
    ft.setHTML(2, 0, "Email:");
    ft.setHTML(3, 0, "Language:");
    ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
    ft.getFlexCellFormatter().setStyleName(2, 0, "itemName");
    ft.getFlexCellFormatter().setStyleName(3, 0, "itemName");
    final ListBox languages = new ListBox();
    languages.setWidth("200px");
    //languages.addItem("Czech", "cs");
    languages.addItem("English", "en");
    languages.setSelectedIndex(1);
    if (!Utils.getNativeLanguage().isEmpty()) {
        languages.addItem(Utils.getNativeLanguage().get(2), Utils.getNativeLanguage().get(0));
    }
    final ExtendedTextBox name = new ExtendedTextBox();
    final ExtendedTextBox email = new ExtendedTextBox();
    final ExtendedTextBox.TextBoxValidator nameValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (name.getTextBox().getText().trim().isEmpty()) {
                name.setError("Name can't be empty.");
                return false;
            } else {
                name.setOk();
                return true;
            }
        }
    };
    final ExtendedTextBox.TextBoxValidator emailValidator = new ExtendedTextBox.TextBoxValidator() {

        @Override
        public boolean validateTextBox() {
            if (email.getTextBox().getText().trim().isEmpty()) {
                email.setError("Email can't be empty.");
                return false;
            } else if (!JsonUtils.isValidEmail(email.getTextBox().getText().trim())) {
                email.setError("Not valid email address format.");
                return false;
            } else {
                email.setOk();
                return true;
            }
        }
    };
    // Name is now optional
    // name.setValidator(nameValidator);
    email.setValidator(emailValidator);
    ft.setWidget(1, 1, name);
    ft.setWidget(2, 1, email);
    ft.setWidget(3, 1, languages);
    vp.add(ft);
    final TabItem tab = this;
    final CustomButton sendInvitationButton = new CustomButton("Send invitation", SmallIcons.INSTANCE.emailIcon());
    sendInvitationButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            //if (!nameValidator.validateTextBox() || !emailValidator.validateTextBox()) return;
            if (!emailValidator.validateTextBox())
                return;
            SendInvitation invite = new SendInvitation(vo.getId(), groupId, JsonCallbackEvents.closeTabDisableButtonEvents(sendInvitationButton, tab));
            invite.inviteUser(email.getTextBox().getText().trim(), name.getTextBox().getText().trim(), languages.getValue(languages.getSelectedIndex()));
        }
    });
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    menu.addWidget(sendInvitationButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    contentWidget.setWidget(vp);
    return getWidget();
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SendInvitation(cz.metacentrum.perun.webgui.json.registrarManager.SendInvitation)

Example 75 with CustomButton

use of cz.metacentrum.perun.webgui.widgets.CustomButton in project perun by CESNET.

the class UserDetailTabItem method loadServiceIdentities.

public VerticalPanel loadServiceIdentities() {
    // Content
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    if (user.isServiceUser()) {
        // SERVICE TYPE user
        // request
        final GetUsersBySpecificUser request = new GetUsersBySpecificUser(userId);
        // menu
        TabMenu menu = new TabMenu();
        vp.add(menu);
        vp.setCellHeight(menu, "30px");
        // buttons
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add new user to service identity: " + user.getLastName(), new ClickHandler() {

            public void onClick(ClickEvent clickEvent) {
                session.getTabManager().addTabToCurrentTab(new ConnectServiceIdentityTabItem(user), true);
            }
        }));
        final CustomButton removeUserButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove user from service identity " + user.getLastName());
        menu.addWidget(removeUserButton);
        removeUserButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent clickEvent) {
                final ArrayList<User> list = request.getTableSelectedList();
                final ArrayList<User> fullList = request.getList();
                if (fullList.size() == list.size()) {
                    UiElements.generateAlert("Remove warning", "<strong><span class=\"serverResponseLabelError\">If you remove all users from service identity you won't be able to use it in the future.</br></br>Please consider keeping at least one user, e.g. add someone else before you remove yourself.</span></strong><p><strong>Do you wish to continue anyway ?</strong>", new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            UiElements.showDeleteConfirm(list, "Following users will be removed from service identity and they will lose all access to it. Only users associated with service identity can add other users again. If you remove all users connected to the service identity, you won't be able to use it in future!", new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent event) {
                                    for (int i = 0; i < list.size(); i++) {
                                        // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                                        RemoveSpecificUserOwner req;
                                        if (i == list.size() - 1) {
                                            req = new RemoveSpecificUserOwner(JsonCallbackEvents.disableButtonEvents(removeUserButton, JsonCallbackEvents.refreshTableEvents(request)));
                                        } else {
                                            req = new RemoveSpecificUserOwner(JsonCallbackEvents.disableButtonEvents(removeUserButton));
                                        }
                                        req.removeServiceUser(list.get(i), user);
                                    // TODO - consider fixing authz in session ?
                                    }
                                }
                            });
                        }
                    });
                } else {
                    // if not selected myself, continue same way
                    UiElements.showDeleteConfirm(list, "Following users will be removed from service identity and they will lose any access to it. Only users associated with service identity can add other users again. If you remove all users connected to the service identity, it will be deleted too!", new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            for (int i = 0; i < list.size(); i++) {
                                // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                                RemoveSpecificUserOwner req;
                                if (i == list.size() - 1) {
                                    req = new RemoveSpecificUserOwner(JsonCallbackEvents.disableButtonEvents(removeUserButton, JsonCallbackEvents.refreshTableEvents(request)));
                                } else {
                                    req = new RemoveSpecificUserOwner(JsonCallbackEvents.disableButtonEvents(removeUserButton));
                                }
                                req.removeServiceUser(list.get(i), user);
                            // TODO - consider fixing authz in session ?
                            }
                        }
                    });
                }
            }
        });
        // table
        CellTable<User> table = request.getTable(new FieldUpdater<User, String>() {

            public void update(int i, User user, String s) {
                session.getTabManager().addTab(new UserDetailTabItem(user));
            }
        });
        removeUserButton.setEnabled(false);
        JsonUtils.addTableManagedButton(request, table, removeUserButton);
        table.addStyleName("perun-table");
        table.setWidth("100%");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        vp.add(sp);
    } else {
        // PERSON TYPE user
        // request
        final GetSpecificUsersByUser request = new GetSpecificUsersByUser(userId);
        request.setHideSponsored(true);
        // menu
        TabMenu menu = new TabMenu();
        vp.add(menu);
        vp.setCellHeight(menu, "30px");
        // buttons
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add new service identity to " + user.getFullName(), new ClickHandler() {

            public void onClick(ClickEvent clickEvent) {
                session.getTabManager().addTabToCurrentTab(new ConnectServiceIdentityTabItem(user), true);
            }
        }));
        final CustomButton removeUserButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove service identity from " + user.getFullName());
        menu.addWidget(removeUserButton);
        removeUserButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                final ArrayList<User> list = request.getTableSelectedList();
                UiElements.showDeleteConfirm(list, "Following service identities will be removed from user.", new ClickHandler() {

                    @Override
                    public void onClick(ClickEvent event) {
                        // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                        for (int i = 0; i < list.size(); i++) {
                            RemoveSpecificUserOwner req;
                            // if last, refresh
                            if (i == list.size() - 1) {
                                req = new RemoveSpecificUserOwner(JsonCallbackEvents.refreshTableEvents(request));
                            } else {
                                req = new RemoveSpecificUserOwner();
                            }
                            req.removeServiceUser(user, list.get(i));
                        }
                    }
                });
            }
        });
        // table
        CellTable<User> table = request.getTable(new FieldUpdater<User, String>() {

            public void update(int i, User user, String s) {
                session.getTabManager().addTab(new UserDetailTabItem(user));
            }
        });
        removeUserButton.setEnabled(false);
        JsonUtils.addTableManagedButton(request, table, removeUserButton);
        table.addStyleName("perun-table");
        table.setWidth("100%");
        ScrollPanel sp = new ScrollPanel(table);
        sp.addStyleName("perun-tableScrollPanel");
        vp.add(sp);
    }
    return vp;
}
Also used : GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Aggregations

CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)174 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)161 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)161 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)132 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)115 ArrayList (java.util.ArrayList)113 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)98 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)71 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)38 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)32 PerunError (cz.metacentrum.perun.webgui.model.PerunError)30 HashMap (java.util.HashMap)29 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)21 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)20 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)20 Map (java.util.Map)20 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)19 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)19 Group (cz.metacentrum.perun.webgui.model.Group)17 User (cz.metacentrum.perun.webgui.model.User)17