2019-08-26 22:38:00 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sgFreebusy - A directive that watches some attributes of a component. Any child component
|
|
|
|
* should depends on this directive and extend the 'onUpdate' method instead of creating new
|
|
|
|
* independent watchers.
|
|
|
|
* @memberof SOGo.SchedulerUI
|
|
|
|
*/
|
|
|
|
function sgFreebusy() {
|
|
|
|
return {
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {},
|
|
|
|
bindToController: {
|
|
|
|
component: '=sgComponent'
|
|
|
|
},
|
|
|
|
controller: sgFreebusyController
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
sgFreebusyController.$inject = ['$scope', '$element', '$q'];
|
|
|
|
function sgFreebusyController($scope, $element, $q) {
|
|
|
|
var $ctrl = this;
|
|
|
|
|
|
|
|
this.$onInit = function () {
|
|
|
|
var watchedAttrs = ['start', 'end', 'attendees'];
|
|
|
|
|
|
|
|
$scope.$watch(
|
|
|
|
function() {
|
2019-08-27 22:33:10 +02:00
|
|
|
return $ctrl.component? {
|
|
|
|
start: $ctrl.component.start,
|
|
|
|
end: $ctrl.component.end,
|
|
|
|
attendees: _.map($ctrl.component.attendees, 'email')
|
|
|
|
} : null;
|
2019-08-26 22:38:00 +02:00
|
|
|
},
|
2019-08-27 22:33:10 +02:00
|
|
|
function(newAttrs, oldAttrs) {
|
2019-10-07 17:10:17 +02:00
|
|
|
if (newAttrs && newAttrs.attendees) {
|
2019-08-27 22:33:10 +02:00
|
|
|
// Attendees have changed
|
2019-08-26 22:38:00 +02:00
|
|
|
$q.all(_.values($ctrl.component.$attendees.$futureFreebusyData)).then(function() {
|
|
|
|
$ctrl.onUpdate();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true // compare for object equality
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.onUpdate = function () {
|
|
|
|
// console.debug('dates or attendees changed -- refresh freebusy');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.SchedulerUI')
|
|
|
|
.directive('sgFreebusy', sgFreebusy);
|
|
|
|
})();
|