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

Getting tag URL Parameter from JSON Request

Asked by Martin
9 years ago.

Dear all,

I'm using this JSON Code for my monthly calendar:
class Event {}
$events = array();

foreach($result as $row) {
$e = new Event();
$e->id = $row['plan_id'];
$e->text = $row['text'];
$e->start = $row['plan_datum'];
$e->end = $row['plan_datum'];
$e->backColor = $row['plan_status_color'];
$events[] = $e;
}

Works fine.

But how can I add tag parameters like URL in this query?

The static HTML works fine with this:
var e = new DayPilot.Event({
text:{'text}',
start: '{plan_datum}',
end: '{plan_datum}',
id: '{plan_id}',
backColor: '{plan_status_color}',
tags: {
url: 'planung.php?id={plan_id}',
}
});
dp.events.add(e);

I need this tag for onEventClicked:
dp.onEventClicked = function(args) {
window.location.href = args.e.tag("url");
};

Many thanks in advise,
Martin

Answer posted by Dan Letecky [DayPilot]
9 years ago.

There are two options:

1. You can send the url from the server:

class Event {} 
class Tags {}
$events = array();

foreach($result as $row) { 
  $e = new Event();
  $e->id = $row['plan_id']; 
  $e->text = $row['text']; 
  $e->start = $row['plan_datum']; 
  $e->end = $row['plan_datum']; 
  $e->backColor = $row['plan_status_color']; 
  $e->tags = new Tags();
  $e->tags->url = "planung.php?id=".$row['plan_id']; 
  $events[] = $e; 
}

And use your existing onEventClicked handler:

dp.onEventClicked = function(args) { 
  window.location.href = args.e.tag("url"); 
};

2. Or you can build the URL in onEventClicked. This is possible because you just need the id which is already accessible:

dp.onEventClicked = function(args) { 
  window.location.href = 'planung.php?id=' + args.e.id(); 
};

This would be also more efficient because you don't need to send the full url with the event data.

Comment posted by Martin
9 years ago.

Thank Dan, you saved my day again.

Best wishes
Martin

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