2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-06-01 03:56:10 +02:00
|
|
|
ComponentController.$inject = ['$rootScope', '$mdDialog', 'Calendar', 'Component', 'AddressBook', 'Alarm', 'Account', 'stateComponent'];
|
|
|
|
function ComponentController($rootScope, $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
|
|
|
|
2016-03-24 19:53:27 +01:00
|
|
|
vm.calendarService = Calendar;
|
2016-03-01 20:30:36 +01:00
|
|
|
vm.service = Component;
|
2015-07-21 14:26:50 +02:00
|
|
|
vm.component = stateComponent;
|
|
|
|
vm.close = close;
|
2015-08-05 22:44:25 +02:00
|
|
|
vm.cardFilter = cardFilter;
|
2016-06-01 03:56:10 +02:00
|
|
|
vm.newMessageWithAllRecipients = newMessageWithAllRecipients;
|
|
|
|
vm.newMessageWithRecipient = newMessageWithRecipient;
|
2015-07-21 14:26:50 +02:00
|
|
|
vm.edit = edit;
|
2015-07-27 22:02:05 +02:00
|
|
|
vm.editAllOccurrences = editAllOccurrences;
|
2015-08-05 22:44:25 +02:00
|
|
|
vm.reply = reply;
|
|
|
|
vm.replyAllOccurrences = replyAllOccurrences;
|
2015-09-28 17:27:20 +02:00
|
|
|
vm.deleteOccurrence = deleteOccurrence;
|
|
|
|
vm.deleteAllOccurrences = deleteAllOccurrences;
|
2015-12-04 21:00:58 +01:00
|
|
|
vm.toggleRawSource = toggleRawSource;
|
2016-03-24 19:53:27 +01:00
|
|
|
vm.copySelectedComponent = copySelectedComponent;
|
|
|
|
vm.moveSelectedComponent = moveSelectedComponent;
|
2015-07-21 14:26:50 +02:00
|
|
|
|
|
|
|
// Load all attributes of component
|
|
|
|
if (angular.isUndefined(vm.component.$futureComponentData)) {
|
2015-11-06 21:12:24 +01:00
|
|
|
component = Calendar.$get(vm.component.pid).$getComponent(vm.component.id, vm.component.occurrenceId);
|
2015-07-21 14:26:50 +02:00
|
|
|
component.$futureComponentData.then(function() {
|
|
|
|
vm.component = component;
|
2015-08-05 22:44:25 +02:00
|
|
|
vm.organizer = [vm.component.organizer];
|
2015-07-21 14:26:50 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
}
|
|
|
|
|
2015-08-05 22:44:25 +02:00
|
|
|
// Autocomplete cards for attendees
|
|
|
|
function cardFilter($query) {
|
2016-11-01 14:26:44 +01:00
|
|
|
return AddressBook.$filterAll($query);
|
2015-07-27 22:02:05 +02:00
|
|
|
}
|
|
|
|
|
2016-06-01 03:56:10 +02:00
|
|
|
function newMessageWithAllRecipients($event) {
|
|
|
|
var recipients = _.map(vm.component.attendees, function(attendee) {
|
|
|
|
return attendee.name + " <" + attendee.email + ">";
|
|
|
|
});
|
|
|
|
_newMessage($event, recipients);
|
|
|
|
}
|
|
|
|
|
|
|
|
function newMessageWithRecipient($event, name, email) {
|
|
|
|
_newMessage($event, [name + " <" + email + ">"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _newMessage($event, recipients) {
|
|
|
|
Account.$findAll().then(function(accounts) {
|
|
|
|
var account = _.find(accounts, function(o) {
|
|
|
|
if (o.id === 0)
|
|
|
|
return o;
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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',
|
|
|
|
locals: {
|
|
|
|
stateAccount: account,
|
|
|
|
stateMessage: message
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$event.preventDefault();
|
|
|
|
$event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2015-07-21 14:26:50 +02:00
|
|
|
function edit() {
|
|
|
|
var type = (vm.component.component == 'vevent')? 'Appointment':'Task';
|
|
|
|
$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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-08-05 22:44:25 +02:00
|
|
|
|
|
|
|
function editAllOccurrences() {
|
|
|
|
component = Calendar.$get(vm.component.pid).$getComponent(vm.component.id);
|
|
|
|
component.$futureComponentData.then(function() {
|
|
|
|
vm.component = component;
|
|
|
|
edit();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function reply(component) {
|
|
|
|
var c = component || vm.component;
|
|
|
|
|
|
|
|
c.$reply().then(function() {
|
2015-11-06 21:12:24 +01:00
|
|
|
$rootScope.$emit('calendars:list');
|
2015-08-05 22:44:25 +02:00
|
|
|
$mdDialog.hide();
|
|
|
|
Alarm.getAlarms();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function replyAllOccurrences() {
|
|
|
|
// Retrieve master event
|
|
|
|
component = Calendar.$get(vm.component.pid).$getComponent(vm.component.id);
|
|
|
|
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
|
|
|
|
reply(component);
|
|
|
|
});
|
|
|
|
}
|
2015-09-28 17:27:20 +02:00
|
|
|
|
|
|
|
function deleteOccurrence() {
|
|
|
|
vm.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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteAllOccurrences() {
|
|
|
|
vm.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();
|
|
|
|
});
|
|
|
|
}
|
2015-10-02 22:49:08 +02:00
|
|
|
|
2015-12-04 21:00:58 +01:00
|
|
|
function toggleRawSource($event) {
|
2015-10-02 22:49:08 +02:00
|
|
|
Calendar.$$resource.post(vm.component.pid + '/' + vm.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();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-03-24 19:53:27 +01:00
|
|
|
|
|
|
|
function copySelectedComponent(calendar) {
|
|
|
|
vm.component.copyTo(calendar).then(function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
$rootScope.$emit('calendars:list');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveSelectedComponent(calendar) {
|
|
|
|
vm.component.moveTo(calendar).then(function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
$rootScope.$emit('calendars:list');
|
|
|
|
});
|
|
|
|
}
|
2015-10-02 22:49:08 +02:00
|
|
|
}
|
2015-07-21 14:26:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2016-10-28 17:47:40 +02:00
|
|
|
ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$mdDialog', 'User', 'CalendarSettings', 'Calendar', 'Component', 'AddressBook', 'Card', 'Alarm', 'stateComponent'];
|
|
|
|
function ComponentEditorController($rootScope, $scope, $log, $timeout, $mdDialog, User, CalendarSettings, Calendar, Component, AddressBook, Card, Alarm, stateComponent) {
|
2015-10-30 13:38:19 +01:00
|
|
|
var vm = this, component, oldStartDate, oldEndDate, oldDueDate;
|
2015-07-21 14:26:50 +02:00
|
|
|
|
2015-12-10 17:11:22 +01:00
|
|
|
vm.service = Calendar;
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.component = stateComponent;
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.categories = {};
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.showRecurrenceEditor = vm.component.$hasCustomRepeat;
|
2015-05-20 17:11:01 +02:00
|
|
|
vm.toggleRecurrenceEditor = toggleRecurrenceEditor;
|
2016-06-16 22:08:21 +02:00
|
|
|
vm.showAttendeesEditor = false;
|
2015-06-04 22:08:45 +02:00
|
|
|
vm.toggleAttendeesEditor = toggleAttendeesEditor;
|
2015-10-02 22:49:08 +02:00
|
|
|
//vm.searchText = null;
|
2015-06-04 22:08:45 +02:00
|
|
|
vm.cardFilter = cardFilter;
|
|
|
|
vm.addAttendee = addAttendee;
|
2016-02-29 19:59:31 +01:00
|
|
|
vm.removeAttendee = removeAttendee;
|
2015-07-01 20:34:35 +02:00
|
|
|
vm.addAttachUrl = addAttachUrl;
|
2016-04-21 23:02:07 +02:00
|
|
|
vm.priorityLevel = priorityLevel;
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.cancel = cancel;
|
|
|
|
vm.save = save;
|
2016-02-15 21:58:58 +01:00
|
|
|
vm.attendeeConflictError = false;
|
2015-06-04 22:08:45 +02:00
|
|
|
vm.attendeesEditor = {
|
2015-11-13 16:46:32 +01:00
|
|
|
days: getDays(),
|
2015-06-04 22:08:45 +02:00
|
|
|
hours: getHours()
|
|
|
|
};
|
2015-10-30 13:38:19 +01:00
|
|
|
vm.addStartDate = addStartDate;
|
|
|
|
vm.addDueDate = addDueDate;
|
|
|
|
|
|
|
|
// Synchronize start and end dates
|
|
|
|
vm.adjustStartTime = adjustStartTime;
|
|
|
|
vm.adjustEndTime = adjustEndTime;
|
|
|
|
vm.adjustDueTime = adjustDueTime;
|
|
|
|
|
|
|
|
if (vm.component.start)
|
|
|
|
oldStartDate = new Date(vm.component.start.getTime());
|
|
|
|
if (vm.component.end)
|
|
|
|
oldEndDate = new Date(vm.component.end.getTime());
|
|
|
|
if (vm.component.due)
|
|
|
|
oldDueDate = new Date(vm.component.due.getTime());
|
2015-06-04 22:08:45 +02:00
|
|
|
|
2015-07-01 20:34:35 +02:00
|
|
|
function addAttachUrl() {
|
|
|
|
var i = vm.component.addAttachUrl('');
|
|
|
|
focus('attachUrl_' + i);
|
2015-07-24 22:14:53 +02:00
|
|
|
}
|
2015-07-01 20:34:35 +02:00
|
|
|
|
2015-05-20 17:11:01 +02:00
|
|
|
function toggleRecurrenceEditor() {
|
|
|
|
vm.showRecurrenceEditor = !vm.showRecurrenceEditor;
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.component.$hasCustomRepeat = vm.showRecurrenceEditor;
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2015-06-04 22:08:45 +02:00
|
|
|
function toggleAttendeesEditor() {
|
|
|
|
vm.showAttendeesEditor = !vm.showAttendeesEditor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Autocomplete cards for attendees
|
|
|
|
function cardFilter($query) {
|
2015-08-05 22:44:25 +02:00
|
|
|
AddressBook.$filterAll($query);
|
|
|
|
return AddressBook.$cards;
|
2015-06-04 22:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addAttendee(card) {
|
|
|
|
if (angular.isString(card)) {
|
|
|
|
// User pressed "Enter" in search field, adding a non-matching card
|
2015-06-05 22:20:57 +02:00
|
|
|
if (card.isValidEmail()) {
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.component.addAttendee(new Card({ emails: [{ value: card }] }));
|
2015-06-05 22:20:57 +02:00
|
|
|
vm.searchText = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.component.addAttendee(card);
|
2015-06-04 22:08:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-29 19:59:31 +01:00
|
|
|
function removeAttendee(attendee) {
|
|
|
|
vm.component.deleteAttendee(attendee);
|
|
|
|
if (vm.component.attendees.length === 0)
|
|
|
|
vm.showAttendeesEditor = false;
|
|
|
|
}
|
|
|
|
|
2016-04-21 23:02:07 +02:00
|
|
|
function priorityLevel() {
|
2016-05-06 20:18:32 +02:00
|
|
|
if (vm.component && vm.component.priority) {
|
2016-04-21 23:02:07 +02:00
|
|
|
if (vm.component.priority > 5)
|
|
|
|
return l('low');
|
|
|
|
else if (vm.component.priority > 4)
|
|
|
|
return l('normal');
|
|
|
|
else
|
|
|
|
return l('high');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-15 21:58:58 +01:00
|
|
|
function save(form, options) {
|
2015-05-06 04:06:13 +02:00
|
|
|
if (form.$valid) {
|
2016-02-15 21:58:58 +01:00
|
|
|
vm.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-21 14:26:50 +02:00
|
|
|
$mdDialog.hide();
|
2015-07-28 17:54:49 +02:00
|
|
|
Alarm.getAlarms();
|
2016-02-15 21:58:58 +01:00
|
|
|
}, function(response) {
|
2016-10-28 17:47:40 +02:00
|
|
|
if (response.status == CalendarSettings.ConflictHTTPErrorCode &&
|
2016-02-16 18:40:59 +01:00
|
|
|
response.data && response.data.message &&
|
|
|
|
angular.isObject(response.data.message))
|
2016-02-15 21:58:58 +01:00
|
|
|
vm.attendeeConflictError = response.data.message;
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancel() {
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.component.$reset();
|
|
|
|
if (vm.component.isNew) {
|
2015-05-06 04:06:13 +02:00
|
|
|
// Cancelling the creation of a component
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.component = null;
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2015-11-06 21:12:24 +01:00
|
|
|
$mdDialog.cancel();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2015-06-04 22:08:45 +02:00
|
|
|
|
|
|
|
function getDays() {
|
|
|
|
var days = [];
|
|
|
|
|
2015-06-25 17:30:44 +02:00
|
|
|
if (vm.component.start && vm.component.end)
|
|
|
|
days = vm.component.start.daysUpTo(vm.component.end);
|
2015-06-04 22:08:45 +02:00
|
|
|
|
|
|
|
return _.map(days, function(date) {
|
|
|
|
return { stringWithSeparator: date.stringWithSeparator(),
|
|
|
|
getDayString: date.getDayString() };
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
function addStartDate() {
|
|
|
|
vm.component.$addStartDate();
|
|
|
|
oldStartDate = new Date(vm.component.start.getTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
function addDueDate() {
|
|
|
|
vm.component.$addDueDate();
|
|
|
|
oldDueDate = new Date(vm.component.due.getTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjustStartTime() {
|
2016-05-09 21:53:19 +02:00
|
|
|
if (vm.component.start) {
|
|
|
|
// Preserve the delta between the start and end dates
|
|
|
|
var delta;
|
|
|
|
delta = oldStartDate.valueOf() - vm.component.start.valueOf();
|
|
|
|
if (delta !== 0) {
|
|
|
|
oldStartDate = new Date(vm.component.start.getTime());
|
|
|
|
if (vm.component.type === 'appointment') {
|
|
|
|
vm.component.end = new Date(vm.component.start.getTime());
|
|
|
|
vm.component.end.addMinutes(vm.component.delta);
|
|
|
|
oldEndDate = new Date(vm.component.end.getTime());
|
|
|
|
}
|
|
|
|
updateFreeBusy();
|
2015-10-30 13:38:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjustEndTime() {
|
2016-05-09 21:53:19 +02:00
|
|
|
if (vm.component.end) {
|
|
|
|
// The end date must be after the start date
|
|
|
|
var delta = oldEndDate.valueOf() - vm.component.end.valueOf();
|
|
|
|
if (delta !== 0) {
|
2015-12-17 20:00:56 +01:00
|
|
|
delta = vm.component.start.minutesTo(vm.component.end);
|
2016-05-09 21:53:19 +02:00
|
|
|
if (delta < 0)
|
|
|
|
vm.component.end = new Date(oldEndDate.getTime());
|
|
|
|
else {
|
|
|
|
vm.component.delta = delta;
|
|
|
|
oldEndDate = new Date(vm.component.end.getTime());
|
|
|
|
}
|
|
|
|
updateFreeBusy();
|
2015-12-17 20:00:56 +01:00
|
|
|
}
|
2015-10-30 13:38:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjustDueTime() {
|
|
|
|
oldDueDate = new Date(vm.component.due.getTime());
|
|
|
|
}
|
2015-11-13 16:46:32 +01:00
|
|
|
|
|
|
|
function updateFreeBusy() {
|
|
|
|
vm.attendeesEditor.days = getDays();
|
|
|
|
vm.component.updateFreeBusy();
|
|
|
|
}
|
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
|
|
|
})();
|