Search in sources :

Example 11 with SetAttributes

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

the class VoSettingsTabItem method draw.

public Widget draw() {
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(vo.getName()) + ": settings");
    // MAIN PANEL
    VerticalPanel firstTabPanel = new VerticalPanel();
    firstTabPanel.setSize("100%", "100%");
    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    // refresh
    menu.addWidget(UiElements.getRefreshButton(this));
    // Get Attributes
    final GetAttributesV2 jsonCallback = new GetAttributesV2();
    // We want VO attributes
    jsonCallback.getVoAttributes(voId);
    // get the table
    CellTable<Attribute> table = jsonCallback.getTable();
    if (!session.isVoAdmin(voId))
        jsonCallback.setCheckable(false);
    final CustomButton setButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    menu.addWidget(setButton);
    if (!session.isVoAdmin(voId))
        setButton.setEnabled(false);
    // refresh table
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(jsonCallback);
    // set button event with button disable
    final JsonCallbackEvents setButtonEvent = JsonCallbackEvents.disableButtonEvents(setButton, events);
    setButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("vo", voId);
                SetAttributes request = new SetAttributes(setButtonEvent);
                request.setAttributes(ids, list);
            }
        }
    });
    CustomButton addButton = TabMenu.getPredefinedButton(ButtonType.ADD, true, ButtonTranslation.INSTANCE.setNewAttributes(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Map<String, Integer> ids = new HashMap<String, Integer>();
            ids.put("vo", voId);
            session.getTabManager().addTabToCurrentTab(new SetNewAttributeTabItem(ids, jsonCallback.getList()), true);
        }
    });
    menu.addWidget(addButton);
    if (!session.isVoAdmin(voId))
        addButton.setEnabled(false);
    // remove attr button
    final CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    menu.addWidget(removeButton);
    if (!session.isVoAdmin(voId))
        removeButton.setEnabled(false);
    // remove button event
    final JsonCallbackEvents removeButtonEvent = JsonCallbackEvents.disableButtonEvents(removeButton, events);
    removeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("vo", voId);
                RemoveAttributes request = new RemoveAttributes(removeButtonEvent);
                request.removeAttributes(ids, list);
            }
        }
    });
    // add a class to the table and wrap it into scroll panel
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    if (session.isVoAdmin(voId))
        JsonUtils.addTableManagedButton(jsonCallback, table, removeButton);
    // add menu and the table to the main panel
    firstTabPanel.add(menu);
    firstTabPanel.setCellHeight(menu, "30px");
    firstTabPanel.add(sp);
    session.getUiElements().resizePerunTable(sp, 350, this);
    this.contentWidget.setWidget(firstTabPanel);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) 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) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) 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 12 with SetAttributes

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

the class PerunAttributeTableWidget method save.

/**
 * Saves the attributes
 * If attribute with value null, asks if remove it
 * Called recursively
 *
 * @param attrs
 */
private void save(final ArrayList<Attribute> attrs) {
    // call the method
    if (saveEvent == null) {
        // ids must be set
        if (ids == null || ids.isEmpty())
            return;
        final ArrayList<Attribute> toSet = new ArrayList<Attribute>();
        final ArrayList<Attribute> toRemove = new ArrayList<Attribute>();
        for (Attribute a : attrs) {
            Object oldValue = originalAttributes.get(a.getId());
            if (a.getValue().equals(oldValue)) {
            // do not save not changed
            } else if (a.getValueAsObject() == null) {
                toRemove.add(a);
            } else {
                toSet.add(a);
            }
        }
        if (!toSet.isEmpty()) {
            SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // for all attributes to be saved/removed
                    for (Attribute a : toSet) {
                        originalAttributes.put(a.getId(), a.getValueAsObject());
                    }
                }
            }));
            request.setAttributes(ids, toSet);
        }
        if (!toRemove.isEmpty()) {
            RemoveAttributes request2 = new RemoveAttributes(JsonCallbackEvents.disableButtonEvents(saveButton, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // for all attributes to be saved/removed
                    for (Attribute a : toRemove) {
                        originalAttributes.put(a.getId(), a.getValueAsObject());
                    }
                }
            }));
            request2.removeAttributes(ids, toRemove);
        }
        if (toSet.isEmpty() && toRemove.isEmpty()) {
            UiElements.generateAlert("No changes", "No changes to save.");
        }
        return;
    }
    saveEvent.save(attrs);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 13 with SetAttributes

use of cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes 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>" + SafeHtmlUtils.fromString((listbox.getSelectedObject().getName() != null) ? listbox.getSelectedObject().getName() : "").asString() + "</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 14 with SetAttributes

