Search in sources :

Example 1 with FindCompleteRichMembers

use of cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers in project perun by CESNET.

the class AddMemberToResourceTabItem method draw.

@Override
public Widget draw() {
    this.titleWidget.setText("Add member(s) to resource");
    final TabItem tab = this;
    if (state == State.SELECT_MEMBERS) {
        this.contentWidget.clear();
        session.getTabManager().changeStyleOfInnerTab(true);
        // main tab
        FlexTable hp = new FlexTable();
        hp.setSize("100%", "100%");
        hp.setCellPadding(5);
        // members list
        VerticalPanel membersListPanel = new VerticalPanel();
        membersListPanel.setSize("100%", "100%");
        TabMenu membersListMenu = new TabMenu();
        membersListPanel.add(membersListMenu);
        membersListPanel.setCellHeight(membersListMenu, "30px");
        // members list callback
        final FindCompleteRichMembers findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, voId, "", null);
        membersListMenu.addSearchWidget(new PerunSearchEvent() {

            @Override
            public void searchFor(String text) {
                if (UiElements.searchStingCantBeEmpty(text)) {
                    findMembers.searchFor(text);
                }
            }
        }, ButtonTranslation.INSTANCE.searchMemberInVo());
        final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, "Add selected members to list", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                ArrayList<RichMember> list = findMembers.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(list)) {
                    selectedMembers.addItems(list);
                    findMembers.clearTableSelectedSet();
                }
            }
        });
        membersListMenu.addWidget(addButton);
        membersListMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                session.getTabManager().closeTab(tab);
            }
        }));
        final CustomButton continueButton = TabMenu.getPredefinedButton(ButtonType.CONTINUE, "Continue to resource selection", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // change state
                state = State.SELECT_RESOURCE_OR_FACILITY;
                // redraw the page
                tab.draw();
            }
        });
        membersListMenu.addWidget(continueButton);
        // if no member selected, disable
        if (selectedMembers.getList().size() == 0) {
            continueButton.setEnabled(false);
        }
        // selection of some member will enable continue button
        selectedMembers.setEvents(new AddRemoveItemsTable.HandleItemsAction<RichMember>() {

            @Override
            public void onAdd(RichMember object) {
                continueButton.setEnabled(true);
            }

            @Override
            public void onRemove(RichMember object) {
                if (selectedMembers.getList().size() == 0) {
                    continueButton.setEnabled(false);
                }
            }
        });
        // put table in content
        ScrollPanel tableWrapper = new ScrollPanel();
        tableWrapper.setWidth("100%");
        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));
            }
        });
        addButton.setEnabled(false);
        JsonUtils.addTableManagedButton(findMembers, table, addButton);
        table.addStyleName("perun-table");
        table.setWidth("100%");
        tableWrapper.setWidget(table);
        tableWrapper.addStyleName("perun-tableScrollPanel");
        session.getUiElements().resizeSmallTabPanel(tableWrapper, 350, this);
        membersListPanel.add(tableWrapper);
        // selected members
        VerticalPanel selectedMembersPanel = new VerticalPanel();
        selectedMembersPanel.setSize("100%", "100%");
        TabMenu selectedMembersMenu = new TabMenu();
        selectedMembersPanel.add(selectedMembersMenu);
        selectedMembersPanel.setCellHeight(selectedMembersMenu, "30px");
        selectedMembersMenu.addWidget(new HTML("<h3>Selected&nbsp;members:</h3>"));
        selectedMembersPanel.add(selectedMembers);
        hp.setWidget(0, 0, membersListPanel);
        hp.setWidget(0, 1, selectedMembersPanel);
        hp.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT);
        hp.getFlexCellFormatter().setWidth(0, 0, "80%");
        hp.getFlexCellFormatter().setWidth(0, 1, "20%");
        this.contentWidget.add(hp);
    } else if (state == State.SELECT_RESOURCE_OR_FACILITY) {
        this.contentWidget.clear();
        session.getTabManager().changeStyleOfInnerTab(false);
        FlexTable layout = new FlexTable();
        layout.setSize("100%", "100%");
        TabMenu menu = new TabMenu();
        if (!startedAtTwo) {
            menu.addWidget(TabMenu.getPredefinedButton(ButtonType.BACK, "Back to members selection", new ClickHandler() {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    // get back and reload
                    state = State.SELECT_MEMBERS;
                    tab.draw();
                }
            }));
        } else {
            this.titleWidget.setText("Add member to resource");
        }
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CONTINUE, "", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                state = State.SELECT_GROUP;
                tab.draw();
            }
        }));
        // RESOURCE LAYOUT
        FlexTable resourceLayout = new FlexTable();
        resourceLayout.setStyleName("inputFormFlexTable");
        // by default do not choose facility or service
        facilitiesListbox.addNotSelectedOption();
        servicesListbox.addNotSelectedOption();
        // TODO
        servicesListbox.setEnabled(false);
        // fill services event
        final JsonCallbackEvents fillServEvent = new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                services.setHTML("");
                ArrayList<Service> servList = JsonUtils.jsoAsList(jso);
                servList = new TableSorter<Service>().sortByName(servList);
                for (Service s : servList) {
                    services.setHTML(services.getHTML().concat(s.getName() + "</br>"));
                }
            }

            @Override
            public void onError(PerunError errro) {
                services.setHTML("Error while loading available services.");
            }
        };
        // fill resources event
        final JsonCallbackEvents fillResEvent = new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                // list of VO facilities filled by loaded resources
                ArrayList<Facility> facs = new ArrayList<Facility>();
                ArrayList<RichResource> resList = JsonUtils.jsoAsList(jso);
                resList = new TableSorter<RichResource>().sortByName(resList);
                Set<String> unificator = new HashSet<String>();
                for (RichResource r : resList) {
                    allResources.add(r);
                    resourcesListbox.addItem(r);
                    if (r.getFacility() != null && !unificator.contains(r.getFacility().getName())) {
                        unificator.add(r.getFacility().getName());
                        facs.add(r.getFacility());
                    }
                }
                // sort and fill facilities
                facs = new TableSorter<Facility>().sortByName(facs);
                facilitiesListbox.addAllItems(facs);
                // initial setup
                // refresh rest
                description.setText(resourcesListbox.getSelectedObject().getDescription());
                GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
                servCall.retrieveData();
            }

            @Override
            public void onLoadingStart() {
                resourcesListbox.clear();
            }

            @Override
            public void onError(PerunError error) {
                resourcesListbox.addItem("Error while loading");
            }
        };
        resourcesListbox.addChangeHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent changeEvent) {
                description.setText(resourcesListbox.getSelectedObject().getDescription());
                // fill information about services on resource
                GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
                servCall.retrieveData();
            }
        });
        facilitiesListbox.addChangeHandler(new ChangeHandler() {

            @Override
            public void onChange(ChangeEvent changeEvent) {
                if (facilitiesListbox.getSelectedIndex() > 0) {
                    // fill only resources on facility
                    resourcesListbox.clear();
                    for (RichResource r : allResources) {
                        if (r.getFacility().getId() == facilitiesListbox.getSelectedObject().getId()) {
                            resourcesListbox.addItem(r);
                        }
                    }
                } else {
                    // fill all resources
                    resourcesListbox.clear();
                    resourcesListbox.addAllItems(allResources);
                }
                // refresh rest
                description.setText(resourcesListbox.getSelectedObject().getDescription());
                GetAssignedServices servCall = new GetAssignedServices(resourcesListbox.getSelectedObject().getId(), fillServEvent);
                servCall.retrieveData();
            }
        });
        GetRichResources resCall = new GetRichResources(voId, fillResEvent);
        if (allResources.isEmpty()) {
            resCall.retrieveData();
        }
        resourceLayout.setHTML(0, 0, "Filter by Facility:");
        resourceLayout.setWidget(0, 1, facilitiesListbox);
        //resourceLayout.setHTML(1, 0, "Filter by Service:");
        //resourceLayout.setWidget(1, 1, servicesListbox);
        resourceLayout.setHTML(1, 0, "Selected resource:");
        resourceLayout.setWidget(1, 1, resourcesListbox);
        resourceLayout.setHTML(2, 0, "Description:");
        resourceLayout.setWidget(2, 1, description);
        resourceLayout.setHTML(3, 0, "Services on Resource:");
        resourceLayout.setWidget(3, 1, services);
        for (int i = 0; i < resourceLayout.getRowCount(); i++) {
            resourceLayout.getFlexCellFormatter().addStyleName(i, 0, "itemName");
        }
        // set layout
        layout.setWidget(0, 0, menu);
        layout.setWidget(1, 0, resourceLayout);
        this.contentWidget.add(layout);
    } else if (state == State.SELECT_GROUP) {
        this.contentWidget.clear();
        session.getTabManager().changeStyleOfInnerTab(true);
        final GetAssignedGroups assGroupCall = new GetAssignedGroups(resourcesListbox.getSelectedObject().getId());
        assGroupCall.setSingleSelection(true);
        assGroupCall.setCoreGroupsCheckable(false);
        VerticalPanel vp = new VerticalPanel();
        vp.setSize("100%", "100%");
        TabMenu menu = new TabMenu();
        menu.addWidget(TabMenu.getPredefinedButton(ButtonType.BACK, "Back to resource selection", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // get back and reload
                state = State.SELECT_RESOURCE_OR_FACILITY;
                tab.draw();
            }
        }));
        final CustomButton addToGroupButton = new CustomButton("Add to Group", "Add members to selected Group", SmallIcons.INSTANCE.addIcon());
        menu.addWidget(addToGroupButton);
        addToGroupButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                if (UiElements.cantSaveEmptyListDialogBox(assGroupCall.getTableSelectedList())) {
                    final Group grp = assGroupCall.getTableSelectedList().get(0);
                    final FlexTable content = new FlexTable();
                    GetAssignedResources getRes = new GetAssignedResources(grp.getId(), PerunEntity.GROUP, new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            ArrayList<Resource> rr = JsonUtils.jsoAsList(jso);
                            String items = new String("<ul>");
                            for (Resource r : rr) {
                                items += "<li>" + r.getName() + "</li>";
                            }
                            items += "</ul>";
                            ScrollPanel sp = new ScrollPanel();
                            sp.add(new HTML(items));
                            sp.setSize("300px", "150px");
                            content.setWidget(1, 0, sp);
                        }

                        public void onError(PerunError error) {
                            content.setWidget(1, 0, new AjaxLoaderImage().loadingError(error));
                        }
                    });
                    getRes.retrieveData();
                    content.setHTML(0, 0, "<p><strong>By adding member into this group, he/she will gain access to following resources:</strong>");
                    content.setWidget(1, 0, new AjaxLoaderImage().loadingStart());
                    Confirm c = new Confirm("Confirm add action", content, new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addToGroupButton));
                            for (RichMember m : selectedMembers.getList()) {
                                request.addMemberToGroup(grp, m);
                            }
                        }
                    }, true);
                    c.setNonScrollable(true);
                    c.show();
                }
            }
        });
        menu.addWidget(new CustomButton("Create group…", "Create new empty group", SmallIcons.INSTANCE.addIcon(), new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // get back and reload
                state = State.CREATE_GROUP;
                tab.draw();
            }
        }));
        CustomButton finish = TabMenu.getPredefinedButton(ButtonType.FINISH, "Close the tab", new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                session.getTabManager().closeTab(tab, false);
            }
        });
        finish.setImageAlign(true);
        menu.addWidget(finish);
        menu.addWidget(new Image(SmallIcons.INSTANCE.helpIcon()));
        menu.addWidget(new HTML("<strong>Please select group in which you wish to add members to."));
        CellTable<Group> table = assGroupCall.getTable();
        addToGroupButton.setEnabled(false);
        JsonUtils.addTableManagedButton(assGroupCall, table, addToGroupButton);
        // 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");
        session.getUiElements().resizeSmallTabPanel(sp, 350, this);
        vp.add(menu);
        vp.add(sp);
        this.contentWidget.add(vp);
    } else if (state == State.CREATE_GROUP) {
        session.getTabManager().changeStyleOfInnerTab(false);
        VerticalPanel vp = new VerticalPanel();
        // form inputs
        final ExtendedTextBox groupNameTextBox = new ExtendedTextBox();
        final TextBox groupDescriptionTextBox = new TextBox();
        final ListBoxWithObjects<Group> vosGroups = new ListBoxWithObjects<Group>();
        vosGroups.setVisible(false);
        final CheckBox asSubGroup = new CheckBox("", false);
        cz.metacentrum.perun.webgui.widgets.TabMenu menu = new cz.metacentrum.perun.webgui.widgets.TabMenu();
        final CustomButton createButton = TabMenu.getPredefinedButton(ButtonType.CREATE, "");
        final CustomButton cancelButton = TabMenu.getPredefinedButton(ButtonType.CANCEL, "");
        final HTML parentGroupText = new HTML("Parent group:");
        parentGroupText.setVisible(false);
        final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {

            @Override
            public boolean validateTextBox() {
                if (groupNameTextBox.getTextBox().getText().trim().isEmpty()) {
                    groupNameTextBox.setError("Name can't be empty.");
                } else if (!groupNameTextBox.getTextBox().getText().trim().matches(Utils.GROUP_SHORT_NAME_MATCHER)) {
                    groupNameTextBox.setError("Name can contain only letters, numbers, spaces, dots, '_' and '-'.");
                } else {
                    groupNameTextBox.setOk();
                    return true;
                }
                return false;
            }
        };
        groupNameTextBox.setValidator(validator);
        final GetAllGroups groupsCall = new GetAllGroups(voId, new JsonCallbackEvents() {

            public void onFinished(JavaScriptObject jso) {
                vosGroups.clear();
                ArrayList<Group> retGroups = JsonUtils.jsoAsList(jso);
                retGroups = new TableSorter<Group>().sortByName(retGroups);
                for (Group g : retGroups) {
                    if (g.isCoreGroup()) {
                        // SKIP CORE GROUPS !!
                        continue;
                    }
                    vosGroups.addItem(g);
                }
                createButton.setEnabled(true);
            }

            public void onLoadingStart() {
                vosGroups.clear();
                vosGroups.addItem("Loading...");
                createButton.setEnabled(false);
            }

            public void onError(PerunError error) {
                vosGroups.clear();
                vosGroups.addItem("Error while loading");
                if (asSubGroup.getValue()) {
                    createButton.setEnabled(false);
                } else {
                    createButton.setEnabled(true);
                }
            }
        });
        asSubGroup.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

            @Override
            public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
                if (booleanValueChangeEvent.getValue() == true) {
                    // set title
                    vosGroups.setVisible(true);
                    parentGroupText.setVisible(true);
                    groupsCall.retrieveData();
                    createButton.setTitle(ButtonTranslation.INSTANCE.createSubGroup());
                } else {
                    createButton.setEnabled(true);
                    vosGroups.setVisible(false);
                    parentGroupText.setVisible(false);
                    createButton.setTitle(ButtonTranslation.INSTANCE.createGroup());
                }
            }
        });
        // layout
        FlexTable layout = new FlexTable();
        layout.setStyleName("inputFormFlexTable");
        FlexTable.FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
        // send button
        createButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                if (!validator.validateTextBox())
                    return;
                // redirect event
                final JsonCallbackEvents redirectEvent = new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        state = State.SELECT_GROUP;
                        session.getTabManager().changeStyleOfInnerTab(true);
                        tab.draw();
                    }
                };
                // assign group after creation
                final JsonCallbackEvents assignEvent = new JsonCallbackEvents() {

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        Group g = jso.cast();
                        if (g != null) {
                            AssignGroupToResources assign = new AssignGroupToResources(JsonCallbackEvents.disableButtonEvents(createButton, redirectEvent));
                            assign.assignGroupToResources(g, JsonUtils.<RichResource>toList(resourcesListbox.getSelectedObject()));
                        }
                    }
                };
                // creates a new request
                CreateGroup cg = new CreateGroup(JsonCallbackEvents.disableButtonEvents(createButton, assignEvent));
                if (asSubGroup.getValue()) {
                    if (vosGroups.getSelectedObject() != null) {
                        cg.createGroupInGroup(vosGroups.getSelectedObject().getId(), groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText());
                    } else {
                        UiElements.generateInfo("No parent group selected", "You checked create this group as sub-group, but no parent group is selected. Please select parent group.");
                    }
                } else {
                    cg.createGroupInVo(voId, groupNameTextBox.getTextBox().getText().trim(), groupDescriptionTextBox.getText());
                }
            }
        });
        // cancel button
        cancelButton.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent clickEvent) {
                // redirect back to select group
                state = State.SELECT_GROUP;
                session.getTabManager().changeStyleOfInnerTab(true);
                tab.draw();
            }
        });
        // Add some standard form options
        layout.setHTML(0, 0, "Name:");
        layout.setWidget(0, 1, groupNameTextBox);
        layout.setHTML(1, 0, "Description:");
        layout.setWidget(1, 1, groupDescriptionTextBox);
        layout.setHTML(2, 0, "As sub-group:");
        layout.setWidget(2, 1, asSubGroup);
        layout.setWidget(3, 0, parentGroupText);
        layout.setWidget(3, 1, vosGroups);
        for (int i = 0; i < layout.getRowCount(); i++) {
            cellFormatter.addStyleName(i, 0, "itemName");
        }
        // button align
        menu.addWidget(createButton);
        menu.addWidget(cancelButton);
        vp.add(layout);
        vp.add(menu);
        vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
        this.contentWidget.setWidget(vp);
    }
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) AddMember(cz.metacentrum.perun.webgui.json.groupsManager.AddMember) ImageResource(com.google.gwt.resources.client.ImageResource) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) CreateGroup(cz.metacentrum.perun.webgui.json.groupsManager.CreateGroup) HashSet(java.util.HashSet) Set(java.util.Set) cz.metacentrum.perun.webgui.widgets(cz.metacentrum.perun.webgui.widgets) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) CreateGroup(cz.metacentrum.perun.webgui.json.groupsManager.CreateGroup) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Example 2 with FindCompleteRichMembers

