summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/static/js/fullcalendar-options.js
blob: 85423b86fcd090a3b2fd44caedf1075cafa3d91f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var tmpevent;

// converts a moment to a readable fomat for the backend
function convertInputTime(time) {
    return time;
    //return moment(time).format('YYYY-MM-DD HH:00 ZZ');
}

function sendEventToForm(event) {
    $('#starttimepicker').data("DateTimePicker").date(convertInputTime(event.start));
    $('#endtimepicker').data("DateTimePicker").date(convertInputTime(event.end));
}

var calendarOptions = {
    height: 600,
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'agendaWeek,month'
    },
    timezone: user_timezone, // set in booking_calendar.html
    defaultView: 'month',
    slotDuration: '00:60:00',
    slotLabelFormat: "HH:mm",
    firstDay: 1,
    allDaySlot: false,
    selectOverlap: false,
    eventOverlap: false,
    selectable: true,
    editable: false,
    eventLimit: true, // allow "more" link when too many events
    timeFormat: 'H(:mm)', // uppercase H for 24-hour clock
    unselectAuto: true,
    nowIndicator: true,

    // selectHelper is only working in the agendaWeek view, this is a workaround:
    // if an event is selected, the existing selection is removed and a temporary event is added
    // to the calendar
    select: function (start, end) {
        if (tmpevent != undefined) {
            $('#calendar').fullCalendar('removeEvents', tmpevent.id);
            $('#calendar').fullCalendar('rerenderEvents');
        }
        // the times need to be converted here to make them show up in the agendaWeek view if they
        // are created in the month view. If they are not converted, the tmpevent will only show
        // up in the (deactivated) allDaySlot
        start = convertInputTime(start);
        end = convertInputTime(end);

        tmpevent = {
            id: '537818f62bc63518ece15338fb86c8be',
            title: 'New Booking',
            start: start,
            end: end,
            editable: true
        };

        $('#calendar').fullCalendar('renderEvent', tmpevent, true);
        sendEventToForm(tmpevent);
    },

    eventClick: function (event) {
        if (tmpevent != undefined) {
            if (event.id != tmpevent.id) {
                $('#calendar').fullCalendar('removeEvents', tmpevent.id);
                $('#calendar').fullCalendar('rerenderEvents');
            }
        }
    },

    eventDrop: function (event) {
        sendEventToForm(event);
    },

    eventResize: function (event) {
        sendEventToForm(event);
    }
};