Search in sources :

Example 36 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 37 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)

Example 38 with CustomButton

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

the class UserDetailTabItem method loadExternalIdentities.

private Widget loadExternalIdentities() {
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    final GetUserExtSources extSources = new GetUserExtSources(user.getId());
    // reload tab events
    final TabItem tab = this;
    final JsonCallbackEvents reloadTabEvents = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            session.getTabManager().reloadTab(tab);
        }
    };
    // buttons
    CustomButton addUserExtSourceButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add new external identity to user", new ClickHandler() {

        public void onClick(ClickEvent event) {
            // when user click on add ext source btn
            session.getTabManager().addTabToCurrentTab(new AddUserExtSourceTabItem(user.getId()));
        }
    });
    final CustomButton removeUserExtSourceButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Removes selected external identities from this user");
    removeUserExtSourceButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<UserExtSource> list = extSources.getTableSelectedList();
            UiElements.showDeleteConfirm(list, "Following external identities will be removed from user.", new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    for (int i = 0; i < list.size(); i++) {
                        // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                        if (i == list.size() - 1) {
                            RemoveUserExtSource request = new RemoveUserExtSource(JsonCallbackEvents.disableButtonEvents(removeUserExtSourceButton, reloadTabEvents));
                            request.removeUserExtSource(user.getId(), list.get(i).getId());
                        } else {
                            RemoveUserExtSource request = new RemoveUserExtSource(JsonCallbackEvents.disableButtonEvents(removeUserExtSourceButton));
                            request.removeUserExtSource(user.getId(), list.get(i).getId());
                        }
                    }
                }
            });
        }
    });
    menu.addWidget(addUserExtSourceButton);
    menu.addWidget(removeUserExtSourceButton);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<UserExtSource> table = extSources.getTable(new FieldUpdater<UserExtSource, String>() {

        @Override
        public void update(int index, UserExtSource object, String value) {
            session.getTabManager().addTab(new UserExtSourceDetailTabItem(object));
        }
    });
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    session.getUiElements().resizeSmallTabPanel(sp, 320, this);
    removeUserExtSourceButton.setEnabled(false);
    JsonUtils.addTableManagedButton(extSources, table, removeUserExtSourceButton);
    return vp;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) UsersPublicationsTabItem(cz.metacentrum.perun.webgui.tabs.cabinettabs.UsersPublicationsTabItem) ResourceDetailTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) FacilityDetailTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 39 with CustomButton

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

the class UserDetailTabItem method loadMemberSubContent.

