snappymail/dev/ViewModels/AbstractSystemDropDownViewModel.js

120 lines
2.9 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
window = require('window'),
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'),
LinkBuilder = require('Common/LinkBuilder'),
2014-08-21 23:08:34 +08:00
2014-08-27 23:59:44 +08:00
Settings = require('Storage:Settings'),
Data = require('Storage:RainLoop:Data'),
Remote = require('Storage:RainLoop:Remote'),
2014-08-21 23:08:34 +08:00
2014-08-27 23:59:44 +08:00
KnoinAbstractViewModel = require('Knoin:AbstractViewModel')
2014-08-21 23:08:34 +08:00
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function AbstractSystemDropDownViewModel()
{
KnoinAbstractViewModel.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-08-27 23:59:44 +08:00
this.capaAdditionalAccounts = 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-08-21 23:08:34 +08:00
_.extend(AbstractSystemDropDownViewModel.prototype, KnoinAbstractViewModel.prototype);
2014-08-21 23:08:34 +08:00
AbstractSystemDropDownViewModel.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-08-21 23:08:34 +08:00
AbstractSystemDropDownViewModel.prototype.emailTitle = function ()
{
2014-08-22 23:08:56 +08:00
return Data.accountEmail();
2014-08-21 23:08:34 +08:00
};
2014-08-21 23:08:34 +08:00
AbstractSystemDropDownViewModel.prototype.settingsClick = function ()
{
2014-08-27 23:59:44 +08:00
require('App:Knoin').setHash(LinkBuilder.settings());
2014-08-21 23:08:34 +08:00
};
2014-04-29 23:31:49 +08:00
2014-08-21 23:08:34 +08:00
AbstractSystemDropDownViewModel.prototype.settingsHelp = function ()
{
2014-08-27 23:59:44 +08:00
require('App:Knoin').showScreenPopup(require('View:Popup:KeyboardShortcutsHelp'));
2014-08-21 23:08:34 +08:00
};
2014-08-21 23:08:34 +08:00
AbstractSystemDropDownViewModel.prototype.addAccountClick = function ()
{
if (this.capaAdditionalAccounts)
{
2014-08-27 23:59:44 +08:00
require('App:Knoin').showScreenPopup(require('View:Popup:AddAccount'));
}
2014-08-21 23:08:34 +08:00
};
2014-08-21 23:08:34 +08:00
AbstractSystemDropDownViewModel.prototype.logoutClick = function ()
{
Remote.logout(function () {
if (window.__rlah_clear)
{
window.__rlah_clear();
}
2014-08-27 23:59:44 +08:00
require('App:RainLoop').loginAndLogoutReload(true,
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-08-21 23:08:34 +08:00
AbstractSystemDropDownViewModel.prototype.onBuild = function ()
{
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-08-27 23:59:44 +08:00
require('App:Knoin').showScreenPopup(require('View:Popup:KeyboardShortcutsHelp'));
2014-08-21 23:08:34 +08:00
return false;
}
});
};
2014-08-22 23:08:56 +08:00
module.exports = AbstractSystemDropDownViewModel;
2014-08-21 23:08:34 +08:00
2014-09-05 06:49:03 +08:00
}());