Search in sources :

Example 1 with GetMemberGroups

use of cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups 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>" + SafeHtmlUtils.fromString((listbox.getSelectedObject().getName() != null) ? listbox.getSelectedObject().getName() : "").asString() + "</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("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) {
                    PerunWebSession.getInstance().getTabManager().addTabToCurrentTab(new ChangeStatusTabItem(member, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            loadMemberSubContent(subContent, voLabel, listbox);
                        }
                    }));
                }
            });
            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) ChangeStatusTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.ChangeStatusTabItem) 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 2 with GetMemberGroups

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

the class ApplicationFormGui method isUserMemberOfVo.

private void isUserMemberOfVo() {
    // CHECK USER IF PRESENT
    if (session.getUser() != null) {
        GetMemberByUser req = new GetMemberByUser(vo.getId(), session.getUser().getId(), new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                Member member = jso.cast();
                if (member.getVoId() == vo.getId()) {
                    // USER IS MEMBER OF VO
                    if (groupName != null && !groupName.isEmpty()) {
                        GetMemberGroups call = new GetMemberGroups(member.getId(), new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                ArrayList<Group> groups = JsonUtils.jsoAsList(jso);
                                for (Group g : groups) {
                                    if (g.getId() == group.getId()) {
                                        // USER IS MEMBER OF GROUP
                                        prepareGui(PerunEntity.GROUP, "EXTENSION");
                                        return;
                                    }
                                }
                                // USER IS NOT MEMBER OF GROUP
                                prepareGui(PerunEntity.GROUP, "INITIAL");
                            }

                            @Override
                            public void onError(PerunError error) {
                                RootLayoutPanel panel = RootLayoutPanel.get();
                                panel.clear();
                                panel.add(getErrorWidget(error));
                            }
                        });
                        call.retrieveData();
                    } else {
                        // only VO application
                        prepareGui(PerunEntity.VIRTUAL_ORGANIZATION, "EXTENSION");
                    }
                } else {
                // TODO display error ? - retrieved member is not member of VO ??
                }
            }

            public void onError(PerunError error) {
                // not member of VO - load initial
                if (error.getName().equalsIgnoreCase("MemberNotExistsException")) {
                    if (groupName != null && !groupName.isEmpty()) {
                        // load application to group for NOT vo members
                        prepareGui(PerunEntity.GROUP, "INITIAL");
                    // Do NOT display application to Group if not member of VO
                    //RootLayoutPanel panel = RootLayoutPanel.get();
                    //panel.clear();
                    //panel.add(getCustomErrorWidget(error, ApplicationMessages.INSTANCE.mustBeVoMemberFirst()));
                    } else {
                        prepareGui(PerunEntity.VIRTUAL_ORGANIZATION, "INITIAL");
                    }
                } else {
                    RootLayoutPanel panel = RootLayoutPanel.get();
                    panel.clear();
                    panel.add(getErrorWidget(error));
                }
            }
        });
        req.setHidden(true);
        req.retrieveData();
        return;
    }
    // UNKNOWN USER - LOAD INITIAL
    if (groupName != null && !groupName.isEmpty()) {
        prepareGui(PerunEntity.GROUP, "INITIAL");
    } else {
        prepareGui(PerunEntity.VIRTUAL_ORGANIZATION, "INITIAL");
    }
    return;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) GetMemberGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups)

Example 3 with GetMemberGroups

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

the class SelfVosTabItem method displayVoSubtab.

/**
 * Internal method which renders subtab for each (selected) VO
 *
 * @param vo VO to render preferences for
 * @return subtab widget
 */
