2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
(function () {
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
'use strict';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
var
|
2014-08-25 23:49:01 +08:00
|
|
|
window = require('window'),
|
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Enums = require('Common/Enums'),
|
2015-01-26 07:09:22 +08:00
|
|
|
Translator = require('Common/Translator'),
|
2014-10-06 02:37:31 +08:00
|
|
|
Links = require('Common/Links'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2015-01-28 06:16:00 +08:00
|
|
|
AccountStore = require('Stores/User/Account'),
|
2015-02-06 23:26:20 +08:00
|
|
|
IdentityStore = require('Stores/User/Identity'),
|
2015-01-28 06:16:00 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
Remote = require('Storage/User/Remote')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-10-30 21:59:25 +08:00
|
|
|
function AccountsUserSettings()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-02-02 04:46:23 +08:00
|
|
|
this.accounts = AccountStore.accounts;
|
2015-02-06 23:26:20 +08:00
|
|
|
this.identities = IdentityStore.identities;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
this.processText = ko.computed(function () {
|
2015-02-02 04:46:23 +08:00
|
|
|
return AccountStore.accounts.loading() ? Translator.i18n('SETTINGS_ACCOUNTS/LOADING_PROCESS') : '';
|
2014-08-21 23:08:34 +08:00
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.visibility = ko.computed(function () {
|
|
|
|
return '' === this.processText() ? 'hidden' : 'visible';
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
this.accountForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
|
|
|
|
function (oPrev) {
|
|
|
|
if (oPrev)
|
|
|
|
{
|
|
|
|
oPrev.deleteAccess(false);
|
|
|
|
}
|
|
|
|
}, function (oNext) {
|
|
|
|
if (oNext)
|
|
|
|
{
|
|
|
|
oNext.deleteAccess(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]});
|
2015-02-06 23:26:20 +08:00
|
|
|
|
|
|
|
this.identityForDeletion = ko.observable(null).extend({'falseTimeout': 3000}).extend({'toggleSubscribe': [this,
|
|
|
|
function (oPrev) {
|
|
|
|
if (oPrev)
|
|
|
|
{
|
|
|
|
oPrev.deleteAccess(false);
|
|
|
|
}
|
|
|
|
}, function (oNext) {
|
|
|
|
if (oNext)
|
|
|
|
{
|
|
|
|
oNext.deleteAccess(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]});
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
2015-01-28 06:16:00 +08:00
|
|
|
AccountsUserSettings.prototype.scrollableOptions = function ()
|
|
|
|
{
|
|
|
|
return {
|
2015-02-01 23:44:44 +08:00
|
|
|
handle: '.drag-handle'
|
2015-01-28 06:16:00 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
AccountsUserSettings.prototype.addNewAccount = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-02-06 23:26:20 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'));
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
AccountsUserSettings.prototype.editAccount = function (oAccountItem)
|
2014-10-22 00:49:15 +08:00
|
|
|
{
|
|
|
|
if (oAccountItem && oAccountItem.canBeEdit())
|
|
|
|
{
|
2015-02-06 23:26:20 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'), [oAccountItem]);
|
2014-10-22 00:49:15 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-06 23:26:20 +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]);
|
|
|
|
};
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
/**
|
|
|
|
* @param {AccountModel} oAccountToRemove
|
|
|
|
*/
|
2014-10-30 21:59:25 +08:00
|
|
|
AccountsUserSettings.prototype.deleteAccount = function (oAccountToRemove)
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
if (oAccountToRemove && oAccountToRemove.deleteAccess())
|
|
|
|
{
|
|
|
|
this.accountForDeletion(null);
|
|
|
|
|
|
|
|
var
|
2014-09-06 05:44:29 +08:00
|
|
|
kn = require('Knoin/Knoin'),
|
2014-08-21 23:08:34 +08:00
|
|
|
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();
|
2014-10-06 02:37:31 +08:00
|
|
|
kn.setHash(Links.root(), true);
|
2014-08-21 23:08:34 +08:00
|
|
|
kn.routeOff();
|
|
|
|
|
|
|
|
_.defer(function () {
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-18 21:43:44 +08:00
|
|
|
require('App/User').accountsAndIdentities();
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}, oAccountToRemove.email);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-06 23:26:20 +08:00
|
|
|
/**
|
|
|
|
* @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').accountsAndIdentities();
|
|
|
|
}, oIdentityToRemove.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
AccountsUserSettings.prototype.onBuild = function (oDom)
|
2014-10-22 00:49:15 +08:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
oDom
|
2015-02-06 23:26:20 +08:00
|
|
|
.on('click', '.accounts-list .account-item .e-action', function () {
|
2014-10-22 00:49:15 +08:00
|
|
|
var oAccountItem = ko.dataFor(this);
|
|
|
|
if (oAccountItem)
|
|
|
|
{
|
|
|
|
self.editAccount(oAccountItem);
|
|
|
|
}
|
|
|
|
})
|
2015-02-06 23:26:20 +08:00
|
|
|
.on('click', '.identities-list .identity-item .e-action', function () {
|
|
|
|
var oIdentityItem = ko.dataFor(this);
|
|
|
|
if (oIdentityItem)
|
|
|
|
{
|
|
|
|
self.editIdentity(oIdentityItem);
|
|
|
|
}
|
|
|
|
})
|
2014-10-22 00:49:15 +08:00
|
|
|
;
|
|
|
|
};
|
|
|
|
|
2014-10-30 21:59:25 +08:00
|
|
|
module.exports = AccountsUserSettings;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|