Search in sources :

Example 6 with RegistrarFormItemGenerator

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

the class GetFormItems method prepareApplicationForm.

/**
	 * Prepares the widgets from the items as A DISPLAY FOR THE USER
	 * DEPRECATED: Use GetFormItemsWithPrefilledValues instead
	 *
	 * @param items
	 */
@Deprecated
public void prepareApplicationForm(final ArrayList<ApplicationFormItem> items) {
    FlexTable ft = new FlexTable();
    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);
    }
    int i = 0;
    for (final ApplicationFormItem item : items) {
        String value = "";
        if (item.getShortname().equals("affiliation") || item.getShortname().equals("mail") || item.getShortname().equals("displayName")) {
            value = "from federation";
        }
        RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, value, locale);
        this.applFormGenerators.add(gen);
        if (!gen.isVisible()) {
            continue;
        }
        ItemTexts itemTexts = item.getItemTexts(locale);
        // WITH LABEL (input box ...)
        if (gen.isLabelShown()) {
            // 0 = label
            ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "</strong>");
            // 1 = widget
            Widget w = gen.getWidget();
            w.setTitle(itemTexts.getHelp());
            ft.setWidget(i, 1, w);
        // ELSE HTML COMMENT
        } else {
            ft.setWidget(i, 0, gen.getWidget());
            // colspan = 2
            fcf.setColSpan(i, 0, 2);
        }
        // format
        fcf.setHeight(i, 0, "35px");
        fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_TOP);
        fcf.setVerticalAlignment(i, 1, HasVerticalAlignment.ALIGN_MIDDLE);
        i++;
    }
    contents.setWidget(ft);
}
Also used : RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator) FlexCellFormatter(com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)

Example 7 with RegistrarFormItemGenerator

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

the class GetFormItems method getValues.

/**
	 * Generates the values from the form
	 * @return
	 */
public ArrayList<ApplicationFormItemData> getValues() {
    ArrayList<ApplicationFormItemData> formItemDataList = new ArrayList<ApplicationFormItemData>();
    // goes through all the item generators and retrieves the value
    for (RegistrarFormItemGenerator gen : applFormGenerators) {
        String value = gen.getValue();
        String prefilled = gen.getPrefilledValue();
        JSONObject formItemJSON = new JSONObject(gen.getFormItem());
        // remove text (locale), saves data transfer & removes problem with parsing locale
        formItemJSON.put("i18n", new JSONObject());
        // cast form item back
        ApplicationFormItem formItem = formItemJSON.getJavaScriptObject().cast();
        // prepare package with data
        ApplicationFormItemData data = ApplicationFormItemData.construct(formItem, formItem.getShortname(), value, prefilled, "");
        formItemDataList.add(data);
    }
    return formItemDataList;
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator) ArrayList(java.util.ArrayList)

Example 8 with RegistrarFormItemGenerator

use of cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator 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)

Example 9 with RegistrarFormItemGenerator

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

the class GetFormItemsWithPrefilledValues method validateFormValues.

/**
	 * Validates the form values
	 */
protected boolean validateFormValues(boolean forcedValidation) {
    if (sendButton == null)
        return false;
    boolean valid = true;
    sendButton.setEnabled(true);
    for (RegistrarFormItemGenerator gen : applFormGenerators) {
        if (gen.getInputChecker().isValidating() || !gen.getInputChecker().isValid(forcedValidation)) {
            sendButton.setEnabled(false);
            valid = false;
            if (!forcedValidation) {
                return false;
            }
        }
    }
    return valid;
}
Also used : RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)

Example 10 with RegistrarFormItemGenerator

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

the class PreviewFormTabItem method validateFormValues.

/**
	 * Validates the form values
	 */
protected boolean validateFormValues(boolean forcedValidation) {
    if (sendButton == null)
        return false;
    boolean valid = true;
    sendButton.setEnabled(true);
    for (RegistrarFormItemGenerator gen : applFormGenerators) {
        if (gen.getInputChecker().isValidating() || !gen.getInputChecker().isValid(forcedValidation)) {
            sendButton.setEnabled(false);
            valid = false;
            if (!forcedValidation) {
                return false;
            }
        }
    }
    return valid;
}
Also used : RegistrarFormItemGenerator(cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)

Aggregations

RegistrarFormItemGenerator (cz.metacentrum.perun.webgui.client.applicationresources.RegistrarFormItemGenerator)10 FlexCellFormatter (com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 JSONObject (com.google.gwt.json.client.JSONObject)2 FormValidator (cz.metacentrum.perun.webgui.client.applicationresources.FormValidator)2 Confirm (cz.metacentrum.perun.webgui.widgets.Confirm)2 ArrayList (java.util.ArrayList)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 JSONString (com.google.gwt.json.client.JSONString)1 Element (com.google.gwt.user.client.Element)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 ApplicationFormItem (cz.metacentrum.perun.webgui.model.ApplicationFormItem)1 ApplicationFormItemData (cz.metacentrum.perun.webgui.model.ApplicationFormItemData)1 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)1 EditFormItemTabItem (cz.metacentrum.perun.webgui.tabs.registrartabs.EditFormItemTabItem)1 AjaxLoaderImage (cz.metacentrum.perun.webgui.widgets.AjaxLoaderImage)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1