use of cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes 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, SafeHtmlUtils.fromString((user.getFullNameWithTitles() != null) ? user.getFullNameWithTitles() : "").asString());
    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) ChangeStatusTabItem(cz.metacentrum.perun.webgui.tabs.memberstabs.ChangeStatusTabItem) 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 15 with SetAttributes

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

the class SelfPersonalTabItem method draw.

public Widget draw() {
    // content
    final ScrollPanel sp = new ScrollPanel();
    sp.setSize("100%", "100%");
    sp.setStyleName("perun-tableScrollPanel");
    session.getUiElements().resizeSmallTabPanel(sp, 350, this);
    HorizontalPanel horizontalSplitter = new HorizontalPanel();
    horizontalSplitter.setStyleName("perun-table");
    horizontalSplitter.setSize("100%", "100%");
    final VerticalPanel leftPanel = new VerticalPanel();
    final VerticalPanel rightPanel = new VerticalPanel();
    horizontalSplitter.add(leftPanel);
    horizontalSplitter.add(rightPanel);
    horizontalSplitter.setCellWidth(leftPanel, "50%");
    horizontalSplitter.setCellWidth(rightPanel, "50%");
    final VerticalPanel innerVp = new VerticalPanel();
    innerVp.setSize("100%", "100%");
    final TabMenu menu = new TabMenu();
    innerVp.add(menu);
    innerVp.setCellHeight(menu, "30px");
    menu.addWidget(UiElements.getRefreshButton(this));
    innerVp.add(horizontalSplitter);
    sp.setWidget(innerVp);
    FlexTable quickHeader = new FlexTable();
    quickHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.directionIcon()));
    quickHeader.setHTML(0, 1, "<p class=\"subsection-heading\">Quick links</p>");
    FlexTable prefHeader = new FlexTable();
    prefHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.settingToolsIcon()));
    prefHeader.setHTML(0, 1, "<p class=\"subsection-heading\">Global settings</p>");
    leftPanel.add(quickHeader);
    rightPanel.add(prefHeader);
    // widgets
    final ExtendedTextBox preferredEmail = new ExtendedTextBox();
    preferredEmail.getTextBox().setWidth("300px");
    preferredEmail.setWidth("300px");
    final ListBox preferredLanguage = new ListBox();
    preferredLanguage.addItem("Not selected", "");
    if (!Utils.getNativeLanguage().isEmpty()) {
        preferredLanguage.addItem(Utils.getNativeLanguage().get(2), Utils.getNativeLanguage().get(0));
    }
    preferredLanguage.addItem("English", "en");
    final ListBox timezone = new ListBox();
    timezone.addItem("Not set", "null");
    for (String zone : Utils.getTimezones()) {
        timezone.addItem(zone, zone);
    }
    final PreferredShellsWidget preferredShellsWidget = new PreferredShellsWidget();
    final PreferredUnixGroupNameWidget preferredUnixGroupNameWidget = new PreferredUnixGroupNameWidget();
    // content
    final FlexTable settingsTable = new FlexTable();
    settingsTable.setStyleName("inputFormFlexTableDark");
    settingsTable.setHTML(1, 0, "Preferred&nbsp;mail:");
    settingsTable.setWidget(1, 1, preferredEmail);
    settingsTable.getFlexCellFormatter().setRowSpan(1, 0, 2);
    settingsTable.setHTML(2, 0, "");
    settingsTable.setHTML(3, 0, "Preferred&nbsp;language:");
    settingsTable.setWidget(3, 1, preferredLanguage);
    settingsTable.setHTML(4, 0, "Timezone:");
    settingsTable.setWidget(4, 1, timezone);
    settingsTable.setHTML(5, 0, "Preferred shells:");
    settingsTable.setWidget(5, 1, preferredShellsWidget);
    settingsTable.getFlexCellFormatter().setRowSpan(5, 0, 2);
    settingsTable.setHTML(6, 0, "List of preferred shells ordered from the most preferred to least is used to determine your shell on provided resources. If none of preferred shells is available on resource (or no preferred shell is set), resource's default is used.");
    settingsTable.getFlexCellFormatter().setStyleName(6, 0, "inputFormInlineComment");
    settingsTable.setHTML(7, 0, "Preferred primary unix groups names:");
    for (int i = 1; i < settingsTable.getRowCount(); i++) {
        if (i == 2 || i == 6)
            continue;
        settingsTable.getFlexCellFormatter().addStyleName(i, 0, "itemName");
    }
    // SET SAVE CLICK HANDLER
    final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in preferences");
    // TabMenu menu = new TabMenu();
    // menu.addWidget(save);
    settingsTable.setWidget(0, 0, save);
    final GetListOfAttributes attrsCall = new GetListOfAttributes();
    // list of wanted attributes
    final ArrayList<String> list = new ArrayList<String>();
    list.add("urn:perun:user:attribute-def:def:preferredLanguage");
    list.add("urn:perun:user:attribute-def:def:preferredMail");
    list.add("urn:perun:user:attribute-def:def:timezone");
    list.add("urn:perun:user:attribute-def:def:preferredShells");
    for (String s : Utils.getNamespacesForPreferredGroupNames()) {
        list.add("urn:perun:user:attribute-def:def:preferredUnixGroupName-namespace:" + s);
    }
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("user", userId);
    save.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // will be set
            ArrayList<Attribute> toSend = new ArrayList<Attribute>();
            for (final Attribute a : userAttrs) {
                String oldValue = a.getValue();
                String newValue = "";
                if (a.getFriendlyName().equalsIgnoreCase("preferredLanguage")) {
                    newValue = preferredLanguage.getValue(preferredLanguage.getSelectedIndex());
                } else if (a.getFriendlyName().equalsIgnoreCase("timezone")) {
                    newValue = timezone.getValue(timezone.getSelectedIndex());
                } else if (a.getFriendlyName().equalsIgnoreCase("preferredMail")) {
                    newValue = preferredEmail.getTextBox().getValue().trim();
                } else if (a.getFriendlyName().equalsIgnoreCase("preferredShells")) {
                    String s = preferredShellsWidget.getAttribute().getValue();
                    newValue = (!s.equalsIgnoreCase("null")) ? s : "";
                } else if (a.getBaseFriendlyName().equals("preferredUnixGroupName-namespace")) {
                    String s = preferredUnixGroupNameWidget.getAttribute(a.getName()).getValue();
                    newValue = (!s.equalsIgnoreCase("null")) ? s : "";
                } else {
                    // other than contact attributes must be skipped
                    continue;
                }
                if (oldValue.equals(newValue) || (oldValue.equalsIgnoreCase("null") && ("").equals(newValue))) {
                    // skip this cycle
                    continue;
                } else {
                    if (("").equals(newValue) || ("null").equals(newValue)) {
                        Attribute newA = JsonUtils.clone(a).cast();
                        // set value
                        newA.setValueAsJso(null);
                        // value was cleared
                        toSend.add(newA);
                    // preferred email can't be ever removed from here
                    } else {
                        if (a.getFriendlyName().equalsIgnoreCase("preferredMail")) {
                            RequestPreferredEmailChange call = new RequestPreferredEmailChange(JsonCallbackEvents.disableButtonEvents(save));
                            call.requestChange(user, newValue);
                        } else {
                            Attribute newA = JsonUtils.clone(a).cast();
                            // set value
                            newA.setValue(newValue);
                            // value was changed / added
                            toSend.add(newA);
                        }
                    }
                }
            }
            // ids
            Map<String, Integer> localIds = new HashMap<String, Integer>();
            localIds.put("user", userId);
            // requests
            SetAttributes request = new SetAttributes(JsonCallbackEvents.disableButtonEvents(save, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    attrsCall.getListOfAttributes(ids, list);
                }
            }));
            // send if not empty
            if (!toSend.isEmpty()) {
                request.setAttributes(localIds, toSend);
            }
        }
    });
    // GET USER ATTRIBUTES BY NAME
    attrsCall.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            userAttrs = JsonUtils.jsoAsList(jso);
            settingsTable.setWidget(1, 1, preferredEmail);
            settingsTable.setWidget(3, 1, preferredLanguage);
            settingsTable.setWidget(4, 1, timezone);
            settingsTable.setWidget(5, 1, preferredShellsWidget);
            settingsTable.setWidget(7, 1, preferredUnixGroupNameWidget);
            // clear on re-init
            preferredUnixGroupNameWidget.clear();
            for (final Attribute a : userAttrs) {
                if (a.getValue() == null || a.getValue().equalsIgnoreCase("null")) {
                    if (a.getFriendlyName().equalsIgnoreCase("preferredShells")) {
                        // don't skip this null attribute
                        preferredShellsWidget.setAttribute(a);
                    }
                    if (a.getBaseFriendlyName().equalsIgnoreCase("preferredUnixGroupName-namespace")) {
                        // don't skip this null attribute
                        preferredUnixGroupNameWidget.setAttribute((Attribute) JsonUtils.clone(a).cast());
                    }
                    // skip null attributes
                    continue;
                }
                if (a.getBaseFriendlyName().equalsIgnoreCase("preferredUnixGroupName-namespace")) {
                    // don't skip this null attribute
                    preferredUnixGroupNameWidget.setAttribute((Attribute) JsonUtils.clone(a).cast());
                } else if (a.getFriendlyName().equalsIgnoreCase("preferredLanguage")) {
                    if (!Utils.getNativeLanguage().isEmpty() && a.getValue().equals(Utils.getNativeLanguage().get(0))) {
                        preferredLanguage.setSelectedIndex(1);
                    } else if (a.getValue().equals("en")) {
                        preferredLanguage.setSelectedIndex(2);
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("preferredMail")) {
                    preferredEmail.getTextBox().setText(a.getValue());
                    // display notice if there is any valid pending change request
                    GetPendingPreferredEmailChanges get = new GetPendingPreferredEmailChanges(user.getId(), new JsonCallbackEvents() {

                        @Override
                        public void onFinished(JavaScriptObject jso) {
                            // process returned value
                            if (jso != null) {
                                BasicOverlayType basic = jso.cast();
                                emails = basic.getListOfStrings();
                                if (!emails.isEmpty()) {
                                    for (String s : emails) {
                                        if (!s.equals(preferredEmail.getTextBox().getText().trim())) {
                                            resultText += s + ", ";
                                        }
                                    }
                                    if (resultText.length() >= 2)
                                        resultText = resultText.substring(0, resultText.length() - 2);
                                    settingsTable.setHTML(2, 0, "You have pending change request. Please check inbox of: " + SafeHtmlUtils.fromString(resultText).asString() + " for validation email.");
                                    settingsTable.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment serverResponseLabelError");
                                }
                            }
                            // set validator with respect to returned values
                            preferredEmail.setValidator(new ExtendedTextBox.TextBoxValidator() {

                                @Override
                                public boolean validateTextBox() {
                                    if (preferredEmail.getTextBox().getText().trim().isEmpty()) {
                                        preferredEmail.setError("Preferred email address can't be empty.");
                                        return false;
                                    } else if (!JsonUtils.isValidEmail(preferredEmail.getTextBox().getText().trim())) {
                                        preferredEmail.setError("Not valid email address format.");
                                        return false;
                                    }
                                    // update notice under textbox on any cut/past/type action
                                    if (!preferredEmail.getTextBox().getText().trim().equals(a.getValue())) {
                                        settingsTable.setHTML(2, 0, "No changes are saved, until new address is validated. After change please check your inbox for validation mail." + ((!resultText.isEmpty()) ? "<p><span class=\"serverResponseLabelError\">You have pending change request. Please check inbox of: " + resultText + " for validation email.</span>" : ""));
                                        settingsTable.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
                                    } else {
                                        settingsTable.setHTML(2, 0, (!resultText.isEmpty()) ? "You have pending change request. Please check inbox of: " + SafeHtmlUtils.fromString(resultText).asString() + " for validation email." : "");
                                        settingsTable.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment serverResponseLabelError");
                                    }
                                    preferredEmail.setOk();
                                    return true;
                                }
                            });
                        }

                        @Override
                        public void onError(PerunError error) {
                            // save.setEnabled(true);
                            // add basic validator even if there is any error
                            preferredEmail.setValidator(new ExtendedTextBox.TextBoxValidator() {

                                @Override
                                public boolean validateTextBox() {
                                    if (preferredEmail.getTextBox().getText().trim().isEmpty()) {
                                        preferredEmail.setError("Preferred email address can't be empty.");
                                        return false;
                                    } else if (!JsonUtils.isValidEmail(preferredEmail.getTextBox().getText().trim())) {
                                        preferredEmail.setError("Not valid email address format.");
                                        return false;
                                    } else {
                                        preferredEmail.setOk();
                                        return true;
                                    }
                                }
                            });
                        }

                        @Override
                        public void onLoadingStart() {
                        // save.setEnabled(false);
                        }
                    });
                    get.retrieveData();
                } else if (a.getFriendlyName().equalsIgnoreCase("timezone")) {
                    for (int i = 0; i < timezone.getItemCount(); i++) {
                        if (timezone.getValue(i).equals(a.getValue())) {
                            timezone.setSelectedIndex(i);
                        }
                    }
                } else if (a.getFriendlyName().equalsIgnoreCase("preferredShells")) {
                    // set attribute and display value
                    preferredShellsWidget.setAttribute(a);
                }
            }
        }

        @Override
        public void onLoadingStart() {
            settingsTable.setWidget(1, 1, new AjaxLoaderImage(true));
            settingsTable.setWidget(3, 1, new AjaxLoaderImage(true));
            settingsTable.setWidget(4, 1, new AjaxLoaderImage(true));
            settingsTable.setWidget(5, 1, new AjaxLoaderImage(true));
            settingsTable.setWidget(7, 1, new AjaxLoaderImage(true));
        }

        @Override
        public void onError(PerunError error) {
            settingsTable.setWidget(1, 1, new AjaxLoaderImage(true).loadingError(error));
            settingsTable.setWidget(3, 1, new AjaxLoaderImage(true).loadingError(error));
            settingsTable.setWidget(4, 1, new AjaxLoaderImage(true).loadingError(error));
            settingsTable.setWidget(5, 1, new AjaxLoaderImage(true).loadingError(error));
            settingsTable.setWidget(7, 1, new AjaxLoaderImage(true).loadingError(error));
        }
    });
    attrsCall.getListOfAttributes(ids, list);
    FlexTable quickLinks = new FlexTable();
    quickHeader.setStyleName("inputFormFlexTable");
    String span = "<span style=\"font-weight: bold; padding-left: 25px; line-height: 2;\">";
    Anchor name = new Anchor(span + "Edit name titles</span>", true);
    name.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().addTabToCurrentTab(new EditUserDetailsTabItem(user, new JsonCallbackEvents() {

                @Override
                public void onFinished(JavaScriptObject jso) {
                    // refresh parent tab
                    SelfDetailTabItem item = (SelfDetailTabItem) session.getTabManager().getActiveTab();
                    item.setUser((User) jso);
                    item.open();
                    item.draw();
                }
            }));
        }
    });
    quickLinks.setWidget(0, 0, name);
    Anchor password = new Anchor(span + "Change / reset password</span>", true);
    password.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            tabPanel.selectTab(tabPanel.getSelectedIndex() + 3);
        }
    });
    quickLinks.setWidget(1, 0, password);
    Anchor cert = new Anchor(span + "<a href=\"" + Utils.getIdentityConsolidatorLink(false) + "\" target=\"_blank\">Add certificate</a></span>", true);
    quickLinks.setWidget(2, 0, cert);
    Anchor ssh = new Anchor(span + "Manage SSH keys</span>", true);
    ssh.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            tabPanel.selectTab(tabPanel.getSelectedIndex() + 3);
        }
    });
    quickLinks.setWidget(3, 0, ssh);
    Anchor report = new Anchor(span + "Report new publication</span>", true);
    report.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            session.getTabManager().addTab(new AddPublicationsTabItem(user));
        }
    });
    quickLinks.setWidget(4, 0, report);
    Anchor request = new Anchor(span + "Request data/files quota change</span>", true);
    request.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            tabPanel.selectTab(tabPanel.getSelectedIndex() + 2);
        }
    });
    quickLinks.setWidget(5, 0, request);
    if (session.getEditableUsers().size() > 1) {
        Anchor serv = new Anchor(span + "Manage service identities</span>", true);
        serv.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                tabPanel.selectTab(tabPanel.getSelectedIndex() + 6);
            }
        });
        quickLinks.setWidget(6, 0, serv);
    }
    rightPanel.add(settingsTable);
    leftPanel.add(quickLinks);
    Scheduler.get().scheduleDeferred(new Command() {

        @Override
        public void execute() {
            sp.scrollToTop();
        }
    });
    this.contentWidget.setWidget(sp);
    return getWidget();
}
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) GetPendingPreferredEmailChanges(cz.metacentrum.perun.webgui.json.usersManager.GetPendingPreferredEmailChanges) AddPublicationsTabItem(cz.metacentrum.perun.webgui.tabs.cabinettabs.AddPublicationsTabItem) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) RequestPreferredEmailChange(cz.metacentrum.perun.webgui.json.usersManager.RequestPreferredEmailChange) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Command(com.google.gwt.user.client.Command) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)17 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)14 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)14 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)14 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)13 Map (java.util.Map)12 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)11 Attribute (cz.metacentrum.perun.webgui.model.Attribute)9 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)9 GetAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetAttributesV2)8 SetNewAttributeTabItem (cz.metacentrum.perun.webgui.tabs.attributestabs.SetNewAttributeTabItem)8 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 GetResourceRequiredAttributesV2 (cz.metacentrum.perun.webgui.json.attributesManager.GetResourceRequiredAttributesV2)3 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)3 FieldUpdater (com.google.gwt.cell.client.FieldUpdater)2 ImageResource (com.google.gwt.resources.client.ImageResource)2