Search in sources :

Example 6 with GetAttributesV2

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

the class UserDetailTabItem method loadFacilitySubContent.

private void loadFacilitySubContent(final SimplePanel subContent, final Hyperlink facilityLabel, final ListBoxWithObjects<Facility> listbox) {
    final VerticalPanel entryPanel = new VerticalPanel();
    entryPanel.setSize("100%", "100%");
    subContent.setWidget(entryPanel);
    facilityLabel.setHTML(SafeHtmlUtils.fromSafeConstant("<h2>" + listbox.getSelectedObject().getName() + "</h2>"));
    facilityLabel.setTargetHistoryToken(session.getTabManager().getLinkForTab(new FacilityDetailTabItem(listbox.getSelectedObject())));
    final GetAttributesV2 attributes = new GetAttributesV2();
    attributes.getUserFacilityAttributes(listbox.getSelectedObject().getId(), user.getId());
    TabMenu menu = new TabMenu();
    final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes");
    saveAttrButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", listbox.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", new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", listbox.getSelectedObject().getId());
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, attributes.getList()), true);
        }
    }));
    final CustomButton removeAttrButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove attributes");
    removeAttrButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            ids.put("facility", listbox.getSelectedObject().getId());
            RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
            request.removeAttributes(ids, list);
        }
    });
    menu.addWidget(removeAttrButton);
    entryPanel.add(menu);
    CellTable<Attribute> table = attributes.getTable();
    table.addStyleName("perun-table");
    table.setWidth("100%");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    entryPanel.add(sp);
    // better format
    entryPanel.add(new SimplePanel());
    entryPanel.setCellHeight(entryPanel.getWidget(entryPanel.getWidgetCount() - 1), "100%");
    session.getUiElements().resizeSmallTabPanel(sp, 320, this);
}
Also used : HashMap(java.util.HashMap) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) FacilityDetailTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 7 with GetAttributesV2

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

the class UserDetailTabItem method loadInformationOverview.

