2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for SOGoPreferences */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-12-18 17:43:05 +01:00
|
|
|
PreferencesController.$inject = ['$q', '$window', '$state', '$mdMedia', '$mdSidenav', '$mdDialog', '$mdToast', 'sgFocus', 'Dialog', 'User', 'Account', 'statePreferences', 'Authentication'];
|
|
|
|
function PreferencesController($q, $window, $state, $mdMedia, $mdSidenav, $mdDialog, $mdToast, focus, Dialog, User, Account, statePreferences, Authentication) {
|
2016-10-19 22:14:27 +02:00
|
|
|
var vm = this, account, mailboxes = [], today = new Date(), tomorrow = today.beginOfDay().addDays(1);
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
vm.preferences = statePreferences;
|
|
|
|
vm.passwords = { newPassword: null, newPasswordConfirmation: null };
|
|
|
|
|
2015-07-28 02:11:57 +02:00
|
|
|
vm.go = go;
|
2015-11-24 20:57:40 +01:00
|
|
|
vm.onLanguageChange = onLanguageChange;
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.addCalendarCategory = addCalendarCategory;
|
|
|
|
vm.removeCalendarCategory = removeCalendarCategory;
|
|
|
|
vm.addContactCategory = addContactCategory;
|
|
|
|
vm.removeContactCategory = removeContactCategory;
|
|
|
|
vm.addMailAccount = addMailAccount;
|
|
|
|
vm.editMailAccount = editMailAccount;
|
|
|
|
vm.removeMailAccount = removeMailAccount;
|
|
|
|
vm.addMailLabel = addMailLabel;
|
|
|
|
vm.removeMailLabel = removeMailLabel;
|
|
|
|
vm.addMailFilter = addMailFilter;
|
|
|
|
vm.editMailFilter = editMailFilter;
|
|
|
|
vm.removeMailFilter = removeMailFilter;
|
2015-08-18 20:57:29 +02:00
|
|
|
vm.addDefaultEmailAddresses = addDefaultEmailAddresses;
|
2016-06-22 03:29:44 +02:00
|
|
|
vm.userFilter = userFilter;
|
2016-03-29 18:15:37 +02:00
|
|
|
vm.confirmChanges = confirmChanges;
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.save = save;
|
|
|
|
vm.canChangePassword = canChangePassword;
|
|
|
|
vm.changePassword = changePassword;
|
2015-07-21 21:21:57 +02:00
|
|
|
vm.timeZonesList = window.timeZonesList;
|
|
|
|
vm.timeZonesListFilter = timeZonesListFilter;
|
|
|
|
vm.timeZonesSearchText = '';
|
2016-06-15 22:02:12 +02:00
|
|
|
vm.sieveVariablesCapability = ($window.sieveCapabilities.indexOf('variables') >= 0);
|
2016-10-18 15:22:32 +02:00
|
|
|
vm.updateVacationDates = updateVacationDates;
|
2016-10-19 22:14:27 +02:00
|
|
|
vm.toggleVacationStartDate = toggleVacationStartDate;
|
|
|
|
vm.toggleVacationEndDate = toggleVacationEndDate;
|
|
|
|
vm.validateVacationStartDate = validateVacationStartDate;
|
|
|
|
vm.validateVacationEndDate = validateVacationEndDate;
|
|
|
|
|
2015-10-08 22:42:24 +02:00
|
|
|
|
|
|
|
// Fetch a flatten version of the mailboxes list of the main account (0)
|
|
|
|
// This list will be forwarded to the Sieve filter controller
|
|
|
|
account = new Account({ id: 0 });
|
|
|
|
account.$getMailboxes().then(function() {
|
|
|
|
var allMailboxes = account.$flattenMailboxes({all: true}),
|
|
|
|
index = -1,
|
|
|
|
length = allMailboxes.length;
|
|
|
|
while (++index < length) {
|
|
|
|
mailboxes.push(allMailboxes[index]);
|
|
|
|
}
|
|
|
|
});
|
2015-07-28 02:11:57 +02:00
|
|
|
|
2015-12-07 17:05:01 +01:00
|
|
|
// Set alternate avatar in User service
|
|
|
|
statePreferences.ready().then(function() {
|
|
|
|
if (statePreferences.defaults.SOGoAlternateAvatar)
|
|
|
|
User.$alternateAvatar = statePreferences.defaults.SOGoAlternateAvatar;
|
2016-10-18 15:22:32 +02:00
|
|
|
updateVacationDates();
|
2015-12-07 17:05:01 +01:00
|
|
|
});
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function go(module, form) {
|
|
|
|
if (form.$valid) {
|
|
|
|
// Close sidenav on small devices
|
|
|
|
if ($mdMedia('xs'))
|
|
|
|
$mdSidenav('left').close();
|
|
|
|
$state.go('preferences.' + module);
|
|
|
|
}
|
2015-07-28 02:11:57 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function onLanguageChange(form) {
|
2015-11-24 20:57:40 +01:00
|
|
|
Dialog.confirm(l('Warning'),
|
|
|
|
l('Save preferences and reload page now?'),
|
|
|
|
{ok: l('Yes'), cancel: l('No')})
|
|
|
|
.then(function() {
|
2016-03-29 18:15:37 +02:00
|
|
|
save(form, { quick: true }).then(function() {
|
2015-11-24 20:57:40 +01:00
|
|
|
$window.location.reload(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function addCalendarCategory(form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.preferences.defaults.SOGoCalendarCategoriesColors["New category"] = "#aaa";
|
|
|
|
vm.preferences.defaults.SOGoCalendarCategories.push("New category");
|
2015-12-10 17:46:56 +01:00
|
|
|
focus('calendarCategory_' + (vm.preferences.defaults.SOGoCalendarCategories.length - 1));
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function removeCalendarCategory(index, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
var key = vm.preferences.defaults.SOGoCalendarCategories[index];
|
|
|
|
vm.preferences.defaults.SOGoCalendarCategories.splice(index, 1);
|
|
|
|
delete vm.preferences.defaults.SOGoCalendarCategoriesColors[key];
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function addContactCategory(form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.preferences.defaults.SOGoContactsCategories.push("");
|
2015-12-10 17:46:56 +01:00
|
|
|
focus('contactCategory_' + (vm.preferences.defaults.SOGoContactsCategories.length - 1));
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function removeContactCategory(index, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.preferences.defaults.SOGoContactsCategories.splice(index, 1);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function addMailAccount(ev, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
var account;
|
|
|
|
|
|
|
|
vm.preferences.defaults.AuxiliaryMailAccounts.push({});
|
2015-08-06 22:13:10 +02:00
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
account = _.last(vm.preferences.defaults.AuxiliaryMailAccounts);
|
2015-08-06 22:13:10 +02:00
|
|
|
account.name = l("New account");
|
|
|
|
account.identities = [
|
|
|
|
{
|
|
|
|
fullName: "",
|
|
|
|
email: ""
|
|
|
|
}
|
|
|
|
];
|
|
|
|
account.receipts = {
|
|
|
|
receiptAction: "ignore",
|
|
|
|
receiptNonRecipientAction: "ignore",
|
|
|
|
receiptOutsideDomainAction: "ignore",
|
|
|
|
receiptAnyAction: "ignore"
|
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
$mdDialog.show({
|
|
|
|
controller: 'AccountDialogController',
|
2015-08-06 22:13:10 +02:00
|
|
|
controllerAs: '$AccountDialogController',
|
2015-05-06 04:06:13 +02:00
|
|
|
templateUrl: 'editAccount?account=new',
|
|
|
|
targetEvent: ev,
|
|
|
|
locals: {
|
2015-08-06 22:13:10 +02:00
|
|
|
defaults: vm.preferences.defaults,
|
2015-05-06 04:06:13 +02:00
|
|
|
account: account,
|
|
|
|
accountId: (vm.preferences.defaults.AuxiliaryMailAccounts.length-1),
|
|
|
|
mailCustomFromEnabled: window.mailCustomFromEnabled
|
|
|
|
}
|
2016-03-29 18:15:37 +02:00
|
|
|
}).then(function() {
|
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function editMailAccount(event, index, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
var account = vm.preferences.defaults.AuxiliaryMailAccounts[index];
|
|
|
|
$mdDialog.show({
|
|
|
|
controller: 'AccountDialogController',
|
2015-08-06 22:13:10 +02:00
|
|
|
controllerAs: '$AccountDialogController',
|
2015-05-06 04:06:13 +02:00
|
|
|
templateUrl: 'editAccount?account=' + index,
|
2015-08-06 22:13:10 +02:00
|
|
|
targetEvent: event,
|
2015-05-06 04:06:13 +02:00
|
|
|
locals: {
|
2015-08-06 22:13:10 +02:00
|
|
|
defaults: vm.preferences.defaults,
|
2015-05-06 04:06:13 +02:00
|
|
|
account: account,
|
|
|
|
accountId: index,
|
|
|
|
mailCustomFromEnabled: window.mailCustomFromEnabled
|
|
|
|
}
|
|
|
|
}).then(function() {
|
|
|
|
vm.preferences.defaults.AuxiliaryMailAccounts[index] = account;
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function removeMailAccount(index, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.preferences.defaults.AuxiliaryMailAccounts.splice(index, 1);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function addMailLabel(form) {
|
2015-12-10 21:12:12 +01:00
|
|
|
// See $omit() in the Preferences services for real key generation
|
|
|
|
var key = '_$$' + guid();
|
|
|
|
vm.preferences.defaults.SOGoMailLabelsColors[key] = ["New label", "#aaa"];
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function removeMailLabel(key, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
delete vm.preferences.defaults.SOGoMailLabelsColors[key];
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function addMailFilter(ev, form) {
|
2015-10-05 16:45:30 +02:00
|
|
|
var filter = { match: 'all' };
|
2015-10-08 22:42:24 +02:00
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: 'editFilter?filter=new',
|
2015-10-05 16:45:30 +02:00
|
|
|
controller: 'FiltersDialogController',
|
|
|
|
controllerAs: 'filterEditor',
|
2015-05-06 04:06:13 +02:00
|
|
|
targetEvent: ev,
|
|
|
|
locals: {
|
|
|
|
filter: filter,
|
2015-10-08 22:42:24 +02:00
|
|
|
mailboxes: mailboxes,
|
|
|
|
labels: vm.preferences.defaults.SOGoMailLabelsColors
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2015-10-05 16:45:30 +02:00
|
|
|
}).then(function() {
|
|
|
|
if (!vm.preferences.defaults.SOGoSieveFilters)
|
|
|
|
vm.preferences.defaults.SOGoSieveFilters = [];
|
|
|
|
vm.preferences.defaults.SOGoSieveFilters.push(filter);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function editMailFilter(ev, index, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
var filter = angular.copy(vm.preferences.defaults.SOGoSieveFilters[index]);
|
|
|
|
|
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: 'editFilter?filter=' + index,
|
2015-10-05 16:45:30 +02:00
|
|
|
controller: 'FiltersDialogController',
|
|
|
|
controllerAs: 'filterEditor',
|
2015-05-06 04:06:13 +02:00
|
|
|
targetEvent: null,
|
|
|
|
locals: {
|
|
|
|
filter: filter,
|
2015-10-08 22:42:24 +02:00
|
|
|
mailboxes: mailboxes,
|
|
|
|
labels: vm.preferences.defaults.SOGoMailLabelsColors
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
}).then(function() {
|
|
|
|
vm.preferences.defaults.SOGoSieveFilters[index] = filter;
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function removeMailFilter(index, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
vm.preferences.defaults.SOGoSieveFilters.splice(index, 1);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2015-08-18 20:57:29 +02:00
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function addDefaultEmailAddresses(form) {
|
2015-08-18 20:57:29 +02:00
|
|
|
var v = [];
|
|
|
|
|
|
|
|
if (angular.isDefined(vm.preferences.defaults.Vacation.autoReplyEmailAddresses)) {
|
|
|
|
v = vm.preferences.defaults.Vacation.autoReplyEmailAddresses.split(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
vm.preferences.defaults.Vacation.autoReplyEmailAddresses = (_.union(window.defaultEmailAddresses.split(','), v)).join(',');
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2015-08-18 20:57:29 +02:00
|
|
|
}
|
2016-03-29 18:15:37 +02:00
|
|
|
|
2016-06-22 03:29:44 +02:00
|
|
|
function userFilter(search, excludedUsers) {
|
|
|
|
return User.$filter(search, excludedUsers).then(function(users) {
|
|
|
|
// Set users avatars
|
|
|
|
_.forEach(users, function(user) {
|
|
|
|
if (!user.$$image) {
|
|
|
|
if (user.image)
|
|
|
|
user.$$image = user.image;
|
|
|
|
else
|
|
|
|
vm.preferences.avatar(user.c_email, 32, {no_404: true}).then(function(url) {
|
|
|
|
user.$$image = url;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return users;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-29 18:15:37 +02:00
|
|
|
function confirmChanges($event, form) {
|
|
|
|
var target;
|
|
|
|
|
|
|
|
if (form.$dirty) {
|
|
|
|
// Stop default action
|
|
|
|
$event.preventDefault();
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
|
|
|
// Find target link
|
|
|
|
target = $event.target;
|
|
|
|
while (target.tagName != 'A')
|
|
|
|
target = target.parentNode;
|
|
|
|
|
|
|
|
Dialog.confirm(l('Unsaved Changes'),
|
|
|
|
l('Do you want to save your changes made to the configuration?'),
|
|
|
|
{ ok: l('Save'), cancel: l('Don\'t Save') })
|
|
|
|
.then(function() {
|
|
|
|
// Save & follow link
|
|
|
|
save(form, { quick: true }).then(function() {
|
|
|
|
$window.location = target.href;
|
|
|
|
});
|
|
|
|
}, function() {
|
|
|
|
// Don't save & follow link
|
|
|
|
$window.location = target.href;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function save(form, options) {
|
2015-11-24 21:05:03 +01:00
|
|
|
var i, sendForm, addresses, defaultAddresses, domains, domain;
|
|
|
|
|
|
|
|
sendForm = true;
|
|
|
|
domains = [];
|
2015-08-18 21:25:51 +02:00
|
|
|
|
|
|
|
// We do some sanity checks
|
2016-10-14 17:49:23 +02:00
|
|
|
if ($window.forwardConstraints > 0 &&
|
2015-08-18 21:25:51 +02:00
|
|
|
angular.isDefined(vm.preferences.defaults.Forward) &&
|
|
|
|
vm.preferences.defaults.Forward.enabled &&
|
|
|
|
angular.isDefined(vm.preferences.defaults.Forward.forwardAddress)) {
|
|
|
|
|
2015-11-24 21:05:03 +01:00
|
|
|
addresses = vm.preferences.defaults.Forward.forwardAddress.split(",");
|
2015-08-18 21:25:51 +02:00
|
|
|
|
|
|
|
// We first extract the list of 'known domains' to SOGo
|
2016-10-14 17:49:23 +02:00
|
|
|
defaultAddresses = $window.defaultEmailAddresses.split(/, */);
|
2015-08-18 21:25:51 +02:00
|
|
|
|
|
|
|
_.forEach(defaultAddresses, function(adr) {
|
|
|
|
var domain = adr.split("@")[1];
|
|
|
|
if (domain) {
|
|
|
|
domains.push(domain.toLowerCase());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// We check if we're allowed or not to forward based on the domain defaults
|
2015-11-24 21:05:03 +01:00
|
|
|
for (i = 0; i < addresses.length && sendForm; i++) {
|
|
|
|
domain = addresses[i].split("@")[1].toLowerCase();
|
2016-10-14 17:49:23 +02:00
|
|
|
if (domains.indexOf(domain) < 0 && $window.forwardConstraints == 1) {
|
2015-08-18 21:25:51 +02:00
|
|
|
Dialog.alert(l('Error'), l("You are not allowed to forward your messages to an external email address."));
|
|
|
|
sendForm = false;
|
|
|
|
}
|
2016-10-14 17:49:23 +02:00
|
|
|
else if (domains.indexOf(domain) >= 0 && $window.forwardConstraints == 2) {
|
2015-08-18 21:25:51 +02:00
|
|
|
Dialog.alert(l('Error'), l("You are not allowed to forward your messages to an internal email address."));
|
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendForm)
|
2015-11-24 21:05:03 +01:00
|
|
|
return vm.preferences.$save().then(function(data) {
|
2016-03-29 18:15:37 +02:00
|
|
|
if (!options || !options.quick) {
|
|
|
|
$mdToast.show(
|
|
|
|
$mdToast.simple()
|
|
|
|
.content(l('Preferences saved'))
|
|
|
|
.position('bottom right')
|
|
|
|
.hideDelay(2000));
|
|
|
|
form.$setPristine();
|
|
|
|
}
|
2015-08-20 20:53:43 +02:00
|
|
|
});
|
2015-11-24 21:05:03 +01:00
|
|
|
|
|
|
|
return $q.reject();
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function canChangePassword() {
|
|
|
|
if (vm.passwords.newPassword && vm.passwords.newPassword.length > 0 &&
|
|
|
|
vm.passwords.newPasswordConfirmation && vm.passwords.newPasswordConfirmation.length &&
|
|
|
|
vm.passwords.newPassword == vm.passwords.newPasswordConfirmation)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function changePassword() {
|
|
|
|
Authentication.changePassword(vm.passwords.newPassword).then(function() {
|
|
|
|
var alert = $mdDialog.alert({
|
|
|
|
title: l('Password'),
|
|
|
|
content: l('The password was changed successfully.'),
|
2015-11-24 21:05:03 +01:00
|
|
|
ok: l('OK')
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
$mdDialog.show( alert )
|
|
|
|
.finally(function() {
|
|
|
|
alert = undefined;
|
|
|
|
});
|
|
|
|
}, function(msg) {
|
|
|
|
var alert = $mdDialog.alert({
|
|
|
|
title: l('Password'),
|
|
|
|
content: msg,
|
2015-11-24 21:05:03 +01:00
|
|
|
ok: l('OK')
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
$mdDialog.show( alert )
|
|
|
|
.finally(function() {
|
|
|
|
alert = undefined;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-07-21 21:21:57 +02:00
|
|
|
|
|
|
|
function timeZonesListFilter(filter) {
|
|
|
|
return _.filter(vm.timeZonesList, function(value) {
|
|
|
|
return value.toUpperCase().indexOf(filter.toUpperCase()) >= 0;
|
|
|
|
});
|
|
|
|
}
|
2016-10-14 17:49:23 +02:00
|
|
|
|
2016-10-18 15:22:32 +02:00
|
|
|
function updateVacationDates() {
|
2016-10-19 22:14:27 +02:00
|
|
|
var d = vm.preferences.defaults;
|
|
|
|
|
|
|
|
if (d &&
|
|
|
|
d.Vacation &&
|
|
|
|
d.Vacation.enabled) {
|
|
|
|
toggleVacationStartDate();
|
|
|
|
toggleVacationEndDate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleVacationStartDate() {
|
|
|
|
var v;
|
|
|
|
|
|
|
|
v = vm.preferences.defaults.Vacation;
|
|
|
|
|
|
|
|
if (v.startDateEnabled) {
|
|
|
|
// Enabling the start date
|
|
|
|
if (v.endDateEnabled && v.startDate.getTime() > v.endDate.getTime()) {
|
|
|
|
v.startDate = new Date(v.endDate.getTime());
|
|
|
|
v.startDate.addDays(-1);
|
|
|
|
}
|
|
|
|
if (v.startDate.getTime() < tomorrow.getTime()) {
|
|
|
|
v.startDate = new Date(tomorrow.getTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleVacationEndDate() {
|
|
|
|
var v;
|
|
|
|
|
|
|
|
v = vm.preferences.defaults.Vacation;
|
|
|
|
|
|
|
|
if (v.endDateEnabled) {
|
|
|
|
// Enabling the end date
|
|
|
|
if (v.startDateEnabled && v.endDate.getTime() < v.startDate.getTime()) {
|
|
|
|
v.endDate = new Date(v.startDate.getTime());
|
|
|
|
v.endDate.addDays(1);
|
|
|
|
}
|
|
|
|
else if (v.endDate.getTime() < tomorrow.getTime()) {
|
|
|
|
v.endDate = new Date(tomorrow.getTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateVacationStartDate(date) {
|
|
|
|
var d = vm.preferences.defaults, r = true;
|
|
|
|
if (d &&
|
|
|
|
d.Vacation &&
|
|
|
|
d.Vacation.enabled) {
|
|
|
|
if (d.Vacation.startDateEnabled) {
|
|
|
|
r = (!d.Vacation.endDateEnabled ||
|
|
|
|
date.getTime() < d.Vacation.endDate.getTime()) &&
|
|
|
|
date.getTime() >= tomorrow.getTime();
|
2016-10-18 15:22:32 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-19 22:14:27 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateVacationEndDate(date) {
|
|
|
|
var d = vm.preferences.defaults, r = true;
|
|
|
|
if (d &&
|
|
|
|
d.Vacation &&
|
|
|
|
d.Vacation.enabled) {
|
|
|
|
if (d.Vacation.endDateEnabled) {
|
|
|
|
r = (!d.Vacation.startDateEnabled ||
|
|
|
|
date.getTime() > d.Vacation.startDate.getTime()) &&
|
|
|
|
date.getTime() >= tomorrow.getTime();
|
|
|
|
}
|
2016-10-18 15:22:32 +02:00
|
|
|
}
|
2016-10-19 22:14:27 +02:00
|
|
|
|
|
|
|
return r;
|
2016-10-14 17:49:23 +02:00
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.PreferencesUI')
|
|
|
|
.controller('PreferencesController', PreferencesController);
|
|
|
|
|
|
|
|
})();
|