snappymail/dev/Stores/User/Account.js

60 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-01-28 06:16:00 +08:00
(function () {
'use strict';
var
_ = require('_'),
ko = require('ko'),
Remote = require('Storage/User/Remote')
;
/**
* @constructor
*/
function AccountUserStore()
{
this.accounts = ko.observableArray([]);
this.accounts.loading = ko.observable(false).extend({'throttle': 100});
2015-01-28 06:16:00 +08:00
this.accountsEmailNames = ko.observableArray([]).extend({'throttle': 1000});
this.accountsEmailNames.skipFirst = true;
2015-01-28 06:16:00 +08:00
this.accounts.subscribe(function (aList) {
this.accountsEmailNames(_.compact(_.map(aList, function (oItem) {
2015-01-28 06:16:00 +08:00
return oItem ? oItem.email : null;
})));
}, this);
this.accountsEmailNames.subscribe(function (aList) {
if (this.accountsEmailNames.skipFirst)
2015-01-28 06:16:00 +08:00
{
this.accountsEmailNames.skipFirst = false;
2015-01-28 06:16:00 +08:00
}
else if (aList && 1 < aList.length)
{
Remote.accountSortOrder(null, aList);
}
}, this);
this.accountsUnreadCount = ko.computed(function () {
var iResult = 0;
_.each(this.accounts(), function (oItem) {
if (oItem)
{
iResult += oItem.count();
}
});
return iResult;
}, this);
2015-01-28 06:16:00 +08:00
}
module.exports = new AccountUserStore();
}());