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-10-02 22:49:08 +02:00
|
|
|
vm.viewRawSource = viewRawSource;
|
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
|
|
|
|
|
|
|
function viewRawSource($event) {
|
|
|
|
Calendar.$$resource.post(vm.component.pid + '/' + vm.component.id, "raw").then(function(data) {
|
|
|
|
$mdDialog.show({
|
|
|
|
parent: angular.element(document.body),
|
|
|
|
targetEvent: $event,
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
escapeToClose: true,
|
|
|
|
template: [
|
|
|
|
'<md-dialog flex="80" flex-sm="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>',
|
|
|
|
' <div class="md-actions">',
|
|
|
|
' <md-button ng-click="close()">' + l('Close') + '</md-button>',
|
|
|
|
' </div>',
|
|
|
|
'</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
|
|
|
|
|
|
|
vm.calendars = Calendar.$calendars;
|
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;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
function save(form) {
|
|
|
|
if (form.$valid) {
|
2015-06-25 17:30:44 +02:00
|
|
|
vm.component.$save()
|
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();
|
2015-05-06 04:06:13 +02:00
|
|
|
}, function(data, status) {
|
|
|
|
$log.debug('failed');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-11-13 16:46:32 +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-11-03 21:47:30 +01:00
|
|
|
var delta = vm.component.start.minutesTo(vm.component.end);
|
2015-10-30 13:38:19 +01:00
|
|
|
if (delta < 0)
|
|
|
|
vm.component.end = new Date(oldEndDate.getTime());
|
|
|
|
else {
|
2015-11-03 21:47:30 +01:00
|
|
|
vm.component.delta = delta;
|
2015-10-30 13:38:19 +01:00
|
|
|
oldEndDate = new Date(vm.component.end.getTime());
|
|
|
|
}
|
2015-11-13 16:46:32 +01:00
|
|
|
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
|
|
|
})();
|