Search in sources :

Example 21 with Confirm

use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.

the class TestDataGridTabItem 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<VirtualOrganization> vosList = new ArrayList<VirtualOrganization>();
    final GetVos getVos = new GetVos(new JsonCallbackEvents() {

        public void onFinished(JavaScriptObject jso) {
            vosList.addAll(new TableSorter<VirtualOrganization>().sortByName(JsonUtils.<VirtualOrganization>jsoAsList(jso)));
            gridTable.setRowData(vosList);
            gridTable.redraw();
        }
    });
    getVos.retrieveData();
    gridTable.setSelectionModel(new MultiSelectionModel<VirtualOrganization>(new GeneralKeyProvider<VirtualOrganization>()));
    final SelectionModel<VirtualOrganization> selectionModel = gridTable.getSelectionModel();
    Column<VirtualOrganization, Boolean> checkBoxColumn = new Column<VirtualOrganization, Boolean>(new CheckboxCell(true, true)) {

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

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, Boolean aBoolean) {
            selectionModel.setSelected(virtualOrganization, 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 (VirtualOrganization obj : vosList) {
                selectionModel.setSelected(obj, value);
            }
        }
    });
    gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
    gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);
    TextColumn<VirtualOrganization> idColumn = new TextColumn<VirtualOrganization>() {

        @Override
        public String getValue(VirtualOrganization object) {
            return String.valueOf(object.getId());
        }
    };
    gridTable.addColumn(idColumn, "Id", "Id");
    gridTable.setColumnWidth(idColumn, "90px");
    Column<VirtualOrganization, String> nameColumn = JsonUtils.addColumn(new JsonUtils.GetValue<VirtualOrganization, String>() {

        public String getValue(VirtualOrganization object) {
            return object.getName();
        }
    }, new FieldUpdater<VirtualOrganization, String>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, String s) {
            session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
        }
    });
    gridTable.addColumn(nameColumn, "Name", "Name");
    TextColumn<VirtualOrganization> shortnameColumn = new TextColumn<VirtualOrganization>() {

        @Override
        public String getValue(VirtualOrganization object) {
            return object.getShortName();
        }
    };
    gridTable.addColumn(shortnameColumn, "Short name", "Short name");
    shortnameColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, String s) {
            session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
        }
    });
    idColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, String s) {
            session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
        }
    });
    nameColumn.setFieldUpdater(new FieldUpdater<VirtualOrganization, String>() {

        @Override
        public void update(int i, VirtualOrganization virtualOrganization, String s) {
            session.getTabManager().addTab(new VoDetailTabItem(virtualOrganization));
        }
    });
    TabMenu tabMenu = new TabMenu();
    // CREATE & DELETE ONLY WITH PERUN ADMIN
    if (session.isPerunAdmin()) {
        tabMenu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createVo(), new ClickHandler() {

            public void onClick(ClickEvent event) {
                session.getTabManager().addTabToCurrentTab(new CreateVoTabItem());
            }
        }));
        final cz.metacentrum.perun.webgui.widgets.CustomButton removeButton = TabMenu.getPredefinedButton(ButtonType.DELETE, ButtonTranslation.INSTANCE.deleteVo());
        removeButton.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                final ArrayList<VirtualOrganization> itemsToRemove = getVos.getTableSelectedList();
                if (UiElements.cantSaveEmptyListDialogBox(itemsToRemove)) {
                    VerticalPanel removePanel = new VerticalPanel();
                    removePanel.add(new Label("These VOs will be removed:"));
                    for (int i = 0; i < itemsToRemove.size(); i++) {
                        VirtualOrganization vo = itemsToRemove.get(i);
                        removePanel.add(new Label(" - " + vo.getName()));
                    }
                    // confirmation
                    Confirm c = new Confirm("Remove VOs", removePanel, new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            for (int i = 0; i < itemsToRemove.size(); i++) {
                                DeleteVo request;
                                // if last, refresh
                                if (i == itemsToRemove.size() - 1) {
                                    request = new DeleteVo(JsonCallbackEvents.disableButtonEvents(removeButton));
                                } else {
                                    request = new DeleteVo(JsonCallbackEvents.disableButtonEvents(removeButton));
                                }
                                request.deleteVo(itemsToRemove.get(i).getId(), false);
                            }
                            getVos.clearTableSelectedSet();
                        }
                    }, true);
                    c.show();
                }
            }
        });
        tabMenu.addWidget(removeButton);
    }
    // filter
    tabMenu.addFilterWidget(new ExtendedSuggestBox(getVos.getOracle()), new PerunSearchEvent() {

        @Override
        public void searchFor(String text) {
            getVos.filterTable(text);
        }
    }, ButtonTranslation.INSTANCE.filterVo());
    ft.addNorth(tabMenu, 50);
    ft.add(gridTable);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) DataGrid(com.google.gwt.user.cellview.client.DataGrid) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) VirtualOrganization(cz.metacentrum.perun.webgui.model.VirtualOrganization) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) DeleteVo(cz.metacentrum.perun.webgui.json.vosManager.DeleteVo) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) CreateVoTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.CreateVoTabItem) ExtendedSuggestBox(cz.metacentrum.perun.webgui.widgets.ExtendedSuggestBox) CheckboxCell(com.google.gwt.cell.client.CheckboxCell) TextColumn(com.google.gwt.user.cellview.client.TextColumn) PerunSearchEvent(cz.metacentrum.perun.webgui.client.resources.PerunSearchEvent) GetVos(cz.metacentrum.perun.webgui.json.vosManager.GetVos) GeneralKeyProvider(cz.metacentrum.perun.webgui.json.keyproviders.GeneralKeyProvider) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Header(com.google.gwt.user.cellview.client.Header) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) VoDetailTabItem(cz.metacentrum.perun.webgui.tabs.vostabs.VoDetailTabItem)

