/**
* OLAT - Online Learning and Training<br />
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br />
* you may not use this file except in compliance with the License.<br />
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br />
* software distributed under the License is distributed on an "AS IS" BASIS, <br />
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br />
* See the License for the specific language governing permissions and <br />
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br />
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.instantMessaging.ui;
import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.formelements.RadioButtonGroupElement;
import org.olat.core.gui.formelements.SpacerElement;
import org.olat.core.gui.formelements.StaticSingleSelectionElement;
import org.olat.core.gui.formelements.VisibilityDependsOnSelectionRule;
import org.olat.core.gui.translator.Translator;
import org.olat.core.id.Identity;
import org.olat.instantMessaging.ImPreferences;
/**
* Initial Date: August 08, 2005
*
* @author Alexander Schneider
*
* Comment: The user can select if his name is (in)visible on the online user list.
*/
public class OnlineListForm extends Form {
private static final String ONLINELIST = "onlineList";
private static final String ONLINETIME = "onlineTime";
private static final String COURSENAME = "courseName";
private RadioButtonGroupElement toogleVisibility;
private StaticSingleSelectionElement onlineTimeSwitch, courseNameSwitch;
/**
* @param name
* @param translator
* @param identity
* @param imPrefs
*/
public OnlineListForm(String name, Translator translator, Identity identity, ImPreferences imPrefs) {
super(name, translator);
// on online user list visible
String[] ynKeys = new String[] { Boolean.TRUE.toString(), Boolean.FALSE.toString() };
String[] ynValue = new String[] { translate("yes"), translate("no") };
toogleVisibility = new RadioButtonGroupElement(false, "form.onlinelist", ynKeys, ynValue);
if (imPrefs.isVisibleToOthers()) toogleVisibility.select(Boolean.TRUE.toString(), true);
else toogleVisibility.select(Boolean.FALSE.toString(), true);
addFormElement(ONLINELIST, toogleVisibility);
SpacerElement s1 = new SpacerElement(true, false);
addFormElement("s1", s1);
// online time visible switch
String[] onlineTimeSwitchKeys = new String[] { Boolean.TRUE.toString(), Boolean.FALSE.toString() };
String[] onlineTimeSwitchValues = new String[] { translate("yes"), translate("no") };
onlineTimeSwitch = new StaticSingleSelectionElement("form.onlinetime", onlineTimeSwitchKeys, onlineTimeSwitchValues);
if (imPrefs.isOnlineTimeVisible()) onlineTimeSwitch.select(Boolean.TRUE.toString(), true);
else onlineTimeSwitch.select(Boolean.FALSE.toString(), true);
addFormElement(ONLINETIME, onlineTimeSwitch);
SpacerElement s2 = new SpacerElement(true, false);
addFormElement("s2", s2);
// course name visible
String[] courseNameSwitchKeys = new String[] { Boolean.TRUE.toString(), Boolean.FALSE.toString() };
String[] courseNameSwitchValues = new String[] { translate("yes"), translate("no") };
courseNameSwitch = new StaticSingleSelectionElement("form.coursename", courseNameSwitchKeys, courseNameSwitchValues);
if (imPrefs.isAwarenessVisible()) courseNameSwitch.select(Boolean.TRUE.toString(), true);
else courseNameSwitch.select(Boolean.FALSE.toString(), true);
addFormElement(COURSENAME, courseNameSwitch);
SpacerElement s3 = new SpacerElement(true, false);
addFormElement("s3", s3);
// rules
VisibilityDependsOnSelectionRule rule;
rule = new VisibilityDependsOnSelectionRule(toogleVisibility, onlineTimeSwitch, Boolean.FALSE.toString(), false, Boolean.FALSE
.toString(), true);
addVisibilityDependsOnSelectionRule(rule);
rule = new VisibilityDependsOnSelectionRule(toogleVisibility, courseNameSwitch, Boolean.FALSE.toString(), false, Boolean.FALSE
.toString(), true);
addVisibilityDependsOnSelectionRule(rule);
rule = new VisibilityDependsOnSelectionRule(toogleVisibility, s1, Boolean.FALSE.toString(), false, null, true);
addVisibilityDependsOnSelectionRule(rule);
rule = new VisibilityDependsOnSelectionRule(toogleVisibility, s2, Boolean.FALSE.toString(), false, null, true);
addVisibilityDependsOnSelectionRule(rule);
addVisibilityDependsOnSelectionRule(rule);
rule = new VisibilityDependsOnSelectionRule(toogleVisibility, s3, Boolean.FALSE.toString(), false, null, true);
addVisibilityDependsOnSelectionRule(rule);
addSubmitKey("save", "save");
setCancelButton();
}
/**
* @param imPrefs
*/
public void updateImPreferencesFromFormData(ImPreferences imPrefs){
boolean isVisibleToOthers = toogleVisibility.getSelectedKey().equals(Boolean.TRUE.toString());
imPrefs.setVisibleToOthers(isVisibleToOthers);
boolean isDisplayTimeVisible = onlineTimeSwitch.getSelectedKey().equals(Boolean.TRUE.toString());
imPrefs.setOnlineTimeVisible(isDisplayTimeVisible);
boolean isAwarenessVisible = courseNameSwitch.getSelectedKey().equals(Boolean.TRUE.toString());
imPrefs.setAwarenessVisible(isAwarenessVisible);
}
/**
* @see org.olat.core.gui.components.Form#validate(org.olat.core.gui.UserRequest)
*/
public boolean validate() {
return true;
}
}