use of cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers 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) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < membersForRemoving.size(); i++) {
                        DeleteMember request;
                        if (i == membersForRemoving.size() - 1) {
                            request = new DeleteMember(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
                        } else {
                            request = new DeleteMember(JsonCallbackEvents.disableButtonEvents(removeButton));
                        }
                        request.deleteMember(membersForRemoving.get(i).getId());
                    }
                }
            });
        }
    });
    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) DeleteMember(cz.metacentrum.perun.webgui.json.membersManager.DeleteMember) 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) PerunError(cz.metacentrum.perun.webgui.model.PerunError) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Example 3 with FindCompleteRichMembers

use of cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers in project perun by CESNET.

the class AddMemberToGroupTabItem method draw.

public Widget draw() {
    titleWidget.setText("Add member(s)");
    // MAIN PANEL
    final VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    boolean isMembersGroup = group.isCoreGroup();
    // if members or admins group, hide
    if (isMembersGroup) {
        firstTabPanel.add(new HTML("<p>Group \"" + group.getName() + "\" can't have members managed from Group admin. Please use VO admin section.</p>"));
        this.contentWidget.setWidget(firstTabPanel);
        return getWidget();
    }
    // MENU
    TabMenu tabMenu = new TabMenu();
    firstTabPanel.add(tabMenu);
    firstTabPanel.setCellHeight(tabMenu, "30px");
    // for resize
    final TabItem tab = this;
    // CALLBACKS
    // for both
    final FindCompleteRichMembers findMembers;
    // for both
    final GetCompleteRichMembers getAllMembers;
    // for VO/group admin differs search
    final FindCandidatesOrUsersToAddToVo findCandidatesOrUsersToAddToVo;
    // elements handled by callback events
    final CustomButton searchButton = new CustomButton("Search in VO", ButtonTranslation.INSTANCE.searchMemberInVo(), SmallIcons.INSTANCE.findIcon());
    final CustomButton searchGloballyButton = new CustomButton("Search globally", ButtonTranslation.INSTANCE.searchForMembersInExtSources(), SmallIcons.INSTANCE.findIcon());
    final CustomButton listAllButton = new CustomButton("List all VO members", ButtonTranslation.INSTANCE.listAllMembersInVo(), SmallIcons.INSTANCE.userGreenIcon());
    final CheckBox disabled = new CheckBox(WidgetTranslation.INSTANCE.showDisabledMembers());
    // search through whole VO
    findMembers = new FindCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), "", null);
    getAllMembers = new GetCompleteRichMembers(PerunEntity.VIRTUAL_ORGANIZATION, group.getVoId(), null);
    if (session.isVoAdmin(group.getVoId())) {
        // will search vo ext sources and users
        findCandidatesOrUsersToAddToVo = new FindCandidatesOrUsersToAddToVo(group.getVoId(), 0, "", null);
    } else {
        // will search group ext sources only
        findCandidatesOrUsersToAddToVo = new FindCandidatesOrUsersToAddToVo(group.getVoId(), group.getId(), "", null);
    }
    final CellTable<Candidate> candidatesTable = findCandidatesOrUsersToAddToVo.getEmptyTable();
    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(), groupId));
        }
    });
    final CustomButton inviteButton = new CustomButton("Invite selected", SmallIcons.INSTANCE.emailIcon());
    final CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedMemberToGroup());
    final ExtendedTextBox searchBox = tabMenu.addSearchWidget(new PerunSearchEvent() {

        public void searchFor(String text) {
            searchString = text;
            findMembers.searchFor(searchString);
            search = true;
            searchCandidates = false;
            // remove previous table
            firstTabPanel.getWidget(2).removeFromParent();
            firstTabPanel.add(sp);
            UiElements.runResizeCommands(tab);
        }
    }, searchButton);
    searchBox.getTextBox().setText(searchString);
    // bind text box also to search globally
    searchBox.getTextBox().addKeyUpHandler(new KeyUpHandler() {

        public void onKeyUp(KeyUpEvent event) {
            if (!searchBox.getTextBox().getText().trim().isEmpty()) {
                searchGloballyButton.setEnabled(true);
            // do not trigger search on both !!
            } else {
                searchGloballyButton.setEnabled(false);
            }
        }
    });
    searchBox.getTextBox().addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(BlurEvent event) {
            // fake some meaningless KeyUpEvent
            DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_DOWN), searchBox.getTextBox());
        }
    });
    searchBox.getTextBox().addValueChangeHandler(new ValueChangeHandler<String>() {

        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            // fake some meaningless KeyUpEvent
            DomEvent.fireNativeEvent(Document.get().createKeyUpEvent(false, false, false, false, KeyCodes.KEY_DOWN), searchBox.getTextBox());
        }
    });
    // button click triggers action
    searchGloballyButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            if (UiElements.searchStingCantBeEmpty(searchBox.getTextBox().getText().trim())) {
                new PerunSearchEvent() {

                    public void searchFor(String text) {
                        searchString = text;
                        findCandidatesOrUsersToAddToVo.searchFor(searchString);
                        searchCandidates = true;
                        search = false;
                        // remove previous table
                        firstTabPanel.getWidget(2).removeFromParent();
                        firstTabPanel.add(sp2);
                        UiElements.runResizeCommands(tab);
                    }
                }.searchFor(searchBox.getTextBox().getText().trim());
            }
        }
    });
    searchGloballyButton.setEnabled(false);
    findMembers.setEvents(JsonCallbackEvents.disableButtonEvents(searchButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // if found 1 item, select
            listAllButton.setEnabled(true);
            searchGloballyButton.setEnabled(true);
            searchBox.getTextBox().setEnabled(true);
            ArrayList<RichMember> list = JsonUtils.jsoAsList(jso);
            if (list != null && list.size() == 1) {
                findMembers.getSelectionModel().setSelected(list.get(0), true);
            }
        }

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

        @Override
        public void onLoadingStart() {
            listAllButton.setEnabled(false);
            searchGloballyButton.setEnabled(false);
            disabled.setVisible(false);
            searchBox.getTextBox().setEnabled(false);
            addButton.setEnabled(false);
            inviteButton.setEnabled(false);
        }
    }));
    getAllMembers.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.");
            searchButton.setEnabled(true);
            searchBox.getTextBox().setEnabled(true);
        }

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

        @Override
        public void onLoadingStart() {
            searchButton.setEnabled(false);
            disabled.setVisible(true);
            searchBox.getTextBox().setEnabled(false);
            addButton.setEnabled(false);
            inviteButton.setEnabled(false);
        }
    }));
    findCandidatesOrUsersToAddToVo.setEvents(JsonCallbackEvents.disableButtonEvents(searchGloballyButton, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // if found 1 item, select
            listAllButton.setEnabled(true);
            searchButton.setEnabled(true);
            searchBox.getTextBox().setEnabled(true);
            ArrayList<Candidate> list = JsonUtils.jsoAsList(jso);
            if (list != null && list.size() == 1) {
                findCandidatesOrUsersToAddToVo.setSelected(list.get(0));
            }
        }

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

        @Override
        public void onLoadingStart() {
            disabled.setVisible(false);
            listAllButton.setEnabled(false);
            searchButton.setEnabled(false);
            searchBox.getTextBox().setEnabled(false);
            addButton.setEnabled(false);
            inviteButton.setEnabled(false);
        }
    }));
    // DISABLED CHECKBOX
    disabled.setTitle(WidgetTranslation.INSTANCE.showDisabledMembersTitle());
    disabled.setVisible(false);
    // checkbox click handler
    disabled.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            getAllMembers.excludeDisabled(!disabled.getValue());
            findMembers.clearTable();
            getAllMembers.retrieveData();
        }
    });
    listAllButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            search = false;
            searchCandidates = false;
            searchString = "";
            searchBox.getTextBox().setText("");
            findMembers.clearTable();
            findCandidatesOrUsersToAddToVo.clearTable();
            getAllMembers.retrieveData();
            // remove previous table
            firstTabPanel.getWidget(2).removeFromParent();
            firstTabPanel.add(sp);
            UiElements.runResizeCommands(tab);
        }
    });
    // click handler
    addButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (searchCandidates) {
                // searched users or candidates
                Candidate candidateToBeAdded = findCandidatesOrUsersToAddToVo.getSelected();
                if (candidateToBeAdded == null) {
                    UiElements.cantSaveEmptyListDialogBox(null);
                } else {
                    if (candidateToBeAdded.getObjectType().equalsIgnoreCase("Candidate")) {
                        CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                            private Candidate saveSelected;

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                // put names to already added
                                if (saveSelected != null) {
                                    GeneralObject go = saveSelected.cast();
                                    alreadyAddedList.add(go);
                                }
                                findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
                                rebuildAlreadyAddedWidget();
                                // clear search
                                searchBox.getTextBox().setText("");
                            }

                            @Override
                            public void onLoadingStart() {
                                saveSelected = findCandidatesOrUsersToAddToVo.getSelected();
                            }
                        }));
                        request.createMember(group.getVoId(), group, candidateToBeAdded);
                    } else {
                        CreateMember request = new CreateMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                            private User saveSelected;

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                // put names to already added
                                if (saveSelected != null) {
                                    GeneralObject go = saveSelected.cast();
                                    alreadyAddedList.add(go);
                                    findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
                                    rebuildAlreadyAddedWidget();
                                    // clear search
                                    searchBox.getTextBox().setText("");
                                }
                            }

                            @Override
                            public void onLoadingStart() {
                                Candidate cand = findCandidatesOrUsersToAddToVo.getSelected();
                                saveSelected = cand.cast();
                            }
                        }));
                        User user = candidateToBeAdded.cast();
                        request.createMember(group.getVoId(), group, user);
                    }
                }
            } else {
                // searched members / all members
                final ArrayList<RichMember> membersToAdd = findMembers.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(membersToAdd)) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < membersToAdd.size(); i++) {
                        final int n = i;
                        AddMember request = new AddMember(JsonCallbackEvents.disableButtonEvents(addButton, new JsonCallbackEvents() {

                            private RichMember saveSelected;

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                // unselect added person
                                findMembers.getSelectionModel().setSelected(saveSelected, false);
                                // put names to already added
                                GeneralObject go = saveSelected.cast();
                                alreadyAddedList.add(go);
                                rebuildAlreadyAddedWidget();
                                // clear search
                                searchBox.getTextBox().setText("");
                            }

                            @Override
                            public void onLoadingStart() {
                                saveSelected = membersToAdd.get(n);
                            }
                        }));
                        request.addMemberToGroup(group, membersToAdd.get(i));
                    }
                }
            }
        }
    });
    tabMenu.addWidget(searchGloballyButton);
    tabMenu.addWidget(listAllButton);
    tabMenu.addWidget(addButton);
    tabMenu.addWidget(inviteButton);
    inviteButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (searchCandidates) {
                // we expect, that candidate is always single
                Candidate candid = findCandidatesOrUsersToAddToVo.getSelected();
                if (candid != null) {
                    if (candid.getObjectType().equalsIgnoreCase("Candidate")) {
                        SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
                        invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
                            }
                        }));
                        invite.inviteUser(candid);
                    } else {
                        SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
                        invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                findCandidatesOrUsersToAddToVo.clearTableSelectedSet();
                            }
                        }));
                        User user = candid.cast();
                        invite.inviteUser(user);
                    }
                }
            } else {
                // members / all members
                SendInvitation invite = new SendInvitation(group.getVoId(), groupId);
                ArrayList<RichMember> usrs = findMembers.getTableSelectedList();
                for (int i = 0; i < usrs.size(); i++) {
                    if (i == usrs.size() - 1) {
                        invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton, new JsonCallbackEvents() {

                            @Override
                            public void onFinished(JavaScriptObject jso) {
                                findMembers.clearTableSelectedSet();
                            }
                        }));
                    } else {
                        invite.setEvents(JsonCallbackEvents.disableButtonEvents(inviteButton));
                    }
                    invite.inviteUser(usrs.get(i).getUser());
                }
            }
        }
    });
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            // with refresh if somebody was added
            session.getTabManager().closeTab(tab, !alreadyAddedList.isEmpty());
        }
    }));
    tabMenu.addWidget(disabled);
    rebuildAlreadyAddedWidget();
    firstTabPanel.add(alreadyAdded);
    addButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findMembers, table, addButton);
    inviteButton.setEnabled(false);
    JsonUtils.addTableManagedButton(findMembers, table, inviteButton);
    JsonUtils.addTableManagedButton(findCandidatesOrUsersToAddToVo, candidatesTable, addButton);
    JsonUtils.addTableManagedButton(findCandidatesOrUsersToAddToVo, candidatesTable, inviteButton);
    table.addStyleName("perun-table");
    sp.setWidget(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    candidatesTable.addStyleName("perun-table");
    sp2.setWidget(candidatesTable);
    sp2.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp2, 350, this);
    // if not empty - start searching
    if (search) {
        findMembers.searchFor(searchString);
        firstTabPanel.add(sp);
    } else if (searchCandidates) {
        findCandidatesOrUsersToAddToVo.searchFor(searchString);
        firstTabPanel.add(sp2);
    } else {
        getAllMembers.excludeDisabled(!disabled.getValue());
        getAllMembers.retrieveData();
        firstTabPanel.add(sp);
    }
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) BlurHandler(com.google.gwt.event.dom.client.BlurHandler) User(cz.metacentrum.perun.webgui.model.User) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) KeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler) CreateMember(cz.metacentrum.perun.webgui.json.membersManager.CreateMember) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) AddMember(cz.metacentrum.perun.webgui.json.groupsManager.AddMember) GeneralObject(cz.metacentrum.perun.webgui.model.GeneralObject) Candidate(cz.metacentrum.perun.webgui.model.Candidate) 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) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) FindCandidatesOrUsersToAddToVo(cz.metacentrum.perun.webgui.json.vosManager.FindCandidatesOrUsersToAddToVo) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) SendInvitation(cz.metacentrum.perun.webgui.json.registrarManager.SendInvitation) BlurEvent(com.google.gwt.event.dom.client.BlurEvent) PerunError(cz.metacentrum.perun.webgui.model.PerunError) FindCompleteRichMembers(cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)

