use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
the class CalendarEntryDetailsController method doSave.
private void doSave(UserRequest ureq) {
// ok, save edited entry
kalendarEvent = eventForm.getUpdatedKalendarEvent();
if (isNew) {
boolean doneSuccessfully = true;
// this is a new event, add event to calendar
String calendarID = eventForm.getChoosenKalendarID();
for (Iterator<KalendarRenderWrapper> iter = availableCalendars.iterator(); iter.hasNext(); ) {
KalendarRenderWrapper calendarWrapper = iter.next();
if (!calendarWrapper.getKalendar().getCalendarID().equals(calendarID)) {
continue;
}
Kalendar cal = calendarWrapper.getKalendar();
boolean result = calendarManager.addEventTo(cal, kalendarEvent);
if (result == false) {
// if one failed => done not successfully
doneSuccessfully = false;
}
}
reportSaveStatus(ureq, doneSuccessfully);
} else if (kalendarEvent instanceof KalendarRecurEvent && !StringHelper.containsNonWhitespace(kalendarEvent.getRecurrenceID())) {
updateCtr = new ConfirmUpdateController(ureq, getWindowControl(), (KalendarRecurEvent) kalendarEvent);
listenTo(updateCtr);
String title = translate("cal.edit.update");
cmc = new CloseableModalController(getWindowControl(), translate("close"), updateCtr.getInitialComponent(), true, title);
listenTo(cmc);
cmc.activate();
} else {
// this is an existing event, so we get the previousely assigned calendar from the event
Kalendar cal = kalendarEvent.getCalendar();
boolean doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
reportSaveStatus(ureq, doneSuccessfully);
}
}
use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
the class CalendarEntryDetailsController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == deleteCtr) {
if (event instanceof CalendarGUIDeleteEvent) {
doDelete((CalendarGUIDeleteEvent) event);
cmc.deactivate();
cleanUp();
fireEvent(ureq, Event.DONE_EVENT);
} else {
cmc.deactivate();
cleanUp();
}
} else if (source == activeLinkProvider) {
if (kalendarEvent.getCalendar() != null) {
fireEvent(ureq, Event.DONE_EVENT);
}
} else if (source == eventForm) {
if (event == Event.DONE_EVENT) {
doSave(ureq);
} else if ("delete".equals(event.getCommand())) {
doConfirmDelete(ureq);
} else if (event == Event.CANCELLED_EVENT) {
eventForm.setEntry(kalendarEvent);
// user canceled, finish workflow
fireEvent(ureq, Event.DONE_EVENT);
}
} else if (source == updateCtr) {
if (event instanceof CalendarGUIUpdateEvent) {
doUpdate((CalendarGUIUpdateEvent) event);
cmc.deactivate();
cleanUp();
fireEvent(ureq, Event.DONE_EVENT);
} else {
cmc.deactivate();
cleanUp();
}
} else if (source == customMediaChooserCtr) {
boolean doneSuccessfully = true;
if (event instanceof URLChoosenEvent) {
URLChoosenEvent urlEvent = (URLChoosenEvent) event;
String url = urlEvent.getURL();
List<KalendarEventLink> links = kalendarEvent.getKalendarEventLinks();
String provider = customMediaChooserCtr.getClass().getSimpleName();
String id = url;
String displayName = StringHelper.containsNonWhitespace(urlEvent.getDisplayName()) ? urlEvent.getDisplayName() : url;
String uri = url.contains("://") ? url : (Settings.getServerContextPathURI() + url);
String iconCssClass = urlEvent.getIconCssClass();
if (!StringHelper.containsNonWhitespace(iconCssClass)) {
iconCssClass = CSSHelper.createFiletypeIconCssClassFor(url);
}
links.add(new KalendarEventLink(provider, id, displayName, uri, iconCssClass));
Kalendar cal = kalendarEvent.getCalendar();
doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
}
if (doneSuccessfully) {
fireEvent(ureq, event);
} else {
showError("cal.error.save");
fireEvent(ureq, Event.FAILED_EVENT);
}
} else if (source == externalLinksController || source == mediaLinksController) {
// save externals links
Kalendar cal = kalendarEvent.getCalendar();
if (kalendarEvent.getCalendar() != null) {
boolean doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
if (doneSuccessfully) {
fireEvent(ureq, Event.DONE_EVENT);
} else {
showError("cal.error.save");
fireEvent(ureq, Event.FAILED_EVENT);
}
}
} else if (cmc == source) {
cleanUp();
}
}
use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
the class CalendarPersonalConfigurationController method doDeleteCalendar.
private void doDeleteCalendar(UserRequest ureq, CalendarPersonalConfigurationRow row) {
if (!row.isImported())
return;
Kalendar calendar = row.getWrapper().getKalendar();
importCalendarManager.deleteCalendar(getIdentity(), calendar);
List<CalendarPersonalConfigurationRow> currentRows = model.getObjects();
currentRows.remove(row);
model.setObjects(currentRows);
tableEl.reloadData();
fireEvent(ureq, new CalendarGUIRemoveEvent(row.getWrapper()));
}
use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
the class CalendarNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si = null;
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
// can't be loaded when already deleted
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
Long id = p.getResId();
String type = p.getSubidentifier();
try {
Translator translator = Util.createPackageTranslator(CalendarModule.class, locale);
String calType = null;
String title = null;
if (type.equals(CalendarController.ACTION_CALENDAR_COURSE)) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", id), false);
if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
calType = CalendarManager.TYPE_COURSE;
title = translator.translate("cal.notifications.header.course", new String[] { displayName });
} else if (type.equals(CalendarController.ACTION_CALENDAR_GROUP)) {
BusinessGroup group = businessGroupDao.load(id);
calType = CalendarManager.TYPE_GROUP;
if (group == null) {
return notificationsManager.getNoSubscriptionInfo();
}
title = translator.translate("cal.notifications.header.group", new String[] { group.getName() });
}
if (calType != null) {
Formatter form = Formatter.getInstance(locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_CALENDAR_ICON), null);
String bPath;
if (StringHelper.containsNonWhitespace(p.getBusinessPath())) {
bPath = p.getBusinessPath();
} else if ("CalendarManager.course".equals(p.getResName())) {
try {
OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.getCourseTypeName(), p.getResId());
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(ores, true);
// Fallback
bPath = "[RepositoryEntry:" + re.getKey() + "]";
} catch (Exception e) {
log.error("Error processing calendar notifications of publisher:" + p.getKey(), e);
return notificationsManager.getNoSubscriptionInfo();
}
} else {
// cannot make link without business path
return notificationsManager.getNoSubscriptionInfo();
}
Kalendar cal = calendarManager.getCalendar(calType, id.toString());
Collection<KalendarEvent> calEvents = cal.getEvents();
for (KalendarEvent kalendarEvent : calEvents) {
if (showEvent(compareDate, kalendarEvent)) {
log.debug("found a KalendarEvent: " + kalendarEvent.getSubject() + " with time: " + kalendarEvent.getBegin() + " modified before: " + compareDate.toString(), null);
// found a modified event in this calendar
Date modDate = null;
if (kalendarEvent.getLastModified() > 0) {
modDate = new Date(kalendarEvent.getLastModified());
} else if (kalendarEvent.getCreated() > 0) {
modDate = new Date(kalendarEvent.getCreated());
} else if (kalendarEvent.getBegin() != null) {
modDate = kalendarEvent.getBegin();
}
String subject = kalendarEvent.getSubject();
String author = kalendarEvent.getCreatedBy();
if (author == null)
author = "";
String location = "";
if (StringHelper.containsNonWhitespace(kalendarEvent.getLocation())) {
location = kalendarEvent.getLocation() == null ? "" : translator.translate("cal.notifications.location", new String[] { kalendarEvent.getLocation() });
}
String dateStr;
if (kalendarEvent.isAllDayEvent()) {
dateStr = form.formatDate(kalendarEvent.getBegin());
} else {
dateStr = form.formatDate(kalendarEvent.getBegin()) + " - " + form.formatDate(kalendarEvent.getEnd());
}
String desc = translator.translate("cal.notifications.entry", new String[] { subject, dateStr, location, author });
String businessPath = bPath + "[path=" + kalendarEvent.getID() + ":0]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_CALENDAR_ICON);
si.addSubscriptionListItem(subListItem);
}
}
}
} catch (Exception e) {
log.error("Unexpected exception", e);
checkPublisher(p);
si = notificationsManager.getNoSubscriptionInfo();
}
} else {
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
the class CopyEventToCalendarController method formOK.
@Override
protected void formOK(UserRequest ureq) {
for (MultipleSelectionElement copyEl : copyEls) {
if (copyEl.isEnabled() && copyEl.isAtLeastSelected(1)) {
KalendarRenderWrapper calendarWrapper = (KalendarRenderWrapper) copyEl.getUserObject();
Kalendar cal = calendarWrapper.getKalendar();
KalendarEvent clonedKalendarEvent = (KalendarEvent) XStreamHelper.xstreamClone(kalendarEvent);
if (clonedKalendarEvent.getKalendarEventLinks().size() > 0) {
clonedKalendarEvent.setKalendarEventLinks(new ArrayList<KalendarEventLink>());
}
calendarManager.addEventTo(cal, clonedKalendarEvent);
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
Aggregations