Search in sources :

Example 1 with GetMemberByUser

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

the class SelfResourcesSettingsTabItem method loadSettings.

/**
	 * Load settings for each resource (loaded only once onClick on header)
	 *
	 * @return settings content for each resource
	 */
private Widget loadSettings(final DisclosurePanel settings, final Resource resource) {
    // create content table
    final FlexTable layoutx = new FlexTable();
    layoutx.setCellSpacing(5);
    // get member
    final GetMemberByUser callMember = new GetMemberByUser(resource.getVoId(), userId, new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            // member
            final Member mem = jso.cast();
            // set ids
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("member", mem.getId());
            ids.put("resource", resource.getId());
            // to filter empty values
            ids.put("resourceToGetServicesFrom", resource.getId());
            ids.put("workWithUserAttributes", 1);
            // get req. attrs - to filter eg. if quota is used or not
            final GetRequiredAttributes attributes = new GetRequiredAttributes(ids);
            final JsonCallbackEvents refreshEvent = new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    /// reload resource settings data
                    attributes.retrieveData();
                }
            };
            attributes.setEvents(new JsonCallbackEvents() {

                public void onLoadingStart() {
                    AjaxLoaderImage loader = new AjaxLoaderImage(true);
                    layoutx.setWidget(0, 0, loader.loadingStart());
                }

                public void onError(PerunError error) {
                    AjaxLoaderImage loader = new AjaxLoaderImage(true);
                    layoutx.setWidget(0, 0, loader.loadingError(error));
                }

                public void onFinished(JavaScriptObject jso) {
                    // fill layout
                    ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
                    // check if any attributes displayed
                    boolean empty = true;
                    // remove loading image
                    layoutx.getWidget(0, 0).removeFromParent();
                    int row = 0;
                    // process shell
                    for (final Attribute a : attrs) {
                        // user's shell on facility (DEF is exception from default VIRT so display them)
                        if (a.getFriendlyName().equalsIgnoreCase("shell") && !a.getDefinition().equalsIgnoreCase("virt")) {
                            layoutx.setHTML(row, 0, "<strong>Shell: </strong>");
                            empty = false;
                            // change button
                            CustomButton cb = new CustomButton("Change…", SmallIcons.INSTANCE.cogIcon());
                            layoutx.setWidget(row, 2, cb);
                            // click handler
                            cb.addClickHandler(new ClickHandler() {

                                public void onClick(ClickEvent event) {
                                    session.getTabManager().addTabToCurrentTab(new ShellChangeTabItem(resource, userId, a, refreshEvent));
                                }
                            });
                            if (!a.getValue().equalsIgnoreCase("null")) {
                                // FIXME - we can't offer what default would be, since virt value is always same as def value
                                layoutx.setHTML(row, 1, a.getValue());
                                row++;
                                layoutx.setHTML(row, 1, "You are using specific shell for this resource overriding your global preferences.<br />To get back to default use change button.");
                                layoutx.getFlexCellFormatter().setStyleName(row, 1, "inputFormInlineComment");
                                layoutx.getFlexCellFormatter().setColSpan(row, 1, 2);
                            }
                            for (Attribute ia : attrs) {
                                if (ia.getFriendlyName().equalsIgnoreCase("shell") && ia.getDefinition().equalsIgnoreCase("virt")) {
                                    if (a.getValue().equalsIgnoreCase("null") && ia.getValue().equalsIgnoreCase("null")) {
                                        layoutx.setHTML(row, 1, "Using default (default: Not set)");
                                    } else if (a.getValue().equalsIgnoreCase("null")) {
                                        layoutx.setHTML(row, 1, "Using default (default: " + ia.getValue() + ")");
                                        row++;
                                        layoutx.setHTML(row, 1, "You are using default shell taken from your global preferences.<br />Use change button to set specific shell for this resource.");
                                        layoutx.getFlexCellFormatter().setStyleName(row, 1, "inputFormInlineComment");
                                        layoutx.getFlexCellFormatter().setColSpan(row, 1, 2);
                                    }
                                    break;
                                }
                            }
                            row++;
                            break;
                        }
                    }
                    for (final Attribute a : attrs) {
                        if (a.getFriendlyName().equalsIgnoreCase("dataLimit")) {
                            final int rowDataLimit = row;
                            final CustomButton quotaChangeButton = new CustomButton("Request change…", SmallIcons.INSTANCE.databaseIcon());
                            // display value
                            layoutx.setHTML(row, 0, "<strong>Data quota: </strong>");
                            // get default
                            Map<String, Integer> ids = new HashMap<String, Integer>();
                            ids.put("resource", resource.getId());
                            GetAttributes defaultAttr = new GetAttributes(new JsonCallbackEvents() {

                                public void onError(PerunError error) {
                                    if (a.getValue().equalsIgnoreCase("null")) {
                                        layoutx.setHTML(rowDataLimit, 1, "Using default (default: error while loading)");
                                    } else {
                                        layoutx.setHTML(rowDataLimit, 1, String.valueOf(a.getValue()) + " (default: error while loading)");
                                    }
                                    quotaChangeButton.addClickHandler(new ClickHandler() {

                                        public void onClick(ClickEvent event) {
                                            session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.DATA, a.getValue(), "error while loading"));
                                        }
                                    });
                                }

                                public void onFinished(JavaScriptObject jso) {
                                    ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
                                    boolean empty = true;
                                    for (final Attribute resAttr : attrs) {
                                        if (resAttr.getFriendlyName().equalsIgnoreCase("defaultDataLimit")) {
                                            if (a.getValue().equalsIgnoreCase("null")) {
                                                // null private + default
                                                layoutx.setHTML(rowDataLimit, 1, "Using default (default: " + resAttr.getValue() + ")");
                                            } else {
                                                // private - default
                                                layoutx.setHTML(rowDataLimit, 1, String.valueOf(a.getValue()) + " (default: " + resAttr.getValue() + ")");
                                            }
                                            empty = false;
                                            quotaChangeButton.addClickHandler(new ClickHandler() {

                                                public void onClick(ClickEvent event) {
                                                    session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.DATA, a.getValue(), resAttr.getValue()));
                                                }
                                            });
                                        }
                                    }
                                    // if no default found, write down at least private
                                    if (empty) {
                                        if (a.getValue().equalsIgnoreCase("null")) {
                                            layoutx.setHTML(rowDataLimit, 1, "Using default (default: Not set)");
                                        } else {
                                            layoutx.setHTML(rowDataLimit, 1, String.valueOf(a.getValue()) + " (default: Not set)");
                                        }
                                        quotaChangeButton.addClickHandler(new ClickHandler() {

                                            public void onClick(ClickEvent event) {
                                                session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.DATA, a.getValue(), "Not set"));
                                            }
                                        });
                                    }
                                }
                            });
                            defaultAttr.setIds(ids);
                            defaultAttr.retrieveData();
                            empty = false;
                            layoutx.setWidget(row, 2, quotaChangeButton);
                            row++;
                            break;
                        }
                    }
                    for (final Attribute a : attrs) {
                        if (a.getFriendlyName().equalsIgnoreCase("filesLimit")) {
                            layoutx.setHTML(row, 0, "<strong>Files quota: </strong>");
                            final int rowFilesQuota = row;
                            // get default
                            Map<String, Integer> ids = new HashMap<String, Integer>();
                            ids.put("resource", resource.getId());
                            final CustomButton quotaChangeButton = new CustomButton("Request change…", SmallIcons.INSTANCE.databaseIcon());
                            GetAttributes defaultAttr = new GetAttributes(new JsonCallbackEvents() {

                                public void onError(PerunError error) {
                                    if (a.getValue().equalsIgnoreCase("null")) {
                                        layoutx.setHTML(rowFilesQuota, 1, "Using default (default: error while loading)");
                                    } else {
                                        layoutx.setHTML(rowFilesQuota, 1, String.valueOf(a.getValue()) + " (default: error while loading)");
                                    }
                                    quotaChangeButton.addClickHandler(new ClickHandler() {

                                        public void onClick(ClickEvent event) {
                                            session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.FILES, a.getValue(), "Error while loading"));
                                        }
                                    });
                                }

                                public void onFinished(JavaScriptObject jso) {
                                    ArrayList<Attribute> attrs = JsonUtils.jsoAsList(jso);
                                    boolean empty = true;
                                    for (final Attribute resAttr : attrs) {
                                        if (resAttr.getFriendlyName().equalsIgnoreCase("defaultFilesLimit")) {
                                            if (a.getValue().equalsIgnoreCase("null")) {
                                                // null private + default
                                                layoutx.setHTML(rowFilesQuota, 1, "Using default (default: " + resAttr.getValue() + ")");
                                            } else {
                                                // private + default
                                                layoutx.setHTML(rowFilesQuota, 1, String.valueOf(a.getValue()) + " (default: " + resAttr.getValue() + ")");
                                            }
                                            empty = false;
                                            quotaChangeButton.addClickHandler(new ClickHandler() {

                                                public void onClick(ClickEvent event) {
                                                    session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.FILES, a.getValue(), resAttr.getValue()));
                                                }
                                            });
                                        }
                                    }
                                    // if no default found, write down at least private
                                    if (empty) {
                                        if (a.getValue().equalsIgnoreCase("null")) {
                                            layoutx.setHTML(rowFilesQuota, 1, "Using default (default: Not set)");
                                        } else {
                                            layoutx.setHTML(rowFilesQuota, 1, String.valueOf(a.getValue()) + " (default: Not set)");
                                        }
                                        quotaChangeButton.addClickHandler(new ClickHandler() {

                                            public void onClick(ClickEvent event) {
                                                session.getTabManager().addTabToCurrentTab(new RequestQuotaChangeTabItem(resource, user, QuotaType.FILES, a.getValue(), "Not set"));
                                            }
                                        });
                                    }
                                    layoutx.setWidget(rowFilesQuota, 2, quotaChangeButton);
                                }
                            });
                            defaultAttr.setIds(ids);
                            defaultAttr.retrieveData();
                            empty = false;
                            row++;
                            break;
                        }
                    }
                    for (final Attribute a : attrs) {
                        if (a.getFriendlyName().equalsIgnoreCase("optOutMailingList")) {
                            layoutx.setHTML(row, 0, "<strong>Mailing: </strong>");
                            // find attribute with settings
                            final CheckBox exclude = new CheckBox("Exclude me from this mailing list");
                            exclude.setValue(Boolean.parseBoolean(a.getValue()));
                            final int rowMail = row;
                            exclude.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

                                @Override
                                public void onValueChange(ValueChangeEvent<Boolean> event) {
                                    if (exclude.getValue()) {
                                        a.setValue("true");
                                    } else {
                                        a.setValue(null);
                                    }
                                    Map<String, Integer> ids = new HashMap<String, Integer>();
                                    ids.put("resource", resource.getId());
                                    ids.put("member", mem.getId());
                                    ArrayList<Attribute> ls = new ArrayList<Attribute>();
                                    ls.add(a);
                                    SetAttributes set = new SetAttributes(new JsonCallbackEvents() {

                                        @Override
                                        public void onFinished(JavaScriptObject jso) {
                                            layoutx.setWidget(rowMail, 1, exclude);
                                        }

                                        @Override
                                        public void onLoadingStart() {
                                            layoutx.setWidget(rowMail, 1, new AjaxLoaderImage(true));
                                        }

                                        @Override
                                        public void onError(PerunError error) {
                                            layoutx.setWidget(rowMail, 1, exclude);
                                            // change back since we were not able to change value in Perun
                                            exclude.setValue(!exclude.getValue());
                                        }
                                    });
                                    set.setAttributes(ids, ls);
                                }
                            });
                            layoutx.setWidget(row, 1, exclude);
                            empty = false;
                        }
                    }
                    if (empty) {
                        layoutx.setHTML(0, 0, "<strong>No settings available for this resource.</strong>");
                        layoutx.getFlexCellFormatter().setColSpan(0, 0, 3);
                    }
                }
            });
            attributes.retrieveData();
        }

        public void onLoadingStart() {
            AjaxLoaderImage loader = new AjaxLoaderImage(true);
            layoutx.setWidget(0, 0, loader.loadingStart());
        }

        public void onError(PerunError error) {
            AjaxLoaderImage loader = new AjaxLoaderImage(true);
            layoutx.setWidget(0, 0, loader.loadingError(error));
        }
    });
    // load content on open
    settings.addOpenHandler(new OpenHandler<DisclosurePanel>() {

        public void onOpen(OpenEvent<DisclosurePanel> event) {
            if (settings.getContent() == null) {
                callMember.retrieveData();
                // set content
                settings.setContent(layoutx);
            }
        }
    });
    return settings;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetVosWhereUserIsMember(cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember) GetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes) GetRequiredAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetRequiredAttributes) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with GetMemberByUser

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

