2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sgCalendarDayBlock - An event block to be displayed in a week
|
2015-11-06 21:12:24 +01:00
|
|
|
* @memberof SOGo.SchedulerUI
|
2015-05-06 04:06:13 +02:00
|
|
|
* @restrict element
|
|
|
|
* @param {object} sgBlock - the event block definition
|
2015-07-29 02:45:46 +02:00
|
|
|
* @param {function} sgClick - the function to call when clicking on a block.
|
|
|
|
* Two variables are available: clickEvent (the event that triggered the mouse click),
|
|
|
|
* and clickComponent (a Component object)
|
|
|
|
*
|
2015-05-06 04:06:13 +02:00
|
|
|
* @example:
|
|
|
|
|
|
|
|
<sg-calendar-day-block
|
2015-07-29 02:45:46 +02:00
|
|
|
ng-repeat="block in blocks[day]"
|
|
|
|
sg-block="block"
|
|
|
|
sg-click="open(clickEvent, clickComponent)" />
|
2015-05-06 04:06:13 +02:00
|
|
|
*/
|
2015-11-06 21:12:24 +01:00
|
|
|
sgCalendarDayBlock.$inject = ['CalendarSettings'];
|
|
|
|
function sgCalendarDayBlock(CalendarSettings) {
|
2015-05-06 04:06:13 +02:00
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
2015-07-29 02:45:46 +02:00
|
|
|
block: '=sgBlock',
|
|
|
|
clickBlock: '&sgClick'
|
2015-05-06 04:06:13 +02:00
|
|
|
},
|
|
|
|
replace: true,
|
2016-04-22 16:50:19 +02:00
|
|
|
template: template,
|
|
|
|
link: link
|
|
|
|
};
|
|
|
|
|
|
|
|
function template(tElem, tAttrs) {
|
|
|
|
var p = _.has(tAttrs, 'sgCalendarGhost')? '' : '::';
|
|
|
|
|
|
|
|
return [
|
2015-11-20 19:30:26 +01:00
|
|
|
'<div class="sg-event"',
|
2015-11-06 21:12:24 +01:00
|
|
|
// Add a class while dragging
|
|
|
|
' ng-class="{\'sg-event--dragging\': block.dragging}">',
|
2015-11-20 19:30:26 +01:00
|
|
|
' <div class="eventInside"',
|
|
|
|
' ng-click="clickBlock({clickEvent: $event, clickComponent: block.component})">',
|
2015-11-14 20:29:21 +01:00
|
|
|
// Categories color stripes
|
2016-04-22 16:50:19 +02:00
|
|
|
' <div class="sg-category" ng-repeat="category in '+p+'block.component.categories"',
|
2016-09-21 21:08:10 +02:00
|
|
|
' ng-class="'+p+'(\'bg-category\' + category)"',
|
|
|
|
' ng-style="'+p+'{ right: ($index * 3) + \'px\' }"></div>',
|
2016-04-21 23:02:07 +02:00
|
|
|
' <div class="text">',
|
2016-04-22 16:50:19 +02:00
|
|
|
// Priority
|
|
|
|
' <span ng-show="'+p+'block.component.c_priority" class="sg-priority">{{'+p+'block.component.c_priority}}</span>',
|
|
|
|
// Summary
|
|
|
|
' {{ '+p+'block.component.summary }}',
|
2015-11-06 21:12:24 +01:00
|
|
|
' <span class="icons">',
|
2015-11-13 16:48:27 +01:00
|
|
|
// Component is reccurent
|
2016-04-22 16:50:19 +02:00
|
|
|
' <md-icon ng-if="'+p+'block.component.occurrenceId" class="material-icons icon-repeat"></md-icon>',
|
2015-11-06 21:12:24 +01:00
|
|
|
// Component has an alarm
|
2016-04-22 16:50:19 +02:00
|
|
|
' <md-icon ng-if="'+p+'block.component.c_nextalarm" class="material-icons icon-alarm"></md-icon>',
|
2015-11-06 21:12:24 +01:00
|
|
|
// Component is confidential
|
2016-05-24 17:07:04 +02:00
|
|
|
' <md-icon ng-if="'+p+'block.component.c_classification == 2" class="material-icons icon-visibility-off"></md-icon>',
|
2015-11-06 21:12:24 +01:00
|
|
|
// Component is private
|
2016-05-24 17:07:04 +02:00
|
|
|
' <md-icon ng-if="'+p+'block.component.c_classification == 1" class="material-icons icon-vpn-key"></md-icon>',
|
2015-11-06 21:12:24 +01:00
|
|
|
' </span>',
|
2015-11-14 20:29:21 +01:00
|
|
|
// Location
|
2016-04-22 16:50:19 +02:00
|
|
|
' <div class="secondary" ng-if="'+p+'block.component.c_location">',
|
2017-10-16 16:26:08 +02:00
|
|
|
' <md-icon>place</md-icon> <span ng-bind="'+p+'block.component.c_location"></span>',
|
2015-11-14 20:29:21 +01:00
|
|
|
' </div>',
|
2015-05-06 04:06:13 +02:00
|
|
|
' </div>',
|
2015-11-06 21:12:24 +01:00
|
|
|
' </div>',
|
2016-01-22 02:46:04 +01:00
|
|
|
' <div class="ghostStartHour" ng-if="block.startHour">{{ block.startHour }}</div>',
|
|
|
|
' <div class="ghostEndHour" ng-if="block.endHour">{{ block.endHour }}</div>',
|
2015-05-06 04:06:13 +02:00
|
|
|
'</div>'
|
2016-04-22 16:50:19 +02:00
|
|
|
].join('');
|
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
function link(scope, iElement, attrs) {
|
2015-11-06 21:12:24 +01:00
|
|
|
var pc, left, right;
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2016-04-22 16:50:19 +02:00
|
|
|
if (!_.has(attrs, 'sgCalendarGhost')) {
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2016-04-22 16:50:19 +02:00
|
|
|
// Compute overlapping (2%)
|
|
|
|
pc = 100 / scope.block.siblings;
|
|
|
|
left = scope.block.position * pc;
|
|
|
|
right = 100 - (scope.block.position + 1) * pc;
|
|
|
|
if (pc < 100) {
|
|
|
|
if (left > 0)
|
|
|
|
left -= 2;
|
|
|
|
if (right > 0)
|
|
|
|
right -= 2;
|
|
|
|
}
|
2015-09-19 03:08:01 +02:00
|
|
|
|
2016-04-22 16:50:19 +02:00
|
|
|
// Add some padding (2%)
|
|
|
|
if (left === 0)
|
|
|
|
left = 2;
|
|
|
|
if (right === 0)
|
|
|
|
right = 2;
|
|
|
|
|
|
|
|
// Set position
|
|
|
|
iElement.css('left', left + '%');
|
|
|
|
iElement.css('right', right + '%');
|
|
|
|
if (!scope.block.component || !scope.block.component.c_isallday) {
|
|
|
|
iElement.addClass('starts' + scope.block.start);
|
|
|
|
iElement.addClass('lasts' + scope.block.length);
|
|
|
|
}
|
2015-11-06 21:12:24 +01:00
|
|
|
|
2016-04-22 16:50:19 +02:00
|
|
|
// Add class for user's participation state
|
|
|
|
if (scope.block.userState)
|
|
|
|
iElement.addClass('sg-event--' + scope.block.userState);
|
|
|
|
|
|
|
|
if (scope.block.component) {
|
2016-04-22 18:22:02 +02:00
|
|
|
// Set background color
|
2016-04-22 16:50:19 +02:00
|
|
|
iElement.addClass('bg-folder' + scope.block.component.pid);
|
|
|
|
iElement.addClass('contrast-bdr-folder' + scope.block.component.pid);
|
2016-04-22 18:22:02 +02:00
|
|
|
|
|
|
|
// Add class for transparency
|
|
|
|
if (scope.block.component.c_isopaque === 0)
|
|
|
|
iElement.addClass('sg-event--transparent');
|
2016-07-05 15:08:51 +02:00
|
|
|
|
|
|
|
// Add class for cancelled event
|
|
|
|
if (scope.block.component.c_status === 0)
|
|
|
|
iElement.addClass('sg-event--cancelled');
|
2016-04-22 16:50:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.SchedulerUI')
|
|
|
|
.directive('sgCalendarDayBlock', sgCalendarDayBlock);
|
|
|
|
})();
|