From bbe2c935427a820577273f8ed9bf724606d67c42 Mon Sep 17 00:00:00 2001 From: nathangray Date: Fri, 12 Aug 2016 09:16:24 -0600 Subject: [PATCH] Fix planner view's vertical time bar when weekends are hidden - it was not accounting for the missing days --- calendar/js/et2_widget_planner.js | 33 ++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/calendar/js/et2_widget_planner.js b/calendar/js/et2_widget_planner.js index 21be5cb915..b50f58cb15 100644 --- a/calendar/js/et2_widget_planner.js +++ b/calendar/js/et2_widget_planner.js @@ -2022,6 +2022,9 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e x = Math.round(x); y = Math.round(y); + + // Round to user's preferred event interval + var interval = egw.preference('interval','calendar') || 30; // Relative horizontal position, as a percentage var rel_x = Math.min(x / jQuery('.calendar_eventRows',this.div).width(),1); @@ -2029,12 +2032,37 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e // Relative time, in minutes from start var rel_time = 0; + var day_header = jQuery('.calendar_plannerScaleDay',this.headers); + // Simple math, the x is offset from start date - if(this.options.group_by !== 'month') + if(this.options.group_by !== 'month' && ( + // Either all days are visible, or only 1 day (no day header) + this.options.show_weekend || day_header.length === 0 + )) { rel_time = (new Date(this.options.end_date) - new Date(this.options.start_date))*rel_x/1000; this.date_helper.set_value(this.options.start_date.toJSON()); } + // Not so simple math, need to account for missing days + else if(this.options.group_by !== 'month' && !this.options.show_weekend) + { + // Find which day + if(day_header.length === 0) return false; + var day = document.elementFromPoint( + day_header.offset().left + rel_x * this.headers.innerWidth(), + day_header.offset().top + ); + + // Use day, and find time in that day + if(day && day.dataset && day.dataset.date) + { + this.date_helper.set_value(day.dataset.date); + rel_time = ((x - jQuery(day).position().left) / jQuery(day).outerWidth(true)) * 24*60; + this.date_helper.set_minutes(Math.round(rel_time/interval) * interval); + return new Date(this.date_helper.getValue()); + } + return false; + } else { // Find the correct row so we know which month, then get the offset @@ -2089,7 +2117,6 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e } if(rel_time < 0) return false; - var interval = egw.preference('interval','calendar') || 30; this.date_helper.set_minutes(Math.round(rel_time / (60 * interval))*interval); return new Date(this.date_helper.getValue()); @@ -2152,7 +2179,7 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e var time = this._get_time_from_position(event.offsetX, event.offsetY); } - return this._drag_create_end({date: time.toJSON()}); + return this._drag_create_end(time ? {date: time.toJSON()} : false); }, /**