Example 22 with Confirm

use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.

the class GetApplicationDataById method prepareApplicationForm.

/**
 * Prepares the widgets from the items as A DISPLAY FOR THE USER
 */
public void prepareApplicationForm() {
    FlexTable ft = new FlexTable();
    ft.setWidth("100%");
    ft.setCellPadding(5);
    ft.setCellSpacing(0);
    ft.setStyleName("stripped");
    FlexCellFormatter fcf = ft.getFlexCellFormatter();
    String locale = "en";
    if (!Utils.getNativeLanguage().isEmpty() && !LocaleInfo.getCurrentLocale().getLocaleName().equals("default") && !LocaleInfo.getCurrentLocale().getLocaleName().equals("en")) {
        locale = Utils.getNativeLanguage().get(0);
    }
    if (this.embedded) {
        Attribute attr = this.user.getAttribute("urn:perun:user:attribute-def:def:preferredMail");
        if (attr != null) {
            ft.setHTML(0, 0, "<strong>" + attr.getDisplayName() + "</strong>");
            ft.setWidget(0, 2, new HTML(SafeHtmlUtils.fromString(attr.getValue())));
            // format
            fcf.setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP);
            fcf.setVerticalAlignment(0, 2, HasVerticalAlignment.ALIGN_TOP);
            fcf.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT);
            fcf.setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_LEFT);
            fcf.setWidth(0, 0, "25%");
            fcf.setWidth(0, 2, "75%");
            contents.setWidget(ft);
        }
    } else {
        int i = 0;
        for (final ApplicationFormItemData item : applFormItems) {
            RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item.getFormItem(), (item.getValue() != null) ? SafeHtmlUtils.fromString(item.getValue()).asString() : null, locale);
            this.applFormGenerators.add(gen);
            // show only visible items - show also hidden to perun admin and vo/group admin
            if (!gen.isVisible() && !(session.isPerunAdmin() || session.isVoAdmin() || session.isGroupAdmin())) {
                continue;
            }
            // if only for admin
            if (!showAdminItems && gen.isVisibleOnlyToAdmin()) {
                continue;
            }
            // WITH LABEL (input box ...)
            if (gen.isLabelShown()) {
                // don't show password
                if (!item.getFormItem().getType().equalsIgnoreCase("PASSWORD")) {
                    // FIXME for now, we can only detect that the item was hidden for the 'ALWAYS' option. This will be for the most cases.
                    if (item.getFormItem().getHidden().equals("ALWAYS")) {
                        // hidden
                        ft.setHTML(i, 0, "<strong>" + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString() + "</strong><br /><i>(value provided by external source)</i>");
                    // FIXME for now, we can only detect that the item was disabled for the 'ALWAYS' option. This will be for the most cases.
                    } else if (item.getFormItem().getDisabled().equals("ALWAYS")) {
                        // show
                        ft.setHTML(i, 0, "<strong>" + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString() + "</strong><br /><i>(value provided by external source)</i>");
                    } else {
                        ft.setHTML(i, 0, "<strong>" + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString() + "</strong>");
                    }
                    if (PerunWebSession.getInstance().isPerunAdmin() && gen.isUpdatable() && editable) {
                        final int finalI = i;
                        CustomButton editButton = new CustomButton("", "Editor form item data.", SmallIcons.INSTANCE.applicationFormEditIcon(), new ClickHandler() {

                            @Override
                            public void onClick(ClickEvent event) {
                                TextArea content = new TextArea();
                                if (item.getValue() != null) {
                                    content.setText(item.getValue());
                                }
                                content.setSize("350px", "100px");
                                Confirm confirm = new Confirm("Edit item: " + SafeHtmlUtils.fromString(gen.getLabelOrShortname()).asString(), content, new ClickHandler() {

                                    @Override
                                    public void onClick(ClickEvent event) {
                                        // save old value and push new value
                                        String previousValue = item.getValue();
                                        item.setValue(content.getText());
                                        UpdateFormItemData update = new UpdateFormItemData(new JsonCallbackEvents() {

                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                                // update local UI
                                                ft.setWidget(finalI, 2, new HTML((item.getValue() != null) ? (SafeHtmlUtils.fromString(item.getValue()).asString()) : null));
                                            }

                                            @Override
                                            public void onError(PerunError error) {
                                                // put back old value
                                                item.setValue(previousValue);
                                            }
                                        });
                                        update.updateFormItemData(appId, item);
                                    }
                                }, "Update form item", true);
                                confirm.setNonScrollable(true);
                                confirm.show();
                            }
                        });
                        ft.setWidget(i, 1, editButton);
                    }
                    // 1 = value
                    ft.setWidget(i, 2, new HTML((item.getValue() != null) ? (SafeHtmlUtils.fromString(item.getValue()).asString()) : null));
                    // format
                    fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_TOP);
                    fcf.setVerticalAlignment(i, 2, HasVerticalAlignment.ALIGN_TOP);
                    fcf.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
                    fcf.setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_LEFT);
                    fcf.setWidth(i, 0, "25%");
                    fcf.setWidth(i, 2, "75%");
                }
            }
            i++;
        }
        // set empty text
        if (!applFormItems.isEmpty()) {
            contents.setWidget(ft);
        }
    }
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) Attribute(cz.metacentrum.perun.webgui.model.Attribute) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) ApplicationFormItemData(cz.metacentrum.perun.webgui.model.ApplicationFormItemData) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) PerunError(cz.metacentrum.perun.webgui.model.PerunError)

