Search in sources :

Example 1 with MemberDetailTabItem

use of cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem in project perun by CESNET.

the class SearcherTabItem method loadMembersTab.

private Widget loadMembersTab() {
    // request
    final GetMembers request = new GetMembers(0);
    // MAIN TAB PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    PerunSearchParametersWidget params = new PerunSearchParametersWidget(PerunEntity.MEMBER, new PerunSearchParametersWidget.SearchEvent() {

        public void search(Map<String, String> map) {
            request.clearParameters();
            for (Map.Entry<String, String> entry : map.entrySet()) {
                request.addSearchParameter(entry.getKey(), entry.getValue());
            }
            request.search();
        }
    });
    final ListBoxWithObjects<VirtualOrganization> vos = new ListBoxWithObjects<VirtualOrganization>();
    vos.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            request.setVoId(vos.getSelectedObject().getId());
        }
    });
    // initial fill listbox and trigger groups loading
    GetVos vosCall = new GetVos(new JsonCallbackEvents() {

        public void onLoadingStart() {
            vos.clear();
            vos.addItem("Loading...");
        }

        public void onFinished(JavaScriptObject jso) {
            vos.clear();
            ArrayList<VirtualOrganization> returnedVos = JsonUtils.jsoAsList(jso);
            returnedVos = new TableSorter<VirtualOrganization>().sortByName(returnedVos);
            if (returnedVos == null || returnedVos.isEmpty()) {
                vos.addItem("No VO available");
                return;
            }
            vos.addAllItems(returnedVos);
            request.setVoId(vos.getSelectedObject().getId());
        }

        public void onError(PerunError error) {
            vos.clear();
            vos.addItem("Error while loading");
        }
    });
    vosCall.retrieveData();
    TabMenu menu = new TabMenu();
    menu.addWidget(new HTML("<strong>Selected VO:</strong>"));
    menu.addWidget(vos);
    firstTabPanel.add(menu);
    firstTabPanel.add(params);
    // get the table
    final CellTable<Member> table = request.getEmptyTable(new FieldUpdater<Member, String>() {

        public void update(int index, Member object, String value) {
            // opens the tab
            session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), object.getSourceGroupId()));
        }
    });
    // 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");
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    return firstTabPanel;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Member(cz.metacentrum.perun.webgui.model.Member) PerunSearchParametersWidget(cz.metacentrum.perun.webgui.widgets.PerunSearchParametersWidget) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) GetMembers(cz.metacentrum.perun.webgui.json.searcher.GetMembers) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 2 with MemberDetailTabItem

use of cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem 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 3 with MemberDetailTabItem

use of cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem in project perun by CESNET.

the class VoMembersTabItem method draw.