the class UserDetailTabItem method loadMemberSubContent.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Example 3 with GetMemberByUser

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

the class ApplicationFormGui method isUserMemberOfVo.

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

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

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

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

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

Example 4 with GetMemberByUser

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

the class SelfVosTabItem method displayVoSubtab.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        @Override
        public void onLoadingStart() {
            groupsTable.setWidget(0, 0, new AjaxLoaderImage().loadingStart());
        }
    });
    memCall.retrieveData();
    return horizontalSplitter;
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetVosWhereUserIsMember(cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember) GetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) GetMemberGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups)

Example 5 with GetMemberByUser

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

the class SelfResourcesSettingsTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": Resources settings");
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    final ScrollPanel scroll = new ScrollPanel();
    scroll.setWidget(vp);
    scroll.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(scroll, 350, this);
    scroll.setWidth("100%");
    final AjaxLoaderImage loader = new AjaxLoaderImage();
    // RETRIEVES ALL VOS WHERE USER IS A MEMBER
    GetVosWhereUserIsMember vosRequest = new GetVosWhereUserIsMember(userId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            vp.getWidget(1).removeFromParent();
            ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
            vos = new TableSorter<VirtualOrganization>().sortByName(vos);
            // if vos length = 1, load immediately all resources
            final boolean loadImmediately = (vos.size() == 1);
            // FOR EACH VO, FIND THE MEMBER
            for (final VirtualOrganization innerVo : vos) {
                final FlexTable header = new FlexTable();
                header.setWidth("100%");
                header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.buildingIcon()));
                header.getFlexCellFormatter().setWidth(0, 0, "40px");
                Anchor a = new Anchor("<p class=\"now-managing disclosurePanelHeader\">" + innerVo.getName() + "</p>", true);
                header.setWidget(0, 1, a);
                header.setTitle("Click to show resources for " + innerVo.getName());
                // disclosure panel
                final DisclosurePanel settings = new DisclosurePanel();
                settings.setWidth("100%");
                settings.setHeader(header);
                // load content on open
                settings.addOpenHandler(new OpenHandler<DisclosurePanel>() {

                    public void onOpen(OpenEvent<DisclosurePanel> event) {
                        if (settings.getContent() == null) {
                            GetMemberByUser memberRequest = new GetMemberByUser(innerVo.getId(), userId, new JsonCallbackEvents() {

                                @Override
                                public void onFinished(JavaScriptObject jso) {
                                    Member member = jso.cast();
                                    // set content
                                    settings.setContent(userSettingsForVo(innerVo, member));
                                }
                            });
                            memberRequest.retrieveData();
                        }
                    }
                });
                vp.add(settings);
                settings.setOpen((vos.size() == 1) || (vo != null && vo.getId() == innerVo.getId()));
            }
        }

        @Override
        public void onLoadingStart() {
            vp.add(loader);
        }

        @Override
        public void onError(PerunError error) {
            loader.loadingError(error);
        }
    });
    vosRequest.retrieveData();
    this.contentWidget.setWidget(scroll);
    return getWidget();
}
Also used : GetVosWhereUserIsMember(cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) ArrayList(java.util.ArrayList) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) OpenHandler(com.google.gwt.event.logical.shared.OpenHandler) GetMemberByUser(cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser) GetVosWhereUserIsMember(cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember) OpenEvent(com.google.gwt.event.logical.shared.OpenEvent)

Aggregations

JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)5 GetMemberByUser (cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser)5 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)4 ArrayList (java.util.ArrayList)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 GetMemberGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups)3 GetVosWhereUserIsMember (cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember)3 HashMap (java.util.HashMap)3 GetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes)2 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)2 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 Map (java.util.Map)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 OpenEvent (com.google.gwt.event.logical.shared.OpenEvent)1 OpenHandler (com.google.gwt.event.logical.shared.OpenHandler)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)1