snappymail/dev/ViewModels/Popups/PopupsLanguagesViewModel.js
RainLoop Team ccbf04cb67 Code refactoring
Fixed languages popup
Release commit
2014-09-02 04:15:31 +04:00

82 lines
1.8 KiB
JavaScript

(function (module, require) {
'use strict';
var
_ = require('_'),
ko = require('ko'),
Utils = require('Utils'),
Globals = require('Globals'),
kn = require('App:Knoin'),
KnoinAbstractViewModel = require('Knoin:AbstractViewModel')
;
/**
* @constructor
* @extends KnoinAbstractViewModel
*/
function PopupsLanguagesViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsLanguages');
this.Data = Globals.__APP.data(); // TODO
this.exp = ko.observable(false);
this.languages = ko.computed(function () {
return _.map(this.Data.languages(), function (sLanguage) {
return {
'key': sLanguage,
'selected': ko.observable(false),
'fullName': Utils.convertLangName(sLanguage)
};
});
}, this);
this.Data.mainLanguage.subscribe(function () {
this.resetMainLanguage();
}, this);
kn.constructorEnd(this);
}
kn.extendAsViewModel(['View:Popup:Languages', 'PopupsLanguagesViewModel'], PopupsLanguagesViewModel);
_.extend(PopupsLanguagesViewModel.prototype, KnoinAbstractViewModel.prototype);
PopupsLanguagesViewModel.prototype.languageEnName = function (sLanguage)
{
return Utils.convertLangName(sLanguage, true);
};
PopupsLanguagesViewModel.prototype.resetMainLanguage = function ()
{
var sCurrent = this.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)
{
this.Data.mainLanguage(sLang);
this.cancelCommand();
};
module.exports = PopupsLanguagesViewModel;
}(module, require));