public Widget draw() {
    // SET TAB NAME
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": members");
    // MAIN PANEL
    final VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // MENU
    TabMenu tabMenu = new TabMenu();
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // DISABLED CHECKBOX
    final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
    disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
    disabled.setValue(wasDisabled);
    disabled.setVisible(false);
    // CALLBACKS
    final GetCompleteRichMembers members = new GetCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, null);
    final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, "", null);
    members.excludeDisabled(!wasDisabled);
    final CustomButton searchButton = TabMenu.getPredefinedButton(ButtonType.SEARCH, ButtonTranslation.INSTANCE.searchMemberInVo());
    final CustomButton listAllButton = TabMenu.getPredefinedButton(ButtonType.LIST_ALL_MEMBERS, ButtonTranslation.INSTANCE.listAllMembersInVo());
    if (!session.isVoAdmin(voId))
        findMembers.setCheckable(false);
    final CellTable<RichMember> table = findMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {

        // when user click on a row -> open new tab
        public void update(int index, RichMember object, RichMember value) {
            session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), 0));
        }
    });
    // refresh
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // ADD
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMemberToVo(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AddMemberToVoTabItem(voId), true);
        }
    });
    if (!session.isVoAdmin(voId))
        addButton.setEnabled(false);
    tabMenu.addWidget(addButton);
    // REMOVE
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMemberFromVo());
    if (!session.isVoAdmin(voId))
        removeButton.setEnabled(false);
    tabMenu.addWidget(removeButton);
    /*
		final CustomButton addServiceButton = new CustomButton(ButtonTranslation.INSTANCE.createServiceMemberButton(), ButtonTranslation.INSTANCE.createServiceMember(), SmallIcons.INSTANCE.addIcon(), new ClickHandler() {
			public void onClick(ClickEvent clickEvent) {
				session.getTabManager().addTabToCurrentTab(new CreateServiceMemberInVoTabItem(vo));
			}
		});
		if (!session.isVoAdmin(voId)) addServiceButton.setEnabled(false);
		tabMenu.addWidget(addServiceButton);
		*/
    // refreshMembers
    final JsonCallbackEvents refreshEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            if (search) {
                findMembers.searchFor(searchString);
            } else {
                findMembers.clearTable();
                members.retrieveData();
            }
        }
    };
    // add click handler for remove button
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // state specific events
            final ArrayList<RichMember> membersForRemoving = findMembers.getTableSelectedList();
            String text = "Following members will be removed from VO and their settings will be lost.<p>You can consider changing their status to \"DISABLED\", which will prevent them from accessing VO resources.";
            UiElements.showDeleteConfirm(membersForRemoving, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    DeleteMembers request = new DeleteMembers(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
                    request.deleteMembers(membersForRemoving);
                }
            });
        }
    });
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        public void searchFor(String text) {
            searchString = text;
            search = true;
            findMembers.searchFor(text);
        }
    }, searchButton);
    searchBox.getTextBox().setText(searchString);
    // checkbox click handler
    disabled.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            wasDisabled = disabled.getValue();
            if (search) {
                // case when update but not triggered by button
                searchString = searchBox.getTextBox().getText();
                members.excludeDisabled(!disabled.getValue());
            } else {
                members.excludeDisabled(!disabled.getValue());
                members.retrieveData();
            }
        }
    });
    findMembers.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(searchButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            searchBox.getTextBox().setEnabled(true);
            listAllButton.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            searchBox.getTextBox().setEnabled(true);
            listAllButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            searchBox.getTextBox().setEnabled(false);
            listAllButton.setEnabled(false);
            disabled.setVisible(false);
        }
    }));
    members.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(listAllButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // pass data to table handling callback
            findMembers.onFinished(jso);
            ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("VO has no members.");
            searchBox.getTextBox().setEnabled(true);
            searchButton.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            // pass data to table handling callback
            findMembers.onError(error);
            searchBox.getTextBox().setEnabled(true);
            searchButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            searchBox.getTextBox().setEnabled(false);
            searchButton.setEnabled(false);
            disabled.setVisible(true);
            // to show progress when reloading
            ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
        }
    }));
    // LIST ALL BUTTON
    listAllButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            search = false;
            searchString = "";
            searchBox.getTextBox().setText("");
            findMembers.clearTable();
            members.retrieveData();
        }
    });
    tabMenu.addWidget(listAllButton);
    tabMenu.addWidget(disabled);
    /* WHEN TAB RELOADS, CHECK THE STATE */
    if (search) {
        findMembers.searchFor(searchString);
    } else {
        members.excludeDisabled(!disabled.getValue());
        members.retrieveData();
    }
    ScrollPanel tableWrapper = new ScrollPanel();
    table.addStyleName("perun-table");
    tableWrapper.setWidget(table);
    tableWrapper.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(tableWrapper, 350, this);
    // add menu and the table to the main panel
    firstTabPanel.add(tableWrapper);
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findMembers, table, removeButton);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AddMemberToVoTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.AddMemberToVoTabItem) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) RichMember(cz.metacentrum.perun.webgui.model.RichMember) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) DeleteMembers(cz.metacentrum.perun.webgui.json.membersManager.DeleteMembers) PerunError(cz.metacentrum.perun.webgui.model.PerunError) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Example 4 with MemberDetailTabItem