// FIXME and TODO - all private methods should be separate TabItems !!! Connect them with user menu etc. ?
private Widget loadInformationOverview() {
    // content
    ScrollPanel scroll = new ScrollPanel();
    VerticalPanel extendedInfoVp = new VerticalPanel();
    extendedInfoVp.setStyleName("perun-table");
    scroll.setWidget(extendedInfoVp);
    scroll.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(scroll, 350, this);
    extendedInfoVp.setWidth("100%");
    // detail header
    Widget userHeader = new HTML("<h2>" + "User details" + "</h2>");
    extendedInfoVp.add(userHeader);
    extendedInfoVp.setCellHeight(userHeader, "30px");
    final TabItem tab = this;
    final JsonCallbackEvents events = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            user = jso.cast();
            tab.draw();
        }
    };
    CustomButton change = new CustomButton("", "Edit user", SmallIcons.INSTANCE.applicationFormEditIcon());
    change.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new EditUserDetailsTabItem(user, events));
        }
    });
    // detail content
    FlexTable layout = new FlexTable();
    layout.setCellSpacing(6);
    // Add some standard form options
    layout.setHTML(0, 0, "<strong>Full&nbsp;name:</strong>");
    layout.setHTML(0, 1, user.getFullNameWithTitles());
    layout.setWidget(0, 2, change);
    layout.setHTML(0, 3, "<strong>User&nbsp;ID:</strong>");
    layout.setHTML(0, 4, String.valueOf(user.getId()));
    layout.setHTML(0, 5, "<strong>User&nbsp;type:</strong>");
    if (user.isServiceUser()) {
        layout.setHTML(0, 6, "Service");
    } else if (user.isSponsoredUser()) {
        layout.setHTML(0, 6, "Sponsored");
    } else {
        layout.setHTML(0, 6, "Person");
    }
    // wrap the content in a DecoratorPanel
    DecoratorPanel decPanel = new DecoratorPanel();
    decPanel.setWidget(layout);
    extendedInfoVp.add(decPanel);
    // user attributes
    final GetAttributesV2 attributes = new GetAttributesV2();
    attributes.getUserAttributes(user.getId());
    CellTable<Attribute> tableAttributes = attributes.getTable();
    tableAttributes.addStyleName("perun-table");
    tableAttributes.setWidth("100%");
    Widget attributesHeader = new HTML("<h2>" + "User attributes" + "</h2>");
    extendedInfoVp.add(attributesHeader);
    extendedInfoVp.setCellHeight(attributesHeader, "30px");
    TabMenu menu = new TabMenu();
    final CustomButton saveAttrButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in attributes for user");
    saveAttrButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            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 user", new ClickHandler() {

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

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = attributes.getTableSelectedList();
            if (list == null || list.isEmpty()) {
                Confirm c = new Confirm("No changes to save", new Label("You must select some attributes to save."), true);
                c.show();
                return;
            }
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("user", userId);
            RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeAttrButton, JsonCallbackEvents.refreshTableEvents(attributes)));
            request.removeAttributes(ids, list);
        }
    });
    menu.addWidget(removeAttrButton);
    extendedInfoVp.add(menu);
    extendedInfoVp.add(tableAttributes);
    // VOS
    GetVosWhereUserIsMember vos = new GetVosWhereUserIsMember(user.getId());
    vos.setCheckable(false);
    // get the table with custom onclick
    CellTable<VirtualOrganization> simpeVosTable = vos.getTable(new FieldUpdater<VirtualOrganization, VirtualOrganization>() {

        public void update(int index, VirtualOrganization object, VirtualOrganization value) {
            session.getTabManager().addTab(new VoDetailTabItem(object));
        }
    });
    // format the table
    simpeVosTable.addStyleName("perun-table");
    simpeVosTable.setWidth("100%");
    // simple table
    Widget vosHeader = new HTML("<h2>" + "Virtual organizations" + "</h2>");
    extendedInfoVp.add(vosHeader);
    extendedInfoVp.setCellHeight(vosHeader, "30px");
    extendedInfoVp.add(simpeVosTable);
    return scroll;
}
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) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) MemberDetailTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.MemberDetailTabItem) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) UsersPublicationsTabItem(cz.metacentrum.perun.webgui.tabs.cabinettabs.UsersPublicationsTabItem) ResourceDetailTabItem(cz.metacentrum.perun.webgui.tabs.resourcestabs.ResourceDetailTabItem) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) FacilityDetailTabItem(cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 8 with GetAttributesV2

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

the class TestDataGridAttributesTabItem method draw.

public Widget draw() {
    //contentWidget.setSize("100%", "100%");
    DockLayoutPanel ft = new DockLayoutPanel(Style.Unit.PX);
    contentWidget.setWidget(ft);
    final DataGrid gridTable = new DataGrid();
    gridTable.setSize("100%", "100%");
    final ArrayList<Attribute> vosList = new ArrayList<Attribute>();
    final GetAttributesV2 getVos = new GetAttributesV2(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosList.addAll(new TableSorter<Attribute>().sortByAttrNameTranslation(JsonUtils.<Attribute>jsoAsList(jso)));
            gridTable.setRowData(vosList);
            gridTable.redraw();
        }
    });
    getVos.getUserAttributes(3411);
    getVos.retrieveData();
    gridTable.setSelectionModel(new MultiSelectionModel<Attribute>(new GeneralKeyProvider<Attribute>()));
    final SelectionModel<Attribute> selectionModel = gridTable.getSelectionModel();
    gridTable.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    Column<Attribute, Boolean> checkBoxColumn = new Column<Attribute, Boolean>(new CheckboxCell(true, true)) {

        @Override
        public Boolean getValue(Attribute object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkBoxColumn.setFieldUpdater(new FieldUpdater<Attribute, Boolean>() {

        @Override
        public void update(int i, Attribute Attribute, Boolean aBoolean) {
            selectionModel.setSelected(Attribute, aBoolean);
        }
    });
    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader = new Header<Boolean>(cb) {

        public Boolean getValue() {
            //return true to see a checked checkbox.
            return false;
        }
    };
    checkBoxHeader.setUpdater(new ValueUpdater<Boolean>() {

        public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (Attribute obj : vosList) {
                selectionModel.setSelected(obj, value);
            }
        }
    });
    gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
    gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
    TextColumn<Attribute> idColumn = new TextColumn<Attribute>() {

        @Override
        public String getValue(Attribute object) {
            return String.valueOf(object.getId());
        }
    };
    if (JsonUtils.isExtendedInfoVisible()) {
        gridTable.addColumn(idColumn, "Id", "Id");
        gridTable.setColumnWidth(idColumn, "90px");
    }
    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());
    // Description column
    Column<Attribute, Attribute> descriptionColumn = JsonUtils.addColumn(new PerunAttributeDescriptionCell());
    // Value column
    Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), new FieldUpdater<Attribute, Attribute>() {

        public void update(int index, Attribute object, Attribute value) {
            object = value;
            selectionModel.setSelected(object, object.isAttributeValid());
        }
    });
    ColumnSortEvent.ListHandler<Attribute> columnSortHandler = new ColumnSortEvent.ListHandler<Attribute>(vosList);
    gridTable.addColumnSortHandler(columnSortHandler);
    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(nameColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_NAME));
    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(descriptionColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_DESCRIPTION));
    // Add sorting
    gridTable.addColumnSortHandler(columnSortHandler);
    // updates the columns size
    gridTable.setColumnWidth(nameColumn, 200.0, Style.Unit.PX);
    gridTable.setColumnWidth(valueColumn, 420.0, Style.Unit.PX);
    gridTable.addColumn(nameColumn, "Name");
    gridTable.addColumn(valueColumn, "Value");
    gridTable.addColumn(descriptionColumn, "Description");
    TabMenu tabMenu = new TabMenu();
    tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.ADD, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().addTabToCurrentTab(new TestDataGridTabItem(), true);
        }
    }));
    ft.addNorth(tabMenu, 50);
    ft.add(gridTable);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) GeneralKeyProvider(cz.metacentrum.perun.webgui.json.keyproviders.GeneralKeyProvider) PerunAttributeNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) PerunAttributeDescriptionCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) DockLayoutPanel(com.google.gwt.user.client.ui.DockLayoutPanel) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 9 with GetAttributesV2

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

