Search in sources :

Example 1 with FormValidator

use of cz.metacentrum.perun.webgui.client.applicationresources.FormValidator in project perun by CESNET.

the class PreviewFormTabItem method prepareApplicationForm.

/**
	 * Prepares the widgets from the items as A DISPLAY FOR THE USER
	 *
	 * @param sp scroll panel
	 */
public void prepareApplicationForm(ScrollPanel sp) {
    FlexTable ft = new FlexTable();
    ft.setSize("100%", "100%");
    ft.setCellPadding(10);
    FlexCellFormatter fcf = ft.getFlexCellFormatter();
    int i = 0;
    for (final ApplicationFormItem item : formItems) {
        // skip items not from correct app type
        ArrayList<String> itemApplicationTypes = JsonUtils.listFromJsArrayString(item.getApplicationTypes());
        if (!itemApplicationTypes.contains(appType))
            continue;
        // generate correct items
        RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, locale);
        this.applFormGenerators.add(gen);
        gen.addValidationTrigger(new FormValidator() {

            public void triggerValidation() {
                validateFormValues(false);
            }
        });
        // if button, add onclick
        if (item.getType().equals("SUBMIT_BUTTON")) {
            this.sendButton = (Button) gen.getWidget();
            sendButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    // revalidate again, with force validation
                    if (!validateFormValues(true)) {
                        return;
                    }
                    // sending is disabled
                    Confirm c = new Confirm("Sending disabled", new Label("Sending form is disabled in preview mode, but form items value validation works."), true);
                    c.show();
                }
            });
        }
        // get localized texts
        ItemTexts itemTexts = item.getItemTexts(locale);
        if (!gen.isVisible()) {
            continue;
        }
        // WITH LABEL (input box ...)
        if (gen.isLabelShown()) {
            // 0 = label
            if (item.isRequired() == true) {
                // required
                ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "*</strong>");
            } else {
                // optional
                ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "</strong>");
            }
            // 1 = widget
            Widget w = gen.getWidget();
            w.setTitle(itemTexts.getHelp());
            ft.setWidget(i, 1, w);
            // 2 = status
            ft.setWidget(i, 2, gen.getStatusWidget());
            // 3 = HELP
            if (itemTexts.getHelp() != null && itemTexts.getHelp().length() > 0) {
                Label help = new Label(itemTexts.getHelp());
                ft.setWidget(i, 3, help);
            }
            // format
            fcf.setStyleName(i, 0, "applicationFormLabel");
            fcf.setStyleName(i, 1, "applicationFormWidget");
            fcf.setStyleName(i, 2, "applicationFormCheck");
            fcf.setStyleName(i, 3, "applicationFormHelp");
            ft.setWidth("100%");
        // ELSE HTML COMMENT
        } else {
            ft.setWidget(i, 0, gen.getWidget());
            // colspan = 2
            fcf.setColSpan(i, 0, 4);
            fcf.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_LEFT);
            fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_MIDDLE);
        }
        i++;
    }
    sp.setWidget(ft);
}
Also used : FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Confirm(cz.metacentrum.perun.webgui.widgets.Confirm) FormValidator(cz.metacentrum.perun.webgui.client.applicationresources.FormValidator) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)

Example 2 with FormValidator

use of cz.metacentrum.perun.webgui.client.applicationresources.FormValidator in project perun by CESNET.

the class GetFormItemsWithPrefilledValues method prepareApplicationForm.

/**
	 * Prepares the widgets from the items as A DISPLAY FOR THE USER
	 */
public void prepareApplicationForm() {
    FlexTable ft = new FlexTable();
    ft.setCellPadding(10);
    ft.setWidth("100%");
    FlexCellFormatter fcf = ft.getFlexCellFormatter();
    String locale;
    if (!Utils.getNativeLanguage().isEmpty() && LocaleInfo.getCurrentLocale().getLocaleName().equals(Utils.getNativeLanguage().get(0))) {
        locale = Utils.getNativeLanguage().get(0);
    } else {
        locale = "en";
    }
    int i = 0;
    for (final ApplicationFormItemWithPrefilledValue item : applFormItems) {
        RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, locale);
        this.applFormGenerators.add(gen);
        gen.addValidationTrigger(new FormValidator() {

            public void triggerValidation() {
                validateFormValues(false);
            }
        });
        // if button, add onclick
        if (item.getFormItem().getType().equals("SUBMIT_BUTTON") || item.getFormItem().getType().equals("AUTO_SUBMIT_BUTTON")) {
            this.sendButton = (CustomButton) gen.getWidget();
            sendButton.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    // revalidate again, with force validation
                    if (!validateFormValues(true)) {
                        Element elem = DOM.getElementById("input-status-error");
                        elem.scrollIntoView();
                        return;
                    }
                    if (sendFormHandler != null) {
                        sendFormHandler.sendApplicationForm(sendButton);
                    }
                }
            });
        }
        // get localized texts
        ItemTexts itemTexts = item.getFormItem().getItemTexts(locale);
        if (!gen.isVisible()) {
            continue;
        }
        // WITH LABEL (input box ...)
        if (gen.isLabelShown()) {
            // 0 = label
            if (item.getFormItem().isRequired() == true) {
                // required
                ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "*</strong>");
            } else {
                // optional
                ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "</strong>");
            }
            // 1 = widget
            Widget w = gen.getWidget();
            w.setTitle(itemTexts.getHelp());
            ft.setWidget(i, 1, w);
            // 2 = status
            ft.setWidget(i, 2, gen.getStatusWidget());
            // 3 = HELP
            if (itemTexts.getHelp() != null && itemTexts.getHelp().length() > 0) {
                Label help = new Label(itemTexts.getHelp());
                ft.setWidget(i, 3, help);
            }
            // format
            fcf.setStyleName(i, 0, "applicationFormLabel");
            fcf.setStyleName(i, 1, "applicationFormWidget");
            fcf.setStyleName(i, 2, "applicationFormCheck");
            fcf.setStyleName(i, 3, "applicationFormHelp");
            ft.setWidth("100%");
        // ELSE HTML COMMENT, SUBMIT BUTTON, HEADING
        } else {
            ft.setWidget(i, 0, gen.getWidget());
            // colspan = 2
            fcf.setColSpan(i, 0, 4);
            fcf.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_LEFT);
            fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_MIDDLE);
        }
        i++;
    }
    contents.setWidget(ft);
}
Also used : FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Element(com.google.gwt.user.client.Element) FormValidator(cz.metacentrum.perun.webgui.client.applicationresources.FormValidator) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)

Aggregations

ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)2 FormValidator (cz.metacentrum.perun.webgui.client.applicationresources.FormValidator)2 RegistrarFormItemGenerator (cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)2 Element (com.google.gwt.user.client.Element)1 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)1