From 7e9be1ea38811a50f5b19cbf5cc8746c23fec986 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 14 Sep 2015 20:47:25 +0000 Subject: [PATCH] Calendar bugs: - Fix infinite loop west of GMT - Sidebox calendar now only changes views in day, week or month. Other views just change the date - Fix inconsistant week number in planner --- calendar/js/app.js | 45 ++++++++++++++++++++++---- calendar/js/et2_widget_planner.js | 15 ++++++--- calendar/templates/default/sidebox.xet | 4 ++- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/calendar/js/app.js b/calendar/js/app.js index f0e48610a8..cbc2dd14e8 100644 --- a/calendar/js/app.js +++ b/calendar/js/app.js @@ -66,6 +66,11 @@ app.classes.calendar = AppJS.extend( states_to_save: ['owner','filter','cat_id','view','sortby','planner_days'], + // If you are in one of these views and select a date in the sidebox, the view + // will change as needed to show the date. Other views will only change the + // date in the current view. + sidebox_changes_views: ['day','week','month'], + /** * Constructor * @@ -2305,10 +2310,17 @@ app.classes.calendar = AppJS.extend( date.setUTCDate(1); date.setFullYear(year); date.setUTCMonth(month-1); - app.calendar.update_state({ - view: 'month', - date: date - }) + var state = {date: date}; + if(app.calendar.sidebox_changes_views.indexOf(app.calendar.state.view) >= 0) + { + state.view = 'month'; + } + else if (app.calendar.state.view == 'planner') + { + state.planner_days = 0; + state.last = false; + } + app.calendar.update_state(state); }, // Mark holidays beforeShowDay: function (date) @@ -2346,11 +2358,21 @@ app.classes.calendar = AppJS.extend( $j(this).siblings().find('a').removeClass('ui-state-hover'); }) .on('click', '.ui-datepicker-week-col', function() { + var view = app.calendar.state.view; + // Fake a click event on the first day to get the updated date $j(this).next().click(); - // Set to week view - app.calendar.update_state({view: 'week', date: date.getValue()}); + // Set to week view, if in one of the views where we change view + if(app.calendar.sidebox_changes_views.indexOf(view) >= 0) + { + app.calendar.update_state({view: 'week', date: date.getValue()}); + } + else if (app.calendar.state.view == 'planner') + { + // Clicked a week, show just a week + app.calendar.update_state({planner_days: 7}); + } }); } }, @@ -2406,6 +2428,11 @@ app.classes.calendar = AppJS.extend( } }, + /** + * Super class for the different views. + * + * Each separate view overrides what it needs + */ View: { // List of etemplates to show for this view etemplates: ['calendar.view'], @@ -2578,6 +2605,12 @@ jQuery.extend(app.classes.calendar,{ }, show_weekend: function(state) { return true; + }, + scroll: function(delta) + { + var d = new Date(app.calendar.state.date); + d.setUTCDate(d.getUTCDate() + (4 * delta)); + return d; } }), week: app.classes.calendar.prototype.View.extend({ diff --git a/calendar/js/et2_widget_planner.js b/calendar/js/et2_widget_planner.js index 71744fc9f6..9d770c07ff 100644 --- a/calendar/js/et2_widget_planner.js +++ b/calendar/js/et2_widget_planner.js @@ -773,12 +773,16 @@ var et2_calendar_planner = et2_valueWidget.extend([et2_IDetachedDOM, et2_IResize var content = '
'; var days_in_month = 0; var day_width = 100 / days; - for(var t = new Date(start),left = 0,i = 0; i < days; t.setUTCDate(t.getUTCDate() + days_in_month),left += days_in_month*day_width,i += days_in_month) + var t = new Date(start.valueOf()); + for(var left = 0,i = 0; i < days;t.setUTCDate(1),t.setUTCMonth(t.getUTCMonth()+1),left += days_in_month*day_width,i += days_in_month) { + var u = new Date(t.getUTCFullYear(),t.getUTCMonth()+1,0,-t.getTimezoneOffset()/60); this.date_helper.set_year(t.getUTCFullYear()); - this.date_helper.set_month(t.getUTCMonth()+1); + this.date_helper.set_month(t.getUTCMonth()+2); this.date_helper.set_date(0); days_in_month = this.date_helper.get_date() - (t.getUTCDate()-1); + + if(days_in_month <= 0) break; if (i + days_in_month > days) { @@ -849,10 +853,11 @@ var et2_calendar_planner = et2_valueWidget.extend([et2_IDetachedDOM, et2_IResize var state = '' // we're not using UTC so date() formatting function works - var t = new Date(start.valueOf() + start.getTimezoneOffset() * 60 * 1000); - for(var left = 0,i = 0; i < days; t.setDate(t.getDate() + 7),left += week_width,i += 7) + //var t = new Date(start.valueOf() + start.getTimezoneOffset() * 60 * 1000); + var t = new Date(start); + for(var left = 0,i = 0; i < days; t.setUTCDate(t.getUTCDate() + 7),left += week_width,i += 7) { - var title = egw.lang('Week')+' '+date('W',t); + var title = egw.lang('Week')+' '+app.calendar.date.week_number(t); state = new Date(t.valueOf() - start.getTimezoneOffset() * 60 * 1000).toJSON(); if (days <= 7) diff --git a/calendar/templates/default/sidebox.xet b/calendar/templates/default/sidebox.xet index 42a75a912f..dcdde277a5 100644 --- a/calendar/templates/default/sidebox.xet +++ b/calendar/templates/default/sidebox.xet @@ -37,7 +37,9 @@ Egroupware