use of cz.metacentrum.perun.webgui.model.ApplicationFormItem in project perun by CESNET.
the class CreateFormItemTabItem method createItem.
/**
* Creates the item
*
* @param shortname
* @param type
* @param positionToAdd
*/
protected void createItem(String shortname, String type, int positionToAdd) {
ApplicationFormItem item = RegistrarFormItemGenerator.generateFormItem(shortname, type);
// set both app types checked for new item
JSONArray array = new JSONArray();
array.set(0, new JSONString("INITIAL"));
array.set(1, new JSONString("EXTENSION"));
item.setApplicationTypes(array.getJavaScriptObject());
// set also position
item.setOrdnum(positionToAdd);
sourceList.add(positionToAdd, item);
session.getTabManager().addTabToCurrentTab(new EditFormItemTabItem(item, events));
events.onFinished(item);
}
use of cz.metacentrum.perun.webgui.model.ApplicationFormItem in project perun by CESNET.
the class CreateFormItemTabItem method draw.
public Widget draw() {
// vertical panel
VerticalPanel vp = new VerticalPanel();
vp.setSize("425px", "100%");
// flex table
final FlexTable layout = new FlexTable();
layout.setStyleName("inputFormFlexTable");
FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();
// select widget short name
final ExtendedTextBox shortNameTextBox = new ExtendedTextBox();
shortNameTextBox.setWidth("200px");
final ExtendedTextBox.TextBoxValidator validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (shortNameTextBox.getTextBox().getText().trim().isEmpty()) {
shortNameTextBox.setError("Short name can't be empty.");
return false;
} else {
shortNameTextBox.setOk();
return true;
}
}
};
shortNameTextBox.setValidator(validator);
// select widget type
final ListBox typeListBox = new ListBox();
for (String type : inputTypes.keySet()) {
typeListBox.addItem(inputTypes.get(type), type);
}
// insert after
final ListBox insertAfterListBox = new ListBox();
insertAfterListBox.addItem(" - insert to the beginning - ", 0 + "");
for (int i = 0; i < sourceList.size(); i++) {
ApplicationFormItem item = sourceList.get(i);
// with default en locale
RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, "");
String label = gen.getFormItem().getShortname();
// crop length
if (label.length() > CROP_LABEL_LENGTH) {
label = label.substring(0, CROP_LABEL_LENGTH);
}
// add to box
insertAfterListBox.addItem(label, (i + 1) + "");
}
layout.setHTML(0, 0, "Short name:");
layout.setWidget(0, 1, shortNameTextBox);
layout.setHTML(1, 0, "Input widget:");
layout.setWidget(1, 1, typeListBox);
layout.setHTML(2, 0, "Insert after:");
layout.setWidget(2, 1, insertAfterListBox);
for (int i = 0; i < layout.getRowCount(); i++) {
cellFormatter.addStyleName(i, 0, "itemName");
}
layout.setHTML(3, 0, "");
cellFormatter.setColSpan(3, 0, 2);
cellFormatter.setStyleName(3, 0, "inputFormInlineComment");
typeListBox.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
String type = typeListBox.getValue(typeListBox.getSelectedIndex());
if (type.equals("TEXTFIELD")) {
layout.setHTML(3, 0, "Editable text field useful to gather short text input, e.g. name, phone.");
} else if (type.equals("TEXTAREA")) {
layout.setHTML(3, 0, "Editable text area useful to gather longer text input with linebreaks, e.g. comments, SSH key");
} else if (type.equals("SELECTIONBOX")) {
layout.setHTML(3, 0, "Simple selection box with defined custom values that user can choose.");
} else if (type.equals("COMBOBOX")) {
layout.setHTML(3, 0, "Selection box with defined custom values and one special option: \"--custom value--\", which allows users to input own text (as simple text field).");
} else if (type.equals("CHECKBOX")) {
layout.setHTML(3, 0, "List of defined custom options with checkboxes. Selected values are gathered as comma separated string.");
} else if (type.equals("USERNAME")) {
layout.setHTML(3, 0, "Special text field to gather user`s login. It checks login availability on user input.");
} else if (type.equals("PASSWORD")) {
layout.setHTML(3, 0, "Two password fields to gather user`s new password. Input is never displayed. User must type same password in both fields.");
} else if (type.equals("VALIDATED_EMAIL")) {
layout.setHTML(3, 0, "Special text field to gather and verify user`s email address. Input is checked on email address format. If user enters new value, then validation email is sent. Application then can't be approved unless provided email address is validated.");
} else if (type.equals("SUBMIT_BUTTON")) {
layout.setHTML(3, 0, "Button used to submit the form with custom label. All other form items are checked on valid input before submission. If it fails, form is not sent.");
} else if (type.equals("AUTO_SUBMIT_BUTTON")) {
layout.setHTML(3, 0, "Button used to auto-submit the form with custom label. All other form items are checked on valid input before submission. If validation fail (at least once) user must submit form manually. If it's OK, then form is automatically submitted.");
} else if (type.equals("HTML_COMMENT")) {
layout.setHTML(3, 0, "Item is used to display custom HTML content anywhere on form. Useful for explanation descriptions, dividing parts of form etc.");
} else if (type.equals("HEADING")) {
layout.setHTML(3, 0, "Item is used to display customizable heading of form. Can have any HTML content.");
} else if (type.equals("TIMEZONE")) {
layout.setHTML(3, 0, "Selection box with pre-defined values of UTC timezones.");
} else if (type.equals("FROM_FEDERATION_HIDDEN")) {
layout.setHTML(3, 0, "Non-editable and hidden form item. Form is submitted even on invalid input ! Useful to automatically gather information provided by AUTH mechanism (IdP federation, certificate).");
} else if (type.equals("FROM_FEDERATION_SHOW")) {
layout.setHTML(3, 0, "Non-editable and visible form item. Form is submitted even on invalid input ! Useful to automatically gather information provided by AUTH mechanism (IdP federation, certificate).");
} else {
layout.setHTML(3, 0, "");
}
}
});
layout.setHTML(3, 0, "Editable text field useful to gather short text input, e.g. name, phone.");
TabMenu menu = new TabMenu();
// create button
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createFormItem(), new ClickHandler() {
public void onClick(ClickEvent event) {
if (validator.validateTextBox()) {
int positionToAdd = Integer.parseInt(insertAfterListBox.getValue(insertAfterListBox.getSelectedIndex()));
String type = typeListBox.getValue(typeListBox.getSelectedIndex());
String shortName = shortNameTextBox.getTextBox().getText().trim();
createItem(shortName, type, positionToAdd);
}
}
}));
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
session.getTabManager().closeTab(tab, false);
}
}));
vp.add(layout);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.ApplicationFormItem in project perun by CESNET.
the class RegistrarFormItemGenerator method generateFormItem.
/**
* Generates form item from given values
*
* @param shortname
* @param type
* @return
*/
public static ApplicationFormItem generateFormItem(String shortname, String type) {
JSONObject jsonObj = new JSONObject();
jsonObj.put("id", new JSONNumber(0));
jsonObj.put("shortname", new JSONString(shortname));
jsonObj.put("type", new JSONString(type));
jsonObj.put("regex", new JSONString(""));
jsonObj.put("federationAttribute", new JSONString(""));
jsonObj.put("perunDestinationAttribute", new JSONString(""));
jsonObj.put("applicationTypes", new JSONArray());
jsonObj.put("required", JSONBoolean.getInstance(false));
jsonObj.put("i18n", new JSONArray());
jsonObj.put("ordnum", new JSONNumber(-1));
// convert to ApplicationFormItem
ApplicationFormItem formItem = jsonObj.getJavaScriptObject().cast();
return formItem;
}
Aggregations