use of cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem in project perun by CESNET.

the class GroupMembersTabItem method draw.

public Widget draw() {
    // SET TAB NAME
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": members");
    // MAIN PANEL
    final VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // MENU
    final TabMenu tabMenu = new TabMenu();
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // DISABLED CHECKBOX
    final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
    disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
    disabled.setValue(wasDisabled);
    // CALLBACKS
    final GetCompleteRichMembers members = new GetCompleteRichMembers(PerunEntity.GROUP, groupId, null);
    final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.GROUP, groupId, "", null);
    members.excludeDisabled(!wasDisabled);
    members.setIndirectCheckable(false);
    findMembers.setHideGroupStatusColumn("members".equals(group.getName()));
    findMembers.setIndirectCheckable(false);
    final CustomButton searchButton = TabMenu.getPredefinedButton(ButtonType.SEARCH, ButtonTranslation.INSTANCE.searchMemberInGroup());
    final CustomButton listAllButton = TabMenu.getPredefinedButton(ButtonType.LIST_ALL_MEMBERS, ButtonTranslation.INSTANCE.listAllMembersInGroup());
    if ((!session.isVoAdmin(group.getVoId()) && !session.isGroupAdmin(groupId)) || group.isCoreGroup()) {
        findMembers.setCheckable(false);
    }
    table = findMembers.getEmptyTable(new FieldUpdater<RichMember, RichMember>() {

        // when user click on a row -> open new tab
        public void update(int index, RichMember object, RichMember value) {
            session.getTabManager().addTab(new MemberDetailTabItem(object.getId(), groupId));
        }
    });
    tableWidget = table.getEmptyTableWidget();
    // refresh
    tabMenu.addWidget(UiElements.getRefreshButton(this));
    // ADD
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.addMemberToGroup(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new AddMemberToGroupTabItem(groupId), true);
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        addButton.setEnabled(false);
    CustomButton inviteButton = new CustomButton("Invite member…", SmallIcons.INSTANCE.emailAddIcon(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new InviteUserTabItem(group.getVoId(), group));
        }
    });
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        inviteButton.setEnabled(false);
    // REMOVE
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeMemberFromGroup());
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        removeButton.setEnabled(false);
    if (!group.isCoreGroup()) {
        tabMenu.addWidget(addButton);
        tabMenu.addWidget(inviteButton);
        tabMenu.addWidget(removeButton);
    }
    // refreshMembers
    final JsonCallbackEvents refreshEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            if (search) {
                findMembers.searchFor(searchString);
            } else {
                findMembers.clearTable();
                members.retrieveData();
            }
        }
    };
    // add click handler for remove button
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // state specific events
            final ArrayList<RichMember> membersForRemoving = findMembers.getTableSelectedList();
            String text = "Following members will be removed from group. They will lose access to resources provided by this group.";
            UiElements.showDeleteConfirm(membersForRemoving, text, new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    RemoveMembers request = new RemoveMembers(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
                    request.removeMembersFromGroup(group, membersForRemoving);
                }
            });
        }
    });
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        public void searchFor(String text) {
            table.setEmptyTableWidget(tableWidget);
            searchString = text;
            search = true;
            findMembers.searchFor(text);
        }
    }, searchButton);
    searchBox.getTextBox().setText(searchString);
    // checkbox click handler
    disabled.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            wasDisabled = disabled.getValue();
            if (search) {
                // case when update but not triggered by button
                searchString = searchBox.getTextBox().getText();
                members.excludeDisabled(!disabled.getValue());
            } else {
                members.excludeDisabled(!disabled.getValue());
                members.retrieveData();
            }
        }
    });
    findMembers.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(searchButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            searchBox.getTextBox().setEnabled(true);
            listAllButton.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            searchBox.getTextBox().setEnabled(true);
            listAllButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            searchBox.getTextBox().setEnabled(false);
            listAllButton.setEnabled(false);
            disabled.setVisible(false);
        }
    }));
    members.setEvents(JsonCallbackEvents.mergeEvents(JsonCallbackEvents.disableButtonEvents(listAllButton, JsonCallbackEvents.disableCheckboxEvents(disabled)), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // pass data to table handling callback
            findMembers.onFinished(jso);
            ((AjaxLoaderImage) table.getEmptyTableWidget()).setEmptyResultMessage("Group has no members.");
            searchBox.getTextBox().setEnabled(true);
            searchButton.setEnabled(true);
        }

        @Override
        public void onError(PerunError error) {
            // pass data to table handling callback
            findMembers.onError(error);
            searchBox.getTextBox().setEnabled(true);
            searchButton.setEnabled(true);
        }

        @Override
        public void onLoadingStart() {
            table.setEmptyTableWidget(tableWidget);
            searchBox.getTextBox().setEnabled(false);
            searchButton.setEnabled(false);
            disabled.setVisible(true);
            // to show progress when reloading
            ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingStart();
        }
    }));
    // LIST ALL BUTTON
    listAllButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            table.setEmptyTableWidget(tableWidget);
            search = false;
            searchString = "";
            searchBox.getTextBox().setText("");
            findMembers.clearTable();
            members.retrieveData();
        }
    });
    tabMenu.addWidget(listAllButton);
    tabMenu.addWidget(disabled);
    /* WHEN TAB RELOADS, CHECK THE STATE */
    if (search) {
        findMembers.searchFor(searchString);
    } else {
        GetGroupMembersCount count = new GetGroupMembersCount(groupId, new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                int membersCount = ((BasicOverlayType) jso.cast()).getInt();
                if (membersCount > 1000) {
                    FlexTable panel = new FlexTable();
                    panel.setSize("100%", "150px");
                    HTML label = new HTML();
                    label.setHTML("<h2>Group has " + membersCount + " members. We suggest you to use search instead.</h2><h2>You can search member by name, login, email or click List all to see all members.</h2>");
                    panel.setWidget(0, 0, label);
                    panel.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                    table.setEmptyTableWidget(panel);
                } else {
                    // load all members
                    members.excludeDisabled(!disabled.getValue());
                    members.retrieveData();
                }
                onceAsked = true;
            }

            @Override
            public void onError(PerunError error) {
                // load all members
                members.excludeDisabled(!disabled.getValue());
                members.retrieveData();
            }

            @Override
            public void onLoadingStart() {
            }
        });
        if (!onceAsked) {
            count.retrieveData();
        } else {
            // load all members
            members.excludeDisabled(!disabled.getValue());
            members.retrieveData();
        }
    }
    ScrollPanel tableWrapper = new ScrollPanel();
    table.addStyleName("perun-table");
    tableWrapper.setWidget(table);
    tableWrapper.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(tableWrapper, 350, this);
    // add menu and the table to the main panel
    firstTabPanel.add(tableWrapper);
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findMembers, table, removeButton);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) GetGroupMembersCount(cz.metacentrum.perun.webgui.json.groupsManager.GetGroupMembersCount) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) FieldUpdater(com.google.gwt.cell.client.FieldUpdater) ExtendedTextBox(cz.metacentrum.perun.webgui.widgets.ExtendedTextBox) RichMember(cz.metacentrum.perun.webgui.model.RichMember) InviteUserTabItem(cz.metacentrum.perun.webgui.tabs.userstabs.InviteUserTabItem) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers) AddMemberToGroupTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.AddMemberToGroupTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) RemoveMembers(cz.metacentrum.perun.webgui.json.groupsManager.RemoveMembers) PerunError(cz.metacentrum.perun.webgui.model.PerunError) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)4 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 MemberDetailTabItem (cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem)4 ArrayList (java.util.ArrayList)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 PerunError (cz.metacentrum.perun.webgui.model.PerunError)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 FindCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)2 GetCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers)2 RichMember (cz.metacentrum.perun.webgui.model.RichMember)2 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)2 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)2 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)1 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)1