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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations