Search in sources :

Example 1 with AssignGroupsToResource

use of cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource in project perun by CESNET.

the class ManageGroupsBeforeAssigning method draw.

public Widget draw() {
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    final ListBoxWithObjects<Group> groupsDropDown = new ListBoxWithObjects<Group>();
    for (Group grp : groupsToAssign) {
        groupsDropDown.addItem(grp);
    }
    final ListBoxWithObjects<Group> subgroupsDropDown = new ListBoxWithObjects<Group>();
    subgroupsDropDown.addNotSelectedOption();
    final CustomButton finishAssigningButton = TabMenu.getPredefinedButton(ButtonType.FINISH, ButtonTranslation.INSTANCE.finishGroupAssigning());
    final JsonCallbackEvents closeTabEvents = JsonCallbackEvents.closeTabDisableButtonEvents(finishAssigningButton, this);
    final JsonCallbackEvents disableButtonEvents = JsonCallbackEvents.disableButtonEvents(finishAssigningButton);
    finishAssigningButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // assign all
            if (groupsDropDown.getSelectedIndex() == 0) {
                AssignGroupsToResource request = new AssignGroupsToResource(closeTabEvents);
                request.assignGroupsToResource(groupsToAssign, resource);
            } else {
                // assign selected
                if (groupsDropDown.getSelectedObject() == null) {
                    Window.alert("No group selected");
                    return;
                }
                JsonCallbackEvents localEvents = new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        // call previus events
                        closeTabEvents.onFinished(null);
                        // removed finished group
                        groupsDropDown.removeSelectedItem();
                        if (groupsDropDown.isEmpty()) {
                            // if no group left - close windows
                            closeTabEvents.onFinished(null);
                        }
                    }
                };
                AssignGroupToResources request = new AssignGroupToResources(JsonCallbackEvents.disableButtonEvents(finishAssigningButton, localEvents));
                request.assignGroupToResources(groupsDropDown.getSelectedObject(), JsonUtils.<RichResource>toList(resource));
            }
        }
    });
    menu.addWidget(finishAssigningButton);
    menu.addWidget(new HTML("<strong>Selected group: </strong>"));
    menu.addWidget(groupsDropDown);
    // TODO - get subgroups correctly too
    //menu.addWidget(new HTML("<strong>Configure sub-groups: </strong>"));
    //menu.addWidget(subgroupsDropDown);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    groupsDropDown.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            // removes previous table
            if (vp.getWidgetCount() == 2) {
                vp.remove(1);
            }
            if (groupsDropDown.getSelectedIndex() > 0) {
                /*
					// fill subgroups listbox with groups
					subgroupsDropDown.removeAllOption();
					subgroupsDropDown.removeNotSelectedOption();
					subgroupsDropDown.clear();
					subgroupsDropDown.addNotSelectedOption();
					for (Group grp : findSubgroups(groupsDropDown.getSelectedObject())){
					subgroupsDropDown.addItem(grp);
					}
					subgroupsDropDown.addAllOption();
					*/
                // some group selected
                TabItem ti = new GroupResourceRequiredAttributesTabItem(resourceId, groupsDropDown.getSelectedObject().getId());
                ti.draw();
                Widget w = ti.getWidget();
                vp.add(w);
                vp.setCellHeight(w, "100%");
            } else {
                /*
					//clear listbox
					subgroupsDropDown.removeAllOption();
					subgroupsDropDown.removeNotSelectedOption();
					subgroupsDropDown.clear();
					subgroupsDropDown.addNotSelectedOption();
					subgroupsDropDown.addItem("All");
					*/
                // all groups tab
                TabItem ti = new GroupsResourceRequiredAttributesTabItem(resourceId, groupsToAssign);
                ti.draw();
                Widget w = ti.getWidget();
                vp.add(w);
                vp.setCellHeight(w, "100%");
            }
        }
    });
    /*

			 subgroupsDropDown.addChangeHandler(new ChangeHandler(){
			 public void onChange(ChangeEvent event) {
			 if (vp.getWidgetCount() == 2) { vp.remove(1); } // removes previous table
			 if (subgroupsDropDown.getSelectedIndex() > 1){
// sub-group selected
TabItem ti = new GroupResourceRequiredAttributesTabItem(session, resourceId, subgroupsDropDown.getSelectedObject().getId());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
} else if (subgroupsDropDown.getSelectedIndex() == 1){
// all selected
if (groupsDropDown.getSelectedIndex() > 0) {
// all subgroups of selected group
TabItem ti = new GroupsResourceRequiredAttributesTabItem(session, resourceId, subgroupsDropDown.getAllObjects());
ti.draw();
Widget w = ti.getWidget();
vp.add(w);
vp.setCellHeight(w, "100%");
} else {
		// all groups and subgroups
		TabItem ti = new GroupsResourceRequiredAttributesTabItem(session, resourceId, allGroups);
		ti.draw();
		Widget w = ti.getWidget();
		vp.add(w);
		vp.setCellHeight(w, "100%");
}
} else {
		// parent-group selected / subgroup not selected
		TabItem ti = new GroupResourceRequiredAttributesTabItem(session, resourceId, groupsDropDown.getSelectedObject().getId());
		ti.draw();
		Widget w = ti.getWidget();
		vp.add(w);
		vp.setCellHeight(w, "100%");
}
			 }
			 });

*/
    TabItem ti = new GroupResourceRequiredAttributesTabItem(resourceId, groupsDropDown.getSelectedObject().getId());
    ti.draw();
    Widget w = ti.getWidget();
    vp.add(w);
    vp.setCellHeight(w, "100%");
    groupsDropDown.addAllOption();
    /*
// if some group selected
if (groupsDropDown.getSelectedObject() != null){
// fill subgroups listbox with groups
subgroupsDropDown.addNotSelectedOption();
for (Group grp : findSubgroups(groupsDropDown.getSelectedObject())){
subgroupsDropDown.addItem(grp);
}
subgroupsDropDown.addAllOption();
}
*/
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) RichResource(cz.metacentrum.perun.webgui.model.RichResource) AssignGroupToResources(cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupToResources) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) AssignGroupsToResource(cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GroupsResourceRequiredAttributesTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupsResourceRequiredAttributesTabItem) GroupResourceRequiredAttributesTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupResourceRequiredAttributesTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ListBoxWithObjects(cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects) 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) GroupsResourceRequiredAttributesTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupsResourceRequiredAttributesTabItem) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GroupResourceRequiredAttributesTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupResourceRequiredAttributesTabItem)

