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-11-24 20:57:40 +01:00
|
|
|
PreferencesController.$inject = ['$q', '$window', '$state', '$mdDialog', '$mdToast', 'Dialog', 'User', 'Account', 'statePreferences', 'Authentication'];
|
|
|
|
function PreferencesController($q, $window, $state, $mdDialog, $mdToast, Dialog, User, Account, statePreferences, Authentication) {
|
2015-10-08 22:42:24 +02:00
|
|
|
var vm = this, account, mailboxes = [];
|
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;
|
2015-07-07 22:39:28 +02:00
|
|
|
vm.userFilter = User.$filter;
|
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 = '';
|
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;
|
|
|
|
});
|
|
|
|
|
2015-07-28 02:11:57 +02:00
|
|
|
function go(module) {
|
|
|
|
$state.go('preferences.' + module);
|
|
|
|
}
|
|
|
|
|
2015-11-24 20:57:40 +01:00
|
|
|
function onLanguageChange() {
|
|
|
|
Dialog.confirm(l('Warning'),
|
|
|
|
l('Save preferences and reload page now?'),
|
|
|
|
{ok: l('Yes'), cancel: l('No')})
|
|
|
|
.then(function() {
|
|
|
|
save().then(function() {
|
|
|
|
$window.location.reload(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
function addCalendarCategory() {
|
|
|
|
vm.preferences.defaults.SOGoCalendarCategoriesColors["New category"] = "#aaa";
|
|
|
|
vm.preferences.defaults.SOGoCalendarCategories.push("New category");
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeCalendarCategory(index) {
|
|
|
|
var key = vm.preferences.defaults.SOGoCalendarCategories[index];
|
|
|
|
vm.preferences.defaults.SOGoCalendarCategories.splice(index, 1);
|
|
|
|
delete vm.preferences.defaults.SOGoCalendarCategoriesColors[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
function addContactCategory() {
|
|
|
|
vm.preferences.defaults.SOGoContactsCategories.push("");
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeContactCategory(index) {
|
|
|
|
vm.preferences.defaults.SOGoContactsCategories.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addMailAccount(ev) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-08-06 22:13:10 +02:00
|
|
|
function editMailAccount(event, index) {
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeMailAccount(index) {
|
|
|
|
vm.preferences.defaults.AuxiliaryMailAccounts.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addMailLabel() {
|
2015-07-24 22:14:53 +02:00
|
|
|
vm.preferences.defaults.SOGoMailLabelsColors.new_label = ["New label", "#aaa"];
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeMailLabel(key) {
|
|
|
|
delete vm.preferences.defaults.SOGoMailLabelsColors[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
function addMailFilter(ev) {
|
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);
|
2015-05-06 04:06:13 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-10-05 16:45:30 +02:00
|
|
|
function editMailFilter(ev, index) {
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeMailFilter(index) {
|
|
|
|
vm.preferences.defaults.SOGoSieveFilters.splice(index, 1);
|
|
|
|
}
|
2015-08-18 20:57:29 +02:00
|
|
|
|
|
|
|
function addDefaultEmailAddresses() {
|
|
|
|
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(',');
|
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
|
|
|
|
function save() {
|
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
|
|
|
|
if (window.forwardConstraints > 0 &&
|
|
|
|
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
|
2015-11-24 21:05:03 +01: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();
|
2015-08-18 21:25:51 +02:00
|
|
|
if (domains.indexOf(domain) < 0 && window.forwardConstraints == 1) {
|
|
|
|
Dialog.alert(l('Error'), l("You are not allowed to forward your messages to an external email address."));
|
|
|
|
sendForm = false;
|
|
|
|
}
|
|
|
|
else if (domains.indexOf(domain) >= 0 && window.forwardConstraints == 2) {
|
|
|
|
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) {
|
|
|
|
$mdToast.show({
|
|
|
|
controller: 'savePreferencesToastCtrl',
|
|
|
|
template: [
|
|
|
|
'<md-toast>',
|
|
|
|
' <span flex>' + l('Preferences saved') + '</span>',
|
|
|
|
' <md-button class="md-icon-button md-primary" ng-click="closeToast()">',
|
|
|
|
' <md-icon>close</md-icon>',
|
|
|
|
' </md-button>',
|
|
|
|
'</md-toast>'
|
|
|
|
].join(''),
|
|
|
|
hideDelay: 2000,
|
|
|
|
position: 'top right'
|
|
|
|
});
|
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;
|
|
|
|
});
|
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
2015-11-24 21:05:03 +01:00
|
|
|
savePreferencesToastCtrl.$inject = ['$scope', '$mdToast'];
|
|
|
|
function savePreferencesToastCtrl($scope, $mdToast) {
|
|
|
|
$scope.closeToast = function() {
|
|
|
|
$mdToast.hide();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-05-06 04:06:13 +02:00
|
|
|
angular
|
|
|
|
.module('SOGo.PreferencesUI')
|
2015-11-24 21:05:03 +01:00
|
|
|
.controller('savePreferencesToastCtrl', savePreferencesToastCtrl)
|
2015-05-06 04:06:13 +02:00
|
|
|
.controller('PreferencesController', PreferencesController);
|
|
|
|
|
|
|
|
})();
|