2015-01-28 06:16:00 +08:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var
|
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
|
|
|
|
2015-02-03 07:58:58 +08:00
|
|
|
Settings = require('Storage/Settings'),
|
|
|
|
|
2015-01-28 06:16:00 +08:00
|
|
|
Remote = require('Storage/User/Remote')
|
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function AccountUserStore()
|
|
|
|
{
|
2015-02-03 07:58:58 +08:00
|
|
|
this.email = ko.observable('');
|
|
|
|
// this.incLogin = ko.observable('');
|
|
|
|
// this.outLogin = ko.observable('');
|
|
|
|
|
|
|
|
this.signature = ko.observable('');
|
|
|
|
|
2015-02-02 04:46:23 +08:00
|
|
|
this.accounts = ko.observableArray([]);
|
|
|
|
this.accounts.loading = ko.observable(false).extend({'throttle': 100});
|
2015-01-28 06:16:00 +08:00
|
|
|
|
2015-02-02 04:46:23 +08:00
|
|
|
this.accountsEmailNames = ko.observableArray([]).extend({'throttle': 1000});
|
|
|
|
this.accountsEmailNames.skipFirst = true;
|
2015-01-28 06:16:00 +08:00
|
|
|
|
2015-02-02 04:46:23 +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);
|
|
|
|
|
2015-02-02 04:46:23 +08:00
|
|
|
this.accountsEmailNames.subscribe(function (aList) {
|
|
|
|
if (this.accountsEmailNames.skipFirst)
|
2015-01-28 06:16:00 +08:00
|
|
|
{
|
2015-02-02 04:46:23 +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);
|
2015-02-02 04:46:23 +08:00
|
|
|
|
|
|
|
this.accountsUnreadCount = ko.computed(function () {
|
|
|
|
|
|
|
|
var iResult = 0;
|
|
|
|
|
2015-02-03 07:58:58 +08:00
|
|
|
// _.each(this.accounts(), function (oItem) {
|
|
|
|
// if (oItem)
|
|
|
|
// {
|
|
|
|
// iResult += oItem.count();
|
|
|
|
// }
|
|
|
|
// });
|
2015-02-02 04:46:23 +08:00
|
|
|
|
|
|
|
return iResult;
|
|
|
|
|
|
|
|
}, this);
|
2015-01-28 06:16:00 +08:00
|
|
|
}
|
|
|
|
|
2015-02-03 07:58:58 +08:00
|
|
|
AccountUserStore.prototype.populate = function ()
|
|
|
|
{
|
|
|
|
this.email(Settings.settingsGet('Email'));
|
|
|
|
// this.incLogin(Settings.settingsGet('IncLogin'));
|
|
|
|
// this.outLogin(Settings.settingsGet('OutLogin'));
|
|
|
|
|
2015-02-06 23:26:20 +08:00
|
|
|
// this.signature(Settings.settingsGet('Signature'));
|
2015-02-03 07:58:58 +08:00
|
|
|
};
|
|
|
|
|
2015-01-28 06:16:00 +08:00
|
|
|
module.exports = new AccountUserStore();
|
|
|
|
|
|
|
|
}());
|