snappymail/dev/Settings/User/Accounts.js

97 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-07-16 05:29:42 +08:00
import ko from 'ko';
2016-06-30 08:02:45 +08:00
import { Capa } from 'Common/Enums';
2021-03-10 18:44:48 +08:00
import { Settings } from 'Common/Globals';
2016-06-30 08:02:45 +08:00
import { AccountUserStore } from 'Stores/User/Account';
import { IdentityUserStore } from 'Stores/User/Identity';
import Remote from 'Remote/User/Fetch';
2016-06-30 08:02:45 +08:00
import { showScreenPopup } from 'Knoin/Knoin';
import { AccountPopupView } from 'View/Popup/Account';
import { IdentityPopupView } from 'View/Popup/Identity';
export class AccountsUserSettings /*extends AbstractViewSettings*/ {
2016-07-16 05:29:42 +08:00
constructor() {
2021-03-10 18:44:48 +08:00
this.allowAdditionalAccount = Settings.capa(Capa.AdditionalAccounts);
this.allowIdentities = Settings.capa(Capa.Identities);
2016-06-30 08:02:45 +08:00
this.accounts = AccountUserStore.accounts;
this.loading = AccountUserStore.loading;
this.identities = IdentityUserStore;
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
this.accountForDeletion = ko.observable(null).deleteAccessHelper();
this.identityForDeletion = ko.observable(null).deleteAccessHelper();
}
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
addNewAccount() {
showScreenPopup(AccountPopupView);
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
editAccount(account) {
2019-07-05 03:19:24 +08:00
if (account && account.canBeEdit()) {
showScreenPopup(AccountPopupView, [account]);
2016-07-16 05:29:42 +08:00
}
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
addNewIdentity() {
showScreenPopup(IdentityPopupView);
2016-07-16 05:29:42 +08:00
}
2015-01-28 06:16:00 +08:00
2016-07-16 05:29:42 +08:00
editIdentity(identity) {
showScreenPopup(IdentityPopupView, [identity]);
2016-07-16 05:29:42 +08:00
}
2014-08-21 23:08:34 +08:00
2016-07-16 05:29:42 +08:00
/**
* @param {AccountModel} accountToRemove
* @returns {void}
*/
deleteAccount(accountToRemove) {
2019-07-05 03:19:24 +08:00
if (accountToRemove && accountToRemove.deleteAccess()) {
2016-07-16 05:29:42 +08:00
this.accountForDeletion(null);
2019-07-05 03:19:24 +08:00
if (accountToRemove) {
2016-07-16 05:29:42 +08:00
this.accounts.remove((account) => accountToRemove === account);
2014-10-22 00:49:15 +08:00
Remote.accountDelete((iError, data) => {
2021-03-18 21:48:21 +08:00
if (!iError && data.Reload) {
rl.route.root();
setTimeout(() => location.reload(), 1);
2019-07-05 03:19:24 +08:00
} else {
2020-09-15 15:29:25 +08:00
rl.app.accountsAndIdentities();
2016-07-16 05:29:42 +08:00
}
}, accountToRemove.email);
}
2014-08-21 23:08:34 +08:00
}
2016-06-30 08:02:45 +08:00
}
2016-07-16 05:29:42 +08:00
/**
* @param {IdentityModel} identityToRemove
* @returns {void}
*/
deleteIdentity(identityToRemove) {
2019-07-05 03:19:24 +08:00
if (identityToRemove && identityToRemove.deleteAccess()) {
2016-07-16 05:29:42 +08:00
this.identityForDeletion(null);
2019-07-05 03:19:24 +08:00
if (identityToRemove) {
IdentityUserStore.remove(oIdentity => identityToRemove === oIdentity);
Remote.identityDelete(() => rl.app.accountsAndIdentities(), identityToRemove.id());
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
}
}
2016-07-16 05:29:42 +08:00
accountsAndIdentitiesAfterMove() {
Remote.accountsAndIdentitiesSortOrder(null, AccountUserStore.getEmailAddresses(), IdentityUserStore.getIDS());
2016-07-16 05:29:42 +08:00
}
2016-06-30 08:02:45 +08:00
2016-07-16 05:29:42 +08:00
onBuild(oDom) {
oDom.addEventListener('click', event => {
2021-09-09 23:00:31 +08:00
let el = event.target.closestWithin('.accounts-list .e-action', oDom);
el && ko.dataFor(el) && this.editAccount(ko.dataFor(el));
2021-09-09 23:00:31 +08:00
el = event.target.closestWithin('.identities-list .e-action', oDom);
el && ko.dataFor(el) && this.editIdentity(ko.dataFor(el));
});
2016-07-16 05:29:42 +08:00
}
}