private void loadMemberSubContent(final SimplePanel subContent, final Hyperlink voLabel, final ListBoxWithObjects<VirtualOrganization> listbox) {
    subContent.setWidget(new AjaxLoaderImage());
    final GetMemberByUser gmbu = new GetMemberByUser(listbox.getSelectedObject().getId(), user.getId());
    JsonCallbackEvents loadEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // get member
            final Member member = jso.cast();
            // create content panel and put it on page
            final VerticalPanel entryPanel = new VerticalPanel();
            entryPanel.setStyleName("perun-table");
            entryPanel.setSize("100%", "100%");
            subContent.setWidget(entryPanel);
            voLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + listbox.getSelectedObject().getName() + "</h2>"));
            voLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new VoDetailTabItem(listbox.getSelectedObject())));
            // detail header
            Widget memberHeader = new HTML("<h2>" + "Member details" + "</h2>");
            entryPanel.add(memberHeader);
            entryPanel.setCellHeight(memberHeader, "30px");
            // detail content
            FlexTable layout = new FlexTable();
            layout.setCellSpacing(6);
            // Add some standard form options
            layout.setHTML(0, 0, "<strong>Member&nbsp;ID:</strong>");
            layout.setHTML(0, 1, String.valueOf(member.getId()));
            ImageResource ir = null;
            // member status
            if (member.getStatus().equalsIgnoreCase("VALID")) {
                ir = SmallIcons.INSTANCE.acceptIcon();
            } else if (member.getStatus().equalsIgnoreCase("INVALID")) {
                ir = SmallIcons.INSTANCE.flagRedIcon();
            } else if (member.getStatus().equalsIgnoreCase("SUSPENDED")) {
                ir = SmallIcons.INSTANCE.stopIcon();
            } else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
                ir = SmallIcons.INSTANCE.flagYellowIcon();
            } else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
                ir = SmallIcons.INSTANCE.binClosedIcon();
            }
            HTML status = new HTML("<a>" + member.getStatus() + " " + new Image(ir) + "</a>");
            layout.setHTML(1, 0, "<strong>Member status: </strong>");
            layout.setWidget(1, 1, status);
            // member status - on click action
            status.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    FlexTable widget = new FlexTable();
                    final ListBox lb = new ListBox(false);
                    lb.addItem("VALID", "VALID");
                    lb.addItem("INVALID", "INVALID");
                    lb.addItem("SUSPENDED", "SUSPENDED");
                    lb.addItem("EXPIRED", "EXPIRED");
                    lb.addItem("DISABLED", "DISABLED");
                    widget.setHTML(0, 0, "<strong>Status: </strong>");
                    widget.setWidget(0, 1, lb);
                    // pick which one is already set
                    for (int i = 0; i < lb.getItemCount(); i++) {
                        if (lb.getItemText(i).equalsIgnoreCase(member.getStatus())) {
                            lb.setSelectedIndex(i);
                        }
                    }
                    Confirm conf = new Confirm("Change member's status", widget, true);
                    conf.setCancelButtonText("Cancel");
                    conf.setOkButtonText("Change status");
                    conf.setOkClickHandler(new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            SetStatus call = new SetStatus(member.getId(), new JsonCallbackEvents() {

                                @Override
                                public void onLoadingStart() {
                                    subContent.setWidget(new AjaxLoaderImage());
                                }

                                public void onFinished(JavaScriptObject jso) {
                                    subContent.setWidget(entryPanel);
                                    gmbu.retrieveData();
                                }

                                public void onError(PerunError error) {
                                    subContent.setWidget(entryPanel);
                                    gmbu.retrieveData();
                                }
                            });
                            call.setStatus(lb.getValue(lb.getSelectedIndex()));
                        }
                    });
                    conf.show();
                }
            });
            final ListBoxWithObjects<Resource> resList = new ListBoxWithObjects<Resource>();
            GetAssignedResources res = new GetAssignedResources(member.getId(), PerunEntity.MEMBER, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    resList.clear();
                    ArrayList<Resource> list = JsonUtils.jsoAsList(jso);
                    if (list == null || list.isEmpty()) {
                        resList.addItem("No resources found");
                    } else {
                        list = new TableSorter<Resource>().sortByName(list);
                        resList.addNotSelectedOption();
                        resList.addAllItems(list);
                    }
                }

                @Override
                public void onError(PerunError error) {
                    resList.clear();
                    resList.addItem("Error while loading");
                }

                @Override
                public void onLoadingStart() {
                    resList.clear();
                    resList.addItem("Loading...");
                }
            });
            res.retrieveData();
            // link to member's detail
            Hyperlink link = new Hyperlink();
            link.setText("View detail");
            layout.setHTML(2, 0, "<strong>Member's detail page:</strong>");
            layout.setWidget(2, 1, link);
            link.setTargetHistoryToken(session.getTabManager().getLinkForTab(new MemberDetailTabItem(member.getId(), 0)));
            // wrap the content in a DecoratorPanel
            DecoratorPanel decPanel = new DecoratorPanel();
            decPanel.setWidget(layout);
            entryPanel.add(decPanel);
            entryPanel.setCellHeight(decPanel, "50px");
            // tables
            // detail header
            Widget groupHeader = new HTML("<h2>" + "Member groups" + "</h2>");
            entryPanel.add(groupHeader);
            entryPanel.setCellHeight(groupHeader, "30px");
            final GetMemberGroups groups = new GetMemberGroups(member.getId());
            groups.setCheckable(false);
            groups.setEditable(false);
            CellTable<Group> table = groups.getTable();
            table.addStyleName("perun-table");
            table.setWidth("100%");
            entryPanel.add(table);
            // detail header
            Widget attrHeader = new HTML("<h2>" + "Member / Member-resource attributes" + "</h2>");
            entryPanel.add(attrHeader);
            entryPanel.setCellHeight(attrHeader, "30px");
            final GetAttributesV2 attributes = new GetAttributesV2();
            attributes.getMemberAttributes(member.getId());
            resList.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(ChangeEvent event) {
                    if (resList.getSelectedIndex() == 0) {
                        attributes.getMemberAttributes(member.getId());
                        attributes.retrieveData();
                    } else {
                        attributes.getMemberResourceAttributes(member.getId(), resList.getSelectedObject().getId());
                        attributes.retrieveData();
                    }
                }
            });
            TabMenu menu = new TabMenu();
            final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for member");
            saveAttrButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    ArrayList<Attribute> list = attributes.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        Map<String, Integer> ids = new HashMap<String, Integer>();
                        ids.put("member", member.getId());
                        if (resList.getSelectedIndex() > 0) {
                            ids.put("resource", resList.getSelectedObject().getId());
                        }
                        SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
                        request.setAttributes(ids, list);
                    }
                }
            });
            menu.addWidget(saveAttrButton);
            menu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, true, "Set new attributes for member", new ClickHandler() {

                public void onClick(ClickEvent event) {
                    Map<String, Integer> ids = new HashMap<String, Integer>();
                    ids.put("member", member.getId());
                    if (resList.getSelectedIndex() > 0) {
                        ids.put("resource", resList.getSelectedObject().getId());
                    }
                    session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
                }
            }));
            final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes from member");
            removeAttrButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    ArrayList<Attribute> list = attributes.getTableSelectedList();
                    if (UiElements.cantSaveEmptyListDialogBox(list)) {
                        Map<String, Integer> ids = new HashMap<String, Integer>();
                        ids.put("member", member.getId());
                        if (resList.getSelectedIndex() > 0) {
                            ids.put("resource", resList.getSelectedObject().getId());
                        }
                        RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
                        request.removeAttributes(ids, list);
                    }
                }
            });
            menu.addWidget(removeAttrButton);
            menu.addWidget(new HTML("<strong>Resource:</strong>"));
            menu.addWidget(resList);
            entryPanel.add(menu);
            CellTable<Attribute> attrTable = attributes.getTable();
            attrTable.addStyleName("perun-table");
            attrTable.setWidth("100%");
            entryPanel.add(attrTable);
        }

        @Override
        public void onError(PerunError error) {
            subContent.setWidget(new AjaxLoaderImage().loadingError(error));
        }
    };
    // set events & load data
    gmbu.setEvents(loadEvent);
    gmbu.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) ImageResource(com.google.gwt.resources.client.ImageResource) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetStatus(cz.metacentrum.perun.webgui.json.membersManager.SetStatus) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ImageResource(com.google.gwt.resources.client.ImageResource) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) GetAssignedResources(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources) HashMap(java.util.HashMap) Map(java.util.Map) GetMemberGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 40 with CustomButton

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

the class AddSecurityTeamManagerTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add member");
    final CustomButton searchButton = new CustomButton("Search", ButtonTranslation.INSTANCE.searchUsers(), SmallIcons.INSTANCE.findIcon());
    this.users = new FindCompleteRichUsers("", null, JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // if found 1 item, select
            ArrayList<User> list = JsonUtils.jsoAsList(jso);
            if (list != null && list.size() == 1) {
                users.getSelectionModel().setSelected(list.get(0), true);
            }
        }
    }));
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu tabMenu = new TabMenu();
    // get the table
    final CellTable<User> table;
    if (session.isPerunAdmin()) {
        table = users.getTable(new FieldUpdater<User, String>() {

            public void update(int i, User user, String s) {
                session.getTabManager().addTab(new UserDetailTabItem(user));
            }
        });
    } else {
        table = users.getTable();
    }
    rebuildAlreadyAddedWidget();
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedManagersToSecurityTeam());
    final TabItem tab = this;
    // search textbox
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            startSearching(text);
            searchString = text;
        }
    }, searchButton);
    tabMenu.addWidget(addButton);
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
        }
    }));
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<User> list = users.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                for (int i = 0; i < list.size(); i++) {
                    // FIXME - Should have only one callback to core
                    final int n = i;
                    AddAdmin request = new AddAdmin(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // put names to already added
                            alreadyAddedList.add(list.get(n));
                            rebuildAlreadyAddedWidget();
                            // unselect added person
                            users.getSelectionModel().setSelected(list.get(n), false);
                            // clear search
                            searchBox.getTextBox().setText("");
                        }
                    }));
                    request.addSecurityTeamAdmin(securityTeam, list.get(i));
                }
            }
        }
    });
    // if some text has been searched before
    if (!searchString.equals("")) {
        searchBox.getTextBox().setText(searchString);
        startSearching(searchString);
    }
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(users, table, addButton);
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    // add menu and the table to the main panel
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    firstTabPanel.add(alreadyAdded);
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) User(cz.metacentrum.perun.webgui.model.User) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FindCompleteRichUsers(cz.metacentrum.perun.webgui.json.usersManager.FindCompleteRichUsers) ArrayList(java.util.ArrayList) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) AddAdmin(cz.metacentrum.perun.webgui.json.authzResolver.AddAdmin) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) UserDetailTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.UserDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) 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