2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-08-05 22:44:25 +02:00
|
|
|
ComponentController.$inject = ['$rootScope', '$mdDialog', 'Calendar', 'AddressBook', 'Alarm', 'stateComponent'];
|
|
|
|
function ComponentController($rootScope, $mdDialog, Calendar, AddressBook, Alarm, stateComponent) {
|
2015-07-21 14:26:50 +02:00
|
|
|
var vm = this, component;
|
2015-05-06 04:06:13 +02:00
|
|
|
|
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;
|
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;
|
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) {
|
|
|
|
AddressBook.$filterAll($query);
|
|
|
|
return AddressBook.$cards;
|
2015-07-27 22:02:05 +02:00
|
|
|
}
|
|
|
|
|
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: [
|
2015-12-04 21:00:58 +01:00
|
|
|
'<md-dialog flex="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">',
|
2015-10-02 22:49:08 +02:00
|
|
|
' <pre>',
|
|
|
|
data,
|
|
|
|
' </pre>',
|
|
|
|
' </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(''),
|
|
|
|
controller: ComponentRawSourceDialogController
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
ComponentRawSourceDialogController.$inject = ['scope', '$mdDialog'];
|
|
|
|
function ComponentRawSourceDialogController(scope, $mdDialog) {
|
|
|
|
scope.close = function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-07-21 14:26:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-07-28 17:54:49 +02:00
|
|
|
ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$mdDialog', 'User', 'Calendar', 'Component', 'AddressBook', 'Card', 'Alarm', 'stateComponent'];
|
|
|
|
function ComponentEditorController($rootScope, $scope, $log, $timeout, $mdDialog, User, 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;
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.showAttendeesEditor = angular.isDefined(vm.component.attendees);
|
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;
|
2015-07-01 20:34:35 +02:00
|
|
|
vm.addAttachUrl = addAttachUrl;
|
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.updateStartTime = updateStartTime;
|
|
|
|
vm.adjustStartTime = adjustStartTime;
|
|
|
|
vm.updateEndTime = updateEndTime;
|
|
|
|
vm.adjustEndTime = adjustEndTime;
|
|
|
|
vm.updateDueTime = updateDueTime;
|
|
|
|
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-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) {
|
|
|
|
if (response.status == 403 &&
|
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(Component.timeFormat.formatTime(i, 0));
|
|
|
|
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 updateStartTime() {
|
|
|
|
// When using the datepicker, the time is reset to 00:00; restore it
|
|
|
|
vm.component.start.addMinutes(oldStartDate.getHours() * 60 + oldStartDate.getMinutes());
|
|
|
|
adjustStartTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjustStartTime() {
|
|
|
|
// 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());
|
|
|
|
}
|
2015-12-17 20:00:56 +01:00
|
|
|
updateFreeBusy();
|
2015-10-30 13:38:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateEndTime() {
|
|
|
|
// When using the datepicker, the time is reset to 00:00; restore it
|
|
|
|
vm.component.end.addMinutes(oldEndDate.getHours() * 60 + oldEndDate.getMinutes());
|
|
|
|
adjustEndTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
function adjustEndTime() {
|
|
|
|
// The end date must be after the start date
|
2015-12-17 20:00:56 +01:00
|
|
|
var delta = oldEndDate.valueOf() - vm.component.end.valueOf();
|
|
|
|
if (delta !== 0) {
|
|
|
|
delta = vm.component.start.minutesTo(vm.component.end);
|
|
|
|
if (delta < 0)
|
|
|
|
vm.component.end = new Date(oldEndDate.getTime());
|
|
|
|
else {
|
|
|
|
vm.component.delta = delta;
|
|
|
|
oldEndDate = new Date(vm.component.end.getTime());
|
|
|
|
}
|
|
|
|
updateFreeBusy();
|
2015-10-30 13:38:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateDueTime() {
|
|
|
|
// When using the datepicker, the time is reset to 00:00; restore it
|
|
|
|
vm.component.due.addMinutes(oldDueDate.getHours() * 60 + oldDueDate.getMinutes());
|
|
|
|
adjustDueTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
})();
|