2016-03-01 17:27:45 +01:00
|
|
|
/*
|
2015-05-06 21:03:45 +02:00
|
|
|
* Egroupware
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
et2_core_valueWidget;
|
|
|
|
/calendar/js/et2_widget_event.js;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2016-01-13 23:07:09 +01:00
|
|
|
* Class which implements the "calendar-timegrid" XET-Tag for displaying a single days
|
2015-05-06 21:03:45 +02:00
|
|
|
*
|
2016-01-13 23:07:09 +01:00
|
|
|
* This widget is responsible mostly for positioning its events
|
2015-05-06 21:03:45 +02:00
|
|
|
*
|
2016-01-13 23:07:09 +01:00
|
|
|
* @augments et2_valueWidget
|
2015-05-06 21:03:45 +02:00
|
|
|
*/
|
2016-03-01 17:27:45 +01:00
|
|
|
var et2_calendar_daycol = (function(){ "use strict"; return et2_valueWidget.extend([et2_IDetachedDOM, et2_IResizeable],
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
attributes: {
|
|
|
|
date: {
|
|
|
|
name: "Date",
|
|
|
|
type: "any",
|
2015-08-26 01:30:32 +02:00
|
|
|
description: "What date is this daycol for. YYYYMMDD or Date",
|
|
|
|
default: et2_no_init
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
owner: {
|
|
|
|
name: "Owner",
|
2016-01-13 23:07:09 +01:00
|
|
|
type: "any", // Integer, string, or array of either
|
2016-01-26 00:47:58 +01:00
|
|
|
default: et2_no_init,
|
2015-05-06 21:03:45 +02:00
|
|
|
description: "Account ID number of the calendar owner, if not the current user"
|
|
|
|
},
|
|
|
|
display_birthday_as_event: {
|
|
|
|
name: "Birthdays",
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
|
|
|
description: "Display birthdays as events"
|
|
|
|
},
|
|
|
|
display_holiday_as_event: {
|
|
|
|
name: "Holidays",
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
|
|
|
description: "Display holidays as events"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @memberOf et2_calendar_daycol
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Main container
|
2016-06-02 16:51:15 +02:00
|
|
|
this.div = jQuery(document.createElement("div"))
|
2015-05-06 21:03:45 +02:00
|
|
|
.addClass("calendar_calDayCol")
|
2015-10-21 21:53:19 +02:00
|
|
|
.css('width',this.options.width)
|
|
|
|
.css('left', this.options.left);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.header = jQuery(document.createElement('div'))
|
2015-10-21 21:53:19 +02:00
|
|
|
.addClass("calendar_calDayColHeader")
|
|
|
|
.css('width',this.options.width)
|
|
|
|
.css('left', this.options.left);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.title = jQuery(document.createElement('div'))
|
2015-10-06 01:45:51 +02:00
|
|
|
.appendTo(this.header);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.all_day = jQuery(document.createElement('div'))
|
2015-10-28 16:55:10 +01:00
|
|
|
.addClass("calendar_calDayColAllDay")
|
|
|
|
.appendTo(this.header);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.event_wrapper = jQuery(document.createElement('div'))
|
2016-02-02 22:12:44 +01:00
|
|
|
.addClass("event_wrapper")
|
2016-01-15 21:22:55 +01:00
|
|
|
.appendTo(this.div);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
this.setDOMNode(this.div[0]);
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
// Used for its date calculations - note this is a datetime, parent
|
|
|
|
// uses just a date
|
|
|
|
this.date_helper = et2_createWidget('date-time',{},null);
|
|
|
|
this.date_helper.loadingFinished();
|
2015-05-06 21:03:45 +02:00
|
|
|
|
2016-01-13 23:07:09 +01:00
|
|
|
// Init to defaults, just in case - they will be updated from parent
|
2015-05-06 21:03:45 +02:00
|
|
|
this.display_settings = {
|
|
|
|
wd_start: 60*9,
|
|
|
|
wd_end: 60*17,
|
|
|
|
granularity: 30,
|
|
|
|
rowsToDisplay: 10,
|
2015-07-15 18:29:10 +02:00
|
|
|
rowHeight: 20,
|
|
|
|
// Percentage; not yet available
|
|
|
|
titleHeight: 2.0
|
2016-03-01 17:27:45 +01:00
|
|
|
};
|
2016-01-05 21:43:19 +01:00
|
|
|
|
|
|
|
this.registeredUID = null;
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
doLoadingFinished: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// Parent will have everything we need, just load it from there
|
2016-01-26 00:47:58 +01:00
|
|
|
|
|
|
|
if(this._parent && this._parent.options.owner)
|
|
|
|
{
|
|
|
|
this.set_owner(this._parent.options.owner);
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
if(this.title.text() === '' && this.options.date &&
|
|
|
|
this._parent && this._parent.instanceOf(et2_calendar_timegrid))
|
|
|
|
{
|
|
|
|
// Forces an update
|
|
|
|
var date = this.options.date;
|
|
|
|
this.options.date = '';
|
|
|
|
this.set_date(date);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2015-08-26 01:30:32 +02:00
|
|
|
this.div.off();
|
2015-10-06 01:45:51 +02:00
|
|
|
this.header.off().remove();
|
2015-08-26 01:30:32 +02:00
|
|
|
this.title.off();
|
|
|
|
this.div = null;
|
2015-10-06 01:45:51 +02:00
|
|
|
this.header = null;
|
2015-08-26 01:30:32 +02:00
|
|
|
this.title = null;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-08-26 01:30:32 +02:00
|
|
|
// date_helper has no parent, so we must explicitly remove it
|
|
|
|
this.date_helper.destroy();
|
|
|
|
this.date_helper = null;
|
2015-07-15 18:29:10 +02:00
|
|
|
|
2016-01-05 21:43:19 +01:00
|
|
|
egw.dataUnregisterUID(this.registeredUID,false,this);
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
2016-01-15 21:22:55 +01:00
|
|
|
getDOMNode: function(sender)
|
|
|
|
{
|
|
|
|
if(!sender || sender === this) return this.div[0];
|
|
|
|
if(sender.instanceOf && sender.instanceOf(et2_calendar_event))
|
|
|
|
{
|
|
|
|
if(this.display_settings.granularity === 0)
|
|
|
|
{
|
|
|
|
return this.event_wrapper[0];
|
|
|
|
}
|
|
|
|
if(sender.options.value.whole_day_on_top ||
|
|
|
|
sender.options.value.whole_day && sender.options.value.non_blocking === true)
|
|
|
|
{
|
|
|
|
return this.all_day[0];
|
|
|
|
}
|
2016-01-19 19:03:42 +01:00
|
|
|
return this.div[0];
|
2016-01-15 21:22:55 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
/**
|
2016-01-13 23:07:09 +01:00
|
|
|
* Draw the individual divs for clicking to add an event
|
2015-05-06 21:03:45 +02:00
|
|
|
*/
|
|
|
|
_draw: function() {
|
|
|
|
// Remove any existing
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calAddEvent',this.div).remove();
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Grab real values from parent
|
|
|
|
if(this._parent && this._parent.instanceOf(et2_calendar_timegrid))
|
|
|
|
{
|
|
|
|
this.display_settings.wd_start = 60*this._parent.options.day_start;
|
|
|
|
this.display_settings.wd_end = 60*this._parent.options.day_end;
|
|
|
|
this.display_settings.granularity = this._parent.options.granularity;
|
2015-10-21 21:53:19 +02:00
|
|
|
var header = this._parent.dayHeader.children();
|
|
|
|
|
|
|
|
// Figure out insert index
|
|
|
|
var idx = 0;
|
2016-03-01 17:27:45 +01:00
|
|
|
var siblings = this._parent.getDOMNode(this).childNodes;
|
2015-10-21 21:53:19 +02:00
|
|
|
while(idx < siblings.length && siblings[idx] != this.getDOMNode())
|
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
// Stick header in the right place
|
|
|
|
if(idx == 0)
|
|
|
|
{
|
|
|
|
this._parent.dayHeader.prepend(this.header);
|
|
|
|
}
|
|
|
|
else if(header.length)
|
|
|
|
{
|
|
|
|
header.eq(Math.min(header.length,idx)-1).after(this.header);
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
|
2016-02-11 18:02:06 +01:00
|
|
|
this.div.attr('data-date', this.options.date);
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the date
|
|
|
|
*
|
|
|
|
* @param {string|Date} _date New date
|
2016-03-01 17:27:45 +01:00
|
|
|
* @param {Object[]} events =false List of event data to be displayed, or false to
|
2015-05-06 21:03:45 +02:00
|
|
|
* automatically fetch data from content array
|
2016-03-01 17:27:45 +01:00
|
|
|
* @param {boolean} force_redraw =false Redraw even if the date is the same.
|
2015-06-10 23:51:28 +02:00
|
|
|
* Used for when new data is available.
|
2015-05-06 21:03:45 +02:00
|
|
|
*/
|
2015-06-10 23:51:28 +02:00
|
|
|
set_date: function(_date, events, force_redraw)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
if(typeof events === 'undefined' || !events)
|
|
|
|
{
|
|
|
|
events = false;
|
|
|
|
}
|
2015-06-10 23:51:28 +02:00
|
|
|
if(typeof force_redraw === 'undefined' || !force_redraw)
|
|
|
|
{
|
|
|
|
force_redraw = false;
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
if(!this._parent || !this._parent.date_helper)
|
|
|
|
{
|
|
|
|
egw.debug('warn', 'Day col widget "' + this.id + '" is missing its parent.');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(typeof _date === "object")
|
|
|
|
{
|
|
|
|
this._parent.date_helper.set_value(_date);
|
|
|
|
}
|
|
|
|
else if(typeof _date === "string")
|
|
|
|
{
|
2015-07-22 01:45:38 +02:00
|
|
|
// Need a new date to avoid invalid month/date combinations when setting
|
2015-10-29 20:47:01 +01:00
|
|
|
// month then day. Use a string to avoid browser timezone.
|
|
|
|
this._parent.date_helper.set_value(_date.substring(0,4)+'-'+(_date.substring(4,6))+'-'+_date.substring(6,8)+'T00:00:00Z');
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
this.date = new Date(this._parent.date_helper.getValue());
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Keep internal option in Ymd format, it gets passed around in this format
|
2015-06-10 23:51:28 +02:00
|
|
|
var new_date = ""+this._parent.date_helper.get_year()+
|
|
|
|
sprintf("%02d",this._parent.date_helper.get_month())+
|
|
|
|
sprintf("%02d",this._parent.date_helper.get_date());
|
2015-07-15 18:29:10 +02:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// Set label
|
2015-12-28 23:21:47 +01:00
|
|
|
if(!this.options.label)
|
|
|
|
{
|
|
|
|
// Add timezone offset back in, or formatDate will lose those hours
|
|
|
|
var formatDate = new Date(this.date.valueOf() + this.date.getTimezoneOffset() * 60 * 1000);
|
2016-04-04 19:55:49 +02:00
|
|
|
|
|
|
|
this.title.html('<span class="long_date">'+jQuery.datepicker.formatDate('DD',formatDate)+
|
|
|
|
'</span><span class="short_date">'+jQuery.datepicker.formatDate('D',formatDate)+'</span>'+
|
|
|
|
jQuery.datepicker.formatDate('d',formatDate));
|
2015-12-28 23:21:47 +01:00
|
|
|
}
|
|
|
|
this.title
|
2015-10-06 01:45:51 +02:00
|
|
|
.attr("data-date", new_date);
|
2015-11-10 19:35:24 +01:00
|
|
|
this.header
|
|
|
|
.attr('data-date',new_date)
|
|
|
|
.attr('data-whole_day',true);
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Avoid redrawing if date is the same
|
2016-01-13 00:55:59 +01:00
|
|
|
if(new_date === this.options.date &&
|
|
|
|
this.display_settings.granularity === this._parent.options.granularity &&
|
|
|
|
!force_redraw
|
|
|
|
)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-07-15 18:29:10 +02:00
|
|
|
|
2016-01-05 21:43:19 +01:00
|
|
|
var cache_id = app.classes.calendar._daywise_cache_id(new_date,this.options.owner);
|
2016-03-01 17:27:45 +01:00
|
|
|
if(this.options.date && this.registeredUID &&
|
2016-01-05 21:43:19 +01:00
|
|
|
cache_id !== this.registeredUID)
|
2015-08-05 23:24:07 +02:00
|
|
|
{
|
2016-01-05 21:43:19 +01:00
|
|
|
egw.dataUnregisterUID(this.registeredUID,false,this);
|
2015-11-17 17:57:34 +01:00
|
|
|
|
|
|
|
// Remove existing events
|
|
|
|
while(this._children.length > 0)
|
|
|
|
{
|
|
|
|
var node = this._children[this._children.length-1];
|
|
|
|
this.removeChild(node);
|
|
|
|
node.free();
|
|
|
|
}
|
2015-08-05 23:24:07 +02:00
|
|
|
}
|
2015-07-15 18:29:10 +02:00
|
|
|
|
|
|
|
this.options.date = new_date;
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Set holiday and today classes
|
2015-06-25 19:44:28 +02:00
|
|
|
this.day_class_holiday();
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Update all the little boxes
|
|
|
|
this._draw();
|
|
|
|
|
2015-07-15 18:29:10 +02:00
|
|
|
|
|
|
|
// Register for updates on events for this day
|
2016-01-05 21:43:19 +01:00
|
|
|
if(this.registeredUID !== cache_id)
|
|
|
|
{
|
|
|
|
this.registeredUID = cache_id;
|
|
|
|
egw.dataRegisterUID(this.registeredUID, this._data_callback,this,this.getInstanceManager().execId,this.id);
|
2015-07-15 18:29:10 +02:00
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the owner of this day
|
|
|
|
*
|
2016-01-13 23:07:09 +01:00
|
|
|
* @param {number|number[]|string|string[]} _owner - Owner ID, which can
|
|
|
|
* be an account ID, a resource ID (as defined in calendar_bo, not
|
|
|
|
* necessarily an entry from the resource app), or a list containing a
|
|
|
|
* combination of both.
|
2015-05-06 21:03:45 +02:00
|
|
|
*/
|
|
|
|
set_owner: function(_owner) {
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-08 23:38:11 +01:00
|
|
|
this.title
|
|
|
|
.attr("data-owner", _owner);
|
|
|
|
this.header.attr('data-owner',_owner);
|
|
|
|
|
2015-08-26 01:30:32 +02:00
|
|
|
// Simple comparison, both numbers
|
|
|
|
if(_owner === this.options.owner) return;
|
|
|
|
|
|
|
|
// More complicated comparison, one or the other is an array
|
|
|
|
if((typeof _owner == 'object' || typeof this.options.owner == 'object') &&
|
|
|
|
_owner.toString() == this.options.owner.toString())
|
2015-07-15 18:29:10 +02:00
|
|
|
{
|
2015-08-26 01:30:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-26 00:47:58 +01:00
|
|
|
this.options.owner = typeof _owner !== 'object' ? [_owner] : _owner;
|
2015-08-26 01:30:32 +02:00
|
|
|
|
2016-03-01 17:27:45 +01:00
|
|
|
var cache_id = app.classes.calendar._daywise_cache_id(this.options.date,_owner);
|
2016-01-05 21:43:19 +01:00
|
|
|
if(this.options.date && this.registeredUID &&
|
|
|
|
cache_id !== this.registeredUID)
|
|
|
|
{
|
|
|
|
egw.dataUnregisterUID(this.registeredUID,false,this);
|
|
|
|
}
|
2015-07-15 18:29:10 +02:00
|
|
|
|
2016-01-05 21:43:19 +01:00
|
|
|
if(this.registeredUID !== cache_id)
|
|
|
|
{
|
|
|
|
this.registeredUID = cache_id;
|
|
|
|
egw.dataRegisterUID(this.registeredUID, this._data_callback,this,this.getInstanceManager().execId,this.id);
|
|
|
|
}
|
2015-11-18 18:44:22 +01:00
|
|
|
},
|
|
|
|
|
2016-02-05 00:14:54 +01:00
|
|
|
set_class: function(classnames) {
|
|
|
|
this.header.removeClass(this.class);
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.header.addClass(classnames);
|
|
|
|
},
|
|
|
|
|
2015-11-18 18:44:22 +01:00
|
|
|
/**
|
|
|
|
* Callback used when the daywise data changes
|
2016-01-13 23:07:09 +01:00
|
|
|
*
|
|
|
|
* Events should update themselves when their data changes, here we are
|
|
|
|
* dealing with a change in which events are displayed on this day.
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-11-18 18:44:22 +01:00
|
|
|
* @param {String[]} event_ids
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
_data_callback: function(event_ids) {
|
|
|
|
var events = [];
|
|
|
|
if(event_ids == null || typeof event_ids.length == 'undefined') event_ids = [];
|
|
|
|
for(var i = 0; i < event_ids.length; i++)
|
|
|
|
{
|
|
|
|
var event = egw.dataGetUIDdata('calendar::'+event_ids[i]);
|
2015-11-25 18:20:30 +01:00
|
|
|
event = event && event.data || false;
|
2016-04-05 01:58:23 +02:00
|
|
|
if(event && event.date && et2_calendar_event.owner_check(event, this) && (
|
2015-11-18 18:44:22 +01:00
|
|
|
event.date === this.options.date ||
|
|
|
|
// Accept multi-day events
|
|
|
|
new Date(event.start) <= this.date //&& new Date(event.end) >= this.date
|
|
|
|
))
|
2015-08-26 01:30:32 +02:00
|
|
|
{
|
2015-11-18 18:44:22 +01:00
|
|
|
events.push(event);
|
2015-08-26 01:30:32 +02:00
|
|
|
}
|
2016-04-05 01:58:23 +02:00
|
|
|
else if (event)
|
|
|
|
{
|
|
|
|
// Got an ID that doesn't belong
|
2016-05-11 19:29:58 +02:00
|
|
|
event_ids.splice(i--,1);
|
2016-04-05 01:58:23 +02:00
|
|
|
}
|
2015-11-18 18:44:22 +01:00
|
|
|
}
|
2016-01-16 01:38:44 +01:00
|
|
|
if(!this._parent.disabled)
|
|
|
|
this._update_events(events);
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
2015-12-28 23:21:47 +01:00
|
|
|
set_label: function(label) {
|
|
|
|
this.options.label = label;
|
|
|
|
this.title.text(label);
|
2016-01-06 21:37:29 +01:00
|
|
|
this.title.toggleClass('et2_clickable et2_link',label === '');
|
2015-12-28 23:21:47 +01:00
|
|
|
},
|
2015-10-06 01:45:51 +02:00
|
|
|
set_left: function(left) {
|
2015-11-13 00:10:16 +01:00
|
|
|
if(this.div)
|
|
|
|
{
|
|
|
|
this.div.css('left',left);
|
|
|
|
}
|
2015-10-06 01:45:51 +02:00
|
|
|
},
|
|
|
|
set_width: function(width) {
|
2016-02-04 22:05:31 +01:00
|
|
|
this.options.width = width;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-02-04 22:05:31 +01:00
|
|
|
if(this.div)
|
2015-11-13 00:10:16 +01:00
|
|
|
{
|
2016-02-04 22:05:31 +01:00
|
|
|
this.div.outerWidth(this.options.width);
|
|
|
|
this.header.outerWidth(this.options.width);
|
2015-11-13 00:10:16 +01:00
|
|
|
}
|
2015-10-06 01:45:51 +02:00
|
|
|
},
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
/**
|
|
|
|
* Applies class for today, and any holidays for current day
|
|
|
|
*/
|
2015-06-25 19:44:28 +02:00
|
|
|
day_class_holiday: function() {
|
2016-01-08 23:38:11 +01:00
|
|
|
this.title
|
|
|
|
// Remove all special day classes
|
|
|
|
.removeClass('calendar_calToday calendar_calBirthday calendar_calHoliday')
|
2015-05-06 21:03:45 +02:00
|
|
|
// Except this one...
|
2015-10-06 01:45:51 +02:00
|
|
|
.addClass("et2_clickable et2_link");
|
2015-10-29 22:53:47 +01:00
|
|
|
this.title.attr('data-holiday','');
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Set today class - note +1 when dealing with today, as months in JS are 0-11
|
|
|
|
var today = new Date();
|
2016-01-22 01:58:12 +01:00
|
|
|
today.setUTCMinutes(today.getUTCMinutes() - today.getTimezoneOffset());
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-10-29 22:53:47 +01:00
|
|
|
this.title.toggleClass("calendar_calToday", this.options.date === ''+today.getUTCFullYear()+
|
2015-05-06 21:03:45 +02:00
|
|
|
sprintf("%02d",today.getUTCMonth()+1)+
|
|
|
|
sprintf("%02d",today.getUTCDate())
|
|
|
|
);
|
|
|
|
|
|
|
|
// Holidays and birthdays
|
2016-01-13 23:07:09 +01:00
|
|
|
var holidays = et2_calendar_view.get_holidays(this,this.options.date.substring(0,4));
|
2015-05-06 21:03:45 +02:00
|
|
|
var holiday_list = [];
|
|
|
|
if(holidays && holidays[this.options.date])
|
|
|
|
{
|
|
|
|
holidays = holidays[this.options.date];
|
|
|
|
for(var i = 0; i < holidays.length; i++)
|
|
|
|
{
|
|
|
|
if (typeof holidays[i]['birthyear'] !== 'undefined')
|
|
|
|
{
|
2016-06-14 03:08:56 +02:00
|
|
|
// Show holidays as events on mobile
|
|
|
|
if(egwIsMobile())
|
|
|
|
{
|
|
|
|
// Create event
|
|
|
|
this._parent.date_helper.set_value(this.options.date.substring(0,4)+'-'+
|
|
|
|
(this.options.date.substring(4,6))+'-'+this.options.date.substring(6,8)+
|
|
|
|
'T00:00:00Z');
|
|
|
|
var event = et2_createWidget('calendar-event',{
|
|
|
|
id:'event_'+holidays[i].name,
|
|
|
|
value: {
|
|
|
|
title: holidays[i].name,
|
|
|
|
whole_day: true,
|
|
|
|
whole_day_on_top: true,
|
|
|
|
start: new Date(this._parent.date_helper.get_value()),
|
|
|
|
end: this.options.date,
|
|
|
|
owner: this.options.owner,
|
|
|
|
participants: this.options.owner,
|
2016-06-15 17:17:12 +02:00
|
|
|
app: 'calendar',
|
|
|
|
class: 'calendar_calBirthday'
|
2016-06-14 03:08:56 +02:00
|
|
|
},
|
|
|
|
readonly: true,
|
|
|
|
class: 'calendar_calBirthday'
|
|
|
|
},this);
|
|
|
|
event.doLoadingFinished();
|
|
|
|
event._update();
|
|
|
|
}
|
|
|
|
else
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-06-14 03:08:56 +02:00
|
|
|
//If the birthdays are already displayed as event, don't
|
|
|
|
//show them in the caption
|
|
|
|
this.title.addClass('calendar_calBirthday');
|
2015-05-06 21:03:45 +02:00
|
|
|
holiday_list.push(holidays[i]['name']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-14 03:08:56 +02:00
|
|
|
// Show holidays as events on mobile
|
|
|
|
if(egwIsMobile())
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-06-14 03:08:56 +02:00
|
|
|
// Create event
|
|
|
|
this._parent.date_helper.set_value(this.options.date.substring(0,4)+'-'+
|
|
|
|
(this.options.date.substring(4,6))+'-'+this.options.date.substring(6,8)+
|
|
|
|
'T00:00:00Z');
|
|
|
|
var event = et2_createWidget('calendar-event',{
|
|
|
|
id:'event_'+holidays[i].name,
|
|
|
|
value: {
|
|
|
|
title: holidays[i].name,
|
|
|
|
whole_day: true,
|
|
|
|
whole_day_on_top: true,
|
|
|
|
start: new Date(this._parent.date_helper.get_value()),
|
|
|
|
end: this.options.date,
|
|
|
|
owner: this.options.owner,
|
|
|
|
participants: this.options.owner,
|
2016-06-15 17:17:12 +02:00
|
|
|
app: 'calendar',
|
|
|
|
class: 'calendar_calBirthday'
|
2016-06-14 03:08:56 +02:00
|
|
|
},
|
|
|
|
readonly: true,
|
|
|
|
class: 'calendar_calHoliday'
|
|
|
|
},this);
|
|
|
|
event.doLoadingFinished();
|
|
|
|
event._update();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.title.addClass('calendar_calHoliday');
|
|
|
|
this.title.attr('data-holiday', holidays[i]['name']);
|
|
|
|
|
|
|
|
//If the birthdays are already displayed as event, don't
|
|
|
|
//show them in the caption
|
|
|
|
if (!this.options.display_holiday_as_event)
|
|
|
|
{
|
|
|
|
holiday_list.push(holidays[i]['name']);
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 22:53:47 +01:00
|
|
|
this.title.attr('title', holiday_list.join(','));
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the event data for this day and create event widgets for each.
|
|
|
|
*
|
|
|
|
* If event information is not provided, it will be pulled from the content array.
|
|
|
|
*
|
|
|
|
* @param {Object[]} [_events] Array of event information, one per event.
|
|
|
|
*/
|
|
|
|
_update_events: function(_events)
|
|
|
|
{
|
2015-07-22 01:45:38 +02:00
|
|
|
var events = _events || this.getArrayMgr('content').getEntry(this.options.date) || [];
|
|
|
|
|
|
|
|
// Remove extra events
|
2015-08-26 01:30:32 +02:00
|
|
|
while(this._children.length > 0)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2015-07-03 19:56:36 +02:00
|
|
|
var node = this._children[this._children.length-1];
|
|
|
|
this.removeChild(node);
|
2016-01-13 23:07:09 +01:00
|
|
|
node.free();
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
// Make sure children are in cronological order, or columns are backwards
|
|
|
|
events.sort(function(a,b) {
|
|
|
|
var start = new Date(a.start) - new Date(b.start);
|
|
|
|
var end = new Date(a.end) - new Date(b.end);
|
2015-11-09 22:21:17 +01:00
|
|
|
// Whole day events sorted by ID, normal events by start / end time
|
2016-01-14 22:24:01 +01:00
|
|
|
if(a.whole_day && b.whole_day)
|
|
|
|
{
|
|
|
|
return (a.app_id - b.app_id);
|
|
|
|
}
|
|
|
|
else if (a.whole_day || b.whole_day)
|
|
|
|
{
|
|
|
|
return a.whole_day ? -1 : 1;
|
|
|
|
}
|
|
|
|
return start ? start : end;
|
2015-07-22 01:45:38 +02:00
|
|
|
});
|
2016-01-15 21:22:55 +01:00
|
|
|
|
2015-08-26 01:30:32 +02:00
|
|
|
for(var c = 0; c < events.length; c++)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2015-07-03 19:56:36 +02:00
|
|
|
// Create event
|
|
|
|
var event = et2_createWidget('calendar-event',{
|
2016-01-05 21:43:19 +01:00
|
|
|
id:'event_'+events[c].id,
|
2015-07-03 19:56:36 +02:00
|
|
|
value: events[c]
|
|
|
|
},this);
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
|
2015-07-03 19:56:36 +02:00
|
|
|
// Seperate loop so column sorting finds all children in the right place
|
2015-07-22 01:45:38 +02:00
|
|
|
for(var c = 0; c < events.length && c < this._children.length; c++)
|
2015-07-03 19:56:36 +02:00
|
|
|
{
|
2016-01-05 21:43:19 +01:00
|
|
|
var event = this.getWidgetById('event_'+events[c].id);
|
|
|
|
if(!event) continue;
|
|
|
|
if(this.isInTree())
|
|
|
|
{
|
|
|
|
event.doLoadingFinished();
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
2015-11-04 22:47:52 +01:00
|
|
|
|
2016-06-14 03:08:56 +02:00
|
|
|
|
|
|
|
// Show holidays as events on mobile
|
|
|
|
if(egwIsMobile())
|
|
|
|
{
|
|
|
|
this.day_class_holiday();
|
|
|
|
}
|
|
|
|
|
2015-11-04 22:47:52 +01:00
|
|
|
// Apply styles to hidden events
|
|
|
|
this._out_of_view();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply styles for out-of-view and partially hidden events
|
2016-02-05 19:17:47 +01:00
|
|
|
*
|
|
|
|
* There are 3 different states or modes of display:
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2016-02-05 19:17:47 +01:00
|
|
|
* - 'Normal' - When showing events positioned by time, the indicator is just
|
|
|
|
* a bar colored by the last category color. On hover it shows either the
|
|
|
|
* title of a single event or "x event(s)" if more than one are hidden.
|
|
|
|
* Clicking adjusts the current view to show the earliest / latest hidden
|
|
|
|
* event
|
|
|
|
*
|
|
|
|
* - Fixed - When showing events positioned by time but in a fixed-height
|
|
|
|
* week (not auto-sized to fit screen) the indicator is the same as sized.
|
|
|
|
* On hover it shows the titles of the hidden events, clicking changes
|
|
|
|
* the view to the selected day.
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2016-02-05 19:17:47 +01:00
|
|
|
* - GridList - When showing just a list, the indicator shows "x event(s)",
|
|
|
|
* and on hover shows the category color, title & time. Clicking changes
|
|
|
|
* the view to the selected day, and opens the event for editing.
|
2015-11-04 22:47:52 +01:00
|
|
|
*/
|
|
|
|
_out_of_view: function()
|
|
|
|
{
|
|
|
|
// Reset
|
|
|
|
this.header.children('.hiddenEventBefore').remove();
|
|
|
|
this.div.children('.hiddenEventAfter').remove();
|
2016-01-15 21:22:55 +01:00
|
|
|
this.event_wrapper.css('overflow','visible');
|
2016-02-04 23:35:34 +01:00
|
|
|
this.all_day.removeClass('overflown');
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calEventBody', this.div).css({'padding-top': '','margin-top':''});
|
2015-11-04 22:47:52 +01:00
|
|
|
|
|
|
|
var timegrid = this._parent;
|
|
|
|
|
|
|
|
// elem is jquery div of event
|
|
|
|
function isHidden(elem) {
|
2016-03-24 18:28:51 +01:00
|
|
|
// Add an extra 5px top and bottom to include events just on the
|
|
|
|
// edge of visibility
|
|
|
|
var docViewTop = timegrid.scrolling.scrollTop() + 5,
|
2016-03-01 17:27:45 +01:00
|
|
|
docViewBottom = docViewTop + (
|
2016-01-15 21:22:55 +01:00
|
|
|
this.display_settings.granularity === 0 ?
|
|
|
|
this.event_wrapper.height() :
|
2016-03-24 18:28:51 +01:00
|
|
|
timegrid.scrolling.height() - 10
|
2016-01-15 21:22:55 +01:00
|
|
|
),
|
2015-11-04 22:47:52 +01:00
|
|
|
elemTop = elem.position().top,
|
2015-12-15 18:43:03 +01:00
|
|
|
elemBottom = elemTop + elem.outerHeight(true);
|
2015-11-04 22:47:52 +01:00
|
|
|
if((elemBottom <= docViewBottom) && (elemTop >= docViewTop))
|
|
|
|
{
|
|
|
|
// Entirely visible
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var visible = {
|
|
|
|
hidden: elemTop > docViewTop ? 'bottom' : 'top',
|
|
|
|
completely: false
|
|
|
|
};
|
|
|
|
visible.completely = visible.hidden == 'top' ? elemBottom < docViewTop : elemTop > docViewBottom;
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
2016-01-15 21:22:55 +01:00
|
|
|
// In gridlist view, we can quickly check if we need it at all
|
|
|
|
if(this.display_settings.granularity === 0 && this._children.length)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('div.calendar_calEvent',this.div).show(0);
|
2016-01-15 21:22:55 +01:00
|
|
|
if(Math.ceil(this.div.height() / this._children[0].div.height()) > this._children.length)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-02-04 23:35:34 +01:00
|
|
|
// Check all day overflow
|
2016-03-01 17:27:45 +01:00
|
|
|
this.all_day.toggleClass('overflown',
|
2016-04-28 00:23:06 +02:00
|
|
|
this.all_day[0].scrollHeight - this.all_day.innerHeight() > 5
|
2016-02-04 23:35:34 +01:00
|
|
|
);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-11-04 22:47:52 +01:00
|
|
|
// Check each event
|
|
|
|
this.iterateOver(function(event) {
|
|
|
|
// Skip whole day events and events missing value
|
2016-01-13 00:55:59 +01:00
|
|
|
if(this.display_settings.granularity && (
|
|
|
|
(!event.options || !event.options.value || event.options.value.whole_day_on_top))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-11-04 22:47:52 +01:00
|
|
|
// Reset
|
2016-01-21 19:37:31 +01:00
|
|
|
event.title.css({'top':'','background-color':''});
|
2016-02-05 19:17:47 +01:00
|
|
|
event.body.css({'padding-top':'','margin-top':''});
|
2015-11-04 22:47:52 +01:00
|
|
|
var hidden = isHidden.call(this,event.div);
|
2016-02-05 19:17:47 +01:00
|
|
|
var day = this;
|
2015-11-04 22:47:52 +01:00
|
|
|
if(!hidden)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Only top is hidden, move label
|
|
|
|
// Bottom hidden is fine
|
2016-04-13 00:48:16 +02:00
|
|
|
if(hidden.hidden === 'top' && !hidden.completely && !event.div.hasClass('calendar_calEventSmall'))
|
2015-11-04 22:47:52 +01:00
|
|
|
{
|
2016-02-05 19:17:47 +01:00
|
|
|
var title_height = event.title.outerHeight();
|
2016-01-21 19:37:31 +01:00
|
|
|
event.title.css({
|
|
|
|
'top': timegrid.scrolling.scrollTop() - event.div.position().top,
|
|
|
|
'background-color': 'transparent'
|
|
|
|
});
|
2016-02-05 19:17:47 +01:00
|
|
|
event.body.css({
|
|
|
|
'padding-top': timegrid.scrolling.scrollTop() - event.div.position().top + title_height,
|
|
|
|
'margin-top' : -title_height
|
|
|
|
});
|
2015-11-04 22:47:52 +01:00
|
|
|
}
|
2016-01-13 23:07:09 +01:00
|
|
|
// Too many in gridlist view, show indicator
|
2016-01-14 22:24:01 +01:00
|
|
|
else if (this.display_settings.granularity === 0 && hidden)
|
2016-01-13 00:55:59 +01:00
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
if(jQuery('.hiddenEventAfter',this.div).length == 0)
|
2016-01-14 22:24:01 +01:00
|
|
|
{
|
2016-01-15 21:22:55 +01:00
|
|
|
this.event_wrapper.css('overflow','hidden');
|
2016-01-14 22:24:01 +01:00
|
|
|
}
|
2016-01-15 21:22:55 +01:00
|
|
|
this._hidden_indicator(event, false, function() {
|
|
|
|
app.calendar.update_state({view: 'day', date: day.date});
|
|
|
|
});
|
|
|
|
// Avoid partially visible events
|
|
|
|
// We need to hide all, or the next row will be visible
|
|
|
|
event.div.hide(0);
|
2016-01-13 00:55:59 +01:00
|
|
|
}
|
2015-11-04 22:47:52 +01:00
|
|
|
// Completely out of view, show indicator
|
|
|
|
else if (hidden.completely)
|
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
this._hidden_indicator(event, hidden.hidden == 'top',false);
|
2016-01-13 00:55:59 +01:00
|
|
|
}
|
|
|
|
}, this, et2_calendar_event);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show an indicator that there are hidden events
|
|
|
|
*
|
2016-02-11 18:02:06 +01:00
|
|
|
* The indicator works 3 different ways, depending on if the day can be
|
|
|
|
* scrolled, is fixed, or if in gridview.
|
|
|
|
*
|
|
|
|
* @see _out_of_view()
|
|
|
|
*
|
2016-01-13 00:55:59 +01:00
|
|
|
* @param {et2_calendar_event} event Event we're creating the indicator for
|
|
|
|
* @param {boolean} top Events hidden at the top (true) or bottom (false)
|
|
|
|
* @param {function} [onclick] Callback for when user clicks on the indicator
|
|
|
|
*/
|
|
|
|
_hidden_indicator: function _hidden_indicator(event, top, onclick)
|
|
|
|
{
|
|
|
|
var indicator = '';
|
|
|
|
var day = this;
|
|
|
|
var timegrid = this._parent;
|
2016-02-05 19:17:47 +01:00
|
|
|
var fixed_height = timegrid.div.hasClass('calendar_calTimeGridFixed');
|
2016-02-11 18:02:06 +01:00
|
|
|
|
|
|
|
// Event is before the displayed times
|
2016-01-13 00:55:59 +01:00
|
|
|
if(top)
|
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
// Create if not already there
|
2016-06-02 16:51:15 +02:00
|
|
|
if(jQuery('.hiddenEventBefore',this.header).length === 0)
|
2016-01-13 00:55:59 +01:00
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
indicator = jQuery('<div class="hiddenEventBefore"></div>')
|
2016-01-13 00:55:59 +01:00
|
|
|
.appendTo(this.header)
|
2016-02-05 19:17:47 +01:00
|
|
|
.attr('data-hidden_count', 1);
|
|
|
|
if(!fixed_height)
|
|
|
|
{
|
|
|
|
indicator
|
|
|
|
.text(event.options.value.title)
|
|
|
|
.on('click', typeof onclick === 'function' ? onclick : function() {
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calEvent',day.div).first()[0].scrollIntoView();
|
2016-02-05 19:17:47 +01:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2016-01-13 00:55:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
indicator = jQuery('.hiddenEventBefore',this.header);
|
2016-01-13 00:55:59 +01:00
|
|
|
indicator.attr('data-hidden_count', parseInt(indicator.attr('data-hidden_count')) + 1);
|
2016-02-05 19:17:47 +01:00
|
|
|
|
2016-02-11 18:02:06 +01:00
|
|
|
if (!fixed_height)
|
2016-02-05 19:17:47 +01:00
|
|
|
{
|
|
|
|
indicator.text(day.egw().lang('%1 event(s) %2',indicator.attr('data-hidden_count'),''));
|
|
|
|
}
|
2016-01-13 00:55:59 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-11 18:02:06 +01:00
|
|
|
// Event is after displayed times
|
2016-01-13 00:55:59 +01:00
|
|
|
else
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
indicator = jQuery('.hiddenEventAfter',this.div);
|
2016-02-11 18:02:06 +01:00
|
|
|
// Create if not already there
|
2016-01-13 00:55:59 +01:00
|
|
|
if(indicator.length === 0)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
indicator = jQuery('<div class="hiddenEventAfter"></div>')
|
2016-01-14 22:24:01 +01:00
|
|
|
.attr('data-hidden_count', 0)
|
2016-02-11 18:02:06 +01:00
|
|
|
.appendTo(this.div);
|
|
|
|
if(!fixed_height)
|
|
|
|
{
|
|
|
|
indicator
|
|
|
|
.on('click', typeof onclick === 'function' ? onclick : function() {
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calEvent',day.div).last()[0].scrollIntoView(false);
|
2016-02-11 18:02:06 +01:00
|
|
|
// Better re-run this to clean up
|
|
|
|
day._out_of_view();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
2016-02-05 19:17:47 +01:00
|
|
|
{
|
|
|
|
indicator
|
|
|
|
.on('mouseover', function() {
|
|
|
|
indicator.css({
|
|
|
|
'height': (indicator.attr('data-hidden_count')*1.2) + 'em',
|
|
|
|
'margin-top': -(indicator.attr('data-hidden_count')*1.2) + 'em'
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.on('mouseout', function() {
|
|
|
|
indicator.css({
|
|
|
|
'height': '',
|
|
|
|
'margin-top': ''
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2016-01-13 00:55:59 +01:00
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
var count = parseInt(indicator.attr('data-hidden_count')) + 1;
|
2016-01-14 22:24:01 +01:00
|
|
|
indicator.attr('data-hidden_count', count);
|
|
|
|
if(this.display_settings.granularity === 0)
|
|
|
|
{
|
|
|
|
indicator.append(event.div.clone());
|
|
|
|
indicator.attr('data-hidden_label', day.egw().lang('%1 event(s) %2',indicator.attr('data-hidden_count'),''));
|
|
|
|
}
|
2016-02-11 18:02:06 +01:00
|
|
|
else if (!fixed_height)
|
2016-01-13 00:55:59 +01:00
|
|
|
{
|
2016-01-14 22:24:01 +01:00
|
|
|
indicator.text(day.egw().lang('%1 event(s) %2',indicator.attr('data-hidden_count'),''));
|
2015-11-04 22:47:52 +01:00
|
|
|
}
|
2016-01-14 22:24:01 +01:00
|
|
|
indicator.css('top',timegrid.scrolling.height() + timegrid.scrolling.scrollTop()-indicator.innerHeight());
|
2016-01-13 00:55:59 +01:00
|
|
|
}
|
2016-02-11 18:02:06 +01:00
|
|
|
// Show different stuff for fixed height
|
|
|
|
if(fixed_height)
|
|
|
|
{
|
|
|
|
indicator
|
|
|
|
.append("<div id='"+event.dom_id +
|
|
|
|
"' data-id='"+event.options.value.id+"'>"+
|
|
|
|
event.options.value.title+
|
|
|
|
"</div>"
|
|
|
|
);
|
|
|
|
}
|
2016-01-13 00:55:59 +01:00
|
|
|
// Match color to the event
|
|
|
|
if(indicator !== '')
|
|
|
|
{
|
|
|
|
// Avoid white, which is hard to see
|
|
|
|
// Use border-bottom-color, Firefox doesn't give a value with border-color
|
2016-02-05 19:17:47 +01:00
|
|
|
var color = jQuery.Color(event.div.css('background-color')).toString() !== jQuery.Color('white').toString() ?
|
|
|
|
event.div.css('background-color') : event.div.css('border-bottom-color');
|
2016-01-13 00:55:59 +01:00
|
|
|
if(color !== 'rgba(0, 0, 0, 0)')
|
|
|
|
{
|
|
|
|
indicator.css('border-color', color);
|
|
|
|
}
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort a day's events into minimally overlapping columns
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-05-06 21:03:45 +02:00
|
|
|
* @returns {Array[]} Events sorted into columns
|
|
|
|
*/
|
2015-07-03 19:56:36 +02:00
|
|
|
_spread_events: function()
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-01-13 00:55:59 +01:00
|
|
|
if(!this.date) return [];
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
var day_start = this.date.valueOf() / 1000;
|
|
|
|
var dst_check = new Date(this.date);
|
2015-06-10 23:51:28 +02:00
|
|
|
dst_check.setUTCHours(12);
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// if daylight saving is switched on or off, correct $day_start
|
|
|
|
// gives correct times after 2am, times between 0am and 2am are wrong
|
|
|
|
var daylight_diff = day_start + 12*60*60 - (dst_check.valueOf()/1000);
|
|
|
|
if(daylight_diff)
|
|
|
|
{
|
|
|
|
day_start -= daylight_diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
var eventCols = [], col_ends = [];
|
2015-07-15 18:29:10 +02:00
|
|
|
|
|
|
|
// Make sure children are in cronological order, or columns are backwards
|
|
|
|
this._children.sort(function(a,b) {
|
|
|
|
var start = new Date(a.options.value.start) - new Date(b.options.value.start);
|
|
|
|
var end = new Date(a.options.value.end) - new Date(b.options.value.end);
|
2016-01-14 22:24:01 +01:00
|
|
|
// Whole day events sorted by ID, normal events by start / end time
|
|
|
|
if(a.options.value.whole_day && b.options.value.whole_day)
|
|
|
|
{
|
2016-01-28 22:35:22 +01:00
|
|
|
// Longer duration comes first so we have nicer bars across the top
|
2016-03-01 17:27:45 +01:00
|
|
|
var duration =
|
2016-01-28 22:35:22 +01:00
|
|
|
(new Date(b.options.value.end) - new Date(b.options.value.start)) -
|
|
|
|
(new Date(a.options.value.end) - new Date(a.options.value.start));
|
|
|
|
|
|
|
|
return duration ? duration : (a.options.value.app_id - b.options.value.app_id);
|
2016-01-14 22:24:01 +01:00
|
|
|
}
|
|
|
|
else if (a.options.value.whole_day || b.options.value.whole_day)
|
|
|
|
{
|
|
|
|
return a.options.value.whole_day ? -1 : 1;
|
|
|
|
}
|
|
|
|
return start ? start : end;
|
2015-07-15 18:29:10 +02:00
|
|
|
});
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-03 19:56:36 +02:00
|
|
|
for(var i = 0; i < this._children.length; i++)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2015-07-03 19:56:36 +02:00
|
|
|
var event = this._children[i].options.value || false;
|
|
|
|
if(!event) continue;
|
2016-03-01 17:27:45 +01:00
|
|
|
if(event.date && event.date != this.options.date &&
|
2015-09-28 21:31:01 +02:00
|
|
|
// Multi-day events date may be different
|
|
|
|
(new Date(event.start) >= this.date || new Date(event.end) <= this.date )
|
|
|
|
)
|
2015-07-22 01:45:38 +02:00
|
|
|
{
|
|
|
|
// Still have a child event that has changed date (DnD)
|
|
|
|
this._children[i].destroy();
|
|
|
|
this.removeChild(this._children[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
var c = 0;
|
|
|
|
event['multiday'] = false;
|
2015-06-10 23:51:28 +02:00
|
|
|
if(typeof event.start !== 'object')
|
|
|
|
{
|
2016-01-16 01:38:44 +01:00
|
|
|
event.start = new Date(event.start);
|
2015-06-10 23:51:28 +02:00
|
|
|
}
|
|
|
|
if(typeof event.end !== 'object')
|
|
|
|
{
|
2016-01-16 01:38:44 +01:00
|
|
|
event.end = new Date(event.end);
|
2015-06-10 23:51:28 +02:00
|
|
|
}
|
|
|
|
event['start_m'] = parseInt((event.start.valueOf()/1000 - day_start) / 60);
|
2015-05-06 21:03:45 +02:00
|
|
|
if (event['start_m'] < 0)
|
|
|
|
{
|
|
|
|
event['start_m'] = 0;
|
|
|
|
event['multiday'] = true;
|
|
|
|
}
|
2015-06-10 23:51:28 +02:00
|
|
|
event['end_m'] = parseInt((event.end.valueOf()/1000 - day_start) / 60);
|
2015-05-06 21:03:45 +02:00
|
|
|
if (event['end_m'] >= 24*60)
|
|
|
|
{
|
|
|
|
event['end_m'] = 24*60-1;
|
|
|
|
event['multiday'] = true;
|
|
|
|
}
|
2015-06-10 23:51:28 +02:00
|
|
|
if(!event.start.getUTCHours() && !event.start.getUTCMinutes() && event.end.getUTCHours() == 23 && event.end.getUTCMinutes() == 59)
|
|
|
|
{
|
|
|
|
event.whole_day_on_top = (event.non_blocking && event.non_blocking != '0');
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
if (!event['whole_day_on_top'])
|
|
|
|
{
|
|
|
|
for(c = 0; event['start_m'] < col_ends[c]; ++c);
|
|
|
|
col_ends[c] = event['end_m'];
|
|
|
|
}
|
2015-07-15 18:29:10 +02:00
|
|
|
if(typeof eventCols[c] === 'undefined')
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
eventCols[c] = [];
|
|
|
|
}
|
2015-07-03 19:56:36 +02:00
|
|
|
eventCols[c].push(this._children[i]);
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
return eventCols;
|
|
|
|
},
|
2015-07-03 19:56:36 +02:00
|
|
|
|
|
|
|
/**
|
2016-01-13 23:07:09 +01:00
|
|
|
* Position the event according to its time and how this widget is laid
|
2015-07-03 19:56:36 +02:00
|
|
|
* out.
|
|
|
|
*
|
2016-01-13 23:07:09 +01:00
|
|
|
* @param {et2_calendar_event} [event] - Event to be updated
|
|
|
|
* If a single event is not provided, all events are repositioned.
|
2015-07-03 19:56:36 +02:00
|
|
|
*/
|
|
|
|
position_event: function(event)
|
|
|
|
{
|
2016-05-25 23:21:39 +02:00
|
|
|
// If hidden, skip it - it takes too long
|
|
|
|
if(!this.div.is(':visible')) return;
|
|
|
|
|
2015-07-03 19:56:36 +02:00
|
|
|
// Sort events into minimally-overlapping columns
|
|
|
|
var columns = this._spread_events();
|
|
|
|
|
|
|
|
for(var c = 0; c < columns.length; c++)
|
|
|
|
{
|
|
|
|
// Calculate horizontal positioning
|
2015-10-29 22:53:47 +01:00
|
|
|
var left = Math.ceil(5 + (1.5 * 100 / (parseFloat(this.options.width) || 100)));
|
2016-01-18 21:02:35 +01:00
|
|
|
var right = 2;
|
2015-07-03 19:56:36 +02:00
|
|
|
if (columns.length !== 1)
|
|
|
|
{
|
2016-01-18 21:02:35 +01:00
|
|
|
right = !c ? 30 : 2;
|
2015-07-03 19:56:36 +02:00
|
|
|
left += c * (100.0-left) / columns.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var i = 0; (columns[c].indexOf(event) >= 0 || !event) && i < columns[c].length; i++)
|
|
|
|
{
|
|
|
|
// Calculate vertical positioning
|
|
|
|
var top = 0;
|
|
|
|
var height = 0;
|
2016-01-13 00:55:59 +01:00
|
|
|
// Position the event
|
|
|
|
if(this.display_settings.granularity === 0)
|
|
|
|
{
|
|
|
|
if(this.all_day.has(columns[c][i].div).length)
|
|
|
|
{
|
2016-01-15 21:22:55 +01:00
|
|
|
columns[c][i].div.prependTo(this.event_wrapper);
|
2016-01-13 00:55:59 +01:00
|
|
|
}
|
|
|
|
columns[c][i].div.css('top', '');
|
|
|
|
columns[c][i].div.css('height', '');
|
|
|
|
columns[c][i].div.css('left', '');
|
2016-01-18 21:02:35 +01:00
|
|
|
columns[c][i].div.css('right', '');
|
2016-01-13 00:55:59 +01:00
|
|
|
// Strip out of view padding
|
|
|
|
columns[c][i].body.css('padding-top','');
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-03 19:56:36 +02:00
|
|
|
if(columns[c][i].options.value.whole_day_on_top)
|
|
|
|
{
|
2015-11-12 02:01:21 +01:00
|
|
|
if(!this.all_day.has(columns[c][i].div).length)
|
|
|
|
{
|
2015-12-09 21:54:01 +01:00
|
|
|
columns[c][i].div.css('top', '');
|
|
|
|
columns[c][i].div.css('height','');
|
|
|
|
columns[c][i].div.css('left', '');
|
2016-01-18 21:02:35 +01:00
|
|
|
columns[c][i].div.css('right', '');
|
2015-12-09 21:54:01 +01:00
|
|
|
columns[c][i].body.css('padding-top','');
|
2015-11-12 02:01:21 +01:00
|
|
|
columns[c][i].div
|
|
|
|
.appendTo(this.all_day);
|
2015-12-09 21:54:01 +01:00
|
|
|
this._parent.resizeTimes();
|
2015-11-12 02:01:21 +01:00
|
|
|
}
|
2015-10-06 01:45:51 +02:00
|
|
|
continue;
|
2015-07-03 19:56:36 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-12 02:01:21 +01:00
|
|
|
if(this.all_day.has(columns[c][i].div).length)
|
|
|
|
{
|
2016-01-15 21:22:55 +01:00
|
|
|
columns[c][i].div.appendTo(this.event_wrapper);
|
2015-12-09 21:54:01 +01:00
|
|
|
this._parent.resizeTimes();
|
2015-11-12 02:01:21 +01:00
|
|
|
}
|
2016-01-13 23:07:09 +01:00
|
|
|
top = this._time_to_position(columns[c][i].options.value.start_m);
|
|
|
|
height = this._time_to_position(columns[c][i].options.value.end_m)-top;
|
2015-07-03 19:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Position the event
|
|
|
|
if(event && columns[c].indexOf(event) >= 0 || !event)
|
|
|
|
{
|
|
|
|
columns[c][i].div.css('top', top+'%');
|
|
|
|
columns[c][i].div.css('height', height+'%');
|
2015-12-28 17:25:53 +01:00
|
|
|
// Remove spacing from border, but only if visible or the height will be wrong
|
|
|
|
if(columns[c][i].div.is(':visible'))
|
|
|
|
{
|
2015-12-29 17:20:50 +01:00
|
|
|
var border_diff = columns[c][i].div.outerHeight() - columns[c][i].div.height();
|
2016-04-21 21:00:21 +02:00
|
|
|
columns[c][i].div.css('height','calc('+height+'% - ' +border_diff+')');
|
2015-12-28 17:25:53 +01:00
|
|
|
}
|
2015-12-15 18:43:03 +01:00
|
|
|
// This gives the wrong height
|
|
|
|
//columns[c][i].div.outerHeight(height+'%');
|
2015-07-03 19:56:36 +02:00
|
|
|
columns[c][i].div.css('left', left.toFixed(1)+'%');
|
2016-01-18 21:02:35 +01:00
|
|
|
columns[c][i].div.css('right', right.toFixed(1)+'%');
|
2015-11-23 21:00:31 +01:00
|
|
|
columns[c][i].div.css('z-index',parseInt(20)+c);
|
2016-01-28 22:35:22 +01:00
|
|
|
columns[c][i]._small_size();
|
2015-07-03 19:56:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Only wanted to position this event, leave the other columns alone
|
|
|
|
if(event && columns[c].indexOf(event) >= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
/**
|
|
|
|
* Calculates the vertical position based on the time
|
|
|
|
*
|
2015-10-06 01:45:51 +02:00
|
|
|
* This calculation is a percentage from 00:00 to 23:59
|
2015-05-06 21:03:45 +02:00
|
|
|
*
|
|
|
|
* @param {int} time in minutes from midnight
|
|
|
|
* @return {float} position in percent
|
|
|
|
*/
|
2016-01-13 23:07:09 +01:00
|
|
|
_time_to_position: function(time)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
var pos = 0.0;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-10-06 01:45:51 +02:00
|
|
|
// 24h
|
2016-01-13 23:07:09 +01:00
|
|
|
pos = ((time / 60) / 24) * 100;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-13 23:07:09 +01:00
|
|
|
pos = pos.toFixed(1);
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
},
|
|
|
|
|
|
|
|
attachToDOM: function()
|
|
|
|
{
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Remove the binding for the click handler, unless there's something
|
|
|
|
// custom here.
|
|
|
|
if (!this.onclick)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.node).off("click");
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
// But we do want to listen to certain clicks, and handle them internally
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.node).on('click.et2_daycol',
|
2015-05-06 21:03:45 +02:00
|
|
|
'.calendar_calDayColHeader,.calendar_calAddEvent',
|
|
|
|
jQuery.proxy(this.click, this)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click handler calling custom handler set via onclick attribute to this.onclick,
|
|
|
|
* or the default which is to open a new event at that time.
|
|
|
|
*
|
|
|
|
* Normally, you don't bind to this one, but the attribute is supported if you
|
|
|
|
* can get a reference to the widget.
|
|
|
|
*
|
|
|
|
* @param {Event} _ev
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2015-10-06 01:45:51 +02:00
|
|
|
click: function(_ev)
|
|
|
|
{
|
2016-07-01 19:57:06 +02:00
|
|
|
// Drag to create in progress
|
|
|
|
if(this._parent.drag_create.start !== null) return;
|
|
|
|
|
2015-10-06 01:45:51 +02:00
|
|
|
// Click on the title
|
2016-06-02 16:51:15 +02:00
|
|
|
if (jQuery(_ev.target).hasClass('calendar_calAddEvent'))
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-04-28 00:23:06 +02:00
|
|
|
if(this.header.has(_ev.target).length == 0 && !_ev.target.dataset.whole_day)
|
2015-11-13 18:07:48 +01:00
|
|
|
{
|
2016-04-11 16:37:04 +02:00
|
|
|
// Default handler to open a new event at the selected time
|
|
|
|
var options = {
|
|
|
|
date: _ev.target.dataset.date || this.options.date,
|
|
|
|
hour: _ev.target.dataset.hour || this._parent.options.day_start,
|
|
|
|
minute: _ev.target.dataset.minute || 0
|
|
|
|
};
|
|
|
|
if (this.options.owner != app.calendar.state.owner)
|
|
|
|
{
|
|
|
|
options.owner = this.options.owner;
|
|
|
|
}
|
|
|
|
this.egw().open(null, 'calendar', 'add', options, '_blank');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Header, all day non-blocking
|
2016-06-02 16:51:15 +02:00
|
|
|
else if (this.header.has(_ev.target).length && !jQuery('.hiddenEventBefore',this.header).has(_ev.target).length ||
|
2016-04-11 16:37:04 +02:00
|
|
|
this.header.is(_ev.target)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
// Click on the header, but not the title. That's an all-day non-blocking
|
|
|
|
var end = this.date.getFullYear() + '-' + (this.date.getUTCMonth()+1) + '-' + this.date.getUTCDate() + 'T23:59';
|
|
|
|
this.egw().open(null, 'calendar', 'add', {
|
|
|
|
start: this.date.toJSON(),
|
|
|
|
end: end,
|
|
|
|
non_blocking: true
|
|
|
|
} , '_blank');
|
|
|
|
return false;
|
2015-11-13 18:07:48 +01:00
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
2016-04-06 16:56:03 +02:00
|
|
|
// Day label
|
|
|
|
else if(this.title.is(_ev.target) || this.title.has(_ev.target))
|
|
|
|
{
|
|
|
|
app.calendar.update_state({view: 'day',date: this.date.toJSON()});
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-11 16:37:04 +02:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code for implementing et2_IDetachedDOM
|
|
|
|
*
|
|
|
|
* @param {array} _attrs array to add further attributes to
|
|
|
|
*/
|
|
|
|
getDetachedAttributes: function(_attrs) {
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getDetachedNodes: function() {
|
|
|
|
return [this.getDOMNode()];
|
|
|
|
},
|
|
|
|
|
|
|
|
setDetachedAttributes: function(_nodes, _values) {
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-11 20:46:01 +01:00
|
|
|
// Resizable interface
|
|
|
|
/**
|
|
|
|
* Resize
|
|
|
|
*
|
|
|
|
* Parent takes care of setting proper width & height for the containing div
|
|
|
|
* here we just need to adjust the events to fit the new size.
|
|
|
|
*/
|
|
|
|
resize: function ()
|
|
|
|
{
|
|
|
|
if(this.disabled || !this.div.is(':visible') || this._parent.disabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
|
2016-01-13 00:55:59 +01:00
|
|
|
if(this.display_settings.granularity !== this._parent.options.granularity)
|
|
|
|
{
|
|
|
|
// Layout has changed
|
|
|
|
this._draw();
|
|
|
|
|
2016-04-21 21:00:21 +02:00
|
|
|
// Resize & position all events
|
|
|
|
this.position_event();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Don't need to resize & reposition, just clear some stuff
|
|
|
|
// to reset for _out_of_view()
|
|
|
|
this.iterateOver(function(widget) {
|
|
|
|
widget._small_size();
|
|
|
|
}, this, et2_calendar_event);
|
|
|
|
}
|
2016-01-13 00:55:59 +01:00
|
|
|
this._out_of_view();
|
2016-01-11 20:46:01 +01:00
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
});}).call(this);
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
et2_register_widget(et2_calendar_daycol, ["calendar-daycol"]);
|