2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2018-09-24 17:22:09 +02:00
|
|
|
ComponentController.$inject = ['$rootScope', '$scope', '$q', '$mdDialog', 'Calendar', 'Component', 'AddressBook', 'Alarm', 'Account', 'stateComponent'];
|
|
|
|
function ComponentController($rootScope, $scope, $q, $mdDialog, Calendar, Component, AddressBook, Alarm, Account, stateComponent) {
|
2015-07-21 14:26:50 +02:00
|
|
|
var vm = this, component;
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.$onInit = function () {
|
|
|
|
this.calendarService = Calendar;
|
|
|
|
this.service = Component;
|
|
|
|
this.component = stateComponent;
|
|
|
|
|
|
|
|
// Put organizer in an array to display it as an mdChip
|
|
|
|
this.organizer = [stateComponent.organizer];
|
|
|
|
};
|
|
|
|
|
|
|
|
this.close = function () {
|
2015-07-21 14:26:50 +02:00
|
|
|
$mdDialog.hide();
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-07-21 14:26:50 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.highPriority = function () {
|
|
|
|
return (this.component &&
|
|
|
|
this.component.priority &&
|
|
|
|
this.component.priority < 5);
|
|
|
|
};
|
2017-06-22 17:55:53 +02:00
|
|
|
|
2015-08-05 22:44:25 +02:00
|
|
|
// Autocomplete cards for attendees
|
2018-08-22 20:52:44 +02:00
|
|
|
this.cardFilter = function ($query) {
|
2016-11-01 14:26:44 +01:00
|
|
|
return AddressBook.$filterAll($query);
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-07-27 22:02:05 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.newMessageWithAllRecipients = function ($event) {
|
|
|
|
var recipients = _.map(this.component.attendees, function(attendee) {
|
2016-06-01 03:56:10 +02:00
|
|
|
return attendee.name + " <" + attendee.email + ">";
|
|
|
|
});
|
|
|
|
_newMessage($event, recipients);
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2016-06-01 03:56:10 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.newMessageWithRecipient = function ($event, name, email) {
|
2016-06-01 03:56:10 +02:00
|
|
|
_newMessage($event, [name + " <" + email + ">"]);
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2016-06-01 03:56:10 +02:00
|
|
|
|
|
|
|
function _newMessage($event, recipients) {
|
|
|
|
Account.$findAll().then(function(accounts) {
|
|
|
|
var account = _.find(accounts, function(o) {
|
|
|
|
if (o.id === 0)
|
|
|
|
return o;
|
2018-08-22 20:52:44 +02:00
|
|
|
}),
|
|
|
|
onCompleteDeferred = $q.defer();
|
2016-06-01 03:56:10 +02:00
|
|
|
|
|
|
|
// We must initialize the Account with its mailbox
|
|
|
|
// list before proceeding with message's creation
|
|
|
|
account.$getMailboxes().then(function(mailboxes) {
|
|
|
|
account.$newMessage().then(function(message) {
|
|
|
|
angular.extend(message.editable, { to: recipients, subject: vm.component.summary });
|
|
|
|
$mdDialog.show({
|
|
|
|
parent: angular.element(document.body),
|
|
|
|
targetEvent: $event,
|
|
|
|
clickOutsideToClose: false,
|
|
|
|
escapeToClose: false,
|
|
|
|
templateUrl: '../Mail/UIxMailEditor',
|
|
|
|
controller: 'MessageEditorController',
|
|
|
|
controllerAs: 'editor',
|
2018-08-22 20:52:44 +02:00
|
|
|
onComplete: function (scope, element) {
|
|
|
|
return onCompleteDeferred.resolve(element);
|
|
|
|
},
|
2016-06-01 03:56:10 +02:00
|
|
|
locals: {
|
2018-09-24 17:22:09 +02:00
|
|
|
stateParent: $scope,
|
2016-06-01 03:56:10 +02:00
|
|
|
stateAccount: account,
|
2018-08-22 20:52:44 +02:00
|
|
|
stateMessage: message,
|
|
|
|
onCompletePromise: function () {
|
|
|
|
return onCompleteDeferred.promise;
|
|
|
|
}
|
2016-06-01 03:56:10 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$event.preventDefault();
|
|
|
|
$event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.edit = function () {
|
|
|
|
var type = (this.component.component == 'vevent')? 'Appointment':'Task';
|
2015-07-21 14:26:50 +02:00
|
|
|
$mdDialog.hide().then(function() {
|
|
|
|
// UI/Templates/SchedulerUI/UIxAppointmentEditorTemplate.wox or
|
|
|
|
// UI/Templates/SchedulerUI/UIxTaskEditorTemplate.wox
|
|
|
|
var templateUrl = 'UIx' + type + 'EditorTemplate';
|
|
|
|
$mdDialog.show({
|
|
|
|
parent: angular.element(document.body),
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
templateUrl: templateUrl,
|
|
|
|
controller: 'ComponentEditorController',
|
|
|
|
controllerAs: 'editor',
|
|
|
|
locals: {
|
|
|
|
stateComponent: vm.component
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-08-05 22:44:25 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.editAllOccurrences = function () {
|
|
|
|
component = Calendar.$get(this.component.pid).$getComponent(this.component.id);
|
2015-08-05 22:44:25 +02:00
|
|
|
component.$futureComponentData.then(function() {
|
|
|
|
vm.component = component;
|
2018-08-22 20:52:44 +02:00
|
|
|
vm.edit();
|
2015-08-05 22:44:25 +02:00
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-08-05 22:44:25 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.reply = function (component) {
|
|
|
|
var c = component || this.component;
|
2015-08-05 22:44:25 +02:00
|
|
|
|
|
|
|
c.$reply().then(function() {
|
2015-11-06 21:12:24 +01:00
|
|
|
$rootScope.$emit('calendars:list');
|
2015-08-05 22:44:25 +02:00
|
|
|
Alarm.getAlarms();
|
2017-02-28 22:13:58 +01:00
|
|
|
$mdDialog.hide();
|
2015-08-05 22:44:25 +02:00
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-08-05 22:44:25 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.replyAllOccurrences = function () {
|
2015-08-05 22:44:25 +02:00
|
|
|
// Retrieve master event
|
2018-08-22 20:52:44 +02:00
|
|
|
component = Calendar.$get(this.component.pid).$getComponent(this.component.id);
|
2015-08-05 22:44:25 +02:00
|
|
|
component.$futureComponentData.then(function() {
|
|
|
|
// Propagate the participant status and alarm to the master event
|
|
|
|
component.reply = vm.component.reply;
|
|
|
|
component.delegatedTo = vm.component.delegatedTo;
|
|
|
|
component.$hasAlarm = vm.component.$hasAlarm;
|
|
|
|
component.alarm = vm.component.alarm;
|
|
|
|
// Send reply to the server
|
2018-08-22 20:52:44 +02:00
|
|
|
vm.reply(component);
|
2015-08-05 22:44:25 +02:00
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-09-28 17:27:20 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.deleteOccurrence = function () {
|
|
|
|
this.component.remove(true).then(function() {
|
2015-11-06 21:12:24 +01:00
|
|
|
$rootScope.$emit('calendars:list');
|
2015-09-28 17:27:20 +02:00
|
|
|
$mdDialog.hide();
|
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-09-28 17:27:20 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.deleteAllOccurrences = function () {
|
|
|
|
this.component.remove().then(function() {
|
2015-11-06 21:12:24 +01:00
|
|
|
$rootScope.$emit('calendars:list');
|
2015-09-28 17:27:20 +02:00
|
|
|
$mdDialog.hide();
|
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-10-02 22:49:08 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.toggleRawSource = function ($event) {
|
|
|
|
Calendar.$$resource.post(this.component.pid + '/' + this.component.id, "raw").then(function(data) {
|
2015-12-04 21:00:58 +01:00
|
|
|
$mdDialog.hide();
|
2015-10-02 22:49:08 +02:00
|
|
|
$mdDialog.show({
|
|
|
|
parent: angular.element(document.body),
|
|
|
|
targetEvent: $event,
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
template: [
|
2016-05-18 20:35:24 +02:00
|
|
|
'<md-dialog flex="40" flex-sm="80" flex-xs="100" aria-label="' + l('View Raw Source') + '">',
|
2015-10-14 16:31:15 +02:00
|
|
|
' <md-dialog-content class="md-dialog-content">',
|
2016-06-08 22:06:58 +02:00
|
|
|
' <pre ng-bind-html="data"></pre>',
|
2015-10-02 22:49:08 +02:00
|
|
|
' </md-dialog-content>',
|
2015-11-27 19:56:31 +01:00
|
|
|
' <md-dialog-actions>',
|
2015-10-02 22:49:08 +02:00
|
|
|
' <md-button ng-click="close()">' + l('Close') + '</md-button>',
|
2015-11-27 19:56:31 +01:00
|
|
|
' </md-dialog-actions>',
|
2015-10-02 22:49:08 +02:00
|
|
|
'</md-dialog>'
|
|
|
|
].join(''),
|
2016-06-08 22:06:58 +02:00
|
|
|
controller: ComponentRawSourceDialogController,
|
|
|
|
locals: { data: data }
|
2015-10-02 22:49:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-06-08 22:06:58 +02:00
|
|
|
ComponentRawSourceDialogController.$inject = ['scope', '$mdDialog', 'data'];
|
|
|
|
function ComponentRawSourceDialogController(scope, $mdDialog, data) {
|
|
|
|
scope.data = data;
|
2015-10-02 22:49:08 +02:00
|
|
|
scope.close = function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2016-03-24 19:53:27 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.copySelectedComponent = function (calendar) {
|
|
|
|
this.component.copyTo(calendar).then(function() {
|
2016-03-24 19:53:27 +01:00
|
|
|
$mdDialog.hide();
|
|
|
|
$rootScope.$emit('calendars:list');
|
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2016-03-24 19:53:27 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.moveSelectedComponent = function (calendar) {
|
|
|
|
this.component.moveTo(calendar).then(function() {
|
2016-03-24 19:53:27 +01:00
|
|
|
$mdDialog.hide();
|
|
|
|
$rootScope.$emit('calendars:list');
|
|
|
|
});
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-10-02 22:49:08 +02:00
|
|
|
}
|
2015-07-21 14:26:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2020-04-16 23:11:50 +02:00
|
|
|
ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$window', '$element', '$mdDialog', '$mdToast', 'sgFocus', 'User', 'CalendarSettings', 'Calendar', 'Component', 'Attendees', 'AddressBook', 'Card', 'Alarm', 'Preferences', 'stateComponent'];
|
|
|
|
function ComponentEditorController($rootScope, $scope, $log, $timeout, $window, $element, $mdDialog, $mdToast, focus, User, CalendarSettings, Calendar, Component, Attendees, AddressBook, Card, Alarm, Preferences, stateComponent) {
|
2019-10-10 20:22:56 +02:00
|
|
|
var vm = this, component, oldStartDate, oldEndDate, oldDueDate, dayStartTime, dayEndTime;
|
2015-07-21 14:26:50 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.$onInit = function () {
|
2019-02-08 14:17:23 +01:00
|
|
|
stateComponent.initAttendees();
|
2018-08-22 20:52:44 +02:00
|
|
|
this.service = Calendar;
|
|
|
|
this.component = stateComponent;
|
|
|
|
this.categories = {};
|
|
|
|
this.showRecurrenceEditor = this.component.$hasCustomRepeat;
|
|
|
|
this.showAttendeesEditor = this.component.attendees && this.component.attendees.length;
|
|
|
|
//this.searchText = null;
|
|
|
|
this.attendeeConflictError = false;
|
|
|
|
this.attendeesEditor = {
|
2019-02-08 14:17:23 +01:00
|
|
|
days: this.component.$attendees.$days,
|
|
|
|
hours: getHours(),
|
|
|
|
containerElement: $element[0].querySelector('#freebusy')
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
|
|
|
|
2019-10-10 20:22:56 +02:00
|
|
|
if (this.component.start) {
|
2018-08-22 20:52:44 +02:00
|
|
|
oldStartDate = new Date(this.component.start.getTime());
|
2019-10-10 20:22:56 +02:00
|
|
|
this.startTime = new Date(this.component.start.getTime());
|
|
|
|
}
|
|
|
|
if (this.component.end) {
|
2018-08-22 20:52:44 +02:00
|
|
|
oldEndDate = new Date(this.component.end.getTime());
|
2019-10-10 20:22:56 +02:00
|
|
|
this.endTime = new Date(this.component.end.getTime());
|
|
|
|
}
|
|
|
|
if (this.component.due) {
|
2018-08-22 20:52:44 +02:00
|
|
|
oldDueDate = new Date(this.component.due.getTime());
|
2019-10-10 20:22:56 +02:00
|
|
|
this.dueTime = new Date(this.component.due.getTime());
|
|
|
|
}
|
2019-02-19 17:49:26 +01:00
|
|
|
|
2019-02-20 16:21:27 +01:00
|
|
|
if (this.component.attendees)
|
|
|
|
$timeout(scrollToStart);
|
2019-10-10 20:22:56 +02:00
|
|
|
|
|
|
|
dayStartTime = parseInt(Preferences.defaults.SOGoDayStartTime);
|
|
|
|
dayEndTime = parseInt(Preferences.defaults.SOGoDayEndTime);
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this.addAttachUrl = function () {
|
|
|
|
var i = this.component.addAttachUrl('');
|
2015-07-01 20:34:35 +02:00
|
|
|
focus('attachUrl_' + i);
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-07-01 20:34:35 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.toggleRecurrenceEditor = function () {
|
|
|
|
this.showRecurrenceEditor = !this.showRecurrenceEditor;
|
|
|
|
this.component.$hasCustomRepeat = this.showRecurrenceEditor;
|
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.toggleAttendeesEditor = function () {
|
|
|
|
this.showAttendeesEditor = !this.showAttendeesEditor;
|
|
|
|
};
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.recurrenceMonthDaysAreRequired = function () {
|
|
|
|
return this.component &&
|
|
|
|
this.component.repeat.frequency == 'monthly' &&
|
|
|
|
this.component.repeat.month.type == 'bymonthday';
|
|
|
|
};
|
2017-02-28 22:13:58 +01:00
|
|
|
|
2019-10-30 16:04:59 +01:00
|
|
|
this.frequencies = function () {
|
|
|
|
return _.filter($window.repeatFrequencies, function (frequency) {
|
|
|
|
return frequency[0] != 'custom' || vm.component.repeat.frequency == 'custom';
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.changeFrequency = function () {
|
|
|
|
if (this.component.repeat.frequency == 'custom')
|
|
|
|
this.showRecurrenceEditor = true;
|
|
|
|
};
|
2017-12-15 22:17:51 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.changeCalendar = function () {
|
|
|
|
var updateRequired = (this.component.attendees && this.component.attendees.length > 0);
|
2017-07-27 22:50:03 +02:00
|
|
|
if (updateRequired)
|
2018-08-22 20:52:44 +02:00
|
|
|
this.component.initOrganizer(Calendar.$get(this.component.destinationCalendar));
|
|
|
|
};
|
2017-07-27 22:50:03 +02:00
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
// Autocomplete cards for attendees
|
2018-08-22 20:52:44 +02:00
|
|
|
this.cardFilter = function ($query) {
|
2015-08-05 22:44:25 +02:00
|
|
|
AddressBook.$filterAll($query);
|
|
|
|
return AddressBook.$cards;
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.addAttendee = function (card, partial) {
|
|
|
|
var initOrganizer = (!this.component.attendees || this.component.attendees.length === 0),
|
|
|
|
destinationCalendar = Calendar.$get(this.component.destinationCalendar),
|
2017-07-27 22:50:03 +02:00
|
|
|
options = initOrganizer? { organizerCalendar: destinationCalendar } : {};
|
2017-11-17 17:34:18 +01:00
|
|
|
var emailRE = /([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i,
|
|
|
|
i, address;
|
2018-08-22 20:52:44 +02:00
|
|
|
if (partial) options.partial = partial;
|
2017-11-17 17:34:18 +01:00
|
|
|
|
|
|
|
function createCard(str) {
|
|
|
|
var match = str.match(emailRE),
|
|
|
|
email = match[0],
|
|
|
|
name = str.replace(new RegExp(" *<?" + email + ">? *"), '');
|
|
|
|
vm.showAttendeesEditor |= initOrganizer;
|
|
|
|
vm.searchText = '';
|
|
|
|
return new Card({ c_cn: _.trim(name, ' "'), emails: [{ value: email }] });
|
|
|
|
}
|
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
if (angular.isString(card)) {
|
|
|
|
// User pressed "Enter" in search field, adding a non-matching card
|
2017-11-17 17:34:18 +01:00
|
|
|
// Examples that are handled:
|
|
|
|
// Smith, John <john@smith.com>
|
|
|
|
// <john@appleseed.com>;<foo@bar.com>
|
|
|
|
// foo@bar.com abc@xyz.com
|
|
|
|
address = '';
|
|
|
|
for (i = 0; i < card.length; i++) {
|
|
|
|
if ((card.charCodeAt(i) == 9 || // tab
|
|
|
|
card.charCodeAt(i) == 32 || // space
|
|
|
|
card.charCodeAt(i) == 44 || // ,
|
|
|
|
card.charCodeAt(i) == 59) && // ;
|
|
|
|
emailRE.test(address)) {
|
2019-02-08 14:17:23 +01:00
|
|
|
this.component.$attendees.add(createCard(address), options);
|
2017-11-17 17:34:18 +01:00
|
|
|
address = '';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
address += card.charAt(i);
|
|
|
|
}
|
2015-06-05 22:20:57 +02:00
|
|
|
}
|
2017-11-17 17:34:18 +01:00
|
|
|
if (address)
|
2019-02-08 14:17:23 +01:00
|
|
|
this.component.$attendees.add(createCard(address), options);
|
2015-06-05 22:20:57 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-02-08 14:17:23 +01:00
|
|
|
this.component.$attendees.add(card, options);
|
2018-08-22 20:52:44 +02:00
|
|
|
this.showAttendeesEditor |= initOrganizer;
|
2015-06-04 22:08:45 +02:00
|
|
|
}
|
2019-02-08 14:17:23 +01:00
|
|
|
|
|
|
|
$timeout(scrollToStart);
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2019-02-08 14:17:23 +01:00
|
|
|
function scrollToStart() {
|
2019-08-27 22:33:10 +02:00
|
|
|
var dayElement, scrollLeft;
|
|
|
|
if (!vm.attendeesEditor.containerElement) {
|
|
|
|
vm.attendeesEditor.containerElement = $element[0].querySelector('#freebusy');
|
|
|
|
}
|
2019-10-07 21:58:09 +02:00
|
|
|
dayElement = $element[0].querySelector('#freebusy_day_' + vm.component.start.getDayString());
|
|
|
|
if (vm.attendeesEditor.containerElement && dayElement) {
|
2019-08-27 22:33:10 +02:00
|
|
|
scrollLeft = dayElement.offsetLeft - vm.attendeesEditor.containerElement.offsetLeft;
|
|
|
|
vm.attendeesEditor.containerElement.scrollLeft = scrollLeft;
|
|
|
|
}
|
2019-02-08 14:17:23 +01:00
|
|
|
}
|
|
|
|
|
2019-08-27 22:33:10 +02:00
|
|
|
this.expandAttendee = function (attendee) {
|
|
|
|
if (attendee.members.length > 0) {
|
|
|
|
this.component.$attendees.remove(attendee);
|
|
|
|
_.forEach(attendee.members, function (member) {
|
|
|
|
vm.component.$attendees.add(member);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.removeAttendee = function (attendee, form) {
|
2019-02-08 14:17:23 +01:00
|
|
|
this.component.$attendees.remove(attendee);
|
2019-12-03 16:34:47 +01:00
|
|
|
if (this.component.$attendees.getLength() === 0) {
|
2018-08-22 20:52:44 +02:00
|
|
|
this.showAttendeesEditor = false;
|
2019-12-03 16:34:47 +01:00
|
|
|
this.component.$attendees.remove(this.component.organizer);
|
|
|
|
}
|
2016-11-04 19:37:23 +01:00
|
|
|
form.$setDirty();
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2016-02-29 19:59:31 +01:00
|
|
|
|
2019-07-04 21:10:41 +02:00
|
|
|
this.defaultIconForAttendee = function (attendee) {
|
|
|
|
if (attendee.isGroup) {
|
|
|
|
return 'group';
|
|
|
|
} else if (attendee.isResource) {
|
|
|
|
return 'meeting_room';
|
|
|
|
} else {
|
|
|
|
return 'person';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-08 14:17:23 +01:00
|
|
|
this.nextSlot = function () {
|
|
|
|
findSlot(1);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.previousSlot = function () {
|
|
|
|
findSlot(-1);
|
|
|
|
};
|
|
|
|
|
|
|
|
function findSlot(direction) {
|
|
|
|
vm.component.$attendees.findSlot(direction).then(function () {
|
2020-04-16 23:11:50 +02:00
|
|
|
}).catch(function (err) {
|
|
|
|
vm.component.start = new Date(vm.component.start.getTime() + 1); // trigger update in sgFreeBusy
|
|
|
|
$timeout(scrollToStart);
|
|
|
|
$mdToast.show({
|
|
|
|
template: [
|
|
|
|
'<md-toast>',
|
|
|
|
' <div class="md-toast-content">',
|
|
|
|
' <md-icon class="md-warn md-hue-1">error_outline</md-icon>',
|
|
|
|
' <span flex>' + err + '</span>',
|
|
|
|
' </div>',
|
|
|
|
'</md-toast>'
|
|
|
|
].join(''),
|
|
|
|
hideDelay: 5000,
|
|
|
|
position: 'top right'
|
|
|
|
});
|
|
|
|
}).finally(function () {
|
2019-02-08 14:17:23 +01:00
|
|
|
$timeout(scrollToStart);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.priorityLevel = function () {
|
|
|
|
if (this.component && this.component.priority) {
|
|
|
|
if (this.component.priority > 5)
|
2017-06-22 17:55:53 +02:00
|
|
|
return l('low'); // 6-7-8-9
|
2018-08-22 20:52:44 +02:00
|
|
|
else if (this.component.priority > 4)
|
2017-06-22 17:55:53 +02:00
|
|
|
return l('normal'); // 5
|
2016-04-21 23:02:07 +02:00
|
|
|
else
|
2017-06-22 17:55:53 +02:00
|
|
|
return l('high'); // 1-2-3-4
|
2016-04-21 23:02:07 +02:00
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2016-04-21 23:02:07 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.changeAlarmRelation = function (form) {
|
2019-10-02 15:20:35 +02:00
|
|
|
if (form.alarmRelation) {
|
|
|
|
if (this.component.type == 'task' && this.component.$hasAlarm &&
|
|
|
|
(this.component.start || this.component.due) &&
|
|
|
|
((!this.component.start && this.component.alarm.relation == 'START') ||
|
|
|
|
(!this.component.due && this.component.alarm.relation == 'END'))) {
|
|
|
|
form.alarmRelation.$setValidity('alarm', false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
form.alarmRelation.$setValidity('alarm', true);
|
|
|
|
}
|
2018-03-06 22:35:08 +01:00
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2018-03-06 22:35:08 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.onAlarmChange = function (form) {
|
|
|
|
if (this.component.type !== 'task') {
|
2018-04-17 17:20:19 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
if (!this.component.start && this.component.alarm.relation == 'START') {
|
|
|
|
this.component.alarm.relation = 'END';
|
|
|
|
} else if (!this.component.due && this.component.alarm.relation == 'END') {
|
|
|
|
this.component.alarm.relation = 'START';
|
2018-04-17 17:20:19 +02:00
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
this.changeAlarmRelation(form);
|
|
|
|
};
|
2018-04-17 17:20:19 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.save = function (form, options) {
|
|
|
|
this.changeAlarmRelation(form);
|
2015-05-06 04:06:13 +02:00
|
|
|
if (form.$valid) {
|
2018-08-22 20:52:44 +02:00
|
|
|
this.component.$save(options)
|
2015-05-06 04:06:13 +02:00
|
|
|
.then(function(data) {
|
2015-11-06 21:12:24 +01:00
|
|
|
$rootScope.$emit('calendars:list');
|
2015-07-28 17:54:49 +02:00
|
|
|
Alarm.getAlarms();
|
2016-11-04 19:29:54 +01:00
|
|
|
$mdDialog.hide();
|
2016-02-15 21:58:58 +01:00
|
|
|
}, function(response) {
|
2017-02-28 22:13:58 +01:00
|
|
|
if (response.status == CalendarSettings.ConflictHTTPErrorCode &&
|
|
|
|
_.isObject(response.data.message))
|
2016-02-15 21:58:58 +01:00
|
|
|
vm.attendeeConflictError = response.data.message;
|
2017-02-28 22:13:58 +01:00
|
|
|
else
|
2018-09-24 17:22:09 +02:00
|
|
|
vm.edit(form);
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.reset = function (form) {
|
|
|
|
this.component.$reset();
|
2016-11-04 19:29:54 +01:00
|
|
|
form.$setPristine();
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2016-11-04 19:29:54 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.cancel = function (form) {
|
|
|
|
this.reset(form);
|
|
|
|
if (this.component.isNew) {
|
2015-05-06 04:06:13 +02:00
|
|
|
// Cancelling the creation of a component
|
2018-08-22 20:52:44 +02:00
|
|
|
this.component = null;
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2017-11-17 17:34:18 +01:00
|
|
|
$mdDialog.hide();
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2018-09-24 17:22:09 +02:00
|
|
|
this.edit = function (form) {
|
|
|
|
this.attendeeConflictError = false;
|
2016-11-04 19:29:54 +01:00
|
|
|
form.$setPristine();
|
|
|
|
form.$setDirty();
|
2018-09-24 17:22:09 +02:00
|
|
|
};
|
2016-11-04 19:29:54 +01:00
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
function getHours() {
|
|
|
|
var hours = [];
|
|
|
|
for (var i = 0; i <= 23; i++) {
|
|
|
|
hours.push(i.toString());
|
|
|
|
}
|
|
|
|
return hours;
|
|
|
|
}
|
2015-10-30 13:38:19 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.addStartDate = function (form) {
|
|
|
|
this.component.$addStartDate();
|
|
|
|
oldStartDate = new Date(this.component.start.getTime());
|
2019-10-10 20:22:56 +02:00
|
|
|
this.startTime = new Date(this.component.start.getTime());
|
2018-08-22 20:52:44 +02:00
|
|
|
if (!this.component.due) {
|
|
|
|
this.component.alarm.relation = 'START';
|
2018-03-06 22:35:08 +01:00
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
this.changeAlarmRelation(form);
|
2019-10-10 20:22:56 +02:00
|
|
|
form.$setDirty();
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2018-03-06 22:35:08 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.removeStartDate = function (form) {
|
|
|
|
this.component.$deleteStartDate();
|
|
|
|
if (this.component.due) {
|
|
|
|
this.component.alarm.relation = 'END';
|
2018-03-06 22:35:08 +01:00
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
this.changeAlarmRelation(form);
|
2019-10-10 20:22:56 +02:00
|
|
|
form.$setDirty();
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-10-30 13:38:19 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.addDueDate = function (form) {
|
|
|
|
this.component.$addDueDate();
|
|
|
|
oldDueDate = new Date(this.component.due.getTime());
|
2019-10-10 20:22:56 +02:00
|
|
|
this.dueTime = new Date(this.component.due.getTime());
|
2018-08-22 20:52:44 +02:00
|
|
|
if (!this.component.start) {
|
|
|
|
this.component.alarm.relation = 'END';
|
2018-03-06 22:35:08 +01:00
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
this.changeAlarmRelation(form);
|
2019-10-10 20:22:56 +02:00
|
|
|
form.$setDirty();
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2018-03-06 22:35:08 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.removeDueDate = function (form) {
|
|
|
|
this.component.$deleteDueDate();
|
|
|
|
if (this.component.start) {
|
|
|
|
this.component.alarm.relation = 'START';
|
2018-03-06 22:35:08 +01:00
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
this.changeAlarmRelation(form);
|
2019-10-10 20:22:56 +02:00
|
|
|
form.$setDirty();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.adjustAllDay = function () {
|
|
|
|
if (!this.component.isAllDay) {
|
|
|
|
this.component.start.setHours(dayStartTime);
|
|
|
|
this.component.start.setMinutes(0);
|
|
|
|
this.startTime = new Date(this.component.start.getTime());
|
|
|
|
oldStartDate = new Date(this.component.start.getTime());
|
|
|
|
this.component.end.setHours(dayEndTime);
|
|
|
|
this.component.end.setMinutes(0);
|
|
|
|
this.endTime = new Date(this.component.end.getTime());
|
|
|
|
oldEndDate = new Date(this.component.end.getTime());
|
|
|
|
this.component.delta = this.component.start.minutesTo(this.component.end);
|
|
|
|
}
|
|
|
|
this.component.$attendees.updateFreeBusyCoverage();
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-10-30 13:38:19 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.adjustStartTime = function () {
|
2019-10-10 20:22:56 +02:00
|
|
|
var delta;
|
|
|
|
if (this.component.start && this.startTime) {
|
|
|
|
// Update the component start date
|
|
|
|
this.component.start.setHours(this.startTime.getHours());
|
|
|
|
this.component.start.setMinutes(this.startTime.getMinutes());
|
2016-05-09 21:53:19 +02:00
|
|
|
// Preserve the delta between the start and end dates
|
2018-08-22 20:52:44 +02:00
|
|
|
delta = oldStartDate.valueOf() - this.component.start.valueOf();
|
2016-05-09 21:53:19 +02:00
|
|
|
if (delta !== 0) {
|
2018-08-22 20:52:44 +02:00
|
|
|
oldStartDate = new Date(this.component.start.getTime());
|
|
|
|
if (this.component.type === 'appointment') {
|
|
|
|
this.component.end = new Date(this.component.start.getTime());
|
|
|
|
this.component.end.addMinutes(this.component.delta);
|
2019-10-10 20:22:56 +02:00
|
|
|
this.endTime = new Date(this.component.end.getTime());
|
2018-08-22 20:52:44 +02:00
|
|
|
oldEndDate = new Date(this.component.end.getTime());
|
2016-05-09 21:53:19 +02:00
|
|
|
}
|
|
|
|
updateFreeBusy();
|
2015-10-30 13:38:19 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-10-30 13:38:19 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.adjustEndTime = function () {
|
2019-10-10 20:22:56 +02:00
|
|
|
var delta;
|
|
|
|
if (this.component.end && this.endTime) {
|
|
|
|
// Update the component start date
|
|
|
|
this.component.end.setHours(this.endTime.getHours());
|
|
|
|
this.component.end.setMinutes(this.endTime.getMinutes());
|
2016-05-09 21:53:19 +02:00
|
|
|
// The end date must be after the start date
|
2019-10-10 20:22:56 +02:00
|
|
|
delta = oldEndDate.valueOf() - this.component.end.valueOf();
|
2016-05-09 21:53:19 +02:00
|
|
|
if (delta !== 0) {
|
2018-08-22 20:52:44 +02:00
|
|
|
delta = this.component.start.minutesTo(this.component.end);
|
2019-10-10 20:22:56 +02:00
|
|
|
if (delta < 0) {
|
2018-08-22 20:52:44 +02:00
|
|
|
this.component.end = new Date(oldEndDate.getTime());
|
2019-10-10 20:22:56 +02:00
|
|
|
this.endTime = new Date(this.component.end.getTime());
|
|
|
|
}
|
2016-05-09 21:53:19 +02:00
|
|
|
else {
|
2018-08-22 20:52:44 +02:00
|
|
|
this.component.delta = delta;
|
|
|
|
oldEndDate = new Date(this.component.end.getTime());
|
2016-05-09 21:53:19 +02:00
|
|
|
}
|
|
|
|
updateFreeBusy();
|
2015-12-17 20:00:56 +01:00
|
|
|
}
|
2015-10-30 13:38:19 +01:00
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-10-30 13:38:19 +01:00
|
|
|
|
2018-08-22 20:52:44 +02:00
|
|
|
this.adjustDueTime = function () {
|
2019-10-10 20:22:56 +02:00
|
|
|
if (this.component.due && this.dueTime) {
|
|
|
|
this.component.due.setHours(this.dueTime.getHours());
|
|
|
|
this.component.due.setMinutes(this.dueTime.getMinutes());
|
|
|
|
oldDueDate = new Date(this.component.due.getTime());
|
|
|
|
}
|
2018-08-22 20:52:44 +02:00
|
|
|
};
|
2015-11-13 16:46:32 +01:00
|
|
|
|
|
|
|
function updateFreeBusy() {
|
2019-02-08 14:17:23 +01:00
|
|
|
vm.component.$attendees.updateFreeBusyCoverage();
|
|
|
|
vm.component.$attendees.updateFreeBusy();
|
2019-10-04 15:54:29 +02:00
|
|
|
$timeout(scrollToStart);
|
2015-11-13 16:46:32 +01:00
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
2015-08-05 22:44:25 +02:00
|
|
|
.module('SOGo.SchedulerUI')
|
2015-07-21 14:26:50 +02:00
|
|
|
.controller('ComponentController', ComponentController)
|
|
|
|
.controller('ComponentEditorController', ComponentEditorController);
|
2015-05-06 04:06:13 +02:00
|
|
|
})();
|