Example 23 with Confirm

use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.

the class HandleApplication method approveApplication.

/**
 * Approve application
 *
 * @param app
 */
public void approveApplication(final Application app) {
    this.appId = app.getId();
    // test arguments
    if (!this.testApplication()) {
        return;
    }
    // new events
    final JsonCallbackEvents newEvents = new JsonCallbackEvents() {

        @Override
        public void onError(PerunError error) {
            session.getUiElements().setLogErrorText("Approving application failed.");
            events.onError(error);
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            session.getUiElements().setLogSuccessText("Application approved.");
            events.onFinished(jso);
        }

        @Override
        public void onLoadingStart() {
            events.onLoadingStart();
        }
    };
    final JSONObject appIdObj = new JSONObject();
    appIdObj.put("appId", new JSONNumber(appId));
    final JSONObject idObj = new JSONObject();
    idObj.put("id", new JSONNumber(appId));
    // check if can be approved
    JsonPostClient jspc = new JsonPostClient(new JsonCallbackEvents() {

        @Override
        public void onError(final PerunError error) {
            session.getUiElements().setLogErrorText("Checking approval failed.");
            events.onError(error);
            if (error == null) {
                PerunError e = (PerunError) JsonUtils.parseJson("{\"errorId\":\"0\",\"name\":\"Cross-site request\",\"type\":\"" + WidgetTranslation.INSTANCE.jsonClientAlertBoxErrorCrossSiteType() + "\",\"message\":\"" + WidgetTranslation.INSTANCE.jsonClientAlertBoxErrorCrossSiteText() + "\"}").cast();
                JsonErrorHandler.alertBox(e);
            } else if (!error.getName().equals("CantBeApprovedException")) {
                JsonErrorHandler.alertBox(error);
            } else {
                FlexTable layout = new FlexTable();
                layout.setWidget(0, 0, new HTML("<p>" + new Image(LargeIcons.INSTANCE.errorIcon())));
                if ("NOT_ACADEMIC".equals(error.getReason())) {
                    layout.setHTML(0, 1, "<p>User is not active academia member and application shouldn't be approved.<p><b>LoA:</b> " + SafeHtmlUtils.fromString(app.getExtSourceLoa() + "").asString() + "</br><b>IdP category:</b> " + (!(error.getCategory().equals("")) ? SafeHtmlUtils.fromString(error.getCategory()).asString() : "N/A") + "</br><b>Affiliation:</b> " + (!(error.getAffiliation().equals("")) ? SafeHtmlUtils.fromString(error.getAffiliation().replace(";", ", ")).asString() : "N/A") + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
                }
                if ("NOT_ELIGIBLE".equals(error.getReason())) {
                    layout.setHTML(0, 1, "<p>User is not eligible for CESNET services and application shouldn't be approved." + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
                } else {
                    layout.setHTML(0, 1, "<p>" + SafeHtmlUtils.fromString(error.getErrorInfo()).asString() + ((error.isSoft()) ? "<p>You can try to override above restriction by clicking 'Approve anyway' button." : ""));
                }
                layout.getFlexCellFormatter().setAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                layout.getFlexCellFormatter().setAlignment(0, 1, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP);
                layout.getFlexCellFormatter().setStyleName(0, 0, "alert-box-image");
                if (error.isSoft()) {
                    Confirm c = new Confirm("Application shouldn't be approved", layout, new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            // ok approve sending data
                            JsonPostClient jspc = new JsonPostClient(newEvents);
                            jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
                        }
                    }, new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent clickEvent) {
                            events.onFinished(null);
                        }
                    }, true);
                    c.setOkButtonText("Approve anyway");
                    c.setNonScrollable(true);
                    c.show();
                } else {
                    Confirm c = new Confirm("Application can't be approved", layout, true);
                    c.setNonScrollable(true);
                    c.show();
                }
            }
        }

        @Override
        public void onFinished(JavaScriptObject jso) {
            if (app.getUser() != null) {
                // ok approve sending data
                JsonPostClient jspc2 = new JsonPostClient(newEvents);
                jspc2.sendData(JSON_URL_APPROVE, prepareJSONObject());
            } else {
                JsonPostClient checkJspc = new JsonPostClient(new JsonCallbackEvents() {

                    @Override
                    public void onError(PerunError error) {
                        session.getUiElements().setLogErrorText("Approving application failed.");
                        events.onError(error);
                    }

                    @Override
                    public void onFinished(JavaScriptObject jso) {
                        ArrayList<Identity> users = JsonUtils.jsoAsList(jso);
                        if (users != null && !users.isEmpty()) {
                            FlexTable ft = new FlexTable();
                            ft.setWidth("600px");
                            ft.setHTML(0, 0, "<p><strong>Following similar user(s) were found in system:");
                            ft.getFlexCellFormatter().setColSpan(0, 0, 3);
                            ft.setHTML(1, 0, "<strong>" + ApplicationMessages.INSTANCE.name() + "</strong>");
                            ft.setHTML(1, 1, "<strong>" + ApplicationMessages.INSTANCE.email() + "</strong>");
                            ft.setHTML(1, 2, "<strong>" + ApplicationMessages.INSTANCE.organization() + "</strong>");
                            int i = 2;
                            for (Identity user : users) {
                                ft.setHTML(i, 0, SafeHtmlUtils.fromString(user.getName()).asString());
                                if (user.getEmail() != null && !user.getEmail().isEmpty()) {
                                    ft.setHTML(i, 1, SafeHtmlUtils.fromString(user.getEmail()).asString());
                                } else {
                                    ft.setHTML(i, 1, "N/A");
                                }
                                if (user.getOrganization() != null && !user.getOrganization().isEmpty()) {
                                    ft.setHTML(i, 2, SafeHtmlUtils.fromString(user.getOrganization()).asString());
                                } else {
                                    ft.setHTML(i, 2, "N/A");
                                }
                                i++;
                            }
                            String type = "";
                            if (app.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509")) {
                                type = "cert";
                            } else if (app.getExtSourceType().equals("cz.metacentrum.perun.core.impl.ExtSourceIdp")) {
                                type = "fed";
                            }
                            ft.setHTML(i, 0, "<p>Please contact new applicant with question, if he/she isn't already member of any other VO." + "<ul><li>If YES, ask him/her to join identities at <a href=\"" + Utils.getIdentityConsolidatorLink(type, false) + "\" target=\"_blank\">identity consolidator</a> before approving this application." + "</li><li>If NO, you can approve this application anyway. " + "</li><li>If UNSURE, contact <a href=\"mailto:" + Utils.perunReportEmailAddress() + "\">support</a> to help you.</li></ul>");
                            ft.getFlexCellFormatter().setColSpan(i, 0, 3);
                            i++;
                            ft.setHTML(i, 0, "<strong>Do you wish to approve this application anyway ?</strong>");
                            ft.getFlexCellFormatter().setColSpan(i, 0, 3);
                            Confirm c = new Confirm("Similar users found!", ft, new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent clickEvent) {
                                    // ok approve sending data
                                    JsonPostClient jspc = new JsonPostClient(newEvents);
                                    jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
                                }
                            }, new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent clickEvent) {
                                    events.onFinished(null);
                                }
                            }, true);
                            c.setOkButtonText("Approve");
                            c.setNonScrollable(true);
                            c.show();
                        } else {
                            // ok approve sending data
                            JsonPostClient jspc = new JsonPostClient(newEvents);
                            jspc.sendData(JSON_URL_APPROVE, prepareJSONObject());
                        }
                    }

                    @Override
                    public void onLoadingStart() {
                        events.onLoadingStart();
                    }
                });
                checkJspc.sendData("registrarManager/checkForSimilarUsers", appIdObj);
            }
        }

        @Override
        public void onLoadingStart() {
            events.onLoadingStart();
        }
    });
    // we have own error handling
    jspc.setHidden(true);
    jspc.sendData(JSON_URL_CHECK, idObj);
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) JsonPostClient(cz.metacentrum.perun.webgui.json.JsonPostClient) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FlexTable(com.google.gwt.user.client.ui.FlexTable) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) HTML(com.google.gwt.user.client.ui.HTML) JSONString(com.google.gwt.json.client.JSONString) Image(com.google.gwt.user.client.ui.Image) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) JSONNumber(com.google.gwt.json.client.JSONNumber) PerunError(cz.metacentrum.perun.webgui.model.PerunError) Identity(cz.metacentrum.perun.webgui.model.Identity)

