Search in sources :

Example 16 with KalendarRecurEvent

use of org.olat.commons.calendar.model.KalendarRecurEvent in project OpenOLAT by OpenOLAT.

the class FullCalendarElement method doResize.

protected void doResize(UserRequest ureq, String eventId, String minuteDelta, String allDayStr) {
    Long minute = null;
    if (StringHelper.isLong(minuteDelta)) {
        minute = Long.parseLong(minuteDelta);
    }
    Boolean allDay = null;
    if ("true".equals(allDayStr)) {
        allDay = Boolean.TRUE;
    } else if ("false".equals(allDayStr)) {
        allDay = Boolean.FALSE;
    }
    if (component.isOccurenceOfCalendarEvent(eventId)) {
        String uid = component.getCalendarEventUid(eventId);
        KalendarRenderWrapper cal = component.getCalendarById(uid);
        KalendarRecurEvent rEvent = getCurrenceKalendarEvent(cal, eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUIResizeEvent(this, rEvent, cal, minute, allDay));
    } else if (component.isReccurenceOfCalendarEvent(eventId)) {
        String uid = component.getCalendarEventUid(eventId);
        KalendarRenderWrapper cal = component.getCalendarById(uid);
        KalendarRecurEvent rEvent = getCurrenceKalendarEvent(cal, eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUIResizeEvent(this, rEvent, cal, minute, allDay));
    } else {
        KalendarEvent event = component.getCalendarEvent(eventId);
        KalendarRenderWrapper calWrapper = component.getCalendarByNormalizedId(eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUIResizeEvent(this, event, calWrapper, minute, allDay));
    }
}
Also used : CalendarGUIResizeEvent(org.olat.commons.calendar.ui.events.CalendarGUIResizeEvent) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent)

Example 17 with KalendarRecurEvent

use of org.olat.commons.calendar.model.KalendarRecurEvent in project openolat by klemens.

the class FullCalendarElement method doSelect.

private void doSelect(UserRequest ureq, String eventId, String targetDomId) {
    KalendarEvent event = component.getCalendarEvent(eventId);
    if (component.isOccurenceOfCalendarEvent(eventId)) {
        String uid = component.getCalendarEventUid(eventId);
        KalendarRenderWrapper cal = component.getCalendarById(uid);
        KalendarRecurEvent recurEvent = getCurrenceKalendarEvent(cal, eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, recurEvent, cal, targetDomId));
    } else if (component.isReccurenceOfCalendarEvent(eventId)) {
        String uid = component.getCalendarEventUid(eventId);
        KalendarRenderWrapper cal = component.getCalendarById(uid);
        KalendarRecurEvent recurEvent = getCurrenceKalendarEvent(cal, eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, recurEvent, cal, targetDomId));
    } else {
        KalendarRenderWrapper calWrapper = component.getCalendarByNormalizedId(eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, event, calWrapper, targetDomId));
    }
}
Also used : KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) CalendarGUISelectEvent(org.olat.commons.calendar.ui.events.CalendarGUISelectEvent)

Example 18 with KalendarRecurEvent

use of org.olat.commons.calendar.model.KalendarRecurEvent in project openolat by klemens.

the class FullCalendarElement method doMove.

protected void doMove(UserRequest ureq, String eventId, String dayDelta, String minuteDelta, String allDayStr) {
    Long day = null;
    if (StringHelper.isLong(dayDelta)) {
        day = Long.parseLong(dayDelta);
    }
    Long minute = null;
    if (StringHelper.isLong(minuteDelta)) {
        minute = Long.parseLong(minuteDelta);
    }
    Boolean allDay = null;
    if ("true".equals(allDayStr)) {
        allDay = Boolean.TRUE;
    } else if ("false".equals(allDayStr)) {
        allDay = Boolean.FALSE;
    }
    if (component.isOccurenceOfCalendarEvent(eventId)) {
        String uid = component.getCalendarEventUid(eventId);
        KalendarRenderWrapper cal = component.getCalendarById(uid);
        KalendarRecurEvent rEvent = getCurrenceKalendarEvent(cal, eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUIMoveEvent(this, rEvent, cal, day, minute, allDay));
    } else if (component.isReccurenceOfCalendarEvent(eventId)) {
        String uid = component.getCalendarEventUid(eventId);
        KalendarRenderWrapper cal = component.getCalendarById(uid);
        KalendarRecurEvent rEvent = getCurrenceKalendarEvent(cal, eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUIMoveEvent(this, rEvent, cal, day, minute, allDay));
    } else {
        KalendarEvent event = component.getCalendarEvent(eventId);
        KalendarRenderWrapper calWrapper = component.getCalendarByNormalizedId(eventId);
        getRootForm().fireFormEvent(ureq, new CalendarGUIMoveEvent(this, event, calWrapper, day, minute, allDay));
    }
}
Also used : CalendarGUIMoveEvent(org.olat.commons.calendar.ui.events.CalendarGUIMoveEvent) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent)

Example 19 with KalendarRecurEvent

use of org.olat.commons.calendar.model.KalendarRecurEvent in project openolat by klemens.

the class ICalFileCalendarManager method getRecurringEventsInPeriod.

