2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for SOGoPreferences */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
2018-09-08 03:38:31 +02:00
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2017-06-01 19:46:57 +02:00
|
|
|
PreferencesController.$inject = ['$q', '$window', '$state', '$mdMedia', '$mdSidenav', '$mdDialog', '$mdToast', 'sgSettings', 'sgFocus', 'Dialog', 'User', 'Account', 'Preferences', 'Authentication'];
|
|
|
|
function PreferencesController($q, $window, $state, $mdMedia, $mdSidenav, $mdDialog, $mdToast, sgSettings, focus, Dialog, User, Account, Preferences, Authentication) {
|
2018-11-01 20:56:33 +01:00
|
|
|
var vm = this, mailboxes = [], today = new Date().beginOfDay();
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.$onInit = function() {
|
|
|
|
this.preferences = Preferences;
|
|
|
|
this.passwords = { newPassword: null, newPasswordConfirmation: null };
|
2017-06-28 18:00:36 +02:00
|
|
|
this.timeZonesList = $window.timeZonesList;
|
2017-06-20 21:25:07 +02:00
|
|
|
this.timeZonesSearchText = '';
|
|
|
|
this.sieveVariablesCapability = ($window.sieveCapabilities.indexOf('variables') >= 0);
|
2018-05-15 05:18:30 +02:00
|
|
|
this.mailLabelKeyRE = new RegExp(/^(?!^_\$)[^(){} %*\"\\\\]*?$/);
|
2017-06-20 21:25:07 +02:00
|
|
|
|
|
|
|
// Set alternate avatar in User service
|
|
|
|
if (Preferences.defaults.SOGoAlternateAvatar)
|
|
|
|
User.$alternateAvatar = Preferences.defaults.SOGoAlternateAvatar;
|
2015-07-28 02:11:57 +02:00
|
|
|
|
2020-01-31 22:51:33 +01:00
|
|
|
this.preferences.hasActiveExternalSieveScripts();
|
2017-06-20 21:25:07 +02:00
|
|
|
this.updateVacationDates();
|
|
|
|
};
|
2015-12-07 17:05:01 +01:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.go = function(module, form) {
|
2016-03-29 18:15:37 +02:00
|
|
|
if (form.$valid) {
|
|
|
|
// Close sidenav on small devices
|
2018-08-31 19:14:56 +02:00
|
|
|
if (!$mdMedia('gt-md'))
|
2016-03-29 18:15:37 +02:00
|
|
|
$mdSidenav('left').close();
|
|
|
|
$state.go('preferences.' + module);
|
|
|
|
}
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-07-28 02:11:57 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.onLanguageChange = function(form) {
|
|
|
|
if (form.$valid)
|
|
|
|
Dialog.confirm(l('Warning'),
|
|
|
|
l('Save preferences and reload page now?'),
|
|
|
|
{ok: l('Yes'), cancel: l('No')})
|
2015-11-24 20:57:40 +01:00
|
|
|
.then(function() {
|
2017-06-20 21:25:07 +02:00
|
|
|
vm.save(form, { quick: true }).then(function() {
|
2015-11-24 20:57:40 +01:00
|
|
|
$window.location.reload(true);
|
|
|
|
});
|
|
|
|
});
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-11-24 20:57:40 +01:00
|
|
|
|
2018-09-08 03:38:31 +02:00
|
|
|
this.resetCalendarCategories = function(form) {
|
|
|
|
this.preferences.defaults.SOGoCalendarCategories = _.keys($window.defaultCalendarCategories);
|
2018-09-11 21:17:31 +02:00
|
|
|
this.preferences.defaults.SOGoCalendarCategoriesColorsValues = _.values($window.defaultCalendarCategories);
|
2018-09-08 03:38:31 +02:00
|
|
|
form.$setDirty();
|
|
|
|
};
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.addCalendarCategory = function(form) {
|
2019-08-08 16:11:42 +02:00
|
|
|
var i = _.indexOf(this.preferences.defaults.SOGoCalendarCategories, l('New category'));
|
|
|
|
if (i < 0) {
|
|
|
|
this.preferences.defaults.SOGoCalendarCategories.push(l('New category'));
|
|
|
|
this.preferences.defaults.SOGoCalendarCategoriesColorsValues.push("#aaa");
|
|
|
|
form.$setDirty();
|
|
|
|
i = this.preferences.defaults.SOGoCalendarCategories.length - 1;
|
|
|
|
}
|
|
|
|
focus('calendarCategory_' + i);
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2018-08-02 15:29:33 +02:00
|
|
|
this.resetCalendarCategoryValidity = function(index, form) {
|
|
|
|
form['calendarCategory_' + index].$setValidity('duplicate', true);
|
|
|
|
};
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.removeCalendarCategory = function(index, form) {
|
|
|
|
this.preferences.defaults.SOGoCalendarCategories.splice(index, 1);
|
2018-09-11 21:17:31 +02:00
|
|
|
this.preferences.defaults.SOGoCalendarCategoriesColorsValues.splice(index, 1);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.addContactCategory = function(form) {
|
2017-10-10 20:55:22 +02:00
|
|
|
var i = _.indexOf(this.preferences.defaults.SOGoContactsCategories, "");
|
|
|
|
if (i < 0) {
|
|
|
|
this.preferences.defaults.SOGoContactsCategories.push("");
|
|
|
|
i = this.preferences.defaults.SOGoContactsCategories.length - 1;
|
|
|
|
}
|
|
|
|
focus('contactCategory_' + i);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.removeContactCategory = function(index, form) {
|
|
|
|
this.preferences.defaults.SOGoContactsCategories.splice(index, 1);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.addMailAccount = function(ev, form) {
|
2015-05-06 04:06:13 +02:00
|
|
|
var account;
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.preferences.defaults.AuxiliaryMailAccounts.push({});
|
2015-08-06 22:13:10 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
account = _.last(this.preferences.defaults.AuxiliaryMailAccounts);
|
2016-10-21 16:49:09 +02:00
|
|
|
angular.extend(account,
|
|
|
|
{
|
2018-01-12 20:47:31 +01:00
|
|
|
isNew: true,
|
2016-10-21 16:49:09 +02:00
|
|
|
name: "",
|
|
|
|
identities: [
|
|
|
|
{
|
|
|
|
fullName: "",
|
|
|
|
email: ""
|
|
|
|
}
|
|
|
|
],
|
|
|
|
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: {
|
2017-06-20 21:25:07 +02:00
|
|
|
defaults: this.preferences.defaults,
|
2015-05-06 04:06:13 +02:00
|
|
|
account: account,
|
2017-06-20 21:25:07 +02:00
|
|
|
accountId: (this.preferences.defaults.AuxiliaryMailAccounts.length-1),
|
|
|
|
mailCustomFromEnabled: $window.mailCustomFromEnabled
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
2016-03-29 18:15:37 +02:00
|
|
|
}).then(function() {
|
|
|
|
form.$setDirty();
|
2016-10-21 16:49:09 +02:00
|
|
|
}).catch(function() {
|
|
|
|
vm.preferences.defaults.AuxiliaryMailAccounts.pop();
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.editMailAccount = function(event, index, form) {
|
|
|
|
var account = this.preferences.defaults.AuxiliaryMailAccounts[index];
|
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=' + index,
|
2015-08-06 22:13:10 +02:00
|
|
|
targetEvent: event,
|
2015-05-06 04:06:13 +02:00
|
|
|
locals: {
|
2017-06-20 21:25:07 +02:00
|
|
|
defaults: this.preferences.defaults,
|
2015-05-06 04:06:13 +02:00
|
|
|
account: account,
|
|
|
|
accountId: index,
|
2017-06-20 21:25:07 +02:00
|
|
|
mailCustomFromEnabled: $window.mailCustomFromEnabled
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
}).then(function() {
|
|
|
|
vm.preferences.defaults.AuxiliaryMailAccounts[index] = account;
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-12-19 15:53:48 +01:00
|
|
|
}, function() {
|
|
|
|
// Cancel
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.removeMailAccount = function(index, form) {
|
|
|
|
this.preferences.defaults.AuxiliaryMailAccounts.splice(index, 1);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2017-10-12 21:44:14 +02:00
|
|
|
|
|
|
|
this.resetMailLabelValidity = function(index, form) {
|
|
|
|
form['mailIMAPLabel_' + index].$setValidity('duplicate', true);
|
|
|
|
};
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.addMailLabel = function(form) {
|
2015-12-10 21:12:12 +01:00
|
|
|
// See $omit() in the Preferences services for real key generation
|
|
|
|
var key = '_$$' + guid();
|
2017-10-12 21:44:14 +02:00
|
|
|
this.preferences.defaults.SOGoMailLabelsColorsKeys.push("label");
|
|
|
|
this.preferences.defaults.SOGoMailLabelsColorsValues.push(["New label", "#aaa"]);
|
|
|
|
focus('mailLabel_' + (_.size(this.preferences.defaults.SOGoMailLabelsColorsKeys) - 1));
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-10-12 21:44:14 +02:00
|
|
|
this.removeMailLabel = function(index, form) {
|
|
|
|
this.preferences.defaults.SOGoMailLabelsColorsKeys.splice(index, 1);
|
|
|
|
this.preferences.defaults.SOGoMailLabelsColorsValues.splice(index, 1);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2018-11-01 20:56:33 +01:00
|
|
|
function _loadAllMailboxes() {
|
|
|
|
var account;
|
|
|
|
|
|
|
|
if (mailboxes.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sgSettings.activeUser('path').mail) {
|
|
|
|
// 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]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.addMailFilter = function(ev, form) {
|
2018-02-23 16:22:42 +01:00
|
|
|
var filter = { match: 'all', active: 1 };
|
2015-10-08 22:42:24 +02:00
|
|
|
|
2018-11-01 20:56:33 +01:00
|
|
|
_loadAllMailboxes();
|
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,
|
2017-06-20 21:25:07 +02:00
|
|
|
labels: this.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
|
|
|
});
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2018-09-08 03:38:31 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.editMailFilter = function(ev, index, form) {
|
|
|
|
var filter = angular.copy(this.preferences.defaults.SOGoSieveFilters[index]);
|
2018-09-08 03:38:31 +02:00
|
|
|
|
2018-11-01 20:56:33 +01:00
|
|
|
_loadAllMailboxes();
|
2015-05-06 04:06:13 +02:00
|
|
|
$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,
|
2017-06-20 21:25:07 +02:00
|
|
|
labels: this.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();
|
2018-08-21 16:20:55 +02:00
|
|
|
},
|
|
|
|
_.noop); // Cancel
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.removeMailFilter = function(index, form) {
|
|
|
|
this.preferences.defaults.SOGoSieveFilters.splice(index, 1);
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-08-18 20:57:29 +02:00
|
|
|
|
2018-08-20 16:41:21 +02:00
|
|
|
this.onFiltersOrderChanged = function(form) {
|
|
|
|
// Return a callback that will affect the form
|
|
|
|
if (!this._onFiltersOrderChanged) {
|
|
|
|
this._onFiltersOrderChanged = function(type) {
|
|
|
|
form.$setDirty();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return this._onFiltersOrderChanged;
|
|
|
|
};
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.addDefaultEmailAddresses = function(form) {
|
2015-08-18 20:57:29 +02:00
|
|
|
var v = [];
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
if (angular.isDefined(this.preferences.defaults.Vacation.autoReplyEmailAddresses)) {
|
|
|
|
v = this.preferences.defaults.Vacation.autoReplyEmailAddresses.split(',');
|
2015-08-18 20:57:29 +02:00
|
|
|
}
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.preferences.defaults.Vacation.autoReplyEmailAddresses = (_.union($window.defaultEmailAddresses.split(','), v)).join(',');
|
2016-03-29 18:15:37 +02:00
|
|
|
form.$setDirty();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2016-03-29 18:15:37 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.userFilter = function(search, excludedUsers) {
|
2016-10-26 21:44:43 +02:00
|
|
|
if (search.length < sgSettings.minimumSearchLength())
|
|
|
|
return [];
|
|
|
|
|
2016-06-22 03:29:44 +02:00
|
|
|
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
|
2019-02-18 20:59:07 +01:00
|
|
|
user.$$image = vm.preferences.avatar(user.c_email, 40, {no_404: true});
|
2016-06-22 03:29:44 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return users;
|
|
|
|
});
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2016-06-22 03:29:44 +02:00
|
|
|
|
2019-11-15 20:37:35 +01:00
|
|
|
this.manageSieveScript = function(form) {
|
2020-01-31 22:51:33 +01:00
|
|
|
this.preferences.hasActiveExternalSieveScripts(false);
|
2019-11-15 20:37:35 +01:00
|
|
|
form.$setDirty();
|
|
|
|
};
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.confirmChanges = function($event, form) {
|
2016-03-29 18:15:37 +02:00
|
|
|
var target;
|
|
|
|
|
2018-01-19 03:56:30 +01:00
|
|
|
if (form.$dirty && form.$valid) {
|
2016-03-29 18:15:37 +02:00
|
|
|
// 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
|
2017-06-20 21:25:07 +02:00
|
|
|
vm.save(form, { quick: true }).then(function() {
|
2016-03-29 18:15:37 +02:00
|
|
|
$window.location = target.href;
|
|
|
|
});
|
|
|
|
}, function() {
|
|
|
|
// Don't save & follow link
|
|
|
|
$window.location = target.href;
|
|
|
|
});
|
|
|
|
}
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2016-03-29 18:15:37 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.save = function(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 &&
|
2017-06-20 21:25:07 +02:00
|
|
|
angular.isDefined(this.preferences.defaults.Forward) &&
|
|
|
|
this.preferences.defaults.Forward.enabled &&
|
|
|
|
angular.isDefined(this.preferences.defaults.Forward.forwardAddress)) {
|
2015-08-18 21:25:51 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
addresses = this.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;
|
|
|
|
}
|
2019-08-15 18:48:53 +02:00
|
|
|
else if ($window.forwardConstraints == 2 &&
|
|
|
|
$window.forwardConstraintsDomains.length > 0 &&
|
|
|
|
$window.forwardConstraintsDomains.indexOf(domain) < 0) {
|
|
|
|
Dialog.alert(l('Error'), l("You are not allowed to forward your messages to this domain:") + " " + domain);
|
|
|
|
sendForm = false;
|
|
|
|
}
|
2015-08-18 21:25:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:29:33 +02:00
|
|
|
// IMAP labels must be unique
|
2017-10-12 21:44:14 +02:00
|
|
|
if (this.preferences.defaults.SOGoMailLabelsColorsKeys.length !=
|
|
|
|
this.preferences.defaults.SOGoMailLabelsColorsValues.length ||
|
|
|
|
this.preferences.defaults.SOGoMailLabelsColorsKeys.length !=
|
|
|
|
_.uniq(this.preferences.defaults.SOGoMailLabelsColorsKeys).length) {
|
|
|
|
Dialog.alert(l('Error'), l("IMAP labels must have unique names."));
|
|
|
|
_.forEach(this.preferences.defaults.SOGoMailLabelsColorsKeys, function (value, i, keys) {
|
|
|
|
if (form['mailIMAPLabel_' + i].$dirty &&
|
|
|
|
(keys.indexOf(value) != i ||
|
|
|
|
keys.indexOf(value, i+1) > -1)) {
|
|
|
|
form['mailIMAPLabel_' + i].$setValidity('duplicate', false);
|
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-02 15:29:33 +02:00
|
|
|
// Calendar categories must be unique
|
|
|
|
if (this.preferences.defaults.SOGoCalendarCategories.length !=
|
|
|
|
_.uniq(this.preferences.defaults.SOGoCalendarCategories).length) {
|
|
|
|
Dialog.alert(l('Error'), l("Calendar categories must have unique names."));
|
|
|
|
_.forEach(this.preferences.defaults.SOGoCalendarCategories, function (value, i, keys) {
|
|
|
|
if (form['calendarCategory_' + i].$dirty &&
|
|
|
|
(keys.indexOf(value) != i ||
|
|
|
|
keys.indexOf(value, i+1) > -1)) {
|
|
|
|
form['calendarCategory_' + i].$setValidity('duplicate', false);
|
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-08 16:11:42 +02:00
|
|
|
// Contact categories must be unique
|
|
|
|
if (this.preferences.defaults.SOGoContactsCategories.length !=
|
|
|
|
_.uniq(this.preferences.defaults.SOGoContactsCategories).length) {
|
|
|
|
Dialog.alert(l('Error'), l("Contact categories must have unique names."));
|
|
|
|
_.forEach(this.preferences.defaults.SOGoContactsCategories, function (value, i, keys) {
|
|
|
|
if (form['contactCategory_' + i].$dirty &&
|
|
|
|
(keys.indexOf(value) != i ||
|
|
|
|
keys.indexOf(value, i+1) > -1)) {
|
|
|
|
form['contactCategory_' + i].$setValidity('duplicate', false);
|
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:25:51 +02:00
|
|
|
if (sendForm)
|
2017-06-20 21:25:07 +02:00
|
|
|
return this.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();
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.canChangePassword = function() {
|
|
|
|
if (this.passwords.newPassword && this.passwords.newPassword.length > 0 &&
|
|
|
|
this.passwords.newPasswordConfirmation && this.passwords.newPasswordConfirmation.length &&
|
|
|
|
this.passwords.newPassword == this.passwords.newPasswordConfirmation)
|
2015-05-06 04:06:13 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2018-09-08 03:38:31 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.changePassword = function() {
|
|
|
|
Authentication.changePassword(this.passwords.newPassword).then(function() {
|
2015-05-06 04:06:13 +02:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
});
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-07-21 21:21:57 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.timeZonesListFilter = function(filter) {
|
|
|
|
return _.filter(this.timeZonesList, function(value) {
|
2015-07-21 21:21:57 +02:00
|
|
|
return value.toUpperCase().indexOf(filter.toUpperCase()) >= 0;
|
|
|
|
});
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2016-10-14 17:49:23 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.updateVacationDates = function() {
|
|
|
|
var d = this.preferences.defaults;
|
2016-10-19 22:14:27 +02:00
|
|
|
|
|
|
|
if (d &&
|
|
|
|
d.Vacation &&
|
|
|
|
d.Vacation.enabled) {
|
2017-06-20 21:25:07 +02:00
|
|
|
this.toggleVacationStartDate();
|
|
|
|
this.toggleVacationEndDate();
|
2016-10-19 22:14:27 +02:00
|
|
|
}
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2016-10-19 22:14:27 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.toggleVacationStartDate = function() {
|
2016-10-19 22:14:27 +02:00
|
|
|
var v;
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
v = this.preferences.defaults.Vacation;
|
2016-10-19 22:14:27 +02:00
|
|
|
|
|
|
|
if (v.startDateEnabled) {
|
|
|
|
// Enabling the start date
|
2019-10-10 21:37:50 +02:00
|
|
|
if (!v.startDate) {
|
|
|
|
v.startDate = new Date();
|
|
|
|
}
|
|
|
|
if (v.endDateEnabled && v.endDate && v.startDate.getTime() > v.endDate.getTime()) {
|
2016-10-19 22:14:27 +02:00
|
|
|
v.startDate = new Date(v.endDate.getTime());
|
|
|
|
v.startDate.addDays(-1);
|
|
|
|
}
|
|
|
|
}
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2016-10-19 22:14:27 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.toggleVacationEndDate = function() {
|
2016-10-19 22:14:27 +02:00
|
|
|
var v;
|
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
v = this.preferences.defaults.Vacation;
|
2016-10-19 22:14:27 +02:00
|
|
|
|
|
|
|
if (v.endDateEnabled) {
|
|
|
|
// Enabling the end date
|
2019-10-10 21:37:50 +02:00
|
|
|
if (!v.endDate) {
|
|
|
|
v.endDate = new Date();
|
|
|
|
}
|
|
|
|
if (v.startDateEnabled && v.startDate && v.endDate.getTime() < v.startDate.getTime()) {
|
2016-10-19 22:14:27 +02:00
|
|
|
v.endDate = new Date(v.startDate.getTime());
|
|
|
|
v.endDate.addDays(1);
|
|
|
|
}
|
|
|
|
}
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2016-10-19 22:14:27 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.validateVacationStartDate = function(date) {
|
2016-10-19 22:14:27 +02:00
|
|
|
var d = vm.preferences.defaults, r = true;
|
|
|
|
if (d &&
|
|
|
|
d.Vacation &&
|
|
|
|
d.Vacation.enabled) {
|
|
|
|
if (d.Vacation.startDateEnabled) {
|
|
|
|
r = (!d.Vacation.endDateEnabled ||
|
2019-10-10 21:37:50 +02:00
|
|
|
!d.Vacation.endDate ||
|
2019-11-07 17:37:57 +01:00
|
|
|
date.getTime() <= d.Vacation.endDate.getTime());
|
2016-10-18 15:22:32 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-19 22:14:27 +02:00
|
|
|
|
|
|
|
return r;
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2016-10-19 22:14:27 +02:00
|
|
|
|
2017-06-20 21:25:07 +02:00
|
|
|
this.validateVacationEndDate = function(date) {
|
2016-10-19 22:14:27 +02:00
|
|
|
var d = vm.preferences.defaults, r = true;
|
|
|
|
if (d &&
|
|
|
|
d.Vacation &&
|
|
|
|
d.Vacation.enabled) {
|
|
|
|
if (d.Vacation.endDateEnabled) {
|
|
|
|
r = (!d.Vacation.startDateEnabled ||
|
2019-10-10 21:37:50 +02:00
|
|
|
!d.Vacation.startDate ||
|
2019-11-07 17:37:57 +01:00
|
|
|
date.getTime() >= d.Vacation.startDate.getTime());
|
2016-10-19 22:14:27 +02:00
|
|
|
}
|
2016-10-18 15:22:32 +02:00
|
|
|
}
|
2016-10-19 22:14:27 +02:00
|
|
|
|
|
|
|
return r;
|
2017-06-20 21:25:07 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.PreferencesUI')
|
|
|
|
.controller('PreferencesController', PreferencesController);
|
|
|
|
|
|
|
|
})();
|