/**
* 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) 1999-2007 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.commons.calendar.ui;
import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.formelements.TextElement;
import org.olat.core.gui.translator.Translator;
import org.olat.core.gui.UserRequest;
import org.olat.core.id.Identity;
import org.olat.commons.calendar.CalendarManager;
import org.olat.commons.calendar.CalendarManagerFactory;
import org.olat.commons.calendar.ImportCalendarManager;
public class CalendarImportNameForm extends Form {
private static final String SUBMIT_SINGLE = "submit";
private TextElement calendarName;
private Identity identity;
/**
* Display an event for modification or to add a new event.
* @param name
*/
public CalendarImportNameForm(String name, Translator translator, UserRequest ureq) {
super(name, translator);
this.identity = ureq.getIdentity();
// title
// addFormElement("cal.import.calname.title", new TitleElement("cal.import.calname.title"));
// prompt for the calendar name
int identityLen = ureq.getIdentity().getName().length();
// 41=OresHelper.ORES_TYPE_LENGTH - 2 - 7
// 2 because: 1 for the '_' which is added between identity and calendar name,
// and 1 for fuzzy counting which TextElement seems to do...
// 7 because: the CalendarManager.TYPE is prepended to the whole thing adding a _
// and the max length of TYPE is 6 - hence 7
// @see jira OLAT-4202
calendarName = new TextElement("cal.import.calname.prompt", 41-identityLen);
addFormElement("cal.import.calname.prompt", calendarName);
// submit/cancel buttons
addSubmitKey("cal.import.calname.submit", SUBMIT_SINGLE);
// add the cancel button
setCancelButton();
}
public boolean validate() {
if (calendarName.isEmpty()) {
calendarName.setErrorKey("cal.import.calname.empty.error");
return false;
} else {
CalendarManager calManager = CalendarManagerFactory.getInstance().getCalendarManager();
String calID = ImportCalendarManager.getImportedCalendarID(identity, calendarName.getValue());
if (calManager.calendarExists(calManager.TYPE_USER, calID)) {
calendarName.setErrorKey("cal.import.calname.exists.error");
return false;
}
}
return true;
}
public String getCalendarName() {
return calendarName.getValue();
}
}