2016-03-01 17:27:45 +01:00
|
|
|
/*
|
2015-05-06 21:03:45 +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-05-06 21:03:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "calendar-timegrid" XET-Tag for displaying a span of days
|
|
|
|
*
|
2016-01-13 23:07:09 +01:00
|
|
|
* This widget is responsible for the times on the side, and it is also the
|
|
|
|
* controller for both positioning and setting the day columns. Day columns are
|
|
|
|
* recycled rather than removed and re-created to reduce reloading. Similarly,
|
|
|
|
* the horizontal time grid (when used - see granularity attribute) is only
|
|
|
|
* redrawn or resized when needed. Unfortunately resizing is needed every time
|
|
|
|
* the all day section has an event added or removed so the full work day from
|
|
|
|
* start time to end time is properly displayed.
|
2015-05-06 21:03:45 +02:00
|
|
|
*
|
2016-01-13 23:07:09 +01:00
|
|
|
*
|
|
|
|
* @augments et2_calendar_view
|
2015-05-06 21:03:45 +02:00
|
|
|
*/
|
2016-03-31 22:55:41 +02:00
|
|
|
var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.extend([et2_IDetachedDOM, et2_IResizeable,et2_IPrint],
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
createNamespace: true,
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
attributes: {
|
|
|
|
value: {
|
|
|
|
type: "any",
|
|
|
|
description: "An array of events, indexed by date (Ymd format)."
|
|
|
|
},
|
|
|
|
day_start: {
|
|
|
|
name: "Day start time",
|
|
|
|
type: "string",
|
|
|
|
default: parseInt(egw.preference('workdaystarts','calendar')) || 9,
|
|
|
|
description: "Work day start time. If unset, this will default to the current user's preference"
|
|
|
|
},
|
|
|
|
day_end: {
|
|
|
|
name: "Day end time",
|
|
|
|
type: "string",
|
|
|
|
default: parseInt(egw.preference('workdayends','calendar')) || 17,
|
|
|
|
description: "Work day end time. If unset, this will default to the current user's preference"
|
|
|
|
},
|
|
|
|
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."
|
|
|
|
},
|
|
|
|
granularity: {
|
|
|
|
name: "Granularity",
|
|
|
|
type: "integer",
|
|
|
|
default: parseInt(egw.preference('interval','calendar')) || 30,
|
2016-01-13 00:55:59 +01:00
|
|
|
description: "How many minutes per row, or 0 to display events as a list"
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
2015-06-10 23:51:28 +02:00
|
|
|
"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."
|
|
|
|
},
|
2015-05-06 21:03:45 +02:00
|
|
|
height: {
|
|
|
|
"default": '100%'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @memberOf et2_calendar_timegrid
|
|
|
|
*/
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Main container
|
2016-06-02 16:51:15 +02:00
|
|
|
this.div = jQuery(document.createElement("div"))
|
2015-08-25 02:00:45 +02:00
|
|
|
.addClass("calendar_calTimeGrid")
|
|
|
|
.addClass("calendar_TimeGridNoLabel");
|
2015-05-06 21:03:45 +02:00
|
|
|
|
2015-10-06 01:45:51 +02:00
|
|
|
// Headers
|
2016-06-02 16:51:15 +02:00
|
|
|
this.gridHeader = jQuery(document.createElement("div"))
|
2015-11-12 02:01:21 +01:00
|
|
|
.addClass("calendar_calGridHeader")
|
2015-05-06 21:03:45 +02:00
|
|
|
.appendTo(this.div);
|
2016-06-02 16:51:15 +02:00
|
|
|
this.dayHeader = jQuery(document.createElement("div"))
|
2015-10-06 01:45:51 +02:00
|
|
|
.appendTo(this.gridHeader);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-10-06 01:45:51 +02:00
|
|
|
// Contains times / rows
|
2016-06-02 16:51:15 +02:00
|
|
|
this.scrolling = jQuery(document.createElement('div'))
|
2015-10-06 01:45:51 +02:00
|
|
|
.addClass("calendar_calTimeGridScroll")
|
2016-01-05 21:43:19 +01:00
|
|
|
.appendTo(this.div)
|
|
|
|
.append('<div class="calendar_calTimeLabels"></div>');
|
2015-10-06 01:45:51 +02:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// Contains days / columns
|
2016-06-02 16:51:15 +02:00
|
|
|
this.days = jQuery(document.createElement("div"))
|
2015-05-06 21:03:45 +02:00
|
|
|
.addClass("calendar_calDayCols")
|
2015-10-06 01:45:51 +02:00
|
|
|
.appendTo(this.scrolling);
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Used for owners
|
|
|
|
this.owner = et2_createWidget('select-account_ro',{},this);
|
2015-08-19 02:08:22 +02:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
this._labelContainer = jQuery(document.createElement("label"))
|
2016-04-05 23:48:57 +02:00
|
|
|
.addClass("et2_label et2_link")
|
2015-08-19 02:08:22 +02:00
|
|
|
.appendTo(this.gridHeader);
|
2016-02-11 18:02:06 +01:00
|
|
|
|
|
|
|
this.gridHover = jQuery('<div style="height:5px;" class="calendar_calAddEvent drop-hover">');
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// List of dates in Ymd
|
|
|
|
// The first one should be start_date, last should be end_date
|
|
|
|
this.day_list = [];
|
|
|
|
this.day_widgets = [];
|
|
|
|
|
|
|
|
// Update timer, to avoid redrawing twice when changing start & end date
|
|
|
|
this.update_timer = null;
|
|
|
|
|
2015-12-29 23:36:20 +01:00
|
|
|
// Timer to re-scale time to fit
|
|
|
|
this.resize_timer = null;
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
this.setDOMNode(this.div[0]);
|
|
|
|
},
|
|
|
|
destroy: function() {
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-12-08 22:54:40 +01:00
|
|
|
// Stop listening to tab changes
|
2016-01-28 17:59:23 +01:00
|
|
|
if(framework.getApplicationByName('calendar').tab)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(framework.getApplicationByName('calendar').tab.contentDiv).off('show.' + this.id);
|
2016-01-28 17:59:23 +01:00
|
|
|
}
|
2015-12-08 22:54:40 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
this._super.apply(this, arguments);
|
2015-08-26 01:30:32 +02:00
|
|
|
|
|
|
|
// Delete all old objects
|
|
|
|
this._actionObject.clear();
|
|
|
|
this._actionObject.unregisterActions();
|
|
|
|
this._actionObject.remove();
|
|
|
|
this._actionObject = null;
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
this.div.off();
|
2015-08-26 01:30:32 +02:00
|
|
|
this.div = null;
|
|
|
|
this.gridHeader = null;
|
2015-10-06 01:45:51 +02:00
|
|
|
this.dayHeader = null;
|
2015-08-26 01:30:32 +02:00
|
|
|
this.days = null;
|
2015-10-06 01:45:51 +02:00
|
|
|
this.scrolling = null;
|
2015-08-26 01:30:32 +02:00
|
|
|
this._labelContainer = null;
|
2015-05-06 21:03:45 +02:00
|
|
|
|
2016-01-13 23:07:09 +01:00
|
|
|
// Stop the resize timer
|
2015-12-09 21:54:01 +01:00
|
|
|
if(this.resize_timer)
|
|
|
|
{
|
|
|
|
window.clearTimeout(this.resize_timer);
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
doLoadingFinished: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2015-12-08 22:54:40 +01:00
|
|
|
|
|
|
|
// Listen to tab show to make sure we scroll to the day start, not top
|
2016-01-28 17:59:23 +01:00
|
|
|
if(framework.getApplicationByName('calendar').tab)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(framework.getApplicationByName('calendar').tab.contentDiv)
|
2016-01-28 17:59:23 +01:00
|
|
|
.on('show.' + this.id, jQuery.proxy(
|
|
|
|
function()
|
|
|
|
{
|
|
|
|
if(this.scrolling)
|
|
|
|
{
|
|
|
|
this.scrolling.scrollTop(this._top_time);
|
|
|
|
}
|
|
|
|
},this)
|
|
|
|
);
|
|
|
|
}
|
2015-12-08 22:54:40 +01:00
|
|
|
|
2015-10-06 01:45:51 +02:00
|
|
|
// Need to get the correct internal sizing
|
|
|
|
this.resize();
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
this._drawGrid();
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
// 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 || []);
|
|
|
|
|
|
|
|
// Automatically bind drag and resize for every event using jQuery directly
|
|
|
|
// - no action system -
|
|
|
|
var timegrid = this;
|
|
|
|
|
2015-07-02 21:31:52 +02:00
|
|
|
/**
|
|
|
|
* 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, and we won't need exceptions
|
|
|
|
* for planner view to resize horizontally.
|
|
|
|
*/
|
|
|
|
this.div.on('mouseover', '.calendar_calEvent:not(.ui-resizable):not(.rowNoEdit)', function() {
|
2016-01-13 00:55:59 +01:00
|
|
|
// Only resize in timegrid
|
|
|
|
if(timegrid.options.granularity === 0) return;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-02 21:31:52 +02:00
|
|
|
// Load the event
|
|
|
|
timegrid._get_event_info(this);
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
//Resizable event handler
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).resizable
|
2015-07-02 21:31:52 +02:00
|
|
|
({
|
|
|
|
distance: 10,
|
2015-10-06 01:45:51 +02:00
|
|
|
// Grid matching preference
|
|
|
|
grid: [10000,timegrid.rowHeight],
|
2015-07-02 21:31:52 +02:00
|
|
|
autoHide: false,
|
|
|
|
handles: 's,se',
|
|
|
|
containment:'parent',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered when the resizable is created.
|
|
|
|
*
|
|
|
|
* @param {event} event
|
|
|
|
* @param {Object} ui
|
|
|
|
*/
|
|
|
|
create:function(event, ui)
|
|
|
|
{
|
|
|
|
var resizeHelper = event.target.getAttribute('data-resize');
|
|
|
|
if (resizeHelper == 'WD' || resizeHelper == 'WDS')
|
|
|
|
{
|
|
|
|
jQuery(this).resizable('destroy');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = timegrid._get_event_info(this);
|
2016-01-19 19:03:42 +01:00
|
|
|
var event_widget = timegrid.getWidgetById(event_data.widget_id);
|
2015-07-02 21:31:52 +02:00
|
|
|
var sT = event_widget.options.value.start_m;
|
|
|
|
if (typeof this.dropEnd != 'undefined' && this.dropEnd.length == 1)
|
|
|
|
{
|
2016-03-24 19:47:58 +01:00
|
|
|
var eT = (parseInt(timegrid._drop_data.hour) * 60) + parseInt(timegrid._drop_data.minute);
|
2015-07-02 21:31:52 +02:00
|
|
|
e.data.duration = ((eT - sT)/60) * 3600;
|
|
|
|
|
|
|
|
if(event_widget)
|
|
|
|
{
|
2015-07-03 19:56:36 +02:00
|
|
|
event_widget.options.value.end_m = eT;
|
|
|
|
event_widget.options.value.duration = e.data.duration;
|
2015-07-02 21:31:52 +02:00
|
|
|
}
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).trigger(e);
|
2015-12-04 18:37:26 +01:00
|
|
|
event_widget._update(event_widget.options.value);
|
2015-07-02 21:31:52 +02:00
|
|
|
|
|
|
|
// That cleared the resize handles, so remove for re-creation...
|
2016-06-02 16:51:15 +02:00
|
|
|
if(jQuery(this).resizable('instance'))
|
2015-11-05 21:56:13 +01:00
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).resizable('destroy');
|
2015-11-05 21:56:13 +01:00
|
|
|
}
|
2015-07-02 21:31:52 +02:00
|
|
|
}
|
|
|
|
// Clear the helper, re-draw
|
2015-11-05 21:56:13 +01:00
|
|
|
if(event_widget && event_widget._parent)
|
2015-07-03 19:56:36 +02:00
|
|
|
{
|
|
|
|
event_widget._parent.position_event(event_widget);
|
|
|
|
}
|
2015-10-06 01:45:51 +02:00
|
|
|
timegrid.div.children('.drop-hover').removeClass('.drop-hover');
|
2015-07-02 21:31:52 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered during the resize, on the drag of the resize handler
|
|
|
|
*
|
|
|
|
* @param {event} event
|
|
|
|
* @param {Object} ui
|
|
|
|
*/
|
|
|
|
resize:function(event, ui)
|
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
// Add a bit for better understanding - it will show _to_ the start,
|
|
|
|
// covering the 'actual' target
|
|
|
|
timegrid._get_time_from_position(ui.helper[0].getBoundingClientRect().left, ui.helper[0].getBoundingClientRect().bottom+5);
|
|
|
|
timegrid.gridHover.hide();
|
|
|
|
var drop = timegrid._drag_helper(this,ui.element[0]);
|
2015-10-06 01:45:51 +02:00
|
|
|
if(drop && !drop.is(':visible'))
|
|
|
|
{
|
|
|
|
drop.get(0).scrollIntoView(false);
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
}
|
2015-07-02 21:31:52 +02:00
|
|
|
});
|
|
|
|
});
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +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-10 19:35:24 +01:00
|
|
|
// Act like you clicked the header, makes it easier to position
|
2016-02-11 18:02:06 +01:00
|
|
|
// but put it to the side (-5) so we can still do the hover
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this).draggable('option','cursorAt', {top: 5, left: -5});
|
2015-06-10 23:51:28 +02:00
|
|
|
})
|
2015-07-22 01:45:38 +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-07-22 01:45:38 +02:00
|
|
|
.css('top', '').css('left','')
|
2015-06-10 23:51:28 +02:00
|
|
|
.appendTo(ui.helper);
|
2016-06-02 16:51:15 +02:00
|
|
|
ui.helper.width(jQuery(this).width());
|
2016-02-11 18:02:06 +01:00
|
|
|
})
|
|
|
|
.on('mousemove', function(event) {
|
|
|
|
timegrid._get_time_from_position(event.clientX, event.clientY);
|
|
|
|
})
|
2016-03-22 18:57:17 +01:00
|
|
|
.on('mouseout', function(event) {
|
|
|
|
if(timegrid.div.has(event.relatedTarget).length === 0)
|
|
|
|
{
|
|
|
|
timegrid.gridHover.hide();
|
|
|
|
}
|
2015-07-22 01:45:38 +02:00
|
|
|
});
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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} helper
|
|
|
|
* @param {type} height
|
2015-07-22 01:45:38 +02:00
|
|
|
*/
|
|
|
|
_drag_helper: function(element, helper,height)
|
|
|
|
{
|
2015-11-10 19:35:24 +01:00
|
|
|
if(!element) return;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-02-11 18:02:06 +01:00
|
|
|
element.dropEnd = this.gridHover;
|
2015-07-22 01:45:38 +02:00
|
|
|
|
2015-11-02 21:04:31 +01:00
|
|
|
if(element.dropEnd.length)
|
|
|
|
{
|
2016-03-24 19:47:58 +01:00
|
|
|
this._drop_data = jQuery.extend({},element.dropEnd[0].dataset || {});
|
2015-11-02 21:04:31 +01:00
|
|
|
}
|
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
if (typeof element.dropEnd != 'undefined' && element.dropEnd.length)
|
|
|
|
{
|
2015-10-06 01:45:51 +02:00
|
|
|
// Make sure the target is visible in the scrollable day
|
2016-02-11 18:02:06 +01:00
|
|
|
if(this.gridHover.is(':visible'))
|
2015-10-06 01:45:51 +02:00
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
if(this.scrolling.scrollTop() > 0 && this.scrolling.scrollTop() >= this.gridHover.position().top - this.rowHeight)
|
2015-12-08 20:27:25 +01:00
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
this.scrolling.scrollTop(this.gridHover.position().top-this.rowHeight);
|
2015-12-08 20:27:25 +01:00
|
|
|
}
|
2016-02-11 18:02:06 +01:00
|
|
|
else if (this.scrolling.scrollTop() + this.scrolling.height() <= this.gridHover.position().top + (2*this.rowHeight))
|
2015-12-08 20:27:25 +01:00
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
this.scrolling.scrollTop(this.scrolling.scrollTop() + this.rowHeight);
|
2015-12-08 20:27:25 +01:00
|
|
|
}
|
2015-10-06 01:45:51 +02:00
|
|
|
}
|
2015-11-10 19:35:24 +01:00
|
|
|
var time = '';
|
|
|
|
if(this._drop_data.whole_day)
|
|
|
|
{
|
|
|
|
time = this.egw().lang('Whole day');
|
|
|
|
}
|
2016-01-13 00:55:59 +01:00
|
|
|
else if (this.options.granularity === 0)
|
|
|
|
{
|
|
|
|
// No times, keep what's in the event
|
|
|
|
// Add class to helper to keep formatting
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(helper).addClass('calendar_calTimeGridList');
|
2016-01-13 00:55:59 +01:00
|
|
|
}
|
2015-11-10 19:35:24 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
time = jQuery.datepicker.formatTime(
|
2015-11-17 21:19:47 +01:00
|
|
|
egw.preference("timeformat") === "12" ? "h:mmtt" : "HH:mm",
|
2015-11-10 19:35:24 +01:00
|
|
|
{
|
|
|
|
hour: element.dropEnd.attr('data-hour'),
|
|
|
|
minute: element.dropEnd.attr('data-minute'),
|
|
|
|
seconds: 0,
|
|
|
|
timezone: 0
|
|
|
|
},
|
|
|
|
{"ampm": (egw.preference("timeformat") == "12")}
|
|
|
|
);
|
|
|
|
}
|
2015-07-22 01:45:38 +02:00
|
|
|
element.innerHTML = '<div style="font-size: 1.1em; text-align:center; font-weight: bold; height:100%;"><span class="calendar_timeDemo" >'+time+'</span></div>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
element.innerHTML = '<div class="calendar_d-n-d_forbiden" style="height:100%"></div>';
|
|
|
|
}
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(element).width(jQuery(helper).width());
|
2015-07-22 01:45:38 +02:00
|
|
|
return element.dropEnd;
|
|
|
|
},
|
2015-06-10 23:51:28 +02:00
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
/**
|
|
|
|
* Handler for dropping an event on the timegrid
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
|
|
|
* @param {type} timegrid
|
|
|
|
* @param {type} event
|
|
|
|
* @param {type} ui
|
|
|
|
* @param {type} dropEnd
|
2015-07-22 01:45:38 +02:00
|
|
|
*/
|
2015-11-02 21:04:31 +01:00
|
|
|
_event_drop: function(timegrid, event,ui, dropEnd) {
|
2015-07-22 01:45:38 +02:00
|
|
|
var e = new jQuery.Event('change');
|
|
|
|
e.originalEvent = event;
|
|
|
|
e.data = {start: 0};
|
2015-11-10 19:35:24 +01:00
|
|
|
|
2015-11-02 21:04:31 +01:00
|
|
|
if(typeof dropEnd != 'undefined' && dropEnd)
|
|
|
|
{
|
|
|
|
var drop_date = dropEnd.date||false;
|
2015-06-10 23:51:28 +02:00
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
var event_data = timegrid._get_event_info(ui.draggable);
|
2016-01-13 23:07:09 +01:00
|
|
|
var event_widget = timegrid.getWidgetById(event_data.widget_id);
|
2015-07-22 01:45:38 +02:00
|
|
|
if(!event_widget)
|
|
|
|
{
|
|
|
|
// Widget was moved across weeks / owners
|
2016-01-13 23:07:09 +01:00
|
|
|
event_widget = timegrid.getParent().getWidgetById(event_data.widget_id);
|
2015-07-22 01:45:38 +02:00
|
|
|
}
|
|
|
|
if(event_widget)
|
|
|
|
{
|
2016-04-05 00:06:01 +02:00
|
|
|
// Send full string to avoid rollover between months using set_month()
|
|
|
|
event_widget._parent.date_helper.set_value(
|
|
|
|
drop_date.substring(0,4)+'-'+drop_date.substring(4,6)+'-'+drop_date.substring(6,8)+
|
|
|
|
'T00:00:00Z'
|
|
|
|
);
|
2016-04-04 18:03:59 +02:00
|
|
|
|
|
|
|
|
2015-11-10 19:35:24 +01:00
|
|
|
// Make sure whole day events stay as whole day events by ignoring drop time
|
|
|
|
if(event_data.app == 'calendar' && event_widget.options.value.whole_day)
|
|
|
|
{
|
|
|
|
event_widget._parent.date_helper.set_hours(0);
|
2016-01-13 00:55:59 +01:00
|
|
|
event_widget._parent.date_helper.set_minutes(0);
|
|
|
|
}
|
|
|
|
else if (timegrid.options.granularity === 0)
|
|
|
|
{
|
|
|
|
// List, not time grid - keep time
|
|
|
|
event_widget._parent.date_helper.set_hours(event_widget.options.value.start.getUTCHours());
|
|
|
|
event_widget._parent.date_helper.set_minutes(event_widget.options.value.start.getUTCMinutes());
|
2015-11-10 19:35:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Non-whole day events, and integrated apps, can change
|
|
|
|
event_widget._parent.date_helper.set_hours(dropEnd.whole_day ? 0 : dropEnd.hour||0);
|
|
|
|
event_widget._parent.date_helper.set_minutes(dropEnd.whole_day ? 0 : dropEnd.minute||0);
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
// Leave the helper there until the update is done
|
2016-06-02 16:51:15 +02:00
|
|
|
var loading = ui.helper.clone(true).appendTo(jQuery('body'));
|
2015-08-06 19:14:20 +02:00
|
|
|
// and add a loading icon so user knows something is happening
|
2016-06-02 16:51:15 +02:00
|
|
|
if(jQuery('.calendar_timeDemo',loading).length == 0)
|
2015-11-10 20:57:05 +01:00
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calEventHeader',loading).addClass('loading');
|
2015-11-10 20:57:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_timeDemo',loading).after('<div class="loading"></div>');
|
2015-11-10 20:57:05 +01:00
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
event_widget.recur_prompt(function(button_id) {
|
2015-11-02 21:04:31 +01:00
|
|
|
if(button_id === 'cancel' || !button_id)
|
|
|
|
{
|
|
|
|
// Need to refresh the event with original info to clean up
|
|
|
|
var app_id = event_widget.options.value.app_id ? event_widget.options.value.app_id : event_widget.options.value.id + (event_widget.options.value.recur_type ? ':'+event_widget.options.value.recur_date : '');
|
2015-11-13 21:22:58 +01:00
|
|
|
egw().dataStoreUID('calendar::'+app_id,egw.dataGetUIDdata('calendar::'+app_id).data);
|
|
|
|
loading.remove();
|
2015-11-02 21:04:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-07-22 01:45:38 +02:00
|
|
|
//Get infologID if in case if it's an integrated infolog event
|
|
|
|
if (event_data.app === 'infolog')
|
2015-06-10 23:51:28 +02:00
|
|
|
{
|
2015-11-10 19:35:24 +01:00
|
|
|
// Duration - infologs are always non-blocking
|
|
|
|
var duration = dropEnd.whole_day ? 86400-1 : (
|
|
|
|
event_widget.options.value.whole_day ? (egw().preference('defaultlength','calendar')*60) : false);
|
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
// If it is an integrated infolog event we need to edit infolog entry
|
|
|
|
egw().json('stylite_infolog_calendar_integration::ajax_moveInfologEvent',
|
2015-12-01 23:02:47 +01:00
|
|
|
[event_data.app_id, event_widget._parent.date_helper.getValue()||false,duration],
|
2015-07-22 01:45:38 +02:00
|
|
|
function() {loading.remove();}
|
|
|
|
).sendRequest(true);
|
2015-06-10 23:51:28 +02:00
|
|
|
}
|
2015-07-22 01:45:38 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
//Edit calendar event
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-11-10 19:35:24 +01:00
|
|
|
// Duration - check for whole day dropped on a time, change it to full day
|
|
|
|
var duration = event_widget.options.value.whole_day && dropEnd.hour ? 86400-1 : false;
|
|
|
|
// Event (whole day or not) dropped on whole day section, change to whole day non blocking
|
|
|
|
if(dropEnd.whole_day) duration = 'whole_day';
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-11-27 17:57:25 +01:00
|
|
|
// Send the update
|
|
|
|
var _send = function(series_instance)
|
|
|
|
{
|
|
|
|
var start = new Date(event_widget._parent.date_helper.getValue());
|
|
|
|
|
|
|
|
egw().json('calendar.calendar_uiforms.ajax_moveEvent', [
|
|
|
|
button_id==='series' ? event_data.id : event_data.app_id,event_data.owner,
|
|
|
|
start,
|
|
|
|
timegrid.options.owner||egw.user('account_id'),
|
|
|
|
duration,
|
|
|
|
series_instance
|
|
|
|
],
|
|
|
|
function() { loading.remove();}
|
|
|
|
).sendRequest(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Check for modifying a series that started before today
|
2015-12-07 16:48:29 +01:00
|
|
|
if (event_widget.options.value.recur_type && button_id === 'series')
|
2015-11-27 17:57:25 +01:00
|
|
|
{
|
2015-12-04 18:37:26 +01:00
|
|
|
event_widget.series_split_prompt(function(_button_id) {
|
|
|
|
if (_button_id === et2_dialog.OK_BUTTON)
|
2015-11-27 17:57:25 +01:00
|
|
|
{
|
2015-12-04 18:37:26 +01:00
|
|
|
_send(event_widget.options.value.recur_date);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loading.remove();
|
|
|
|
}
|
|
|
|
});
|
2015-11-27 17:57:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_send(event_widget.options.value.recur_date);
|
|
|
|
}
|
2015-07-22 01:45:38 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Something changed, and the days need to be re-drawn. We wait a bit to
|
|
|
|
* avoid re-drawing twice if start and end date both changed, then recreate
|
|
|
|
* the days.
|
|
|
|
* The whole grid is not regenerated because times aren't expected to change,
|
|
|
|
* just the days.
|
2015-06-10 23:51:28 +02:00
|
|
|
*
|
2015-12-28 23:21:47 +01:00
|
|
|
* @param {boolean} [trigger=false] Trigger an event once things are done.
|
2015-06-10 23:51:28 +02:00
|
|
|
* Waiting until invalidate completes prevents 2 updates when changing the date range.
|
2015-05-06 21:03:45 +02:00
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
2015-06-10 23:51:28 +02:00
|
|
|
invalidate: function(trigger) {
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Reset the list of days
|
|
|
|
this.day_list = [];
|
|
|
|
|
|
|
|
// Wait a bit to see if anything else changes, then re-draw the days
|
2016-01-05 21:43:19 +01:00
|
|
|
if(this.update_timer)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-01-05 21:43:19 +01:00
|
|
|
window.clearTimeout(this.update_timer);
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
2016-01-05 21:43:19 +01:00
|
|
|
this.update_timer = window.setTimeout(jQuery.proxy(function() {
|
|
|
|
this.widget.update_timer = null;
|
2016-01-13 00:55:59 +01:00
|
|
|
window.clearTimeout(this.resize_timer);
|
2016-01-05 21:43:19 +01:00
|
|
|
this.widget.loader.hide().show();
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-05 21:43:19 +01:00
|
|
|
// Update actions
|
|
|
|
if(this.widget._actionManager)
|
|
|
|
{
|
|
|
|
this.widget._link_actions(this.widget._actionManager.children);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.widget._drawDays();
|
|
|
|
// We have to completely re-do times, as they may have changed in
|
|
|
|
// scale to the point where more labels are needed / need to be removed
|
|
|
|
this.widget._drawTimes();
|
|
|
|
if(this.trigger)
|
|
|
|
{
|
|
|
|
this.widget.change();
|
|
|
|
}
|
|
|
|
// Hide loader
|
2016-04-26 00:09:57 +02:00
|
|
|
window.setTimeout(jQuery.proxy(function() {this.loader.hide();},this.widget),200);
|
2016-01-05 21:43:19 +01:00
|
|
|
},{widget:this,"trigger":trigger}),ET2_GRID_INVALIDATE_TIMEOUT);
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
detachFromDOM: function() {
|
|
|
|
// Remove the binding to the change handler
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.div).off(".et2_calendar_timegrid");
|
2015-06-10 23:51: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-10 23:51: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) {
|
2016-01-19 19:03:42 +01:00
|
|
|
return e.data.change.call(e.data, e, this);
|
|
|
|
});
|
2015-06-10 23:51:28 +02:00
|
|
|
|
2016-01-19 19:03:42 +01:00
|
|
|
// Catch resize and prevent it from bubbling further, triggering
|
|
|
|
// etemplate's resize
|
|
|
|
this.div.on('resize', this, function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
2015-06-10 23:51:28 +02:00
|
|
|
},
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
getDOMNode: function(_sender) {
|
|
|
|
if(_sender === this || !_sender)
|
|
|
|
{
|
2015-10-27 17:45:37 +01:00
|
|
|
return this.div ? this.div[0] : null;
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
else if (_sender.instanceOf(et2_calendar_daycol))
|
|
|
|
{
|
2015-10-27 17:45:37 +01:00
|
|
|
return this.days ? this.days[0] : null;
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
else if (_sender)
|
|
|
|
{
|
2015-10-27 17:45:37 +01:00
|
|
|
return this.gridHeader ? this.gridHeader[0] : null;
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
},
|
2015-07-02 21:31:52 +02:00
|
|
|
|
2016-01-05 21:43:19 +01:00
|
|
|
set_disabled: function(disabled) {
|
2016-04-21 21:00:21 +02:00
|
|
|
var old_value = this.options.disabled;
|
2016-01-05 21:43:19 +01:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
if(disabled)
|
|
|
|
{
|
|
|
|
this.loader.show();
|
|
|
|
}
|
2016-04-21 21:00:21 +02:00
|
|
|
else if (old_value !== disabled)
|
|
|
|
{
|
|
|
|
// Scroll to start of day - stops jumping in FF
|
|
|
|
// For some reason on Chrome & FF this doesn't quite get the day start
|
|
|
|
// to the top, so add 2px;
|
|
|
|
this.scrolling.scrollTop(this._top_time+2);
|
|
|
|
}
|
|
|
|
|
2016-01-05 21:43:19 +01:00
|
|
|
},
|
|
|
|
|
2015-07-02 21:31:52 +02:00
|
|
|
/**
|
|
|
|
* Clear everything, and redraw the whole grid
|
|
|
|
*/
|
2015-05-06 21:03:45 +02:00
|
|
|
_drawGrid: function() {
|
|
|
|
|
|
|
|
this.div.css('height', this.options.height)
|
|
|
|
.empty();
|
2016-01-05 21:43:19 +01:00
|
|
|
this.loader.prependTo(this.div).show();
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Draw in the horizontal - the times
|
|
|
|
this._drawTimes();
|
|
|
|
|
|
|
|
// Draw in the vertical - the days
|
2015-06-10 23:51:28 +02:00
|
|
|
this.invalidate();
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the DOM nodes for the times in the left column, and the horizontal
|
2016-01-13 23:07:09 +01:00
|
|
|
* lines (mostly via CSS) that span the whole date range.
|
2015-05-06 21:03:45 +02:00
|
|
|
*/
|
|
|
|
_drawTimes: function() {
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calTimeRow',this.div).remove();
|
2015-10-27 20:08:33 +01:00
|
|
|
|
2016-01-13 00:55:59 +01:00
|
|
|
this.div.toggleClass('calendar_calTimeGridList', this.options.granularity === 0);
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
this.gridHeader
|
2015-09-03 00:40:38 +02:00
|
|
|
.attr('data-date', this.options.start_date)
|
|
|
|
.attr('data-owner', this.options.owner)
|
2015-10-28 16:55:10 +01:00
|
|
|
.append(this._labelContainer)
|
2015-09-03 00:40:38 +02:00
|
|
|
.append(this.owner.getDOMNode())
|
2015-10-06 01:45:51 +02:00
|
|
|
.append(this.dayHeader)
|
2015-05-06 21:03:45 +02:00
|
|
|
.appendTo(this.div);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-13 00:55:59 +01:00
|
|
|
// Max with 18 avoids problems when it's not shown
|
|
|
|
var header_height = Math.max(this.gridHeader.outerHeight(true), 18);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-13 00:55:59 +01:00
|
|
|
this.scrolling
|
|
|
|
.appendTo(this.div)
|
2016-03-01 17:27:45 +01:00
|
|
|
.off();
|
2016-01-13 00:55:59 +01:00
|
|
|
|
|
|
|
// No time grid - list
|
|
|
|
if(this.options.granularity === 0)
|
|
|
|
{
|
|
|
|
this.scrolling.css('height','100%');
|
|
|
|
this.days.css('height', '100%');
|
|
|
|
this.iterateOver(function(day) {
|
|
|
|
day.resize();
|
|
|
|
},this,et2_calendar_daycol);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var wd_start = 60*this.options.day_start;
|
|
|
|
var wd_end = 60*this.options.day_end;
|
|
|
|
var granularity = this.options.granularity;
|
|
|
|
var totalDisplayMinutes = wd_end - wd_start;
|
|
|
|
var rowsToDisplay = Math.ceil((totalDisplayMinutes+60)/granularity);
|
2016-02-11 18:02:06 +01:00
|
|
|
var row_count = (1440 / this.options.granularity);
|
2015-05-06 21:03:45 +02:00
|
|
|
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-10-06 01:45:51 +02:00
|
|
|
this.scrolling
|
2016-01-13 00:55:59 +01:00
|
|
|
.on('scroll', jQuery.proxy(this._scroll, this));
|
2015-10-06 01:45:51 +02:00
|
|
|
|
2015-10-29 22:53:47 +01:00
|
|
|
// Percent
|
|
|
|
var rowHeight = (100/rowsToDisplay).toFixed(1);
|
|
|
|
// Pixels
|
2015-11-12 02:01:21 +01:00
|
|
|
this.rowHeight = this.scrolling.height() / rowsToDisplay;
|
2015-10-29 22:53:47 +01:00
|
|
|
|
2016-02-11 18:02:06 +01:00
|
|
|
// We need a reasonable bottom limit here, but resize will handle it
|
|
|
|
// if we get too small
|
2015-11-17 17:57:34 +01:00
|
|
|
if(this.rowHeight < 5 && this.div.is(':visible'))
|
2015-11-16 19:31:09 +01:00
|
|
|
{
|
2016-01-05 21:43:19 +01:00
|
|
|
if(this.rowHeight === 0)
|
|
|
|
{
|
|
|
|
// Something is not right...
|
|
|
|
this.rowHeight = 5;
|
|
|
|
}
|
2015-11-16 19:31:09 +01:00
|
|
|
}
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// the hour rows
|
|
|
|
var show = {
|
|
|
|
5 : [0,15,30,45],
|
|
|
|
10 : [0,30],
|
|
|
|
15 : [0,30],
|
|
|
|
45 : [0,15,30,45]
|
|
|
|
};
|
|
|
|
var html = '';
|
2015-11-16 19:31:09 +01:00
|
|
|
var line_height = parseInt(this.div.css('line-height'));
|
2016-03-01 17:27:45 +01:00
|
|
|
this._top_time = 0;
|
2015-10-06 01:45:51 +02:00
|
|
|
for(var t = 0,i = 0; t < 1440; t += granularity,++i)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-03-22 16:09:39 +01:00
|
|
|
if(t <= wd_start && t + granularity > wd_start)
|
|
|
|
{
|
|
|
|
this._top_time = this.rowHeight * (i+1+(wd_start - (t+granularity))/granularity);
|
|
|
|
}
|
|
|
|
var working_hours = (t >= wd_start && t < wd_end) ? ' calendar_calWorkHours' : '';
|
|
|
|
html += '<div class="calendar_calTimeRow' + working_hours + '" style="height: '+(100/row_count)+'%;">';
|
2015-05-06 21:03:45 +02:00
|
|
|
// show time for full hours, always for 45min interval and at least on every 3 row
|
|
|
|
var time = jQuery.datepicker.formatTime(
|
2015-11-17 21:19:47 +01:00
|
|
|
egw.preference("timeformat") === "12" ? "h:mmtt" : "HH:mm",
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
hour: t / 60,
|
|
|
|
minute: t % 60,
|
|
|
|
seconds: 0,
|
|
|
|
timezone: 0
|
|
|
|
},
|
2015-11-17 21:19:47 +01:00
|
|
|
{"ampm": (egw.preference("timeformat") === "12")}
|
2015-05-06 21:03:45 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
var time_label = (typeof show[granularity] === 'undefined' ? t % 60 === 0 : show[granularity].indexOf(t % 60) !== -1) ? time : '';
|
2016-01-27 19:21:14 +01:00
|
|
|
if(time_label && egw.preference("timeformat") == "12" && time_label.split(':')[0] < 10)
|
|
|
|
{
|
|
|
|
time_label =' ' + time_label;
|
|
|
|
}
|
2015-06-10 23:51:28 +02:00
|
|
|
html += '<div class="calendar_calTimeRowTime et2_clickable" data-time="'+time.trim()+'" data-hour="'+Math.floor(t/60)+'" data-minute="'+(t%60)+'">'+time_label+"</div></div>\n";
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
2015-10-06 01:45:51 +02:00
|
|
|
|
|
|
|
// Set heights in pixels for scrolling
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calTimeLabels',this.scrolling)
|
2016-01-05 21:43:19 +01:00
|
|
|
.empty()
|
2016-02-11 18:02:06 +01:00
|
|
|
.height(this.rowHeight*i)
|
2016-01-05 21:43:19 +01:00
|
|
|
.append(html);
|
2015-10-06 01:45:51 +02:00
|
|
|
this.days.css('height', (this.rowHeight*i)+'px');
|
2016-02-11 18:02:06 +01:00
|
|
|
this.gridHover.css('height', this.rowHeight);
|
2015-10-06 01:45:51 +02:00
|
|
|
|
|
|
|
// Scroll to start of day
|
|
|
|
this.scrolling.scrollTop(this._top_time);
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
2015-12-09 21:54:01 +01:00
|
|
|
/**
|
|
|
|
* As window size and number of all day non-blocking events change, we need
|
|
|
|
* to re-scale the time grid to make sure the full working day is shown.
|
2016-01-13 23:07:09 +01:00
|
|
|
*
|
|
|
|
* We use a timeout to avoid doing it multiple times if redrawing or resizing.
|
2015-12-09 21:54:01 +01:00
|
|
|
*/
|
|
|
|
resizeTimes: function() {
|
|
|
|
// Wait a bit to see if anything else changes, then re-draw the times
|
2015-12-29 23:36:20 +01:00
|
|
|
if(this.resize_timer)
|
2015-12-09 21:54:01 +01:00
|
|
|
{
|
2015-12-29 23:36:20 +01:00
|
|
|
window.clearTimeout(this.resize_timer);
|
2015-12-09 21:54:01 +01:00
|
|
|
}
|
2016-01-13 00:55:59 +01:00
|
|
|
// No point if it is just going to be redone completely
|
2016-04-21 21:00:21 +02:00
|
|
|
if(this.update_timer) return;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-12-29 23:36:20 +01:00
|
|
|
this.resize_timer = window.setTimeout(jQuery.proxy(function() {
|
|
|
|
if(this._resizeTimes)
|
|
|
|
{
|
|
|
|
this.resize_timer = null;
|
|
|
|
|
|
|
|
this._resizeTimes();
|
|
|
|
}
|
|
|
|
},this),1);
|
2015-12-09 21:54:01 +01:00
|
|
|
},
|
2016-01-13 23:07:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-scale the time grid to make sure the full working day is shown.
|
|
|
|
* This is the timeout callback that does the actual re-size immediately.
|
|
|
|
*/
|
2015-11-12 02:01:21 +01:00
|
|
|
_resizeTimes: function() {
|
|
|
|
|
2016-01-11 21:19:45 +01:00
|
|
|
if(!this.div.is(':visible'))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-11-12 02:01:21 +01:00
|
|
|
var wd_start = 60*this.options.day_start;
|
|
|
|
var wd_end = 60*this.options.day_end;
|
|
|
|
var totalDisplayMinutes = wd_end - wd_start;
|
|
|
|
var rowsToDisplay = Math.ceil((totalDisplayMinutes+60)/this.options.granularity);
|
2016-02-11 18:02:06 +01:00
|
|
|
var row_count = (1440 / this.options.granularity);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-11-12 02:01:21 +01:00
|
|
|
var new_height = this.scrolling.height() / rowsToDisplay;
|
2016-02-11 18:02:06 +01:00
|
|
|
var old_height = this.rowHeight;
|
2015-11-13 01:53:23 +01:00
|
|
|
this.rowHeight = new_height;
|
2016-02-11 18:02:06 +01:00
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calTimeLabels', this.scrolling).height(this.rowHeight*row_count);
|
2016-01-13 00:55:59 +01:00
|
|
|
this.days.css('height', this.options.granularity === 0 ?
|
|
|
|
'100%' :
|
2016-02-11 18:02:06 +01:00
|
|
|
(this.rowHeight*row_count)+'px'
|
2016-01-13 00:55:59 +01:00
|
|
|
);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-11-13 00:10:16 +01:00
|
|
|
// Scroll to start of day
|
|
|
|
this._top_time = (wd_start * this.rowHeight) / this.options.granularity;
|
2016-03-24 18:28:51 +01:00
|
|
|
// For some reason on Chrome & FF this doesn't quite get the day start
|
|
|
|
// to the top, so add 2px;
|
|
|
|
this.scrolling.scrollTop(this._top_time+2);
|
2016-01-13 00:55:59 +01:00
|
|
|
|
2016-02-11 18:02:06 +01:00
|
|
|
if(this.rowHeight != old_height)
|
|
|
|
{
|
|
|
|
this.iterateOver(function(child) {
|
|
|
|
if(child === this) return;
|
|
|
|
child.resize();
|
|
|
|
},this, et2_IResizeable);
|
|
|
|
}
|
2015-11-12 02:01:21 +01:00
|
|
|
},
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
/**
|
|
|
|
* Set up the needed day widgets to correctly display the selected date
|
|
|
|
* range. First we calculate the needed dates, then we create any needed
|
|
|
|
* widgets. Existing widgets are recycled rather than discarded.
|
|
|
|
*/
|
|
|
|
_drawDays: function() {
|
2015-10-06 01:45:51 +02:00
|
|
|
this.scrolling.append(this.days);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// If day list is still empty, recalculate it from start & end date
|
2015-12-08 01:22:50 +01:00
|
|
|
if(this.day_list.length === 0 && this.options.start_date && this.options.end_date)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
this.day_list = this._calculate_day_list(this.options.start_date, this.options.end_date, this.options.show_weekend);
|
|
|
|
}
|
2015-12-28 23:21:47 +01:00
|
|
|
// For a single day, we show each owner in their own daycol
|
2016-06-01 21:47:18 +02:00
|
|
|
this.daily_owner = this.day_list.length === 1 &&
|
2016-01-13 00:55:59 +01:00
|
|
|
this.options.owner.length > 1 &&
|
2016-01-13 01:23:37 +01:00
|
|
|
this.options.owner.length < (parseInt(egw.preference('day_consolidate','calendar')) || 6);
|
2016-06-01 21:47:18 +02:00
|
|
|
var daycols_needed = this.daily_owner ? this.options.owner.length : this.day_list.length;
|
2016-06-02 16:51:15 +02:00
|
|
|
var day_width = ( Math.min( jQuery(this.getInstanceManager().DOMContainer).width(),this.days.width())/daycols_needed);
|
2015-11-06 16:52:06 +01:00
|
|
|
if(!day_width || !this.day_list)
|
|
|
|
{
|
|
|
|
// Hidden on another tab, or no days for some reason
|
|
|
|
var dim = egw.getHiddenDimensions(this.days, false);
|
2015-12-28 23:21:47 +01:00
|
|
|
day_width = ( dim.w /Math.max(daycols_needed,1));
|
2015-11-06 16:52:06 +01:00
|
|
|
}
|
2015-10-21 21:53:19 +02:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// Create any needed widgets - otherwise, we'll just recycle
|
|
|
|
// Add any needed day widgets (now showing more days)
|
2015-10-21 21:53:19 +02:00
|
|
|
var add_index = 0;
|
|
|
|
var before = true;
|
2015-12-28 23:21:47 +01:00
|
|
|
|
|
|
|
while(daycols_needed > this.day_widgets.length)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-06-01 21:47:18 +02:00
|
|
|
var existing_index = this.day_widgets[add_index] && !this.daily_owner ?
|
|
|
|
this.day_list.indexOf(this.day_widgets[add_index].options.date) :
|
|
|
|
-1;
|
2015-10-21 21:53:19 +02:00
|
|
|
before = existing_index > add_index;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
var day = et2_createWidget('calendar-daycol',{
|
2015-10-21 21:53:19 +02:00
|
|
|
owner: this.options.owner,
|
2015-10-28 16:55:10 +01:00
|
|
|
width: (before ? 0 : day_width) + "px"
|
2015-05-06 21:03:45 +02:00
|
|
|
},this);
|
|
|
|
if(this.isInTree())
|
|
|
|
{
|
|
|
|
day.doLoadingFinished();
|
|
|
|
}
|
2015-10-21 21:53:19 +02:00
|
|
|
if(existing_index != -1 && parseInt(this.day_list[add_index]) < parseInt(this.day_list[existing_index]))
|
|
|
|
{
|
|
|
|
this.day_widgets.unshift(day);
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.getDOMNode(day)).prepend(day.getDOMNode(day));
|
2015-10-21 21:53:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.day_widgets.push(day);
|
|
|
|
}
|
|
|
|
add_index++;
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
|
|
|
// Remove any extra day widgets (now showing less)
|
|
|
|
var delete_index = this.day_widgets.length - 1;
|
2015-10-21 21:53:19 +02:00
|
|
|
before = false;
|
2015-12-28 23:21:47 +01:00
|
|
|
while(this.day_widgets.length > daycols_needed)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
// If we're going down to an existing one, just keep it for cool CSS animation
|
2015-12-28 23:21:47 +01:00
|
|
|
while(delete_index > 1 && this.day_list.indexOf(this.day_widgets[delete_index].options.date) > -1)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
delete_index--;
|
2015-10-21 21:53:19 +02:00
|
|
|
before = true;
|
|
|
|
}
|
2015-12-28 23:21:47 +01:00
|
|
|
if(delete_index < 0) delete_index = 0;
|
2015-10-21 21:53:19 +02:00
|
|
|
|
|
|
|
// Widgets that are before our date shrink, after just get pushed out
|
|
|
|
if(before)
|
|
|
|
{
|
|
|
|
this.day_widgets[delete_index].set_width('0px');
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
2016-02-04 22:05:31 +01:00
|
|
|
this.day_widgets[delete_index].div.hide();
|
|
|
|
this.day_widgets[delete_index].header.hide();
|
|
|
|
this.day_widgets[delete_index].destroy();
|
2015-05-06 21:03:45 +02:00
|
|
|
this.day_widgets.splice(delete_index--,1);
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-15 18:29:10 +02:00
|
|
|
// Create / update day widgets with dates and data
|
2015-12-28 23:21:47 +01:00
|
|
|
for(var i = 0; i < this.day_widgets.length; i++)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
day = this.day_widgets[i];
|
2016-02-05 00:14:54 +01:00
|
|
|
|
|
|
|
// Classes
|
2016-04-07 00:23:43 +02:00
|
|
|
if(app.calendar && app.calendar.state &&
|
|
|
|
this.day_list[i] && parseInt(this.day_list[i].substr(4,2)) !== new Date(app.calendar.state.date).getUTCMonth()+1)
|
2016-02-05 00:14:54 +01:00
|
|
|
{
|
|
|
|
day.set_class('calendar_differentMonth');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
day.set_class('');
|
|
|
|
}
|
|
|
|
|
2015-10-06 01:45:51 +02:00
|
|
|
// Position
|
2015-10-28 16:55:10 +01:00
|
|
|
day.set_left((day_width * i) + 'px');
|
2016-06-01 21:47:18 +02:00
|
|
|
if(this.daily_owner)
|
2015-12-28 23:21:47 +01:00
|
|
|
{
|
2016-01-13 23:07:09 +01:00
|
|
|
// Each 'day' is the same date, different user
|
2016-01-05 21:43:19 +01:00
|
|
|
day.set_id(this.day_list[0]+'-'+this.options.owner[i]);
|
2015-12-28 23:21:47 +01:00
|
|
|
day.set_date(this.day_list[0], false);
|
|
|
|
day.set_owner(this.options.owner[i]);
|
|
|
|
day.set_label(this._get_owner_name(this.options.owner[i]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-13 23:07:09 +01:00
|
|
|
// Go back to self-calculated date by clearing the label
|
2015-12-28 23:21:47 +01:00
|
|
|
day.set_label('');
|
2016-01-05 21:43:19 +01:00
|
|
|
day.set_id(this.day_list[i]);
|
2015-12-28 23:21:47 +01:00
|
|
|
day.set_date(this.day_list[i], this.value[this.day_list[i]] || false);
|
|
|
|
day.set_owner(this.options.owner);
|
|
|
|
}
|
2015-10-28 16:55:10 +01:00
|
|
|
day.set_width(day_width + 'px');
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
2016-01-19 19:03:42 +01:00
|
|
|
|
|
|
|
// Adjust and scroll to start of day
|
|
|
|
this.resizeTimes();
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-08-06 19:14:20 +02:00
|
|
|
// Don't hold on to value any longer, use the data cache for best info
|
|
|
|
this.value = {};
|
2016-01-05 21:43:19 +01:00
|
|
|
|
2016-06-01 21:47:18 +02:00
|
|
|
if(this.daily_owner)
|
2016-01-05 21:43:19 +01:00
|
|
|
{
|
|
|
|
this.set_label('');
|
|
|
|
}
|
|
|
|
|
2015-11-04 22:47:52 +01:00
|
|
|
// Handle not fully visible elements
|
|
|
|
this._scroll();
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// TODO: Figure out how to do this with detached nodes
|
|
|
|
/*
|
|
|
|
var nodes = this.day_col.getDetachedNodes();
|
|
|
|
var supportedAttrs = [];
|
|
|
|
this.day_col.getDetachedAttributes(supportedAttrs);
|
|
|
|
supportedAttrs.push("id");
|
|
|
|
|
|
|
|
for(var i = 0; i < day_count; i++)
|
|
|
|
{
|
|
|
|
this.day_col.setDetachedAttributes(nodes.clone(),)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
|
2015-11-04 22:47:52 +01:00
|
|
|
/**
|
|
|
|
* Update UI while scrolling within the selected time
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-11-04 22:47:52 +01:00
|
|
|
* Toggles out of view indicators and adjusts not visible headers
|
|
|
|
* @param {Event} event Scroll event
|
|
|
|
*/
|
|
|
|
_scroll: function(event)
|
|
|
|
{
|
2016-02-23 22:29:13 +01:00
|
|
|
if(!this.day_widgets) return;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-11-04 22:47:52 +01:00
|
|
|
// Loop through days, let them deal with it
|
|
|
|
for(var day = 0; day < this.day_widgets.length; day++)
|
|
|
|
{
|
|
|
|
this.day_widgets[day]._out_of_view();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
/**
|
|
|
|
* Calculate a list of days between start and end date, skipping weekends if
|
|
|
|
* desired.
|
|
|
|
*
|
|
|
|
* @param {Date|string} start_date Date that et2_date widget can understand
|
|
|
|
* @param {Date|string} end_date Date that et2_date widget can understand
|
|
|
|
* @param {boolean} show_weekend If not showing weekend, Saturday and Sunday
|
|
|
|
* will not be in the returned list.
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-05-06 21:03:45 +02:00
|
|
|
* @returns {string[]} List of days in Ymd format
|
|
|
|
*/
|
|
|
|
_calculate_day_list: function(start_date, end_date, show_weekend) {
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
var day_list = [];
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
this.date_helper.set_value(end_date);
|
|
|
|
var end = this.date_helper.date.getTime();
|
|
|
|
var i = 1;
|
2016-02-05 00:14:54 +01:00
|
|
|
this.date_helper.set_value(new Date(start_date));
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2016-05-11 19:29:58 +02:00
|
|
|
if(show_weekend || !show_weekend && [0,6].indexOf(this.date_helper.date.getUTCDay()) === -1 || end_date === start_date)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
day_list.push(''+this.date_helper.get_year() + sprintf('%02d',this.date_helper.get_month()) + sprintf('%02d',this.date_helper.get_date()));
|
|
|
|
}
|
|
|
|
this.date_helper.set_date(this.date_helper.get_date()+1);
|
|
|
|
}
|
|
|
|
// Limit it to 14 days to avoid infinite loops in case something is mis-set,
|
|
|
|
// though the limit is more based on how wide the screen is
|
|
|
|
while(end >= this.date_helper.date.getTime() && i <= 14)
|
|
|
|
|
|
|
|
return day_list;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link the actions to the DOM nodes / widget bits.
|
|
|
|
*
|
|
|
|
* @param {object} actions {ID: {attributes..}+} map of egw action information
|
|
|
|
*/
|
|
|
|
_link_actions: function(actions)
|
|
|
|
{
|
2015-06-10 23:51:28 +02:00
|
|
|
// Get the parent? Might be a grid row, might not. Either way, it is
|
|
|
|
// just a container with no valid actions
|
2015-08-05 23:24:07 +02:00
|
|
|
var objectManager = egw_getObjectManager(this.getInstanceManager().app,true,1);
|
|
|
|
objectManager = objectManager.getObjectById(this.getInstanceManager().uniqueId,2) || objectManager;
|
2016-01-06 23:42:52 +01:00
|
|
|
var parent = objectManager.getObjectById(this.id,1) || objectManager.getObjectById(this._parent.id,1) || objectManager;
|
2015-08-05 23:24:07 +02:00
|
|
|
if(!parent)
|
|
|
|
{
|
|
|
|
debugger;
|
2016-03-01 17:27:45 +01:00
|
|
|
egw.debug('error','No parent objectManager found');
|
2015-08-05 23:24:07 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-06-01 21:47:18 +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());
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
for(var i = 0; i < parent.children.length; i++)
|
|
|
|
{
|
2016-02-23 22:29:13 +01:00
|
|
|
var parent_finder = jQuery(parent.children[i].iface.doGetDOMNode()).find(this.div);
|
2015-06-10 23:51:28 +02:00
|
|
|
if(parent_finder.length > 0)
|
|
|
|
{
|
|
|
|
parent = parent.children[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-11 19:29:58 +02:00
|
|
|
// Determine if we allow a dropped event to use the invite/change actions
|
|
|
|
var _invite_enabled = function(action, event, target)
|
|
|
|
{
|
|
|
|
var event = event.iface.getWidget();
|
|
|
|
var timegrid = target.iface.getWidget() || false;
|
|
|
|
if(event === timegrid || !event || !timegrid ||
|
2016-06-01 21:47:18 +02:00
|
|
|
!event.options || !event.options.value.participants || !timegrid.options.owner ) return false;
|
2016-05-11 19:29:58 +02:00
|
|
|
var owner_match = false;
|
2016-06-01 21:47:18 +02:00
|
|
|
for(var id in event.options.value.participants)
|
2016-05-11 19:29:58 +02:00
|
|
|
{
|
2016-06-01 21:47:18 +02:00
|
|
|
if(!timegrid.daily_owner)
|
2016-05-11 19:29:58 +02:00
|
|
|
{
|
|
|
|
if(timegrid.options.owner === id ||
|
|
|
|
timegrid.options.owner.indexOf &&
|
|
|
|
timegrid.options.owner.indexOf(id) >= 0)
|
|
|
|
{
|
|
|
|
owner_match = true;
|
|
|
|
}
|
|
|
|
}
|
2016-06-01 21:47:18 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
timegrid.iterateOver(function(col) {
|
2016-06-02 18:01:12 +02:00
|
|
|
// Check scroll section or header section
|
|
|
|
if(col.div.has(timegrid.gridHover).length || col.header.has(timegrid.gridHover).length)
|
2016-06-01 21:47:18 +02:00
|
|
|
{
|
|
|
|
owner_match = owner_match || col.options.owner.indexOf(id) !== -1;
|
|
|
|
}
|
|
|
|
}, this, et2_calendar_daycol);
|
|
|
|
}
|
2016-05-11 19:29:58 +02:00
|
|
|
}
|
2016-06-01 21:47:18 +02:00
|
|
|
var enabled = !owner_match;
|
|
|
|
widget_object.getActionLink('invite').enabled = enabled;
|
|
|
|
widget_object.getActionLink('change_participant').enabled = enabled;
|
2015-07-02 21:31:52 +02:00
|
|
|
|
2016-06-01 21:47:18 +02:00
|
|
|
// If invite or change participant are enabled, drag is not
|
|
|
|
widget_object.getActionLink('egw_link_drop').enabled = !enabled;
|
|
|
|
};
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
aoi.doTriggerEvent = function(_event, _data) {
|
|
|
|
// Determine target node
|
|
|
|
var event = _data.event || false;
|
|
|
|
if(!event) return;
|
2015-07-22 01:45:38 +02:00
|
|
|
if(_data.ui.draggable.hasClass('rowNoEdit')) return;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
/*
|
|
|
|
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')
|
|
|
|
{
|
2015-11-04 00:41:55 +01:00
|
|
|
var dropEnd = false;
|
2016-06-02 16:51:15 +02:00
|
|
|
var helper = jQuery('.calendar_d-n-d_timeCounter',_data.ui.helper)[0];
|
2015-11-04 00:41:55 +01:00
|
|
|
if(helper && helper.dropEnd && helper.dropEnd.length >= 1)
|
2016-05-11 19:29:58 +02:00
|
|
|
if (typeof this.dropEnd !== 'undefined' && this.dropEnd.length >= 1)
|
2015-11-04 00:41:55 +01:00
|
|
|
{
|
|
|
|
dropEnd = helper.dropEnd[0].dataset || false;
|
|
|
|
}
|
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, dropEnd);
|
2015-07-22 01:45:38 +02:00
|
|
|
}
|
2016-06-01 21:47:18 +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],ui.helper[0],0);
|
2016-06-01 21:47:18 +02:00
|
|
|
if(aoi.getWidget().daily_owner)
|
|
|
|
{
|
|
|
|
_invite_enabled(
|
|
|
|
widget_object.getActionLink('invite').actionObj,
|
|
|
|
event,
|
|
|
|
widget_object
|
|
|
|
);
|
|
|
|
}
|
2015-07-22 01:45:38 +02:00
|
|
|
};
|
2016-06-02 16:51:15 +02:00
|
|
|
var time = jQuery('.calendar_d-n-d_timeCounter',_data.ui.helper);
|
2015-06-10 23:51:28 +02:00
|
|
|
switch(_event)
|
|
|
|
{
|
2015-07-02 21:31:52 +02:00
|
|
|
// Triggered once, when something is dragged into the timegrid's div
|
2015-06-10 23:51:28 +02:00
|
|
|
case EGW_AI_DRAG_OVER:
|
2015-07-22 01:45:38 +02:00
|
|
|
// 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);
|
|
|
|
});
|
2015-12-09 21:54:01 +01:00
|
|
|
|
|
|
|
// Remove formatting for out-of-view events (full day non-blocking)
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calEventHeader',_data.ui.helper).css('top','');
|
|
|
|
jQuery('.calendar_calEventBody',_data.ui.helper).css('padding-top','');
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-05-11 19:29:58 +02:00
|
|
|
// Disable invite / change actions for same calendar or already participant
|
|
|
|
var event = _data.ui.draggable.data('selected')[0];
|
|
|
|
if(!event || event.id && event.id.indexOf('calendar') !== 0)
|
|
|
|
{
|
|
|
|
event = false;
|
|
|
|
}
|
2016-06-01 21:47:18 +02:00
|
|
|
if(event)
|
|
|
|
{
|
|
|
|
_invite_enabled(
|
|
|
|
widget_object.getActionLink('invite').actionObj,
|
|
|
|
event,
|
|
|
|
widget_object
|
|
|
|
);
|
|
|
|
}
|
2016-05-11 19:29:58 +02:00
|
|
|
|
2015-07-22 01:45:38 +02:00
|
|
|
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>');
|
|
|
|
}
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
break;
|
2015-07-02 21:31:52 +02:00
|
|
|
|
|
|
|
// Triggered once, when something is dragged out of the timegrid
|
2015-06-10 23:51:28 +02:00
|
|
|
case EGW_AI_DRAG_OUT:
|
2015-07-22 01:45:38 +02:00
|
|
|
// Stop listening
|
|
|
|
_data.ui.draggable.off('drag.et2_timegrid'+widget_object.id);
|
2016-02-11 18:02:06 +01:00
|
|
|
// Remove highlighted time square
|
|
|
|
var timegrid = aoi.getWidget();
|
|
|
|
timegrid.gridHover.hide();
|
|
|
|
timegrid.scrolling.scrollTop(timegrid._top_time);
|
2015-07-22 01:45:38 +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();
|
|
|
|
}
|
2015-06-10 23:51:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
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,
|
2015-08-11 17:35:54 +02:00
|
|
|
this._actionManager|| parent.manager.getActionById(this.id) || parent.manager
|
2015-06-10 23:51:28 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
widget_object.setAOI(aoi);
|
|
|
|
}
|
2015-08-12 00:30:50 +02:00
|
|
|
this._actionObject = widget_object;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
// Delete all old objects
|
|
|
|
widget_object.clear();
|
|
|
|
widget_object.unregisterActions();
|
2015-05-06 21:03:45 +02:00
|
|
|
|
2015-06-10 23:51:28 +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);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
widget_object.updateActionLinks(action_links);
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-06-10 23:51:28 +02:00
|
|
|
* Automatically add dnd support for linking
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
|
|
|
* @param {type} mgr
|
|
|
|
* @param {type} actionLinks
|
2015-05-06 21:03:45 +02:00
|
|
|
*/
|
2015-06-10 23:51:28 +02:00
|
|
|
_init_links_dnd: function(mgr,actionLinks) {
|
|
|
|
var self = this;
|
2015-05-06 21:03:45 +02:00
|
|
|
|
2016-05-11 19:29:58 +02:00
|
|
|
var drop_link = mgr.getActionById('egw_link_drop');
|
|
|
|
var drop_change_participant = mgr.getActionById('change_participant');
|
|
|
|
var drop_invite = mgr.getActionById('invite');
|
2015-06-10 23:51:28 +02:00
|
|
|
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-05-06 21:03:45 +02:00
|
|
|
{
|
2016-05-11 19:29:58 +02:00
|
|
|
if(drop_link)
|
2015-06-10 23:51:28 +02:00
|
|
|
{
|
2016-05-11 19:29:58 +02:00
|
|
|
drop_link.remove();
|
|
|
|
if(actionLinks.indexOf(drop_link.id) >= 0)
|
2015-06-10 23:51:28 +02:00
|
|
|
{
|
2016-05-11 19:29:58 +02:00
|
|
|
actionLinks.splice(actionLinks.indexOf(drop_link.id),1);
|
2015-06-10 23:51:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(drag_action)
|
|
|
|
{
|
|
|
|
drag_action.remove();
|
|
|
|
if(actionLinks.indexOf(drag_action.id) >= 0)
|
|
|
|
{
|
|
|
|
actionLinks.splice(actionLinks.indexOf(drag_action.id),1);
|
|
|
|
}
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-06-10 23:51:28 +02:00
|
|
|
// Don't re-add
|
2016-05-11 19:29:58 +02:00
|
|
|
if(drop_link == null)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2015-06-10 23:51:28 +02:00
|
|
|
// Create the drop action that links entries
|
2016-05-11 19:29:58 +02:00
|
|
|
drop_link = mgr.addAction('drop', 'egw_link_drop', egw.lang('Create link'), egw.image('link'), function(action, source, target) {
|
2015-07-02 21:31:52 +02:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
// Extract link IDs
|
|
|
|
var links = [];
|
|
|
|
var id = '';
|
|
|
|
for(var i = 0; i < source.length; i++)
|
|
|
|
{
|
2015-07-02 21:31:52 +02:00
|
|
|
// Check for no ID (invalid) or same manager (dragging an event)
|
2015-11-02 21:04:31 +01:00
|
|
|
if(!source[i].id) continue;
|
|
|
|
if(source[i].manager === target.manager)
|
|
|
|
{
|
2015-11-04 00:41:55 +01:00
|
|
|
// Find the timegrid, could have dropped on an event
|
|
|
|
var timegrid = target.iface.getWidget();
|
|
|
|
while(target.parent && timegrid.instanceOf && !timegrid.instanceOf(et2_calendar_timegrid))
|
|
|
|
{
|
|
|
|
target = target.parent;
|
|
|
|
timegrid = target.iface.getWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (timegrid && timegrid._drop_data)
|
2015-11-02 21:04:31 +01:00
|
|
|
{
|
2015-11-04 00:41:55 +01:00
|
|
|
timegrid._event_drop.call(source[i].iface.getDOMNode(),timegrid,null, action.ui,timegrid._drop_data);
|
2015-11-02 21:04:31 +01:00
|
|
|
}
|
2015-11-04 00:41:55 +01:00
|
|
|
timegrid._drop_data = false;
|
2015-11-02 21:04:31 +01:00
|
|
|
// Ok, stop.
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
id = source[i].id.split('::');
|
|
|
|
links.push({app: id[0] == 'filemanager' ? 'link' : id[0], id: id[1]});
|
|
|
|
}
|
2015-07-02 21:31:52 +02:00
|
|
|
if(links.length && target && target.iface.getWidget() && target.iface.getWidget().instanceOf(et2_calendar_event))
|
2015-06-10 23:51:28 +02:00
|
|
|
{
|
2015-07-02 21:31:52 +02:00
|
|
|
// Link the entries
|
|
|
|
egw.json(self.egw().getAppName()+".etemplate_widget_link.ajax_link.etemplate",
|
|
|
|
target.id.split('::').concat([links]),
|
|
|
|
function(result) {
|
|
|
|
if(result)
|
|
|
|
{
|
|
|
|
this.egw().message('Linked');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
self,
|
|
|
|
true,
|
|
|
|
self
|
|
|
|
).sendRequest();
|
|
|
|
}
|
|
|
|
else if (links.length)
|
|
|
|
{
|
|
|
|
// Get date and time
|
2016-06-02 16:51:15 +02:00
|
|
|
var params = jQuery.extend({},jQuery('.drop-hover[data-date]',target.iface.getDOMNode())[0].dataset || {});
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-07-02 21:31:52 +02:00
|
|
|
// Add link IDs
|
|
|
|
var app_registry = egw.link_get_registry('calendar');
|
|
|
|
params[app_registry.add_app] = [];
|
|
|
|
params[app_registry.add_id] = [];
|
|
|
|
for(var n in links)
|
|
|
|
{
|
|
|
|
params[app_registry.add_app].push( links[n].app);
|
|
|
|
params[app_registry.add_id].push( links[n].id);
|
|
|
|
}
|
|
|
|
egw.open('','calendar','add',params);
|
2015-06-10 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
},true);
|
2016-05-11 19:29:58 +02:00
|
|
|
|
|
|
|
drop_link.acceptedTypes = ['default','link'];
|
|
|
|
drop_link.hideOnDisabled = true;
|
|
|
|
|
|
|
|
// Create the drop action for moving events between calendars
|
|
|
|
var invite_action = function(action, source, target) {
|
|
|
|
|
|
|
|
// Extract link IDs
|
|
|
|
var links = [];
|
|
|
|
var id = '';
|
|
|
|
for(var i = 0; i < source.length; i++)
|
|
|
|
{
|
|
|
|
// Check for no ID (invalid) or same manager (dragging an event)
|
|
|
|
if(!source[i].id) continue;
|
|
|
|
if(source[i].manager === target.manager)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Find the timegrid, could have dropped on an event
|
|
|
|
var timegrid = target.iface.getWidget();
|
|
|
|
while(target.parent && timegrid.instanceOf && !timegrid.instanceOf(et2_calendar_timegrid))
|
|
|
|
{
|
|
|
|
target = target.parent;
|
|
|
|
timegrid = target.iface.getWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leave the helper there until the update is done
|
2016-06-02 16:51:15 +02:00
|
|
|
var loading = action.ui.helper.clone(true).appendTo(jQuery('body'));
|
2016-06-01 01:18:46 +02:00
|
|
|
|
|
|
|
// and add a loading icon so user knows something is happening
|
2016-06-02 16:51:15 +02:00
|
|
|
if(jQuery('.calendar_timeDemo',loading).length == 0)
|
2016-06-01 01:18:46 +02:00
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_calEventHeader',loading).addClass('loading');
|
2016-06-01 01:18:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery('.calendar_timeDemo',loading).after('<div class="loading"></div>');
|
2016-06-01 01:18:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var event_data = egw.dataGetUIDdata(source[i].id).data;
|
|
|
|
et2_calendar_event.recur_prompt(event_data, function(button_id) {
|
|
|
|
if(button_id === 'cancel' || !button_id)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-06-01 21:47:18 +02:00
|
|
|
var add_owner = jQuery.extend([],timegrid.options.owner);
|
|
|
|
if(timegrid.daily_owner)
|
|
|
|
{
|
|
|
|
timegrid.iterateOver(function(col) {
|
2016-06-08 00:14:11 +02:00
|
|
|
if(col.div.has(timegrid.gridHover).length || col.header.has(timegrid.gridHover).length)
|
2016-06-01 21:47:18 +02:00
|
|
|
{
|
|
|
|
add_owner = col.options.owner;
|
|
|
|
}
|
|
|
|
}, this, et2_calendar_daycol);
|
|
|
|
}
|
2016-06-01 01:18:46 +02:00
|
|
|
egw().json('calendar.calendar_uiforms.ajax_invite', [
|
|
|
|
button_id==='series' ? event_data.id : event_data.app_id,
|
2016-06-01 21:47:18 +02:00
|
|
|
add_owner,
|
2016-06-01 01:18:46 +02:00
|
|
|
action.id === 'change_participant' ?
|
|
|
|
jQuery.extend([],source[i].iface.getWidget().getParent().options.owner) :
|
|
|
|
[]
|
|
|
|
],
|
|
|
|
function() { loading.remove();}
|
|
|
|
).sendRequest(true);
|
|
|
|
});
|
2016-05-11 19:29:58 +02:00
|
|
|
// Ok, stop.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-01 01:18:46 +02:00
|
|
|
drop_change_participant = mgr.addAction('drop', 'change_participant', egw.lang('Move to'), egw.image('participant'), invite_action,true);
|
2016-05-11 19:29:58 +02:00
|
|
|
drop_change_participant.acceptedTypes = ['calendar'];
|
|
|
|
drop_change_participant.hideOnDisabled = true;
|
|
|
|
|
|
|
|
drop_invite = mgr.addAction('drop', 'invite', egw.lang('Invite'), egw.image('participant'), invite_action,true);
|
|
|
|
drop_invite.acceptedTypes = ['calendar'];
|
|
|
|
drop_invite.hideOnDisabled = true;
|
2015-05-06 21:03:45 +02:00
|
|
|
}
|
2016-05-11 19:29:58 +02:00
|
|
|
if(actionLinks.indexOf(drop_link.id) < 0)
|
2015-06-10 23:51:28 +02:00
|
|
|
{
|
2016-05-11 19:29:58 +02:00
|
|
|
actionLinks.push(drop_link.id);
|
2015-06-10 23:51:28 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 19:29:58 +02:00
|
|
|
actionLinks.push(drop_invite.id);
|
|
|
|
actionLinks.push(drop_change_participant.id);
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
// 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) {
|
2015-07-22 01:45:38 +02:00
|
|
|
// Drag helper - list titles.
|
2015-06-10 23:51:28 +02:00
|
|
|
// 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 timegrid itself is not draggable, so don't add a link.
|
|
|
|
// The action is there for the children (events) to use
|
|
|
|
if(false && actionLinks.indexOf(drag_action.id) < 0)
|
2015-06-10 23:51:28 +02:00
|
|
|
{
|
2015-07-22 01:45:38 +02:00
|
|
|
actionLinks.push(drag_action.id);
|
2015-06-10 23:51:28 +02:00
|
|
|
}
|
2016-05-11 19:29:58 +02:00
|
|
|
drag_action.set_dragType(['link','calendar']);
|
2015-06-10 23:51:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-05-06 21:03:45 +02:00
|
|
|
/**
|
|
|
|
* Provide specific data to be displayed.
|
2016-01-13 23:07:09 +01:00
|
|
|
* This is a way to set start and end dates, owner and event data in one call.
|
2015-05-06 21:03:45 +02:00
|
|
|
*
|
2016-01-13 23:07:09 +01:00
|
|
|
* Events will be retrieved automatically from the egw.data cache, so there
|
|
|
|
* is no great need to provide them.
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-05-06 21:03:45 +02:00
|
|
|
* @param {Object[]} events Array of events, indexed by date in Ymd format:
|
|
|
|
* {
|
|
|
|
* 20150501: [...],
|
|
|
|
* 20150502: [...]
|
|
|
|
* }
|
|
|
|
* Days should be in order.
|
2016-03-01 17:27:45 +01:00
|
|
|
* {string|number|Date} events.start_date - New start date
|
|
|
|
* {string|number|Date} events.end_date - New end date
|
|
|
|
* {number|number[]|string|string[]} event.owner - Owner ID, which can
|
2016-01-13 23:07:09 +01:00
|
|
|
* 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
|
|
|
*/
|
2016-02-23 22:29:13 +01:00
|
|
|
set_value: function set_value(events)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
|
|
|
if(typeof events !== 'object') return false;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
var use_days_sent = true;
|
|
|
|
|
|
|
|
if(events.start_date)
|
|
|
|
{
|
|
|
|
use_days_sent = false;
|
|
|
|
}
|
|
|
|
if(events.end_date)
|
|
|
|
{
|
|
|
|
use_days_sent = false;
|
|
|
|
}
|
|
|
|
|
2016-01-13 23:07:09 +01:00
|
|
|
this._super.apply(this,arguments);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
if(use_days_sent)
|
|
|
|
{
|
|
|
|
var day_list = Object.keys(events);
|
|
|
|
if(day_list.length)
|
|
|
|
{
|
|
|
|
this.set_start_date(day_list[0]);
|
|
|
|
this.set_end_date(day_list[day_list.length-1]);
|
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-05-01 11:57:48 +02:00
|
|
|
|
2016-04-07 00:23:43 +02:00
|
|
|
// Sub widgets actually get their own data from egw.data, so we'll
|
|
|
|
// stick it there
|
|
|
|
var consolidated = et2_calendar_view.is_consolidated(this.options.owner, this.day_list.length == 1 ? 'day' : 'week');
|
|
|
|
for(var day in events)
|
2016-01-27 18:35:25 +01:00
|
|
|
{
|
2016-04-07 00:23:43 +02:00
|
|
|
var day_list = [];
|
|
|
|
for(var i = 0; i < events[day].length; i++)
|
2016-01-27 18:35:25 +01:00
|
|
|
{
|
2016-04-07 00:23:43 +02:00
|
|
|
day_list.push(events[day][i].row_id);
|
|
|
|
egw.dataStoreUID('calendar::'+events[day][i].row_id, events[day][i]);
|
|
|
|
}
|
|
|
|
// Might be split by user, so we have to check that too
|
|
|
|
for(var i = 0; i < this.options.owner.length; i++)
|
|
|
|
{
|
|
|
|
var owner = consolidated ? this.options.owner : this.options.owner[i];
|
|
|
|
var day_id = app.classes.calendar._daywise_cache_id(day,owner);
|
|
|
|
egw.dataStoreUID(day_id, day_list);
|
|
|
|
if(consolidated) break;
|
2016-01-27 18:35:25 +01:00
|
|
|
}
|
2016-02-23 22:29:13 +01:00
|
|
|
}
|
2015-06-10 23:51:28 +02:00
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
// Reset and calculate instead of just use the keys so we can get the weekend preference
|
|
|
|
this.day_list = [];
|
2016-01-05 21:43:19 +01:00
|
|
|
|
|
|
|
// None of the above changed anything, hide the loader
|
|
|
|
if(!this.update_timer)
|
|
|
|
{
|
2016-04-26 00:09:57 +02:00
|
|
|
window.setTimeout(jQuery.proxy(function() {this.loader.hide();},this),200);
|
2016-01-05 21:43:19 +01:00
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
2015-07-15 18:29:10 +02:00
|
|
|
/**
|
|
|
|
* Set which user owns this. Owner is passed along to the individual
|
|
|
|
* days.
|
|
|
|
*
|
|
|
|
* @param {number|number[]} _owner Account ID
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
set_owner: function(_owner)
|
|
|
|
{
|
|
|
|
var old = this.options.owner || 0;
|
2016-01-26 00:47:58 +01:00
|
|
|
this._super.apply(this, arguments);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-08-19 02:08:22 +02:00
|
|
|
this.owner.set_label('');
|
2015-08-25 02:00:45 +02:00
|
|
|
this.div.removeClass('calendar_TimeGridNoLabel');
|
2015-09-03 00:40:38 +02:00
|
|
|
|
2015-08-12 01:20:24 +02:00
|
|
|
if(typeof _owner == 'string' && isNaN(_owner))
|
|
|
|
{
|
2016-04-01 00:32:13 +02:00
|
|
|
this.set_label('');
|
2015-08-12 01:20:24 +02:00
|
|
|
switch(_owner[0])
|
|
|
|
{
|
2015-12-12 01:07:40 +01:00
|
|
|
case 'c':
|
|
|
|
this.owner.options.application = 'addressbook';
|
|
|
|
this.owner.set_value(_owner.substr(1));
|
|
|
|
break;
|
2015-08-12 01:20:24 +02:00
|
|
|
case 'r':
|
|
|
|
this.owner.options.application = 'resources';
|
|
|
|
this.owner.set_value(_owner.substr(1));
|
|
|
|
break;
|
|
|
|
}
|
2015-08-25 02:00:45 +02:00
|
|
|
|
|
|
|
// Label is empty, but give extra space for the owner name
|
|
|
|
this.div.removeClass('calendar_TimeGridNoLabel');
|
2015-08-12 01:20:24 +02:00
|
|
|
}
|
2016-01-05 21:43:19 +01:00
|
|
|
else if (!_owner || typeof _owner == 'object' && _owner.length)
|
2015-08-12 18:37:02 +02:00
|
|
|
{
|
2015-08-19 02:08:22 +02:00
|
|
|
// Don't show owners if more than one, show week number
|
|
|
|
this.owner.set_value('');
|
|
|
|
if(this.options.start_date)
|
2015-08-12 18:37:02 +02:00
|
|
|
{
|
2016-04-07 00:23:43 +02:00
|
|
|
this.set_label(egw.lang('wk') + ' ' +
|
|
|
|
(app.calendar ? app.calendar.date.week_number(this.options.start_date) : '')
|
|
|
|
);
|
2015-08-12 18:37:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-12 01:20:24 +02:00
|
|
|
else
|
|
|
|
{
|
2016-05-01 11:57:48 +02:00
|
|
|
this.owner.options.application = 'api-accounts';
|
2015-08-12 01:20:24 +02:00
|
|
|
this.owner.set_value(typeof _owner == "string" || typeof _owner == "number" ? _owner : jQuery.extend([],_owner));
|
2016-01-05 21:43:19 +01:00
|
|
|
this.set_label('');
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.getDOMNode(this.owner)).prepend(this.owner.getDOMNode());
|
2015-08-12 01:20:24 +02:00
|
|
|
}
|
2015-07-15 18:29:10 +02:00
|
|
|
|
|
|
|
if(this.isAttached() && (
|
2016-01-19 17:52:05 +01:00
|
|
|
typeof old === "number" && typeof _owner === "number" && old !== this.options.owner ||
|
2015-07-15 18:29:10 +02:00
|
|
|
// Array of ids will not compare as equal
|
2016-01-19 17:52:05 +01:00
|
|
|
((typeof old === 'object' || typeof _owner === 'object') && old.toString() !== _owner.toString()) ||
|
|
|
|
// Strings
|
|
|
|
typeof old === 'string' && ''+old !== ''+this.options.owner
|
2015-07-15 18:29:10 +02:00
|
|
|
))
|
|
|
|
{
|
|
|
|
this.invalidate(true);
|
|
|
|
}
|
|
|
|
},
|
2015-08-19 02:08:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a label for this week
|
|
|
|
*
|
|
|
|
* May conflict with owner, which is displayed when there's only one owner.
|
|
|
|
*
|
|
|
|
* @param {string} label
|
|
|
|
*/
|
|
|
|
set_label: function(label)
|
|
|
|
{
|
|
|
|
this.options.label = label;
|
2015-10-28 16:55:10 +01:00
|
|
|
this._labelContainer.html(label);
|
|
|
|
this.gridHeader.prepend(this._labelContainer);
|
2015-08-25 02:00:45 +02:00
|
|
|
|
|
|
|
// If it's a short label (eg week number), don't give it an extra line
|
|
|
|
// but is empty, but give extra space for a single owner name
|
2016-01-26 23:17:51 +01:00
|
|
|
this.div.toggleClass(
|
|
|
|
'calendar_TimeGridNoLabel',
|
|
|
|
label.trim().length > 0 && label.trim().length < 6 ||
|
|
|
|
this.options.owner.length > 1
|
|
|
|
);
|
2015-08-19 02:08:22 +02:00
|
|
|
},
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-08-19 02:08:22 +02:00
|
|
|
/**
|
|
|
|
* Set how big the time divisions are
|
2016-01-13 23:07:09 +01:00
|
|
|
*
|
|
|
|
* Setting granularity to 0 will remove the time divisions and display
|
|
|
|
* each days events in a list style. This 'gridlist' is not to be confused
|
|
|
|
* with the list view, which uses a nextmatch.
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-08-19 02:08:22 +02:00
|
|
|
* @param {number} minutes
|
|
|
|
*/
|
|
|
|
set_granularity: function(minutes)
|
|
|
|
{
|
2016-01-13 00:55:59 +01:00
|
|
|
// Avoid < 0
|
|
|
|
minutes = Math.max(0,minutes);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-05 21:43:19 +01:00
|
|
|
if(this.options.granularity !== minutes)
|
2015-08-19 02:08:22 +02:00
|
|
|
{
|
2016-01-13 00:55:59 +01:00
|
|
|
if(this.options.granularity === 0 || minutes === 0)
|
|
|
|
{
|
|
|
|
this.options.granularity = minutes;
|
|
|
|
// Need to re-do a bunch to make sure this is propagated
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.options.granularity = minutes;
|
|
|
|
this._drawTimes();
|
|
|
|
}
|
2015-08-19 02:08:22 +02:00
|
|
|
}
|
2016-01-13 00:55:59 +01:00
|
|
|
else if (!this.update_timer)
|
2016-01-05 21:43:19 +01:00
|
|
|
{
|
2016-01-11 21:19:45 +01:00
|
|
|
this.resizeTimes();
|
2016-01-05 21:43:19 +01:00
|
|
|
}
|
2015-08-19 02:08:22 +02:00
|
|
|
},
|
|
|
|
|
2015-07-15 18:29:10 +02:00
|
|
|
/**
|
|
|
|
* Turn on or off the visibility of weekends
|
|
|
|
*
|
|
|
|
* @param {boolean} weekends
|
|
|
|
*/
|
|
|
|
set_show_weekend: function(weekends)
|
|
|
|
{
|
2016-01-05 21:43:19 +01:00
|
|
|
weekends = weekends ? true : false;
|
2015-07-15 18:29:10 +02:00
|
|
|
if(this.options.show_weekend !== weekends)
|
|
|
|
{
|
2016-01-05 21:43:19 +01:00
|
|
|
this.options.show_weekend = weekends;
|
2015-07-15 18:29:10 +02:00
|
|
|
if(this.isAttached())
|
|
|
|
{
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
/**
|
|
|
|
* Call change handler, if set
|
|
|
|
*/
|
|
|
|
change: function() {
|
|
|
|
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-10 23:51: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-10 23:51: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;
|
|
|
|
},
|
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
get_granularity: function()
|
|
|
|
{
|
|
|
|
// get option, or user's preference
|
|
|
|
if(typeof this.options.granularity === 'undefined')
|
|
|
|
{
|
|
|
|
this.options.granularity = egw.preference('interval','calendar') || 30;
|
|
|
|
}
|
|
|
|
return parseInt(this.options.granularity);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-05-06 21:03:45 +02:00
|
|
|
*/
|
|
|
|
click: function(_ev)
|
|
|
|
{
|
|
|
|
var result = true;
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-05-06 21:03:45 +02:00
|
|
|
// Is this click in the event stuff, or in the header?
|
2016-06-02 16:51:15 +02:00
|
|
|
if(_ev.target.dataset.id || jQuery(_ev.target).parents('.calendar_calEvent').length)
|
2015-05-06 21:03:45 +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);
|
|
|
|
}
|
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
var event_node = jQuery(event.event_node);
|
2016-02-23 23:23:01 +01:00
|
|
|
if(event.id && result && !this.disabled && !this.options.readonly &&
|
|
|
|
// Permissions - opening will fail if we try
|
|
|
|
event_node && !(event_node.hasClass('rowNoView'))
|
|
|
|
)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
if(event.widget_id && this.getWidgetById(event.widget_id))
|
|
|
|
{
|
|
|
|
this.getWidgetById(event.widget_id).recur_prompt();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
et2_calendar_event.recur_prompt(event);
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2016-04-04 23:51:06 +02:00
|
|
|
else if (this.gridHeader.is(_ev.target) && _ev.target.dataset ||
|
|
|
|
this._labelContainer.is(_ev.target) && this.gridHeader[0].dataset)
|
2015-09-03 00:40:38 +02:00
|
|
|
{
|
2016-04-04 23:51:06 +02:00
|
|
|
app.calendar.update_state(jQuery.extend(
|
|
|
|
{view: 'week'},
|
|
|
|
this._labelContainer.is(_ev.target) ?
|
|
|
|
this.gridHeader[0].dataset :
|
|
|
|
_ev.target.dataset
|
|
|
|
));
|
2015-09-03 00:40:38 +02:00
|
|
|
}
|
2015-10-06 01:45:51 +02:00
|
|
|
else if (this.dayHeader.has(_ev.target).length)
|
|
|
|
{
|
|
|
|
// Click on a day header - let day deal with it
|
|
|
|
// First child is a selectAccount
|
|
|
|
for(var i = 1; i < this._children.length; i++)
|
|
|
|
{
|
2015-10-29 22:53:47 +01:00
|
|
|
if(this._children[i].header && (
|
|
|
|
this._children[i].header.has(_ev.target).length || this._children[i].header.is(_ev.target))
|
|
|
|
)
|
2015-10-06 01:45:51 +02:00
|
|
|
{
|
|
|
|
return this._children[i].click(_ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 19:10:43 +01:00
|
|
|
// No time grid, click on a day
|
|
|
|
else if (this.options.granularity === 0 &&
|
2016-06-02 16:51:15 +02:00
|
|
|
(jQuery(_ev.target).hasClass('event_wrapper') || jQuery(_ev.target).hasClass('.calendar_calDayCol'))
|
2016-03-09 19:10:43 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
// Default handler to open a new event at the selected time
|
2016-06-02 16:51:15 +02:00
|
|
|
var target = jQuery(_ev.target).hasClass('event_wrapper') ? _ev.target.parentNode : _ev.target;
|
2016-03-09 19:10:43 +01:00
|
|
|
var options = {
|
|
|
|
date: target.dataset.date || this.options.date,
|
|
|
|
hour: target.dataset.hour || this._parent.options.day_start,
|
|
|
|
minute: 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;
|
|
|
|
}
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
/**
|
2016-01-13 23:07:09 +01:00
|
|
|
* Get time from position for drag and drop
|
|
|
|
*
|
|
|
|
* This does not return an actual time on a clock, but finds the closest
|
|
|
|
* time node (.calendar_calAddEvent or day column) to the given position.
|
2016-03-01 17:27:45 +01:00
|
|
|
*
|
2015-06-10 23:51:28 +02:00
|
|
|
* @param {number} x
|
|
|
|
* @param {number} y
|
|
|
|
* @returns {DOMNode[]} time node(s) for the given position
|
|
|
|
*/
|
|
|
|
_get_time_from_position: function(x,y) {
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2015-06-10 23:51:28 +02:00
|
|
|
x = Math.round(x);
|
|
|
|
y = Math.round(y);
|
2016-05-01 11:57:48 +02:00
|
|
|
|
2016-02-11 18:02:06 +01:00
|
|
|
var path = [];
|
|
|
|
var day = null;
|
|
|
|
var time = null;
|
|
|
|
|
|
|
|
var node = document.elementFromPoint(x,y);
|
2016-06-02 16:51:15 +02:00
|
|
|
var $node = jQuery(node);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-04-20 19:25:06 +02:00
|
|
|
// Ignore high level & non-time (grid itself, header parent & week label)
|
2016-04-21 17:32:43 +02:00
|
|
|
if([this.node, this.gridHeader[0], this._labelContainer[0]].indexOf(node) !== -1 ||
|
|
|
|
// Day labels
|
2016-04-28 00:23:06 +02:00
|
|
|
this.gridHeader.has(node).length && !$node.hasClass("calendar_calDayColAllDay") && !$node.hasClass('calendar_calDayColHeader'))
|
2016-04-20 19:25:06 +02:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2016-05-30 17:33:15 +02:00
|
|
|
for(var id in this.gridHover[0].dataset) {
|
|
|
|
delete this.gridHover[0].dataset[id];
|
|
|
|
}
|
2016-02-11 18:02:06 +01:00
|
|
|
while(node && node != this.node && node.tagName != 'BODY' && path.length < 10)
|
|
|
|
{
|
|
|
|
path.push(node);
|
|
|
|
node.style.display = 'none';
|
2016-06-02 16:51:15 +02:00
|
|
|
$node = jQuery(node);
|
2016-02-11 18:02:06 +01:00
|
|
|
if($node.hasClass('calendar_calDayColHeader')) {
|
|
|
|
for(var id in node.dataset) {
|
|
|
|
this.gridHover[0].dataset[id] = node.dataset[id];
|
|
|
|
}
|
|
|
|
this.gridHover.css({
|
|
|
|
position: 'absolute',
|
|
|
|
top: '',
|
|
|
|
bottom: '0px',
|
|
|
|
height: $node.css('padding-bottom')
|
|
|
|
});
|
|
|
|
day = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if($node.hasClass('calendar_calDayCol'))
|
|
|
|
{
|
|
|
|
day = node;
|
|
|
|
this.gridHover
|
|
|
|
.attr('data-date',day.dataset.date);
|
|
|
|
}
|
|
|
|
if($node.hasClass('calendar_calTimeRowTime'))
|
|
|
|
{
|
|
|
|
time = node;
|
|
|
|
this.gridHover
|
|
|
|
.attr('data-hour',time.dataset.hour)
|
|
|
|
.attr('data-minute',time.dataset.minute);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
node = document.elementFromPoint(x,y);
|
|
|
|
}
|
|
|
|
for(var i = 0; i < path.length; i++)
|
|
|
|
{
|
|
|
|
path[i].style.display = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!day)
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
this.gridHover
|
|
|
|
.show()
|
|
|
|
.appendTo(day);
|
|
|
|
if(time)
|
|
|
|
{
|
|
|
|
this.gridHover
|
|
|
|
.height(this.rowHeight)
|
|
|
|
.position({my:'left top', at: 'left top', of: time});
|
|
|
|
}
|
|
|
|
this.gridHover.css('left','');
|
|
|
|
return this.gridHover;
|
2015-05-06 21:03:45 +02:00
|
|
|
},
|
2016-03-01 17:27:45 +01: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) {
|
|
|
|
_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-05-06 21:03:45 +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-02-09 22:02:01 +01:00
|
|
|
/**
|
2016-03-01 17:27:45 +01:00
|
|
|
* @param {boolean} [_too_small=null] Force the widget to act as if it was too small
|
2016-02-09 22:02:01 +01:00
|
|
|
*/
|
|
|
|
resize: function (_too_small)
|
2015-05-06 21:03:45 +02:00
|
|
|
{
|
2016-01-05 21:43:19 +01:00
|
|
|
if(this.disabled || !this.div.is(':visible'))
|
2015-11-05 21:56:13 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-02-11 18:02:06 +01:00
|
|
|
|
2016-02-05 19:17:47 +01:00
|
|
|
/*
|
|
|
|
We expect the timegrid to be in a table with 0 or more other timegrids,
|
|
|
|
1 per row. We want each timegrid to be as large as possible, but space
|
|
|
|
shared equally. Height can't be set to a percentage on the rows, because
|
2016-02-11 18:02:06 +01:00
|
|
|
that doesn't work. However, if any timegrid is too small (1/2 hour < 1 line
|
2016-02-05 19:17:47 +01:00
|
|
|
height), we change to showing only the working hours with no vertical
|
2016-02-11 18:02:06 +01:00
|
|
|
scrollbar. Each week gets as much space as it needs, and all scroll together.
|
2016-02-05 19:17:47 +01:00
|
|
|
*/
|
2015-10-06 01:45:51 +02:00
|
|
|
// How many rows?
|
2016-01-05 21:43:19 +01:00
|
|
|
var rowCount = 0;
|
|
|
|
this._parent.iterateOver(function(widget) {
|
|
|
|
if(!widget.disabled) rowCount++;
|
|
|
|
},this, et2_calendar_timegrid);
|
2015-10-06 01:45:51 +02:00
|
|
|
|
|
|
|
// Take the whole tab height
|
2016-06-02 16:51:15 +02:00
|
|
|
var 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-03-01 17:27:45 +01:00
|
|
|
|
2016-01-06 19:24:45 +01:00
|
|
|
this.options.height = Math.floor(height / rowCount);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-06 19:24:45 +01:00
|
|
|
// Allow for borders & padding
|
2015-10-06 01:45:51 +02:00
|
|
|
this.options.height -= 2*((this.div.outerWidth(true) - this.div.innerWidth()) + parseInt(this.div.parent().css('padding-top')));
|
2016-01-18 21:32:33 +01:00
|
|
|
|
2016-02-05 19:17:47 +01:00
|
|
|
// Calculate how much space is needed, and
|
|
|
|
// if too small be bigger
|
|
|
|
var needed = ((this.day_end - this.day_start) /
|
|
|
|
(this.options.granularity / 60) * parseInt(this.div.css('line-height'))) +
|
|
|
|
this.gridHeader.outerHeight();
|
|
|
|
var too_small = needed > this.options.height && this.options.granularity != 0;
|
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.getInstanceManager().DOMContainer)
|
2016-02-05 19:17:47 +01:00
|
|
|
.css({
|
2016-02-09 22:02:01 +01:00
|
|
|
'overflow-y': too_small || _too_small ? 'auto' : 'hidden',
|
2016-02-05 19:17:47 +01:00
|
|
|
'overflow-x': 'hidden',
|
2016-02-09 22:02:01 +01:00
|
|
|
'height': too_small || _too_small ? height : '100%'
|
2016-02-05 19:17:47 +01:00
|
|
|
});
|
2016-02-09 22:02:01 +01:00
|
|
|
if(too_small || _too_small)
|
2016-02-05 19:17:47 +01:00
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
this.options.height = Math.max(this.options.height, needed);
|
2016-02-09 22:02:01 +01:00
|
|
|
// Set all others to match
|
2016-02-23 22:29:13 +01:00
|
|
|
if(!_too_small && rowCount > 1 && this._parent)
|
2016-02-05 19:17:47 +01:00
|
|
|
{
|
|
|
|
window.setTimeout(jQuery.proxy(function() {
|
2016-02-23 22:29:13 +01:00
|
|
|
if(!this._parent) return;
|
2016-02-05 19:17:47 +01:00
|
|
|
this._parent.iterateOver(function(widget) {
|
2016-02-09 22:02:01 +01:00
|
|
|
if(!widget.disabled) widget.resize(true);
|
2016-02-05 19:17:47 +01:00
|
|
|
},this, et2_calendar_timegrid);
|
|
|
|
},this),1);
|
2016-02-09 22:02:01 +01:00
|
|
|
return;
|
2016-02-05 19:17:47 +01:00
|
|
|
}
|
|
|
|
this.div.addClass('calendar_calTimeGridFixed');
|
|
|
|
}
|
|
|
|
else
|
2016-01-18 21:32:33 +01:00
|
|
|
{
|
2016-02-05 19:17:47 +01:00
|
|
|
this.div.removeClass('calendar_calTimeGridFixed');
|
2016-01-18 21:32:33 +01:00
|
|
|
}
|
2016-01-22 01:22:08 +01:00
|
|
|
this.div.css('height', this.options.height);
|
2016-03-01 17:27:45 +01:00
|
|
|
|
2016-01-22 01:22:08 +01:00
|
|
|
// Re-do time grid
|
2016-02-11 21:30:55 +01:00
|
|
|
if(!this.update_timer)
|
2016-01-22 01:22:08 +01:00
|
|
|
{
|
2016-02-11 18:02:06 +01:00
|
|
|
this.resizeTimes();
|
2015-11-13 00:10:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to resize width, though animations cause problems
|
2016-06-02 16:51:15 +02:00
|
|
|
var total_width = jQuery(this.getInstanceManager().DOMContainer).parent().innerWidth() - this.days.position().left;
|
|
|
|
var day_width = (total_width > 0 ? total_width : jQuery(this.getInstanceManager().DOMContainer).width())/this.day_widgets.length;
|
2015-11-13 00:10:16 +01:00
|
|
|
// update day widgets
|
2015-12-28 23:21:47 +01:00
|
|
|
for(var i = 0; i < this.day_widgets.length; i++)
|
2015-11-13 00:10:16 +01:00
|
|
|
{
|
|
|
|
var day = this.day_widgets[i];
|
|
|
|
|
|
|
|
// Position
|
|
|
|
day.set_left((day_width * i) + 'px');
|
|
|
|
day.set_width(day_width + 'px');
|
2015-10-06 01:45:51 +02:00
|
|
|
}
|
2016-03-31 22:55:41 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up for printing
|
|
|
|
*
|
|
|
|
* @return {undefined|Deferred} Return a jQuery Deferred object if not done setting up
|
|
|
|
* (waiting for data)
|
|
|
|
*/
|
|
|
|
beforePrint: function() {
|
|
|
|
|
|
|
|
if(this.disabled || !this.div.is(':visible'))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-04-20 00:45:43 +02:00
|
|
|
|
2016-04-20 00:57:23 +02:00
|
|
|
var height_check = this.div.height();
|
|
|
|
this.div.css('max-height','17cm');
|
|
|
|
if(this.div.height() != height_check)
|
|
|
|
{
|
|
|
|
this.div.height('17cm');
|
|
|
|
this._resizeTimes();
|
|
|
|
}
|
|
|
|
|
2016-05-10 18:03:26 +02:00
|
|
|
// update day widgets, if not on single day view
|
|
|
|
if(this.day_widgets.length > 1)
|
2016-03-31 22:55:41 +02:00
|
|
|
{
|
2016-05-10 18:03:26 +02:00
|
|
|
var day_width = (100 / this.day_widgets.length);
|
|
|
|
for(var i = 0; i < this.day_widgets.length; i++)
|
|
|
|
{
|
|
|
|
var day = this.day_widgets[i];
|
2016-03-31 22:55:41 +02:00
|
|
|
|
2016-05-10 18:03:26 +02:00
|
|
|
// Position
|
|
|
|
day.set_left((i*day_width) + '%');
|
|
|
|
day.set_width(day_width + '%');
|
|
|
|
// For some reason the column's method does not set it correctly in Chrome
|
|
|
|
day.header[0].style.width = day_width + '%';
|
|
|
|
}
|
2016-03-31 22:55:41 +02:00
|
|
|
}
|
2016-04-06 20:31:13 +02:00
|
|
|
|
|
|
|
// Stop Firefox from scrolling the day to the top - this would break printing in Chrome
|
|
|
|
if (navigator.userAgent.match(/(firefox|safari|iceweasel)/i) && !navigator.userAgent.match(/chrome/i))
|
|
|
|
{
|
2016-04-20 00:45:43 +02:00
|
|
|
var height = this.scrolling.scrollTop() + this.scrolling.height();
|
|
|
|
this.scrolling
|
|
|
|
// Disable scroll event, or it will recalculate out of view events
|
|
|
|
.off('scroll')
|
|
|
|
// Explicitly transform to the correct place
|
|
|
|
.css({
|
|
|
|
'transform': 'translateY(-'+this.scrolling.scrollTop()+'px)',
|
2016-05-10 18:03:26 +02:00
|
|
|
'margin-bottom': '-'+this.scrolling.scrollTop()+'px',
|
2016-04-20 00:45:43 +02:00
|
|
|
'height': height+'px'
|
2016-04-06 20:31:13 +02:00
|
|
|
});
|
2016-04-20 00:57:23 +02:00
|
|
|
this.div.css({'height':'','max-height':''});
|
2016-04-06 20:31:13 +02:00
|
|
|
}
|
2016-03-31 22:55:41 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset after printing
|
|
|
|
*/
|
2016-04-06 20:31:13 +02:00
|
|
|
afterPrint: function() {
|
2016-04-20 00:45:43 +02:00
|
|
|
this.div.css('maxHeight','');
|
2016-04-06 20:31:13 +02:00
|
|
|
this.scrolling.children().css({'transform':'', 'overflow':''});
|
2016-04-20 00:57:23 +02:00
|
|
|
this.div.height(this.options.height);
|
2016-04-20 00:45:43 +02:00
|
|
|
if (navigator.userAgent.match(/(firefox|safari|iceweasel)/i) && !navigator.userAgent.match(/chrome/i))
|
|
|
|
{
|
|
|
|
this._resizeTimes();
|
|
|
|
this.scrolling
|
|
|
|
// Re-enable out-of-view formatting on scroll
|
|
|
|
.on('scroll', jQuery.proxy(this._scroll, this))
|
|
|
|
// Remove translation
|
2016-05-10 18:03:26 +02:00
|
|
|
.css({'transform':'', 'margin-bottom':''});
|
2016-04-20 00:45:43 +02:00
|
|
|
}
|
2016-04-06 20:31:13 +02:00
|
|
|
}
|
2016-03-01 17:27:45 +01:00
|
|
|
});}).call(this);
|
2015-05-06 21:03:45 +02:00
|
|
|
et2_register_widget(et2_calendar_timegrid, ["calendar-timegrid"]);
|