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

103 lines
2 KiB
JavaScript
Raw Normal View History

(function () {
'use strict';
var
_ = require('_'),
2015-02-16 05:55:59 +08:00
key = require('key'),
2015-02-16 05:55:59 +08:00
Enums = require('Common/Enums'),
Globals = require('Common/Globals'),
2014-10-06 02:37:31 +08:00
Links = require('Common/Links'),
2015-02-23 00:35:17 +08:00
Cache = require('Common/Cache'),
2016-05-01 09:07:10 +08:00
Settings = require('Storage/Settings'),
kn = require('Knoin/Knoin'),
AbstractView = require('Knoin/AbstractView')
;
/**
* @param {?} oScreen
*
* @constructor
* @extends AbstractView
*/
2014-10-18 21:43:44 +08:00
function MenuSettingsUserView(oScreen)
{
AbstractView.call(this, 'Left', 'SettingsMenu');
this.leftPanelDisabled = Globals.leftPanelDisabled;
2016-05-01 09:07:10 +08:00
this.mobile = Settings.appSettingsGet('mobile');
this.menu = oScreen.menu;
kn.constructorEnd(this);
}
2014-10-18 21:43:44 +08:00
kn.extendAsViewModel(['View/User/Settings/Menu', 'View/App/Settings/Menu', 'SettingsMenuViewModel'], MenuSettingsUserView);
_.extend(MenuSettingsUserView.prototype, AbstractView.prototype);
2015-02-16 05:55:59 +08:00
MenuSettingsUserView.prototype.onBuild = function (oDom)
{
// var self = this;
// key('esc', Enums.KeyState.Settings, function () {
// self.backToMailBoxClick();
// });
2016-05-01 09:07:10 +08:00
if (this.mobile)
{
oDom
.on('click', '.b-settings-menu .e-item.selectable', function () {
Globals.leftPanelDisabled(true);
})
;
}
2015-02-16 05:55:59 +08:00
key('up, down', Enums.KeyState.Settings, _.throttle(function (event, handler) {
var
sH = '',
iIndex = -1,
bUp = handler && 'up' === handler.shortcut,
$items = $('.b-settings-menu .e-item', oDom)
;
if (event && $items.length)
{
iIndex = $items.index($items.filter('.selected'));
if (bUp && iIndex > 0)
{
iIndex--;
}
else if (!bUp && iIndex < $items.length - 1)
{
iIndex++;
}
sH = $items.eq(iIndex).attr('href');
if (sH)
{
kn.setHash(sH, false, true);
}
}
}, 200));
};
2014-10-18 21:43:44 +08:00
MenuSettingsUserView.prototype.link = function (sRoute)
{
2014-10-06 02:37:31 +08:00
return Links.settings(sRoute);
};
2014-10-18 21:43:44 +08:00
MenuSettingsUserView.prototype.backToMailBoxClick = function ()
{
kn.setHash(Links.inbox(Cache.getFolderInboxName()));
};
2014-10-18 21:43:44 +08:00
module.exports = MenuSettingsUserView;
2016-06-28 04:54:38 +08:00
}());