2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
var
|
|
|
|
window = require('window'),
|
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
|
|
|
|
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Links = require('Common/Links'),
|
|
|
|
|
|
|
|
AccountStore = require('Stores/User/Account'),
|
|
|
|
IdentityStore = require('Stores/User/Identity'),
|
|
|
|
|
|
|
|
Settings = require('Storage/Settings'),
|
|
|
|
Remote = require('Remote/User/Ajax');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function AccountsUserSettings()
|
|
|
|
{
|
|
|
|
this.allowAdditionalAccount = Settings.capa(Enums.Capa.AdditionalAccounts);
|
|
|
|
this.allowIdentities = Settings.capa(Enums.Capa.Identities);
|
|
|
|
|
|
|
|
this.accounts = AccountStore.accounts;
|
|
|
|
this.identities = IdentityStore.identities;
|
|
|
|
|
|
|
|
this.accountForDeletion = ko.observable(null).deleteAccessHelper();
|
|
|
|
this.identityForDeletion = ko.observable(null).deleteAccessHelper();
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountsUserSettings.prototype.scrollableOptions = function(sWrapper)
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
handle: '.drag-handle',
|
|
|
|
containment: sWrapper || 'parent',
|
|
|
|
axis: 'y'
|
|
|
|
};
|
|
|
|
};
|
2015-01-28 06:16:00 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
AccountsUserSettings.prototype.addNewAccount = function()
|
|
|
|
{
|
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'));
|
|
|
|
};
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
AccountsUserSettings.prototype.editAccount = function(oAccountItem)
|
|
|
|
{
|
|
|
|
if (oAccountItem && oAccountItem.canBeEdit())
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'), [oAccountItem]);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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())
|
2015-01-28 06:16:00 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.accountForDeletion(null);
|
2015-01-28 06:16:00 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
var
|
|
|
|
kn = require('Knoin/Knoin'),
|
|
|
|
fRemoveAccount = function(oAccount) {
|
|
|
|
return oAccountToRemove === oAccount;
|
|
|
|
};
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
if (oAccountToRemove)
|
2014-10-22 00:49:15 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.accounts.remove(fRemoveAccount);
|
2014-10-22 00:49:15 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
Remote.accountDelete(function(sResult, oData) {
|
2015-02-06 23:26:20 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
if (Enums.StorageResultType.Success === sResult && oData &&
|
|
|
|
oData.Result && oData.Reload)
|
|
|
|
{
|
|
|
|
kn.routeOff();
|
|
|
|
kn.setHash(Links.root(), true);
|
|
|
|
kn.routeOff();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
_.defer(function() {
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
require('App/User').default.accountsAndIdentities();
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
}, oAccountToRemove.email);
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {IdentityModel} oIdentityToRemove
|
|
|
|
*/
|
|
|
|
AccountsUserSettings.prototype.deleteIdentity = function(oIdentityToRemove)
|
|
|
|
{
|
|
|
|
if (oIdentityToRemove && oIdentityToRemove.deleteAccess())
|
2015-02-06 23:26:20 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
this.identityForDeletion(null);
|
|
|
|
|
|
|
|
if (oIdentityToRemove)
|
2015-02-06 23:26:20 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
IdentityStore.identities.remove(function(oIdentity) {
|
|
|
|
return oIdentityToRemove === oIdentity;
|
|
|
|
});
|
2015-02-06 23:26:20 +08:00
|
|
|
|
2016-06-30 08:02:45 +08:00
|
|
|
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)
|
2015-02-06 23:26:20 +08:00
|
|
|
{
|
2016-06-30 08:02:45 +08:00
|
|
|
self.editAccount(oAccountItem);
|
2015-02-06 23:26:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
})
|
|
|
|
.on('click', '.identities-list .identity-item .e-action', function() {
|
|
|
|
var oIdentityItem = ko.dataFor(this);
|
|
|
|
if (oIdentityItem)
|
|
|
|
{
|
|
|
|
self.editIdentity(oIdentityItem);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 03:54:37 +08:00
|
|
|
export {AccountsUserSettings, AccountsUserSettings as default};
|