Agent-readable demo data

Title
Event Context Menu (JavaScript Event Calendar) | DayPilot Lite for JavaScript Demo
Tree
DayPilot JavaScript Demo
Catalog root
Lite
Description
Note: Read more about event context menu [doc.daypilot.org].

Inline demo script 1

const dp = new DayPilot.Calendar("dp", {
            viewType: "Week",
            startDate: "2023-03-20",
            contextMenu: new DayPilot.Menu({
                items: [
                    {text: "Edit...", onClick: args => app.editEvent(args.source) },
                    {text: "Delete", onClick: args => app.deleteEvent(args.source) },
                    {text: "-"},
                    {text: "Duplicate", onClick: args => app.duplicateEvent(args.source) },
                    {text: "Postpone", onClick: args => app.postponeEvent(args.source) },
                ]
            }),
            onTimeRangeSelected: async (args) => {
                const modal = await DayPilot.Modal.prompt("New event name:", "Event");
                if (modal.canceled) {
                    return;
                }
                dp.events.add({
                    start: args.start,
                    end: args.end,
                    id: DayPilot.guid(),
                    resource: args.resource,
                    text: modal.result
                });
                dp.clearSelection();
            },
            onBeforeEventRender: args => {
                args.data.areas = [
                    {
                        right: 5,
                        top: 5,
                        width: 17,
                        height: 17,
                        symbol: "../icons/daypilot.svg#minichevron-down-4",
                        action: "ContextMenu",
                        cssClass: "event-menu",
                    }
                ];
            }
        });
        dp.init();




        const app = {
            init() {
                app.loadEvents();
            },
            loadEvents() {
                const events = [
                    {
                        start: new DayPilot.Date("2023-03-20T12:00:00"),
                        end: new DayPilot.Date("2023-03-20T12:00:00").addHours(3),
                        id: DayPilot.guid(),
                        text: "Special event"
                    }
                ];

                dp.update({events});
            },
            async editEvent(e) {
                const modal = await DayPilot.Modal.prompt("Edit event name:", e.text());
                if (modal.canceled) {
                    return;
                }
                e.data.text = modal.result;
                dp.events.update(e);
            },
            deleteEvent(e) {
                dp.events.remove(e);
            },
            duplicateEvent(e) {
                const newEvent = {
                    start: e.start(),
                    end: e.end(),
                    id: DayPilot.guid(),
                    text: e.text() + " (copy)"
                };
                dp.events.add(newEvent);
            },
            postponeEvent(e) {
                const newStart = e.start().addDays(1);
                const newEnd = e.end().addDays(1);
                e.start(newStart);
                e.end(newEnd);
                dp.events.update(e);
            }
        };

        app.init();