Example 24 with Confirm

use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.

the class ApplicationFormPage method similarUsersFound.

/**
	 * When similar users found, display a message
	 *
	 * @param users
	 */
protected void similarUsersFound(ArrayList<Identity> users) {
    boolean foundNew = false;
    for (Identity u : users) {
        boolean foundOld = false;
        for (Identity user : foundUsers) {
            if (user.getId() == u.getId()) {
                // was already found
                foundOld = true;
                break;
            }
        }
        // user was not found in old ones
        if (!foundOld) {
            foundNew = true;
            break;
        }
    }
    if (!foundNew)
        return;
    foundUsers = users;
    FlexTable ft = new FlexTable();
    ft.setWidth("600px");
    FlexCellFormatter ftf = ft.getFlexCellFormatter();
    ft.setHTML(0, 0, ApplicationMessages.INSTANCE.similarUsersFoundIsItYou() + "<br /><br />");
    ftf.setColSpan(0, 0, 3);
    ft.setHTML(1, 0, "<strong>" + ApplicationMessages.INSTANCE.name() + "</strong>");
    ft.setHTML(1, 1, "<strong>" + ApplicationMessages.INSTANCE.email() + "</strong>");
    ft.setHTML(1, 2, "<strong>" + ApplicationMessages.INSTANCE.organization() + "</strong>");
    //ft.setHTML(1, 1, "<strong>" + ApplicationMessages.INSTANCE.identities() +"</strong>");
    int i = 2;
    for (Identity user : users) {
        ft.setHTML(i, 0, user.getName());
        ft.setHTML(i, 1, (user.getEmail() != null && !user.getEmail().isEmpty()) ? user.getEmail() : "N/A");
        ft.setHTML(i, 2, (user.getOrganization() != null && !user.getOrganization().isEmpty()) ? user.getOrganization() : "N/A");
        /*

			ft.setHTML(i, 0, "<strong>"+user.getName()+"</strong><br/>"+user.getOrganization()+"<br/><i>"+user.getEmail()+"</i>");

			//ft.setHTML(i, 1, user.getEmail());
			//ft.setHTML(i, 2, user.getOrganization());

			FlowPanel idents = new FlowPanel();
			ft.setWidget(i, 1, idents);
			idents.setStyleName("identsTable");

			boolean certFound = false;
			for (int n=0; n<user.getExternalIdentities().length(); n++) {

				ExtSource source = user.getExternalIdentities().get(n);

				if (source.getType().equals("cz.metacentrum.perun.core.impl.ExtSourceX509") && !certFound) {
					certFound = true;

					String name[] = source.getName().split("\\/");
					for (String cn : name) {
						if (cn.startsWith("CN=")) {
							idents.insert(new CustomButton(cn.substring(3), SmallIcons.INSTANCE.documentSignatureIcon(), new ClickHandler(){
								@Override
								public void onClick(ClickEvent event) {
									// TODO - get safe hash of own for non-authz
									Window.Location.replace(Utils.getIdentityConsolidatorLink("cert", true));
								}
							}), 0);
							break;
						}
					}
				} else if (source.getType().equals("cz.metacentrum.perun.core.impl.ExtSourceIdp")) {

					idents.add(new CustomButton(translateIdp(source.getName()), SmallIcons.INSTANCE.userGreenIcon(), new ClickHandler(){
						@Override
						public void onClick(ClickEvent event) {
							// TODO - get safe hash of own for non-authz
							Window.Location.replace(Utils.getIdentityConsolidatorLink("fed", true));
						}
					}));

				}

			}

			if (idents.getWidgetCount() == 0) {
				idents.add(new HTML(ApplicationMessages.INSTANCE.noIdentsFound()));
			}

			*/
        i++;
    }
    // confirm element
    final Confirm confirm = new Confirm(ApplicationMessages.INSTANCE.similarUsersFound(), ft, new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Window.Location.replace(Utils.getIdentityConsolidatorLink(true));
        }
    }, true);
    confirm.setOkButtonText(ApplicationMessages.INSTANCE.joinIdentity());
    confirm.setOkIcon(SmallIcons.INSTANCE.userGreenIcon());
    confirm.setCancelButtonText(ApplicationMessages.INSTANCE.notJoinIdentity());
    //confirm.setOkIcon(SmallIcons.INSTANCE.stopIcon());
    confirm.show();
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm)

