2016-03-01 17:27:45 +01:00
|
|
|
/*
|
2015-06-25 19:44:28 +02:00
|
|
|
* Egroupware Calendar timegrid
|
|
|
|
* @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
|
2015-12-28 23:21:47 +01:00
|
|
|
/calendar/js/et2_widget_view.js;
|
2015-06-25 19:44:28 +02:00
|
|
|
/calendar/js/et2_widget_planner_row.js;
|
|
|
|
/calendar/js/et2_widget_event.js;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "calendar-planner" XET-Tag for displaying a longer
|
2016-01-13 23:07:09 +01:00
|
|
|
* ( > 10 days) span of time. Events can be grouped into rows by either user,
|
|
|
|
* category, or month. Their horizontal position and size in the row is determined
|
|
|
|
* by their start date and duration relative to the displayed date range.
|
2015-06-25 19:44:28 +02:00
|
|
|
*
|
2016-01-13 23:07:09 +01:00
|
|
|
* @augments et2_calendar_view
|
2015-06-25 19:44:28 +02:00
|
|
|
*/
|
2016-03-01 17:27:45 +01:00
|
|
|
var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.extend([et2_IDetachedDOM, et2_IResizeable],
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
createNamespace: true,
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
attributes: {
|
|
|
|
group_by: {
|
|
|
|
name: "Group by",
|
|
|
|
type: "string", // or category ID
|
|
|
|
default: "0",
|
|
|
|
description: "Display planner by 'user', 'month', or the given category"
|
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
name: "Filter",
|
|
|
|
type: "string",
|
|
|
|
default: '',
|
|
|
|
description: 'A filter that is used to select events. It is passed along when events are queried.'
|
|
|
|
},
|
2016-04-19 22:27:09 +02:00
|
|
|
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."
|
|
|
|
},
|
2015-06-25 19:44:28 +02:00
|
|
|
value: {
|
|
|
|
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"
|
|
|
|
},
|
|
|
|
"onchange": {
|
|
|
|
"name": "onchange",
|
|
|
|
"type": "js",
|
|
|
|
"default": et2_no_init,
|
|
|
|
"description": "JS code which is executed when the date range changes."
|
|
|
|
},
|
|
|
|
"onevent_change": {
|
|
|
|
"name": "onevent_change",
|
|
|
|
"type": "js",
|
|
|
|
"default": et2_no_init,
|
|
|
|
"description": "JS code which is executed when an event changes."
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @memberOf et2_calendar_planner
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Main container
|
2016-06-02 16:51:15 +02:00
|
|
|
this.div = jQuery(document.createElement("div"))
|
2015-06-25 19:44:28 +02:00
|
|
|
.addClass("calendar_plannerWidget");
|
|
|
|
|
|
|
|
// Header
|
2016-06-02 16:51:15 +02:00
|
|
|
this.gridHeader = jQuery(document.createElement("div"))
|
2015-06-25 19:44:28 +02:00
|
|
|
.addClass("calendar_plannerHeader")
|
|
|
|
.appendTo(this.div);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.headerTitle = jQuery(document.createElement("div"))
|
2015-06-25 19:44:28 +02:00
|
|
|
.addClass("calendar_plannerHeaderTitle")
|
|
|
|
.appendTo(this.gridHeader);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.headers = jQuery(document.createElement("div"))
|
2015-06-25 19:44:28 +02:00
|
|
|
.addClass("calendar_plannerHeaderRows")
|
|
|
|
.appendTo(this.gridHeader);
|
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
this.rows = jQuery(document.createElement("div"))
|
2016-01-22 00:07:29 +01:00
|
|
|
.addClass("calendar_plannerRows")
|
|
|
|
.appendTo(this.div);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.grid = jQuery(document.createElement("div"))
|
2016-01-22 00:07:29 +01:00
|
|
|
.addClass("calendar_plannerGrid")
|
2015-06-25 19:44:28 +02:00
|
|
|
.appendTo(this.div);
|
2015-11-06 23:57:27 +01:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
this.vertical_bar = jQuery(document.createElement("div"))
|
2015-11-06 23:57:27 +01:00
|
|
|
.addClass('verticalBar')
|
|
|
|
.appendTo(this.div);
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
this.value = [];
|
|
|
|
|
|
|
|
// Update timer, to avoid redrawing twice when changing start & end date
|
|
|
|
this.update_timer = null;
|
2015-08-26 01:30:32 +02:00
|
|
|
this.doInvalidate = true;
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
this.setDOMNode(this.div[0]);
|
2015-08-11 17:35:54 +02:00
|
|
|
|
|
|
|
this.registeredCallbacks = [];
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.div.off();
|
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
for(var i = 0; i < this.registeredCallbacks.length; i++)
|
|
|
|
{
|
|
|
|
egw.dataUnregisterUID(this.registeredCallbacks[i],false,this);
|
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
doLoadingFinished: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Don't bother to draw anything if there's no date yet
|
|
|
|
if(this.options.start_date)
|
|
|
|
{
|
|
|
|
this._drawGrid();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actions may be set on a parent, so we need to explicitly get in here
|
|
|
|
// and get ours
|
|
|
|
this._link_actions(this.options.actions || this._parent.options.actions || []);
|
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
// Automatically bind drag and resize for every event using jQuery directly
|
|
|
|
// - no action system -
|
|
|
|
var planner = this;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If user puts the mouse over an event, then we'll set up resizing so
|
|
|
|
* they can adjust the length. Should be a little better on resources
|
|
|
|
* than binding it for every calendar event.
|
|
|
|
*/
|
|
|
|
this.div.on('mouseover', '.calendar_calEvent:not(.ui-resizable):not(.rowNoEdit)', function() {
|
2015-11-06 23:57:27 +01:00
|
|
|
// Load the event
|
|
|
|
planner._get_event_info(this);
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
//Resizable event handler
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).resizable
|
2015-11-06 23:57:27 +01:00
|
|
|
({
|
|
|
|
distance: 10,
|
|
|
|
grid: [5, 10000],
|
|
|
|
autoHide: false,
|
|
|
|
handles: 'e',
|
|
|
|
containment:'parent',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered when the resizable is created.
|
|
|
|
*
|
|
|
|
* @param {event} event
|
|
|
|
* @param {Object} ui
|
|
|
|
*/
|
|
|
|
create:function(event, ui)
|
2015-08-11 17:35:54 +02:00
|
|
|
{
|
2015-11-06 23:57:27 +01:00
|
|
|
var resizeHelper = event.target.getAttribute('data-resize');
|
|
|
|
if (resizeHelper == 'WD' || resizeHelper == 'WDS')
|
2015-08-11 17:35:54 +02:00
|
|
|
{
|
2015-11-06 23:57:27 +01:00
|
|
|
jQuery(this).resizable('destroy');
|
2015-08-11 17:35:54 +02:00
|
|
|
}
|
2015-11-06 23:57:27 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered at the end of resizing the calEvent.
|
|
|
|
*
|
|
|
|
* @param {event} event
|
|
|
|
* @param {Object} ui
|
|
|
|
*/
|
|
|
|
stop:function(event, ui)
|
|
|
|
{
|
|
|
|
var e = new jQuery.Event('change');
|
|
|
|
e.originalEvent = event;
|
|
|
|
e.data = {duration: 0};
|
|
|
|
var event_data = planner._get_event_info(this);
|
2016-01-19 19:03:42 +01:00
|
|
|
var event_widget = planner.getWidgetById(event_data.widget_id);
|
2015-11-06 23:57:27 +01:00
|
|
|
var sT = event_widget.options.value.start_m;
|
|
|
|
if (typeof this.dropEnd != 'undefined')
|
|
|
|
{
|
|
|
|
var eT = parseInt(this.dropEnd.getUTCHours() * 60) + parseInt(this.dropEnd.getUTCMinutes());
|
|
|
|
e.data.duration = ((eT - sT)/60) * 3600;
|
|
|
|
|
|
|
|
if(event_widget)
|
|
|
|
{
|
|
|
|
event_widget.options.value.end_m = eT;
|
|
|
|
event_widget.options.value.duration = e.data.duration;
|
|
|
|
}
|
2015-08-11 17:35:54 +02:00
|
|
|
|
2015-11-06 23:57:27 +01:00
|
|
|
// Leave the helper there until the update is done
|
|
|
|
var loading = ui.helper.clone().appendTo(ui.helper.parent());
|
2015-08-11 17:35:54 +02:00
|
|
|
|
2015-11-06 23:57:27 +01:00
|
|
|
// and add a loading icon so user knows something is happening
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_timeDemo',loading).after('<div class="loading"></div>');
|
2015-08-11 17:35:54 +02:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).trigger(e);
|
2015-08-11 17:35:54 +02:00
|
|
|
|
2015-11-06 23:57:27 +01:00
|
|
|
// That cleared the resize handles, so remove for re-creation...
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).resizable('destroy');
|
2015-11-06 23:57:27 +01:00
|
|
|
|
|
|
|
// Remove loading, done or not
|
|
|
|
loading.remove();
|
|
|
|
}
|
|
|
|
// Clear the helper, re-draw
|
|
|
|
if(event_widget)
|
|
|
|
{
|
|
|
|
event_widget._parent.position_event(event_widget);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered during the resize, on the drag of the resize handler
|
|
|
|
*
|
|
|
|
* @param {event} event
|
|
|
|
* @param {Object} ui
|
|
|
|
*/
|
|
|
|
resize:function(event, ui)
|
2015-08-11 17:35:54 +02:00
|
|
|
{
|
2015-11-06 23:57:27 +01:00
|
|
|
planner._drag_helper(this,{
|
|
|
|
top:ui.position.top,
|
|
|
|
left: ui.position.left + ui.helper.width()
|
|
|
|
},ui.helper.outerHeight());
|
2015-08-11 17:35:54 +02:00
|
|
|
}
|
2015-11-06 23:57:27 +01:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.on('mousemove', function(event) {
|
2015-11-10 00:06:17 +01:00
|
|
|
// Not when over header
|
2016-06-02 16:51:15 +02:00
|
|
|
if(jQuery(event.target).closest('.calendar_eventRows').length == 0)
|
2015-11-10 00:06:17 +01:00
|
|
|
{
|
|
|
|
planner.vertical_bar.hide();
|
|
|
|
return;
|
|
|
|
}
|
2015-11-06 23:57:27 +01:00
|
|
|
// Position bar by mouse
|
|
|
|
planner.vertical_bar.position({
|
|
|
|
my: 'right-1',
|
|
|
|
of: event,
|
|
|
|
collision: 'fit'
|
|
|
|
});
|
|
|
|
planner.vertical_bar.css('top','0px');
|
|
|
|
|
|
|
|
// Get time at mouse
|
|
|
|
if(planner.options.group_by == 'month')
|
2015-08-11 17:35:54 +02:00
|
|
|
{
|
2015-11-06 23:57:27 +01:00
|
|
|
var time = planner._get_time_from_position(event.clientX, event.clientY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var time = planner._get_time_from_position(event.offsetX, event.offsetY);
|
|
|
|
}
|
|
|
|
// Passing to formatter, cancel out timezone
|
|
|
|
if(time)
|
|
|
|
{
|
|
|
|
var formatDate = new Date(time.valueOf() + time.getTimezoneOffset() * 60 * 1000);
|
2015-11-10 00:06:17 +01:00
|
|
|
planner.vertical_bar
|
|
|
|
.html('<span>'+date(egw.preference('timeformat','calendar') == 12 ? 'h:ia' : 'H:i',formatDate)+'</span>')
|
|
|
|
.show();
|
2015-11-06 23:57:27 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-10 00:06:17 +01:00
|
|
|
// No (valid) time, just hide
|
|
|
|
planner.vertical_bar.hide();
|
2015-08-11 17:35:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Customize and override some draggable settings
|
2015-11-11 17:54:00 +01:00
|
|
|
this.div.on('dragcreate','.calendar_calEvent', function(event, ui) {
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).draggable('option','cancel','.rowNoEdit');
|
2015-11-11 17:54:00 +01:00
|
|
|
// Act like you clicked the header, makes it easier to position
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).draggable('option','cursorAt', {top: 5, left: 5});
|
2015-08-11 17:35:54 +02:00
|
|
|
})
|
|
|
|
.on('dragstart', '.calendar_calEvent', function(event,ui) {
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calEvent',ui.helper).width(jQuery(this).width())
|
|
|
|
.height(jQuery(this).outerHeight())
|
2015-08-11 17:35:54 +02:00
|
|
|
.css('top', '').css('left','')
|
|
|
|
.appendTo(ui.helper);
|
2016-06-02 16:51:15 +02:00
|
|
|
ui.helper.width(jQuery(this).width());
|
2015-08-11 17:35:54 +02:00
|
|
|
});
|
2015-06-25 19:44:28 +02:00
|
|
|
return true;
|
|
|
|
},
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
/**
|
|
|
|
* These handle the differences between the different group types.
|
|
|
|
* They provide the different titles, labels and grouping
|
|
|
|
*/
|
|
|
|
groupers: {
|
|
|
|
// Group by user has one row for each user
|
|
|
|
user:
|
|
|
|
{
|
|
|
|
// Title in top left corner
|
|
|
|
title: function() { return this.egw().lang('User');},
|
|
|
|
// Column headers
|
|
|
|
headers: function() {
|
|
|
|
var start = new Date(this.options.start_date);
|
|
|
|
var end = new Date(this.options.end_date);
|
|
|
|
var start_date = new Date(start.getUTCFullYear(), start.getUTCMonth(),start.getUTCDate());
|
|
|
|
var end_date = new Date(end.getUTCFullYear(), end.getUTCMonth(),end.getUTCDate());
|
|
|
|
var day_count = Math.round((end_date - start_date) /(1000*3600*24))+1;
|
2016-01-22 00:07:29 +01:00
|
|
|
if(day_count >= 6)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
this.headers.append(this._header_months(start, day_count));
|
|
|
|
}
|
2016-01-22 00:07:29 +01:00
|
|
|
if(day_count < 120)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2016-01-22 00:07:29 +01:00
|
|
|
var weeks = this._header_weeks(start, day_count);
|
|
|
|
this.headers.append(weeks);
|
|
|
|
this.grid.append(weeks);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-09-09 22:59:23 +02:00
|
|
|
if(day_count < 60)
|
|
|
|
{
|
2016-01-22 00:07:29 +01:00
|
|
|
var days = this._header_days(start, day_count);
|
|
|
|
this.headers.append(days);
|
|
|
|
this.grid.append(days);
|
2015-09-09 22:59:23 +02:00
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
if(day_count <= 7)
|
|
|
|
{
|
2016-01-22 00:07:29 +01:00
|
|
|
var hours = this._header_hours(start, day_count);
|
|
|
|
this.headers.append(hours);
|
|
|
|
this.grid.append(hours);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Labels for the rows
|
|
|
|
row_labels: function() {
|
2015-08-12 00:30:50 +02:00
|
|
|
var labels = [];
|
2015-11-10 22:40:42 +01:00
|
|
|
var already_added = [];
|
2015-06-25 19:44:28 +02:00
|
|
|
for(var i = 0; i < this.options.owner.length; i++)
|
|
|
|
{
|
|
|
|
var user = this.options.owner[i];
|
2016-04-04 23:36:44 +02:00
|
|
|
if (user < 0) // groups
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
egw.accountData(user,'account_fullname',true,function(result) {
|
|
|
|
for(var id in result)
|
|
|
|
{
|
2015-11-13 18:07:48 +01:00
|
|
|
if(already_added.indexOf(''+id) < 0)
|
2015-11-10 22:40:42 +01:00
|
|
|
{
|
2016-05-02 17:17:20 +02:00
|
|
|
this.push({id: id, label: result[id]||'', data: {participants:id,owner:id}});
|
2015-11-16 18:15:43 +01:00
|
|
|
already_added.push(''+id);
|
2015-11-10 22:40:42 +01:00
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
},labels);
|
|
|
|
}
|
|
|
|
else // users
|
|
|
|
{
|
2016-04-04 23:36:44 +02:00
|
|
|
if(already_added.indexOf(user) < 0)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2016-05-02 21:22:52 +02:00
|
|
|
var label = this._get_owner_name(user)||'';
|
2016-04-04 23:36:44 +02:00
|
|
|
labels.push({id: user, label: label, data: {participants:user,owner:''}});
|
|
|
|
already_added.push(''+user);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-26 16:35:58 +02:00
|
|
|
|
2016-01-14 23:21:38 +01:00
|
|
|
return labels.sort(function(a,b) {
|
|
|
|
return a.label.localeCompare(b.label);
|
|
|
|
});
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
// Group the events into the rows
|
|
|
|
group: function(labels, rows, event) {
|
|
|
|
// convert filter to allowed status
|
|
|
|
var status_to_show = ['U','A','T','D','G'];
|
|
|
|
switch(this.options.filter)
|
|
|
|
{
|
|
|
|
case 'unknown':
|
|
|
|
status_to_show = ['U','G']; break;
|
|
|
|
case 'accepted':
|
|
|
|
status_to_show = ['A']; break;
|
|
|
|
case 'tentative':
|
|
|
|
status_to_show = ['T']; break;
|
|
|
|
case 'rejected':
|
|
|
|
status_to_show = ['R']; break;
|
|
|
|
case 'delegated':
|
|
|
|
status_to_show = ['D']; break;
|
|
|
|
case 'all':
|
|
|
|
status_to_show = ['U','A','T','D','G','R']; break;
|
|
|
|
default:
|
|
|
|
status_to_show = ['U','A','T','D','G']; break;
|
|
|
|
}
|
2015-11-10 01:56:31 +01:00
|
|
|
var participants = event.participants;
|
|
|
|
var add_row = function(user, participant) {
|
2015-08-12 00:30:50 +02:00
|
|
|
var label_index = false;
|
|
|
|
for(var i = 0; i < labels.length; i++)
|
|
|
|
{
|
|
|
|
if(labels[i].id == user)
|
|
|
|
{
|
|
|
|
label_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(participant && label_index !== false && status_to_show.indexOf(participant.substr(0,1)) >= 0 ||
|
2015-06-25 19:44:28 +02:00
|
|
|
this.options.filter === 'owner' && event.owner === user)
|
|
|
|
{
|
2015-08-12 00:30:50 +02:00
|
|
|
if(typeof rows[label_index] === 'undefined')
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-08-12 00:30:50 +02:00
|
|
|
rows[label_index] = [];
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-08-12 00:30:50 +02:00
|
|
|
rows[label_index].push(event);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
};
|
2015-11-10 01:56:31 +01:00
|
|
|
for(var user in participants)
|
|
|
|
{
|
|
|
|
var participant = participants[user];
|
|
|
|
if (parseInt(user) < 0) // groups
|
|
|
|
{
|
2015-11-10 02:00:44 +01:00
|
|
|
var planner = this;
|
2015-11-10 01:56:31 +01:00
|
|
|
egw.accountData(user,'account_fullname',true,function(result) {
|
|
|
|
for(var id in result)
|
|
|
|
{
|
2015-11-10 02:00:44 +01:00
|
|
|
if(!participants[id]) add_row.call(planner,id,participant);
|
2015-11-10 01:56:31 +01:00
|
|
|
}
|
|
|
|
},labels);
|
|
|
|
continue;
|
|
|
|
}
|
2015-11-10 02:00:44 +01:00
|
|
|
add_row.call(this, user, participant);
|
2015-11-10 01:56:31 +01:00
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
// Draw a single row
|
|
|
|
draw_row: function(sort_key, label, events) {
|
2015-12-16 23:54:00 +01:00
|
|
|
if(['user','both'].indexOf(egw.preference('planner_show_empty_rows','calendar')) !== -1 || events.length)
|
|
|
|
{
|
|
|
|
return this._drawRow(sort_key, label,events,this.options.start_date, this.options.end_date);
|
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Group by month has one row for each month
|
|
|
|
month:
|
|
|
|
{
|
|
|
|
title: function() { return this.egw().lang('Month');},
|
|
|
|
headers: function() {
|
|
|
|
this.headers.append(this._header_day_of_month());
|
|
|
|
},
|
|
|
|
row_labels: function() {
|
2015-08-12 00:30:50 +02:00
|
|
|
var labels = [];
|
2015-06-25 19:44:28 +02:00
|
|
|
var d = new Date(this.options.start_date);
|
|
|
|
d = new Date(d.valueOf() + d.getTimezoneOffset() * 60 * 1000);
|
|
|
|
for(var i = 0; i < 12; i++)
|
|
|
|
{
|
2015-08-19 18:17:55 +02:00
|
|
|
// Not using UTC because we corrected for timezone offset
|
2016-03-18 16:49:11 +01:00
|
|
|
labels.push({id: d.getFullYear() +'-'+d.getMonth(), label:this.egw().lang(date('F',d))+' '+d.getFullYear()});
|
2015-08-19 18:17:55 +02:00
|
|
|
d.setMonth(d.getMonth()+1);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
return labels;
|
|
|
|
},
|
|
|
|
group: function(labels, rows,event) {
|
2015-11-23 23:06:31 +01:00
|
|
|
// Yearly planner does not show infologs
|
|
|
|
if(event && event.app && event.app == 'infolog') return;
|
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
var start = new Date(event.start);
|
2015-08-19 18:17:55 +02:00
|
|
|
start = new Date(start.valueOf() + start.getTimezoneOffset() * 60 * 1000);
|
|
|
|
var key = start.getFullYear() +'-'+start.getMonth();
|
2015-08-12 00:30:50 +02:00
|
|
|
var label_index = false;
|
|
|
|
for(var i = 0; i < labels.length; i++)
|
|
|
|
{
|
|
|
|
if(labels[i].id == key)
|
|
|
|
{
|
|
|
|
label_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(typeof rows[label_index] === 'undefined')
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-08-12 00:30:50 +02:00
|
|
|
rows[label_index] = [];
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-08-12 00:30:50 +02:00
|
|
|
rows[label_index].push(event);
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
// end in a different month?
|
|
|
|
var end = new Date(event.end);
|
2015-08-19 18:17:55 +02:00
|
|
|
end = new Date(end.valueOf() + end.getTimezoneOffset() * 60 * 1000);
|
|
|
|
var end_key = end.getFullYear() +'-'+end.getMonth();
|
2015-11-14 01:09:45 +01:00
|
|
|
var year = start.getFullYear();
|
|
|
|
var month = start.getMonth();
|
2015-06-25 19:44:28 +02:00
|
|
|
while(key !== end_key)
|
|
|
|
{
|
2015-11-14 01:09:45 +01:00
|
|
|
if (++month > 11)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
++year;
|
2015-11-14 01:09:45 +01:00
|
|
|
month = 0;
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-11-14 01:09:45 +01:00
|
|
|
key = sprintf('%04d-%d',year,month);
|
2015-08-12 00:30:50 +02:00
|
|
|
for(var i = 0; i < labels.length; i++)
|
|
|
|
{
|
|
|
|
if(labels[i].id == key)
|
|
|
|
{
|
|
|
|
label_index = i;
|
2015-10-06 01:45:51 +02:00
|
|
|
if(typeof rows[label_index] === 'undefined')
|
|
|
|
{
|
|
|
|
rows[label_index] = [];
|
|
|
|
}
|
2015-08-12 00:30:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rows[label_index].push(event);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Draw a single row, but split up the dates
|
|
|
|
draw_row: function(sort_key, label, events)
|
|
|
|
{
|
|
|
|
var key = sort_key.split('-');
|
2015-11-06 23:57:27 +01:00
|
|
|
this._drawRow(
|
|
|
|
sort_key, label, events,
|
|
|
|
new Date(key[0]+"-"+sprintf("%02d",parseInt(key[1])+1)+"-01T00:00:00Z"),
|
|
|
|
new Date(key[0],parseInt(key[1])+1,0)
|
|
|
|
);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// Group by category has one row for each [sub]category
|
|
|
|
category:
|
|
|
|
{
|
|
|
|
title: function() { return this.egw().lang('Category');},
|
|
|
|
headers: function() {
|
|
|
|
var start = new Date(this.options.start_date);
|
|
|
|
var end = new Date(this.options.end_date);
|
|
|
|
var start_date = new Date(start.getUTCFullYear(), start.getUTCMonth(),start.getUTCDate());
|
|
|
|
var end_date = new Date(end.getUTCFullYear(), end.getUTCMonth(),end.getUTCDate());
|
|
|
|
var day_count = Math.round((end_date - start_date) /(1000*3600*24))+1;
|
|
|
|
|
2016-01-22 00:07:29 +01:00
|
|
|
if(day_count >= 6)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
this.headers.append(this._header_months(start, day_count));
|
|
|
|
}
|
2016-01-22 00:07:29 +01:00
|
|
|
if(day_count < 120)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2016-01-22 00:07:29 +01:00
|
|
|
var weeks = this._header_weeks(start, day_count);
|
|
|
|
this.headers.append(weeks);
|
|
|
|
this.grid.append(weeks);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-09-09 22:59:23 +02:00
|
|
|
if(day_count < 60)
|
|
|
|
{
|
2016-01-22 00:07:29 +01:00
|
|
|
var days = this._header_days(start, day_count);
|
|
|
|
this.headers.append(days);
|
|
|
|
this.grid.append(days);
|
2015-09-09 22:59:23 +02:00
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
if(day_count <= 7)
|
|
|
|
{
|
2016-01-22 00:07:29 +01:00
|
|
|
var hours = this._header_hours(start, day_count);
|
|
|
|
this.headers.append(hours);
|
|
|
|
this.grid.append(hours);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
row_labels: function() {
|
2015-12-16 23:54:00 +01:00
|
|
|
var im = this.getInstanceManager();
|
|
|
|
var categories = et2_selectbox.cat_options({
|
|
|
|
_type:'select-cat',
|
|
|
|
getInstanceManager: function() {return im;}
|
|
|
|
},{application: 'calendar'});
|
|
|
|
|
|
|
|
var labels = [];
|
2016-02-04 17:25:20 +01:00
|
|
|
if(!app.calendar.state.cat_id ||
|
|
|
|
app.calendar.state.cat_id.toString() === '' ||
|
|
|
|
app.calendar.state.cat_id.toString() == '0'
|
|
|
|
)
|
2015-12-16 23:54:00 +01:00
|
|
|
{
|
2015-12-17 23:24:28 +01:00
|
|
|
app.calendar.state.cat_id = '';
|
|
|
|
labels.push({id:'',value:'',label: egw.lang('none'), main: '', data: {}});
|
2015-12-16 23:54:00 +01:00
|
|
|
labels = labels.concat(categories);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var cat_id = app.calendar.state.cat_id;
|
|
|
|
if(typeof cat_id == 'string')
|
|
|
|
{
|
|
|
|
cat_id = cat_id.split(',');
|
|
|
|
}
|
|
|
|
for(var i = 0; i < cat_id.length; i++)
|
|
|
|
{
|
|
|
|
// Find label for that category
|
|
|
|
for(var j = 0; j < categories.length; j++)
|
|
|
|
{
|
|
|
|
if(categories[j].value == cat_id[i])
|
|
|
|
{
|
|
|
|
categories[j].id = categories[j].value;
|
|
|
|
labels.push(categories[j]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-12-22 22:35:08 +01:00
|
|
|
// Get its children immediately
|
|
|
|
egw.json(
|
|
|
|
this.getInstanceManager().app+'.etemplate_widget_menupopup.ajax_get_options.etemplate',
|
|
|
|
['select-cat',',,,calendar,'+cat_id[i]],
|
2015-12-29 17:01:27 +01:00
|
|
|
function(data) {
|
|
|
|
labels = labels.concat(data);
|
|
|
|
}
|
2015-12-22 22:35:08 +01:00
|
|
|
).sendRequest(false);
|
2015-12-16 23:54:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var i = labels.length -1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
labels[i].id = labels[i].value;
|
2015-12-18 00:13:26 +01:00
|
|
|
labels[i].data = {
|
|
|
|
cat_id: labels[i].id,
|
|
|
|
main: labels[i].value==labels[i].main
|
|
|
|
};
|
2015-12-29 17:01:27 +01:00
|
|
|
if(labels[i].children && labels[i].children.length)
|
|
|
|
{
|
|
|
|
labels[i].data.has_children = true;
|
|
|
|
}
|
2015-12-16 23:54:00 +01:00
|
|
|
}
|
|
|
|
return labels;
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
group: function(labels, rows, event) {
|
2015-11-10 00:06:17 +01:00
|
|
|
var cats = event.category;
|
|
|
|
if(typeof event.category === 'string')
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-11-10 00:06:17 +01:00
|
|
|
cats = cats.split(',');
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-11-10 00:06:17 +01:00
|
|
|
for(var cat = 0; cat < cats.length; cat++)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-11-10 00:06:17 +01:00
|
|
|
var label_index = false;
|
2015-12-16 23:54:00 +01:00
|
|
|
var category = cats[cat] ? parseInt(cats[cat],10) : false;
|
|
|
|
if(category == 0 || !category) category = '';
|
2015-11-10 00:06:17 +01:00
|
|
|
for(var i = 0; i < labels.length; i++)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-11-10 00:06:17 +01:00
|
|
|
if(labels[i].id == category)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-12-16 23:54:00 +01:00
|
|
|
// If there's no cat filter, only show the top level
|
|
|
|
if(!app.calendar.state.cat_id)
|
2015-11-10 00:06:17 +01:00
|
|
|
{
|
2015-12-16 23:54:00 +01:00
|
|
|
for(var j = 0; j < labels.length; j++)
|
|
|
|
{
|
|
|
|
if(labels[j].id == labels[i].main)
|
|
|
|
{
|
|
|
|
label_index = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 00:06:17 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-12-16 23:54:00 +01:00
|
|
|
label_index = i;
|
|
|
|
break;
|
2015-11-10 00:06:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(typeof rows[label_index] === 'undefined')
|
|
|
|
{
|
|
|
|
rows[label_index] = [];
|
|
|
|
}
|
2015-12-16 23:54:00 +01:00
|
|
|
if(rows[label_index].indexOf(event) === -1)
|
|
|
|
{
|
|
|
|
rows[label_index].push(event);
|
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
draw_row: function(sort_key, label, events) {
|
2015-12-16 23:54:00 +01:00
|
|
|
if(['cat','both'].indexOf(egw.preference('planner_show_empty_rows','calendar')) !== -1 || events.length)
|
|
|
|
{
|
|
|
|
return this._drawRow(sort_key, label,events,this.options.start_date, this.options.end_date);
|
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Something changed, and the planner needs to be re-drawn. We wait a bit to
|
|
|
|
* avoid re-drawing twice if start and end date both changed, then recreate.
|
|
|
|
*
|
2016-03-01 17:27:45 +01:00
|
|
|
* @param {boolean} trigger =false Trigger an event once things are done.
|
2015-06-25 19:44:28 +02:00
|
|
|
* Waiting until invalidate completes prevents 2 updates when changing the date range.
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
invalidate: function(trigger) {
|
|
|
|
|
2015-08-26 01:30:32 +02:00
|
|
|
// Busy
|
2015-12-29 23:12:30 +01:00
|
|
|
if(!this.doInvalidate) return;
|
2015-08-26 01:30:32 +02:00
|
|
|
|
2016-01-26 23:17:51 +01:00
|
|
|
// Not yet ready
|
|
|
|
if(!this.options.start_date || !this.options.end_date) return;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Wait a bit to see if anything else changes, then re-draw the days
|
2015-08-26 01:30:32 +02:00
|
|
|
if(this.update_timer !== null)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-08-26 01:30:32 +02:00
|
|
|
window.clearTimeout(this.update_timer);
|
|
|
|
}
|
|
|
|
this.update_timer = window.setTimeout(jQuery.proxy(function() {
|
2016-01-05 21:43:19 +01:00
|
|
|
this.widget.doInvalidate = false;
|
2015-06-25 19:44:28 +02:00
|
|
|
|
2015-08-26 01:30:32 +02:00
|
|
|
// Show AJAX loader
|
2016-01-05 21:43:19 +01:00
|
|
|
this.widget.loader.show();
|
|
|
|
|
|
|
|
this.widget.value = this.widget._fetch_data();
|
2015-06-25 19:44:28 +02:00
|
|
|
|
2015-08-26 01:30:32 +02:00
|
|
|
this.widget._drawGrid();
|
|
|
|
|
|
|
|
// Update actions
|
2016-01-05 21:43:19 +01:00
|
|
|
if(this.widget._actionManager)
|
2015-08-26 01:30:32 +02:00
|
|
|
{
|
2016-01-05 21:43:19 +01:00
|
|
|
this.widget._link_actions(this.widget._actionManager.children);
|
2015-08-26 01:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(this.trigger)
|
|
|
|
{
|
|
|
|
this.widget.change();
|
|
|
|
}
|
|
|
|
this.widget.update_timer = null;
|
2016-01-05 21:43:19 +01:00
|
|
|
this.widget.doInvalidate = true;
|
|
|
|
|
2016-05-27 22:57:31 +02:00
|
|
|
window.setTimeout(jQuery.proxy(function() {if(this.loader) this.loader.hide();},this.widget),500);
|
2015-08-26 01:30:32 +02:00
|
|
|
},{widget:this,"trigger":trigger}),ET2_GRID_INVALIDATE_TIMEOUT);
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
detachFromDOM: function() {
|
|
|
|
// Remove the binding to the change handler
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.div).off("change.et2_calendar_timegrid");
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
attachToDOM: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Add the binding for the event change handler
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.div).on("change.et2_calendar_timegrid", '.calendar_calEvent', this, function(e) {
|
2015-06-25 19:44:28 +02:00
|
|
|
// Make sure function gets a reference to the widget
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
if(args.indexOf(this) == -1) args.push(this);
|
|
|
|
|
|
|
|
return e.data.event_change.apply(e.data, args);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add the binding for the change handler
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.div).on("change.et2_calendar_timegrid", '*:not(.calendar_calEvent)', this, function(e) {
|
2015-06-25 19:44:28 +02:00
|
|
|
return e.data.change.call(e.data, e, this);
|
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getDOMNode: function(_sender)
|
|
|
|
{
|
|
|
|
if(_sender === this || !_sender)
|
|
|
|
{
|
|
|
|
return this.div[0];
|
|
|
|
}
|
|
|
|
if(_sender._parent === this)
|
|
|
|
{
|
|
|
|
return this.rows[0];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates all the DOM nodes for the planner grid
|
|
|
|
*
|
|
|
|
* Any existing nodes (& children) are removed, the headers & labels are
|
|
|
|
* determined according to the current group_by value, and then the rows
|
|
|
|
* are created.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @private
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
_drawGrid: function()
|
|
|
|
{
|
|
|
|
|
|
|
|
this.div.css('height', this.options.height);
|
|
|
|
|
|
|
|
// Clear old events
|
|
|
|
var delete_index = this._children.length - 1;
|
|
|
|
while(this._children.length > 0 && delete_index >= 0)
|
|
|
|
{
|
|
|
|
this._children[delete_index].free();
|
|
|
|
this.removeChild(this._children[delete_index--]);
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Clear old rows
|
2016-01-22 00:07:29 +01:00
|
|
|
this.rows.empty()
|
|
|
|
.append(this.grid);
|
|
|
|
this.grid.empty();
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
var grouper = this.groupers[isNaN(this.options.group_by) ? this.options.group_by : 'category'];
|
|
|
|
if(!grouper) return;
|
|
|
|
|
|
|
|
// Headers
|
|
|
|
this.headers.empty();
|
|
|
|
this.headerTitle.text(grouper.title.apply(this));
|
|
|
|
grouper.headers.apply(this);
|
2016-01-22 00:07:29 +01:00
|
|
|
this.grid.find('*').contents().filter(function(){
|
|
|
|
return this.nodeType === 3;
|
|
|
|
}).remove();
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Get the rows / labels
|
|
|
|
var labels = grouper.row_labels.call(this);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Group the events
|
|
|
|
var events = {};
|
|
|
|
for(var i = 0; i < this.value.length; i++)
|
|
|
|
{
|
|
|
|
grouper.group.call(this, labels, events, this.value[i]);
|
|
|
|
}
|
|
|
|
|
2015-10-27 20:08:33 +01:00
|
|
|
// Set height for rows
|
2016-01-06 19:24:45 +01:00
|
|
|
this.rows.height(this.div.height() - this.headers.outerHeight());
|
2015-10-27 20:08:33 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Draw the rows
|
|
|
|
for(var key in labels)
|
|
|
|
{
|
2016-03-18 16:49:11 +01:00
|
|
|
if (!labels.hasOwnProperty(key)) continue;
|
2016-04-26 16:35:58 +02:00
|
|
|
|
2015-12-18 00:13:26 +01:00
|
|
|
// Skip sub-categories (events are merged into top level)
|
|
|
|
if(this.options.group_by == 'category' &&
|
|
|
|
(!app.calendar.state.cat_id || app.calendar.state.cat_id == '') &&
|
|
|
|
labels[key].id != labels[key].main
|
|
|
|
)
|
2015-12-17 23:43:22 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-11-06 23:57:27 +01:00
|
|
|
var row = grouper.draw_row.call(this,labels[key].id, labels[key].label, events[key] || []);
|
|
|
|
|
|
|
|
// Add extra data for clicking on row
|
2015-12-16 23:54:00 +01:00
|
|
|
if(row)
|
2015-11-06 23:57:27 +01:00
|
|
|
{
|
2015-12-16 23:54:00 +01:00
|
|
|
for(var extra in labels[key].data)
|
|
|
|
{
|
|
|
|
row.getDOMNode().dataset[extra] = labels[key].data[extra];
|
|
|
|
}
|
2015-11-06 23:57:27 +01:00
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
|
2015-10-27 20:08:33 +01:00
|
|
|
// Adjust header if there's a scrollbar
|
2016-01-22 00:07:29 +01:00
|
|
|
if(this.rows.children().last().length)
|
2015-12-22 21:07:40 +01:00
|
|
|
{
|
2016-01-22 00:07:29 +01:00
|
|
|
this.gridHeader.css('margin-right', (this.rows.width() - this.rows.children().last().width()) + 'px');
|
2015-12-22 21:07:40 +01:00
|
|
|
}
|
2015-08-26 01:30:32 +02:00
|
|
|
this.value = [];
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a single row of the planner
|
|
|
|
*
|
|
|
|
* @param {string} key Index into the grouped labels & events
|
|
|
|
* @param {string} label
|
|
|
|
* @param {Array} events
|
|
|
|
* @param {Date} start
|
|
|
|
* @param {Date} end
|
|
|
|
*/
|
|
|
|
_drawRow: function(key, label, events, start, end)
|
|
|
|
{
|
|
|
|
var row = et2_createWidget('calendar-planner_row',{
|
2015-12-29 00:33:29 +01:00
|
|
|
id: 'planner_row_'+key,
|
2015-06-25 19:44:28 +02:00
|
|
|
label: label,
|
|
|
|
start_date: start,
|
|
|
|
end_date: end,
|
2016-03-18 16:49:11 +01:00
|
|
|
value: events,
|
|
|
|
readonly: this.options.readonly
|
2015-06-25 19:44:28 +02:00
|
|
|
},this);
|
|
|
|
|
|
|
|
|
|
|
|
if(this.isInTree())
|
|
|
|
{
|
|
|
|
row.doLoadingFinished();
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Add actual events
|
|
|
|
row._update_events(events);
|
2015-11-06 23:57:27 +01:00
|
|
|
|
|
|
|
return row;
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
_header_day_of_month: function()
|
|
|
|
{
|
|
|
|
var day_width = 3.23; // 100.0 / 31;
|
|
|
|
|
|
|
|
// month scale with navigation
|
|
|
|
var content = '<div class="calendar_plannerScale">';
|
|
|
|
var start = new Date(this.options.start_date);
|
|
|
|
start = new Date(start.valueOf() + start.getTimezoneOffset() * 60 * 1000);
|
|
|
|
var end = new Date(this.options.end_date);
|
|
|
|
end = new Date(end.valueOf() + end.getTimezoneOffset() * 60 * 1000);
|
|
|
|
|
2016-03-18 16:49:11 +01:00
|
|
|
var title = this.egw().lang(date('F',start))+' '+date('Y',start)+' - '+
|
|
|
|
this.egw().lang(date('F',end))+' '+date('Y',end);
|
2015-06-25 19:44:28 +02:00
|
|
|
|
2015-09-21 17:41:56 +02:00
|
|
|
content += '<div class="calendar_plannerMonthScale th et2_link" style="left: 0; width: 100%;">'+
|
2015-06-25 19:44:28 +02:00
|
|
|
title+"</div>";
|
|
|
|
content += "</div>"; // end of plannerScale
|
|
|
|
|
|
|
|
// day of month scale
|
|
|
|
content +='<div class="calendar_plannerScale">';
|
|
|
|
|
|
|
|
for(var left = 0, i = 0; i < 31; left += day_width,++i)
|
|
|
|
{
|
|
|
|
content += '<div class="calendar_plannerDayOfMonthScale " style="left: '+left+'%; width: '+day_width+'%;">'+
|
|
|
|
(1+i)+"</div>\n";
|
|
|
|
}
|
|
|
|
content += "</div>\n";
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a header showing the months
|
|
|
|
* @param {Date} start
|
|
|
|
* @param {number} days
|
|
|
|
* @returns {string} HTML snippet
|
|
|
|
*/
|
|
|
|
_header_months: function(start, days)
|
|
|
|
{
|
2015-12-17 00:46:44 +01:00
|
|
|
var content = '<div class="calendar_plannerScale">';
|
2015-06-25 19:44:28 +02:00
|
|
|
var days_in_month = 0;
|
|
|
|
var day_width = 100 / days;
|
2015-12-15 00:46:45 +01:00
|
|
|
var end = new Date(start);
|
|
|
|
end.setUTCDate(end.getUTCDate()+days);
|
2015-09-14 22:47:25 +02:00
|
|
|
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)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-09-14 22:47:25 +02:00
|
|
|
var u = new Date(t.getUTCFullYear(),t.getUTCMonth()+1,0,-t.getTimezoneOffset()/60);
|
2016-03-01 17:27:45 +01:00
|
|
|
days_in_month = 1+ ((u-t) / (24*3600*1000));
|
2015-09-14 22:47:25 +02:00
|
|
|
|
2015-12-17 00:46:44 +01:00
|
|
|
var first = new Date(t.getUTCFullYear(),t.getUTCMonth(),1,-t.getTimezoneOffset()/60);
|
2015-09-14 22:47:25 +02:00
|
|
|
if(days_in_month <= 0) break;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
if (i + days_in_month > days)
|
|
|
|
{
|
|
|
|
days_in_month = days - i;
|
|
|
|
}
|
2016-03-18 16:49:11 +01:00
|
|
|
var title = this.egw().lang(date('F',new Date(t.valueOf() + t.getTimezoneOffset() * 60 * 1000)));
|
2015-06-25 19:44:28 +02:00
|
|
|
if (days_in_month > 10)
|
|
|
|
{
|
|
|
|
title += ' '+t.getUTCFullYear();
|
|
|
|
}
|
2016-01-22 00:07:29 +01:00
|
|
|
else if (days_in_month < 5)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
title = ' ';
|
|
|
|
}
|
2016-02-03 19:27:52 +01:00
|
|
|
content += '<div class="calendar_plannerMonthScale et2_clickable et2_link" data-date="'+first.toJSON()+ '" data-planner_view="month' +
|
2015-12-17 00:46:44 +01:00
|
|
|
'" style="left: '+left+'%; width: '+(day_width*days_in_month)+'%;">'+
|
2015-06-25 19:44:28 +02:00
|
|
|
title+"</div>";
|
|
|
|
}
|
|
|
|
content += "</div>"; // end of plannerScale
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a header showing the week numbers
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-06-25 19:44:28 +02:00
|
|
|
* @param {Date} start
|
|
|
|
* @param {number} days
|
|
|
|
* @returns {string} HTML snippet
|
|
|
|
*/
|
|
|
|
_header_weeks: function(start, days)
|
|
|
|
{
|
|
|
|
|
2016-02-03 19:27:52 +01:00
|
|
|
var content = '<div class="calendar_plannerScale" data-planner_view="week">';
|
2016-03-01 17:27:45 +01:00
|
|
|
var state = '';
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
// we're not using UTC so date() formatting function works
|
2015-12-21 19:14:33 +01:00
|
|
|
var t = new Date(start.valueOf());
|
2015-12-17 23:24:28 +01:00
|
|
|
|
|
|
|
// Make sure we're lining up on the week
|
|
|
|
var week_end = app.calendar.date.end_of_week(start);
|
2015-12-21 19:14:33 +01:00
|
|
|
var days_in_week = Math.floor(((week_end-start ) / (24*3600*1000))+1);
|
2015-12-17 23:24:28 +01:00
|
|
|
var week_width = 100 / days * (days <= 7 ? days : days_in_week);
|
2015-12-18 00:28:47 +01:00
|
|
|
for(var left = 0,i = 0; i < days; t.setUTCDate(t.getUTCDate() + 7),left += week_width)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-12-17 23:24:28 +01:00
|
|
|
// Avoid overflow at the end
|
|
|
|
if(days - i < 7)
|
|
|
|
{
|
2015-12-18 00:38:16 +01:00
|
|
|
days_in_week = days-i;
|
2015-12-17 23:24:28 +01:00
|
|
|
}
|
2015-12-21 19:14:33 +01:00
|
|
|
var usertime = new Date(t.valueOf());
|
|
|
|
if(start.getTimezoneOffset() < 0)
|
|
|
|
{
|
|
|
|
// Gets the right week # east of GMT. West does not need it(?)
|
|
|
|
usertime.setUTCMinutes(usertime.getUTCMinutes() - start.getTimezoneOffset());
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-12-17 23:24:28 +01:00
|
|
|
week_width = 100 / days * Math.min(days, days_in_week);
|
2015-06-25 19:44:28 +02:00
|
|
|
|
2016-03-18 16:49:11 +01:00
|
|
|
var title = this.egw().lang('Week')+' '+app.calendar.date.week_number(usertime);
|
2015-12-21 19:14:33 +01:00
|
|
|
|
|
|
|
if(start.getTimezoneOffset() > 0)
|
|
|
|
{
|
|
|
|
// Gets the right week start west of GMT
|
2016-03-01 17:27:45 +01:00
|
|
|
usertime.setUTCMinutes(usertime.getUTCMinutes() +start.getTimezoneOffset());
|
2015-12-21 19:14:33 +01:00
|
|
|
}
|
|
|
|
state = app.calendar.date.start_of_week(usertime);
|
|
|
|
state.setUTCHours(0);
|
|
|
|
state.setUTCMinutes(0);
|
|
|
|
state = state.toJSON();
|
2015-12-22 21:07:40 +01:00
|
|
|
|
2016-01-22 00:07:29 +01:00
|
|
|
if(days_in_week > 1 || days == 1)
|
2015-12-17 23:24:28 +01:00
|
|
|
{
|
|
|
|
content += '<div class="calendar_plannerWeekScale et2_clickable et2_link" data-date=\'' + state + '\' style="left: '+left+'%; width: '+week_width+'%;">'+title+"</div>";
|
|
|
|
}
|
2015-12-18 00:28:47 +01:00
|
|
|
i+= days_in_week;
|
2015-12-17 23:24:28 +01:00
|
|
|
if(days_in_week != 7)
|
|
|
|
{
|
2015-12-21 19:14:33 +01:00
|
|
|
t.setUTCDate(t.getUTCDate() - (7 - days_in_week));
|
2015-12-17 23:24:28 +01:00
|
|
|
days_in_week = 7;
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
content += "</div>"; // end of plannerScale
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a header for some days
|
|
|
|
*
|
|
|
|
* @param {Date} start
|
|
|
|
* @param {number} days
|
|
|
|
* @returns {string} HTML snippet
|
|
|
|
*/
|
|
|
|
_header_days: function(start, days)
|
|
|
|
{
|
|
|
|
var day_width = 100 / days;
|
2016-02-03 19:27:52 +01:00
|
|
|
var content = '<div class="calendar_plannerScale'+(days > 3 ? 'Day' : '')+'" data-planner_view="day" >';
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
// 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()+1),left += day_width,++i)
|
|
|
|
{
|
2016-04-19 22:27:09 +02:00
|
|
|
if(!this.options.show_weekend && [0,6].indexOf(t.getDay()) !== -1 ) continue;
|
2015-06-25 19:44:28 +02:00
|
|
|
var holidays = [];
|
2015-12-17 00:06:42 +01:00
|
|
|
var tempDate = new Date(t);
|
|
|
|
tempDate.setMinutes(tempDate.getMinutes()-start.getTimezoneOffset());
|
|
|
|
var day_class = this.day_class_holiday(tempDate,holidays);
|
2015-06-25 19:44:28 +02:00
|
|
|
var title = '';
|
|
|
|
var state = '';
|
|
|
|
|
|
|
|
if (days <= 3)
|
|
|
|
{
|
2016-03-18 16:49:11 +01:00
|
|
|
title = this.egw().lang(date('l',t))+', '+date('j',t)+'. '+this.egw().lang(date('F',t));
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
else if (days <= 7)
|
|
|
|
{
|
2016-03-18 16:49:11 +01:00
|
|
|
title = this.egw().lang(date('l',t))+' '+date('j',t);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-18 16:49:11 +01:00
|
|
|
title = this.egw().lang(date('D',t)).substr(0,2)+'<br />'+date('j',t);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
state = new Date(t.valueOf() - start.getTimezoneOffset() * 60 * 1000).toJSON();
|
2015-12-22 21:07:40 +01:00
|
|
|
|
2015-09-21 17:41:56 +02:00
|
|
|
content += '<div class="calendar_plannerDayScale et2_clickable et2_link '+ day_class+
|
2016-04-19 22:27:09 +02:00
|
|
|
'" data-date=\'' + state +'\''+
|
2015-06-25 19:44:28 +02:00
|
|
|
(holidays ? ' title="'+holidays.join(',')+'"' : '')+'>'+title+"</div>\n";
|
|
|
|
}
|
|
|
|
content += "</div>"; // end of plannerScale
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a header with hours
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-06-25 19:44:28 +02:00
|
|
|
* @param {Date} start
|
|
|
|
* @param {number} days
|
|
|
|
* @returns {string} HTML snippet for the header
|
|
|
|
*/
|
|
|
|
_header_hours: function(start,days)
|
|
|
|
{
|
|
|
|
var divisors = [1,2,3,4,6,8,12];
|
|
|
|
var decr = 1;
|
|
|
|
for(var i = 0; i < divisors.length; i++) // numbers dividing 24 without rest
|
|
|
|
{
|
|
|
|
if (divisors[i] > days) break;
|
|
|
|
decr = divisors[i];
|
|
|
|
}
|
|
|
|
var hours = days * 24;
|
|
|
|
if (days === 1) // for a single day we calculate the hours of a days, to take into account daylight saving changes (23 or 25 hours)
|
|
|
|
{
|
2015-08-06 19:14:20 +02:00
|
|
|
var t = new Date(start.getUTCFullYear(),start.getUTCMonth(),start.getUTCDate(),-start.getTimezoneOffset()/60);
|
2015-06-25 19:44:28 +02:00
|
|
|
var s = new Date(start);
|
|
|
|
s.setUTCHours(23);
|
|
|
|
s.setUTCMinutes(59);
|
|
|
|
s.setUTCSeconds(59);
|
2015-07-15 18:29:10 +02:00
|
|
|
hours = Math.ceil((s.getTime() - t.getTime()) / 3600000);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
var cell_width = 100 / hours * decr;
|
|
|
|
|
2016-02-03 19:27:52 +01:00
|
|
|
var content = '<div class="calendar_plannerScale" data-planner_view="day">';
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// 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 < hours; left += cell_width,i += decr)
|
|
|
|
{
|
2016-04-19 22:27:09 +02:00
|
|
|
if(!this.options.show_weekend && [0,6].indexOf(t.getDay()) !== -1 ) continue;
|
2015-06-25 19:44:28 +02:00
|
|
|
var title = date(egw.preference('timeformat','calendar') == 12 ? 'ha' : 'H',t);
|
|
|
|
|
2015-09-21 17:41:56 +02:00
|
|
|
content += '<div class="calendar_plannerHourScale et2_link" data-date="' + t.toJSON() +'" style="left: '+left+'%; width: '+(cell_width)+'%;">'+title+"</div>";
|
2015-06-25 19:44:28 +02:00
|
|
|
t.setHours(t.getHours()+decr);
|
|
|
|
}
|
|
|
|
content += "</div>"; // end of plannerScale
|
|
|
|
|
|
|
|
return content;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies class for today, and any holidays for current day
|
|
|
|
*
|
|
|
|
* @param {Date} date
|
|
|
|
* @param {string[]} holiday_list Filled with a list of holidays for that day
|
|
|
|
*
|
|
|
|
* @return {string} CSS Classes for the day. calendar_calBirthday, calendar_calHoliday, calendar_calToday and calendar_weekend as appropriate
|
|
|
|
*/
|
|
|
|
day_class_holiday: function(date,holiday_list) {
|
|
|
|
|
|
|
|
if(!date) return '';
|
|
|
|
|
|
|
|
var day_class = '';
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Holidays and birthdays
|
2016-01-13 23:07:09 +01:00
|
|
|
var holidays = et2_calendar_view.get_holidays(this,date.getUTCFullYear());
|
2015-06-25 19:44:28 +02:00
|
|
|
|
2015-11-10 00:49:26 +01:00
|
|
|
// Pass a string rather than the date object, to make sure it doesn't get changed
|
|
|
|
this.date_helper.set_value(date.toJSON());
|
2015-06-25 19:44:28 +02:00
|
|
|
var date_key = ''+this.date_helper.get_year() + sprintf('%02d',this.date_helper.get_month()) + sprintf('%02d',this.date_helper.get_date());
|
|
|
|
if(holidays && holidays[date_key])
|
|
|
|
{
|
|
|
|
holidays = holidays[date_key];
|
|
|
|
for(var i = 0; i < holidays.length; i++)
|
|
|
|
{
|
|
|
|
if (typeof holidays[i]['birthyear'] !== 'undefined')
|
|
|
|
{
|
2015-11-06 23:57:27 +01:00
|
|
|
day_class += ' calendar_calBirthday ';
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
holiday_list.push(holidays[i]['name']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-06 23:57:27 +01:00
|
|
|
day_class += 'calendar_calHoliday ';
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
holiday_list.push(holidays[i]['name']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
holidays = holiday_list.join(',');
|
|
|
|
var today = new Date();
|
2015-11-10 00:49:26 +01:00
|
|
|
if(date_key === ''+today.getFullYear()+
|
|
|
|
sprintf("%02d",today.getMonth()+1)+
|
|
|
|
sprintf("%02d",today.getDate())
|
2015-06-25 19:44:28 +02:00
|
|
|
)
|
|
|
|
{
|
2015-11-06 23:57:27 +01:00
|
|
|
day_class += "calendar_calToday ";
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
if(date.getUTCDay() == 0 || date.getUTCDay() == 6)
|
|
|
|
{
|
2015-11-06 23:57:27 +01:00
|
|
|
day_class += "calendar_weekend ";
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
|
|
|
return day_class;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link the actions to the DOM nodes / widget bits.
|
|
|
|
*
|
|
|
|
* @todo This currently does nothing
|
|
|
|
* @param {object} actions {ID: {attributes..}+} map of egw action information
|
|
|
|
*/
|
|
|
|
_link_actions: function(actions)
|
|
|
|
{
|
2015-08-11 17:35:54 +02:00
|
|
|
if(!this._actionObject)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-08-11 17:35:54 +02:00
|
|
|
// Get the parent? Might be a grid row, might not. Either way, it is
|
|
|
|
// just a container with no valid actions
|
|
|
|
var objectManager = egw_getObjectManager(this.getInstanceManager().app,true,1);
|
|
|
|
objectManager = objectManager.getObjectById(this.getInstanceManager().uniqueId,2) || objectManager;
|
|
|
|
var parent = objectManager.getObjectById(this.id,3) || objectManager.getObjectById(this._parent.id,3) || objectManager;
|
|
|
|
if(!parent)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-08-11 17:35:54 +02:00
|
|
|
debugger;
|
2016-03-01 17:27:45 +01:00
|
|
|
egw.debug('error','No parent objectManager found');
|
2015-08-11 17:35:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var i = 0; i < parent.children.length; i++)
|
|
|
|
{
|
|
|
|
var parent_finder = jQuery('#'+this.div.id, parent.children[i].iface.doGetDOMNode());
|
|
|
|
if(parent_finder.length > 0)
|
|
|
|
{
|
|
|
|
parent = parent.children[i];
|
|
|
|
break;
|
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-08-05 23:24:07 +02:00
|
|
|
}
|
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
// This binds into the egw action system. Most user interactions (drag to move, resize)
|
|
|
|
// are handled internally using jQuery directly.
|
|
|
|
var widget_object = this._actionObject || parent.getObjectById(this.id);
|
|
|
|
|
|
|
|
var aoi = new et2_action_object_impl(this,this.getDOMNode());
|
|
|
|
|
|
|
|
aoi.doTriggerEvent = function(_event, _data) {
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
// Determine target node
|
|
|
|
var event = _data.event || false;
|
|
|
|
if(!event) return;
|
|
|
|
if(_data.ui.draggable.hasClass('rowNoEdit')) return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
We have to handle the drop in the normal event stream instead of waiting
|
|
|
|
for the egwAction system so we can get the helper, and destination
|
|
|
|
*/
|
|
|
|
if(event.type === 'drop')
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
this.getWidget()._event_drop.call(jQuery('.calendar_d-n-d_timeCounter',_data.ui.helper)[0],this.getWidget(),event, _data.ui);
|
2015-08-11 17:35:54 +02:00
|
|
|
}
|
|
|
|
var drag_listener = function(event, ui) {
|
2016-06-02 16:51:15 +02:00
|
|
|
aoi.getWidget()._drag_helper(jQuery('.calendar_d-n-d_timeCounter',ui.helper)[0],{
|
2015-08-11 17:35:54 +02:00
|
|
|
top:ui.position.top,
|
2016-06-02 16:51:15 +02:00
|
|
|
left: ui.position.left - jQuery(this).parent().offset().left
|
2015-08-11 17:35:54 +02:00
|
|
|
},0);
|
|
|
|
};
|
2016-06-02 16:51:15 +02:00
|
|
|
var time = jQuery('.calendar_d-n-d_timeCounter',_data.ui.helper);
|
2015-08-11 17:35:54 +02:00
|
|
|
switch(_event)
|
|
|
|
{
|
|
|
|
// Triggered once, when something is dragged into the timegrid's div
|
|
|
|
case EGW_AI_DRAG_OVER:
|
|
|
|
// Listen to the drag and update the helper with the time
|
|
|
|
// This part lets us drag between different timegrids
|
|
|
|
_data.ui.draggable.on('drag.et2_timegrid'+widget_object.id, drag_listener);
|
|
|
|
_data.ui.draggable.on('dragend.et2_timegrid'+widget_object.id, function() {
|
|
|
|
_data.ui.draggable.off('drag.et2_timegrid' + widget_object.id);
|
|
|
|
});
|
|
|
|
if(time.length)
|
|
|
|
{
|
|
|
|
// The out will trigger after the over, so we count
|
|
|
|
time.data('count',time.data('count')+1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_data.ui.helper.prepend('<div class="calendar_d-n-d_timeCounter" data-count="1"><span></span></div>');
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Triggered once, when something is dragged out of the timegrid
|
|
|
|
case EGW_AI_DRAG_OUT:
|
|
|
|
// Stop listening
|
|
|
|
_data.ui.draggable.off('drag.et2_timegrid'+widget_object.id);
|
|
|
|
// Remove any highlighted time squares
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('[data-date]',this.doGetDOMNode()).removeClass("ui-state-active");
|
2015-08-05 23:24:07 +02:00
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
// Out triggers after the over, count to not accidentally remove
|
|
|
|
time.data('count',time.data('count')-1);
|
|
|
|
if(time.length && time.data('count') <= 0)
|
|
|
|
{
|
|
|
|
time.remove();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (widget_object == null) {
|
|
|
|
// Add a new container to the object manager which will hold the widget
|
|
|
|
// objects
|
|
|
|
widget_object = parent.insertObject(false, new egwActionObject(
|
|
|
|
this.id, parent, aoi,
|
|
|
|
this._actionManager || parent.manager.getActionById(this.id) || parent.manager
|
|
|
|
),EGW_AO_FLAG_IS_CONTAINER);
|
|
|
|
}
|
|
|
|
else
|
2015-08-05 23:24:07 +02:00
|
|
|
{
|
2015-08-11 17:35:54 +02:00
|
|
|
widget_object.setAOI(aoi);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-08-05 23:24:07 +02:00
|
|
|
// Go over the widget & add links - this is where we decide which actions are
|
|
|
|
// 'allowed' for this widget at this time
|
|
|
|
var action_links = this._get_action_links(actions);
|
|
|
|
|
|
|
|
this._init_links_dnd(widget_object.manager, action_links);
|
|
|
|
|
|
|
|
widget_object.updateActionLinks(action_links);
|
|
|
|
this._actionObject = widget_object;
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically add dnd support for linking
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
|
|
|
* @param {type} mgr
|
|
|
|
* @param {type} actionLinks
|
2015-06-25 19:44:28 +02:00
|
|
|
*/
|
|
|
|
_init_links_dnd: function(mgr,actionLinks) {
|
2016-05-02 21:22:52 +02:00
|
|
|
|
|
|
|
if (this.options.readonly) return;
|
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
var drop_action = mgr.getActionById('egw_link_drop');
|
|
|
|
var drag_action = mgr.getActionById('egw_link_drag');
|
|
|
|
|
|
|
|
// Check if this app supports linking
|
2015-08-05 23:24:07 +02:00
|
|
|
if(!egw.link_get_registry(this.dataStorePrefix || 'calendar', 'query') ||
|
|
|
|
egw.link_get_registry(this.dataStorePrefix || 'calendar', 'title'))
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
if(drop_action)
|
|
|
|
{
|
|
|
|
drop_action.remove();
|
|
|
|
if(actionLinks.indexOf(drop_action.id) >= 0)
|
|
|
|
{
|
|
|
|
actionLinks.splice(actionLinks.indexOf(drop_action.id),1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(drag_action)
|
|
|
|
{
|
|
|
|
drag_action.remove();
|
|
|
|
if(actionLinks.indexOf(drag_action.id) >= 0)
|
|
|
|
{
|
|
|
|
actionLinks.splice(actionLinks.indexOf(drag_action.id),1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't re-add
|
|
|
|
if(drop_action == null)
|
|
|
|
{
|
|
|
|
// Create the drop action that links entries
|
|
|
|
drop_action = mgr.addAction('drop', 'egw_link_drop', egw.lang('Create link'), egw.image('link'), function(action, source, dropped) {
|
|
|
|
// Extract link IDs
|
|
|
|
var links = [];
|
|
|
|
var id = '';
|
|
|
|
for(var i = 0; i < source.length; i++)
|
|
|
|
{
|
|
|
|
if(!source[i].id) continue;
|
|
|
|
id = source[i].id.split('::');
|
|
|
|
links.push({app: id[0] == 'filemanager' ? 'link' : id[0], id: id[1]});
|
|
|
|
}
|
|
|
|
if(!links.length)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-08-11 17:35:54 +02:00
|
|
|
if(links.length && dropped && dropped.iface.getWidget() && dropped.iface.getWidget().instanceOf(et2_calendar_event))
|
|
|
|
{
|
|
|
|
// Link the entries
|
|
|
|
egw.json(self.egw().getAppName()+".etemplate_widget_link.ajax_link.etemplate",
|
|
|
|
dropped.id.split('::').concat([links]),
|
|
|
|
function(result) {
|
|
|
|
if(result)
|
|
|
|
{
|
|
|
|
this.egw().message('Linked');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
self,
|
|
|
|
true,
|
|
|
|
self
|
|
|
|
).sendRequest();
|
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
},true);
|
|
|
|
}
|
|
|
|
if(actionLinks.indexOf(drop_action.id) < 0)
|
|
|
|
{
|
|
|
|
actionLinks.push(drop_action.id);
|
|
|
|
}
|
|
|
|
// Accept other links, and files dragged from the filemanager
|
|
|
|
// This does not handle files dragged from the desktop. They are
|
|
|
|
// handled by et2_nextmatch, since it needs DOM stuff
|
|
|
|
if(drop_action.acceptedTypes.indexOf('link') == -1)
|
|
|
|
{
|
|
|
|
drop_action.acceptedTypes.push('link');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't re-add
|
|
|
|
if(drag_action == null)
|
|
|
|
{
|
|
|
|
// Create drag action that allows linking
|
|
|
|
drag_action = mgr.addAction('drag', 'egw_link_drag', egw.lang('link'), 'link', function(action, selected) {
|
|
|
|
// As we wanted to have a general defaul helper interface, we return null here and not using customize helper for links
|
|
|
|
// TODO: Need to decide if we need to create a customized helper interface for links anyway
|
|
|
|
//return helper;
|
|
|
|
return null;
|
|
|
|
},true);
|
|
|
|
}
|
2015-08-12 00:30:50 +02:00
|
|
|
// The planner itself is not draggable, the action is there for the children
|
|
|
|
if(false && actionLinks.indexOf(drag_action.id) < 0)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
actionLinks.push(drag_action.id);
|
|
|
|
}
|
|
|
|
drag_action.set_dragType('link');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all action-links / id's of 1.-level actions from a given action object
|
|
|
|
*
|
|
|
|
* Here we are only interested in drop events.
|
|
|
|
*
|
|
|
|
* @param actions
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
|
|
|
_get_action_links: function(actions)
|
|
|
|
{
|
|
|
|
var action_links = [];
|
|
|
|
// TODO: determine which actions are allowed without an action (empty actions)
|
|
|
|
for(var i in actions)
|
|
|
|
{
|
|
|
|
var action = actions[i];
|
|
|
|
if(action.type === 'drop')
|
|
|
|
{
|
|
|
|
action_links.push(typeof action.id !== 'undefined' ? action.id : i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return action_links;
|
|
|
|
},
|
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
/**
|
|
|
|
* Show the current time while dragging
|
|
|
|
* Used for resizing as well as drag & drop
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
|
|
|
* @param {type} element
|
|
|
|
* @param {type} position
|
|
|
|
* @param {type} height
|
2015-08-11 17:35:54 +02:00
|
|
|
*/
|
|
|
|
_drag_helper: function(element, position ,height)
|
|
|
|
{
|
|
|
|
var time = this._get_time_from_position(position.left, position.top);
|
|
|
|
element.dropEnd = time;
|
|
|
|
var formatted_time = jQuery.datepicker.formatTime(
|
2015-11-17 21:19:47 +01:00
|
|
|
egw.preference("timeformat") === "12" ? "h:mmtt" : "HH:mm",
|
2015-08-11 17:35:54 +02:00
|
|
|
{
|
|
|
|
hour: time.getUTCHours(),
|
|
|
|
minute: time.getUTCMinutes(),
|
|
|
|
seconds: 0,
|
|
|
|
timezone: 0
|
|
|
|
},
|
2015-11-17 21:19:47 +01:00
|
|
|
{"ampm": (egw.preference("timeformat") === "12")}
|
2015-08-11 17:35:54 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
element.innerHTML = '<div class="calendar_d-n-d_timeCounter"><span class="calendar_timeDemo" >'+formatted_time+'</span></div>';
|
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
//jQuery(element).width(jQuery(helper).width());
|
2015-08-11 17:35:54 +02:00
|
|
|
},
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
/**
|
|
|
|
* Handler for dropping an event on the timegrid
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
|
|
|
* @param {type} planner
|
|
|
|
* @param {type} event
|
|
|
|
* @param {type} ui
|
2015-08-11 17:35:54 +02:00
|
|
|
*/
|
|
|
|
_event_drop: function(planner, event,ui) {
|
|
|
|
var e = new jQuery.Event('change');
|
|
|
|
e.originalEvent = event;
|
|
|
|
e.data = {start: 0};
|
|
|
|
if (typeof this.dropEnd != 'undefined')
|
|
|
|
{
|
|
|
|
var drop_date = this.dropEnd.toJSON() ||false;
|
|
|
|
|
|
|
|
var event_data = planner._get_event_info(ui.draggable);
|
2016-01-13 23:07:09 +01:00
|
|
|
var event_widget = planner.getWidgetById(event_data.widget_id);
|
2015-08-11 17:35:54 +02:00
|
|
|
if(event_widget)
|
|
|
|
{
|
|
|
|
event_widget._parent.date_helper.set_value(drop_date);
|
|
|
|
event_widget.options.value.start = new Date(event_widget._parent.date_helper.getValue());
|
|
|
|
|
|
|
|
// Leave the helper there until the update is done
|
|
|
|
var loading = ui.helper.clone().appendTo(ui.helper.parent());
|
|
|
|
// and add a loading icon so user knows something is happening
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_timeDemo',loading).after('<div class="loading"></div>');
|
2015-08-11 17:35:54 +02:00
|
|
|
|
|
|
|
event_widget.recur_prompt(function(button_id) {
|
|
|
|
if(button_id === 'cancel' || !button_id) return;
|
|
|
|
//Get infologID if in case if it's an integrated infolog event
|
|
|
|
if (event_data.app === 'infolog')
|
|
|
|
{
|
|
|
|
// If it is an integrated infolog event we need to edit infolog entry
|
|
|
|
egw().json('stylite_infolog_calendar_integration::ajax_moveInfologEvent',
|
|
|
|
[event_data.id, event_widget.options.value.start||false],
|
|
|
|
function() {loading.remove();}
|
|
|
|
).sendRequest(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Edit calendar event
|
|
|
|
egw().json('calendar.calendar_uiforms.ajax_moveEvent', [
|
|
|
|
button_id==='series' ? event_data.id : event_data.app_id,event_data.owner,
|
|
|
|
event_widget.options.value.start,
|
|
|
|
planner.options.owner||egw.user('account_id')
|
|
|
|
],
|
|
|
|
function() { loading.remove();}
|
|
|
|
).sendRequest(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
/**
|
|
|
|
* Use the egw.data system to get data from the calendar list for the
|
|
|
|
* selected time span.
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-06-25 19:44:28 +02:00
|
|
|
*/
|
|
|
|
_fetch_data: function()
|
|
|
|
{
|
2015-07-15 18:29:10 +02:00
|
|
|
var value = [];
|
2015-08-06 19:14:20 +02:00
|
|
|
var fetch = false;
|
2015-08-26 01:30:32 +02:00
|
|
|
this.doInvalidate = false;
|
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
for(var i = 0; i < this.registeredCallbacks.length; i++)
|
|
|
|
{
|
|
|
|
egw.dataUnregisterUID(this.registeredCallbacks[i],false,this);
|
|
|
|
}
|
|
|
|
this.registeredCallbacks.splice(0,this.registeredCallbacks.length);
|
|
|
|
|
2015-07-15 18:29:10 +02:00
|
|
|
// Remember previous day to avoid multi-days duplicating
|
|
|
|
var last_data = [];
|
|
|
|
|
|
|
|
var t = new Date(this.options.start_date);
|
|
|
|
var end = new Date(this.options.end_date);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Cache is by date (and owner, if seperate)
|
|
|
|
var date = t.getUTCFullYear() + sprintf('%02d',t.getUTCMonth()+1) + sprintf('%02d',t.getUTCDate());
|
2015-08-05 23:24:07 +02:00
|
|
|
var cache_id = app.classes.calendar._daywise_cache_id(date, this.options.owner);
|
2015-07-15 18:29:10 +02:00
|
|
|
|
|
|
|
if(egw.dataHasUID(cache_id))
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-07-15 18:29:10 +02:00
|
|
|
var c = egw.dataGetUIDdata(cache_id);
|
|
|
|
if(c.data && c.data !== null)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-07-15 18:29:10 +02:00
|
|
|
// There is data, pass it along now
|
|
|
|
for(var j = 0; j < c.data.length; j++)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2015-07-15 18:29:10 +02:00
|
|
|
if(last_data.indexOf(c.data[j]) === -1 && egw.dataHasUID('calendar::'+c.data[j]))
|
|
|
|
{
|
|
|
|
value.push(egw.dataGetUIDdata('calendar::'+c.data[j]).data);
|
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-10-27 20:08:33 +01:00
|
|
|
last_data = c.data;
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2015-07-15 18:29:10 +02:00
|
|
|
}
|
2015-08-06 19:14:20 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fetch = true;
|
2015-08-11 17:35:54 +02:00
|
|
|
// Assume it's empty, if there is data it will be filled later
|
|
|
|
egw.dataStoreUID(cache_id, []);
|
2015-08-06 19:14:20 +02:00
|
|
|
}
|
2015-08-11 17:35:54 +02:00
|
|
|
this.registeredCallbacks.push(cache_id);
|
|
|
|
egw.dataRegisterUID(cache_id, function(data) {
|
|
|
|
if(data && data.length)
|
|
|
|
{
|
2015-11-10 00:06:17 +01:00
|
|
|
// If displaying by category, we need the infolog (or other app) categories too
|
|
|
|
var im = this.getInstanceManager();
|
|
|
|
for(var i = 0; i < data.length && this.options.group_by == 'category'; i++)
|
|
|
|
{
|
|
|
|
var event = egw.dataGetUIDdata('calendar::'+data[i]);
|
|
|
|
if(event && event.data && event.data.app)
|
|
|
|
{
|
|
|
|
// Fake it to use the cache / call
|
|
|
|
et2_selectbox.cat_options({
|
|
|
|
_type:'select-cat',
|
|
|
|
getInstanceManager: function() {return im;}
|
|
|
|
}, {application:event.data.app||'calendar'});
|
|
|
|
|
|
|
|
// Get CSS too
|
2016-04-26 16:35:58 +02:00
|
|
|
egw.includeCSS('/api/categories.php?app='+event.data.app);
|
2015-11-10 00:06:17 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
this.invalidate(false);
|
|
|
|
}
|
|
|
|
}, this, this.getInstanceManager().execId,this.id);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-15 18:29:10 +02:00
|
|
|
t.setUTCDate(t.getUTCDate() + 1);
|
|
|
|
}
|
|
|
|
while(t < end);
|
2015-08-06 19:14:20 +02:00
|
|
|
// Need to get some more from the server
|
|
|
|
if(fetch && app.calendar)
|
|
|
|
{
|
|
|
|
app.calendar._fetch_data({
|
|
|
|
first: this.options.start_date,
|
|
|
|
last: this.options.end_date,
|
|
|
|
owner: this.options.owner,
|
|
|
|
filter: this.options.filter
|
|
|
|
}, this.getInstanceManager());
|
|
|
|
}
|
2015-08-26 01:30:32 +02:00
|
|
|
|
|
|
|
this.doInvalidate = true;
|
2015-07-15 18:29:10 +02:00
|
|
|
return value;
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide specific data to be displayed.
|
|
|
|
* This is a way to set start and end dates, owner and event data in once call.
|
|
|
|
*
|
|
|
|
* @param {Object[]} events Array of events, indexed by date in Ymd format:
|
|
|
|
* {
|
|
|
|
* 20150501: [...],
|
|
|
|
* 20150502: [...]
|
|
|
|
* }
|
|
|
|
* Days should be in order.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
set_value: function(events)
|
|
|
|
{
|
|
|
|
if(typeof events !== 'object') return false;
|
|
|
|
|
2016-01-13 23:07:09 +01:00
|
|
|
this._super.apply(this, arguments);
|
2015-06-25 19:44:28 +02:00
|
|
|
|
2016-01-26 00:47:58 +01:00
|
|
|
// Planner uses an array, not map
|
|
|
|
var val = this.value;
|
|
|
|
var array = [];
|
|
|
|
Object.keys(this.value).forEach(function (key) {
|
|
|
|
array.push(val[key]);
|
|
|
|
});
|
|
|
|
this.value = array;
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
|
|
|
|
2015-12-29 00:33:29 +01:00
|
|
|
/**
|
|
|
|
* Change the start date
|
|
|
|
* Planner view uses a date object internally
|
|
|
|
*
|
|
|
|
* @param {string|number|Date} new_date New starting date
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
set_start_date: function set_start_date(new_date)
|
|
|
|
{
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.options.start_date = new Date(this.options.start_date);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the end date
|
|
|
|
* Planner view uses a date object internally
|
|
|
|
*
|
|
|
|
* @param {string|number|Date} new_date New end date
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
set_end_date: function set_end_date(new_date)
|
|
|
|
{
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.options.end_date = new Date(this.options.end_date);
|
|
|
|
},
|
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
/**
|
|
|
|
* Change how the planner is grouped
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-06-25 19:44:28 +02:00
|
|
|
* @param {string|number} group_by 'user', 'month', or an integer category ID
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
set_group_by: function(group_by)
|
|
|
|
{
|
|
|
|
if(isNaN(group_by) && typeof this.groupers[group_by] === 'undefined')
|
|
|
|
{
|
|
|
|
throw new Error('Invalid group_by "'+group_by+'"');
|
|
|
|
}
|
|
|
|
var old = this.options.group_by;
|
|
|
|
this.options.group_by = ''+group_by;
|
|
|
|
|
|
|
|
if(old !== this.options.group_by && this.isAttached())
|
|
|
|
{
|
|
|
|
this.invalidate(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-19 22:27:09 +02:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-04-26 16:35:58 +02:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
/**
|
|
|
|
* Call change handler, if set
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
|
|
|
* @param {type} event
|
2015-06-25 19:44:28 +02:00
|
|
|
*/
|
|
|
|
change: function(event) {
|
|
|
|
if (this.onchange)
|
|
|
|
{
|
|
|
|
if(typeof this.onchange == 'function')
|
|
|
|
{
|
|
|
|
// Make sure function gets a reference to the widget
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
if(args.indexOf(this) == -1) args.push(this);
|
|
|
|
|
|
|
|
return this.onchange.apply(this, args);
|
|
|
|
} else {
|
|
|
|
return (et2_compileLegacyJS(this.options.onchange, this, _node))();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call event change handler, if set
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
|
|
|
* @param {type} event
|
|
|
|
* @param {type} dom_node
|
2015-06-25 19:44:28 +02:00
|
|
|
*/
|
|
|
|
event_change: function(event, dom_node) {
|
|
|
|
if (this.onevent_change)
|
|
|
|
{
|
|
|
|
var event_data = this._get_event_info(dom_node);
|
2016-01-19 19:03:42 +01:00
|
|
|
var event_widget = this.getWidgetById(event_data.widget_id);
|
2015-06-25 19:44:28 +02:00
|
|
|
et2_calendar_event.recur_prompt(event_data, jQuery.proxy(function(button_id, event_data) {
|
|
|
|
// No need to continue
|
|
|
|
if(button_id === 'cancel') return false;
|
|
|
|
|
|
|
|
if(typeof this.onevent_change == 'function')
|
|
|
|
{
|
|
|
|
// Make sure function gets a reference to the widget
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
|
|
|
|
if(args.indexOf(event_widget) == -1) args.push(event_widget);
|
|
|
|
|
|
|
|
// Put button ID in event
|
|
|
|
event.button_id = button_id;
|
|
|
|
|
|
|
|
return this.onevent_change.apply(this, [event, event_widget, button_id]);
|
|
|
|
} else {
|
|
|
|
return (et2_compileLegacyJS(this.options.onevent_change, event_widget, dom_node))();
|
|
|
|
}
|
|
|
|
},this));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click handler calling custom handler set via onclick attribute to this.onclick
|
|
|
|
*
|
|
|
|
* This also handles all its own actions, including navigation. If there is
|
|
|
|
* an event associated with the click, it will be found and passed to the
|
|
|
|
* onclick function.
|
|
|
|
*
|
|
|
|
* @param {Event} _ev
|
2016-01-13 23:07:09 +01:00
|
|
|
* @returns {boolean} Continue processing event (true) or stop (false)
|
2015-06-25 19:44:28 +02:00
|
|
|
*/
|
|
|
|
click: function(_ev)
|
|
|
|
{
|
|
|
|
var result = true;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
// Is this click in the event stuff, or in the header?
|
2016-06-02 16:51:15 +02:00
|
|
|
if(!this.options.readonly && this.gridHeader.has(_ev.target).length === 0 && !jQuery(_ev.target).hasClass('calendar_plannerRowHeader'))
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
// Event came from inside, maybe a calendar event
|
|
|
|
var event = this._get_event_info(_ev.originalEvent.target);
|
|
|
|
if(typeof this.onclick == 'function')
|
|
|
|
{
|
|
|
|
// Make sure function gets a reference to the widget, splice it in as 2. argument if not
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
if(args.indexOf(this) == -1) args.splice(1, 0, this);
|
|
|
|
|
|
|
|
result = this.onclick.apply(this, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(event.id && result && !this.options.disabled && !this.options.readonly)
|
|
|
|
{
|
|
|
|
et2_calendar_event.recur_prompt(event);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-06 23:57:27 +01:00
|
|
|
else if (!event.id)
|
|
|
|
{
|
|
|
|
// Clicked in row, but not on an event
|
|
|
|
// Default handler to open a new event at the selected time
|
|
|
|
if(this.options.group_by == 'month')
|
|
|
|
{
|
|
|
|
var date = this._get_time_from_position(_ev.clientX, _ev.clientY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var date = this._get_time_from_position(_ev.offsetX, _ev.offsetY);
|
|
|
|
}
|
2016-06-02 16:51:15 +02:00
|
|
|
var row = jQuery(_ev.target).closest('.calendar_plannerRowWidget');
|
2015-11-10 00:06:17 +01:00
|
|
|
var data = row.length ? row[0].dataset : {};
|
2015-11-06 23:57:27 +01:00
|
|
|
this.egw().open(null, 'calendar', 'add', jQuery.extend({
|
2015-11-17 18:59:23 +01:00
|
|
|
start: date.toJSON(),
|
2015-11-06 23:57:27 +01:00
|
|
|
hour: date.getUTCHours(),
|
|
|
|
minute: date.getUTCMinutes()
|
|
|
|
},data) , '_blank');
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-25 19:44:28 +02:00
|
|
|
return result;
|
|
|
|
}
|
2016-05-27 22:57:31 +02:00
|
|
|
else if (this.gridHeader.has(_ev.target).length > 0 && !jQuery.isEmptyObject(_ev.target.dataset) ||
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(_ev.target).hasClass('calendar_plannerRowHeader') && !jQuery.isEmptyObject(_ev.target.dataset))
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
// Click on a header, we can go there
|
|
|
|
_ev.data = jQuery.extend({},_ev.target.parentNode.dataset, _ev.target.dataset);
|
2015-11-10 00:49:26 +01:00
|
|
|
for(var key in _ev.data)
|
|
|
|
{
|
|
|
|
if(!_ev.data[key])
|
|
|
|
{
|
|
|
|
delete _ev.data[key];
|
|
|
|
}
|
|
|
|
}
|
2015-12-17 00:46:44 +01:00
|
|
|
app.calendar.update_state(_ev.data);
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2016-03-18 16:49:11 +01:00
|
|
|
else if (!this.options.readonly)
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
|
|
|
// Default handler to open a new event at the selected time
|
|
|
|
// TODO: Determine date / time more accurately from position
|
|
|
|
this.egw().open(null, 'calendar', 'add', {
|
2015-11-16 18:07:56 +01:00
|
|
|
date: _ev.target.dataset.date || this.options.start_date.toJSON(),
|
2015-06-25 19:44:28 +02:00
|
|
|
hour: _ev.target.dataset.hour || this.options.day_start,
|
|
|
|
minute: _ev.target.dataset.minute || 0
|
|
|
|
} , '_blank');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
/**
|
|
|
|
* Get time from position
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-06-25 19:44:28 +02:00
|
|
|
* @param {number} x
|
|
|
|
* @param {number} y
|
2016-01-13 23:07:09 +01:00
|
|
|
* @returns {Date|Boolean} A time for the given position, or false if one
|
|
|
|
* could not be determined.
|
2015-06-25 19:44:28 +02:00
|
|
|
*/
|
|
|
|
_get_time_from_position: function(x,y) {
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
x = Math.round(x);
|
|
|
|
y = Math.round(y);
|
2015-08-11 17:35:54 +02:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
var rel_x = Math.min(x / jQuery('.calendar_eventRows',this.div).width(),1);
|
2015-11-06 23:57:27 +01:00
|
|
|
var rel_time = 0;
|
2015-08-11 17:35:54 +02:00
|
|
|
|
2015-11-06 23:57:27 +01:00
|
|
|
// Simple math, the x is offset from start date
|
|
|
|
if(this.options.group_by !== 'month')
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Find the correct row so we know which month, then get the offset
|
2016-06-02 16:51:15 +02:00
|
|
|
var row = jQuery(document.elementFromPoint(x, y)).closest('.calendar_plannerRowWidget');
|
2015-11-06 23:57:27 +01:00
|
|
|
var row_widget = null;
|
|
|
|
for(var i = 0; i < this._children.length && row.length > 0; i++)
|
|
|
|
{
|
|
|
|
if(this._children[i].div[0] == row[0])
|
|
|
|
{
|
|
|
|
row_widget = this._children[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(row_widget)
|
|
|
|
{
|
|
|
|
rel_x = Math.min((x-row_widget.rows.offset().left)/row_widget.rows.width(),1);
|
|
|
|
rel_time = (new Date(row_widget.options.end_date) - new Date(row_widget.options.start_date))*rel_x/1000;
|
|
|
|
this.date_helper.set_value(row_widget.options.start_date.toJSON());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 00:06:17 +01:00
|
|
|
if(rel_time < 0) return false;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-08-11 17:35:54 +02:00
|
|
|
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());
|
2015-06-25 19:44:28 +02:00
|
|
|
},
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-25 19:44:28 +02:00
|
|
|
/**
|
|
|
|
* Code for implementing et2_IDetachedDOM
|
|
|
|
*
|
|
|
|
* @param {array} _attrs array to add further attributes to
|
|
|
|
*/
|
|
|
|
getDetachedAttributes: function(_attrs) {
|
|
|
|
_attrs.push('start_date','end_date');
|
|
|
|
},
|
|
|
|
|
|
|
|
getDetachedNodes: function() {
|
|
|
|
return [this.getDOMNode()];
|
|
|
|
},
|
|
|
|
|
|
|
|
setDetachedAttributes: function(_nodes, _values) {
|
2016-06-02 16:51:15 +02:00
|
|
|
this.div = jQuery(_nodes[0]);
|
2015-06-25 19:44:28 +02:00
|
|
|
|
|
|
|
if(_values.start_date)
|
|
|
|
{
|
|
|
|
this.set_start_date(_values.start_date);
|
|
|
|
}
|
|
|
|
if(_values.end_date)
|
|
|
|
{
|
|
|
|
this.set_end_date(_values.end_date);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Resizable interface
|
2016-01-06 19:24:45 +01:00
|
|
|
resize: function ()
|
2015-06-25 19:44:28 +02:00
|
|
|
{
|
2016-01-06 19:24:45 +01:00
|
|
|
// Take the whole tab height
|
2016-06-02 16:51:15 +02:00
|
|
|
var height = Math.min(jQuery(this.getInstanceManager().DOMContainer).height(),jQuery(this.getInstanceManager().DOMContainer).parent().innerHeight());
|
2016-01-06 19:24:45 +01:00
|
|
|
|
|
|
|
// Allow for toolbar
|
2016-06-02 16:51:15 +02:00
|
|
|
height -= jQuery('#calendar-toolbar',this.div.parents('.egw_fw_ui_tab_content')).outerHeight(true);
|
2016-01-26 23:17:51 +01:00
|
|
|
|
2016-01-06 19:24:45 +01:00
|
|
|
this.options.height = height;
|
2015-06-25 19:44:28 +02:00
|
|
|
this.div.css('height', this.options.height);
|
2016-01-15 21:51:12 +01:00
|
|
|
// Set height for rows
|
|
|
|
this.rows.height(this.div.height() - this.headers.outerHeight());
|
2015-06-25 19:44:28 +02:00
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
});}).call(this);
|
2015-06-25 19:44:28 +02:00
|
|
|
et2_register_widget(et2_calendar_planner, ["calendar-planner"]);
|