2013-11-16 06:21:12 +08:00
|
|
|
/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @extends KnoinAbstractViewModel
|
|
|
|
*/
|
|
|
|
function PopupsLanguagesViewModel()
|
|
|
|
{
|
|
|
|
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsLanguages');
|
|
|
|
|
|
|
|
this.exp = ko.observable(false);
|
|
|
|
|
|
|
|
this.languages = ko.computed(function () {
|
|
|
|
return _.map(RL.data().languages(), function (sLanguage) {
|
|
|
|
return {
|
|
|
|
'key': sLanguage,
|
2013-11-20 01:41:21 +08:00
|
|
|
'selected': ko.observable(false),
|
2013-11-16 06:21:12 +08:00
|
|
|
'fullName': Utils.convertLangName(sLanguage)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2013-11-20 01:41:21 +08:00
|
|
|
|
|
|
|
RL.data().mainLanguage.subscribe(function () {
|
|
|
|
this.resetMainLanguage();
|
|
|
|
}, this);
|
2013-12-09 23:16:58 +08:00
|
|
|
|
|
|
|
Knoin.constructorEnd(this);
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Utils.extendAsViewModel('PopupsLanguagesViewModel', PopupsLanguagesViewModel);
|
|
|
|
|
2013-11-20 01:41:21 +08:00
|
|
|
PopupsLanguagesViewModel.prototype.languageEnName = function (sLanguage)
|
|
|
|
{
|
|
|
|
return Utils.convertLangName(sLanguage, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
PopupsLanguagesViewModel.prototype.resetMainLanguage = function ()
|
|
|
|
{
|
|
|
|
var sCurrent = RL.data().mainLanguage();
|
|
|
|
_.each(this.languages(), function (oItem) {
|
|
|
|
oItem['selected'](oItem['key'] === sCurrent);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
PopupsLanguagesViewModel.prototype.onShow = function ()
|
|
|
|
{
|
|
|
|
this.exp(true);
|
2013-11-20 01:41:21 +08:00
|
|
|
|
|
|
|
this.resetMainLanguage();
|
2013-11-16 06:21:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
PopupsLanguagesViewModel.prototype.onHide = function ()
|
|
|
|
{
|
|
|
|
this.exp(false);
|
|
|
|
};
|
|
|
|
|
2013-12-14 07:27:12 +08:00
|
|
|
PopupsLanguagesViewModel.prototype.onBuild = function ()
|
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
$window.on('keydown', function (oEvent) {
|
|
|
|
var bResult = true;
|
|
|
|
if (oEvent && Enums.EventKeyCode.Esc === oEvent.keyCode && self.modalVisibility())
|
|
|
|
{
|
2013-12-29 04:42:07 +08:00
|
|
|
Utils.delegateRun(self, 'cancelCommand');
|
2013-12-14 07:27:12 +08:00
|
|
|
bResult = false;
|
|
|
|
}
|
|
|
|
return bResult;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-11-16 06:21:12 +08:00
|
|
|
PopupsLanguagesViewModel.prototype.changeLanguage = function (sLang)
|
|
|
|
{
|
|
|
|
RL.data().mainLanguage(sLang);
|
|
|
|
this.cancelCommand();
|
|
|
|
};
|