Search in sources :

Example 51 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class WeeklyCalendarController method pushEditEventController.

/**
 * @param ureq
 * @param kalendarEvent
 * @param kalendarWrapper
 */
private void pushEditEventController(UserRequest ureq, KalendarEvent kalendarEvent, KalendarRenderWrapper kalendarWrapper) {
    if (editController != null)
        return;
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(editController);
    boolean canEdit = false;
    for (Iterator<KalendarRenderWrapper> iter = calendarWrappers.iterator(); iter.hasNext(); ) {
        KalendarRenderWrapper wrapper = iter.next();
        if (wrapper.getAccess() == KalendarRenderWrapper.ACCESS_READ_WRITE && kalendarWrapper.getKalendar().getCalendarID().equals(wrapper.getKalendar().getCalendarID())) {
            canEdit = true;
        }
    }
    if (canEdit) {
        editController = new CalendarEntryDetailsController(ureq, kalendarEvent, kalendarWrapper, calendarWrappers, false, caller, getWindowControl());
        listenTo(editController);
        removeAsListenerAndDispose(cmc);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), editController.getInitialComponent());
        listenTo(cmc);
        cmc.activate();
        // set logging action
        setCalLoggingAction(CalendarLoggingAction.CALENDAR_ENTRY_MODIFIED);
    } else {
        showError("cal.error.readonly");
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 52 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class WeeklyCalendarController method pushAddEventController.

private void pushAddEventController(CalendarGUIAddEvent addEvent, UserRequest ureq) {
    if (editController != null || ureq.getUserSession().getRoles().isGuestOnly()) {
        return;
    }
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(editController);
    KalendarRenderWrapper calendarWrapper = calendarEl.getCalendar(addEvent.getCalendarID());
    List<KalendarRenderWrapper> copyCalendarWrappers = new ArrayList<>(calendarWrappers);
    boolean isReadOnly = calendarWrapper == null ? true : calendarWrapper.getAccess() == KalendarRenderWrapper.ACCESS_READ_ONLY;
    for (KalendarRenderWrapper copyCalendarWrapper : copyCalendarWrappers) {
        isReadOnly &= copyCalendarWrapper.getAccess() == KalendarRenderWrapper.ACCESS_READ_ONLY;
    }
    if (!isReadOnly) {
        // create new KalendarEvent
        KalendarEvent newEvent;
        Date begin = addEvent.getStartDate();
        String eventId = CodeHelper.getGlobalForeverUniqueID();
        if (addEvent.getEndDate() == null) {
            newEvent = new KalendarEvent(eventId, "", begin, (1000 * 60 * 60 * 1));
        } else {
            newEvent = new KalendarEvent(eventId, null, "", begin, addEvent.getEndDate());
        }
        if (calendarWrapper != null && (calendarWrapper.getKalendar().getType().equals(CalendarManager.TYPE_COURSE) || calendarWrapper.getKalendar().getType().equals(CalendarManager.TYPE_GROUP))) {
            newEvent.setClassification(KalendarEvent.CLASS_PUBLIC);
        }
        newEvent.setAllDayEvent(addEvent.isAllDayEvent());
        String lastName = ureq.getIdentity().getUser().getProperty(UserConstants.LASTNAME, getLocale());
        String firstName = ureq.getIdentity().getUser().getProperty(UserConstants.FIRSTNAME, getLocale());
        newEvent.setCreatedBy(firstName + " " + lastName);
        newEvent.setCreated(new Date().getTime());
        editController = new CalendarEntryDetailsController(ureq, newEvent, calendarWrapper, copyCalendarWrappers, true, caller, getWindowControl());
        listenTo(editController);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), editController.getInitialComponent());
        listenTo(cmc);
        cmc.activate();
        // set logging action
        setCalLoggingAction(CalendarLoggingAction.CALENDAR_ENTRY_CREATED);
    }
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date)

Example 53 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class ICalFileCalendarManager method getCalendarForDeletion.

@Override
public KalendarRenderWrapper getCalendarForDeletion(OLATResourceable resource) {
    String type;
    if ("CourseModule".equals(resource.getResourceableTypeName())) {
        type = CalendarManager.TYPE_COURSE;
    } else {
        type = CalendarManager.TYPE_GROUP;
    }
    Kalendar cal = getCalendar(type, resource.getResourceableId().toString());
    KalendarRenderWrapper calendarWrapper = new KalendarRenderWrapper(cal, "To delete");
    calendarWrapper.setCssClass(KalendarRenderWrapper.CALENDAR_COLOR_GREEN);
    calendarWrapper.setVisible(true);
    return calendarWrapper;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 54 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class ICalFileCalendarManager method getImportedCalendar.

@Override
public KalendarRenderWrapper getImportedCalendar(Identity identity, String calendarId) {
    Kalendar cal = getCalendar(CalendarManager.TYPE_USER, calendarId);
    KalendarRenderWrapper calendarWrapper = new KalendarRenderWrapper(cal, calendarId);
    calendarWrapper.setCssClass(KalendarRenderWrapper.CALENDAR_COLOR_BLUE);
    calendarWrapper.setVisible(true);
    calendarWrapper.setImported(true);
    return calendarWrapper;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 55 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project openolat by klemens.

the class ImportCalendarManager method importCalendar.

public KalendarRenderWrapper importCalendar(Identity identity, String calendarName, String type, String url) throws IOException {
    File tmpFile = new File(WebappHelper.getTmpDir(), UUID.randomUUID() + ".ics");
    try (InputStream in = new URL(url).openStream()) {
        Files.copy(in, tmpFile.toPath());
    } catch (IOException e) {
        throw e;
    }
    KalendarRenderWrapper calendarWrapper = null;
    Calendar calendar = calendarManager.readCalendar(tmpFile);
    if (calendar != null) {
        String calendarID = getImportedCalendarID(identity, calendarName);
        File calendarFile = calendarManager.getCalendarFile(type, calendarID);
        if (!tmpFile.renameTo(calendarFile)) {
            Files.copy(tmpFile.toPath(), calendarFile.toPath());
        }
        importedCalendarDao.createImportedCalendar(identity, calendarName, calendarID, type, url, new Date());
        calendarWrapper = calendarManager.getImportedCalendar(identity, calendarID);
        calendarWrapper.setDisplayName(calendarName);
        calendarWrapper.setPrivateEventsVisible(true);
    }
    return calendarWrapper;
}
Also used : InputStream(java.io.InputStream) ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) Calendar(net.fortuna.ical4j.model.Calendar) IOException(java.io.IOException) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) URL(java.net.URL) Date(java.util.Date)

Aggregations

KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)134 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)46 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)28 Identity (org.olat.core.id.Identity)26 Date (java.util.Date)24 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)24 Calendar (java.util.Calendar)22 Kalendar (org.olat.commons.calendar.model.Kalendar)22 ICourse (org.olat.course.ICourse)20 File (java.io.File)18 BusinessGroup (org.olat.group.BusinessGroup)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)14 URL (java.net.URL)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12 CalendarManager (org.olat.commons.calendar.CalendarManager)10 HttpGet (org.apache.http.client.methods.HttpGet)8 UserRequest (org.olat.core.gui.UserRequest)8