From 8cb1bb19b12fe19e46077b718a350ee07b54b3f8 Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 16 Jun 2016 10:28:56 -0600 Subject: [PATCH] Check event filters when updating status or category through edit dialog to remove the event if it no longer matches. --- calendar/inc/class.calendar_ui.inc.php | 25 +++++++++++++++++++-- calendar/inc/class.calendar_uiforms.inc.php | 20 ++++++++++++----- calendar/js/app.js | 2 +- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/calendar/inc/class.calendar_ui.inc.php b/calendar/inc/class.calendar_ui.inc.php index 11bcb71d65..c8855c1a4f 100644 --- a/calendar/inc/class.calendar_ui.inc.php +++ b/calendar/inc/class.calendar_ui.inc.php @@ -606,17 +606,37 @@ class calendar_ui * * @param int $event_id * @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) { - if(!$event_id) return; + if(!$event_id) return false; // Directly update stored data. // Make sure we have the whole event $event = $this->bo->read($event_id, $recurrence_date); $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 $response->generic('data', array('uid' => 'calendar::'.$event_id, 'data' => null)); @@ -644,6 +664,7 @@ class calendar_ui } while ($rrule->valid() && $occurrence <= $this_month ); } + return true; } /** diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index d749108712..6757bfcee1 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -479,6 +479,9 @@ class calendar_uiforms extends calendar_ui $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'])) { + // Update main window + $client_updated = $this->update_client($event['id'], $content['edit_single']); + // refreshing the calendar-view with the changed participant-status if($event['recur_type'] != MCAL_RECUR_NONE) { @@ -497,7 +500,7 @@ class calendar_uiforms extends calendar_ui { $msg = lang('Status changed'); //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']) @@ -787,6 +790,11 @@ class calendar_uiforms extends calendar_ui { $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']); unset($event['ignore']); } @@ -893,11 +901,11 @@ class calendar_uiforms extends calendar_ui $response = Api\Json\Response::get(); if($response && $update_type != 'delete') { - $this->update_client($event['id']); + $client_updated = $this->update_client($event['id']); } $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 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(); 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) { @@ -1018,7 +1026,9 @@ class calendar_uiforms extends calendar_ui } 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(); exit(); diff --git a/calendar/js/app.js b/calendar/js/app.js index 80ed4d6b6e..9d696015bd 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -317,7 +317,7 @@ app.classes.calendar = (function(){ "use strict"; return AppJS.extend( { // Intelligent refresh without reloading everything 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 : ['calendar::'+_id];