Search in sources :

Example 1 with AddAutoRegGroups

use of cz.metacentrum.perun.webgui.json.registrarManager.AddAutoRegGroups in project perun by CESNET.

the class AddAutoRegGroupTabItem method draw.

@Override
public Widget draw() {
    titleWidget.setText("Add group for auto registration");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    menu.addWidget(new HTML(""));
    final GetAllGroups groups = new GetAllGroups(vo.getId());
    groups.setCoreGroupsCheckable(false);
    // remove already added union groups from offering
    JsonCallbackEvents localEvents = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // second callback
            final GetAutoRegistrationGroups alreadySet = new GetAutoRegistrationGroups(vo.getId(), new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<Group> esToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < esToRemove.length(); i++) {
                        groups.removeFromTable(esToRemove.get(i));
                    }
                }
            });
            alreadySet.retrieveData();
        }
    };
    groups.setEvents(localEvents);
    final ExtendedSuggestBox box = new ExtendedSuggestBox(groups.getOracle());
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.addSelectedExtSource());
    final TabItem tab = this;
    assignButton.addClickHandler(event -> {
        final ArrayList<Group> availableGroups = groups.getTableSelectedList();
        if (UiElements.cantSaveEmptyListDialogBox(availableGroups)) {
            AddAutoRegGroups request = new AddAutoRegGroups(JsonCallbackEvents.disableButtonEvents(assignButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // clear search
                    box.getSuggestBox().setText("");
                    groups.retrieveData();
                }
            }));
            request.setAutoRegGroups(availableGroups);
        }
    });
    menu.addFilterWidget(box, new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            groups.filterTable(text);
        }
    }, "Filter by name");
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CLOSE, "", clickEvent -> session.getTabManager().closeTab(tab, isRefreshParentOnClose())));
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    CellTable<Group> table = groups.getTable();
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(groups, table, assignButton);
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    // do not use resizePerunTable() when tab is in overlay - wrong width is calculated
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ImageResource(com.google.gwt.resources.client.ImageResource) SmallIcons(cz.metacentrum.perun.webgui.client.resources.SmallIcons) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) AddAutoRegGroups(cz.metacentrum.perun.webgui.json.registrarManager.AddAutoRegGroups) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) HTML(com.google.gwt.user.client.ui.HTML) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) ArrayList(java.util.ArrayList) Label(com.google.gwt.user.client.ui.Label) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel) ButtonTranslation(cz.metacentrum.perun.webgui.client.localization.ButtonTranslation) UiElements(cz.metacentrum.perun.webgui.client.UiElements) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) GetAutoRegistrationGroups(cz.metacentrum.perun.webgui.json.registrarManager.GetAutoRegistrationGroups) Group(cz.metacentrum.perun.webgui.model.Group) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) MainMenu(cz.metacentrum.perun.webgui.client.mainmenu.MainMenu) PerunWebSession(cz.metacentrum.perun.webgui.client.PerunWebSession) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) JsArray(com.google.gwt.core.client.JsArray) Widget(com.google.gwt.user.client.ui.Widget) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ButtonType(cz.metacentrum.perun.webgui.client.resources.ButtonType) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) CellTable(com.google.gwt.user.cellview.client.CellTable) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) Group(cz.metacentrum.perun.webgui.model.Group) JsArray(com.google.gwt.core.client.JsArray) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) HTML(com.google.gwt.user.client.ui.HTML) AddAutoRegGroups(cz.metacentrum.perun.webgui.json.registrarManager.AddAutoRegGroups) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetAutoRegistrationGroups(cz.metacentrum.perun.webgui.json.registrarManager.GetAutoRegistrationGroups) ScrollPanel(com.google.gwt.user.client.ui.ScrollPanel)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsArray (com.google.gwt.core.client.JsArray)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 CellTable (com.google.gwt.user.cellview.client.CellTable)1 HTML (com.google.gwt.user.client.ui.HTML)1 Label (com.google.gwt.user.client.ui.Label)1 ScrollPanel (com.google.gwt.user.client.ui.ScrollPanel)1 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)1 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)1 Widget (com.google.gwt.user.client.ui.Widget)1 PerunWebSession (cz.metacentrum.perun.webgui.client.PerunWebSession)1 UiElements (cz.metacentrum.perun.webgui.client.UiElements)1 ButtonTranslation (cz.metacentrum.perun.webgui.client.localization.ButtonTranslation)1 MainMenu (cz.metacentrum.perun.webgui.client.mainmenu.MainMenu)1 ButtonType (cz.metacentrum.perun.webgui.client.resources.ButtonType)1 PerunSearchEvent (cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent)1 SmallIcons (cz.metacentrum.perun.webgui.client.resources.SmallIcons)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 JsonUtils (cz.metacentrum.perun.webgui.json.JsonUtils)1 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)1