Example 2 with AssignGroupsToResource

use of cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource in project perun by CESNET.

the class AssignGroupTabItem method draw.

public Widget draw() {
    titleWidget.setText("Assign group");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // menu
    TabMenu menu = new TabMenu();
    final GetAllGroups voGroups = new GetAllGroups(resource.getVoId());
    voGroups.setCoreGroupsCheckable(true);
    final CellTable<Group> table = voGroups.getEmptyTable(new FieldUpdater<Group, String>() {

        public void update(int index, Group object, String value) {
            session.getTabManager().addTab(new GroupDetailTabItem(object));
        }
    });
    // remove already assigned groups from offering
    voGroups.setEvents(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            final GetAssignedGroups alreadyAssigned = new GetAssignedGroups(resourceId, new JsonCallbackEvents() {

                public void onFinished(JavaScriptObject jso) {
                    JsArray<Group> groupsToRemove = JsonUtils.jsoAsArray(jso);
                    for (int i = 0; i < groupsToRemove.length(); i++) {
                        voGroups.removeFromTable(groupsToRemove.get(i));
                    }
                    // if single group, select
                    if (voGroups.getList().size() == 1) {
                        table.getSelectionModel().setSelected(voGroups.getList().get(0), true);
                    }
                }
            });
            alreadyAssigned.retrieveData();
        }
    });
    // checbox is selected by default
    final CheckBox chb = new CheckBox();
    chb.setText(WidgetTranslation.INSTANCE.configureGroupBeforeAssign());
    chb.setTitle(WidgetTranslation.INSTANCE.configureGroupBeforeAssignTitle());
    chb.setValue(false);
    final TabItem tab = this;
    // button
    final CustomButton assignButton = TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.assignSelectedGroupsToResource());
    assignButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Group> groupsToAssign = voGroups.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(groupsToAssign)) {
                if (chb.getValue() == false) {
                    AssignGroupsToResource request = new AssignGroupsToResource(JsonCallbackEvents.closeTabDisableButtonEvents(assignButton, tab));
                    request.assignGroupsToResource(groupsToAssign, resource);
                }
                if (chb.getValue() == true) {
                    session.getTabManager().addTabToCurrentTab(new ManageGroupsBeforeAssigning(resource, groupsToAssign), true);
                }
            }
        }
    });
    menu.addWidget(assignButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    menu.addFilterWidget(new ExtendedSuggestBox(voGroups.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            voGroups.filterTable(text);
            // if single group, select
            if (voGroups.getList().size() == 1) {
                table.getSelectionModel().setSelected(voGroups.getList().get(0), true);
            }
        }
    }, ButtonTranslation.INSTANCE.filterGroup());
    if (session.isPerunAdmin()) {
        // TODO - now is for testing so perun admin only
        menu.addWidget(chb);
    }
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    assignButton.setEnabled(false);
    JsonUtils.addTableManagedButton(voGroups, table, assignButton);
    voGroups.retrieveData();
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    vp.add(sp);
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Group(cz.metacentrum.perun.webgui.model.Group) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) GetAllGroups(cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) GetAssignedGroups(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups) AssignGroupsToResource(cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) GroupDetailTabItem(cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)2 AssignGroupsToResource (cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupsToResource)2 Group (cz.metacentrum.perun.webgui.model.Group)2 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)2 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 GetAllGroups (cz.metacentrum.perun.webgui.json.groupsManager.GetAllGroups)1 AssignGroupToResources (cz.metacentrum.perun.webgui.json.resourcesManager.AssignGroupToResources)1 GetAssignedGroups (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedGroups)1 RichResource (cz.metacentrum.perun.webgui.model.RichResource)1 GroupDetailTabItem (cz.metacentrum.perun.webgui.tabs.groupstabs.GroupDetailTabItem)1 GroupResourceRequiredAttributesTabItem (cz.metacentrum.perun.webgui.tabs.groupstabs.GroupResourceRequiredAttributesTabItem)1 GroupsResourceRequiredAttributesTabItem (cz.metacentrum.perun.webgui.tabs.groupstabs.GroupsResourceRequiredAttributesTabItem)1 ExtendedSuggestBox (cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox)1 ListBoxWithObjects (cz.metacentrum.perun.webgui.widgets.ListBoxWithObjects)1