Periodically refresh event data from server
This commit is contained in:
parent
f001ae250b
commit
e8dff87018
5 changed files with 57 additions and 5 deletions
|
@ -126,6 +126,7 @@ class calendar extends rcube_plugin
|
||||||
$this->register_action('mailtoevent', array($this, 'mail_message2event'));
|
$this->register_action('mailtoevent', array($this, 'mail_message2event'));
|
||||||
$this->register_action('inlineui', array($this, 'get_inline_ui'));
|
$this->register_action('inlineui', array($this, 'get_inline_ui'));
|
||||||
$this->register_action('check-recent', array($this, 'check_recent'));
|
$this->register_action('check-recent', array($this, 'check_recent'));
|
||||||
|
$this->add_hook('refresh', array($this, 'refresh'));
|
||||||
|
|
||||||
// remove undo information...
|
// remove undo information...
|
||||||
if ($undo = $_SESSION['calendar_event_undo']) {
|
if ($undo = $_SESSION['calendar_event_undo']) {
|
||||||
|
@ -918,6 +919,29 @@ class calendar extends rcube_plugin
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for keep-alive requests
|
||||||
|
* This will check for updated data in active calendars and sync them to the client
|
||||||
|
*/
|
||||||
|
public function refresh($attr)
|
||||||
|
{
|
||||||
|
foreach ($this->driver->list_calendars(true) as $cal) {
|
||||||
|
$events = $this->driver->load_events(
|
||||||
|
get_input_value('start', RCUBE_INPUT_GET),
|
||||||
|
get_input_value('end', RCUBE_INPUT_GET),
|
||||||
|
get_input_value('q', RCUBE_INPUT_GET),
|
||||||
|
$cal['id'],
|
||||||
|
1,
|
||||||
|
$attr['last']
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($events as $event) {
|
||||||
|
$args = array('source' => $cal['id'], 'update' => $this->_client_event($event));
|
||||||
|
$this->rc->output->command('plugin.refresh_calendar', $args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for pending_alarms plugin hook triggered by the calendar module on keep-alive requests.
|
* Handler for pending_alarms plugin hook triggered by the calendar module on keep-alive requests.
|
||||||
* This will check for pending notifications and pass them to the client
|
* This will check for pending notifications and pass them to the client
|
||||||
|
|
|
@ -2090,6 +2090,20 @@ function rcube_calendar_ui(settings)
|
||||||
fc.fullCalendar('removeEvents', function(e){ return e.temp; });
|
fc.fullCalendar('removeEvents', function(e){ return e.temp; });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// modify query parameters for refresh requests
|
||||||
|
this.before_refresh = function(query)
|
||||||
|
{
|
||||||
|
var view = fc.fullCalendar('getView');
|
||||||
|
|
||||||
|
query.start = date2unixtime(view.visStart);
|
||||||
|
query.end = date2unixtime(view.visEnd);
|
||||||
|
|
||||||
|
if (this.search_query)
|
||||||
|
query.q = this.search_query;
|
||||||
|
|
||||||
|
return query;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*** event searching ***/
|
/*** event searching ***/
|
||||||
|
|
||||||
|
@ -2784,6 +2798,7 @@ window.rcmail && rcmail.addEventListener('init', function(evt) {
|
||||||
rcmail.addEventListener('plugin.refresh_calendar', function(p){ cal.refresh(p); });
|
rcmail.addEventListener('plugin.refresh_calendar', function(p){ cal.refresh(p); });
|
||||||
rcmail.addEventListener('plugin.import_success', function(p){ cal.import_success(p); });
|
rcmail.addEventListener('plugin.import_success', function(p){ cal.import_success(p); });
|
||||||
rcmail.addEventListener('plugin.import_error', function(p){ cal.import_error(p); });
|
rcmail.addEventListener('plugin.import_error', function(p){ cal.import_error(p); });
|
||||||
|
rcmail.addEventListener('requestrefresh', function(q){ return cal.before_refresh(q); });
|
||||||
|
|
||||||
// let's go
|
// let's go
|
||||||
var cal = new rcube_calendar_ui($.extend(rcmail.env.calendar_settings, rcmail.env.libcal_settings));
|
var cal = new rcube_calendar_ui($.extend(rcmail.env.calendar_settings, rcmail.env.libcal_settings));
|
||||||
|
|
|
@ -236,9 +236,11 @@ abstract class calendar_driver
|
||||||
* @param integer Event's new end (unix timestamp)
|
* @param integer Event's new end (unix timestamp)
|
||||||
* @param string Search query (optional)
|
* @param string Search query (optional)
|
||||||
* @param mixed List of calendar IDs to load events from (either as array or comma-separated string)
|
* @param mixed List of calendar IDs to load events from (either as array or comma-separated string)
|
||||||
|
* @param boolean Include virtual/recurring events (optional)
|
||||||
|
* @param integer Only list events modified since this time (unix timestamp)
|
||||||
* @return array A list of event objects (see header of this file for struct of an event)
|
* @return array A list of event objects (see header of this file for struct of an event)
|
||||||
*/
|
*/
|
||||||
abstract function load_events($start, $end, $query = null, $calendars = null);
|
abstract function load_events($start, $end, $query = null, $calendars = null, $virtual = 1, $modifiedsince = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of pending alarms to be displayed to the user
|
* Get a list of pending alarms to be displayed to the user
|
||||||
|
|
|
@ -724,7 +724,7 @@ class database_driver extends calendar_driver
|
||||||
*
|
*
|
||||||
* @see calendar_driver::load_events()
|
* @see calendar_driver::load_events()
|
||||||
*/
|
*/
|
||||||
public function load_events($start, $end, $query = null, $calendars = null)
|
public function load_events($start, $end, $query = null, $calendars = null, $virtual = 1, $modifiedsince = null)
|
||||||
{
|
{
|
||||||
if (empty($calendars))
|
if (empty($calendars))
|
||||||
$calendars = array_keys($this->calendars);
|
$calendars = array_keys($this->calendars);
|
||||||
|
@ -742,6 +742,12 @@ class database_driver extends calendar_driver
|
||||||
$sql_add = 'AND (' . join(' OR ', $sql_query) . ')';
|
$sql_add = 'AND (' . join(' OR ', $sql_query) . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$virtual)
|
||||||
|
$sql_arr .= ' AND e.recurrence_id = 0';
|
||||||
|
|
||||||
|
if ($modifiedsince)
|
||||||
|
$sql_add .= ' AND e.changed >= ' . $this->rc->db->quote(date('Y-m-d H:i:s', $modifiedsince));
|
||||||
|
|
||||||
$events = array();
|
$events = array();
|
||||||
if (!empty($calendar_ids)) {
|
if (!empty($calendar_ids)) {
|
||||||
$result = $this->rc->db->query(sprintf(
|
$result = $this->rc->db->query(sprintf(
|
||||||
|
|
|
@ -736,20 +736,25 @@ class kolab_driver extends calendar_driver
|
||||||
* @param integer Event's new end (unix timestamp)
|
* @param integer Event's new end (unix timestamp)
|
||||||
* @param string Search query (optional)
|
* @param string Search query (optional)
|
||||||
* @param mixed List of calendar IDs to load events from (either as array or comma-separated string)
|
* @param mixed List of calendar IDs to load events from (either as array or comma-separated string)
|
||||||
* @param boolean Strip virtual events (optional)
|
* @param boolean Include virtual events (optional)
|
||||||
|
* @param integer Only list events modified since this time (unix timestamp)
|
||||||
* @return array A list of event records
|
* @return array A list of event records
|
||||||
*/
|
*/
|
||||||
public function load_events($start, $end, $search = null, $calendars = null, $virtual = 1)
|
public function load_events($start, $end, $search = null, $calendars = null, $virtual = 1, $modifiedsince = null)
|
||||||
{
|
{
|
||||||
if ($calendars && is_string($calendars))
|
if ($calendars && is_string($calendars))
|
||||||
$calendars = explode(',', $calendars);
|
$calendars = explode(',', $calendars);
|
||||||
|
|
||||||
|
$query = array();
|
||||||
|
if ($modifiedsince)
|
||||||
|
$query[] = array('changed', '>=', $modifiedsince);
|
||||||
|
|
||||||
$events = $categories = array();
|
$events = $categories = array();
|
||||||
foreach (array_keys($this->calendars) as $cid) {
|
foreach (array_keys($this->calendars) as $cid) {
|
||||||
if ($calendars && !in_array($cid, $calendars))
|
if ($calendars && !in_array($cid, $calendars))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$events = array_merge($events, $this->calendars[$cid]->list_events($start, $end, $search, $virtual));
|
$events = array_merge($events, $this->calendars[$cid]->list_events($start, $end, $search, $virtual, $query));
|
||||||
$categories += $this->calendars[$cid]->categories;
|
$categories += $this->calendars[$cid]->categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue