Search in sources :

Example 1 with GetVosWhereUserIsMember

use of cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember in project perun by CESNET.

the class SelfVosTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(user.getFullNameWithTitles().trim()) + ": VO settings");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final TabMenu menu = new TabMenu();
    final ScrollPanel sp = new ScrollPanel();
    sp.setSize("100%", "100%");
    sp.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    final ListBoxWithObjects<VirtualOrganization> vosListbox = new ListBoxWithObjects<VirtualOrganization>();
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(new HTML("<strong>Selected VO:</strong>"));
    menu.addWidget(vosListbox);
    vp.add(menu);
    vp.setCellHeight(menu, "50px");
    vp.setCellVerticalAlignment(menu, HasVerticalAlignment.ALIGN_MIDDLE);
    vp.add(new HTML("<hr size=\"1\" color=\"#ccc\">"));
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    final GetVosWhereUserIsMember whereMember = new GetVosWhereUserIsMember(userId, new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
            vos = new TableSorter<VirtualOrganization>().sortByName(vos);
            vosListbox.clear();
            if (vos != null && !vos.isEmpty()) {
                for (VirtualOrganization vo : vos) {
                    vosListbox.addItem(vo);
                    if (vo.getId() == selectedVoId) {
                        vosListbox.setSelected(vo, true);
                    }
                }
                vosListbox.addChangeHandler(new ChangeHandler() {

                    @Override
                    public void onChange(ChangeEvent event) {
                        selectedVoId = vosListbox.getSelectedObject().getId();
                        sp.setWidget(displayVoSubtab(vosListbox.getSelectedObject()));
                    }
                });
                sp.setWidget(displayVoSubtab(vosListbox.getSelectedObject()));
            } else {
                vosListbox.addItem("No VO available");
                sp.setWidget(new HTML(new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>You are not member of any VO.</h2>"));
            }
        }

        @Override
        public void onLoadingStart() {
            vosListbox.clear();
            vosListbox.addItem("Loading...");
        }

        @Override
        public void onError(PerunError error) {
            vosListbox.clear();
            vosListbox.addItem("Error while loading");
            sp.clear();
        }
    });
    whereMember.retrieveData();
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : GetVosWhereUserIsMember(cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler)

Example 2 with GetVosWhereUserIsMember

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

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 GetVosWhereUserIsMember (cz.metacentrum.perun.webgui.json.usersManager.GetVosWhereUserIsMember)2 ArrayList (java.util.ArrayList)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 GetMemberByUser (cz.metacentrum.perun.webgui.json.membersManager.GetMemberByUser)1 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)1 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)1