snappymail/dev/ViewModels/PopupsLanguagesViewModel.js
RainLoop Team 5ece4cc0ec OpenPGP Key Storage (Settings) (#53)
Import, Delete, Generate, View
2014-03-13 02:29:33 +04:00

61 lines
1.3 KiB
JavaScript

/* 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,
'selected': ko.observable(false),
'fullName': Utils.convertLangName(sLanguage)
};
});
});
RL.data().mainLanguage.subscribe(function () {
this.resetMainLanguage();
}, this);
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsLanguagesViewModel', PopupsLanguagesViewModel);
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);
});
};
PopupsLanguagesViewModel.prototype.onShow = function ()
{
this.exp(true);
this.resetMainLanguage();
};
PopupsLanguagesViewModel.prototype.onHide = function ()
{
this.exp(false);
};
PopupsLanguagesViewModel.prototype.changeLanguage = function (sLang)
{
RL.data().mainLanguage(sLang);
this.cancelCommand();
};