2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
(function (module, require) {
|
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-08-25 23:49:01 +08:00
|
|
|
Enums = require('Enums'),
|
|
|
|
Utils = require('Utils'),
|
|
|
|
LinkBuilder = require('LinkBuilder'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-08-27 23:59:44 +08:00
|
|
|
Data = require('Storage:RainLoop:Data'),
|
|
|
|
Remote = require('Storage:RainLoop:Remote')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function SettingsAccounts()
|
|
|
|
{
|
2014-08-22 23:08:56 +08:00
|
|
|
this.accounts = Data.accounts;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
|
|
|
this.processText = ko.computed(function () {
|
2014-08-22 23:08:56 +08:00
|
|
|
return Data.accountsLoading() ? Utils.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]});
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsAccounts.prototype.addNewAccount = function ()
|
|
|
|
{
|
2014-08-27 23:59:44 +08:00
|
|
|
require('App:Knoin').showScreenPopup(require('View:Popup:AddAccount'));
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {AccountModel} oAccountToRemove
|
|
|
|
*/
|
|
|
|
SettingsAccounts.prototype.deleteAccount = function (oAccountToRemove)
|
|
|
|
{
|
|
|
|
if (oAccountToRemove && oAccountToRemove.deleteAccess())
|
|
|
|
{
|
|
|
|
this.accountForDeletion(null);
|
|
|
|
|
|
|
|
var
|
2014-08-27 23:59:44 +08:00
|
|
|
kn = require('App: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();
|
|
|
|
kn.setHash(LinkBuilder.root(), true);
|
|
|
|
kn.routeOff();
|
|
|
|
|
|
|
|
_.defer(function () {
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 23:59:44 +08:00
|
|
|
require('App:RainLoop').accountsAndIdentities();
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}, oAccountToRemove.email);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SettingsAccounts;
|
|
|
|
|
2014-08-25 23:49:01 +08:00
|
|
|
}(module, require));
|