Search in sources :

Example 1 with MailModule

use of org.olat.core.util.mail.MailModule in project OpenOLAT by OpenOLAT.

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());
}
Also used : Charset(java.nio.charset.Charset) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) BaseSecurity(org.olat.basesecurity.BaseSecurity) MailModule(org.olat.core.util.mail.MailModule) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) Preferences(org.olat.core.id.Preferences)

Example 2 with MailModule

use of org.olat.core.util.mail.MailModule 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());
}
Also used : Charset(java.nio.charset.Charset) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) BaseSecurity(org.olat.basesecurity.BaseSecurity) MailModule(org.olat.core.util.mail.MailModule) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) Preferences(org.olat.core.id.Preferences)

Aggregations

Charset (java.nio.charset.Charset)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)2 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 Preferences (org.olat.core.id.Preferences)2 MailModule (org.olat.core.util.mail.MailModule)2