private final List<KalendarRecurEvent> getRecurringEventsInPeriod(KalendarEvent kEvent, Date periodStart, Date periodEnd, TimeZone userTz) {
    VEvent vEvent = getVEvent(kEvent);
    if (vEvent.getEndDate() == null || vEvent.getStartDate().getDate().after(vEvent.getEndDate().getDate())) {
        return Collections.emptyList();
    }
    // calculate the events in the specified period
    Period recurringPeriod = new Period(new DateTime(periodStart), new DateTime(periodEnd));
    PeriodList periodList = vEvent.calculateRecurrenceSet(recurringPeriod);
    List<KalendarRecurEvent> recurringEvents = new ArrayList<>(periodList.size());
    for (Object obj : periodList) {
        Period period = (Period) obj;
        Date date = period.getStart();
        java.util.Calendar eventStartCal = java.util.Calendar.getInstance();
        eventStartCal.clear();
        eventStartCal.setTime(kEvent.getBegin());
        java.util.Calendar eventEndCal = java.util.Calendar.getInstance();
        eventEndCal.clear();
        eventEndCal.setTime(kEvent.getEnd());
        java.util.Calendar recurStartCal = java.util.Calendar.getInstance();
        recurStartCal.clear();
        if (userTz == null) {
            recurStartCal.setTimeInMillis(date.getTime());
        } else {
            recurStartCal.setTimeInMillis(date.getTime() - userTz.getOffset(date.getTime()));
        }
        long duration = kEvent.getEnd().getTime() - kEvent.getBegin().getTime();
        java.util.Calendar beginCal = java.util.Calendar.getInstance();
        beginCal.clear();
        beginCal.set(recurStartCal.get(java.util.Calendar.YEAR), recurStartCal.get(java.util.Calendar.MONTH), recurStartCal.get(java.util.Calendar.DATE), eventStartCal.get(java.util.Calendar.HOUR_OF_DAY), eventStartCal.get(java.util.Calendar.MINUTE), eventStartCal.get(java.util.Calendar.SECOND));
        java.util.Calendar endCal = java.util.Calendar.getInstance();
        endCal.clear();
        endCal.setTimeInMillis(beginCal.getTimeInMillis() + duration);
        boolean original = false;
        if (kEvent.getBegin().compareTo(beginCal.getTime()) == 0) {
            // prevent doubled events
            original = true;
        }
        Date recurrenceEnd = getRecurrenceEndDate(kEvent.getRecurrenceRule());
        if (kEvent.isAllDayEvent() && recurrenceEnd != null && recurStartCal.getTime().after(recurrenceEnd)) {
            // workaround for ical4j-bug in all day events
            continue;
        }
        KalendarRecurEvent recurEvent = new KalendarRecurEvent(kEvent.getID(), original, kEvent.getSubject(), beginCal.getTime(), endCal.getTime());
        recurEvent.setOccurenceDate(beginCal.getTime());
        recurEvent.setSourceEvent(kEvent);
        recurringEvents.add(recurEvent);
    }
    return recurringEvents;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) ArrayList(java.util.ArrayList) Period(net.fortuna.ical4j.model.Period) PeriodList(net.fortuna.ical4j.model.PeriodList) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent)

Example 20 with KalendarRecurEvent

use of org.olat.commons.calendar.model.KalendarRecurEvent in project openolat by klemens.

the class ICalFileCalendarManager method removeEventFrom.

/**
 * @see org.olat.commons.calendar.CalendarManager#removeEventFrom(org.olat.commons.calendar.model.Kalendar, org.olat.commons.calendar.model.KalendarEvent)
 */
@Override
public boolean removeEventFrom(final Kalendar cal, final KalendarEvent kalendarEvent) {
    OLATResourceable calOres = getOresHelperFor(cal);
    Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {

        @Override
        public Boolean execute() {
            String uid = kalendarEvent.getID();
            String recurrenceId = kalendarEvent.getRecurrenceID();
            Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
            if (StringHelper.containsNonWhitespace(recurrenceId)) {
                loadedCal.removeEvent(kalendarEvent);
                KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
                if (rootEvent != null && kalendarEvent instanceof KalendarRecurEvent) {
                    Date recurrenceDate = ((KalendarRecurEvent) kalendarEvent).getOccurenceDate();
                    rootEvent.addRecurrenceExc(recurrenceDate);
                }
            } else {
                for (KalendarEvent kEvent : loadedCal.getEvents()) {
                    if (uid.equals(kEvent.getID())) {
                        loadedCal.removeEvent(kEvent);
                    }
                }
            }
            boolean successfullyPersist = persistCalendar(loadedCal);
            return new Boolean(successfullyPersist);
        }
    });
    // inform all controller about calendar change for reload
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
    return removeSuccessful.booleanValue();
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) OLATResourceable(org.olat.core.id.OLATResourceable) KalendarRecurEvent(org.olat.commons.calendar.model.KalendarRecurEvent) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)

Aggregations

KalendarRecurEvent (org.olat.commons.calendar.model.KalendarRecurEvent)20 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)12 Date (java.util.Date)8 Kalendar (org.olat.commons.calendar.model.Kalendar)8 ExDate (net.fortuna.ical4j.model.property.ExDate)6 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 ArrayList (java.util.ArrayList)4 DateTime (net.fortuna.ical4j.model.DateTime)4 PeriodList (net.fortuna.ical4j.model.PeriodList)4 VEvent (net.fortuna.ical4j.model.component.VEvent)4 CalendarManager (org.olat.commons.calendar.CalendarManager)4 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DateList (net.fortuna.ical4j.model.DateList)2 Period (net.fortuna.ical4j.model.Period)2 PropertyList (net.fortuna.ical4j.model.PropertyList)2 RecurrenceId (net.fortuna.ical4j.model.property.RecurrenceId)2 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)2 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)2