2013-11-16 06:21:12 +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
|
|
|
_ = require('_'),
|
|
|
|
ko = require('ko'),
|
|
|
|
key = require('key'),
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
Enums = require('Common/Enums'),
|
|
|
|
Utils = require('Common/Utils'),
|
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-09-06 05:44:29 +08:00
|
|
|
Settings = require('Storage/Settings'),
|
2014-10-18 21:43:44 +08:00
|
|
|
Remote = require('Storage/User/Remote'),
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView = require('Knoin/AbstractView')
|
2014-08-21 23:08:34 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
2014-09-06 05:44:29 +08:00
|
|
|
* @extends AbstractView
|
2014-08-21 23:08:34 +08:00
|
|
|
*/
|
2014-10-18 21:43:44 +08:00
|
|
|
function AbstractSystemDropDownUserView()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
AbstractView.call(this, 'Right', 'SystemDropDown');
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2015-02-03 07:58:58 +08:00
|
|
|
this.accountEmail = AccountStore.email;
|
2014-04-12 09:05:57 +08:00
|
|
|
|
2015-02-02 04:46:23 +08:00
|
|
|
this.accounts = AccountStore.accounts;
|
|
|
|
this.accountsUnreadCount = AccountStore.accountsUnreadCount;
|
2014-04-12 09:05:57 +08:00
|
|
|
|
2015-02-02 04:46:23 +08:00
|
|
|
this.accountMenuDropdownTrigger = ko.observable(false);
|
2014-10-06 02:37:31 +08:00
|
|
|
this.capaAdditionalAccounts = ko.observable(Settings.capa(Enums.Capa.AdditionalAccounts));
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
this.accountClick = _.bind(this.accountClick, this);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
_.extend(AbstractSystemDropDownUserView.prototype, AbstractView.prototype);
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
AbstractSystemDropDownUserView.prototype.accountClick = function (oAccount, oEvent)
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-08-21 23:08:34 +08:00
|
|
|
if (oAccount && oEvent && !Utils.isUnd(oEvent.which) && 1 === oEvent.which)
|
|
|
|
{
|
2015-02-02 04:46:23 +08:00
|
|
|
AccountStore.accounts.loading(true);
|
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
_.delay(function () {
|
2015-02-02 04:46:23 +08:00
|
|
|
AccountStore.accounts.loading(false);
|
2014-08-21 23:08:34 +08:00
|
|
|
}, 1000);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-08-21 23:08:34 +08:00
|
|
|
return true;
|
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
AbstractSystemDropDownUserView.prototype.emailTitle = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2015-02-03 07:58:58 +08:00
|
|
|
return AccountStore.email();
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
AbstractSystemDropDownUserView.prototype.settingsClick = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-10-06 02:37:31 +08:00
|
|
|
require('Knoin/Knoin').setHash(Links.settings());
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
2014-04-29 23:31:49 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
AbstractSystemDropDownUserView.prototype.settingsHelp = function ()
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
AbstractSystemDropDownUserView.prototype.addAccountClick = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
2014-10-06 02:37:31 +08:00
|
|
|
if (this.capaAdditionalAccounts())
|
2013-11-16 06:21:12 +08:00
|
|
|
{
|
2015-02-06 23:26:20 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'));
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
};
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
AbstractSystemDropDownUserView.prototype.logoutClick = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
Remote.logout(function () {
|
2014-10-18 21:43:44 +08:00
|
|
|
require('App/User').loginAndLogoutReload(true,
|
2014-08-27 23:59:44 +08:00
|
|
|
Settings.settingsGet('ParentEmail') && 0 < Settings.settingsGet('ParentEmail').length);
|
2014-08-21 23:08:34 +08:00
|
|
|
});
|
|
|
|
};
|
2014-04-29 23:31:49 +08:00
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
AbstractSystemDropDownUserView.prototype.onBuild = function ()
|
2014-08-21 23:08:34 +08:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
key('`', [Enums.KeyState.MessageList, Enums.KeyState.MessageView, Enums.KeyState.Settings], function () {
|
|
|
|
if (self.viewModelVisibility())
|
|
|
|
{
|
|
|
|
self.accountMenuDropdownTrigger(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// shortcuts help
|
|
|
|
key('shift+/', [Enums.KeyState.MessageList, Enums.KeyState.MessageView, Enums.KeyState.Settings], function () {
|
|
|
|
if (self.viewModelVisibility())
|
|
|
|
{
|
2014-09-06 05:44:29 +08:00
|
|
|
require('Knoin/Knoin').showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
|
2014-08-21 23:08:34 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-10-18 21:43:44 +08:00
|
|
|
module.exports = AbstractSystemDropDownUserView;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2014-09-05 06:49:03 +08:00
|
|
|
}());
|