snappymail/dev/View/User/Settings/Menu.js

86 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-06-30 08:02:45 +08:00
var
_ = require('_'),
2016-07-16 05:29:42 +08:00
$ = require('$'),
2016-06-30 08:02:45 +08:00
key = require('key'),
2016-06-30 08:02:45 +08:00
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
Links = require('Common/Links'),
2016-06-30 08:02:45 +08:00
Cache = require('Common/Cache'),
Settings = require('Storage/Settings'),
2016-06-30 08:02:45 +08:00
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView');
2016-06-30 08:02:45 +08:00
/**
* @constructor
* @param {Object} oScreen
*/
function MenuSettingsUserView(oScreen)
{
AbstractView.call(this, 'Left', 'SettingsMenu');
2016-06-30 08:02:45 +08:00
this.leftPanelDisabled = Globals.leftPanelDisabled;
2016-06-30 08:02:45 +08:00
this.mobile = Settings.appSettingsGet('mobile');
2016-06-30 08:02:45 +08:00
this.menu = oScreen.menu;
2016-05-01 09:07:10 +08:00
2016-06-30 08:02:45 +08:00
kn.constructorEnd(this);
}
2016-06-30 08:02:45 +08:00
kn.extendAsViewModel(['View/User/Settings/Menu', 'View/App/Settings/Menu', 'SettingsMenuViewModel'], MenuSettingsUserView);
_.extend(MenuSettingsUserView.prototype, AbstractView.prototype);
2016-06-30 08:02:45 +08:00
MenuSettingsUserView.prototype.onBuild = function(oDom)
{
if (this.mobile)
{
oDom
.on('click', '.b-settings-menu .e-item.selectable', function() {
Globals.leftPanelDisabled(true);
});
}
2016-05-01 09:07:10 +08:00
2016-06-30 08:02:45 +08:00
key('up, down', Enums.KeyState.Settings, _.throttle(function(event, handler) {
2015-02-16 05:55:59 +08:00
2016-06-30 08:02:45 +08:00
var
bUp = handler && 'up' === handler.shortcut,
$items = $('.b-settings-menu .e-item', oDom);
2015-02-16 05:55:59 +08:00
2016-06-30 08:02:45 +08:00
if (event && $items.length)
{
2016-08-10 03:52:30 +08:00
var iIndex = $items.index($items.filter('.selected'));
2016-06-30 08:02:45 +08:00
if (bUp && 0 < iIndex)
{
iIndex -= 1;
}
else if (!bUp && iIndex < $items.length - 1)
2015-02-16 05:55:59 +08:00
{
2016-06-30 08:02:45 +08:00
iIndex += 1;
2015-02-16 05:55:59 +08:00
}
2016-08-10 03:52:30 +08:00
var sH = $items.eq(iIndex).attr('href');
2016-06-30 08:02:45 +08:00
if (sH)
{
kn.setHash(sH, false, true);
}
}
2015-02-16 05:55:59 +08:00
2016-07-02 06:49:59 +08:00
}, 200)); // eslint-disable-line no-magic-numbers
2016-06-30 08:02:45 +08:00
};
2016-06-30 08:02:45 +08:00
MenuSettingsUserView.prototype.link = function(sRoute)
{
return Links.settings(sRoute);
};
2016-06-30 08:02:45 +08:00
MenuSettingsUserView.prototype.backToMailBoxClick = function()
{
kn.setHash(Links.inbox(Cache.getFolderInboxName()));
};
2016-06-30 08:02:45 +08:00
module.exports = MenuSettingsUserView;