private Widget displayVoSubtab(final VirtualOrganization vo) {
    // do the layout
    HorizontalPanel horizontalSplitter = new HorizontalPanel();
    horizontalSplitter.setSize("100%", "100%");
    final VerticalPanel leftPanel = new VerticalPanel();
    final VerticalPanel rightPanel = new VerticalPanel();
    horizontalSplitter.add(leftPanel);
    horizontalSplitter.add(rightPanel);
    horizontalSplitter.setCellWidth(leftPanel, "50%");
    horizontalSplitter.setCellWidth(rightPanel, "50%");
    // VO overview
    FlexTable voHeader = new FlexTable();
    voHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.buildingIcon()));
    voHeader.setHTML(0, 1, "<p class=\"subsection-heading\">" + SafeHtmlUtils.fromString((vo.getName() != null) ? vo.getName() : "").asString() + "</p>");
    final FlexTable voOverview = new FlexTable();
    voOverview.setStyleName("inputFormFlexTableDark");
    leftPanel.add(voHeader);
    leftPanel.add(voOverview);
    GetAttributes voAttrsCall = new GetAttributes(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
            int i = 0;
            for (Attribute a : attrs) {
                if (a.getFriendlyName().equalsIgnoreCase("userManualsLink")) {
                    voOverview.setHTML(i, 0, "User's manuals:");
                    String val = SafeHtmlUtils.fromString((a.getValue() != null) ? a.getValue() : "").asString();
                    Anchor link = new Anchor(val, val);
                    link.getElement().setPropertyString("target", "_blank");
                    voOverview.setWidget(i, 1, link);
                    i++;
                } else if (a.getFriendlyName().equalsIgnoreCase("dashboardLink")) {
                    voOverview.setHTML(i, 0, "Dashboard:");
                    String val = SafeHtmlUtils.fromString((a.getValue() != null) ? a.getValue() : "").asString();
                    Anchor link = new Anchor(val, val);
                    link.getElement().setPropertyString("target", "_blank");
                    voOverview.setWidget(i, 1, link);
                    i++;
                } else if (a.getFriendlyName().equalsIgnoreCase("contactEmail")) {
                    voOverview.setHTML(i, 0, "VO contact:");
                    voOverview.setHTML(i, 1, SafeHtmlUtils.fromString((a.getValue() != null) ? a.getValue() : "").asString());
                    i++;
                }
            }
            // no rows in selected result
            if (i < 1) {
                voOverview.setHTML(i, 0, "VO doesn't provide any details or contacts about itself.");
                voOverview.getFlexCellFormatter().setStyleName(i, 0, "inputFormInlineComment");
            } else {
                for (int n = 0; n < voOverview.getRowCount(); n++) {
                    voOverview.getFlexCellFormatter().setStyleName(n, 0, "itemName");
                    voOverview.getFlexCellFormatter().setWidth(n, 0, "200px");
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            voOverview.setHTML(0, 0, "Error while loading");
        }

        @Override
        public void onLoadingStart() {
            voOverview.setWidget(0, 0, new AjaxLoaderImage());
        }
    });
    voAttrsCall.getVoAttributes(vo.getId());
    voAttrsCall.retrieveData();
    // CONTACT INFO
    FlexTable contactHeader = new FlexTable();
    contactHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.vcardIcon()));
    contactHeader.setHTML(0, 1, "<p class=\"subsection-heading\">Contact</p>");
    final PerunAttributeTableWidget contactTable = new PerunAttributeTableWidget();
    contactTable.setDark(true);
    contactTable.setDisplaySaveButton(false);
    leftPanel.add(contactHeader);
    final GetListOfAttributes attributes = new GetListOfAttributes(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            contactTable.add(new TableSorter<Attribute>().sortByAttrNameTranslation(JsonUtils.<Attribute>jsoAsList(jso)));
            leftPanel.add(contactTable.getSaveButton());
            leftPanel.setCellHeight(contactTable.getSaveButton(), "50px");
            leftPanel.add(contactTable);
        }
    });
    final ArrayList<String> list = new ArrayList<String>();
    list.add("urn:perun:member:attribute-def:def:organization");
    list.add("urn:perun:member:attribute-def:def:workplace");
    list.add("urn:perun:member:attribute-def:opt:researchGroup");
    list.add("urn:perun:member:attribute-def:def:mail");
    list.add("urn:perun:member:attribute-def:def:phone");
    list.add("urn:perun:member:attribute-def:def:address");
    GetMemberByUser mem = new GetMemberByUser(vo.getId(), userId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            Member m = jso.cast();
            HashMap<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("member", m.getId());
            contactTable.setIds(ids);
            attributes.getListOfAttributes(ids, list);
        }
    });
    mem.retrieveData();
    // MEMBERSHIP STATE
    FlexTable membershipHeader = new FlexTable();
    membershipHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.userGreenIcon()));
    membershipHeader.setHTML(0, 1, "<p class=\"subsection-heading\">Membership</p>");
    // Membership table
    final FlexTable memberLayout = new FlexTable();
    memberLayout.setStyleName("inputFormFlexTableDark");
    rightPanel.add(membershipHeader);
    rightPanel.add(memberLayout);
    GetMemberByUser call = new GetMemberByUser(vo.getId(), userId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            final Member m = jso.cast();
            memberLayout.setHTML(0, 0, "Status:");
            memberLayout.setHTML(1, 0, "Expiration:");
            memberLayout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
            memberLayout.getFlexCellFormatter().setStyleName(1, 0, "itemName");
            // fill inner layout
            PerunStatusWidget<Member> statusWidget;
            if (session.isVoAdmin(vo.getId())) {
                JsonCallbackEvents event = new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        // REFRESH PARENT TAB
                        draw();
                    }
                };
                statusWidget = new PerunStatusWidget<Member>(m, user.getFullName(), event);
            } else {
                statusWidget = new PerunStatusWidget<Member>(m, user.getFullName(), null);
            }
            memberLayout.setWidget(0, 1, statusWidget);
            HashMap<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("member", m.getId());
            GetListOfAttributes attrCall = new GetListOfAttributes(new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    ArrayList<Attribute> la = JsonUtils.jsoAsList(jso);
                    if (la != null && !la.isEmpty()) {
                        for (Attribute a : la) {
                            if ("urn:perun:member:attribute-def:def:membershipExpiration".equals(a.getName())) {
                                RichMember rm = m.cast();
                                // store value into richmember
                                rm.setAttribute(a);
                                memberLayout.setWidget(1, 1, new MembershipExpirationWidget(rm));
                            }
                        }
                    }
                }
            });
            ArrayList<String> ls = new ArrayList<String>();
            ls.add("urn:perun:member:attribute-def:def:membershipExpiration");
            attrCall.getListOfAttributes(ids, ls);
        }

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

        @Override
        public void onError(PerunError error) {
            memberLayout.setWidget(0, 0, new AjaxLoaderImage().loadingError(error));
        }
    });
    call.retrieveData();
    // RESOURCES SETTINGS
    FlexTable resourcesSettingsHeader = new FlexTable();
    resourcesSettingsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.settingToolsIcon()));
    resourcesSettingsHeader.setHTML(0, 1, "<p class=\"subsection-heading\">Resources settings</p>");
    FlexTable resourcesSettingsTable = new FlexTable();
    resourcesSettingsTable.setStyleName("inputFormFlexTable");
    Anchor a = new Anchor();
    a.setText("Go to Resources settings page >>");
    a.setStyleName("pointer");
    a.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (tabPanel != null) {
                // resource settings tab is next to this one
                SelfResourcesSettingsTabItem tab = ((SelfResourcesSettingsTabItem) tabPanel.getTabItem(tabPanel.getSelectedIndex() + 1));
                tab.setVo(vo);
                tab.draw();
                tabPanel.selectTab(tabPanel.getSelectedIndex() + 1);
            } else {
                session.getTabManager().addTab(new SelfResourcesSettingsTabItem(user, vo), true);
            }
        }
    });
    resourcesSettingsTable.setHTML(0, 0, "Manage VO resources specific settings like: shell, data/files quotas, mailing list exclusions");
    resourcesSettingsTable.getFlexCellFormatter().setStyleName(0, 0, "inputFormInlineComment");
    resourcesSettingsTable.setWidget(1, 0, a);
    rightPanel.add(resourcesSettingsHeader);
    rightPanel.add(resourcesSettingsTable);
    // GROUPS
    FlexTable groupsHeader = new FlexTable();
    groupsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.groupIcon()));
    groupsHeader.setHTML(0, 1, "<p class=\"subsection-heading\">Groups</p>");
    final FlexTable groupsTable = new FlexTable();
    groupsTable.setStyleName("inputFormFlexTable");
    rightPanel.add(groupsHeader);
    rightPanel.add(groupsTable);
    GetMemberByUser memCall = new GetMemberByUser(vo.getId(), userId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            Member m = jso.cast();
            GetMemberGroups groupsCall = new GetMemberGroups(m.getId(), new JsonCallbackEvents() {

                @Override
                public void onError(PerunError error) {
                    groupsTable.setWidget(0, 0, new AjaxLoaderImage().loadingError(error));
                }

                @Override
                public void onFinished(JavaScriptObject jso) {
                    ArrayList<Group> list = JsonUtils.jsoAsList(jso);
                    if (list.isEmpty() || list == null) {
                        groupsTable.setHTML(0, 0, "You aren't member of any group in this VO.");
                        return;
                    }
                    groupsTable.addStyleName("userDetailTable");
                    groupsTable.setHTML(0, 0, "<strong>Name</strong>");
                    groupsTable.setHTML(0, 1, "<strong>Description</strong>");
                    for (int i = 0; i < list.size(); i++) {
                        groupsTable.setHTML(i + 1, 0, SafeHtmlUtils.fromString(list.get(i).getName()).asString());
                        groupsTable.setHTML(i + 1, 1, SafeHtmlUtils.fromString(list.get(i).getDescription()).asString());
                    }
                }
            });
            groupsCall.retrieveData();
        }

        @Override
        public void onError(PerunError error) {
            groupsTable.setWidget(0, 0, new AjaxLoaderImage().loadingError(error));
        }

        @Override
        public void onLoadingStart() {
            groupsTable.setWidget(0, 0, new AjaxLoaderImage().loadingStart());
        }
    });
    memCall.retrieveData();
    return horizontalSplitter;
}
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) GetVosWhereUserIsMember(cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember) GetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) GetMemberGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups)

