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
|
|
|
|
*/
|
2020-06-18 22:53:42 +02:00
|
|
|
AccountDialogController.$inject = ['$timeout', '$window', '$mdConstant', '$mdDialog', 'FileUploader', 'Dialog', 'sgSettings', 'defaults', 'account', 'accountId', 'mailCustomFromEnabled'];
|
|
|
|
function AccountDialogController($timeout, $window, $mdConstant, $mdDialog, FileUploader, Dialog, Settings, defaults, account, accountId, mailCustomFromEnabled) {
|
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
this.defaultPort = 143;
|
|
|
|
this.defaults = defaults;
|
|
|
|
this.account = account;
|
|
|
|
this.accountId = accountId;
|
|
|
|
this.hostnameRE = accountId > 0 ? /^(?!(127\.0\.0\.1|localhost(?:\.localdomain)?)$)/ : /./;
|
|
|
|
this.addressesSearchText = '';
|
|
|
|
this.emailSeparatorKeys = [
|
|
|
|
$mdConstant.KEY_CODE.ENTER,
|
|
|
|
$mdConstant.KEY_CODE.TAB,
|
|
|
|
$mdConstant.KEY_CODE.COMMA,
|
|
|
|
$mdConstant.KEY_CODE.SEMICOLON
|
|
|
|
];
|
|
|
|
this.ckConfig = {
|
2020-05-15 17:03:39 +02:00
|
|
|
'autoGrow_minHeight': 70,
|
|
|
|
'toolbar': [['Bold', 'Italic', '-', 'Link',
|
|
|
|
'Font','FontSize','-','TextColor',
|
|
|
|
'BGColor', 'Source']],
|
|
|
|
language: defaults.LocaleCode
|
|
|
|
};
|
2015-08-06 22:13:10 +02:00
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
if (!this.account.encryption)
|
|
|
|
this.account.encryption = "none";
|
|
|
|
else if (this.account.encryption == "ssl")
|
|
|
|
this.defaultPort = 993;
|
2016-10-21 16:49:09 +02:00
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
_loadCertificate();
|
2017-12-21 22:41:06 +01:00
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
this.uploader = new FileUploader({
|
2017-12-21 22:41:06 +01:00
|
|
|
url: [Settings.activeUser('folderURL') + 'Mail', accountId, 'importCertificate'].join('/'),
|
|
|
|
autoUpload: false,
|
|
|
|
queueLimit: 1,
|
|
|
|
filters: [{ name: filterByExtension, fn: filterByExtension }],
|
|
|
|
onAfterAddingFile: function(item) {
|
|
|
|
vm.certificateFilename = item.file.name;
|
|
|
|
},
|
|
|
|
onSuccessItem: function(item, response, status, headers) {
|
|
|
|
this.clearQueue();
|
2018-01-12 20:47:31 +01:00
|
|
|
$timeout(function() {
|
2020-07-16 23:30:10 +02:00
|
|
|
_.assign(vm.account, {security: {hasCertificate: true}, $$certificate: response});
|
2018-01-12 20:47:31 +01:00
|
|
|
});
|
|
|
|
_loadCertificate();
|
2017-12-21 22:41:06 +01:00
|
|
|
},
|
|
|
|
onErrorItem: function(item, response, status, headers) {
|
|
|
|
Dialog.alert(l('Error'), l('An error occurred while importing the certificate. Verify your password.'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
this.hasIdentities = function () {
|
|
|
|
return _.filter(this.account.identities, vm.isEditableIdentity).length > 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.isEditableIdentity = function (identity) {
|
|
|
|
return !identity.isReadOnly;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.selectIdentity = function (index) {
|
|
|
|
if (this.selectedIdentity == index) {
|
|
|
|
this.selectedIdentity = null;
|
|
|
|
} else {
|
|
|
|
this.selectedIdentity = index;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setDefaultIdentity = function ($event, $index) {
|
|
|
|
_.forEach(this.account.identities, function(identity, i) {
|
|
|
|
if (i == $index)
|
|
|
|
identity.isDefault = !identity.isDefault;
|
|
|
|
else
|
|
|
|
delete identity.isDefault;
|
|
|
|
});
|
|
|
|
$event.stopPropagation();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.canRemoveIdentity = function (index) {
|
|
|
|
return (index == this.selectedIdentity) && (this.account.identities.length > 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.removeIdentity = function (index) {
|
|
|
|
this.account.identities.splice(index, 1);
|
|
|
|
this.selectedIdentity = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.addIdentity = function () {
|
|
|
|
var firstReadonlyIndex = _.findIndex(this.account.identities, { isReadOnly: 1 });
|
|
|
|
var identity = {};
|
|
|
|
|
2020-07-24 21:47:17 +02:00
|
|
|
if (firstReadonlyIndex < 0)
|
|
|
|
firstReadonlyIndex = this.account.identities.length;
|
2020-06-18 22:53:42 +02:00
|
|
|
if (this.customFromIsReadonly())
|
|
|
|
identity.fullName = this.account.identities[0].fullName;
|
|
|
|
this.account.identities.splice(Math.max(firstReadonlyIndex, 0), 0, identity);
|
|
|
|
this.selectedIdentity = firstReadonlyIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.showCkEditor = function ($index) {
|
|
|
|
return this.selectedIdentity == $index && this.defaults.SOGoMailComposeMessageType == 'html';
|
|
|
|
};
|
|
|
|
|
|
|
|
this.filterEmailAddresses = function ($query) {
|
|
|
|
return _.filter($window.defaultEmailAddresses, function (address) {
|
|
|
|
return address.toLowerCase().indexOf($query.toLowerCase()) >= 0;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
function _loadCertificate() {
|
|
|
|
if (vm.account.security && vm.account.security.hasCertificate)
|
2020-06-18 22:53:42 +02:00
|
|
|
vm.account.$certificate().then(function(crt) {
|
2018-01-12 20:47:31 +01:00
|
|
|
vm.certificate = crt;
|
|
|
|
}, function() {
|
|
|
|
delete vm.account.security.hasCertificate;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-21 22:41:06 +01:00
|
|
|
function filterByExtension(item) {
|
|
|
|
var isP12File = item.type.indexOf('pkcs12') > 0 || /\.(p12|pfx)$/.test(item.name);
|
|
|
|
vm.form.certificateFilename.$setValidity('fileformat', isP12File);
|
|
|
|
return isP12File;
|
|
|
|
}
|
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
this.customFromIsReadonly = function () {
|
2015-05-06 04:06:13 +02:00
|
|
|
if (accountId > 0)
|
|
|
|
return false;
|
|
|
|
return !mailCustomFromEnabled;
|
2020-06-18 22:53:42 +02:00
|
|
|
};
|
2015-08-06 22:13:10 +02:00
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
this.importCertificate = function () {
|
|
|
|
this.uploader.queue[0].formData = [{ password: this.certificatePassword }];
|
|
|
|
this.uploader.uploadItem(0);
|
|
|
|
};
|
2017-12-21 22:41:06 +01:00
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
this.onBeforeUploadCertificate = function (form) {
|
|
|
|
this.form = form;
|
|
|
|
this.uploader.clearQueue();
|
|
|
|
};
|
2017-12-21 22:41:06 +01:00
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
this.removeCertificate = function () {
|
|
|
|
this.account.$removeCertificate();
|
|
|
|
};
|
2017-12-21 22:41:06 +01:00
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
this.cancel = function () {
|
2015-05-06 04:06:13 +02:00
|
|
|
$mdDialog.cancel();
|
2020-06-18 22:53:42 +02:00
|
|
|
};
|
2015-08-06 22:13:10 +02:00
|
|
|
|
2020-06-18 22:53:42 +02:00
|
|
|
this.save = function () {
|
2015-05-06 04:06:13 +02:00
|
|
|
$mdDialog.hide();
|
2020-06-18 22:53:42 +02:00
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.PreferencesUI')
|
|
|
|
.controller('AccountDialogController', AccountDialogController);
|
|
|
|
|
|
|
|
})();
|