the class GroupSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings");
    // Main panel
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    final TabMenu menu = new TabMenu();
    // Adds menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    // IDS
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("group", groupId);
    // define GET ATTRIBUTES callback
    final GetAttributesV2 jsonCallback = new GetAttributesV2(true);
    jsonCallback.setIds(ids);
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        jsonCallback.setCheckable(false);
    final CellTable<Attribute> table = jsonCallback.getEmptyTable();
    table.setWidth("100%");
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    vp.add(sp);
    // define GET RES. REQ ATTRIBUTES callback
    final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(null, JsonCallbackEvents.passDataToAnotherCallback(jsonCallback));
    // GROUP RESOURCES LISTBOX
    final ListBoxWithObjects<Resource> resourceDropDown = new ListBoxWithObjects<Resource>();
    resourceDropDown.setTitle("By selecting a resource you will switch to either group-resource or member-resource setting (you must pick member too)");
    // fill table with group attributes on page load
    if (lastSelectedMemberId == 0 && lastSelectedResourceId == 0) {
        jsonCallback.retrieveData();
    } else {
        // load attrs by listbox selection after calls are done
        Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() {

            @Override
            public boolean execute() {
                // load proper table if something was selected
                if (resCallDone && memCallDone) {
                    // trigger change event
                    DomEvent.fireNativeEvent(Document.get().createChangeEvent(), resourceDropDown);
                    return false;
                }
                return true;
            }
        }, 200);
    }
    // fill resources listbox
    if (resources == null) {
        // get assigned resources
        GetAssignedResources resources = new GetAssignedResources(groupId, PerunEntity.GROUP, new JsonCallbackEvents() {

            public void onFinished(JavaScriptObject jso) {
                ArrayList<Resource> resources = JsonUtils.jsoAsList(jso);
                resourceDropDown.clear();
                if (resources != null && !resources.isEmpty()) {
                    resources = new TableSorter<Resource>().sortByName(resources);
                    resourceDropDown.addNotSelectedOption();
                    for (int i = 0; i < resources.size(); i++) {
                        resourceDropDown.addItem(resources.get(i));
                        if (lastSelectedResourceId == resources.get(i).getId()) {
                            resourceDropDown.setSelected(resources.get(i), true);
                        }
                    }
                } else {
                    resourceDropDown.addItem("No resources available");
                }
                resCallDone = true;
            }

            public void onError(PerunError error) {
                resourceDropDown.clear();
                resourceDropDown.addItem("Error while loading");
                resCallDone = true;
            }

            public void onLoadingStart() {
                resCallDone = false;
                resourceDropDown.clear();
                resourceDropDown.addItem("Loading...");
            }
        });
        resources.retrieveData();
    } else {
        // use predefined resources
        resourceDropDown.addNotSelectedOption();
        resources = new TableSorter<Resource>().sortByName(resources);
        resourceDropDown.addAllItems(resources);
    }
    // GROUP MEMBERS LISTBOX
    final ListBoxWithObjects<RichMember> membersDropDown = new ListBoxWithObjects<RichMember>();
    membersDropDown.setTitle("By selecting a member you will switch to either member or member-resource settings (you must pick resource too)");
    // fill members listbox
    GetGroupRichMembers members = new GetGroupRichMembers(groupId, new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
            membersDropDown.clear();
            if (mems != null && !mems.isEmpty()) {
                mems = new TableSorter<RichMember>().sortByName(mems);
                membersDropDown.addNotSelectedOption();
                for (int i = 0; i < mems.size(); i++) {
                    membersDropDown.addItem(mems.get(i));
                    if (mems.get(i).getId() == lastSelectedMemberId) {
                        membersDropDown.setSelected(mems.get(i), true);
                    }
                }
            } else {
                membersDropDown.addItem("No members available");
            }
            memCallDone = true;
        }

        public void onError(PerunError error) {
            membersDropDown.clear();
            membersDropDown.addItem("Error while loading");
            memCallDone = true;
        }

        public void onLoadingStart() {
            memCallDone = false;
            membersDropDown.clear();
            membersDropDown.addItem("Loading...");
        }
    });
    members.retrieveData();
    // CHECKBOXES "FOR ALL MEMBERS"
    final CheckBox memChb = new CheckBox();
    memChb.setText("To all members");
    memChb.setVisible(false);
    memChb.setTitle("Uses this setting for all members of this group.");
    memChb.setValue(false);
    // SAVE CHANGES BUTTON
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        saveChangesButton.setEnabled(false);
    // click handler to save group and member-user attributes
    final ClickHandler saveAttrsClickHandler = new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // refresh table and disable button a event for GetAttributes
                final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(saveChangesButton, JsonCallbackEvents.refreshTableEvents(jsonCallback));
                if (memChb.getValue() == true) {
                    // to all members selected
                    UiElements.generateInfo(WidgetTranslation.INSTANCE.saveConfirmTitle(), "Same value(s) for selected attribute(s) will be set to ALL members of group.", new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            ArrayList<RichMember> memList = membersDropDown.getAllObjects();
                            for (int i = 0; i < memList.size(); i++) {
                                SetAttributes request = new SetAttributes();
                                if (i == memList.size() - 1) {
                                    request.setEvents(events);
                                } else {
                                    request.setEvents(JsonCallbackEvents.disableButtonEvents(saveChangesButton));
                                }
                                Map<String, Integer> ids = new HashMap<String, Integer>();
                                ids.put("member", memList.get(i).getId());
                                ids.put("workWithUserAttributes", 1);
                                request.setAttributes(ids, list);
                            }
                        }
                    });
                } else {
                    // just one group / memeber
                    SetAttributes request = new SetAttributes(events);
                    request.setAttributes(jsonCallback.getIds(), list);
                }
            }
        }
    };
    // click handler to save required attributes
    final ClickHandler saveReqAttrsClickHandler = new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            // check if not empty
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // refresh table and disable button a event for GetResourceRequiredAttributes
                final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        jsonCallback.clearTable();
                        // set back resourceToGetServicesFrom
                        Map<String, Integer> ids = reqAttrs.getIds();
                        if (ids.containsKey("resource")) {
                            ids.put("resourceToGetServicesFrom", ids.get("resource"));
                        }
                        if (ids.containsKey("user")) {
                            ids.put("workWithUserAttributes", 1);
                        }
                        if (ids.containsKey("resource") && ids.containsKey("group")) {
                            ids.put("workWithGroupAttributes", 1);
                        }
                        reqAttrs.setIds(ids);
                        reqAttrs.retrieveData();
                    }
                });
                final SetAttributes request = new SetAttributes();
                if (memChb.getValue() == true) {
                    // to all members selected
                    UiElements.generateInfo(WidgetTranslation.INSTANCE.saveConfirmTitle(), "Same value(s) for selected attribute(s) will be set to ALL members of group.", new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            ArrayList<RichMember> memList = membersDropDown.getAllObjects();
                            for (int i = 0; i < memList.size(); i++) {
                                if (i == 0) {
                                    events.onLoadingStart();
                                }
                                // trigger disable button if first
                                Map<String, Integer> ids = new HashMap<String, Integer>();
                                ids.put("member", memList.get(i).getId());
                                ids.put("user", memList.get(i).getUserId());
                                ids.put("resource", resourceDropDown.getSelectedObject().getId());
                                ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
                                if (i == memList.size() - 1) {
                                    request.setEvents(events);
                                }
                                // set events to last to get refresh and button enable
                                request.setAttributes(ids, list);
                            }
                        }
                    });
                } else {
                    // group or member
                    // disable button events
                    request.setEvents(events);
                    request.setAttributes(reqAttrs.getIds(), list);
                }
            }
        }
    };
    // REMOVE BUTTON
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        removeButton.setEnabled(false);
    // click handler to remove group and member-user attributes
    final ClickHandler removeAttrsClickHandler = new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // refresh table and disable button a event for GetAttributes
                final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(removeButton, JsonCallbackEvents.refreshTableEvents(jsonCallback));
                final RemoveAttributes request = new RemoveAttributes();
                if (memChb.getValue() == true) {
                    // to all members selected
                    UiElements.generateInfo(WidgetTranslation.INSTANCE.deleteConfirmTitle(), "Selected attribute(s) will be removed from ALL members of group.", new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            ArrayList<RichMember> memList = membersDropDown.getAllObjects();
                            for (int i = 0; i < memList.size(); i++) {
                                // trigger disable button if first
                                if (i == 0) {
                                    events.onLoadingStart();
                                }
                                Map<String, Integer> ids = new HashMap<String, Integer>();
                                ids.put("member", memList.get(i).getId());
                                ids.put("workWithUserAttributes", 1);
                                // set events to last to get refresh and button enable
                                if (i == memList.size() - 1) {
                                    request.setEvents(events);
                                }
                                request.removeAttributes(ids, list);
                            }
                        }
                    });
                } else {
                    // just one group / memeber
                    // disable button events
                    request.setEvents(events);
                    request.removeAttributes(jsonCallback.getIds(), list);
                }
            }
        }
    };
    // click handler to remove ResourceRequiredAttributes
    final ClickHandler removeReqAttrsClickHandler = new ClickHandler() {

        public void onClick(ClickEvent event) {
            final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                // refresh table and disable button a event for GetAttributes
                final JsonCallbackEvents events = JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {

                    public void onFinished(JavaScriptObject jso) {
                        jsonCallback.clearTable();
                        // set back resourceToGetServicesFrom
                        Map<String, Integer> ids = reqAttrs.getIds();
                        if (ids.containsKey("resource")) {
                            ids.put("resourceToGetServicesFrom", ids.get("resource"));
                        }
                        if (ids.containsKey("user")) {
                            ids.put("workWithUserAttributes", 1);
                        }
                        if (ids.containsKey("resource") && ids.containsKey("group")) {
                            ids.put("workWithGroupAttributes", 1);
                        }
                        reqAttrs.setIds(ids);
                        reqAttrs.retrieveData();
                    }
                });
                final RemoveAttributes request = new RemoveAttributes();
                if (memChb.getValue() == true) {
                    // to all members selected
                    UiElements.generateInfo(WidgetTranslation.INSTANCE.deleteConfirmTitle(), "Selected attribute(s) will be removed from ALL members of group.", new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            ArrayList<RichMember> memList = membersDropDown.getAllObjects();
                            for (int i = 0; i < memList.size(); i++) {
                                // trigger disable button if first
                                if (i == 0) {
                                    events.onLoadingStart();
                                }
                                Map<String, Integer> ids = new HashMap<String, Integer>();
                                ids.put("member", memList.get(i).getId());
                                ids.put("user", memList.get(i).getUserId());
                                ids.put("resource", resourceDropDown.getSelectedObject().getId());
                                ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
                                // set events to last to get refresh and button enable
                                if (i == memList.size() - 1) {
                                    request.setEvents(events);
                                }
                                request.removeAttributes(ids, list);
                            }
                        }
                    });
                } else {
                    // just one group / member
                    // disable button events
                    request.setEvents(events);
                    request.removeAttributes(reqAttrs.getIds(), list);
                }
            }
        }
    };
    // SET NEW ATTR BUTTON
    final CustomButton setNewAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes());
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
        setNewAttributeButton.setEnabled(false);
    // click handler
    setNewAttributeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ids.clear();
            if (resourceDropDown.getSelectedIndex() > 0) {
                if (membersDropDown.getSelectedIndex() > 0) {
                    ids.put("member", membersDropDown.getSelectedObject().getId());
                    ids.put("user", membersDropDown.getSelectedObject().getUserId());
                    ids.put("resource", resourceDropDown.getSelectedObject().getId());
                    ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
                } else {
                    ids.put("resource", resourceDropDown.getSelectedObject().getId());
                    ids.put("group", groupId);
                    ids.put("workWithGroupAttributes", 1);
                }
            } else {
                if (membersDropDown.getSelectedIndex() > 0) {
                    ids.put("member", membersDropDown.getSelectedObject().getId());
                    ids.put("user", membersDropDown.getSelectedObject().getUserId());
                } else {
                    ids.put("group", groupId);
                }
            }
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, jsonCallback.getList()), true);
        }
    });
    // ClickHandlersRegistration - save onClicks for GetAttributes
    final ArrayList<HandlerRegistration> clickHandlers = new ArrayList<HandlerRegistration>();
    clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
    clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));
    // DEFINE CHANGE HANDLER FOR ALL DROP DOWNS
    ChangeHandler changeHandler = new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            int resIndex = resourceDropDown.getSelectedIndex();
            int memIndex = membersDropDown.getSelectedIndex();
            // no resource or member selected
            if (resIndex == 0 && memIndex == 0) {
                lastSelectedMemberId = 0;
                lastSelectedResourceId = 0;
                memChb.setValue(false);
                memChb.setVisible(false);
                jsonCallback.clearTable();
                ids.clear();
                ids.put("group", groupId);
                jsonCallback.setIds(ids);
                jsonCallback.retrieveData();
                for (HandlerRegistration handler : clickHandlers) {
                    if (handler != null) {
                        handler.removeHandler();
                    }
                }
                clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
                clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));
            }
            // no resource but member selected
            if (resIndex == 0 && memIndex > 0) {
                lastSelectedMemberId = membersDropDown.getSelectedObject().getId();
                lastSelectedResourceId = 0;
                memChb.setValue(false);
                memChb.setVisible(true);
                jsonCallback.clearTable();
                ids.clear();
                ids.put("member", membersDropDown.getSelectedObject().getId());
                ids.put("workWithUserAttributes", 1);
                jsonCallback.setIds(ids);
                jsonCallback.retrieveData();
                for (HandlerRegistration handler : clickHandlers) {
                    if (handler != null) {
                        handler.removeHandler();
                    }
                }
                clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
                clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));
            }
            // resource and no member selected
            if (resIndex > 0 && memIndex == 0) {
                lastSelectedMemberId = 0;
                lastSelectedResourceId = resourceDropDown.getSelectedObject().getId();
                memChb.setValue(false);
                memChb.setVisible(false);
                jsonCallback.clearTable();
                ids.clear();
                ids.put("group", groupId);
                ids.put("resource", resourceDropDown.getSelectedObject().getId());
                ids.put("resourceToGetServicesFrom", ids.get("resource"));
                ids.put("workWithGroupAttributes", 1);
                reqAttrs.setIds(ids);
                reqAttrs.retrieveData();
                // set ids back to make saveChanges work
                ids.remove("resourceToGetServicesFrom");
                reqAttrs.setIds(ids);
                for (HandlerRegistration handler : clickHandlers) {
                    if (handler != null) {
                        handler.removeHandler();
                    }
                }
                clickHandlers.add(saveChangesButton.addClickHandler(saveReqAttrsClickHandler));
                clickHandlers.add(removeButton.addClickHandler(removeReqAttrsClickHandler));
            }
            // resource and member selected
            if (resIndex > 0 && memIndex > 0) {
                lastSelectedMemberId = membersDropDown.getSelectedObject().getId();
                lastSelectedResourceId = resourceDropDown.getSelectedObject().getId();
                memChb.setValue(false);
                memChb.setVisible(true);
                jsonCallback.clearTable();
                ids.clear();
                ids.put("resource", resourceDropDown.getSelectedObject().getId());
                ids.put("resourceToGetServicesFrom", ids.get("resource"));
                ids.put("member", membersDropDown.getSelectedObject().getId());
                ids.put("workWithUserAttributes", 1);
                reqAttrs.setIds(ids);
                reqAttrs.retrieveData();
                // set ids back to make saveChanges work
                ids.clear();
                ids.put("member", membersDropDown.getSelectedObject().getId());
                ids.put("user", membersDropDown.getSelectedObject().getUser().getId());
                ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
                ids.put("resource", resourceDropDown.getSelectedObject().getId());
                reqAttrs.setIds(ids);
                for (HandlerRegistration handler : clickHandlers) {
                    if (handler != null) {
                        handler.removeHandler();
                    }
                }
                clickHandlers.add(saveChangesButton.addClickHandler(saveReqAttrsClickHandler));
                clickHandlers.add(removeButton.addClickHandler(removeReqAttrsClickHandler));
            }
        }
    };
    // ADD CHANGE HANDLERS TO DROP-DOWN MENUS
    resourceDropDown.addChangeHandler(changeHandler);
    membersDropDown.addChangeHandler(changeHandler);
    // PUT ELEMENTS IN MENU
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    //menu.addWidget(resChb);
    menu.addWidget(memChb);
    menu.addWidget(setNewAttributeButton);
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Resources:</strong>"));
    menu.addWidget(resourceDropDown);
    menu.addWidget(new HTML("<strong>Members:</strong>"));
    menu.addWidget(membersDropDown);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) Scheduler(com.google.gwt.core.client.Scheduler) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) GetAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2) ImageResource(com.google.gwt.resources.client.ImageResource) GetResourceRequiredAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetResourceRequiredAttributesV2) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) GetGroupRichMembers(cz.metacentrum.perun.webgui.json.groupsManager.GetGroupRichMembers) GetAssignedResources(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Aggregations

GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)9 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)8 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)8 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)8 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)8 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)8 SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)8 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)7 Attribute (cz.metacentrum.perun.webgui.model.Attribute)5 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)3 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)3 ImageResource (com.google.gwt.resources.client.ImageResource)2 GetAssignedResources (cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 FacilityDetailTabItem (cz.metacentrum.perun.webgui.tabs.facilitiestabs.FacilityDetailTabItem)2