Apply show_weekends to planner view

This commit is contained in:
Nathan Gray 2016-04-19 20:27:09 +00:00
parent f7588fb0ea
commit 8a93fa5068
4 changed files with 72 additions and 8 deletions

View File

@ -40,6 +40,12 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
default: '', default: '',
description: 'A filter that is used to select events. It is passed along when events are queried.' description: 'A filter that is used to select events. It is passed along when events are queried.'
}, },
show_weekend: {
name: "Weekends",
type: "boolean",
default: egw.preference('days_in_weekview','calendar') != 5,
description: "Display weekends. The date range should still include them for proper scrolling, but they just won't be shown."
},
value: { value: {
type: "any", type: "any",
description: "A list of events, optionally you can set start_date, end_date and group_by as keys and events will be fetched" description: "A list of events, optionally you can set start_date, end_date and group_by as keys and events will be fetched"
@ -1012,6 +1018,7 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
var t = new Date(start.valueOf() + start.getTimezoneOffset() * 60 * 1000); var t = new Date(start.valueOf() + start.getTimezoneOffset() * 60 * 1000);
for(var left = 0,i = 0; i < days; t.setDate(t.getDate()+1),left += day_width,++i) for(var left = 0,i = 0; i < days; t.setDate(t.getDate()+1),left += day_width,++i)
{ {
if(!this.options.show_weekend && [0,6].indexOf(t.getDay()) !== -1 ) continue;
var holidays = []; var holidays = [];
var tempDate = new Date(t); var tempDate = new Date(t);
tempDate.setMinutes(tempDate.getMinutes()-start.getTimezoneOffset()); tempDate.setMinutes(tempDate.getMinutes()-start.getTimezoneOffset());
@ -1034,7 +1041,7 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
state = new Date(t.valueOf() - start.getTimezoneOffset() * 60 * 1000).toJSON(); state = new Date(t.valueOf() - start.getTimezoneOffset() * 60 * 1000).toJSON();
content += '<div class="calendar_plannerDayScale et2_clickable et2_link '+ day_class+ content += '<div class="calendar_plannerDayScale et2_clickable et2_link '+ day_class+
'" data-date=\'' + state +'\' style="left: '+left+'%; width: '+day_width+'%;"'+ '" data-date=\'' + state +'\''+
(holidays ? ' title="'+holidays.join(',')+'"' : '')+'>'+title+"</div>\n"; (holidays ? ' title="'+holidays.join(',')+'"' : '')+'>'+title+"</div>\n";
} }
content += "</div>"; // end of plannerScale content += "</div>"; // end of plannerScale
@ -1076,6 +1083,7 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
var t = new Date(start.valueOf() + start.getTimezoneOffset() * 60 * 1000); var t = new Date(start.valueOf() + start.getTimezoneOffset() * 60 * 1000);
for(var left = 0,i = 0; i < hours; left += cell_width,i += decr) for(var left = 0,i = 0; i < hours; left += cell_width,i += decr)
{ {
if(!this.options.show_weekend && [0,6].indexOf(t.getDay()) !== -1 ) continue;
var title = date(egw.preference('timeformat','calendar') == 12 ? 'ha' : 'H',t); var title = date(egw.preference('timeformat','calendar') == 12 ? 'ha' : 'H',t);
content += '<div class="calendar_plannerHourScale et2_link" data-date="' + t.toJSON() +'" style="left: '+left+'%; width: '+(cell_width)+'%;">'+title+"</div>"; content += '<div class="calendar_plannerHourScale et2_link" data-date="' + t.toJSON() +'" style="left: '+left+'%; width: '+(cell_width)+'%;">'+title+"</div>";
@ -1638,6 +1646,24 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
} }
}, },
/**
* Turn on or off the visibility of weekends
*
* @param {boolean} weekends
*/
set_show_weekend: function(weekends)
{
weekends = weekends ? true : false;
if(this.options.show_weekend !== weekends)
{
this.options.show_weekend = weekends;
if(this.isAttached())
{
this.invalidate();
}
}
},
/** /**
* Call change handler, if set * Call change handler, if set
* *

View File

@ -104,14 +104,14 @@ var et2_calendar_planner_row = (function(){ "use strict"; return et2_valueWidget
this.rows.remove('.calendar_eventRowsMarkedDay,.calendar_eventRowsFiller').nextAll().remove(); this.rows.remove('.calendar_eventRowsMarkedDay,.calendar_eventRowsFiller').nextAll().remove();
var days = 31; var days = 31;
var width = 85; var width = 100;
if (this._parent.options.group_by === 'month') if (this._parent.options.group_by === 'month')
{ {
days = new Date(this.options.end_date.getUTCFullYear(),this.options.end_date.getUTCMonth()+1,0).getUTCDate(); days = new Date(this.options.end_date.getUTCFullYear(),this.options.end_date.getUTCMonth()+1,0).getUTCDate();
if(days < 31) if(days < 31)
{ {
width = 85*days/31; width = 100*days/31;
this.rows.css('width',width+'%'); this.rows.css('width','calc('+width+'% - 162px)');
} }
} }
@ -125,7 +125,7 @@ var et2_calendar_planner_row = (function(){ "use strict"; return et2_valueWidget
{ {
// add a filler for non existing days in that month // add a filler for non existing days in that month
this.rows.after('<div class="calendar_eventRowsFiller"'+ this.rows.after('<div class="calendar_eventRowsFiller"'+
' style="left:'+(15+width)+'%; width:'+(85-width)+'%;" ></div>'); ' style="width:'+(99.5-width)+'%;" ></div>');
} }
}, },
@ -406,8 +406,29 @@ var et2_calendar_planner_row = (function(){ "use strict"; return et2_valueWidget
if(t <= start) return 0; // We are left of our scale if(t <= start) return 0; // We are left of our scale
if(t >= end) return 100; // We are right of our scale if(t >= end) return 100; // We are right of our scale
// Remove space for weekends, if hidden
var weekend_count = 0;
var weekend_before = 0;
if(this._parent.options.group_by !== 'month' && this._parent && !this._parent.options.show_weekend)
{
var counter_date = new Date(start);
do
{
if([0,6].indexOf(counter_date.getUTCDay()) !== -1)
{
weekend_count++;
if(counter_date < t) weekend_before++;
}
counter_date.setUTCDate(counter_date.getUTCDate() + 1);
} while(counter_date < end)
// Put it in ms
weekend_before *= 24 * 3600 * 1000;
weekend_count *= 24 * 3600 * 1000;
}
// Basic scaling, doesn't consider working times // Basic scaling, doesn't consider working times
pos = (t - start) / (end - start); pos = (t - start - weekend_before) / (end - start - weekend_count);
// Month view // Month view
if(this._parent.options.group_by !== 'month') if(this._parent.options.group_by !== 'month')

View File

@ -1045,6 +1045,9 @@ Hide subsequent headers in week view with non-consolidated owners
width: 100%; width: 100%;
height: 20px; height: 20px;
line-height: 20px; line-height: 20px;
display: flex;
flex-wrap: nowrap;
align-content: stretch;
} }
.calendar_plannerDayScale,.calendar_plannerMonthScale,.calendar_plannerWeekScale,.calendar_plannerHourScale,.calendar_plannerDayOfMonthScale { .calendar_plannerDayScale,.calendar_plannerMonthScale,.calendar_plannerWeekScale,.calendar_plannerHourScale,.calendar_plannerDayOfMonthScale {
position: absolute; position: absolute;
@ -1060,6 +1063,10 @@ Hide subsequent headers in week view with non-consolidated owners
* width: * width:
*/ */
} }
.calendar_plannerDayScale,.calendar_plannerWeekScale,.calendar_plannerHourScale {
position: static;
flex: 1 1 14%;
}
.calendar_plannerHourScale { .calendar_plannerHourScale {
font-size: 90%; font-size: 90%;
} }

