use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class GuiDemoFlexiFormHideUnhide method initForm.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer, org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("guidemo_flexi_form_hideunhide");
final boolean inputMode = !personData.isReadOnly();
/*
* hide unhide chooser
*/
checkbox = uifactory.addCheckboxesVertical("checkbox", "guidemo.flexi.form.show", formLayout, new String[] { "ison" }, new String[] { "" }, 1);
checkbox.select("ison", true);
// register for on click event to hide/disable other elements
checkbox.addActionListener(FormEvent.ONCLICK);
// rule to hide/unhide is defined at the end
firstName = uifactory.addTextElement("firstname", "guidemo.flexi.form.firstname", 256, personData.getFirstName(), formLayout);
firstName.setNotEmptyCheck("guidemo.flexi.form.mustbefilled");
firstName.setMandatory(true);
firstName.setEnabled(inputMode);
lastName = uifactory.addTextElement("firstname", "guidemo.flexi.form.lastname", 256, personData.getLastName(), formLayout);
lastName.setNotEmptyCheck("guidemo.flexi.form.mustbefilled");
lastName.setMandatory(true);
lastName.setEnabled(inputMode);
institution = uifactory.addTextElement("institution", "guidemo.flexi.form.institution", 256, personData.getInstitution(), formLayout);
institution.setEnabled(inputMode);
if (inputMode) {
// submit only if in input mode
submit = new FormSubmit("submit", "submit");
formLayout.add(submit);
}
/*
* now the rules to hide unhide
*/
Set<FormItem> targets = new HashSet<FormItem>();
targets.add(firstName);
targets.add(lastName);
targets.add(institution);
targets.add(submit);
RulesFactory.createHideRule(checkbox, null, targets, formLayout);
RulesFactory.createShowRule(checkbox, "ison", targets, formLayout);
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class EnrollmentEditForm method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormDescription("coursecreation.enrollment.shortDescription");
FormLayoutContainer formButtons = FormLayoutContainer.createButtonLayout("formButtons", this.getTranslator());
// create group count textbox
groupCount = uifactory.addTextElement("groupCount", "en.groupcount", 3, courseConfig.getGroupCount().toString(), formLayout);
groupCount.setLabel("en.groupcount", null);
groupCount.setErrorKey("cce.enrollment.error.groupcount", null);
groupCount.setRegexMatchCheck("\\d*", "cce.enrollment.error.groupcount");
groupCount.showError(false);
if (courseConfig.getSubscriberCount() != null)
subscriberCount = uifactory.addTextElement("subscriberCount", "en.subscribercount", 3, courseConfig.getSubscriberCount().toString(), formLayout);
else
subscriberCount = uifactory.addTextElement("subscriberCount", "en.subscribercount", 3, SUBSCRIBER_COUNT, formLayout);
subscriberCount.setErrorKey("cce.enrollment.error.subscribercount", null);
subscriberCount.showError(false);
keys = new String[] { "ison" };
values = new String[] { "" };
accessLimit = uifactory.addCheckboxesVertical("accessLimit", formLayout, keys, values, 1);
accessLimit.setLabel("en.accesscheckbox", null);
accessLimit.select("ison", courseConfig.getEnableAccessLimit());
accessLimit.addActionListener(FormEvent.ONCLICK);
keys = new String[elements.size()];
values = new String[elements.size()];
for (int i = 0; i < elements.size(); i++) {
keys[i] = elements.get(i);
}
for (int i = 0; i < elements.size(); i++) {
values[i] = elements.get(i);
}
courseElements = uifactory.addCheckboxesVertical("courseElements", formLayout, keys, values, 1);
courseElements.setLabel("en.selectelements", null);
if (!accessLimit.isSelected(0))
courseElements.setVisible(false);
// copy elements list into an array
for (int i = 0; i < elements.size(); i++) {
keys[i] = elements.get(i);
if (keys[i].equals(translate("cce.informationpage"))) {
courseElements.select(keys[i], courseConfig.isEnableAclSinglePage());
} else if (keys[i].equals(translate("cce.downloadfolder"))) {
courseElements.select(keys[i], courseConfig.isEnableAclDownloadFolder());
} else if (keys[i].equals(translate("cce.forum"))) {
courseElements.select(keys[i], courseConfig.isEnableAclForum());
} else if (keys[i].equals(translate("cce.contactform"))) {
courseElements.select(keys[i], courseConfig.isEnableAclContactForm());
}
}
// rules to hide / unhide
Set<FormItem> targets = new HashSet<FormItem>();
targets.add(courseElements);
RulesFactory.createHideRule(accessLimit, null, targets, formLayout);
RulesFactory.createShowRule(accessLimit, "ison", targets, formLayout);
// Buttons
formLayout.add(formButtons);
uifactory.addFormSubmitButton("okButton", formButtons);
uifactory.addFormCancelButton("cancelButton", formButtons, ureq, getWindowControl());
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class FormLayoutContainer method remove.
/**
* remove the component with the give name from this container
* @param binderName
*/
public void remove(String formCompName) {
FormItem toBeRemoved = getFormComponent(formCompName);
remove(formCompName, toBeRemoved);
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class UserSearchController method doSearch.
private void doSearch(UserRequest ureq) {
String login = searchform.login.getValue();
// build user fields search map
Map<String, String> userPropertiesSearch = new HashMap<>();
for (UserPropertyHandler userPropertyHandler : searchform.userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
FormItem ui = searchform.propFormItems.get(userPropertyHandler.getName());
String uiValue = userPropertyHandler.getStringValue(ui);
if (userPropertyHandler.getName().startsWith("genericCheckboxProperty")) {
if (!"false".equals(uiValue)) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
} else if (StringHelper.containsNonWhitespace(uiValue)) {
userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
}
}
if (userPropertiesSearch.isEmpty()) {
userPropertiesSearch = null;
}
tableCtr = new TableController(tableConfig, ureq, getWindowControl(), myContent.getTranslator());
listenTo(tableCtr);
List<Identity> users = searchUsers(login, userPropertiesSearch, true);
int maxResults = securityModule.getUserSearchMaxResultsValue();
if (maxResults > 0 && users.size() > maxResults) {
users = users.subList(0, maxResults);
showWarning("error.search.maxResults", Integer.toString(maxResults));
}
if (!users.isEmpty()) {
tdm = new UserTableDataModel(users, getLocale(), isAdministrativeUser);
// add the data column descriptors
tdm.addColumnDescriptors(tableCtr, null);
// add the action columns
if (useMultiSelect) {
// add multiselect action
tableCtr.addMultiSelectAction(this.actionKeyChoose, ACTION_MULTISELECT_CHOOSE);
} else {
// add single column selec action
tableCtr.addColumnDescriptor(new StaticColumnDescriptor(ACTION_SINGLESELECT_CHOOSE, "table.header.action", myContent.getTranslator().translate("action.choose")));
}
tableCtr.setTableDataModel(tdm);
tableCtr.setMultiSelect(useMultiSelect);
searchPanel.pushContent(tableCtr.getInitialComponent());
myContent.contextPut("showButton", "true");
} else {
getWindowControl().setInfo(translate("error.no.user.found"));
}
}
use of org.olat.core.gui.components.form.flexible.FormItem in project OpenOLAT by OpenOLAT.
the class NewUserForm method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
// validate if username does match the syntactical login requirements
String loginName = usernameTextElement.getValue();
if (usernameTextElement.isEmpty() || !UserManager.getInstance().syntaxCheckOlatLogin(loginName)) {
usernameTextElement.setErrorKey("new.error.loginname.empty", new String[] {});
return false;
}
// Check if login is still available
Identity identity = BaseSecurityManager.getInstance().findIdentityByName(loginName);
if (identity != null) {
usernameTextElement.setErrorKey("new.error.loginname.choosen", new String[] {});
return false;
}
usernameTextElement.clearError();
// validate special rules for each user property
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
// we assume here that there are only textElements for the user properties
FormItem formItem = flc.getFormComponent(userPropertyHandler.getName());
if (!userPropertyHandler.isValid(null, formItem, null) || formItem.hasError()) {
return false;
}
formItem.clearError();
}
// special test on email address: validate if email is already used
String email = emailTextElement.getValue();
if (!UserManager.getInstance().isEmailAllowed(email)) {
emailTextElement.setErrorKey("new.error.email.choosen", new String[] {});
return false;
}
// password fields depend on form configuration
if (showPasswordFields && psw1TextElement != null && psw2TextElement != null && authCheckbox.isSelected(0)) {
String pwd = psw1TextElement.getValue();
if (psw1TextElement.isEmpty("new.form.mandatory") || psw1TextElement.hasError()) {
return false;
}
if (!UserManager.getInstance().syntaxCheckOlatPassword(pwd)) {
psw1TextElement.setErrorKey("form.checkPassword", new String[] {});
return false;
}
psw1TextElement.clearError();
if (psw2TextElement.isEmpty("new.form.mandatory") || psw2TextElement.hasError()) {
return false;
}
// validate that both passwords are the same
if (!pwd.equals(psw2TextElement.getValue())) {
psw2TextElement.setErrorKey("new.error.password.nomatch", new String[] {});
return false;
}
psw2TextElement.clearError();
}
// all checks passed
return true;
}
Aggregations