Check event filters when updating status or category through edit dialog to remove the event if it no longer matches.

This commit is contained in:
nathangray 2016-06-16 10:28:56 -06:00
parent e4371fd344
commit 8cb1bb19b1
3 changed files with 39 additions and 8 deletions

View File

@ -606,17 +606,37 @@ class calendar_ui
* *
* @param int $event_id * @param int $event_id
* @param Api\DateTime $recurrence_date * @param Api\DateTime $recurrence_date
*
* @return boolean True if the event was updated, false if it could not be
* updated or was removed.
*/ */
public function update_client($event_id, Api\DateTime $recurrence_date = null) public function update_client($event_id, Api\DateTime $recurrence_date = null)
{ {
if(!$event_id) return; if(!$event_id) return false;
// Directly update stored data. // Directly update stored data.
// Make sure we have the whole event // Make sure we have the whole event
$event = $this->bo->read($event_id, $recurrence_date); $event = $this->bo->read($event_id, $recurrence_date);
$response = Api\Json\Response::get(); $response = Api\Json\Response::get();
if(!$event)
// Check filters to see if they still match, may have to remove
// the event because it should no longer be displayed
$filter_match = true;
if($this->cal_prefs['saved_states']['status_filter'] != 'all' ||
$this->cal_prefs['saved_states']['cat_id'])
{
$filter_check = array(
'start' => $event['start'],
'users' => $this->cal_prefs['saved_states']['owner'],
'cat_id' => $this->cal_prefs['saved_states']['cat_id'],
'filter' => $this->cal_prefs['saved_states']['status_filter'],
'num_rows' => 1
);
$filter_match = count($this->bo->search($filter_check, $this->bo->so->cal_table.".cal_id = {$event['id']}")) > 0;
}
if(!$event || !$filter_match)
{ {
// Sending null will trigger a removal // Sending null will trigger a removal
$response->generic('data', array('uid' => 'calendar::'.$event_id, 'data' => null)); $response->generic('data', array('uid' => 'calendar::'.$event_id, 'data' => null));
@ -644,6 +664,7 @@ class calendar_ui
} }
while ($rrule->valid() && $occurrence <= $this_month ); while ($rrule->valid() && $occurrence <= $this_month );
} }
return true;
} }
/** /**

View File

@ -479,6 +479,9 @@ class calendar_uiforms extends calendar_ui
$new_status = calendar_so::combine_status($status, $quantity, $role); $new_status = calendar_so::combine_status($status, $quantity, $role);
if ($this->bo->set_status($event['id'],$uid,$new_status,isset($content['edit_single']) ? $content['participants']['status_date'] : 0, false, true, $content['no_notifications'])) if ($this->bo->set_status($event['id'],$uid,$new_status,isset($content['edit_single']) ? $content['participants']['status_date'] : 0, false, true, $content['no_notifications']))
{ {
// Update main window
$client_updated = $this->update_client($event['id'], $content['edit_single']);
// refreshing the calendar-view with the changed participant-status // refreshing the calendar-view with the changed participant-status
if($event['recur_type'] != MCAL_RECUR_NONE) if($event['recur_type'] != MCAL_RECUR_NONE)
{ {
@ -497,7 +500,7 @@ class calendar_uiforms extends calendar_ui
{ {
$msg = lang('Status changed'); $msg = lang('Status changed');
//Refresh the event in the main window after changing status //Refresh the event in the main window after changing status
Framework::refresh_opener($msg, 'calendar', $event['id']); Framework::refresh_opener($msg, 'calendar', $event['id'], $client_updated ? 'update' : 'delete');
} }
} }
if (!$content['no_popup']) if (!$content['no_popup'])
@ -787,6 +790,11 @@ class calendar_uiforms extends calendar_ui
{ {
$update_type = 'edit'; $update_type = 'edit';
} }
// Changing category may affect event filtering
if($this->cal_prefs['saved_states']['cat_id'] && $old_event['category'] != $event['category'])
{
$update_type = 'edit';
}
$conflicts = $this->bo->update($event,$ignore_conflicts,true,false,true,$messages,$content['no_notifications']); $conflicts = $this->bo->update($event,$ignore_conflicts,true,false,true,$messages,$content['no_notifications']);
unset($event['ignore']); unset($event['ignore']);
} }
@ -893,11 +901,11 @@ class calendar_uiforms extends calendar_ui
$response = Api\Json\Response::get(); $response = Api\Json\Response::get();
if($response && $update_type != 'delete') if($response && $update_type != 'delete')
{ {
$this->update_client($event['id']); $client_updated = $this->update_client($event['id']);
} }
$msg = $message . ($msg ? ', ' . $msg : ''); $msg = $message . ($msg ? ', ' . $msg : '');
Framework::refresh_opener($msg, 'calendar', $event['id'], $event['recur_type'] ? 'edit' : $update_type); Framework::refresh_opener($msg, 'calendar', $event['id'], $client_updated ? ($event['recur_type'] ? 'edit' : $update_type) : 'delete');
// writing links for new entry, existing ones are handled by the widget itself // writing links for new entry, existing ones are handled by the widget itself
if (!$content['id'] && is_array($content['link_to']['to_id'])) if (!$content['id'] && is_array($content['link_to']['to_id']))
{ {
@ -997,7 +1005,7 @@ class calendar_uiforms extends calendar_ui
$response = Api\Json\Response::get(); $response = Api\Json\Response::get();
if($response && !$content['id'] && $event['id']) if($response && !$content['id'] && $event['id'])
{ {
$this->update_client($event['id']); $client_updated = $this->update_client($event['id']);
} }
if (in_array($button,array('cancel','save','delete','delete_exceptions','delete_keep_exceptions')) && $noerror) if (in_array($button,array('cancel','save','delete','delete_exceptions','delete_keep_exceptions')) && $noerror)
{ {
@ -1018,7 +1026,9 @@ class calendar_uiforms extends calendar_ui
} }
else else
{ {
Framework::refresh_opener($msg, 'calendar', $event['id'], $button == 'save' ? ($content['id'] ? $update_type : 'add') : 'delete'); Framework::refresh_opener($msg, 'calendar', $event['id'],
$button == 'save' && $client_updated ? ($content['id'] ? $update_type : 'add') : 'delete'
);
} }
Framework::window_close(); Framework::window_close();
exit(); exit();

View File

@ -317,7 +317,7 @@ app.classes.calendar = (function(){ "use strict"; return AppJS.extend(
{ {
// Intelligent refresh without reloading everything // Intelligent refresh without reloading everything
var recurrences = Object.keys(egw.dataSearchUIDs(new RegExp('^calendar::'+_id+':'))); var recurrences = Object.keys(egw.dataSearchUIDs(new RegExp('^calendar::'+_id+':')));
var ids = event && event.data.recur_type && typeof _id === 'string' && _id.indexOf(':') < 0 || recurrences.length ? var ids = event && event.data && event.data.recur_type && typeof _id === 'string' && _id.indexOf(':') < 0 || recurrences.length ?
recurrences : recurrences :
['calendar::'+_id]; ['calendar::'+_id];