Search in sources :

Example 56 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class MemberOverviewTabItem method draw.

public Widget draw() {
    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(member.getUser().getFullNameWithTitles().trim()));
    // main widget panel
    ScrollPanel vp = new ScrollPanel();
    vp.setSize("100%", "100%");
    VerticalPanel innerVp = new VerticalPanel();
    innerVp.setSize("100%", "100%");
    vp.add(innerVp);
    TabMenu menu = new TabMenu();
    innerVp.add(menu);
    innerVp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    session.getUiElements().resizeSmallTabPanel(vp, 400);
    FlexTable layout = new FlexTable();
    layout.setSize("100%", "100%");
    innerVp.add(layout);
    layout.setHTML(0, 0, "<p>Personal:");
    layout.setHTML(0, 1, "<p>Membership:");
    layout.getFlexCellFormatter().setWidth(0, 0, "50%");
    layout.getFlexCellFormatter().setWidth(0, 1, "50%");
    layout.getFlexCellFormatter().setStyleName(0, 0, "subsection-heading");
    layout.getFlexCellFormatter().setStyleName(0, 1, "subsection-heading");
    // if attribute not set
    final String notSet = "<i>N/A</i>";
    final FlexTable personalLayout = new FlexTable();
    layout.setWidget(1, 0, personalLayout);
    personalLayout.setStyleName("inputFormFlexTableDark");
    personalLayout.setHTML(0, 0, "Organization:");
    personalLayout.setHTML(1, 0, "Workplace:");
    personalLayout.setHTML(2, 0, "Research group:");
    personalLayout.setHTML(3, 0, "Preferred mail:");
    personalLayout.setHTML(4, 0, "Mail:");
    personalLayout.setHTML(5, 0, "Phone:");
    personalLayout.setHTML(6, 0, "Address:");
    personalLayout.setHTML(7, 0, "Preferred language:");
    personalLayout.setHTML(8, 0, "LoA:");
    personalLayout.setHTML(9, 0, "EDU person affiliation:");
    // one empty cell to create empty column
    personalLayout.setHTML(0, 1, "&nbsp;");
    personalLayout.getFlexCellFormatter().setWidth(0, 1, "70%");
    // style personal table
    for (int i = 0; i < personalLayout.getRowCount(); i++) {
        personalLayout.getFlexCellFormatter().addStyleName(i, 0, "itemName");
    }
    // Membership table
    final FlexTable memberLayout = new FlexTable();
    layout.setWidget(1, 1, memberLayout);
    layout.getFlexCellFormatter().setVerticalAlignment(1, 1, HasVerticalAlignment.ALIGN_TOP);
    memberLayout.setStyleName("inputFormFlexTableDark");
    memberLayout.setHTML(0, 0, "Status:");
    final PerunStatusWidget<RichMember> statusWidget;
    if (session.isVoAdmin(member.getVoId())) {
        JsonCallbackEvents event = new JsonCallbackEvents() {

            @Override
            public void onFinished(JavaScriptObject jso) {
                // UPDATE OBJECT
                Member m = jso.cast();
                member.setStatus(m.getStatus());
            }
        };
        statusWidget = new PerunStatusWidget<RichMember>(member, member.getUser().getFullName(), event);
    } else {
        statusWidget = new PerunStatusWidget<RichMember>(member, member.getUser().getFullName(), null);
    }
    memberLayout.setWidget(0, 1, statusWidget);
    memberLayout.getFlexCellFormatter().setRowSpan(0, 0, 2);
    if (member.getStatus().equalsIgnoreCase("VALID")) {
        memberLayout.setHTML(1, 0, "Member is properly configured and have access on provided resources.");
    } else if (member.getStatus().equalsIgnoreCase("INVALID")) {
        memberLayout.setHTML(1, 0, "Member have configuration error and DON'T have access on provided resources. You can check what is wrong by changing member's status to VALID. If possible, procedure will configure all necessary settings by itself.");
    } else if (member.getStatus().equalsIgnoreCase("SUSPENDED")) {
        memberLayout.setHTML(1, 0, "Member violated some rules and DON'T have access on provided resources.");
    } else if (member.getStatus().equalsIgnoreCase("EXPIRED")) {
        memberLayout.setHTML(1, 0, "Member didn't extend membership and DON'T have access on provided resources.");
    } else if (member.getStatus().equalsIgnoreCase("DISABLED")) {
        memberLayout.setHTML(1, 0, "Member didn't extend membership long time ago or was manually disabled and DON'T have access on provided resources.");
    }
    memberLayout.getFlexCellFormatter().setStyleName(1, 0, "inputFormInlineComment");
    memberLayout.setHTML(2, 0, "Expiration:");
    memberLayout.setHTML(3, 0, "Member type:");
    if (member.getUser().isServiceUser()) {
        memberLayout.setHTML(3, 1, "Service");
    } else if (member.getUser().isSponsoredUser()) {
        memberLayout.setHTML(3, 1, "Sponsored");
    } else {
        memberLayout.setHTML(3, 1, "Person");
    }
    memberLayout.setHTML(4, 0, "Sponsored by:");
    memberLayout.setHTML(5, 0, "Member ID:");
    memberLayout.setHTML(5, 1, member.getId() + "");
    memberLayout.setHTML(6, 0, "User ID:");
    memberLayout.setHTML(6, 1, member.getUser().getId() + "");
    if (session.isVoAdmin(member.getVoId())) {
        CustomButton resetButton = new CustomButton("Send password reset request…", "", SmallIcons.INSTANCE.keyIcon(), new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                session.getTabManager().addTabToCurrentTab(new SendPasswordResetRequestTabItem(member));
            }
        });
        memberLayout.setHTML(7, 0, "Password reset");
        memberLayout.setWidget(7, 1, resetButton);
    }
    // style member table
    for (int i = 0; i < memberLayout.getRowCount(); i++) {
        if (i != 1) {
            memberLayout.getFlexCellFormatter().addStyleName(i, 0, "itemName");
        }
    }
    // attributes to load
    ArrayList<String> attrs = new ArrayList<String>();
    // TODO - switch all personal to member attrs
    attrs.add("urn:perun:user:attribute-def:def:organization");
    attrs.add("urn:perun:user:attribute-def:def:workplace");
    attrs.add("urn:perun:user:attribute-def:opt:researchGroup");
    attrs.add("urn:perun:member:attribute-def:def:mail");
    attrs.add("urn:perun:user:attribute-def:def:preferredMail");
    attrs.add("urn:perun:user:attribute-def:def:phone");
    attrs.add("urn:perun:user:attribute-def:def:address");
    attrs.add("urn:perun:user:attribute-def:def:preferredLanguage");
    attrs.add("urn:perun:member:attribute-def:virt:loa");
    attrs.add("urn:perun:member:attribute-def:def:membershipExpiration");
    attrs.add("urn:perun:member:attribute-def:opt:eduPersonAffiliation");
    attrs.add("urn:perun:member:attribute-def:def:sponzoredMember");
    HashMap<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("member", memberId);
    ids.put("workWithUserAttributes", 1);
    GetListOfAttributes attrsCall = new GetListOfAttributes();
    attrsCall.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            ArrayList<Attribute> list = JsonUtils.jsoAsList(jso);
            if (list != null && !list.isEmpty()) {
                for (Attribute a : list) {
                    String value = a.getValue();
                    if (a.getName().equalsIgnoreCase("urn:perun:user:attribute-def:def:organization")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(0, 1, value);
                        } else {
                            personalLayout.setHTML(0, 1, notSet);
                        }
                    // set default value width
                    } else if (a.getName().equalsIgnoreCase("urn:perun:user:attribute-def:def:workplace")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(1, 1, value);
                        } else {
                            personalLayout.setHTML(1, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:user:attribute-def:opt:researchGroup")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(2, 1, value);
                        } else {
                            personalLayout.setHTML(2, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:user:attribute-def:def:preferredMail")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(3, 1, value);
                        } else {
                            personalLayout.setHTML(3, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:member:attribute-def:def:mail")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(4, 1, value);
                        } else {
                            personalLayout.setHTML(4, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:user:attribute-def:def:phone")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(5, 1, value);
                        } else {
                            personalLayout.setHTML(5, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:user:attribute-def:def:address")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(6, 1, value);
                        } else {
                            personalLayout.setHTML(6, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:user:attribute-def:def:preferredLanguage")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(7, 1, value);
                        } else {
                            personalLayout.setHTML(7, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:member:attribute-def:virt:loa")) {
                        if (!"null".equals(value)) {
                            String text = "";
                            if (value.equals("0")) {
                                text = " (not verified = default)";
                            } else if (value.equals("1")) {
                                text = " (verified email)";
                            } else if (value.equals("2")) {
                                text = " (verified identity)";
                            } else if (value.equals("3")) {
                                text = " (verified identity, strict password strength)";
                            }
                            personalLayout.setHTML(8, 1, value + text);
                        } else {
                            personalLayout.setHTML(8, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:member:attribute-def:opt:eduPersonAffiliation")) {
                        if (!"null".equals(value)) {
                            personalLayout.setHTML(9, 1, value);
                        } else {
                            personalLayout.setHTML(9, 1, notSet);
                        }
                    } else if (a.getName().equalsIgnoreCase("urn:perun:member:attribute-def:def:membershipExpiration")) {
                        // set attribute inside member
                        member.setAttribute(a);
                        memberLayout.setWidget(2, 1, new MembershipExpirationWidget(member));
                    } else if (a.getName().equalsIgnoreCase("urn:perun:member:attribute-def:def:sponzoredMember")) {
                        if (!"null".equals(value)) {
                            memberLayout.setHTML(4, 1, value + " (ID of RT ticket with explanation)");
                        } else {
                            memberLayout.setHTML(4, 1, "<i>N/A</i>");
                        }
                    }
                }
            }
        }

        @Override
        public void onError(PerunError error) {
            String text = "<span style=\"color: red\">Error while loading";
            for (int i = 0; i < personalLayout.getRowCount(); i++) {
                personalLayout.setHTML(i, 1, text);
            }
            memberLayout.setHTML(2, 1, text);
            memberLayout.setHTML(4, 1, text);
        }

        @Override
        public void onLoadingStart() {
            for (int i = 0; i < personalLayout.getRowCount(); i++) {
                personalLayout.setWidget(i, 1, new Image(AjaxLoaderImage.SMALL_IMAGE_URL));
            }
            memberLayout.setWidget(2, 1, new Image(AjaxLoaderImage.SMALL_IMAGE_URL));
            memberLayout.setWidget(4, 1, new Image(AjaxLoaderImage.SMALL_IMAGE_URL));
        }
    });
    attrsCall.getListOfAttributes(ids, attrs);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) AjaxLoaderImage(cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) Member(cz.metacentrum.perun.webgui.model.Member) RichMember(cz.metacentrum.perun.webgui.model.RichMember) MembershipExpirationWidget(cz.metacentrum.perun.webgui.widgets.MembershipExpirationWidget) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) RichMember(cz.metacentrum.perun.webgui.model.RichMember) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 57 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class MemberSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(member.getUser().getFullNameWithTitles().trim()) + ": Settings");
    // CONTENT WIDGET
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    // MENU
    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    // callbacks
    final GetAttributesV2 callback = new GetAttributesV2(true);
    if (!session.isVoAdmin(member.getVoId()) && !session.isGroupAdmin(groupId)) {
        callback.setCheckable(false);
    }
    // member & user attrs
    callback.getMemberAttributes(member.getId(), 1);
    final CellTable<Attribute> table = callback.getEmptyTable();
    // others callbacks
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("member", member.getId());
    // work with user
    ids.put("workWithUserAttributes", 1);
    final GetResourceRequiredAttributesV2 resourceRequired = new GetResourceRequiredAttributesV2(ids, JsonCallbackEvents.passDataToAnotherCallback(callback));
    final GetRequiredAttributes required = new GetRequiredAttributes(ids, JsonCallbackEvents.passDataToAnotherCallback(callback));
    if (lastSelectedFilterIndex == 1 || lastSelectedResourceId == 0) {
        // load required by default
        required.retrieveData();
    }
    // listbox with resources
    final ListBoxWithObjects<Resource> listbox = new ListBoxWithObjects<Resource>();
    // listbox for filtering attributes callbacks
    final ListBox filter = new ListBox();
    filter.addItem("All filled attributes");
    filter.addItem("Required");
    filter.addItem("Resource required");
    // required as default
    filter.setSelectedIndex(lastSelectedFilterIndex);
    // change table on selection one of the listboxs
    final ChangeHandler changehandler = new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            // if resource selected
            if (listbox.getSelectedIndex() > 0) {
                // if all attributes
                if (filter.getSelectedIndex() == 0) {
                    callback.clearTable();
                    // with user
                    callback.getMemberAttributes(member.getId(), 1);
                    callback.retrieveData();
                    callback.getMemberResourceAttributes(member.getId(), listbox.getSelectedObject().getId());
                    callback.retrieveData();
                    callback.getUserFacilityAttributes(listbox.getSelectedObject().getFacilityId(), member.getUser().getId());
                    callback.retrieveData();
                // if required attributes
                } else if (filter.getSelectedIndex() == 1) {
                    callback.clearTable();
                    ids.clear();
                    UiElements.generateInfo("Not valid option", "Skipping to \"Resource required\" option.");
                    filter.setSelectedIndex(2);
                    lastSelectedFilterIndex = 2;
                    ids.put("member", member.getId());
                    ids.put("resource", listbox.getSelectedObject().getId());
                    ids.put("resourceToGetServicesFrom", listbox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    resourceRequired.retrieveData();
                // if resource required
                } else if (filter.getSelectedIndex() == 2) {
                    callback.clearTable();
                    ids.clear();
                    ids.put("member", member.getId());
                    ids.put("resource", listbox.getSelectedObject().getId());
                    ids.put("resourceToGetServicesFrom", listbox.getSelectedObject().getId());
                    ids.put("workWithUserAttributes", 1);
                    resourceRequired.retrieveData();
                }
            // if no resource selected
            } else {
                // if all attributes
                if (filter.getSelectedIndex() == 0) {
                    callback.clearTable();
                    callback.getMemberAttributes(member.getId(), 1);
                    callback.retrieveData();
                // if required attributes
                } else if (filter.getSelectedIndex() == 1) {
                    callback.clearTable();
                    ids.clear();
                    ids.put("member", member.getId());
                    ids.put("workWithUserAttributes", 1);
                    required.retrieveData();
                // if resource required
                } else if (filter.getSelectedIndex() == 2) {
                    callback.clearTable();
                    ((AjaxLoaderImage) table.getEmptyTableWidget()).loadingFinished();
                    UiElements.generateInfo("Not valid option", "You must select resource first.");
                }
            }
        }
    };
    ChangeHandler resourceChangeHandler = new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            if (listbox.getSelectedIndex() > 0) {
                // if resource selected
                // load resource-required (by default)
                filter.setSelectedIndex(2);
                lastSelectedFilterIndex = 2;
            } else {
                // else load required by default
                filter.setSelectedIndex(1);
                lastSelectedFilterIndex = 1;
            }
            if (listbox.getSelectedObject() != null) {
                lastSelectedResourceId = listbox.getSelectedObject().getId();
            } else {
                lastSelectedResourceId = 0;
            }
            changehandler.onChange(event);
        }
    };
    ChangeHandler filterChangeHandler = new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            // if required and resource selected
            if (filter.getSelectedIndex() == 1 && listbox.getSelectedIndex() > 0) {
                // cance resource selection
                listbox.setSelectedIndex(0);
                lastSelectedResourceId = 0;
            }
            lastSelectedFilterIndex = filter.getSelectedIndex();
            changehandler.onChange(event);
        }
    };
    // refresh table on listbox change
    listbox.addChangeHandler(resourceChangeHandler);
    filter.addChangeHandler(filterChangeHandler);
    // fill listbox with member's resources
    JsonCallbackEvents events = new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            listbox.clear();
            ArrayList<Resource> res = JsonUtils.jsoAsList(jso);
            res = new TableSorter<Resource>().sortByName(res);
            if (res != null && !res.isEmpty()) {
                listbox.addNotSelectedOption();
            } else {
                listbox.addItem("No resource available");
            }
            for (int i = 0; i < res.size(); i++) {
                listbox.addItem(res.get(i));
                // select last selected
                if (res.get(i).getId() == lastSelectedResourceId) {
                    listbox.setSelected(res.get(i), true);
                }
            }
            if (lastSelectedFilterIndex != 1 && lastSelectedResourceId != 0) {
                DomEvent.fireNativeEvent(Document.get().createChangeEvent(), filter);
            }
        }

        public void onLoadingStart() {
            listbox.clear();
            listbox.addItem("Loading...");
        }

        public void onError(PerunError error) {
            listbox.clear();
            listbox.addItem("Error while loading");
        }
    };
    // get member resources
    GetAssignedResources res = new GetAssignedResources(member.getId(), PerunEntity.MEMBER, events);
    res.retrieveData();
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    // save changes in attributes
    final CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    if (!session.isVoAdmin(member.getVoId()) && !session.isGroupAdmin(groupId))
        saveChangesButton.setEnabled(false);
    saveChangesButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
                // if resource selected
                if (listbox.getSelectedIndex() > 0) {
                    // if all attributes
                    SetAttributes request;
                    if (filter.getSelectedIndex() == 0) {
                        request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                callback.clearTable();
                                // with user
                                callback.getMemberAttributes(member.getId(), 1);
                                callback.retrieveData();
                                callback.getMemberResourceAttributes(member.getId(), listbox.getSelectedObject().getId());
                                callback.retrieveData();
                                callback.getUserFacilityAttributes(listbox.getSelectedObject().getFacilityId(), member.getUser().getId());
                                callback.retrieveData();
                            }
                        }));
                    } else {
                        // if required or resource-required
                        request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                callback.clearTable();
                                ids.clear();
                                ids.put("member", member.getId());
                                ids.put("resource", listbox.getSelectedObject().getId());
                                ids.put("resourceToGetServicesFrom", listbox.getSelectedObject().getId());
                                ids.put("workWithUserAttributes", 1);
                                resourceRequired.retrieveData();
                            }
                        }));
                    }
                    // make setAttributesCall
                    ids.clear();
                    ids.put("member", member.getId());
                    ids.put("resource", listbox.getSelectedObject().getId());
                    ids.put("facility", listbox.getSelectedObject().getFacilityId());
                    ids.put("user", member.getUserId());
                    request.setAttributes(ids, callback.getTableSelectedList());
                } else {
                    // if resource not selected
                    SetAttributes request;
                    if (filter.getSelectedIndex() == 1) {
                        // if required attr option - refresh different callback
                        request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                callback.clearTable();
                                required.retrieveData();
                            }
                        }));
                    } else {
                        request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveChangesButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                callback.clearTable();
                                callback.retrieveData();
                            }
                        }));
                    }
                    // make setAttributes call
                    ids.clear();
                    ids.put("member", member.getId());
                    ids.put("workWithUserAttributes", 1);
                    request.setAttributes(ids, callback.getTableSelectedList());
                }
            }
        }
    });
    menu.addWidget(saveChangesButton);
    // buttons
    CustomButton setNewMemberAttributeButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("member", member.getId());
            ids.put("user", member.getUser().getId());
            if (listbox.getSelectedIndex() > 0) {
                ids.put("resource", listbox.getSelectedObject().getId());
                ids.put("facility", listbox.getSelectedObject().getFacilityId());
            }
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids), true);
        }
    });
    if (!session.isVoAdmin(member.getVoId()) && !session.isGroupAdmin(groupId))
        setNewMemberAttributeButton.setEnabled(false);
    menu.addWidget(setNewMemberAttributeButton);
    // REMOVE ATTRIBUTES BUTTON
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    removeButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // if selected
            if (UiElements.cantSaveEmptyListDialogBox(callback.getTableSelectedList())) {
                // if resource selected
                if (listbox.getSelectedIndex() > 0) {
                    // if all attributes
                    RemoveAttributes request;
                    if (filter.getSelectedIndex() == 0) {
                        request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                callback.clearTable();
                                // with user
                                callback.getMemberAttributes(member.getId(), 1);
                                callback.retrieveData();
                                callback.getMemberResourceAttributes(member.getId(), listbox.getSelectedObject().getId());
                                callback.retrieveData();
                                callback.getUserFacilityAttributes(listbox.getSelectedObject().getFacilityId(), member.getUser().getId());
                                callback.retrieveData();
                            }
                        }));
                    } else {
                        // if required or resource-required
                        request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                callback.clearTable();
                                ids.clear();
                                ids.put("member", member.getId());
                                ids.put("resource", listbox.getSelectedObject().getId());
                                ids.put("resourceToGetServicesFrom", listbox.getSelectedObject().getId());
                                ids.put("workWithUserAttributes", 1);
                                resourceRequired.retrieveData();
                            }
                        }));
                    }
                    // make removeAttributesCall
                    ids.clear();
                    ids.put("member", member.getId());
                    ids.put("resource", listbox.getSelectedObject().getId());
                    ids.put("facility", listbox.getSelectedObject().getFacilityId());
                    ids.put("user", member.getUserId());
                    request.removeAttributes(ids, callback.getTableSelectedList());
                } else {
                    // if resource not selected
                    RemoveAttributes request;
                    if (filter.getSelectedIndex() == 1) {
                        // if required attr option - refresh different callback
                        request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                callback.clearTable();
                                required.retrieveData();
                            }
                        }));
                    } else {
                        request = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(removeButton, new JsonCallbackEvents() {

                            public void onFinished(JavaScriptObject jso) {
                                callback.clearTable();
                                callback.retrieveData();
                            }
                        }));
                    }
                    // make removeAttributes call
                    ids.clear();
                    ids.put("member", member.getId());
                    ids.put("workWithUserAttributes", 1);
                    request.removeAttributes(ids, callback.getTableSelectedList());
                }
            }
        }
    });
    removeButton.setEnabled(false);
    if (session.isVoAdmin(member.getVoId()) || session.isGroupAdmin(groupId))
        JsonUtils.addTableManagedButton(callback, table, removeButton);
    menu.addWidget(removeButton);
    // add listbox to menu
    menu.addWidget(new HTML("<strong>Assigned resources: </strong>"));
    menu.addWidget(listbox);
    menu.addWidget(new HTML("<strong>Filter: </strong>"));
    menu.addWidget(filter);
    // ATTRIBUTES TABLE
    vp.add(sp);
    vp.setCellHeight(sp, "100%");
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) HashMap(java.util.HashMap) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) SetNewAttributeTabItem(cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem) ImageResource(com.google.gwt.resources.client.ImageResource) Resource(cz.metacentrum.perun.webgui.model.Resource) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) PerunError(cz.metacentrum.perun.webgui.model.PerunError) GetAssignedResources(cz.metacentrum.perun.webgui.json.resourcesManager.GetAssignedResources) HashMap(java.util.HashMap) Map(java.util.Map)

Example 58 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class SendPasswordResetRequestTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Send password reset request");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("300px", "100%");
    final FlexTable layout = new FlexTable();
    layout.setSize("100%", "100%");
    layout.setStyleName("inputFormFlexTable");
    layout.setHTML(0, 0, "Select namespace:");
    layout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    layout.setHTML(1, 0, "Login:");
    layout.getFlexCellFormatter().setStyleName(1, 0, "itemName");
    final ListBox namespaces = new ListBox();
    layout.setWidget(0, 1, namespaces);
    final CustomButton changeButton = new CustomButton("Send", "Send email with reset password link", SmallIcons.INSTANCE.emailIcon());
    GetLogins logins = new GetLogins(member.getUserId(), new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            namespaces.clear();
            ArrayList<Attribute> logins = JsonUtils.jsoAsList(jso);
            if (logins != null && !logins.isEmpty()) {
                changeButton.setEnabled(true);
                for (Attribute a : logins) {
                    if (Utils.getSupportedPasswordNamespaces().contains(a.getFriendlyNameParameter())) {
                        namespaces.addItem(a.getFriendlyNameParameter().toUpperCase(), a.getValue());
                        layout.setHTML(1, 1, a.getValue());
                    }
                }
            }
        }

        public void onLoadingStart() {
            changeButton.setEnabled(false);
            namespaces.clear();
            namespaces.addItem("Loading...");
        }

        public void onError(PerunError error) {
            namespaces.clear();
            namespaces.addItem("Error while loading");
        }
    });
    logins.retrieveData();
    namespaces.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            layout.setHTML(1, 1, namespaces.getValue(namespaces.getSelectedIndex()));
        }
    });
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    // by default false
    changeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            SendPasswordResetLinkEmail request = new SendPasswordResetLinkEmail(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
            request.sendEmail(member, namespaces.getItemText(namespaces.getSelectedIndex()).toLowerCase());
        }
    });
    menu.addWidget(changeButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, ButtonTranslation.INSTANCE.cancelButton(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) GetLogins(cz.metacentrum.perun.webgui.json.attributesManager.GetLogins) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) 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) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError) SendPasswordResetLinkEmail(cz.metacentrum.perun.webgui.json.membersManager.SendPasswordResetLinkEmail)

Aggregations

Attribute (cz.metacentrum.perun.webgui.model.Attribute)58 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)17 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)17 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)16 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)16 ArrayList (java.util.ArrayList)16 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)15 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)15 HashMap (java.util.HashMap)14 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)12 PerunError (cz.metacentrum.perun.webgui.model.PerunError)10 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)9 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)9 Map (java.util.Map)9 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)8 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)7 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)7 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)7 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)7 Column (com.google.gwt.user.cellview.client.Column)6