View File

@ -11,7 +11,7 @@
* @package calendar * @package calendar
* @version $Id$ * @version $Id$
*/ */
/* $Id: app.css 55765 2016-04-18 19:03:35Z nathangray $ */ /* $Id: app.css 55773 2016-04-19 17:31:24Z nathangray $ */
/*Media print classes*/ /*Media print classes*/
@media print { @media print {
#calendar-view.et2_container, #calendar-view.et2_container,
@ -128,7 +128,7 @@
padding: 2px; padding: 2px;
background-color: white; background-color: white;
} }
/* Loader */ /* Loader - hide sizing behind overlay*/
#egw-loadin-prompt_calendar::before { #egw-loadin-prompt_calendar::before {
opacity: 1; opacity: 1;
background-color: #e6e6e6; background-color: #e6e6e6;
@ -1015,6 +1015,9 @@ Hide subsequent headers in week view with non-consolidated owners
width: 100%; width: 100%;
height: 20px; height: 20px;
line-height: 20px; line-height: 20px;
display: flex;
flex-wrap: nowrap;
align-content: stretch;
} }
.calendar_plannerDayScale, .calendar_plannerDayScale,
.calendar_plannerMonthScale, .calendar_plannerMonthScale,
@ -1034,6 +1037,12 @@ Hide subsequent headers in week view with non-consolidated owners
* width: * width:
*/ */
} }
.calendar_plannerDayScale,
.calendar_plannerWeekScale,
.calendar_plannerHourScale {
position: static;
flex: 1 1 14%;
}
.calendar_plannerHourScale { .calendar_plannerHourScale {
font-size: 90%; font-size: 90%;
} }
@ -1111,6 +1120,7 @@ Hide subsequent headers in week view with non-consolidated owners
.calendar_eventRowsFiller { .calendar_eventRowsFiller {
position: absolute; position: absolute;
top: 0px; top: 0px;
right: 0px;
height: 93%; height: 93%;
background-color: white; background-color: white;
border: 1px dashed gray; border: 1px dashed gray;