snappymail/dev/Settings/User/Accounts.js

130 lines
2.6 KiB
JavaScript
Raw Normal View History

2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
(function () {
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'),
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'),
2014-10-18 21:43:44 +08:00
Remote = require('Storage/User/Remote')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
*/
function AccountsUserSettings()
2014-08-21 23:08:34 +08:00
{
2015-01-28 06:16:00 +08:00
this.accounts = AccountStore.collection;
2014-08-21 23:08:34 +08:00
this.processText = ko.computed(function () {
2015-01-28 06:16:00 +08:00
return AccountStore.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-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
};
};
AccountsUserSettings.prototype.addNewAccount = function ()
2014-08-21 23:08:34 +08:00
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/AddAccount'));
2014-08-21 23:08:34 +08:00
};
AccountsUserSettings.prototype.editAccount = function (oAccountItem)
2014-10-22 00:49:15 +08:00
{
if (oAccountItem && oAccountItem.canBeEdit())
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/AddAccount'), [oAccountItem]);
}
};
2014-08-21 23:08:34 +08:00
/**
* @param {AccountModel} oAccountToRemove
*/
AccountsUserSettings.prototype.deleteAccount = function (oAccountToRemove)
2014-08-21 23:08:34 +08:00
{
if (oAccountToRemove && oAccountToRemove.deleteAccess())
{
this.accountForDeletion(null);
var
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);
}
}
};
AccountsUserSettings.prototype.onBuild = function (oDom)
2014-10-22 00:49:15 +08:00
{
var self = this;
oDom
.on('click', '.account-item .e-action', function () {
var oAccountItem = ko.dataFor(this);
if (oAccountItem)
{
self.editAccount(oAccountItem);
}
})
;
};
module.exports = AccountsUserSettings;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());