snappymail/dev/View/User/AbstractSystemDropDown.js

111 lines
2.7 KiB
JavaScript
Raw Normal View History

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
_ = 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'),
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
AbstractView = require('Knoin/AbstractView')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
* @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
{
AbstractView.call(this, 'Right', 'SystemDropDown');
2015-02-03 07:58:58 +08:00
this.accountEmail = AccountStore.email;
this.accounts = AccountStore.accounts;
this.accountsUnreadCount = AccountStore.accountsUnreadCount;
this.accountMenuDropdownTrigger = ko.observable(false);
2014-10-06 02:37:31 +08:00
this.capaAdditionalAccounts = ko.observable(Settings.capa(Enums.Capa.AdditionalAccounts));
2014-08-21 23:08:34 +08:00
this.accountClick = _.bind(this.accountClick, this);
}
2014-10-18 21:43:44 +08:00
_.extend(AbstractSystemDropDownUserView.prototype, AbstractView.prototype);
2014-10-18 21:43:44 +08:00
AbstractSystemDropDownUserView.prototype.accountClick = function (oAccount, oEvent)
{
2014-08-21 23:08:34 +08:00
if (oAccount && oEvent && !Utils.isUnd(oEvent.which) && 1 === oEvent.which)
{
AccountStore.accounts.loading(true);
2014-08-21 23:08:34 +08:00
_.delay(function () {
AccountStore.accounts.loading(false);
2014-08-21 23:08:34 +08:00
}, 1000);
}
2014-08-21 23:08:34 +08:00
return true;
};
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
};
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 ()
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
2014-08-21 23:08:34 +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())
{
require('Knoin/Knoin').showScreenPopup(require('View/Popup/Account'));
}
2014-08-21 23:08:34 +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())
{
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
}());