use of org.olat.core.gui.components.form.flexible.elements.StaticTextElement in project openolat by klemens.
the class PreferencesFormController 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)
*/
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("title.prefs");
setFormContextHelp("Configuration#_einstellungen");
// load preferences
Preferences prefs = tobeChangedIdentity.getUser().getPreferences();
// Username
StaticTextElement username = uifactory.addStaticTextElement("form.username", tobeChangedIdentity.getName(), formLayout);
username.setElementCssClass("o_sel_home_settings_username");
username.setEnabled(false);
// Roles
final String[] roleKeys = new String[] { Constants.GROUP_USERMANAGERS, Constants.GROUP_GROUPMANAGERS, Constants.GROUP_POOL_MANAGER, Constants.GROUP_AUTHORS, Constants.GROUP_INST_ORES_MANAGER, Constants.GROUP_ADMIN };
String iname = getIdentity().getUser().getProperty("institutionalName", null);
String ilabel = iname != null ? translate("rightsForm.isInstitutionalResourceManager.institution", iname) : translate("rightsForm.isInstitutionalResourceManager");
final String[] roleValues = new String[] { translate("rightsForm.isUsermanager"), translate("rightsForm.isGroupmanager"), translate("rightsForm.isPoolmanager"), translate("rightsForm.isAuthor"), ilabel, translate("rightsForm.isAdmin") };
final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
String userRoles = "";
List<String> roles = securityManager.getRolesAsString(tobeChangedIdentity);
for (String role : roles) {
for (int i = 0; i < roleKeys.length; i++) {
if (roleKeys[i].equals(role)) {
userRoles = userRoles + roleValues[i] + ", ";
}
}
}
if (userRoles.equals("")) {
userRoles = translate("rightsForm.isAnonymous.false");
} else {
userRoles = userRoles.substring(0, userRoles.lastIndexOf(","));
}
uifactory.addStaticTextElement("rightsForm.roles", userRoles, formLayout);
username.setElementCssClass("o_sel_home_settings_username");
username.setEnabled(false);
// Language
Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
ArrayHelper.sort(langKeys, langValues, false, true, false);
language = uifactory.addDropdownSingleselect("form.language", formLayout, langKeys, langValues, null);
language.setElementCssClass("o_sel_home_settings_language");
String langKey = prefs.getLanguage();
// this server
if (prefs.getLanguage() != null && i18nModule.getEnabledLanguageKeys().contains(langKey)) {
language.select(prefs.getLanguage(), true);
} else {
language.select(I18nModule.getDefaultLocale().toString(), true);
}
// Font size
String[] cssFontsizeValues = new String[] { translate("form.fontsize.xsmall"), translate("form.fontsize.small"), translate("form.fontsize.normal"), translate("form.fontsize.large"), translate("form.fontsize.xlarge"), translate("form.fontsize.presentation") };
fontsize = uifactory.addDropdownSingleselect("form.fontsize", formLayout, cssFontsizeKeys, cssFontsizeValues, null);
fontsize.setElementCssClass("o_sel_home_settings_fontsize");
fontsize.select(prefs.getFontsize(), true);
fontsize.addActionListener(FormEvent.ONCHANGE);
// Email notification interval
NotificationsManager nMgr = NotificationsManager.getInstance();
List<String> intervals = nMgr.getEnabledNotificationIntervals();
if (intervals.size() > 0) {
String[] intervalKeys = new String[intervals.size()];
intervals.toArray(intervalKeys);
String[] intervalValues = new String[intervalKeys.length];
String i18nPrefix = "interval.";
for (int i = 0; i < intervalKeys.length; i++) {
intervalValues[i] = translate(i18nPrefix + intervalKeys[i]);
}
notificationInterval = uifactory.addDropdownSingleselect("form.notification", formLayout, intervalKeys, intervalValues, null);
notificationInterval.setElementCssClass("o_sel_home_settings_notification_interval");
notificationInterval.select(prefs.getNotificationInterval(), true);
}
// fxdiff VCRP-16: intern mail system
MailModule mailModule = (MailModule) CoreSpringFactory.getBean("mailModule");
if (mailModule.isInternSystem()) {
String userEmail = UserManager.getInstance().getUserDisplayEmail(tobeChangedIdentity, ureq.getLocale());
String[] mailInternLabels = new String[] { translate("mail." + mailIntern[0], userEmail), translate("mail." + mailIntern[1], userEmail) };
mailSystem = uifactory.addRadiosVertical("mail-system", "mail.system", formLayout, mailIntern, mailInternLabels);
mailSystem.setElementCssClass("o_sel_home_settings_mail");
String mailPrefs = prefs.getReceiveRealMail();
if (StringHelper.containsNonWhitespace(mailPrefs)) {
if ("true".equals(mailPrefs)) {
mailSystem.select(mailIntern[1], true);
} else {
mailSystem.select(mailIntern[0], true);
}
} else if (mailModule.isReceiveRealMailUserDefaultSetting()) {
mailSystem.select(mailIntern[1], true);
} else {
mailSystem.select(mailIntern[0], true);
}
}
// Text encoding
Map<String, Charset> charsets = Charset.availableCharsets();
String currentCharset = UserManager.getInstance().getUserCharset(tobeChangedIdentity);
String[] csKeys = StringHelper.getMapKeysAsStringArray(charsets);
charset = uifactory.addDropdownSingleselect("form.charset", formLayout, csKeys, csKeys, null);
charset.setElementCssClass("o_sel_home_settings_charset");
if (currentCharset != null) {
for (String csKey : csKeys) {
if (csKey.equals(currentCharset)) {
charset.select(currentCharset, true);
}
}
}
if (!charset.isOneSelected() && charsets.containsKey("UTF-8")) {
charset.select("UTF-8", true);
}
// Submit and cancel buttons
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
buttonLayout.setElementCssClass("o_sel_home_settings_prefs_buttons");
uifactory.addFormSubmitButton("submit", buttonLayout);
uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
use of org.olat.core.gui.components.form.flexible.elements.StaticTextElement in project openolat by klemens.
the class EPShareListController method createContainerForInvitation.
private void createContainerForInvitation(Invitation invitation, EPSharePolicyWrapper policyWrapper, String cmpName, FormLayoutContainer container) {
FormLayoutContainer invitationContainer = FormLayoutContainer.createDefaultFormLayout("map.share.with." + cmpName, getTranslator());
invitationContainer.contextPut("wrapper", policyWrapper);
invitationContainer.setRootForm(mainForm);
container.add("map.share.with." + cmpName, invitationContainer);
TextElement firstNameEl = uifactory.addTextElement("map.share.with.firstName." + cmpName, "map.share.with.firstName", 64, invitation.getFirstName(), invitationContainer);
firstNameEl.setMandatory(true);
firstNameEl.setNotEmptyCheck("map.share.empty.warn");
TextElement lastNameEl = uifactory.addTextElement("map.share.with.lastName." + cmpName, "map.share.with.lastName", 64, invitation.getLastName(), invitationContainer);
lastNameEl.setMandatory(true);
lastNameEl.setNotEmptyCheck("map.share.empty.warn");
TextElement mailEl = uifactory.addTextElement("map.share.with.mail." + cmpName, "map.share.with.mail", 128, invitation.getMail(), invitationContainer);
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("map.share.empty.warn");
if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(invitation.getMail()));
if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
mailEl.setErrorKey("map.share.with.mail.error.olatUser", new String[] { invitation.getMail() });
}
}
policyWrapper.setFirstNameEl(firstNameEl);
policyWrapper.setLastNameEl(lastNameEl);
policyWrapper.setMailEl(mailEl);
String link = getInvitationLink(invitation, map);
StaticTextElement linkEl = uifactory.addStaticTextElement("map.share.with.link." + cmpName, link, invitationContainer);
linkEl.setLabel("map.share.with.link", null);
}
use of org.olat.core.gui.components.form.flexible.elements.StaticTextElement in project openolat by klemens.
the class EPShareListController method initPolicyUI.
/**
* creates the custom formLayoutContainer and adds a form-component for every
* EPSharePolicyWrapper, according to its type.
*/
protected void initPolicyUI() {
String template = Util.getPackageVelocityRoot(this.getClass()) + "/sharePolicy.html";
for (EPSharePolicyWrapper policyWrapper : policyWrappers) {
String cmpName = policyWrapper.getComponentName();
if (cmpName != null && flc.getFormComponent(cmpName) != null) {
flc.remove(cmpName);
}
cmpName = Integer.toString(cmpSuffixGenerator.getAndIncrement());
policyWrapper.setComponentName(cmpName);
FormLayoutContainer container = FormLayoutContainer.createCustomFormLayout(cmpName, getTranslator(), template);
container.contextPut("wrapper", policyWrapper);
container.setRootForm(mainForm);
if (policyWrapper.getType() != null) {
String[] curatedTargetKeys;
String[] curatedTargetValues;
if (!Type.invitation.equals(policyWrapper.getType()) && !loginModule.isInvitationEnabled()) {
curatedTargetKeys = new String[targetKeys.length - 1];
curatedTargetValues = new String[targetKeys.length - 1];
int pos = 0;
for (int i = targetKeys.length; i-- > 0; ) {
if (!targetKeys[i].equals(Type.invitation.name())) {
curatedTargetKeys[pos] = targetKeys[i];
curatedTargetValues[pos++] = targetValues[i];
}
}
} else {
curatedTargetKeys = targetKeys;
curatedTargetValues = targetValues;
}
SingleSelection type = uifactory.addDropdownSingleselect("map.share.target." + cmpName, "map.share.target", container, curatedTargetKeys, curatedTargetValues, null);
type.addActionListener(FormEvent.ONCHANGE);
type.setUserObject(policyWrapper);
type.select(policyWrapper.getType().name(), true);
switch(policyWrapper.getType()) {
case user:
createContainerForUser(policyWrapper, cmpName, container);
break;
case group:
createContainerForGroup(policyWrapper, cmpName, container);
break;
case invitation:
Invitation invitation = policyWrapper.getInvitation();
if (invitation == null) {
invitation = invitationDao.createAndPersistInvitation();
policyWrapper.setInvitation(invitation);
}
createContainerForInvitation(invitation, policyWrapper, cmpName, container);
break;
case allusers:
String text = translate("map.share.with.allOlatUsers");
uifactory.addStaticTextElement("map.share.with." + cmpName, text, container);
break;
}
}
if (policyWrapper instanceof TutorEPSharePolicyWrapper) {
String text = translate("map.share.with.tutor");
uifactory.addStaticTextElement("map.share.text." + cmpName, text, container);
} else {
DateChooser fromChooser = uifactory.addDateChooser("map.share.from." + cmpName, "map.share.from", null, container);
fromChooser.setDate(policyWrapper.getFrom());
fromChooser.setValidDateCheck("map.share.date.invalid");
policyWrapper.setFromChooser(fromChooser);
DateChooser toChooser = uifactory.addDateChooser("map.share.to." + cmpName, "map.share.to", null, container);
toChooser.setDate(policyWrapper.getTo());
toChooser.setValidDateCheck("map.share.date.invalid");
policyWrapper.setToChooser(toChooser);
FormLink addLink = uifactory.addFormLink("map.share.policy.add." + cmpName, "map.share.policy.add", null, container, Link.BUTTON);
addLink.setIconLeftCSS("o_icon o_icon-fw o_icon_add");
addLink.setUserObject(policyWrapper);
FormLink removeLink = uifactory.addFormLink("map.share.policy.delete." + cmpName, "map.share.policy.delete", null, container, Link.BUTTON);
removeLink.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
removeLink.setUserObject(policyWrapper);
if (!policyWrapper.getType().equals(EPMapPolicy.Type.allusers)) {
FormLink inviteLink = uifactory.addFormLink("map.share.policy.invite." + cmpName, "map.share.policy.invite", null, container, Link.BUTTON);
inviteLink.setIconLeftCSS("o_icon o_icon-fw o_icon_share");
inviteLink.setUserObject(policyWrapper);
inviteLink.setEnabled(!policyWrapper.isInvitationSend() && (loginModule.isInvitationEnabled() || !policyWrapper.getType().equals(Type.invitation)));
}
StaticTextElement genErrorPanel = uifactory.addStaticTextElement("errorpanel." + cmpName, "", container);
genErrorPanel.setUserObject(policyWrapper);
policyWrapper.setErrorEl(genErrorPanel);
}
policyWrapper.setComponentName(cmpName);
flc.add(container);
flc.contextPut("wrapper", policyWrapper);
}
flc.contextPut("wrappers", policyWrappers);
}
use of org.olat.core.gui.components.form.flexible.elements.StaticTextElement in project openolat by klemens.
the class EPStructureDetailsController method validateFormLogic.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#validateFormLogic(org.olat.core.gui.UserRequest)
*/
@Override
protected boolean validateFormLogic(UserRequest ureq) {
if (rootStructure instanceof EPStructuredMapTemplate && restrictionElements != null) {
setCollectRestrictions();
clearErrors();
ArrayList<String> usedTypes = new ArrayList<String>();
int i = 0;
boolean hasError = false;
for (SingleSelection restrictionElement : restrictionElements) {
CollectRestriction restriction = (CollectRestriction) restrictionElement.getUserObject();
if (usedTypes.contains(restriction.getArtefactType())) {
StaticTextElement thisErrorEl = errorElements.get(i);
thisErrorEl.setVisible(true);
thisErrorEl.setValue(translate("collect.restriction.duplicate.type"));
hasError = true;
}
usedTypes.add(restriction.getArtefactType());
boolean hasRestriction = StringHelper.containsNonWhitespace(restriction.getRestriction());
boolean hasArtType = StringHelper.containsNonWhitespace(restriction.getArtefactType());
boolean hasAmount = restriction.getAmount() > 0;
boolean isValid = restriction.isValid();
if (!isValid && (hasRestriction || hasArtType || hasAmount)) {
StaticTextElement thisErrorEl = errorElements.get(i);
thisErrorEl.setVisible(true);
thisErrorEl.setValue(translate("collect.restriction.incomplete"));
hasError = true;
}
i++;
}
return !hasError;
}
return true;
}
use of org.olat.core.gui.components.form.flexible.elements.StaticTextElement in project openolat by klemens.
the class CreateRepositoryEntryController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String typeName;
if (handler != null) {
typeName = NewControllerFactory.translateResourceableTypeName(handler.getSupportedType(), getLocale());
} else {
typeName = translate("cif.type.na");
}
StaticTextElement typeEl = uifactory.addStaticTextElement("cif.type", typeName, formLayout);
typeEl.setElementCssClass("o_sel_author_type");
displaynameEl = uifactory.addTextElement("cif.displayname", "cif.displayname", 100, "", formLayout);
displaynameEl.setElementCssClass("o_sel_author_displayname");
displaynameEl.setFocus(true);
displaynameEl.setDisplaySize(30);
displaynameEl.setMandatory(true);
String page = velocity_root + "/example_help.html";
exampleHelpEl = FormLayoutContainer.createCustomFormLayout("example.help", "example.help", getTranslator(), page);
formLayout.add(exampleHelpEl);
exampleHelpEl.setVisible(false);
FormLayoutContainer buttonContainer = FormLayoutContainer.createButtonLayout("buttonContainer", getTranslator());
formLayout.add("buttonContainer", buttonContainer);
buttonContainer.setElementCssClass("o_sel_repo_save_details");
FormSubmit submit = uifactory.addFormSubmitButton("cmd.create.ressource", buttonContainer);
submit.setElementCssClass("o_sel_author_create_submit");
if (handler.isPostCreateWizardAvailable()) {
wizardButton = uifactory.addFormLink("csc.startwizard", buttonContainer, Link.BUTTON);
wizardButton.setElementCssClass("o_sel_author_create_wizard");
}
uifactory.addFormCancelButton("cancel", buttonContainer, ureq, getWindowControl());
}
Aggregations