Example 4 with GetMemberGroups

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

the class MemberGroupsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(member.getUser().getFullNameWithTitles().trim()) + ": groups");
    // main widget panel
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    final GetMemberGroups groupsCall = new GetMemberGroups(memberId);
    menu.addWidget(UiElements.getRefreshButton(this));
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, "Add member to new group", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().addTabToCurrentTab(new MemberAddToGroupTabItem(member), true);
        }
    });
    if (session.isVoObserver(member.getVoId()) && !session.isVoAdmin(member.getVoId())) {
        addButton.setEnabled(false);
        groupsCall.setCheckable(false);
    }
    menu.addWidget(addButton);
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove member from selected group(s)");
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            final ArrayList<Group> list = groupsCall.getTableSelectedList();
            String confirmText = member.getUser().getFullName() + " will be removed from following groups.";
            UiElements.showDeleteConfirm(list, confirmText, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    RemoveMember request = new RemoveMember(JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(groupsCall)));
                    request.removeMemberFromGroups(member, list);
                }
            });
        }
    });
    removeButton.setEnabled(false);
    menu.addWidget(removeButton);
    menu.addFilterWidget(new ExtendedSuggestBox(groupsCall.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            groupsCall.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterGroup());
    CellTable<Group> table = groupsCall.getTable(new FieldUpdater<Group, String>() {

        @Override
        public void update(int i, Group group, String s) {
            if (session.isVoAdmin(group.getVoId()) || session.isVoObserver(group.getVoId()) || session.isGroupAdmin(group.getId())) {
                session.getTabManager().addTab(new GroupDetailTabItem(group));
            } else {
                UiElements.generateInfo("Not privileged", "You are not manager of selected group or it's VO.");
            }
        }
    });
    if (session.isVoAdmin(member.getVoId()) || session.isGroupAdmin(groupId))
        JsonUtils.addTableManagedButton(groupsCall, table, removeButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    vp.add(sp);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : Group(cz.metacentrum.perun.webgui.model.Group) RemoveMember(cz.metacentrum.perun.webgui.json.groupsManager.RemoveMember) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) GetMemberGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups)

Aggregations

GetMemberGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 GetMemberByUser (cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser)3 ArrayList (java.util.ArrayList)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 HashMap (java.util.HashMap)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 GetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes)1 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)1 GetListOfAttributes (cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes)1 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)1 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)1 RemoveMember (cz.metacentrum.perun.webgui.json.groupsManager.RemoveMember)1 GetAssignedResources (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources)1