mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-03 06:27:02 +03:00
Code refactoring (5) (es5 -> es2015)
This commit is contained in:
parent
c148e19ea3
commit
cec53b111f
68 changed files with 2210 additions and 2472 deletions
|
|
@ -1,154 +1,135 @@
|
|||
|
||||
var
|
||||
window = require('window'),
|
||||
_ = require('_'),
|
||||
ko = require('ko'),
|
||||
import window from 'window';
|
||||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
Enums = require('Common/Enums'),
|
||||
Links = require('Common/Links'),
|
||||
import {Capa, StorageResultType} from 'Common/Enums';
|
||||
import {root} from 'Common/Links';
|
||||
|
||||
AccountStore = require('Stores/User/Account'),
|
||||
IdentityStore = require('Stores/User/Identity'),
|
||||
import {capa} from 'Storage/Settings';
|
||||
|
||||
Settings = require('Storage/Settings'),
|
||||
Remote = require('Remote/User/Ajax');
|
||||
import {showScreenPopup, routeOff, setHash} from 'Knoin/Knoin';
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function AccountsUserSettings()
|
||||
import AccountStore from 'Stores/User/Account';
|
||||
import IdentityStore from 'Stores/User/Identity';
|
||||
import Remote from 'Remote/User/Ajax';
|
||||
|
||||
class AccountsUserSettings
|
||||
{
|
||||
this.allowAdditionalAccount = Settings.capa(Enums.Capa.AdditionalAccounts);
|
||||
this.allowIdentities = Settings.capa(Enums.Capa.Identities);
|
||||
constructor() {
|
||||
this.allowAdditionalAccount = capa(Capa.AdditionalAccounts);
|
||||
this.allowIdentities = capa(Capa.Identities);
|
||||
|
||||
this.accounts = AccountStore.accounts;
|
||||
this.identities = IdentityStore.identities;
|
||||
this.accounts = AccountStore.accounts;
|
||||
this.identities = IdentityStore.identities;
|
||||
|
||||
this.accountForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
this.identityForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
this.accountForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
this.identityForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
}
|
||||
|
||||
scrollableOptions(wrapper) {
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
containment: wrapper || 'parent',
|
||||
axis: 'y'
|
||||
};
|
||||
}
|
||||
|
||||
addNewAccount() {
|
||||
showScreenPopup(require('View/Popup/Account'));
|
||||
}
|
||||
|
||||
editAccount(account) {
|
||||
if (account && account.canBeEdit())
|
||||
{
|
||||
showScreenPopup(require('View/Popup/Account'), [account]);
|
||||
}
|
||||
}
|
||||
|
||||
addNewIdentity() {
|
||||
showScreenPopup(require('View/Popup/Identity'));
|
||||
}
|
||||
|
||||
editIdentity(identity) {
|
||||
showScreenPopup(require('View/Popup/Identity'), [identity]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {AccountModel} accountToRemove
|
||||
* @returns {void}
|
||||
*/
|
||||
deleteAccount(accountToRemove) {
|
||||
if (accountToRemove && accountToRemove.deleteAccess())
|
||||
{
|
||||
this.accountForDeletion(null);
|
||||
if (accountToRemove)
|
||||
{
|
||||
this.accounts.remove((account) => accountToRemove === account);
|
||||
|
||||
Remote.accountDelete(function(result, data) {
|
||||
|
||||
if (StorageResultType.Success === result && data && data.Result && data.Reload)
|
||||
{
|
||||
routeOff();
|
||||
setHash(root(), true);
|
||||
routeOff();
|
||||
|
||||
_.defer(() => window.location.reload());
|
||||
}
|
||||
else
|
||||
{
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
}
|
||||
|
||||
}, accountToRemove.email);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {IdentityModel} identityToRemove
|
||||
* @returns {void}
|
||||
*/
|
||||
deleteIdentity(identityToRemove) {
|
||||
if (identityToRemove && identityToRemove.deleteAccess())
|
||||
{
|
||||
this.identityForDeletion(null);
|
||||
|
||||
if (identityToRemove)
|
||||
{
|
||||
IdentityStore.identities.remove((oIdentity) => identityToRemove === oIdentity);
|
||||
|
||||
Remote.identityDelete(() => {
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
}, identityToRemove.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
accountsAndIdentitiesAfterMove() {
|
||||
Remote.accountsAndIdentitiesSortOrder(null,
|
||||
AccountStore.accountsEmails.peek(), IdentityStore.identitiesIDS.peek());
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.accounts-list .account-item .e-action', function() {
|
||||
const account = ko.dataFor(this);
|
||||
if (account)
|
||||
{
|
||||
self.editAccount(account);
|
||||
}
|
||||
})
|
||||
.on('click', '.identities-list .identity-item .e-action', function() {
|
||||
const identity = ko.dataFor(this);
|
||||
if (identity)
|
||||
{
|
||||
self.editIdentity(identity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
AccountsUserSettings.prototype.scrollableOptions = function(sWrapper)
|
||||
{
|
||||
return {
|
||||
handle: '.drag-handle',
|
||||
containment: sWrapper || 'parent',
|
||||
axis: 'y'
|
||||
};
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.addNewAccount = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'));
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.editAccount = function(oAccountItem)
|
||||
{
|
||||
if (oAccountItem && oAccountItem.canBeEdit())
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'), [oAccountItem]);
|
||||
}
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.addNewIdentity = function()
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Identity'));
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.editIdentity = function(oIdentity)
|
||||
{
|
||||
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Identity'), [oIdentity]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {AccountModel} oAccountToRemove
|
||||
*/
|
||||
AccountsUserSettings.prototype.deleteAccount = function(oAccountToRemove)
|
||||
{
|
||||
if (oAccountToRemove && oAccountToRemove.deleteAccess())
|
||||
{
|
||||
this.accountForDeletion(null);
|
||||
|
||||
var
|
||||
kn = require('Knoin/Knoin'),
|
||||
fRemoveAccount = function(oAccount) {
|
||||
return oAccountToRemove === oAccount;
|
||||
};
|
||||
|
||||
if (oAccountToRemove)
|
||||
{
|
||||
this.accounts.remove(fRemoveAccount);
|
||||
|
||||
Remote.accountDelete(function(sResult, oData) {
|
||||
|
||||
if (Enums.StorageResultType.Success === sResult && oData &&
|
||||
oData.Result && oData.Reload)
|
||||
{
|
||||
kn.routeOff();
|
||||
kn.setHash(Links.root(), true);
|
||||
kn.routeOff();
|
||||
|
||||
_.defer(function() {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
}
|
||||
|
||||
}, oAccountToRemove.email);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {IdentityModel} oIdentityToRemove
|
||||
*/
|
||||
AccountsUserSettings.prototype.deleteIdentity = function(oIdentityToRemove)
|
||||
{
|
||||
if (oIdentityToRemove && oIdentityToRemove.deleteAccess())
|
||||
{
|
||||
this.identityForDeletion(null);
|
||||
|
||||
if (oIdentityToRemove)
|
||||
{
|
||||
IdentityStore.identities.remove(function(oIdentity) {
|
||||
return oIdentityToRemove === oIdentity;
|
||||
});
|
||||
|
||||
Remote.identityDelete(function() {
|
||||
require('App/User').default.accountsAndIdentities();
|
||||
}, oIdentityToRemove.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.accountsAndIdentitiesAfterMove = function()
|
||||
{
|
||||
Remote.accountsAndIdentitiesSortOrder(null,
|
||||
AccountStore.accountsEmails.peek(), IdentityStore.identitiesIDS.peek());
|
||||
};
|
||||
|
||||
AccountsUserSettings.prototype.onBuild = function(oDom)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
oDom
|
||||
.on('click', '.accounts-list .account-item .e-action', function() {
|
||||
var oAccountItem = ko.dataFor(this);
|
||||
if (oAccountItem)
|
||||
{
|
||||
self.editAccount(oAccountItem);
|
||||
}
|
||||
})
|
||||
.on('click', '.identities-list .identity-item .e-action', function() {
|
||||
var oIdentityItem = ko.dataFor(this);
|
||||
if (oIdentityItem)
|
||||
{
|
||||
self.editIdentity(oIdentityItem);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export {AccountsUserSettings, AccountsUserSettings as default};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue