/**
* 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.course.archiver;
import java.util.Date;
import java.util.Locale;
import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.formelements.CheckBoxElement;
import org.olat.core.gui.formelements.DateElement;
import org.olat.core.gui.formelements.SpacerElement;
import org.olat.core.gui.translator.Translator;
import org.olat.core.util.Formatter;
/**
* @author schneider
*
* Comment: Shows or don't shows three checkboxes appropriate the parameters in the constructor.
* At least on of them has to be true.
*/
public class LogFileChooserForm extends Form {
private CheckBoxElement logAdmin;
private CheckBoxElement logUser;
private CheckBoxElement logStat;
private DateElement beginDate;
private DateElement endDate;
/**
*
* @param name
* @param translator
* @param isOLATAdmin
* @param aLogV adminLogVisibility
* @param uLogV userLogVisibility
* @param sLogV statisticLogVisibility
*/
public LogFileChooserForm(String name, Translator translator, Locale locale, boolean isOLATAdmin, boolean aLogV, boolean uLogV, boolean sLogV) {
super(name, translator);
logAdmin = new CheckBoxElement("logfilechooserform.logadmin", false);
logUser = new CheckBoxElement("logfilechooserform.loguser", false);
logStat = new CheckBoxElement("logfilechooserform.logstat", false);
if (isOLATAdmin || aLogV)
addFormElement("logAdmin", logAdmin);
if (isOLATAdmin || uLogV)
addFormElement("logUser", logUser);
if (isOLATAdmin || sLogV)
addFormElement("logStat", logStat);
addFormElement("spacer1", new SpacerElement());
this.beginDate = new DateElement("logfilechooserform.begindate", locale);
this.beginDate.setExample(Formatter.getInstance(locale).formatDate(new Date()));
addFormElement("startdate", this.beginDate);
this.endDate = new DateElement("logfilechooserform.enddate", locale);
this.endDate.setExample(Formatter.getInstance(locale).formatDate(new Date()));
addFormElement("enddate", this.endDate);
setSubmitKey("logfilechooserform.archive");
setCancelButton();
}
/**
* @see org.olat.core.gui.components.Form#validate(org.olat.core.gui.UserRequest)
*/
public boolean validate() {
boolean logChecked = false;
boolean beginLessThanEndOk = true;
if(logAdmin.isChecked()
|| logUser.isChecked()
|| logStat.isChecked()){
logChecked = true;
}else{
logStat.setErrorKey("course.logs.error");
}
// note: we're no longer restricting to have both a begin and an end
// - there is no underlying reason for limiting this
if((beginDate.getDate() != null)&&(endDate.getDate() != null)){
if (beginDate.getDate().after(endDate.getDate())){
beginLessThanEndOk= false;
beginDate.setErrorKey("logfilechooserform.endlessthanbegin");
}
}
return logChecked && beginLessThanEndOk;
}
/**
* @return true if logAdmin is checked
*/
public boolean logAdminChecked() {
return logAdmin.isChecked();
}
/**
* @return true if logUser is checked
*/
public boolean logUserChecked() {
return logUser.isChecked();
}
/**
* @return true if logStat is checked
*/
public boolean logStatChecked() {
return logStat.isChecked();
}
/**
*
* @return null if no User input, otherwise the Date
*/
public Date getBeginDate(){
return this.beginDate.getDate();
}
/**
*
* @return null if no User input, otherwise the Date
*/
public Date getEndDate(){
return this.endDate.getDate();
}
}