Example 4 with FindCompleteRichMembers

use of cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers 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.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) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < membersForRemoving.size(); i++) {
                        RemoveMember request;
                        if (i == membersForRemoving.size() - 1) {
                            request = new RemoveMember(JsonCallbackEvents.disableButtonEvents(removeButton, refreshEvent));
                        } else {
                            request = new RemoveMember(JsonCallbackEvents.disableButtonEvents(removeButton));
                        }
                        request.removeMemberFromGroup(group, membersForRemoving.get(i));
                    }
                }
            });
        }
    });
    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) RemoveMember(cz.metacentrum.perun.webgui.json.groupsManager.RemoveMember) 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) 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 FindCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.FindCompleteRichMembers)4 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)4 ArrayList (java.util.ArrayList)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 GetCompleteRichMembers (cz.metacentrum.perun.webgui.json.membersManager.GetCompleteRichMembers)3 PerunError (cz.metacentrum.perun.webgui.model.PerunError)3 RichMember (cz.metacentrum.perun.webgui.model.RichMember)3 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)3 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)3 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 AddMember (cz.metacentrum.perun.webgui.json.groupsManager.AddMember)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 MemberDetailTabItem (cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem)2 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)1 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)1 BlurHandler (com.google.gwt.event.dom.client.BlurHandler)1 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)1