search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Links in right Click Menu

Asked by Steve Lee
1 year ago.

Hi.

I'm a HTML/CSS guy and know practically nothing about JavaScript/PHP.

We are currently developing a scheduling system using DayPilot linked with our Access production system. We're almost done (It works very well) and ready to license DayPilot however I've hit a snag.

Using the right click menu within the scheduler we want to add in a "Click to Open" menu item that will open a PDF stored as a link within the MySql DB as a field "URL"

I've tried, and tried... and tried Googling for a solution however I cannot find an answer.

Can you tell me how to do this?

Answer posted by Dan Letecky [DayPilot]
1 year ago.

1. First, you need to load the link from the database and store it as an additional property of the event data object. This can be done in the backend API endpoint that returns events. In most PHP examples, it is called backend_events.php.

<?php
require_once '_db.php';

$stmt = $db->prepare('SELECT * FROM events WHERE NOT ((end <= :start) OR (start >= :end))');
$stmt->bindParam(':start', $_GET['start']);
$stmt->bindParam(':end', $_GET['end']);
$stmt->execute();
$result = $stmt->fetchAll();

class Event {}
$events = array();

foreach($result as $row) {
  $e = new Event();
  $e->id = $row['id'];
  $e->text = $row['name'];
  $e->start = $row['start'];
  $e->end = $row['end'];
  $e->resource = $row['resource_id'];
  $e->url= $row['URL'];
  $events[] = $e;
}

header('Content-Type: application/json');
echo json_encode($events);

2. Then you need to add the context menu to events (https://api.daypilot.org/daypilot-scheduler-contextmenu/) and add an item that opens the specified URL:

dp.contextMenu = new DayPilot.Menu({
  items: [
    { text: "Click to Open", onClick: args => location.href = args.source.data.url }
  ]
});
Comment posted by Steve Lee
1 year ago.

Thank you :-) Prefect!!

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.