Example 25 with Confirm

use of cz.metacentrum.perun.webgui.widgets.Confirm in project perun by CESNET.

the class ApplicationFormPage method prepareToggleLanguageButton.

/**
	 * Prepares the buttons for local languages
	 */
private void prepareToggleLanguageButton() {
    languageButton = new PushButton(new Image(SmallIcons.INSTANCE.locateIcon()));
    // translation not supported
    if (Utils.getNativeLanguage().isEmpty()) {
        languageButton.setEnabled(false);
        languageButton.setVisible(false);
        return;
    }
    if (!LocaleInfo.getCurrentLocale().getLocaleName().equals(Utils.getNativeLanguage().get(0))) {
        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToCzech(Utils.getNativeLanguage().get(2)));
    } else {
        languageButton.setTitle(WidgetTranslation.INSTANCE.changeLanguageToEnglish());
    }
    languageButton.setStyleName("gwt-Button");
    languageButton.setPixelSize(17, 17);
    languageButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Confirm conf = new Confirm(languageButton.getTitle(), new HTML(ApplicationMessages.INSTANCE.changeLanguageText()), new ClickHandler() {

                public void onClick(ClickEvent event) {
                    String localeName = LocaleInfo.getCurrentLocale().getLocaleName();
                    if (!localeName.equals(Utils.getNativeLanguage().get(0))) {
                        UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", Utils.getNativeLanguage().get(0));
                        Window.Location.replace(builder.buildString());
                    } else {
                        UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", "en");
                        Window.Location.replace(builder.buildString());
                    }
                // on OK
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                // on CANCEL
                }
            }, true);
            conf.setNonScrollable(true);
            conf.show();
        }
    });
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) JSONString(com.google.gwt.json.client.JSONString) UrlBuilder(com.google.gwt.http.client.UrlBuilder)

Aggregations

Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)49 HTML (com.google.gwt.user.client.ui.HTML)26 JSONString (com.google.gwt.json.client.JSONString)19 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)16 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)16 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)15 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)12 Label (com.google.gwt.user.client.ui.Label)8 PerunError (cz.metacentrum.perun.webgui.model.PerunError)8 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)8 Column (com.google.gwt.user.cellview.client.Column)5 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)5 ArrayList (java.util.ArrayList)5 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)4 JsonPostClient (cz.metacentrum.perun.webgui.json.JsonPostClient)4 FlexTable (com.google.gwt.user.client.ui.FlexTable)3 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)3 RegistrarFormItemGenerator (cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)3 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)3 Context (com.google.gwt.cell.client.Cell.Context)2