Agent-readable demo data

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

Inline demo script 1

const dp = new DayPilot.Calendar("dp", {
            startDate: DayPilot.Date.today(),
            viewType: "Week",
            contextMenu: new DayPilot.Menu({
                items: [
                    {
                        text: "Show event ID",
                        onClick: args => DayPilot.Modal.alert(`Event ID: ${args.source.id()}`)
                    },
                    {
                        text: "Show event text",
                        onClick: args => DayPilot.Modal.alert(`Event text: ${args.source.text()}`)
                    },
                    {
                        text: "Show event start",
                        onClick: args => DayPilot.Modal.alert(`Event start: ${args.source.start()}`)
                    },
                    {
                        text: "Delete",
                        onClick: args => dp.events.remove(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 // Assuming that the event text should be the user input
                });
                dp.clearSelection();
                dp.message("Created");
            },
            onBeforeEventRender: args => {
                args.data.areas = [
                    {
                        top: 4,
                        right: 4,
                        height: 14,
                        width: 14,
                        fontColor: "#999",
                        symbol: "../icons/daypilot.svg#minichevron-down-4",
                        visibility: "Hover",
                        action: "ContextMenu",
                        style: "border: 1px solid #999; cursor:pointer;"
                    }
                ];
            }
        });
        dp.init();


        const app = {
            init() {
                this.loadEventData();
            },
            loadEventData() {
                const events = [
                    {
                        start: DayPilot.Date.today().firstDayOfWeek().addDays(1).addHours(11),
                        end: DayPilot.Date.today().firstDayOfWeek().addDays(1).addHours(14),
                        id: DayPilot.guid(),
                        text: "Event 1"
                    },
                    {
                        start: DayPilot.Date.today().firstDayOfWeek().addDays(1).addHours(15),
                        end: DayPilot.Date.today().firstDayOfWeek().addDays(1).addHours(17),
                        id: DayPilot.guid(),
                        text: "Event 2"
                    },
                ];
                dp.update({events});
            }
        };
        app.init();