From 794d6aee5c99f40c9be39e45515dfd06e01801c2 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 27 Jan 2016 17:35:25 +0000 Subject: [PATCH] Fix events missing if home loaded before calendar --- .../class.calendar_favorite_portlet.inc.php | 8 +++++-- calendar/inc/class.calendar_uiviews.inc.php | 4 +++- calendar/js/app.js | 8 ++++++- calendar/js/et2_widget_timegrid.js | 21 +++++++++++++++++++ calendar/js/et2_widget_view.js | 19 +++++++++++++++++ 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/calendar/inc/class.calendar_favorite_portlet.inc.php b/calendar/inc/class.calendar_favorite_portlet.inc.php index 5fdabfdad2..c0df9aa6a8 100644 --- a/calendar/inc/class.calendar_favorite_portlet.inc.php +++ b/calendar/inc/class.calendar_favorite_portlet.inc.php @@ -74,7 +74,11 @@ class calendar_favorite_portlet extends home_favorite_portlet if($this->favorite['state']['start']) $ui->search_params['start'] = $this->favorite['state']['start']; if($this->favorite['state']['cat_id']) $ui->search_params['cat_id'] = $this->favorite['state']['cat_id']; // Owner can be 0 for current user - if(array_key_exists('owner',$this->favorite['state'])) $ui->search_params['users'] = explode(',',$this->favorite['state']['owner']); + if(array_key_exists('owner',$this->favorite['state'])) $ui->search_params['users'] = $this->favorite['state']['owner']; + if($ui->search_params['users'] && !is_array($ui->search_params['users'])) + { + $ui->search_params['users'] = explode(',',$ui->search_params['users']); + } if($this->favorite['state']['filter']) $ui->search_params['filter'] = $this->favorite['state']['filter']; if($this->favorite['state']['sortby']) $ui->search_params['sortby'] = $this->favorite['state']['sortby']; } @@ -134,7 +138,7 @@ class calendar_favorite_portlet extends home_favorite_portlet $this->favorite['state']['view'] == 'day' ? 1 : 4 ); $this->actions =& $etemplate->getElementAttribute('view', 'actions'); - $ui->week($days, $etemplate); + $ui->week($days, $etemplate); return; } diff --git a/calendar/inc/class.calendar_uiviews.inc.php b/calendar/inc/class.calendar_uiviews.inc.php index 2a7c7f6c61..296073aca0 100644 --- a/calendar/inc/class.calendar_uiviews.inc.php +++ b/calendar/inc/class.calendar_uiviews.inc.php @@ -807,7 +807,9 @@ class calendar_uiviews extends calendar_ui { // Always do 7 days for a week so scrolling works properly $this->last = ($days == 4 ? $this->last : $search_params['end'] = strtotime("+$days days",$this->first) - 1); - if (count($users) == 1 || count($users) >= $this->cal_prefs['week_consolidate']) // for more then X users, show all in one row + if (count($users) == 1 || count($users) >= $this->cal_prefs['week_consolidate'] ||// for more then X users, show all in one row + $days == 1 // Showing just 1 day + ) { $content['view'][] = (array)$this->tagWholeDayOnTop($this->bo->search($search_params)) + array('owner' => $users); diff --git a/calendar/js/app.js b/calendar/js/app.js index ed7e9384d0..733171cdf3 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -155,6 +155,7 @@ app.classes.calendar = AppJS.extend( this.sidebox_hooked_templates.push(this.sidebox_et2); $j(_et2.DOMContainer).hide(); this._setup_sidebox_filters(); + this.state = content.data; break; case 'calendar.edit': @@ -1832,6 +1833,11 @@ app.classes.calendar = AppJS.extend( */ setState: function setState(state) { + if(framework && framework.applications.calendar && framework.applications.calendar.hasSideboxMenuContent) + { + framework.setActiveApp(framework.applications.calendar); + } + // State should be an object, not a string, but we'll parse if(typeof state == "string") { @@ -3423,7 +3429,7 @@ jQuery.extend(app.classes.calendar,{ /** * Create a cache ID for the daywise cache * - * @param {String|Date} date + * @param {String|Date} date If a string, date should be in Ymd format * @param {String|integer|String[]} owner * @returns {String} Cache ID */ diff --git a/calendar/js/et2_widget_timegrid.js b/calendar/js/et2_widget_timegrid.js index d2ea50536d..577309f835 100644 --- a/calendar/js/et2_widget_timegrid.js +++ b/calendar/js/et2_widget_timegrid.js @@ -1309,6 +1309,27 @@ var et2_calendar_timegrid = et2_calendar_view.extend([et2_IDetachedDOM, et2_IRes this.set_start_date(day_list[0]); this.set_end_date(day_list[day_list.length-1]); } + + // Sub widgets actually get their own data from egw.data, so we'll + // stick it there + var consolidated = et2_calendar_view.is_consolidated(this.options.owner, this.day_list.length == 1 ? 'day' : 'week'); + for(var day in events) + { + var day_list = []; + for(var i = 0; i < events[day].length; i++) + { + day_list.push(events[day][i].row_id); + egw.dataStoreUID('calendar::'+events[day][i].row_id, events[day][i]); + } + // Might be split by user, so we have to check that too + for(var i = 0; i < this.options.owner.length; i++) + { + var owner = consolidated ? this.options.owner : this.options.owner[i]; + var day_id = app.classes.calendar._daywise_cache_id(day,owner); + egw.dataStoreUID(day_id, day_list); + if(consolidated) break; + } + } } // Reset and calculate instead of just use the keys so we can get the weekend preference diff --git a/calendar/js/et2_widget_view.js b/calendar/js/et2_widget_view.js index c602713da5..2dee689aae 100644 --- a/calendar/js/et2_widget_view.js +++ b/calendar/js/et2_widget_view.js @@ -383,6 +383,25 @@ var et2_calendar_view = et2_valueWidget.extend( // Static class stuff jQuery.extend(et2_calendar_view, { + /** + * Check if the view should be consolidated into one, or listed seperately + * based on the user's preferences + * + * @param {string[]} owners List of owners + * @param {string} view Name of current view (day, week) + * @returns {boolean} True of only one is needed, false if each owner needs + * to be listed seperately. + */ + is_consolidated: function is_consolidated(owners, view) + { + // Seperate owners, or consolidated? + return !( + owners.length > 1 && + (view === 'day' && owners.length < parseInt(egw.preference('day_consolidate','calendar')) || + view === 'week' && owners.length < parseInt(egw.preference('week_consolidate','calendar'))) + ); + }, + holiday_cache: {}, /** * Fetch and cache a list of the year's holidays