Search in sources :

Example 1 with GetAttributes

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes 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 GetAttributes

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes 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 3 with GetAttributes

use of cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes in project perun by CESNET.

the class ShellChangeTabItem method draw.

public Widget draw() {
    VerticalPanel vp = new VerticalPanel();
    final FlexTable ft = new FlexTable();
    ft.setWidth("350px");
    ft.setStyleName("inputFormFlexTable");
    ft.setHTML(0, 0, "Available shells:");
    ft.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    final ListBox shells = new ListBox();
    shells.setWidth("200px");
    ft.setWidget(0, 1, shells);
    vp.add(ft);
    final CustomButton selectShellButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save preferred shell");
    // callback for available shells
    GetAttributes attrs = new GetAttributes(new JsonCallbackEvents() {

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

        @Override
        public void onFinished(JavaScriptObject jso) {
            shells.clear();
            ArrayList<Attribute> list = JsonUtils.jsoAsList(jso);
            if (list.isEmpty() || list == null) {
                shells.addItem("No shells available");
                return;
            }
            // fill shells
            for (Attribute a : list) {
                if (a.getFriendlyName().equalsIgnoreCase("shells")) {
                    for (int i = 0; i < a.getValueAsJsArray().length(); i++) {
                        // fill shell values
                        shells.addItem(a.getValueAsJsArray().get(i));
                    }
                    break;
                }
            }
            // set selected
            for (int i = 0; i < shells.getItemCount(); i++) {
                if (shells.getValue(i).equals(a.getValue())) {
                    shells.setSelectedIndex(i);
                    break;
                }
            }
            if (shells.getValue(shells.getSelectedIndex()).equals(a.getValue())) {
                selectShellButton.setEnabled(false);
            } else {
                selectShellButton.setEnabled(true);
            }
        }

        @Override
        public void onLoadingStart() {
            shells.clear();
            shells.addItem("Loading...");
        }
    });
    final TabItem tab = this;
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    selectShellButton.setEnabled(false);
    selectShellButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // OK click button
            // set new value
            a.setValue(shells.getValue(shells.getSelectedIndex()));
            // send request
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", resource.getFacilityId());
            SetAttribute request = new SetAttribute(JsonCallbackEvents.disableButtonEvents(selectShellButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // refresh only what's necessary
                    events.onFinished(jso);
                    // don't refresh underlaying tab
                    session.getTabManager().closeTab(tab, false);
                }
            }));
            request.setAttribute(ids, a);
        }
    });
    attrs.getResourceAttributes(resource.getId());
    attrs.retrieveData();
    shells.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent changeEvent) {
            if (shells.getValue(shells.getSelectedIndex()).equals(a.getValue())) {
                selectShellButton.setEnabled(false);
            } else {
                selectShellButton.setEnabled(true);
            }
        }
    });
    final CustomButton defaultButton = new CustomButton("Use default", "", SmallIcons.INSTANCE.lightningIcon());
    defaultButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", resource.getFacilityId());
            RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(defaultButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // refresh only what's necessary
                    events.onFinished(jso);
                    // don't refresh underlaying tab
                    session.getTabManager().closeTab(tab, false);
                }
            }));
            ArrayList<Attribute> list = new ArrayList<Attribute>();
            list.add(a);
            request.removeAttributes(ids, list);
        }
    });
    menu.addWidget(selectShellButton);
    menu.addWidget(defaultButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    contentWidget.setWidget(vp);
    return getWidget();
}
Also used : GetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) SetAttribute(cz.metacentrum.perun.webgui.json.attributesManager.SetAttribute) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttribute(cz.metacentrum.perun.webgui.json.attributesManager.SetAttribute) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 GetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributes)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 GetMemberByUser (cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser)2 GetVosWhereUserIsMember (cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember)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 GetListOfAttributes (cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes)1 GetRequiredAttributes (cz.metacentrum.perun.webgui.json.attributesManager.GetRequiredAttributes)1 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)1 SetAttribute (cz.metacentrum.perun.webgui.json.attributesManager.SetAttribute)1 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)1 GetMemberGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetMemberGroups)1 Attribute (cz.metacentrum.perun.webgui.model.Attribute)1