From 82b2af7cbae5abd6d3083ea791637d05ad538d47 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 23 Oct 2013 12:44:52 +0200 Subject: [PATCH] Keep state when reloading the calendar view --- plugins/calendar/calendar.php | 3 +-- plugins/calendar/calendar_ui.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index 074f7bfd..3d8bc20f 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -655,9 +655,8 @@ class calendar extends rcube_plugin $this->rc->output->command('plugin.unlock_saving'); - // TODO: keep view and date selection if ($success && $reload) - $this->rc->output->redirect(''); + $this->rc->output->command('plugin.reload_view'); } diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js index 86a88697..e7165455 100644 --- a/plugins/calendar/calendar_ui.js +++ b/plugins/calendar/calendar_ui.js @@ -2182,6 +2182,28 @@ function rcube_calendar_ui(settings) return query; }; + // reload the calendar view by keeping the current date/view selection + this.reload_view = function() + { + var query = { view: fc.fullCalendar('getView').name }, + date = fc.fullCalendar('getDate'); + if (date) + query.date = date2unixtime(date); + rcmail.redirect(rcmail.url('', query)); + } + + // update browser location to remember current view + this.update_state = function() + { + var query = { view: current_view }, + date = fc.fullCalendar('getDate'); + if (date) + query.date = date2unixtime(date); + + if (window.history.replaceState) + window.history.replaceState({}, document.title, rcmail.url('', query).replace('&_action=', '')); + }; + /*** event searching ***/ @@ -2570,6 +2592,7 @@ function rcube_calendar_ui(settings) if (view.name != current_view) me.view_resize(); current_view = view.name; + me.update_state(); } }, viewRender: function(view) { @@ -2709,6 +2732,12 @@ function rcube_calendar_ui(settings) } }); + if (rcmail.env.date) { + var viewdate = new Date(); + viewdate.setTime(fromunixtime(rcmail.env.date)); + minical.datepicker('setDate', viewdate); + } + // init event dialog $('#eventtabs').tabs({ show: function(event, ui) { @@ -2878,6 +2907,7 @@ window.rcmail && rcmail.addEventListener('init', function(evt) { 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_error', function(p){ cal.import_error(p); }); + rcmail.addEventListener('plugin.reload_view', function(p){ cal.reload_view(p); }); rcmail.addEventListener('requestrefresh', function(q){ return cal.before_refresh(q); }); // let's go