snappymail/dev/View/User/AbstractSystemDropDown.js

114 lines
2.8 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
Settings = require('Storage/Settings'),
2014-10-18 21:43:44 +08:00
Data = require('Storage/User/Data'),
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');
2014-08-22 23:08:56 +08:00
this.accounts = Data.accounts;
this.accountEmail = Data.accountEmail;
this.accountsLoading = Data.accountsLoading;
2014-08-21 23:08:34 +08:00
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.loading = ko.computed(function () {
return this.accountsLoading();
}, this);
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)
{
var self = this;
this.accountsLoading(true);
_.delay(function () {
self.accountsLoading(false);
}, 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
{
2014-08-22 23:08:56 +08:00
return Data.accountEmail();
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/AddAccount'));
}
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
}());