2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-12-09 00:15:46 +08:00
|
|
|
//import { koComputable } from 'External/ko';
|
2022-02-08 21:13:06 +08:00
|
|
|
import { SettingsCapa, SettingsGet } from 'Common/Globals';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { AccountUserStore } from 'Stores/User/Account';
|
2021-02-17 21:40:21 +08:00
|
|
|
import { IdentityUserStore } from 'Stores/User/Identity';
|
2022-12-22 17:01:25 +08:00
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2020-09-17 02:35:29 +08:00
|
|
|
import { showScreenPopup } from 'Knoin/Knoin';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import { AccountPopupView } from 'View/Popup/Account';
|
|
|
|
import { IdentityPopupView } from 'View/Popup/Identity';
|
|
|
|
|
2022-03-08 07:51:32 +08:00
|
|
|
export class UserSettingsAccounts /*extends AbstractViewSettings*/ {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2022-03-06 05:25:32 +08:00
|
|
|
this.allowAdditionalAccount = SettingsCapa('AdditionalAccounts');
|
|
|
|
this.allowIdentities = SettingsCapa('Identities');
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-11-09 00:40:12 +08:00
|
|
|
this.accounts = AccountUserStore;
|
2021-03-11 05:41:35 +08:00
|
|
|
this.loading = AccountUserStore.loading;
|
2021-02-17 21:40:21 +08:00
|
|
|
this.identities = IdentityUserStore;
|
2021-11-15 17:56:52 +08:00
|
|
|
this.mainEmail = SettingsGet('MainEmail');
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2022-01-28 06:07:34 +08:00
|
|
|
this.accountForDeletion = ko.observable(null).askDeleteHelper();
|
|
|
|
this.identityForDeletion = ko.observable(null).askDeleteHelper();
|
2022-12-09 00:15:46 +08:00
|
|
|
|
2022-12-22 17:01:25 +08:00
|
|
|
this.showUnread = SettingsUserStore.showUnreadCount;
|
|
|
|
SettingsUserStore.showUnreadCount.subscribe(value => Remote.saveSetting('ShowUnreadCount', value));
|
|
|
|
|
2022-12-09 00:15:46 +08:00
|
|
|
// this.additionalAccounts = koComputable(() => AccountUserStore.filter(account => account.isAdditional()));
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
addNewAccount() {
|
2021-01-26 05:00:13 +08:00
|
|
|
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) {
|
2022-09-02 17:52:07 +08:00
|
|
|
if (account?.isAdditional()) {
|
2021-01-26 05:00:13 +08:00
|
|
|
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() {
|
2021-01-26 05:00:13 +08:00
|
|
|
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) {
|
2021-01-26 05:00:13 +08:00
|
|
|
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) {
|
2022-09-02 17:52:07 +08:00
|
|
|
if (accountToRemove?.askDelete()) {
|
2016-07-16 05:29:42 +08:00
|
|
|
this.accountForDeletion(null);
|
2022-10-10 19:52:56 +08:00
|
|
|
this.accounts.remove(account => accountToRemove === account);
|
|
|
|
|
|
|
|
Remote.request('AccountDelete', (iError, data) => {
|
|
|
|
if (!iError && data.Reload) {
|
|
|
|
rl.route.root();
|
|
|
|
setTimeout(() => location.reload(), 1);
|
|
|
|
} else {
|
|
|
|
rl.app.accountsAndIdentities();
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
EmailToDelete: 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) {
|
2022-09-02 17:52:07 +08:00
|
|
|
if (identityToRemove?.askDelete()) {
|
2016-07-16 05:29:42 +08:00
|
|
|
this.identityForDeletion(null);
|
2022-10-10 19:52:56 +08:00
|
|
|
IdentityUserStore.remove(oIdentity => identityToRemove === oIdentity);
|
|
|
|
Remote.request('IdentityDelete', () => rl.app.accountsAndIdentities(), {
|
|
|
|
IdToDelete: identityToRemove.id()
|
|
|
|
});
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
accountsAndIdentitiesAfterMove() {
|
2021-12-03 06:15:24 +08:00
|
|
|
Remote.request('AccountsAndIdentitiesSortOrder', null, {
|
|
|
|
Accounts: AccountUserStore.getEmailAddresses().filter(v => v != SettingsGet('MainEmail')),
|
2022-03-21 20:00:10 +08:00
|
|
|
Identities: IdentityUserStore.map(item => (item ? item.id() : ""))
|
2021-12-03 06:15:24 +08:00
|
|
|
});
|
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) {
|
2020-08-30 16:30:50 +08:00
|
|
|
oDom.addEventListener('click', event => {
|
2021-09-09 23:00:31 +08:00
|
|
|
let el = event.target.closestWithin('.accounts-list .e-action', oDom);
|
2020-08-30 16:30:50 +08:00
|
|
|
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);
|
2020-08-30 16:30:50 +08:00
|
|
|
el && ko.dataFor(el) && this.editIdentity(ko.dataFor(el));
|
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
}
|